traps.c 4.8 KB

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