traps.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. /*
  2. * linux/arch/powerpc/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 <kgdb.h>
  36. #include <asm/processor.h>
  37. DECLARE_GLOBAL_DATA_PTR;
  38. /* Returns 0 if exception not found and fixup otherwise. */
  39. extern unsigned long search_exception_table(unsigned long);
  40. /* THIS NEEDS CHANGING to use the board info structure.
  41. */
  42. #define END_OF_MEM (gd->bd->bi_memstart + gd->bd->bi_memsize)
  43. static __inline__ void set_tsr(unsigned long val)
  44. {
  45. #if defined(CONFIG_440)
  46. asm volatile("mtspr 0x150, %0" : : "r" (val));
  47. #else
  48. asm volatile("mttsr %0" : : "r" (val));
  49. #endif
  50. }
  51. static __inline__ unsigned long get_esr(void)
  52. {
  53. unsigned long val;
  54. #if defined(CONFIG_440)
  55. asm volatile("mfspr %0, 0x03e" : "=r" (val) :);
  56. #else
  57. asm volatile("mfesr %0" : "=r" (val) :);
  58. #endif
  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 DEAR: %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. printf("GPR%02d: ", i);
  106. }
  107. printf("%08lX ", regs->gpr[i]);
  108. if ((i % 8) == 7) {
  109. printf("\n");
  110. }
  111. }
  112. }
  113. void
  114. _exception(int signr, struct pt_regs *regs)
  115. {
  116. show_regs(regs);
  117. print_backtrace((unsigned long *)regs->gpr[1]);
  118. panic("Exception");
  119. }
  120. void
  121. MachineCheckException(struct pt_regs *regs)
  122. {
  123. unsigned long fixup, val;
  124. #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  125. u32 value2;
  126. int corr_ecc = 0;
  127. int uncorr_ecc = 0;
  128. #endif
  129. if ((fixup = search_exception_table(regs->nip)) != 0) {
  130. regs->nip = fixup;
  131. val = mfspr(MCSR);
  132. /* Clear MCSR */
  133. mtspr(SPRN_MCSR, val);
  134. return;
  135. }
  136. #if defined(CONFIG_CMD_KGDB)
  137. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  138. return;
  139. #endif
  140. printf("Machine Check Exception.\n");
  141. printf("Caused by (from msr): ");
  142. printf("regs %p ", regs);
  143. val = get_esr();
  144. #if !defined(CONFIG_440) && !defined(CONFIG_405EX)
  145. if (val& ESR_IMCP) {
  146. printf("Instruction");
  147. mtspr(ESR, val & ~ESR_IMCP);
  148. } else {
  149. printf("Data");
  150. }
  151. printf(" machine check.\n");
  152. #elif defined(CONFIG_440) || defined(CONFIG_405EX)
  153. if (val& ESR_IMCP){
  154. printf("Instruction Synchronous Machine Check exception\n");
  155. mtspr(SPRN_ESR, val & ~ESR_IMCP);
  156. } else {
  157. val = mfspr(MCSR);
  158. if (val & MCSR_IB)
  159. printf("Instruction Read PLB Error\n");
  160. #if defined(CONFIG_440)
  161. if (val & MCSR_DRB)
  162. printf("Data Read PLB Error\n");
  163. if (val & MCSR_DWB)
  164. printf("Data Write PLB Error\n");
  165. #else
  166. if (val & MCSR_DB)
  167. printf("Data PLB Error\n");
  168. #endif
  169. if (val & MCSR_TLBP)
  170. printf("TLB Parity Error\n");
  171. if (val & MCSR_ICP){
  172. /*flush_instruction_cache(); */
  173. printf("I-Cache Parity Error\n");
  174. }
  175. if (val & MCSR_DCSP)
  176. printf("D-Cache Search Parity Error\n");
  177. if (val & MCSR_DCFP)
  178. printf("D-Cache Flush Parity Error\n");
  179. if (val & MCSR_IMPE)
  180. printf("Machine Check exception is imprecise\n");
  181. /* Clear MCSR */
  182. mtspr(SPRN_MCSR, val);
  183. }
  184. #if defined(CONFIG_DDR_ECC) && defined(CONFIG_SDRAM_PPC4xx_IBM_DDR2)
  185. /*
  186. * Read and print ECC status register/info:
  187. * The faulting address is only known upon uncorrectable ECC
  188. * errors.
  189. */
  190. mfsdram(SDRAM_ECCES, val);
  191. if (val & SDRAM_ECCES_CE)
  192. printf("ECC: Correctable error\n");
  193. if (val & SDRAM_ECCES_UE) {
  194. printf("ECC: Uncorrectable error at 0x%02x%08x\n",
  195. mfdcr(SDRAM_ERRADDULL), mfdcr(SDRAM_ERRADDLLL));
  196. }
  197. #endif /* CONFIG_DDR_ECC ... */
  198. #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  199. mfsdram(DDR0_00, val) ;
  200. printf("DDR0: DDR0_00 %lx\n", val);
  201. val = (val >> 16) & 0xff;
  202. if (val & 0x80)
  203. printf("DDR0: At least one interrupt active\n");
  204. if (val & 0x40)
  205. printf("DDR0: DRAM initialization complete.\n");
  206. if (val & 0x20) {
  207. printf("DDR0: Multiple uncorrectable ECC events.\n");
  208. uncorr_ecc = 1;
  209. }
  210. if (val & 0x10) {
  211. printf("DDR0: Single uncorrectable ECC event.\n");
  212. uncorr_ecc = 1;
  213. }
  214. if (val & 0x08) {
  215. printf("DDR0: Multiple correctable ECC events.\n");
  216. corr_ecc = 1;
  217. }
  218. if (val & 0x04) {
  219. printf("DDR0: Single correctable ECC event.\n");
  220. corr_ecc = 1;
  221. }
  222. if (val & 0x02)
  223. printf("Multiple accesses outside the defined"
  224. " physical memory space detected\n");
  225. if (val & 0x01)
  226. printf("DDR0: Single access outside the defined"
  227. " physical memory space detected.\n");
  228. mfsdram(DDR0_01, val);
  229. val = (val >> 8) & 0x7;
  230. switch (val ) {
  231. case 0:
  232. printf("DDR0: Write Out-of-Range command\n");
  233. break;
  234. case 1:
  235. printf("DDR0: Read Out-of-Range command\n");
  236. break;
  237. case 2:
  238. printf("DDR0: Masked write Out-of-Range command\n");
  239. break;
  240. case 4:
  241. printf("DDR0: Wrap write Out-of-Range command\n");
  242. break;
  243. case 5:
  244. printf("DDR0: Wrap read Out-of-Range command\n");
  245. break;
  246. default:
  247. mfsdram(DDR0_01, value2);
  248. printf("DDR0: No DDR0 error know 0x%lx %x\n", val, value2);
  249. }
  250. mfsdram(DDR0_23, val);
  251. if (((val >> 16) & 0xff) && corr_ecc)
  252. printf("DDR0: Syndrome for correctable ECC event 0x%lx\n",
  253. (val >> 16) & 0xff);
  254. mfsdram(DDR0_23, val);
  255. if (((val >> 8) & 0xff) && uncorr_ecc)
  256. printf("DDR0: Syndrome for uncorrectable ECC event 0x%lx\n",
  257. (val >> 8) & 0xff);
  258. mfsdram(DDR0_33, val);
  259. if (val)
  260. printf("DDR0: Address of command that caused an "
  261. "Out-of-Range interrupt %lx\n", val);
  262. mfsdram(DDR0_34, val);
  263. if (val && uncorr_ecc)
  264. printf("DDR0: Address of uncorrectable ECC event %lx\n", val);
  265. mfsdram(DDR0_35, val);
  266. if (val && uncorr_ecc)
  267. printf("DDR0: Address of uncorrectable ECC event %lx\n", val);
  268. mfsdram(DDR0_36, val);
  269. if (val && uncorr_ecc)
  270. printf("DDR0: Data of uncorrectable ECC event 0x%08lx\n", val);
  271. mfsdram(DDR0_37, val);
  272. if (val && uncorr_ecc)
  273. printf("DDR0: Data of uncorrectable ECC event 0x%08lx\n", val);
  274. mfsdram(DDR0_38, val);
  275. if (val && corr_ecc)
  276. printf("DDR0: Address of correctable ECC event %lx\n", val);
  277. mfsdram(DDR0_39, val);
  278. if (val && corr_ecc)
  279. printf("DDR0: Address of correctable ECC event %lx\n", val);
  280. mfsdram(DDR0_40, val);
  281. if (val && corr_ecc)
  282. printf("DDR0: Data of correctable ECC event 0x%08lx\n", val);
  283. mfsdram(DDR0_41, val);
  284. if (val && corr_ecc)
  285. printf("DDR0: Data of correctable ECC event 0x%08lx\n", val);
  286. #endif /* CONFIG_440EPX */
  287. #endif /* CONFIG_440 */
  288. show_regs(regs);
  289. print_backtrace((unsigned long *)regs->gpr[1]);
  290. panic("machine check");
  291. }
  292. void
  293. AlignmentException(struct pt_regs *regs)
  294. {
  295. #if defined(CONFIG_CMD_KGDB)
  296. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  297. return;
  298. #endif
  299. show_regs(regs);
  300. print_backtrace((unsigned long *)regs->gpr[1]);
  301. panic("Alignment Exception");
  302. }
  303. void
  304. ProgramCheckException(struct pt_regs *regs)
  305. {
  306. long esr_val;
  307. #if defined(CONFIG_CMD_KGDB)
  308. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  309. return;
  310. #endif
  311. show_regs(regs);
  312. esr_val = get_esr();
  313. if( esr_val & ESR_PIL )
  314. printf( "** Illegal Instruction **\n" );
  315. else if( esr_val & ESR_PPR )
  316. printf( "** Privileged Instruction **\n" );
  317. else if( esr_val & ESR_PTR )
  318. printf( "** Trap Instruction **\n" );
  319. print_backtrace((unsigned long *)regs->gpr[1]);
  320. panic("Program Check Exception");
  321. }
  322. void
  323. DecrementerPITException(struct pt_regs *regs)
  324. {
  325. /*
  326. * Reset PIT interrupt
  327. */
  328. set_tsr(0x08000000);
  329. /*
  330. * Call timer_interrupt routine in interrupts.c
  331. */
  332. timer_interrupt(NULL);
  333. }
  334. void
  335. UnknownException(struct pt_regs *regs)
  336. {
  337. #if defined(CONFIG_CMD_KGDB)
  338. if (debugger_exception_handler && (*debugger_exception_handler)(regs))
  339. return;
  340. #endif
  341. printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  342. regs->nip, regs->msr, regs->trap);
  343. _exception(0, regs);
  344. }
  345. void
  346. DebugException(struct pt_regs *regs)
  347. {
  348. printf("Debugger trap at @ %lx\n", regs->nip );
  349. show_regs(regs);
  350. #if defined(CONFIG_CMD_BEDBUG)
  351. do_bedbug_breakpoint( regs );
  352. #endif
  353. }
  354. /* Probe an address by reading. If not present, return -1, otherwise
  355. * return 0.
  356. */
  357. int
  358. addr_probe(uint *addr)
  359. {
  360. #if 0
  361. int retval;
  362. __asm__ __volatile__( \
  363. "1: lwz %0,0(%1)\n" \
  364. " eieio\n" \
  365. " li %0,0\n" \
  366. "2:\n" \
  367. ".section .fixup,\"ax\"\n" \
  368. "3: li %0,-1\n" \
  369. " b 2b\n" \
  370. ".section __ex_table,\"a\"\n" \
  371. " .align 2\n" \
  372. " .long 1b,3b\n" \
  373. ".text" \
  374. : "=r" (retval) : "r"(addr));
  375. return (retval);
  376. #endif
  377. return 0;
  378. }