traps.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. /*
  2. * linux/arch/ppc/kernel/traps.c
  3. *
  4. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  5. *
  6. * Modified by Cort Dougan (cort@cs.nmt.edu)
  7. * and Paul Mackerras (paulus@cs.anu.edu.au)
  8. *
  9. * (C) Copyright 2000
  10. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  11. *
  12. * See file CREDITS for list of people who contributed to this
  13. * project.
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License as
  17. * published by the Free Software Foundation; either version 2 of
  18. * the License, or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  28. * MA 02111-1307 USA
  29. */
  30. /*
  31. * This file handles the architecture-dependent parts of hardware exceptions
  32. */
  33. #include <common.h>
  34. #include <command.h>
  35. #include <asm/processor.h>
  36. DECLARE_GLOBAL_DATA_PTR;
  37. /* Returns 0 if exception not found and fixup otherwise. */
  38. extern unsigned long search_exception_table(unsigned long);
  39. /* THIS NEEDS CHANGING to use the board info structure.
  40. */
  41. #define END_OF_MEM (gd->bd->bi_memstart + gd->bd->bi_memsize)
  42. static __inline__ void set_tsr(unsigned long val)
  43. {
  44. #if defined(CONFIG_440)
  45. asm volatile("mtspr 0x150, %0" : : "r" (val));
  46. #else
  47. asm volatile("mttsr %0" : : "r" (val));
  48. #endif
  49. }
  50. static __inline__ unsigned long get_esr(void)
  51. {
  52. unsigned long val;
  53. #if defined(CONFIG_440)
  54. asm volatile("mfspr %0, 0x03e" : "=r" (val) :);
  55. #else
  56. asm volatile("mfesr %0" : "=r" (val) :);
  57. #endif
  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 DEAR: %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. printf("GPR%02d: ", i);
  105. }
  106. printf("%08lX ", regs->gpr[i]);
  107. if ((i % 8) == 7) {
  108. printf("\n");
  109. }
  110. }
  111. }
  112. void
  113. _exception(int signr, struct pt_regs *regs)
  114. {
  115. show_regs(regs);
  116. print_backtrace((unsigned long *)regs->gpr[1]);
  117. panic("Exception");
  118. }
  119. void
  120. MachineCheckException(struct pt_regs *regs)
  121. {
  122. unsigned long fixup, val;
  123. #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  124. u32 value2;
  125. int corr_ecc = 0;
  126. int uncorr_ecc = 0;
  127. #endif
  128. if ((fixup = search_exception_table(regs->nip)) != 0) {
  129. regs->nip = fixup;
  130. val = mfspr(MCSR);
  131. /* Clear MCSR */
  132. mtspr(SPRN_MCSR, val);
  133. return;
  134. }
  135. #if defined(CONFIG_CMD_KGDB)
  136. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  137. return;
  138. #endif
  139. printf("Machine Check Exception.\n");
  140. printf("Caused by (from msr): ");
  141. printf("regs %p ", regs);
  142. val = get_esr();
  143. #if !defined(CONFIG_440) && !defined(CONFIG_405EX)
  144. if (val& ESR_IMCP) {
  145. printf("Instruction");
  146. mtspr(ESR, val & ~ESR_IMCP);
  147. } else {
  148. printf("Data");
  149. }
  150. printf(" machine check.\n");
  151. #elif defined(CONFIG_440) || defined(CONFIG_405EX)
  152. if (val& ESR_IMCP){
  153. printf("Instruction Synchronous Machine Check exception\n");
  154. mtspr(SPRN_ESR, val & ~ESR_IMCP);
  155. } else {
  156. val = mfspr(MCSR);
  157. if (val & MCSR_IB)
  158. printf("Instruction Read PLB Error\n");
  159. #if defined(CONFIG_440)
  160. if (val & MCSR_DRB)
  161. printf("Data Read PLB Error\n");
  162. if (val & MCSR_DWB)
  163. printf("Data Write PLB Error\n");
  164. #else
  165. if (val & MCSR_DB)
  166. printf("Data PLB Error\n");
  167. #endif
  168. if (val & MCSR_TLBP)
  169. printf("TLB Parity Error\n");
  170. if (val & MCSR_ICP){
  171. /*flush_instruction_cache(); */
  172. printf("I-Cache Parity Error\n");
  173. }
  174. if (val & MCSR_DCSP)
  175. printf("D-Cache Search Parity Error\n");
  176. if (val & MCSR_DCFP)
  177. printf("D-Cache Flush Parity Error\n");
  178. if (val & MCSR_IMPE)
  179. printf("Machine Check exception is imprecise\n");
  180. /* Clear MCSR */
  181. mtspr(SPRN_MCSR, val);
  182. }
  183. #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  184. mfsdram(DDR0_00, val) ;
  185. printf("DDR0: DDR0_00 %lx\n", val);
  186. val = (val >> 16) & 0xff;
  187. if (val & 0x80)
  188. printf("DDR0: At least one interrupt active\n");
  189. if (val & 0x40)
  190. printf("DDR0: DRAM initialization complete.\n");
  191. if (val & 0x20) {
  192. printf("DDR0: Multiple uncorrectable ECC events.\n");
  193. uncorr_ecc = 1;
  194. }
  195. if (val & 0x10) {
  196. printf("DDR0: Single uncorrectable ECC event.\n");
  197. uncorr_ecc = 1;
  198. }
  199. if (val & 0x08) {
  200. printf("DDR0: Multiple correctable ECC events.\n");
  201. corr_ecc = 1;
  202. }
  203. if (val & 0x04) {
  204. printf("DDR0: Single correctable ECC event.\n");
  205. corr_ecc = 1;
  206. }
  207. if (val & 0x02)
  208. printf("Multiple accesses outside the defined"
  209. " physical memory space detected\n");
  210. if (val & 0x01)
  211. printf("DDR0: Single access outside the defined"
  212. " physical memory space detected.\n");
  213. mfsdram(DDR0_01, val);
  214. val = (val >> 8) & 0x7;
  215. switch (val ) {
  216. case 0:
  217. printf("DDR0: Write Out-of-Range command\n");
  218. break;
  219. case 1:
  220. printf("DDR0: Read Out-of-Range command\n");
  221. break;
  222. case 2:
  223. printf("DDR0: Masked write Out-of-Range command\n");
  224. break;
  225. case 4:
  226. printf("DDR0: Wrap write Out-of-Range command\n");
  227. break;
  228. case 5:
  229. printf("DDR0: Wrap read Out-of-Range command\n");
  230. break;
  231. default:
  232. mfsdram(DDR0_01, value2);
  233. printf("DDR0: No DDR0 error know 0x%lx %x\n", val, value2);
  234. }
  235. mfsdram(DDR0_23, val);
  236. if (((val >> 16) & 0xff) && corr_ecc)
  237. printf("DDR0: Syndrome for correctable ECC event 0x%lx\n",
  238. (val >> 16) & 0xff);
  239. mfsdram(DDR0_23, val);
  240. if (((val >> 8) & 0xff) && uncorr_ecc)
  241. printf("DDR0: Syndrome for uncorrectable ECC event 0x%lx\n",
  242. (val >> 8) & 0xff);
  243. mfsdram(DDR0_33, val);
  244. if (val)
  245. printf("DDR0: Address of command that caused an "
  246. "Out-of-Range interrupt %lx\n", val);
  247. mfsdram(DDR0_34, val);
  248. if (val && uncorr_ecc)
  249. printf("DDR0: Address of uncorrectable ECC event %lx\n", val);
  250. mfsdram(DDR0_35, val);
  251. if (val && uncorr_ecc)
  252. printf("DDR0: Address of uncorrectable ECC event %lx\n", val);
  253. mfsdram(DDR0_36, val);
  254. if (val && uncorr_ecc)
  255. printf("DDR0: Data of uncorrectable ECC event 0x%08lx\n", val);
  256. mfsdram(DDR0_37, val);
  257. if (val && uncorr_ecc)
  258. printf("DDR0: Data of uncorrectable ECC event 0x%08lx\n", val);
  259. mfsdram(DDR0_38, val);
  260. if (val && corr_ecc)
  261. printf("DDR0: Address of correctable ECC event %lx\n", val);
  262. mfsdram(DDR0_39, val);
  263. if (val && corr_ecc)
  264. printf("DDR0: Address of correctable ECC event %lx\n", val);
  265. mfsdram(DDR0_40, val);
  266. if (val && corr_ecc)
  267. printf("DDR0: Data of correctable ECC event 0x%08lx\n", val);
  268. mfsdram(DDR0_41, val);
  269. if (val && corr_ecc)
  270. printf("DDR0: Data of correctable ECC event 0x%08lx\n", val);
  271. #endif /* CONFIG_440EPX */
  272. #endif /* CONFIG_440 */
  273. show_regs(regs);
  274. print_backtrace((unsigned long *)regs->gpr[1]);
  275. panic("machine check");
  276. }
  277. void
  278. AlignmentException(struct pt_regs *regs)
  279. {
  280. #if defined(CONFIG_CMD_KGDB)
  281. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  282. return;
  283. #endif
  284. show_regs(regs);
  285. print_backtrace((unsigned long *)regs->gpr[1]);
  286. panic("Alignment Exception");
  287. }
  288. void
  289. ProgramCheckException(struct pt_regs *regs)
  290. {
  291. long esr_val;
  292. #if defined(CONFIG_CMD_KGDB)
  293. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  294. return;
  295. #endif
  296. show_regs(regs);
  297. esr_val = get_esr();
  298. if( esr_val & ESR_PIL )
  299. printf( "** Illegal Instruction **\n" );
  300. else if( esr_val & ESR_PPR )
  301. printf( "** Privileged Instruction **\n" );
  302. else if( esr_val & ESR_PTR )
  303. printf( "** Trap Instruction **\n" );
  304. print_backtrace((unsigned long *)regs->gpr[1]);
  305. panic("Program Check Exception");
  306. }
  307. void
  308. DecrementerPITException(struct pt_regs *regs)
  309. {
  310. /*
  311. * Reset PIT interrupt
  312. */
  313. set_tsr(0x08000000);
  314. /*
  315. * Call timer_interrupt routine in interrupts.c
  316. */
  317. timer_interrupt(NULL);
  318. }
  319. void
  320. UnknownException(struct pt_regs *regs)
  321. {
  322. #if defined(CONFIG_CMD_KGDB)
  323. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  324. return;
  325. #endif
  326. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  327. regs->nip, regs->msr, regs->trap);
  328. _exception(0, regs);
  329. }
  330. void
  331. DebugException(struct pt_regs *regs)
  332. {
  333. printf("Debugger trap at @ %lx\n", regs->nip );
  334. show_regs(regs);
  335. #if defined(CONFIG_CMD_BEDBUG)
  336. do_bedbug_breakpoint( regs );
  337. #endif
  338. }
  339. /* Probe an address by reading. If not present, return -1, otherwise
  340. * return 0.
  341. */
  342. int
  343. addr_probe(uint *addr)
  344. {
  345. #if 0
  346. int retval;
  347. __asm__ __volatile__( \
  348. "1: lwz %0,0(%1)\n" \
  349. " eieio\n" \
  350. " li %0,0\n" \
  351. "2:\n" \
  352. ".section .fixup,\"ax\"\n" \
  353. "3: li %0,-1\n" \
  354. " b 2b\n" \
  355. ".section __ex_table,\"a\"\n" \
  356. " .align 2\n" \
  357. " .long 1b,3b\n" \
  358. ".text" \
  359. : "=r" (retval) : "r"(addr));
  360. return (retval);
  361. #endif
  362. return 0;
  363. }