traps.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * linux/arch/h8300/boot/traps.c -- general exception handling code
  3. * H8/300 support Yoshinori Sato <ysato@users.sourceforge.jp>
  4. *
  5. * Cloned from Linux/m68k.
  6. *
  7. * No original Copyright holder listed,
  8. * Probable original (C) Roman Zippel (assigned DJD, 1999)
  9. *
  10. * Copyright 1999-2000 D. Jeff Dionne, <jeff@rt-control.com>
  11. *
  12. * This file is subject to the terms and conditions of the GNU General Public
  13. * License. See the file COPYING in the main directory of this archive
  14. * for more details.
  15. */
  16. #include <linux/types.h>
  17. #include <linux/sched.h>
  18. #include <linux/kernel.h>
  19. #include <linux/errno.h>
  20. #include <linux/init.h>
  21. #include <linux/module.h>
  22. #include <linux/bug.h>
  23. #include <asm/system.h>
  24. #include <asm/irq.h>
  25. #include <asm/traps.h>
  26. #include <asm/page.h>
  27. static DEFINE_SPINLOCK(die_lock);
  28. /*
  29. * this must be called very early as the kernel might
  30. * use some instruction that are emulated on the 060
  31. */
  32. void __init base_trap_init(void)
  33. {
  34. }
  35. void __init trap_init (void)
  36. {
  37. }
  38. asmlinkage void set_esp0 (unsigned long ssp)
  39. {
  40. current->thread.esp0 = ssp;
  41. }
  42. /*
  43. * Generic dumping code. Used for panic and debug.
  44. */
  45. static void dump(struct pt_regs *fp)
  46. {
  47. unsigned long *sp;
  48. unsigned char *tp;
  49. int i;
  50. printk("\nCURRENT PROCESS:\n\n");
  51. printk("COMM=%s PID=%d\n", current->comm, current->pid);
  52. if (current->mm) {
  53. printk("TEXT=%08x-%08x DATA=%08x-%08x BSS=%08x-%08x\n",
  54. (int) current->mm->start_code,
  55. (int) current->mm->end_code,
  56. (int) current->mm->start_data,
  57. (int) current->mm->end_data,
  58. (int) current->mm->end_data,
  59. (int) current->mm->brk);
  60. printk("USER-STACK=%08x KERNEL-STACK=%08lx\n\n",
  61. (int) current->mm->start_stack,
  62. (int) PAGE_SIZE+(unsigned long)current);
  63. }
  64. show_regs(fp);
  65. printk("\nCODE:");
  66. tp = ((unsigned char *) fp->pc) - 0x20;
  67. for (sp = (unsigned long *) tp, i = 0; (i < 0x40); i += 4) {
  68. if ((i % 0x10) == 0)
  69. printk("\n%08x: ", (int) (tp + i));
  70. printk("%08x ", (int) *sp++);
  71. }
  72. printk("\n");
  73. printk("\nKERNEL STACK:");
  74. tp = ((unsigned char *) fp) - 0x40;
  75. for (sp = (unsigned long *) tp, i = 0; (i < 0xc0); i += 4) {
  76. if ((i % 0x10) == 0)
  77. printk("\n%08x: ", (int) (tp + i));
  78. printk("%08x ", (int) *sp++);
  79. }
  80. printk("\n");
  81. if (STACK_MAGIC != *(unsigned long *)((unsigned long)current+PAGE_SIZE))
  82. printk("(Possibly corrupted stack page??)\n");
  83. printk("\n\n");
  84. }
  85. void die(char *str, struct pt_regs *fp, unsigned long err)
  86. {
  87. static int diecount;
  88. oops_enter();
  89. console_verbose();
  90. spin_lock_irq(&die_lock);
  91. report_bug(fp->pc, fp);
  92. printk(KERN_EMERG "%s: %04lx [#%d] ", str, err & 0xffff, ++diecount);
  93. dump(fp);
  94. spin_unlock_irq(&die_lock);
  95. do_exit(SIGSEGV);
  96. }
  97. extern char _start, _etext;
  98. #define check_kernel_text(addr) \
  99. ((addr >= (unsigned long)(&_start)) && \
  100. (addr < (unsigned long)(&_etext)))
  101. static int kstack_depth_to_print = 24;
  102. void show_stack(struct task_struct *task, unsigned long *esp)
  103. {
  104. unsigned long *stack, addr;
  105. int i;
  106. if (esp == NULL)
  107. esp = (unsigned long *) &esp;
  108. stack = esp;
  109. printk("Stack from %08lx:", (unsigned long)stack);
  110. for (i = 0; i < kstack_depth_to_print; i++) {
  111. if (((unsigned long)stack & (THREAD_SIZE - 1)) == 0)
  112. break;
  113. if (i % 8 == 0)
  114. printk("\n ");
  115. printk(" %08lx", *stack++);
  116. }
  117. printk("\nCall Trace:");
  118. i = 0;
  119. stack = esp;
  120. while (((unsigned long)stack & (THREAD_SIZE - 1)) != 0) {
  121. addr = *stack++;
  122. /*
  123. * If the address is either in the text segment of the
  124. * kernel, or in the region which contains vmalloc'ed
  125. * memory, it *may* be the address of a calling
  126. * routine; if so, print it so that someone tracing
  127. * down the cause of the crash will be able to figure
  128. * out the call path that was taken.
  129. */
  130. if (check_kernel_text(addr)) {
  131. if (i % 4 == 0)
  132. printk("\n ");
  133. printk(" [<%08lx>]", addr);
  134. i++;
  135. }
  136. }
  137. printk("\n");
  138. }
  139. void show_trace_task(struct task_struct *tsk)
  140. {
  141. show_stack(tsk,(unsigned long *)tsk->thread.esp0);
  142. }
  143. void dump_stack(void)
  144. {
  145. show_stack(NULL,NULL);
  146. }
  147. EXPORT_SYMBOL(dump_stack);