traps.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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 memory as shown by board info and determined by DDR setup.
  48. */
  49. #define END_OF_MEM (gd->bd->bi_memstart + gd->bd->bi_memsize)
  50. static __inline__ void set_tsr(unsigned long val)
  51. {
  52. asm volatile("mtspr 0x150, %0" : : "r" (val));
  53. }
  54. static __inline__ unsigned long get_esr(void)
  55. {
  56. unsigned long val;
  57. asm volatile("mfspr %0, 0x03e" : "=r" (val) :);
  58. return val;
  59. }
  60. #define ESR_MCI 0x80000000
  61. #define ESR_PIL 0x08000000
  62. #define ESR_PPR 0x04000000
  63. #define ESR_PTR 0x02000000
  64. #define ESR_DST 0x00800000
  65. #define ESR_DIZ 0x00400000
  66. #define ESR_U0F 0x00008000
  67. #if defined(CONFIG_CMD_BEDBUG)
  68. extern void do_bedbug_breakpoint(struct pt_regs *);
  69. #endif
  70. /*
  71. * Trap & Exception support
  72. */
  73. void
  74. print_backtrace(unsigned long *sp)
  75. {
  76. int cnt = 0;
  77. unsigned long i;
  78. printf("Call backtrace: ");
  79. while (sp) {
  80. if ((uint)sp > END_OF_MEM)
  81. break;
  82. i = sp[1];
  83. if (cnt++ % 7 == 0)
  84. printf("\n");
  85. printf("%08lX ", i);
  86. if (cnt > 32) break;
  87. sp = (unsigned long *)*sp;
  88. }
  89. printf("\n");
  90. }
  91. void show_regs(struct pt_regs * regs)
  92. {
  93. int i;
  94. printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
  95. regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
  96. printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
  97. regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
  98. regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
  99. regs->msr&MSR_IR ? 1 : 0,
  100. regs->msr&MSR_DR ? 1 : 0);
  101. printf("\n");
  102. for (i = 0; i < 32; i++) {
  103. if ((i % 8) == 0)
  104. {
  105. printf("GPR%02d: ", i);
  106. }
  107. printf("%08lX ", regs->gpr[i]);
  108. if ((i % 8) == 7)
  109. {
  110. printf("\n");
  111. }
  112. }
  113. }
  114. void
  115. _exception(int signr, struct pt_regs *regs)
  116. {
  117. show_regs(regs);
  118. print_backtrace((unsigned long *)regs->gpr[1]);
  119. panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
  120. }
  121. void
  122. CritcalInputException(struct pt_regs *regs)
  123. {
  124. panic("Critical Input Exception");
  125. }
  126. int machinecheck_count = 0;
  127. int machinecheck_error = 0;
  128. void
  129. MachineCheckException(struct pt_regs *regs)
  130. {
  131. unsigned long fixup;
  132. unsigned int mcsr, mcsrr0, mcsrr1, mcar;
  133. /* Probing PCI using config cycles cause this exception
  134. * when a device is not present. Catch it and return to
  135. * the PCI exception handler.
  136. */
  137. if ((fixup = search_exception_table(regs->nip)) != 0) {
  138. regs->nip = fixup;
  139. return;
  140. }
  141. mcsrr0 = mfspr(SPRN_MCSRR0);
  142. mcsrr1 = mfspr(SPRN_MCSRR1);
  143. mcsr = mfspr(SPRN_MCSR);
  144. mcar = mfspr(SPRN_MCAR);
  145. machinecheck_count++;
  146. machinecheck_error=1;
  147. #if defined(CONFIG_CMD_KGDB)
  148. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  149. return;
  150. #endif
  151. printf("Machine check in kernel mode.\n");
  152. printf("Caused by (from mcsr): ");
  153. printf("mcsr = 0x%08x\n", mcsr);
  154. if (mcsr & 0x80000000)
  155. printf("Machine check input pin\n");
  156. if (mcsr & 0x40000000)
  157. printf("Instruction cache parity error\n");
  158. if (mcsr & 0x20000000)
  159. printf("Data cache push parity error\n");
  160. if (mcsr & 0x10000000)
  161. printf("Data cache parity error\n");
  162. if (mcsr & 0x00000080)
  163. printf("Bus instruction address error\n");
  164. if (mcsr & 0x00000040)
  165. printf("Bus Read address error\n");
  166. if (mcsr & 0x00000020)
  167. printf("Bus Write address error\n");
  168. if (mcsr & 0x00000010)
  169. printf("Bus Instruction data bus error\n");
  170. if (mcsr & 0x00000008)
  171. printf("Bus Read data bus error\n");
  172. if (mcsr & 0x00000004)
  173. printf("Bus Write bus error\n");
  174. if (mcsr & 0x00000002)
  175. printf("Bus Instruction parity error\n");
  176. if (mcsr & 0x00000001)
  177. printf("Bus Read parity error\n");
  178. show_regs(regs);
  179. printf("MCSR=0x%08x \tMCSRR0=0x%08x \nMCSRR1=0x%08x \tMCAR=0x%08x\n",
  180. mcsr, mcsrr0, mcsrr1, mcar);
  181. print_backtrace((unsigned long *)regs->gpr[1]);
  182. if (machinecheck_count > 10) {
  183. panic("machine check count too high\n");
  184. }
  185. if (machinecheck_count > 1) {
  186. regs->nip += 4; /* skip offending instruction */
  187. printf("Skipping current instr, Returning to 0x%08x\n",
  188. regs->nip);
  189. } else {
  190. printf("Returning back to 0x%08x\n",regs->nip);
  191. }
  192. }
  193. void
  194. AlignmentException(struct pt_regs *regs)
  195. {
  196. #if defined(CONFIG_CMD_KGDB)
  197. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  198. return;
  199. #endif
  200. show_regs(regs);
  201. print_backtrace((unsigned long *)regs->gpr[1]);
  202. panic("Alignment Exception");
  203. }
  204. void
  205. ProgramCheckException(struct pt_regs *regs)
  206. {
  207. long esr_val;
  208. #if defined(CONFIG_CMD_KGDB)
  209. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  210. return;
  211. #endif
  212. show_regs(regs);
  213. esr_val = get_esr();
  214. if( esr_val & ESR_PIL )
  215. printf( "** Illegal Instruction **\n" );
  216. else if( esr_val & ESR_PPR )
  217. printf( "** Privileged Instruction **\n" );
  218. else if( esr_val & ESR_PTR )
  219. printf( "** Trap Instruction **\n" );
  220. print_backtrace((unsigned long *)regs->gpr[1]);
  221. panic("Program Check Exception");
  222. }
  223. void
  224. PITException(struct pt_regs *regs)
  225. {
  226. /*
  227. * Reset PIT interrupt
  228. */
  229. set_tsr(0x0c000000);
  230. /*
  231. * Call timer_interrupt routine in interrupts.c
  232. */
  233. timer_interrupt(NULL);
  234. }
  235. void
  236. UnknownException(struct pt_regs *regs)
  237. {
  238. #if defined(CONFIG_CMD_KGDB)
  239. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  240. return;
  241. #endif
  242. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  243. regs->nip, regs->msr, regs->trap);
  244. _exception(0, regs);
  245. }
  246. void
  247. ExtIntException(struct pt_regs *regs)
  248. {
  249. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  250. volatile ccsr_pic_t *pic = &immap->im_pic;
  251. uint vect;
  252. #if defined(CONFIG_CMD_KGDB)
  253. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  254. return;
  255. #endif
  256. printf("External Interrupt Exception at PC: %lx, SR: %lx, vector=%lx",
  257. regs->nip, regs->msr, regs->trap);
  258. vect = pic->iack0;
  259. printf(" irq IACK0@%05x=%d\n",&pic->iack0,vect);
  260. show_regs(regs);
  261. print_backtrace((unsigned long *)regs->gpr[1]);
  262. machinecheck_count++;
  263. #ifdef EXTINT_NOSKIP
  264. printf("Returning back to 0x%08x\n",regs->nip);
  265. #else
  266. regs->nip += 4; /* skip offending instruction */
  267. printf("Skipping current instr, Returning to 0x%08x\n",regs->nip);
  268. #endif
  269. }
  270. void
  271. DebugException(struct pt_regs *regs)
  272. {
  273. printf("Debugger trap at @ %lx\n", regs->nip );
  274. show_regs(regs);
  275. #if defined(CONFIG_CMD_BEDBUG)
  276. do_bedbug_breakpoint( regs );
  277. #endif
  278. }
  279. /* Probe an address by reading. If not present, return -1, otherwise
  280. * return 0.
  281. */
  282. int
  283. addr_probe(uint *addr)
  284. {
  285. return 0;
  286. }