traps.c 5.5 KB

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