sysrq.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (C) 2001 - 2003 Jeff Dike (jdike@addtoit.com)
  3. * Licensed under the GPL
  4. */
  5. #include "linux/kernel.h"
  6. #include "linux/smp.h"
  7. #include "linux/sched.h"
  8. #include "linux/kallsyms.h"
  9. #include "asm/ptrace.h"
  10. #include "sysrq.h"
  11. /* This is declared by <linux/sched.h> */
  12. void show_regs(struct pt_regs *regs)
  13. {
  14. printk("\n");
  15. printk("EIP: %04lx:[<%08lx>] CPU: %d %s",
  16. 0xffff & PT_REGS_CS(regs), PT_REGS_IP(regs),
  17. smp_processor_id(), print_tainted());
  18. if (PT_REGS_CS(regs) & 3)
  19. printk(" ESP: %04lx:%08lx", 0xffff & PT_REGS_SS(regs),
  20. PT_REGS_SP(regs));
  21. printk(" EFLAGS: %08lx\n %s\n", PT_REGS_EFLAGS(regs),
  22. print_tainted());
  23. printk("EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
  24. PT_REGS_EAX(regs), PT_REGS_EBX(regs),
  25. PT_REGS_ECX(regs),
  26. PT_REGS_EDX(regs));
  27. printk("ESI: %08lx EDI: %08lx EBP: %08lx",
  28. PT_REGS_ESI(regs), PT_REGS_EDI(regs),
  29. PT_REGS_EBP(regs));
  30. printk(" DS: %04lx ES: %04lx\n",
  31. 0xffff & PT_REGS_DS(regs),
  32. 0xffff & PT_REGS_ES(regs));
  33. show_trace(NULL, (unsigned long *) &regs);
  34. }
  35. /* Copied from i386. */
  36. static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
  37. {
  38. return p > (void *)tinfo &&
  39. p < (void *)tinfo + THREAD_SIZE - 3;
  40. }
  41. /* Adapted from i386 (we also print the address we read from). */
  42. static inline unsigned long print_context_stack(struct thread_info *tinfo,
  43. unsigned long *stack, unsigned long ebp)
  44. {
  45. unsigned long addr;
  46. #ifdef CONFIG_FRAME_POINTER
  47. while (valid_stack_ptr(tinfo, (void *)ebp)) {
  48. addr = *(unsigned long *)(ebp + 4);
  49. printk("%08lx: [<%08lx>]", ebp + 4, addr);
  50. print_symbol(" %s", addr);
  51. printk("\n");
  52. ebp = *(unsigned long *)ebp;
  53. }
  54. #else
  55. while (valid_stack_ptr(tinfo, stack)) {
  56. addr = *stack;
  57. if (__kernel_text_address(addr)) {
  58. printk("%08lx: [<%08lx>]", (unsigned long) stack, addr);
  59. print_symbol(" %s", addr);
  60. printk("\n");
  61. }
  62. stack++;
  63. }
  64. #endif
  65. return ebp;
  66. }
  67. void show_trace(struct task_struct* task, unsigned long * stack)
  68. {
  69. unsigned long ebp;
  70. struct thread_info *context;
  71. /* Turn this into BUG_ON if possible. */
  72. if (!stack) {
  73. stack = (unsigned long*) &stack;
  74. printk("show_trace: got NULL stack, implicit assumption task == current");
  75. WARN_ON(1);
  76. }
  77. if (!task)
  78. task = current;
  79. if (task != current) {
  80. ebp = (unsigned long) KSTK_EBP(task);
  81. } else {
  82. asm ("movl %%ebp, %0" : "=r" (ebp) : );
  83. }
  84. context = (struct thread_info *)
  85. ((unsigned long)stack & (~(THREAD_SIZE - 1)));
  86. print_context_stack(context, stack, ebp);
  87. printk("\n");
  88. }