traps.c 7.6 KB

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