traps.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * linux/arch/ppc/kernel/traps.c
  3. *
  4. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  5. *
  6. * Modified by Cort Dougan (cort@cs.nmt.edu)
  7. * and Paul Mackerras (paulus@cs.anu.edu.au)
  8. * fixed Machine Check Reasons by Reinhard Meyer (r.meyer@emk-elektronik.de)
  9. *
  10. * (C) Copyright 2000-2003
  11. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  12. *
  13. * See file CREDITS for list of people who contributed to this
  14. * project.
  15. *
  16. * This program is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU General Public License as
  18. * published by the Free Software Foundation; either version 2 of
  19. * the License, or (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  29. * MA 02111-1307 USA
  30. */
  31. /*
  32. * This file handles the architecture-dependent parts of hardware exceptions
  33. */
  34. #include <common.h>
  35. #include <command.h>
  36. #include <asm/processor.h>
  37. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  38. int (*debugger_exception_handler)(struct pt_regs *) = 0;
  39. #endif
  40. /* Returns 0 if exception not found and fixup otherwise. */
  41. extern unsigned long search_exception_table(unsigned long);
  42. /* THIS NEEDS CHANGING to use the board info structure.
  43. */
  44. #define END_OF_MEM 0x02000000
  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) break;
  62. sp = (unsigned long *)*sp;
  63. }
  64. printf("\n");
  65. }
  66. void show_regs(struct pt_regs * regs)
  67. {
  68. int i;
  69. printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
  70. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  71. printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
  72. regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
  73. regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
  74. regs->msr&MSR_IR ? 1 : 0,
  75. regs->msr&MSR_DR ? 1 : 0);
  76. printf("\n");
  77. for (i = 0; i < 32; i++) {
  78. if ((i % 8) == 0)
  79. {
  80. printf("GPR%02d: ", i);
  81. }
  82. printf("%08lX ", regs->gpr[i]);
  83. if ((i % 8) == 7)
  84. {
  85. printf("\n");
  86. }
  87. }
  88. }
  89. void
  90. _exception(int signr, struct pt_regs *regs)
  91. {
  92. show_regs(regs);
  93. print_backtrace((unsigned long *)regs->gpr[1]);
  94. panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
  95. }
  96. void
  97. MachineCheckException(struct pt_regs *regs)
  98. {
  99. unsigned long fixup;
  100. /* Probing PCI using config cycles cause this exception
  101. * when a device is not present. Catch it and return to
  102. * the PCI exception handler.
  103. */
  104. if ((fixup = search_exception_table(regs->nip)) != 0) {
  105. regs->nip = fixup;
  106. return;
  107. }
  108. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  109. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  110. return;
  111. #endif
  112. printf("Machine check in kernel mode.\n");
  113. printf("Caused by (from msr): ");
  114. printf("regs %p ",regs);
  115. /* refer to 603e Manual (MPC603EUM/AD), chapter 4.5.2.1 */
  116. switch( regs->msr & 0x000F0000)
  117. {
  118. case (0x80000000>>12) :
  119. printf("Machine check signal - probably due to mm fault\n"
  120. "with mmu off\n");
  121. break;
  122. case (0x80000000>>13) :
  123. printf("Transfer error ack signal\n");
  124. break;
  125. case (0x80000000>>14) :
  126. printf("Data parity signal\n");
  127. break;
  128. case (0x80000000>>15) :
  129. printf("Address parity signal\n");
  130. break;
  131. default:
  132. printf("Unknown values in msr\n");
  133. }
  134. show_regs(regs);
  135. print_backtrace((unsigned long *)regs->gpr[1]);
  136. panic("machine check");
  137. }
  138. void
  139. AlignmentException(struct pt_regs *regs)
  140. {
  141. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  142. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  143. return;
  144. #endif
  145. show_regs(regs);
  146. print_backtrace((unsigned long *)regs->gpr[1]);
  147. panic("Alignment Exception");
  148. }
  149. void
  150. ProgramCheckException(struct pt_regs *regs)
  151. {
  152. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  153. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  154. return;
  155. #endif
  156. show_regs(regs);
  157. print_backtrace((unsigned long *)regs->gpr[1]);
  158. panic("Program Check Exception");
  159. }
  160. void
  161. SoftEmuException(struct pt_regs *regs)
  162. {
  163. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  164. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  165. return;
  166. #endif
  167. show_regs(regs);
  168. print_backtrace((unsigned long *)regs->gpr[1]);
  169. panic("Software Emulation Exception");
  170. }
  171. void
  172. UnknownException(struct pt_regs *regs)
  173. {
  174. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  175. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  176. return;
  177. #endif
  178. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  179. regs->nip, regs->msr, regs->trap);
  180. _exception(0, regs);
  181. }
  182. #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
  183. extern void do_bedbug_breakpoint(struct pt_regs *);
  184. #endif
  185. void
  186. DebugException(struct pt_regs *regs)
  187. {
  188. printf("Debugger trap at @ %lx\n", regs->nip );
  189. show_regs(regs);
  190. #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
  191. do_bedbug_breakpoint( regs );
  192. #endif
  193. }
  194. /* Probe an address by reading. If not present, return -1, otherwise
  195. * return 0.
  196. */
  197. int
  198. addr_probe(uint *addr)
  199. {
  200. #if 0
  201. int retval;
  202. __asm__ __volatile__( \
  203. "1: lwz %0,0(%1)\n" \
  204. " eieio\n" \
  205. " li %0,0\n" \
  206. "2:\n" \
  207. ".section .fixup,\"ax\"\n" \
  208. "3: li %0,-1\n" \
  209. " b 2b\n" \
  210. ".section __ex_table,\"a\"\n" \
  211. " .align 2\n" \
  212. " .long 1b,3b\n" \
  213. ".text" \
  214. : "=r" (retval) : "r"(addr));
  215. return (retval);
  216. #endif
  217. return 0;
  218. }