traps.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * linux/arch/powerpc/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. * SPDX-License-Identifier: GPL-2.0+
  13. */
  14. /*
  15. * This file handles the architecture-dependent parts of hardware exceptions
  16. */
  17. #include <common.h>
  18. #include <command.h>
  19. #include <kgdb.h>
  20. #include <asm/processor.h>
  21. #if defined(CONFIG_CMD_BEDBUG)
  22. extern void do_bedbug_breakpoint(struct pt_regs *);
  23. #endif
  24. /* Returns 0 if exception not found and fixup otherwise. */
  25. extern unsigned long search_exception_table(unsigned long);
  26. /* THIS NEEDS CHANGING to use the board info structure.
  27. */
  28. #define END_OF_MEM 0x0001000
  29. /*
  30. * Print stack backtrace
  31. */
  32. static void print_backtrace(unsigned long *sp)
  33. {
  34. int cnt = 0;
  35. unsigned long i;
  36. printf("Call backtrace: ");
  37. while (sp) {
  38. if ((uint)sp > END_OF_MEM)
  39. break;
  40. i = sp[1];
  41. if (cnt++ % 7 == 0)
  42. printf("\n");
  43. printf("%08lX ", i);
  44. if (cnt > 32) break;
  45. sp = (unsigned long *)*sp;
  46. }
  47. printf("\n");
  48. }
  49. /*
  50. * Print current registers
  51. */
  52. void show_regs(struct pt_regs *regs)
  53. {
  54. int i;
  55. printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
  56. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  57. printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
  58. regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
  59. regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
  60. regs->msr&MSR_IR ? 1 : 0,
  61. regs->msr&MSR_DR ? 1 : 0);
  62. printf("\n");
  63. for (i = 0; i < 32; i++) {
  64. if ((i % 8) == 0)
  65. {
  66. printf("GPR%02d: ", i);
  67. }
  68. printf("%08lX ", regs->gpr[i]);
  69. if ((i % 8) == 7)
  70. {
  71. printf("\n");
  72. }
  73. }
  74. }
  75. /*
  76. * General exception handler routine
  77. */
  78. static void _exception(int signr, struct pt_regs *regs)
  79. {
  80. show_regs(regs);
  81. print_backtrace((unsigned long *)regs->gpr[1]);
  82. panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
  83. }
  84. /*
  85. * Machine check exception handler routine
  86. */
  87. void MachineCheckException(struct pt_regs *regs)
  88. {
  89. unsigned long fixup;
  90. /* Probing PCI using config cycles cause this exception
  91. * when a device is not present. Catch it and return to
  92. * the PCI exception handler.
  93. */
  94. if ((fixup = search_exception_table(regs->nip)) != 0) {
  95. regs->nip = fixup;
  96. return;
  97. }
  98. #if defined(CONFIG_CMD_KGDB)
  99. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  100. return;
  101. #endif
  102. printf("Machine check in kernel mode.\n");
  103. printf("Caused by (from msr): ");
  104. printf("regs %p ",regs);
  105. switch( regs->msr & 0x000F0000) {
  106. case (0x80000000>>12):
  107. printf("Machine check signal\n");
  108. break;
  109. case (0x80000000>>13):
  110. printf("Transfer error ack signal\n");
  111. break;
  112. case (0x80000000>>14):
  113. printf("Data parity signal\n");
  114. break;
  115. case (0x80000000>>15):
  116. printf("Address parity signal\n");
  117. break;
  118. default:
  119. printf("Unknown values in msr\n");
  120. }
  121. show_regs(regs);
  122. print_backtrace((unsigned long *)regs->gpr[1]);
  123. panic("machine check");
  124. }
  125. /*
  126. * Alignment exception handler routine
  127. */
  128. void AlignmentException(struct pt_regs *regs)
  129. {
  130. #if defined(CONFIG_CMD_KGDB)
  131. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  132. return;
  133. #endif
  134. show_regs(regs);
  135. print_backtrace((unsigned long *)regs->gpr[1]);
  136. panic("Alignment Exception");
  137. }
  138. /*
  139. * Program check exception handler routine
  140. */
  141. void ProgramCheckException(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("Program Check Exception");
  150. }
  151. /*
  152. * Software emulation exception handler routine
  153. */
  154. void SoftEmuException(struct pt_regs *regs)
  155. {
  156. #if defined(CONFIG_CMD_KGDB)
  157. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  158. return;
  159. #endif
  160. show_regs(regs);
  161. print_backtrace((unsigned long *)regs->gpr[1]);
  162. panic("Software Emulation Exception");
  163. }
  164. /*
  165. * Unknown exception handler routine
  166. */
  167. void UnknownException(struct pt_regs *regs)
  168. {
  169. #if defined(CONFIG_CMD_KGDB)
  170. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  171. return;
  172. #endif
  173. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  174. regs->nip, regs->msr, regs->trap);
  175. _exception(0, regs);
  176. }
  177. /*
  178. * Debug exception handler routine
  179. */
  180. void DebugException(struct pt_regs *regs)
  181. {
  182. printf("Debugger trap at @ %lx\n", regs->nip );
  183. show_regs(regs);
  184. #if defined(CONFIG_CMD_BEDBUG)
  185. do_bedbug_breakpoint( regs );
  186. #endif
  187. }