traps.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
  3. * Copyright (C) 2007-2009 PetaLogix
  4. * Copyright (C) 2006 Atmark Techno, Inc.
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/kallsyms.h>
  12. #include <linux/module.h>
  13. #include <linux/sched.h>
  14. #include <linux/debug_locks.h>
  15. #include <asm/exceptions.h>
  16. #include <asm/system.h>
  17. void trap_init(void)
  18. {
  19. __enable_hw_exceptions();
  20. }
  21. static unsigned long kstack_depth_to_print = 24;
  22. static int __init kstack_setup(char *s)
  23. {
  24. return !strict_strtoul(s, 0, &kstack_depth_to_print);
  25. }
  26. __setup("kstack=", kstack_setup);
  27. void show_trace(struct task_struct *task, unsigned long *stack)
  28. {
  29. unsigned long addr;
  30. if (!stack)
  31. stack = (unsigned long *)&stack;
  32. printk(KERN_NOTICE "Call Trace: ");
  33. #ifdef CONFIG_KALLSYMS
  34. printk(KERN_NOTICE "\n");
  35. #endif
  36. while (!kstack_end(stack)) {
  37. addr = *stack++;
  38. /*
  39. * If the address is either in the text segment of the
  40. * kernel, or in the region which contains vmalloc'ed
  41. * memory, it *may* be the address of a calling
  42. * routine; if so, print it so that someone tracing
  43. * down the cause of the crash will be able to figure
  44. * out the call path that was taken.
  45. */
  46. if (kernel_text_address(addr))
  47. print_ip_sym(addr);
  48. }
  49. printk(KERN_NOTICE "\n");
  50. if (!task)
  51. task = current;
  52. debug_show_held_locks(task);
  53. }
  54. void show_stack(struct task_struct *task, unsigned long *sp)
  55. {
  56. unsigned long *stack;
  57. int i;
  58. if (sp == NULL) {
  59. if (task)
  60. sp = (unsigned long *) ((struct thread_info *)
  61. (task->stack))->cpu_context.r1;
  62. else
  63. sp = (unsigned long *)&sp;
  64. }
  65. stack = sp;
  66. printk(KERN_INFO "\nStack:\n ");
  67. for (i = 0; i < kstack_depth_to_print; i++) {
  68. if (kstack_end(sp))
  69. break;
  70. if (i && ((i % 8) == 0))
  71. printk("\n ");
  72. printk("%08lx ", *sp++);
  73. }
  74. printk("\n");
  75. show_trace(task, stack);
  76. }
  77. void dump_stack(void)
  78. {
  79. show_stack(NULL, NULL);
  80. }
  81. EXPORT_SYMBOL(dump_stack);
  82. #ifdef CONFIG_MMU
  83. void __bug(const char *file, int line, void *data)
  84. {
  85. if (data)
  86. printk(KERN_CRIT "kernel BUG at %s:%d (data = %p)!\n",
  87. file, line, data);
  88. else
  89. printk(KERN_CRIT "kernel BUG at %s:%d!\n", file, line);
  90. machine_halt();
  91. }
  92. int bad_trap(int trap_num, struct pt_regs *regs)
  93. {
  94. printk(KERN_CRIT
  95. "unimplemented trap %d called at 0x%08lx, pid %d!\n",
  96. trap_num, regs->pc, current->pid);
  97. return -ENOSYS;
  98. }
  99. int debug_trap(struct pt_regs *regs)
  100. {
  101. int i;
  102. printk(KERN_CRIT "debug trap\n");
  103. for (i = 0; i < 32; i++) {
  104. /* printk("r%i:%08X\t",i,regs->gpr[i]); */
  105. if ((i % 4) == 3)
  106. printk(KERN_CRIT "\n");
  107. }
  108. printk(KERN_CRIT "pc:%08lX\tmsr:%08lX\n", regs->pc, regs->msr);
  109. return -ENOSYS;
  110. }
  111. #endif