traps.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * linux/arch/powerpc/kernel/traps.c
  4. *
  5. * Copyright 2007 Freescale Semiconductor.
  6. * Copyright (C) 2003 Motorola
  7. * Modified by Xianghua Xiao(x.xiao@motorola.com)
  8. *
  9. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  10. *
  11. * Modified by Cort Dougan (cort@cs.nmt.edu)
  12. * and Paul Mackerras (paulus@cs.anu.edu.au)
  13. *
  14. * (C) Copyright 2000
  15. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  16. */
  17. /*
  18. * This file handles the architecture-dependent parts of hardware exceptions
  19. */
  20. #include <common.h>
  21. #include <command.h>
  22. #include <kgdb.h>
  23. #include <asm/processor.h>
  24. DECLARE_GLOBAL_DATA_PTR;
  25. /* Returns 0 if exception not found and fixup otherwise. */
  26. extern unsigned long search_exception_table(unsigned long);
  27. /*
  28. * End of addressable memory. This may be less than the actual
  29. * amount of memory on the system if we're unable to keep all
  30. * the memory mapped in.
  31. */
  32. #define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize())
  33. static __inline__ void set_tsr(unsigned long val)
  34. {
  35. asm volatile("mtspr 0x150, %0" : : "r" (val));
  36. }
  37. static __inline__ unsigned long get_esr(void)
  38. {
  39. unsigned long val;
  40. asm volatile("mfspr %0, 0x03e" : "=r" (val) :);
  41. return val;
  42. }
  43. #define ESR_MCI 0x80000000
  44. #define ESR_PIL 0x08000000
  45. #define ESR_PPR 0x04000000
  46. #define ESR_PTR 0x02000000
  47. #define ESR_DST 0x00800000
  48. #define ESR_DIZ 0x00400000
  49. #define ESR_U0F 0x00008000
  50. #if defined(CONFIG_CMD_BEDBUG)
  51. extern void do_bedbug_breakpoint(struct pt_regs *);
  52. #endif
  53. /*
  54. * Trap & Exception support
  55. */
  56. static void print_backtrace(unsigned long *sp)
  57. {
  58. int cnt = 0;
  59. unsigned long i;
  60. printf("Call backtrace: ");
  61. while (sp) {
  62. if ((uint)sp > END_OF_MEM)
  63. break;
  64. i = sp[1];
  65. if (cnt++ % 7 == 0)
  66. printf("\n");
  67. printf("%08lX ", i);
  68. if (cnt > 32) break;
  69. sp = (unsigned long *)*sp;
  70. }
  71. printf("\n");
  72. }
  73. void show_regs(struct pt_regs *regs)
  74. {
  75. int i;
  76. printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
  77. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  78. printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
  79. regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
  80. regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
  81. regs->msr&MSR_IR ? 1 : 0,
  82. regs->msr&MSR_DR ? 1 : 0);
  83. printf("\n");
  84. for (i = 0; i < 32; i++) {
  85. if ((i % 8) == 0)
  86. {
  87. printf("GPR%02d: ", i);
  88. }
  89. printf("%08lX ", regs->gpr[i]);
  90. if ((i % 8) == 7)
  91. {
  92. printf("\n");
  93. }
  94. }
  95. }
  96. static 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. void CritcalInputException(struct pt_regs *regs)
  103. {
  104. panic("Critical Input Exception");
  105. }
  106. int machinecheck_count = 0;
  107. int machinecheck_error = 0;
  108. void MachineCheckException(struct pt_regs *regs)
  109. {
  110. unsigned long fixup;
  111. unsigned int mcsr, mcsrr0, mcsrr1, mcar;
  112. /* Probing PCI using config cycles cause this exception
  113. * when a device is not present. Catch it and return to
  114. * the PCI exception handler.
  115. */
  116. if ((fixup = search_exception_table(regs->nip)) != 0) {
  117. regs->nip = fixup;
  118. return;
  119. }
  120. mcsrr0 = mfspr(SPRN_MCSRR0);
  121. mcsrr1 = mfspr(SPRN_MCSRR1);
  122. mcsr = mfspr(SPRN_MCSR);
  123. mcar = mfspr(SPRN_MCAR);
  124. machinecheck_count++;
  125. machinecheck_error=1;
  126. #if defined(CONFIG_CMD_KGDB)
  127. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  128. return;
  129. #endif
  130. printf("Machine check in kernel mode.\n");
  131. printf("Caused by (from mcsr): ");
  132. printf("mcsr = 0x%08x\n", mcsr);
  133. if (mcsr & 0x80000000)
  134. printf("Machine check input pin\n");
  135. if (mcsr & 0x40000000)
  136. printf("Instruction cache parity error\n");
  137. if (mcsr & 0x20000000)
  138. printf("Data cache push parity error\n");
  139. if (mcsr & 0x10000000)
  140. printf("Data cache parity error\n");
  141. if (mcsr & 0x00000080)
  142. printf("Bus instruction address error\n");
  143. if (mcsr & 0x00000040)
  144. printf("Bus Read address error\n");
  145. if (mcsr & 0x00000020)
  146. printf("Bus Write address error\n");
  147. if (mcsr & 0x00000010)
  148. printf("Bus Instruction data bus error\n");
  149. if (mcsr & 0x00000008)
  150. printf("Bus Read data bus error\n");
  151. if (mcsr & 0x00000004)
  152. printf("Bus Write bus error\n");
  153. if (mcsr & 0x00000002)
  154. printf("Bus Instruction parity error\n");
  155. if (mcsr & 0x00000001)
  156. printf("Bus Read parity error\n");
  157. show_regs(regs);
  158. printf("MCSR=0x%08x \tMCSRR0=0x%08x \nMCSRR1=0x%08x \tMCAR=0x%08x\n",
  159. mcsr, mcsrr0, mcsrr1, mcar);
  160. print_backtrace((unsigned long *)regs->gpr[1]);
  161. if (machinecheck_count > 10) {
  162. panic("machine check count too high\n");
  163. }
  164. if (machinecheck_count > 1) {
  165. regs->nip += 4; /* skip offending instruction */
  166. printf("Skipping current instr, Returning to 0x%08lx\n",
  167. regs->nip);
  168. } else {
  169. printf("Returning back to 0x%08lx\n",regs->nip);
  170. }
  171. }
  172. void AlignmentException(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("Alignment Exception");
  181. }
  182. void ProgramCheckException(struct pt_regs *regs)
  183. {
  184. long esr_val;
  185. #if defined(CONFIG_CMD_KGDB)
  186. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  187. return;
  188. #endif
  189. show_regs(regs);
  190. esr_val = get_esr();
  191. if( esr_val & ESR_PIL )
  192. printf( "** Illegal Instruction **\n" );
  193. else if( esr_val & ESR_PPR )
  194. printf( "** Privileged Instruction **\n" );
  195. else if( esr_val & ESR_PTR )
  196. printf( "** Trap Instruction **\n" );
  197. print_backtrace((unsigned long *)regs->gpr[1]);
  198. panic("Program Check Exception");
  199. }
  200. void PITException(struct pt_regs *regs)
  201. {
  202. /*
  203. * Reset PIT interrupt
  204. */
  205. set_tsr(0x0c000000);
  206. /*
  207. * Call timer_interrupt routine in interrupts.c
  208. */
  209. timer_interrupt(NULL);
  210. }
  211. void UnknownException(struct pt_regs *regs)
  212. {
  213. #if defined(CONFIG_CMD_KGDB)
  214. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  215. return;
  216. #endif
  217. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  218. regs->nip, regs->msr, regs->trap);
  219. _exception(0, regs);
  220. }
  221. void ExtIntException(struct pt_regs *regs)
  222. {
  223. volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
  224. uint vect;
  225. #if defined(CONFIG_CMD_KGDB)
  226. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  227. return;
  228. #endif
  229. printf("External Interrupt Exception at PC: %lx, SR: %lx, vector=%lx",
  230. regs->nip, regs->msr, regs->trap);
  231. vect = pic->iack0;
  232. printf(" irq IACK0@%05x=%d\n",(int)&pic->iack0,vect);
  233. show_regs(regs);
  234. print_backtrace((unsigned long *)regs->gpr[1]);
  235. }
  236. void DebugException(struct pt_regs *regs)
  237. {
  238. printf("Debugger trap at @ %lx\n", regs->nip );
  239. show_regs(regs);
  240. #if defined(CONFIG_CMD_BEDBUG)
  241. do_bedbug_breakpoint( regs );
  242. #endif
  243. }