traps.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 <asm/processor.h>
  30. DECLARE_GLOBAL_DATA_PTR;
  31. extern unsigned long search_exception_table(unsigned long);
  32. /*
  33. * End of addressable memory. This may be less than the actual
  34. * amount of memory on the system if we're unable to keep all
  35. * the memory mapped in.
  36. */
  37. extern ulong get_effective_memsize(void);
  38. #define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize())
  39. /*
  40. * Trap & Exception support
  41. */
  42. void
  43. print_backtrace (unsigned long *sp)
  44. {
  45. int cnt = 0;
  46. unsigned long i;
  47. puts ("Call backtrace: ");
  48. while (sp) {
  49. if ((uint)sp > END_OF_MEM)
  50. break;
  51. i = sp[1];
  52. if (cnt++ % 7 == 0)
  53. putc ('\n');
  54. printf ("%08lX ", i);
  55. if (cnt > 32) break;
  56. sp = (unsigned long *) *sp;
  57. }
  58. putc ('\n');
  59. }
  60. void show_regs (struct pt_regs * regs)
  61. {
  62. int i;
  63. printf ("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
  64. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  65. printf ("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
  66. regs->msr, regs->msr & MSR_EE ? 1 : 0, regs->msr & MSR_PR ? 1 : 0,
  67. regs->msr & MSR_FP ? 1 : 0,regs->msr & MSR_ME ? 1 : 0,
  68. regs->msr & MSR_IR ? 1 : 0,
  69. regs->msr & MSR_DR ? 1 : 0);
  70. putc ('\n');
  71. for (i = 0; i < 32; i++) {
  72. if ((i % 8) == 0) {
  73. printf ("GPR%02d: ", i);
  74. }
  75. printf ("%08lX ", regs->gpr[i]);
  76. if ((i % 8) == 7) {
  77. putc ('\n');
  78. }
  79. }
  80. }
  81. void
  82. _exception (int signr, struct pt_regs *regs)
  83. {
  84. show_regs (regs);
  85. print_backtrace ((unsigned long *)regs->gpr[1]);
  86. panic ("Exception at pc %lx signal %d", regs->nip,signr);
  87. }
  88. void
  89. MachineCheckException (struct pt_regs *regs)
  90. {
  91. unsigned long fixup;
  92. if ((fixup = search_exception_table (regs->nip)) != 0) {
  93. regs->nip = fixup;
  94. return;
  95. }
  96. #ifdef CONFIG_CMD_KGDB
  97. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  98. return;
  99. #endif
  100. puts ("Machine check.\nCaused by (from msr): ");
  101. printf ("regs %p ",regs);
  102. switch (regs->msr & 0x00FF0000) {
  103. case (0x80000000 >> 10):
  104. puts ("Instruction cache parity signal\n");
  105. break;
  106. case (0x80000000 >> 11):
  107. puts ("Data cache parity signal\n");
  108. break;
  109. case (0x80000000 >> 12):
  110. puts ("Machine check signal\n");
  111. break;
  112. case (0x80000000 >> 13):
  113. puts ("Transfer error ack signal\n");
  114. break;
  115. case (0x80000000 >> 14):
  116. puts ("Data parity signal\n");
  117. break;
  118. case (0x80000000 >> 15):
  119. puts ("Address parity signal\n");
  120. break;
  121. default:
  122. puts ("Unknown values in msr\n");
  123. }
  124. show_regs (regs);
  125. print_backtrace ((unsigned long *)regs->gpr[1]);
  126. panic ("machine check");
  127. }
  128. void
  129. AlignmentException (struct pt_regs *regs)
  130. {
  131. #ifdef CONFIG_CMD_KGDB
  132. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  133. return;
  134. #endif
  135. show_regs (regs);
  136. print_backtrace ((unsigned long *)regs->gpr[1]);
  137. panic ("Alignment Exception");
  138. }
  139. void
  140. ProgramCheckException (struct pt_regs *regs)
  141. {
  142. #ifdef CONFIG_CMD_KGDB
  143. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  144. return;
  145. #endif
  146. show_regs (regs);
  147. print_backtrace ((unsigned long *)regs->gpr[1]);
  148. panic ("Program Check Exception");
  149. }
  150. void
  151. SoftEmuException (struct pt_regs *regs)
  152. {
  153. #ifdef CONFIG_CMD_KGDB
  154. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  155. return;
  156. #endif
  157. show_regs (regs);
  158. print_backtrace ((unsigned long *)regs->gpr[1]);
  159. panic ("Software Emulation Exception");
  160. }
  161. void
  162. UnknownException (struct pt_regs *regs)
  163. {
  164. #ifdef CONFIG_CMD_KGDB
  165. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  166. return;
  167. #endif
  168. printf ("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  169. regs->nip, regs->msr, regs->trap);
  170. _exception (0, regs);
  171. }
  172. #ifdef CONFIG_CMD_BEDBUG
  173. extern void do_bedbug_breakpoint (struct pt_regs *);
  174. #endif
  175. void
  176. DebugException (struct pt_regs *regs)
  177. {
  178. printf ("Debugger trap at @ %lx\n", regs->nip );
  179. show_regs (regs);
  180. #ifdef CONFIG_CMD_BEDBUG
  181. do_bedbug_breakpoint (regs);
  182. #endif
  183. }