traps.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. *
  9. * (C) Copyright 2000
  10. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  11. *
  12. * See file CREDITS for list of people who contributed to this
  13. * project.
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License as
  17. * published by the Free Software Foundation; either version 2 of
  18. * the License, or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  28. * MA 02111-1307 USA
  29. */
  30. /*
  31. * This file handles the architecture-dependent parts of hardware exceptions
  32. */
  33. #include <common.h>
  34. #include <command.h>
  35. #include <asm/processor.h>
  36. #if defined(CONFIG_CMD_KGDB)
  37. int (*debugger_exception_handler)(struct pt_regs *) = 0;
  38. #endif
  39. #if defined(CONFIG_CMD_BEDBUG)
  40. extern void do_bedbug_breakpoint(struct pt_regs *);
  41. #endif
  42. /* Returns 0 if exception not found and fixup otherwise. */
  43. extern unsigned long search_exception_table(unsigned long);
  44. /* THIS NEEDS CHANGING to use the board info structure.
  45. */
  46. #define END_OF_MEM 0x0001000
  47. /*
  48. * Print stack backtrace
  49. */
  50. void print_backtrace(unsigned long *sp)
  51. {
  52. int cnt = 0;
  53. unsigned long i;
  54. printf("Call backtrace: ");
  55. while (sp) {
  56. if ((uint)sp > END_OF_MEM)
  57. break;
  58. i = sp[1];
  59. if (cnt++ % 7 == 0)
  60. printf("\n");
  61. printf("%08lX ", i);
  62. if (cnt > 32) break;
  63. sp = (unsigned long *)*sp;
  64. }
  65. printf("\n");
  66. }
  67. /*
  68. * Print current registers
  69. */
  70. void show_regs(struct pt_regs * regs)
  71. {
  72. int i;
  73. printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
  74. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  75. printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
  76. regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
  77. regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
  78. 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. {
  84. printf("GPR%02d: ", i);
  85. }
  86. printf("%08lX ", regs->gpr[i]);
  87. if ((i % 8) == 7)
  88. {
  89. printf("\n");
  90. }
  91. }
  92. }
  93. /*
  94. * General exception handler routine
  95. */
  96. void _exception(int signr, struct pt_regs *regs)
  97. {
  98. show_regs(regs);
  99. print_backtrace((unsigned long *)regs->gpr[1]);
  100. panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
  101. }
  102. /*
  103. * Machine check exception handler routine
  104. */
  105. void MachineCheckException(struct pt_regs *regs)
  106. {
  107. unsigned long fixup;
  108. /* Probing PCI using config cycles cause this exception
  109. * when a device is not present. Catch it and return to
  110. * the PCI exception handler.
  111. */
  112. if ((fixup = search_exception_table(regs->nip)) != 0) {
  113. regs->nip = fixup;
  114. return;
  115. }
  116. #if defined(CONFIG_CMD_KGDB)
  117. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  118. return;
  119. #endif
  120. printf("Machine check in kernel mode.\n");
  121. printf("Caused by (from msr): ");
  122. printf("regs %p ",regs);
  123. switch( regs->msr & 0x000F0000) {
  124. case (0x80000000>>12):
  125. printf("Machine check signal\n");
  126. break;
  127. case (0x80000000>>13):
  128. printf("Transfer error ack signal\n");
  129. break;
  130. case (0x80000000>>14):
  131. printf("Data parity signal\n");
  132. break;
  133. case (0x80000000>>15):
  134. printf("Address parity signal\n");
  135. break;
  136. default:
  137. printf("Unknown values in msr\n");
  138. }
  139. show_regs(regs);
  140. print_backtrace((unsigned long *)regs->gpr[1]);
  141. panic("machine check");
  142. }
  143. /*
  144. * Alignment exception handler routine
  145. */
  146. void AlignmentException(struct pt_regs *regs)
  147. {
  148. #if defined(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("Alignment Exception");
  155. }
  156. /*
  157. * Program check exception handler routine
  158. */
  159. void ProgramCheckException(struct pt_regs *regs)
  160. {
  161. #if defined(CONFIG_CMD_KGDB)
  162. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  163. return;
  164. #endif
  165. show_regs(regs);
  166. print_backtrace((unsigned long *)regs->gpr[1]);
  167. panic("Program Check Exception");
  168. }
  169. /*
  170. * Software emulation exception handler routine
  171. */
  172. void SoftEmuException(struct pt_regs *regs)
  173. {
  174. #if defined(CONFIG_CMD_KGDB)
  175. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  176. return;
  177. #endif
  178. show_regs(regs);
  179. print_backtrace((unsigned long *)regs->gpr[1]);
  180. panic("Software Emulation Exception");
  181. }
  182. /*
  183. * Unknown exception handler routine
  184. */
  185. void 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("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  192. regs->nip, regs->msr, regs->trap);
  193. _exception(0, regs);
  194. }
  195. /*
  196. * Debug exception handler routine
  197. */
  198. void DebugException(struct pt_regs *regs)
  199. {
  200. printf("Debugger trap at @ %lx\n", regs->nip );
  201. show_regs(regs);
  202. #if defined(CONFIG_CMD_BEDBUG)
  203. do_bedbug_breakpoint( regs );
  204. #endif
  205. }