traps.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 <asm/processor.h>
  34. DECLARE_GLOBAL_DATA_PTR;
  35. /* Returns 0 if exception not found and fixup otherwise. */
  36. extern unsigned long search_exception_table(unsigned long);
  37. /*
  38. * End of addressable memory. This may be less than the actual
  39. * amount of memory on the system if we're unable to keep all
  40. * the memory mapped in.
  41. */
  42. extern ulong get_effective_memsize(void);
  43. #define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize())
  44. /*
  45. * Trap & Exception support
  46. */
  47. void
  48. print_backtrace(unsigned long *sp)
  49. {
  50. int cnt = 0;
  51. unsigned long i;
  52. printf("Call backtrace: ");
  53. while (sp) {
  54. if ((uint) sp > END_OF_MEM)
  55. break;
  56. i = sp[1];
  57. if (cnt++ % 7 == 0)
  58. printf("\n");
  59. printf("%08lX ", i);
  60. if (cnt > 32)
  61. break;
  62. sp = (unsigned long *)*sp;
  63. }
  64. printf("\n");
  65. }
  66. void
  67. show_regs(struct pt_regs *regs)
  68. {
  69. int i;
  70. printf("NIP: %08lX XER: %08lX LR: %08lX REGS:"
  71. " %p TRAP: %04lx DAR: %08lX\n",
  72. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  73. printf("MSR: %08lx EE: %01x PR: %01x FP:"
  74. " %01x ME: %01x IR/DR: %01x%01x\n",
  75. regs->msr, regs->msr & MSR_EE ? 1 : 0,
  76. regs->msr & MSR_PR ? 1 : 0, regs->msr & MSR_FP ? 1 : 0,
  77. regs->msr & MSR_ME ? 1 : 0, regs->msr & MSR_IR ? 1 : 0,
  78. regs->msr & MSR_DR ? 1 : 0);
  79. printf("\n");
  80. for (i = 0; i < 32; i++) {
  81. if ((i % 8) == 0) {
  82. printf("GPR%02d: ", i);
  83. }
  84. printf("%08lX ", regs->gpr[i]);
  85. if ((i % 8) == 7) {
  86. printf("\n");
  87. }
  88. }
  89. }
  90. void
  91. _exception(int signr, struct pt_regs *regs)
  92. {
  93. show_regs(regs);
  94. print_backtrace((unsigned long *)regs->gpr[1]);
  95. panic("Exception in kernel pc %lx signal %d", regs->nip, signr);
  96. }
  97. void
  98. MachineCheckException(struct pt_regs *regs)
  99. {
  100. unsigned long fixup;
  101. /* Probing PCI using config cycles cause this exception
  102. * when a device is not present. Catch it and return to
  103. * the PCI exception handler.
  104. */
  105. if ((fixup = search_exception_table(regs->nip)) != 0) {
  106. regs->nip = fixup;
  107. return;
  108. }
  109. #if defined(CONFIG_CMD_KGDB)
  110. if (debugger_exception_handler && (*debugger_exception_handler) (regs))
  111. return;
  112. #endif
  113. printf("Machine check in kernel mode.\n");
  114. printf("Caused by (from msr): ");
  115. printf("regs %p ", regs);
  116. switch ( regs->msr & 0x001F0000) {
  117. case (0x80000000>>11):
  118. printf("MSS error. MSSSR0: %08x\n", mfspr(SPRN_MSSSR0));
  119. break;
  120. case (0x80000000>>12):
  121. printf("Machine check signal - probably due to mm fault\n"
  122. "with mmu off\n");
  123. break;
  124. case (0x80000000 >> 13):
  125. printf("Transfer error ack signal\n");
  126. break;
  127. case (0x80000000 >> 14):
  128. printf("Data parity signal\n");
  129. break;
  130. case (0x80000000 >> 15):
  131. printf("Address parity signal\n");
  132. break;
  133. default:
  134. printf("Unknown values in msr\n");
  135. }
  136. show_regs(regs);
  137. print_backtrace((unsigned long *)regs->gpr[1]);
  138. panic("machine check");
  139. }
  140. void
  141. AlignmentException(struct pt_regs *regs)
  142. {
  143. #if defined(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("Alignment Exception");
  150. }
  151. void
  152. ProgramCheckException(struct pt_regs *regs)
  153. {
  154. unsigned char *p = regs ? (unsigned char *)(regs->nip) : NULL;
  155. int i, j;
  156. #if defined(CONFIG_CMD_KGDB)
  157. if (debugger_exception_handler && (*debugger_exception_handler) (regs))
  158. return;
  159. #endif
  160. show_regs(regs);
  161. p = (unsigned char *)((unsigned long)p & 0xFFFFFFE0);
  162. p -= 32;
  163. for (i = 0; i < 256; i += 16) {
  164. printf("%08x: ", (unsigned int)p + i);
  165. for (j = 0; j < 16; j++) {
  166. printf("%02x ", p[i + j]);
  167. }
  168. printf("\n");
  169. }
  170. print_backtrace((unsigned long *)regs->gpr[1]);
  171. panic("Program Check Exception");
  172. }
  173. void
  174. SoftEmuException(struct pt_regs *regs)
  175. {
  176. #if defined(CONFIG_CMD_KGDB)
  177. if (debugger_exception_handler && (*debugger_exception_handler) (regs))
  178. return;
  179. #endif
  180. show_regs(regs);
  181. print_backtrace((unsigned long *)regs->gpr[1]);
  182. panic("Software Emulation Exception");
  183. }
  184. void
  185. UnknownException(struct pt_regs *regs)
  186. {
  187. #if defined(CONFIG_CMD_KGDB)
  188. if (debugger_exception_handler && (*debugger_exception_handler) (regs))
  189. return;
  190. #endif
  191. printf("UnknownException regs@%lx\n", (ulong)regs);
  192. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  193. regs->nip, regs->msr, regs->trap);
  194. _exception(0, regs);
  195. }
  196. /*
  197. * Probe an address by reading.
  198. * If not present, return -1,
  199. * otherwise return 0.
  200. */
  201. int
  202. addr_probe(uint *addr)
  203. {
  204. return 0;
  205. }