traps.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*
  2. * linux/arch/ppc/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. * See file CREDITS for list of people who contributed to this
  17. * project.
  18. *
  19. * This program is free software; you can redistribute it and/or
  20. * modify it under the terms of the GNU General Public License as
  21. * published by the Free Software Foundation; either version 2 of
  22. * the License, or (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program; if not, write to the Free Software
  31. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  32. * MA 02111-1307 USA
  33. */
  34. /*
  35. * This file handles the architecture-dependent parts of hardware exceptions
  36. */
  37. #include <common.h>
  38. #include <command.h>
  39. #include <asm/processor.h>
  40. DECLARE_GLOBAL_DATA_PTR;
  41. #if defined(CONFIG_CMD_KGDB)
  42. int (*debugger_exception_handler)(struct pt_regs *) = 0;
  43. #endif
  44. /* Returns 0 if exception not found and fixup otherwise. */
  45. extern unsigned long search_exception_table(unsigned long);
  46. /*
  47. * End of addressable memory. This may be less than the actual
  48. * amount of memory on the system if we're unable to keep all
  49. * the memory mapped in.
  50. */
  51. extern ulong get_effective_memsize(void);
  52. #define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize())
  53. static __inline__ void set_tsr(unsigned long val)
  54. {
  55. asm volatile("mtspr 0x150, %0" : : "r" (val));
  56. }
  57. static __inline__ unsigned long get_esr(void)
  58. {
  59. unsigned long val;
  60. asm volatile("mfspr %0, 0x03e" : "=r" (val) :);
  61. return val;
  62. }
  63. #define ESR_MCI 0x80000000
  64. #define ESR_PIL 0x08000000
  65. #define ESR_PPR 0x04000000
  66. #define ESR_PTR 0x02000000
  67. #define ESR_DST 0x00800000
  68. #define ESR_DIZ 0x00400000
  69. #define ESR_U0F 0x00008000
  70. #if defined(CONFIG_CMD_BEDBUG)
  71. extern void do_bedbug_breakpoint(struct pt_regs *);
  72. #endif
  73. /*
  74. * Trap & Exception support
  75. */
  76. void
  77. print_backtrace(unsigned long *sp)
  78. {
  79. int cnt = 0;
  80. unsigned long i;
  81. printf("Call backtrace: ");
  82. while (sp) {
  83. if ((uint)sp > END_OF_MEM)
  84. break;
  85. i = sp[1];
  86. if (cnt++ % 7 == 0)
  87. printf("\n");
  88. printf("%08lX ", i);
  89. if (cnt > 32) break;
  90. sp = (unsigned long *)*sp;
  91. }
  92. printf("\n");
  93. }
  94. void show_regs(struct pt_regs * regs)
  95. {
  96. int i;
  97. printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
  98. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  99. printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
  100. regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
  101. regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
  102. regs->msr&MSR_IR ? 1 : 0,
  103. regs->msr&MSR_DR ? 1 : 0);
  104. printf("\n");
  105. for (i = 0; i < 32; i++) {
  106. if ((i % 8) == 0)
  107. {
  108. printf("GPR%02d: ", i);
  109. }
  110. printf("%08lX ", regs->gpr[i]);
  111. if ((i % 8) == 7)
  112. {
  113. printf("\n");
  114. }
  115. }
  116. }
  117. void
  118. _exception(int signr, struct pt_regs *regs)
  119. {
  120. show_regs(regs);
  121. print_backtrace((unsigned long *)regs->gpr[1]);
  122. panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
  123. }
  124. void
  125. CritcalInputException(struct pt_regs *regs)
  126. {
  127. panic("Critical Input Exception");
  128. }
  129. int machinecheck_count = 0;
  130. int machinecheck_error = 0;
  131. void
  132. MachineCheckException(struct pt_regs *regs)
  133. {
  134. unsigned long fixup;
  135. unsigned int mcsr, mcsrr0, mcsrr1, mcar;
  136. /* Probing PCI using config cycles cause this exception
  137. * when a device is not present. Catch it and return to
  138. * the PCI exception handler.
  139. */
  140. if ((fixup = search_exception_table(regs->nip)) != 0) {
  141. regs->nip = fixup;
  142. return;
  143. }
  144. mcsrr0 = mfspr(SPRN_MCSRR0);
  145. mcsrr1 = mfspr(SPRN_MCSRR1);
  146. mcsr = mfspr(SPRN_MCSR);
  147. mcar = mfspr(SPRN_MCAR);
  148. machinecheck_count++;
  149. machinecheck_error=1;
  150. #if defined(CONFIG_CMD_KGDB)
  151. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  152. return;
  153. #endif
  154. printf("Machine check in kernel mode.\n");
  155. printf("Caused by (from mcsr): ");
  156. printf("mcsr = 0x%08x\n", mcsr);
  157. if (mcsr & 0x80000000)
  158. printf("Machine check input pin\n");
  159. if (mcsr & 0x40000000)
  160. printf("Instruction cache parity error\n");
  161. if (mcsr & 0x20000000)
  162. printf("Data cache push parity error\n");
  163. if (mcsr & 0x10000000)
  164. printf("Data cache parity error\n");
  165. if (mcsr & 0x00000080)
  166. printf("Bus instruction address error\n");
  167. if (mcsr & 0x00000040)
  168. printf("Bus Read address error\n");
  169. if (mcsr & 0x00000020)
  170. printf("Bus Write address error\n");
  171. if (mcsr & 0x00000010)
  172. printf("Bus Instruction data bus error\n");
  173. if (mcsr & 0x00000008)
  174. printf("Bus Read data bus error\n");
  175. if (mcsr & 0x00000004)
  176. printf("Bus Write bus error\n");
  177. if (mcsr & 0x00000002)
  178. printf("Bus Instruction parity error\n");
  179. if (mcsr & 0x00000001)
  180. printf("Bus Read parity error\n");
  181. show_regs(regs);
  182. printf("MCSR=0x%08x \tMCSRR0=0x%08x \nMCSRR1=0x%08x \tMCAR=0x%08x\n",
  183. mcsr, mcsrr0, mcsrr1, mcar);
  184. print_backtrace((unsigned long *)regs->gpr[1]);
  185. if (machinecheck_count > 10) {
  186. panic("machine check count too high\n");
  187. }
  188. if (machinecheck_count > 1) {
  189. regs->nip += 4; /* skip offending instruction */
  190. printf("Skipping current instr, Returning to 0x%08lx\n",
  191. regs->nip);
  192. } else {
  193. printf("Returning back to 0x%08lx\n",regs->nip);
  194. }
  195. }
  196. void
  197. AlignmentException(struct pt_regs *regs)
  198. {
  199. #if defined(CONFIG_CMD_KGDB)
  200. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  201. return;
  202. #endif
  203. show_regs(regs);
  204. print_backtrace((unsigned long *)regs->gpr[1]);
  205. panic("Alignment Exception");
  206. }
  207. void
  208. ProgramCheckException(struct pt_regs *regs)
  209. {
  210. long esr_val;
  211. #if defined(CONFIG_CMD_KGDB)
  212. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  213. return;
  214. #endif
  215. show_regs(regs);
  216. esr_val = get_esr();
  217. if( esr_val & ESR_PIL )
  218. printf( "** Illegal Instruction **\n" );
  219. else if( esr_val & ESR_PPR )
  220. printf( "** Privileged Instruction **\n" );
  221. else if( esr_val & ESR_PTR )
  222. printf( "** Trap Instruction **\n" );
  223. print_backtrace((unsigned long *)regs->gpr[1]);
  224. panic("Program Check Exception");
  225. }
  226. void
  227. PITException(struct pt_regs *regs)
  228. {
  229. /*
  230. * Reset PIT interrupt
  231. */
  232. set_tsr(0x0c000000);
  233. /*
  234. * Call timer_interrupt routine in interrupts.c
  235. */
  236. timer_interrupt(NULL);
  237. }
  238. void
  239. UnknownException(struct pt_regs *regs)
  240. {
  241. #if defined(CONFIG_CMD_KGDB)
  242. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  243. return;
  244. #endif
  245. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  246. regs->nip, regs->msr, regs->trap);
  247. _exception(0, regs);
  248. }
  249. void
  250. ExtIntException(struct pt_regs *regs)
  251. {
  252. volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
  253. uint vect;
  254. #if defined(CONFIG_CMD_KGDB)
  255. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  256. return;
  257. #endif
  258. printf("External Interrupt Exception at PC: %lx, SR: %lx, vector=%lx",
  259. regs->nip, regs->msr, regs->trap);
  260. vect = pic->iack0;
  261. printf(" irq IACK0@%05x=%d\n",(int)&pic->iack0,vect);
  262. show_regs(regs);
  263. print_backtrace((unsigned long *)regs->gpr[1]);
  264. machinecheck_count++;
  265. #ifdef EXTINT_NOSKIP
  266. printf("Returning back to 0x%08x\n",regs->nip);
  267. #else
  268. regs->nip += 4; /* skip offending instruction */
  269. printf("Skipping current instr, Returning to 0x%08lx\n",regs->nip);
  270. #endif
  271. }
  272. void
  273. DebugException(struct pt_regs *regs)
  274. {
  275. printf("Debugger trap at @ %lx\n", regs->nip );
  276. show_regs(regs);
  277. #if defined(CONFIG_CMD_BEDBUG)
  278. do_bedbug_breakpoint( regs );
  279. #endif
  280. }
  281. /* Probe an address by reading. If not present, return -1, otherwise
  282. * return 0.
  283. */
  284. int
  285. addr_probe(uint *addr)
  286. {
  287. return 0;
  288. }