traps.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * (C) Copyright 2000 - 2007
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. *
  22. * Derived from the MPC83xx code.
  23. */
  24. /*
  25. * This file handles the architecture-dependent parts of hardware
  26. * exceptions
  27. */
  28. #include <common.h>
  29. #include <kgdb.h>
  30. #include <asm/processor.h>
  31. DECLARE_GLOBAL_DATA_PTR;
  32. extern unsigned long search_exception_table(unsigned long);
  33. /*
  34. * End of addressable memory. This may be less than the actual
  35. * amount of memory on the system if we're unable to keep all
  36. * the memory mapped in.
  37. */
  38. extern ulong get_effective_memsize(void);
  39. #define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize())
  40. /*
  41. * Trap & Exception support
  42. */
  43. void
  44. print_backtrace (unsigned long *sp)
  45. {
  46. int cnt = 0;
  47. unsigned long i;
  48. puts ("Call backtrace: ");
  49. while (sp) {
  50. if ((uint)sp > END_OF_MEM)
  51. break;
  52. i = sp[1];
  53. if (cnt++ % 7 == 0)
  54. putc ('\n');
  55. printf ("%08lX ", i);
  56. if (cnt > 32) break;
  57. sp = (unsigned long *) *sp;
  58. }
  59. putc ('\n');
  60. }
  61. void show_regs (struct pt_regs * regs)
  62. {
  63. int i;
  64. printf ("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
  65. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  66. printf ("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
  67. regs->msr, regs->msr & MSR_EE ? 1 : 0, regs->msr & MSR_PR ? 1 : 0,
  68. regs->msr & MSR_FP ? 1 : 0,regs->msr & MSR_ME ? 1 : 0,
  69. regs->msr & MSR_IR ? 1 : 0,
  70. regs->msr & MSR_DR ? 1 : 0);
  71. putc ('\n');
  72. for (i = 0; i < 32; i++) {
  73. if ((i % 8) == 0) {
  74. printf ("GPR%02d: ", i);
  75. }
  76. printf ("%08lX ", regs->gpr[i]);
  77. if ((i % 8) == 7) {
  78. putc ('\n');
  79. }
  80. }
  81. }
  82. void
  83. _exception (int signr, struct pt_regs *regs)
  84. {
  85. show_regs (regs);
  86. print_backtrace ((unsigned long *)regs->gpr[1]);
  87. panic ("Exception at pc %lx signal %d", regs->nip,signr);
  88. }
  89. void
  90. MachineCheckException (struct pt_regs *regs)
  91. {
  92. unsigned long fixup;
  93. if ((fixup = search_exception_table (regs->nip)) != 0) {
  94. regs->nip = fixup;
  95. return;
  96. }
  97. #ifdef CONFIG_CMD_KGDB
  98. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  99. return;
  100. #endif
  101. puts ("Machine check.\nCaused by (from msr): ");
  102. printf ("regs %p ",regs);
  103. switch (regs->msr & 0x00FF0000) {
  104. case (0x80000000 >> 10):
  105. puts ("Instruction cache parity signal\n");
  106. break;
  107. case (0x80000000 >> 11):
  108. puts ("Data cache parity signal\n");
  109. break;
  110. case (0x80000000 >> 12):
  111. puts ("Machine check signal\n");
  112. break;
  113. case (0x80000000 >> 13):
  114. puts ("Transfer error ack signal\n");
  115. break;
  116. case (0x80000000 >> 14):
  117. puts ("Data parity signal\n");
  118. break;
  119. case (0x80000000 >> 15):
  120. puts ("Address parity signal\n");
  121. break;
  122. default:
  123. puts ("Unknown values in msr\n");
  124. }
  125. show_regs (regs);
  126. print_backtrace ((unsigned long *)regs->gpr[1]);
  127. panic ("machine check");
  128. }
  129. void
  130. AlignmentException (struct pt_regs *regs)
  131. {
  132. #ifdef CONFIG_CMD_KGDB
  133. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  134. return;
  135. #endif
  136. show_regs (regs);
  137. print_backtrace ((unsigned long *)regs->gpr[1]);
  138. panic ("Alignment Exception");
  139. }
  140. void
  141. ProgramCheckException (struct pt_regs *regs)
  142. {
  143. #ifdef CONFIG_CMD_KGDB
  144. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  145. return;
  146. #endif
  147. show_regs (regs);
  148. print_backtrace ((unsigned long *)regs->gpr[1]);
  149. panic ("Program Check Exception");
  150. }
  151. void
  152. SoftEmuException (struct pt_regs *regs)
  153. {
  154. #ifdef CONFIG_CMD_KGDB
  155. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  156. return;
  157. #endif
  158. show_regs (regs);
  159. print_backtrace ((unsigned long *)regs->gpr[1]);
  160. panic ("Software Emulation Exception");
  161. }
  162. void
  163. UnknownException (struct pt_regs *regs)
  164. {
  165. #ifdef CONFIG_CMD_KGDB
  166. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  167. return;
  168. #endif
  169. printf ("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  170. regs->nip, regs->msr, regs->trap);
  171. _exception (0, regs);
  172. }
  173. #ifdef CONFIG_CMD_BEDBUG
  174. extern void do_bedbug_breakpoint (struct pt_regs *);
  175. #endif
  176. void
  177. DebugException (struct pt_regs *regs)
  178. {
  179. printf ("Debugger trap at @ %lx\n", regs->nip );
  180. show_regs (regs);
  181. #ifdef CONFIG_CMD_BEDBUG
  182. do_bedbug_breakpoint (regs);
  183. #endif
  184. }