sysrq_32.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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_AX(regs), PT_REGS_BX(regs),
  25. PT_REGS_CX(regs), PT_REGS_DX(regs));
  26. printk("ESI: %08lx EDI: %08lx EBP: %08lx",
  27. PT_REGS_SI(regs), PT_REGS_DI(regs), PT_REGS_BP(regs));
  28. printk(" DS: %04lx ES: %04lx\n",
  29. 0xffff & PT_REGS_DS(regs),
  30. 0xffff & PT_REGS_ES(regs));
  31. show_trace(NULL, (unsigned long *) &regs);
  32. }
  33. /* Copied from i386. */
  34. static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
  35. {
  36. return p > (void *)tinfo &&
  37. p < (void *)tinfo + THREAD_SIZE - 3;
  38. }
  39. /* Adapted from i386 (we also print the address we read from). */
  40. static inline unsigned long print_context_stack(struct thread_info *tinfo,
  41. unsigned long *stack, unsigned long ebp)
  42. {
  43. unsigned long addr;
  44. #ifdef CONFIG_FRAME_POINTER
  45. while (valid_stack_ptr(tinfo, (void *)ebp)) {
  46. addr = *(unsigned long *)(ebp + 4);
  47. printk("%08lx: [<%08lx>]", ebp + 4, addr);
  48. print_symbol(" %s", addr);
  49. printk("\n");
  50. ebp = *(unsigned long *)ebp;
  51. }
  52. #else
  53. while (valid_stack_ptr(tinfo, stack)) {
  54. addr = *stack;
  55. if (__kernel_text_address(addr)) {
  56. printk("%08lx: [<%08lx>]", (unsigned long) stack, addr);
  57. print_symbol(" %s", addr);
  58. printk("\n");
  59. }
  60. stack++;
  61. }
  62. #endif
  63. return ebp;
  64. }
  65. void show_trace(struct task_struct* task, unsigned long * stack)
  66. {
  67. unsigned long ebp;
  68. struct thread_info *context;
  69. /* Turn this into BUG_ON if possible. */
  70. if (!stack) {
  71. stack = (unsigned long*) &stack;
  72. printk("show_trace: got NULL stack, implicit assumption task == current");
  73. WARN_ON(1);
  74. }
  75. if (!task)
  76. task = current;
  77. if (task != current) {
  78. ebp = (unsigned long) KSTK_EBP(task);
  79. } else {
  80. asm ("movl %%ebp, %0" : "=r" (ebp) : );
  81. }
  82. context = (struct thread_info *)
  83. ((unsigned long)stack & (~(THREAD_SIZE - 1)));
  84. print_context_stack(context, stack, ebp);
  85. printk("\n");
  86. }