traps.c 6.8 KB

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