traps.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. static void 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. static void _exception(int signr, struct pt_regs *regs)
  82. {
  83. show_regs(regs);
  84. print_backtrace((unsigned long *)regs->gpr[1]);
  85. panic("Exception at pc %lx signal %d", regs->nip, signr);
  86. }
  87. void MachineCheckException(struct pt_regs *regs)
  88. {
  89. unsigned long fixup = search_exception_table(regs->nip);
  90. if (fixup) {
  91. regs->nip = fixup;
  92. return;
  93. }
  94. #ifdef CONFIG_CMD_KGDB
  95. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  96. return;
  97. #endif
  98. puts("Machine check.\nCaused by (from msr): ");
  99. printf("regs %p ", regs);
  100. switch (regs->msr & 0x00FF0000) {
  101. case (0x80000000 >> 10):
  102. puts("Instruction cache parity signal\n");
  103. break;
  104. case (0x80000000 >> 11):
  105. puts("Data cache parity signal\n");
  106. break;
  107. case (0x80000000 >> 12):
  108. puts("Machine check signal\n");
  109. break;
  110. case (0x80000000 >> 13):
  111. puts("Transfer error ack signal\n");
  112. break;
  113. case (0x80000000 >> 14):
  114. puts("Data parity signal\n");
  115. break;
  116. case (0x80000000 >> 15):
  117. puts("Address parity signal\n");
  118. break;
  119. default:
  120. puts("Unknown values in msr\n");
  121. }
  122. show_regs(regs);
  123. print_backtrace((unsigned long *)regs->gpr[1]);
  124. panic("machine check");
  125. }
  126. void AlignmentException(struct pt_regs *regs)
  127. {
  128. #ifdef CONFIG_CMD_KGDB
  129. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  130. return;
  131. #endif
  132. show_regs(regs);
  133. print_backtrace((unsigned long *)regs->gpr[1]);
  134. panic("Alignment Exception");
  135. }
  136. void ProgramCheckException(struct pt_regs *regs)
  137. {
  138. #ifdef CONFIG_CMD_KGDB
  139. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  140. return;
  141. #endif
  142. show_regs(regs);
  143. print_backtrace((unsigned long *)regs->gpr[1]);
  144. panic("Program Check Exception");
  145. }
  146. void SoftEmuException(struct pt_regs *regs)
  147. {
  148. #ifdef CONFIG_CMD_KGDB
  149. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  150. return;
  151. #endif
  152. show_regs(regs);
  153. print_backtrace((unsigned long *)regs->gpr[1]);
  154. panic("Software Emulation Exception");
  155. }
  156. void 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 DebugException(struct pt_regs *regs)
  170. {
  171. printf("Debugger trap at @ %lx\n", regs->nip);
  172. show_regs(regs);
  173. #ifdef CONFIG_CMD_BEDBUG
  174. do_bedbug_breakpoint(regs);
  175. #endif
  176. }