traps.c 4.6 KB

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