traps.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 0x02000000
  29. /*
  30. * Trap & Exception support
  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. void show_regs(struct pt_regs *regs)
  50. {
  51. int i;
  52. printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
  53. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  54. printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
  55. regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
  56. regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
  57. regs->msr&MSR_IR ? 1 : 0,
  58. regs->msr&MSR_DR ? 1 : 0);
  59. printf("\n");
  60. for (i = 0; i < 32; i++) {
  61. if ((i % 8) == 0)
  62. {
  63. printf("GPR%02d: ", i);
  64. }
  65. printf("%08lX ", regs->gpr[i]);
  66. if ((i % 8) == 7)
  67. {
  68. printf("\n");
  69. }
  70. }
  71. }
  72. static void _exception(int signr, struct pt_regs *regs)
  73. {
  74. show_regs(regs);
  75. print_backtrace((unsigned long *)regs->gpr[1]);
  76. panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
  77. }
  78. void MachineCheckException(struct pt_regs *regs)
  79. {
  80. unsigned long fixup;
  81. /* Probing PCI using config cycles cause this exception
  82. * when a device is not present. Catch it and return to
  83. * the PCI exception handler.
  84. */
  85. if ((fixup = search_exception_table(regs->nip)) != 0) {
  86. regs->nip = fixup;
  87. return;
  88. }
  89. #if defined(CONFIG_CMD_KGDB)
  90. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  91. return;
  92. #endif
  93. printf("Machine check in kernel mode.\n");
  94. printf("Caused by (from msr): ");
  95. printf("regs %p ",regs);
  96. switch( regs->msr & 0x000F0000) {
  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. void DebugException(struct pt_regs *regs)
  158. {
  159. printf("Debugger trap at @ %lx\n", regs->nip );
  160. show_regs(regs);
  161. #if defined(CONFIG_CMD_BEDBUG)
  162. do_bedbug_breakpoint( regs );
  163. #endif
  164. }
  165. /* Probe an address by reading. If not present, return -1, otherwise
  166. * return 0.
  167. */
  168. int addr_probe(uint *addr)
  169. {
  170. #if 0
  171. int retval;
  172. __asm__ __volatile__( \
  173. "1: lwz %0,0(%1)\n" \
  174. " eieio\n" \
  175. " li %0,0\n" \
  176. "2:\n" \
  177. ".section .fixup,\"ax\"\n" \
  178. "3: li %0,-1\n" \
  179. " b 2b\n" \
  180. ".section __ex_table,\"a\"\n" \
  181. " .align 2\n" \
  182. " .long 1b,3b\n" \
  183. ".text" \
  184. : "=r" (retval) : "r"(addr));
  185. return (retval);
  186. #endif
  187. return 0;
  188. }