blob: df527e4b273c7a4be50b6c7bb30ae4da608000a2 [file] [log] [blame]
wdenkaffae2b2002-08-17 09:36:01 +00001/*
Stefan Roese88fbf932010-04-15 16:07:28 +02002 * linux/arch/powerpc/kernel/traps.c
wdenkaffae2b2002-08-17 09:36:01 +00003 *
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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020012 * SPDX-License-Identifier: GPL-2.0+
wdenkaffae2b2002-08-17 09:36:01 +000013 */
14
15/*
16 * This file handles the architecture-dependent parts of hardware exceptions
17 */
18
19#include <common.h>
20#include <command.h>
Stefan Roese63b6c422010-01-26 13:33:29 +010021#include <kgdb.h>
wdenkaffae2b2002-08-17 09:36:01 +000022#include <asm/processor.h>
23
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +020024DECLARE_GLOBAL_DATA_PTR;
25
wdenkaffae2b2002-08-17 09:36:01 +000026/* Returns 0 if exception not found and fixup otherwise. */
27extern unsigned long search_exception_table(unsigned long);
28
29/* THIS NEEDS CHANGING to use the board info structure.
30 */
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +020031#define END_OF_MEM (gd->bd->bi_memstart + gd->bd->bi_memsize)
wdenkaffae2b2002-08-17 09:36:01 +000032
wdenkaffae2b2002-08-17 09:36:01 +000033static __inline__ unsigned long get_esr(void)
34{
35 unsigned long val;
36
37#if defined(CONFIG_440)
38 asm volatile("mfspr %0, 0x03e" : "=r" (val) :);
39#else
40 asm volatile("mfesr %0" : "=r" (val) :);
41#endif
42 return val;
43}
44
45#define ESR_MCI 0x80000000
46#define ESR_PIL 0x08000000
47#define ESR_PPR 0x04000000
48#define ESR_PTR 0x02000000
49#define ESR_DST 0x00800000
50#define ESR_DIZ 0x00400000
51#define ESR_U0F 0x00008000
52
Jon Loeligera5217742007-07-09 18:57:22 -050053#if defined(CONFIG_CMD_BEDBUG)
wdenkaffae2b2002-08-17 09:36:01 +000054extern void do_bedbug_breakpoint(struct pt_regs *);
55#endif
56
57/*
58 * Trap & Exception support
59 */
60
Kim Phillipse16737f2012-10-29 13:34:29 +000061static void print_backtrace(unsigned long *sp)
wdenkaffae2b2002-08-17 09:36:01 +000062{
Wolfgang Denk09675ef2007-06-20 18:14:24 +020063 int cnt = 0;
64 unsigned long i;
wdenkaffae2b2002-08-17 09:36:01 +000065
Wolfgang Denk09675ef2007-06-20 18:14:24 +020066 printf("Call backtrace: ");
67 while (sp) {
68 if ((uint)sp > END_OF_MEM)
69 break;
wdenkaffae2b2002-08-17 09:36:01 +000070
Wolfgang Denk09675ef2007-06-20 18:14:24 +020071 i = sp[1];
72 if (cnt++ % 7 == 0)
73 printf("\n");
74 printf("%08lX ", i);
75 if (cnt > 32) break;
76 sp = (unsigned long *)*sp;
77 }
78 printf("\n");
wdenkaffae2b2002-08-17 09:36:01 +000079}
80
Kim Phillipse16737f2012-10-29 13:34:29 +000081void show_regs(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +000082{
83 int i;
84
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +020085 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DEAR: %08lX\n",
wdenkaffae2b2002-08-17 09:36:01 +000086 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
87 printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
88 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
89 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
90 regs->msr&MSR_IR ? 1 : 0,
91 regs->msr&MSR_DR ? 1 : 0);
92
93 printf("\n");
94 for (i = 0; i < 32; i++) {
Wolfgang Denk09675ef2007-06-20 18:14:24 +020095 if ((i % 8) == 0) {
wdenkaffae2b2002-08-17 09:36:01 +000096 printf("GPR%02d: ", i);
97 }
98
99 printf("%08lX ", regs->gpr[i]);
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200100 if ((i % 8) == 7) {
wdenkaffae2b2002-08-17 09:36:01 +0000101 printf("\n");
102 }
103 }
104}
105
106
Kim Phillipse16737f2012-10-29 13:34:29 +0000107static void _exception(int signr, struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +0000108{
109 show_regs(regs);
110 print_backtrace((unsigned long *)regs->gpr[1]);
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200111 panic("Exception");
wdenkaffae2b2002-08-17 09:36:01 +0000112}
113
Kim Phillipse16737f2012-10-29 13:34:29 +0000114void MachineCheckException(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +0000115{
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200116 unsigned long fixup, val;
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200117#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
118 u32 value2;
Stefan Roeseb55f2422007-07-30 11:04:57 +0200119 int corr_ecc = 0;
120 int uncorr_ecc = 0;
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200121#endif
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200122
wdenkaffae2b2002-08-17 09:36:01 +0000123 if ((fixup = search_exception_table(regs->nip)) != 0) {
124 regs->nip = fixup;
Grzegorz Bernackid84fe302007-07-31 18:51:48 +0200125 val = mfspr(MCSR);
126 /* Clear MCSR */
Stefan Roese083c8472007-08-02 08:33:56 +0200127 mtspr(SPRN_MCSR, val);
wdenkaffae2b2002-08-17 09:36:01 +0000128 return;
129 }
130
Jon Loeligera5217742007-07-09 18:57:22 -0500131#if defined(CONFIG_CMD_KGDB)
wdenkaffae2b2002-08-17 09:36:01 +0000132 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
133 return;
134#endif
135
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200136 printf("Machine Check Exception.\n");
wdenkaffae2b2002-08-17 09:36:01 +0000137 printf("Caused by (from msr): ");
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200138 printf("regs %p ", regs);
139
140 val = get_esr();
141
Grant Ericksonb6933412008-05-22 14:44:14 -0700142#if !defined(CONFIG_440) && !defined(CONFIG_405EX)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200143 if (val& ESR_IMCP) {
144 printf("Instruction");
145 mtspr(ESR, val & ~ESR_IMCP);
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200146 } else {
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200147 printf("Data");
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200148 }
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200149 printf(" machine check.\n");
150
Grant Ericksonb6933412008-05-22 14:44:14 -0700151#elif defined(CONFIG_440) || defined(CONFIG_405EX)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200152 if (val& ESR_IMCP){
153 printf("Instruction Synchronous Machine Check exception\n");
154 mtspr(SPRN_ESR, val & ~ESR_IMCP);
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200155 } else {
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200156 val = mfspr(MCSR);
157 if (val & MCSR_IB)
158 printf("Instruction Read PLB Error\n");
Grant Ericksonb6933412008-05-22 14:44:14 -0700159#if defined(CONFIG_440)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200160 if (val & MCSR_DRB)
161 printf("Data Read PLB Error\n");
162 if (val & MCSR_DWB)
163 printf("Data Write PLB Error\n");
Grant Ericksonb6933412008-05-22 14:44:14 -0700164#else
165 if (val & MCSR_DB)
166 printf("Data PLB Error\n");
167#endif
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200168 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
181 /* Clear MCSR */
182 mtspr(SPRN_MCSR, val);
wdenkaffae2b2002-08-17 09:36:01 +0000183 }
Stefan Roese79b6deb2010-07-21 19:06:26 +0200184
185#if defined(CONFIG_DDR_ECC) && defined(CONFIG_SDRAM_PPC4xx_IBM_DDR2)
186 /*
187 * Read and print ECC status register/info:
188 * The faulting address is only known upon uncorrectable ECC
189 * errors.
190 */
191 mfsdram(SDRAM_ECCES, val);
192 if (val & SDRAM_ECCES_CE)
193 printf("ECC: Correctable error\n");
194 if (val & SDRAM_ECCES_UE) {
195 printf("ECC: Uncorrectable error at 0x%02x%08x\n",
196 mfdcr(SDRAM_ERRADDULL), mfdcr(SDRAM_ERRADDLLL));
197 }
198#endif /* CONFIG_DDR_ECC ... */
199
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200200#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
201 mfsdram(DDR0_00, val) ;
Stefan Roese251161b2008-07-10 09:58:06 +0200202 printf("DDR0: DDR0_00 %lx\n", val);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200203 val = (val >> 16) & 0xff;
204 if (val & 0x80)
205 printf("DDR0: At least one interrupt active\n");
206 if (val & 0x40)
207 printf("DDR0: DRAM initialization complete.\n");
Stefan Roeseb55f2422007-07-30 11:04:57 +0200208 if (val & 0x20) {
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200209 printf("DDR0: Multiple uncorrectable ECC events.\n");
Stefan Roeseb55f2422007-07-30 11:04:57 +0200210 uncorr_ecc = 1;
211 }
212 if (val & 0x10) {
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200213 printf("DDR0: Single uncorrectable ECC event.\n");
Stefan Roeseb55f2422007-07-30 11:04:57 +0200214 uncorr_ecc = 1;
215 }
216 if (val & 0x08) {
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200217 printf("DDR0: Multiple correctable ECC events.\n");
Stefan Roeseb55f2422007-07-30 11:04:57 +0200218 corr_ecc = 1;
219 }
220 if (val & 0x04) {
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200221 printf("DDR0: Single correctable ECC event.\n");
Stefan Roeseb55f2422007-07-30 11:04:57 +0200222 corr_ecc = 1;
223 }
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200224 if (val & 0x02)
225 printf("Multiple accesses outside the defined"
226 " physical memory space detected\n");
227 if (val & 0x01)
228 printf("DDR0: Single access outside the defined"
229 " physical memory space detected.\n");
230
231 mfsdram(DDR0_01, val);
232 val = (val >> 8) & 0x7;
233 switch (val ) {
234 case 0:
235 printf("DDR0: Write Out-of-Range command\n");
236 break;
237 case 1:
238 printf("DDR0: Read Out-of-Range command\n");
239 break;
240 case 2:
241 printf("DDR0: Masked write Out-of-Range command\n");
242 break;
243 case 4:
244 printf("DDR0: Wrap write Out-of-Range command\n");
245 break;
246 case 5:
247 printf("DDR0: Wrap read Out-of-Range command\n");
248 break;
249 default:
250 mfsdram(DDR0_01, value2);
Stefan Roese251161b2008-07-10 09:58:06 +0200251 printf("DDR0: No DDR0 error know 0x%lx %x\n", val, value2);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200252 }
253 mfsdram(DDR0_23, val);
Stefan Roeseb55f2422007-07-30 11:04:57 +0200254 if (((val >> 16) & 0xff) && corr_ecc)
Stefan Roese251161b2008-07-10 09:58:06 +0200255 printf("DDR0: Syndrome for correctable ECC event 0x%lx\n",
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200256 (val >> 16) & 0xff);
257 mfsdram(DDR0_23, val);
Stefan Roeseb55f2422007-07-30 11:04:57 +0200258 if (((val >> 8) & 0xff) && uncorr_ecc)
Stefan Roese251161b2008-07-10 09:58:06 +0200259 printf("DDR0: Syndrome for uncorrectable ECC event 0x%lx\n",
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200260 (val >> 8) & 0xff);
261 mfsdram(DDR0_33, val);
262 if (val)
263 printf("DDR0: Address of command that caused an "
Stefan Roese251161b2008-07-10 09:58:06 +0200264 "Out-of-Range interrupt %lx\n", val);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200265 mfsdram(DDR0_34, val);
Stefan Roeseb55f2422007-07-30 11:04:57 +0200266 if (val && uncorr_ecc)
Stefan Roese251161b2008-07-10 09:58:06 +0200267 printf("DDR0: Address of uncorrectable ECC event %lx\n", val);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200268 mfsdram(DDR0_35, val);
Stefan Roeseb55f2422007-07-30 11:04:57 +0200269 if (val && uncorr_ecc)
Stefan Roese251161b2008-07-10 09:58:06 +0200270 printf("DDR0: Address of uncorrectable ECC event %lx\n", val);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200271 mfsdram(DDR0_36, val);
Stefan Roeseb55f2422007-07-30 11:04:57 +0200272 if (val && uncorr_ecc)
Stefan Roese251161b2008-07-10 09:58:06 +0200273 printf("DDR0: Data of uncorrectable ECC event 0x%08lx\n", val);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200274 mfsdram(DDR0_37, val);
Stefan Roeseb55f2422007-07-30 11:04:57 +0200275 if (val && uncorr_ecc)
Stefan Roese251161b2008-07-10 09:58:06 +0200276 printf("DDR0: Data of uncorrectable ECC event 0x%08lx\n", val);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200277 mfsdram(DDR0_38, val);
Stefan Roeseb55f2422007-07-30 11:04:57 +0200278 if (val && corr_ecc)
Stefan Roese251161b2008-07-10 09:58:06 +0200279 printf("DDR0: Address of correctable ECC event %lx\n", val);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200280 mfsdram(DDR0_39, val);
Stefan Roeseb55f2422007-07-30 11:04:57 +0200281 if (val && corr_ecc)
Stefan Roese251161b2008-07-10 09:58:06 +0200282 printf("DDR0: Address of correctable ECC event %lx\n", val);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200283 mfsdram(DDR0_40, val);
Stefan Roeseb55f2422007-07-30 11:04:57 +0200284 if (val && corr_ecc)
Stefan Roese251161b2008-07-10 09:58:06 +0200285 printf("DDR0: Data of correctable ECC event 0x%08lx\n", val);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200286 mfsdram(DDR0_41, val);
Stefan Roeseb55f2422007-07-30 11:04:57 +0200287 if (val && corr_ecc)
Stefan Roese251161b2008-07-10 09:58:06 +0200288 printf("DDR0: Data of correctable ECC event 0x%08lx\n", val);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200289#endif /* CONFIG_440EPX */
290#endif /* CONFIG_440 */
wdenkaffae2b2002-08-17 09:36:01 +0000291 show_regs(regs);
292 print_backtrace((unsigned long *)regs->gpr[1]);
293 panic("machine check");
294}
295
Kim Phillipse16737f2012-10-29 13:34:29 +0000296void AlignmentException(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +0000297{
Jon Loeligera5217742007-07-09 18:57:22 -0500298#if defined(CONFIG_CMD_KGDB)
wdenkaffae2b2002-08-17 09:36:01 +0000299 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
300 return;
301#endif
302
303 show_regs(regs);
304 print_backtrace((unsigned long *)regs->gpr[1]);
305 panic("Alignment Exception");
306}
307
Kim Phillipse16737f2012-10-29 13:34:29 +0000308void ProgramCheckException(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +0000309{
wdenk57b2d802003-06-27 21:31:46 +0000310 long esr_val;
wdenkaffae2b2002-08-17 09:36:01 +0000311
Jon Loeligera5217742007-07-09 18:57:22 -0500312#if defined(CONFIG_CMD_KGDB)
wdenkaffae2b2002-08-17 09:36:01 +0000313 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
314 return;
315#endif
316
317 show_regs(regs);
318
wdenk57b2d802003-06-27 21:31:46 +0000319 esr_val = get_esr();
320 if( esr_val & ESR_PIL )
wdenkaffae2b2002-08-17 09:36:01 +0000321 printf( "** Illegal Instruction **\n" );
wdenk57b2d802003-06-27 21:31:46 +0000322 else if( esr_val & ESR_PPR )
wdenkaffae2b2002-08-17 09:36:01 +0000323 printf( "** Privileged Instruction **\n" );
wdenk57b2d802003-06-27 21:31:46 +0000324 else if( esr_val & ESR_PTR )
wdenkaffae2b2002-08-17 09:36:01 +0000325 printf( "** Trap Instruction **\n" );
326
327 print_backtrace((unsigned long *)regs->gpr[1]);
328 panic("Program Check Exception");
329}
330
Kim Phillipse16737f2012-10-29 13:34:29 +0000331void DecrementerPITException(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +0000332{
wdenk57b2d802003-06-27 21:31:46 +0000333 /*
334 * Reset PIT interrupt
335 */
Stefan Roese61138fe2010-10-04 11:09:40 +0200336 mtspr(SPRN_TSR, 0x08000000);
wdenkaffae2b2002-08-17 09:36:01 +0000337
wdenk57b2d802003-06-27 21:31:46 +0000338 /*
339 * Call timer_interrupt routine in interrupts.c
340 */
341 timer_interrupt(NULL);
wdenkaffae2b2002-08-17 09:36:01 +0000342}
343
344
Kim Phillipse16737f2012-10-29 13:34:29 +0000345void UnknownException(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +0000346{
Jon Loeligera5217742007-07-09 18:57:22 -0500347#if defined(CONFIG_CMD_KGDB)
wdenkaffae2b2002-08-17 09:36:01 +0000348 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
349 return;
350#endif
351
352 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
353 regs->nip, regs->msr, regs->trap);
354 _exception(0, regs);
355}
356
Kim Phillipse16737f2012-10-29 13:34:29 +0000357void DebugException(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +0000358{
359 printf("Debugger trap at @ %lx\n", regs->nip );
360 show_regs(regs);
Jon Loeligera5217742007-07-09 18:57:22 -0500361#if defined(CONFIG_CMD_BEDBUG)
wdenkaffae2b2002-08-17 09:36:01 +0000362 do_bedbug_breakpoint( regs );
363#endif
364}
365
366/* Probe an address by reading. If not present, return -1, otherwise
367 * return 0.
368 */
369int
370addr_probe(uint *addr)
371{
372#if 0
373 int retval;
374
375 __asm__ __volatile__( \
376 "1: lwz %0,0(%1)\n" \
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200377 " eieio\n" \
378 " li %0,0\n" \
379 "2:\n" \
380 ".section .fixup,\"ax\"\n" \
381 "3: li %0,-1\n" \
382 " b 2b\n" \
383 ".section __ex_table,\"a\"\n" \
384 " .align 2\n" \
385 " .long 1b,3b\n" \
386 ".text" \
387 : "=r" (retval) : "r"(addr));
wdenkaffae2b2002-08-17 09:36:01 +0000388
389 return (retval);
390#endif
391 return 0;
392}