2 * linux/arch/powerpc/kernel/traps.c
4 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
6 * Modified by Cort Dougan (cort@cs.nmt.edu)
7 * and Paul Mackerras (paulus@cs.anu.edu.au)
10 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
12 * SPDX-License-Identifier: GPL-2.0+
16 * This file handles the architecture-dependent parts of hardware exceptions
22 #include <asm/processor.h>
24 DECLARE_GLOBAL_DATA_PTR;
26 /* Returns 0 if exception not found and fixup otherwise. */
27 extern unsigned long search_exception_table(unsigned long);
29 /* THIS NEEDS CHANGING to use the board info structure.
31 #define END_OF_MEM (gd->bd->bi_memstart + gd->bd->bi_memsize)
33 static __inline__ unsigned long get_esr(void)
37 #if defined(CONFIG_440)
38 asm volatile("mfspr %0, 0x03e" : "=r" (val) :);
40 asm volatile("mfesr %0" : "=r" (val) :);
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
53 #if defined(CONFIG_CMD_BEDBUG)
54 extern void do_bedbug_breakpoint(struct pt_regs *);
58 * Trap & Exception support
61 static void print_backtrace(unsigned long *sp)
66 printf("Call backtrace: ");
68 if ((uint)sp > END_OF_MEM)
76 sp = (unsigned long *)*sp;
81 void show_regs(struct pt_regs *regs)
85 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DEAR: %08lX\n",
86 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);
94 for (i = 0; i < 32; i++) {
96 printf("GPR%02d: ", i);
99 printf("%08lX ", regs->gpr[i]);
107 static void _exception(int signr, struct pt_regs *regs)
110 print_backtrace((unsigned long *)regs->gpr[1]);
114 void MachineCheckException(struct pt_regs *regs)
116 unsigned long fixup, val;
117 #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
123 if ((fixup = search_exception_table(regs->nip)) != 0) {
127 mtspr(SPRN_MCSR, val);
131 #if defined(CONFIG_CMD_KGDB)
132 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
136 printf("Machine Check Exception.\n");
137 printf("Caused by (from msr): ");
138 printf("regs %p ", regs);
142 #if !defined(CONFIG_440) && !defined(CONFIG_405EX)
144 printf("Instruction");
145 mtspr(ESR, val & ~ESR_IMCP);
149 printf(" machine check.\n");
151 #elif defined(CONFIG_440) || defined(CONFIG_405EX)
153 printf("Instruction Synchronous Machine Check exception\n");
154 mtspr(SPRN_ESR, val & ~ESR_IMCP);
158 printf("Instruction Read PLB Error\n");
159 #if defined(CONFIG_440)
161 printf("Data Read PLB Error\n");
163 printf("Data Write PLB Error\n");
166 printf("Data PLB Error\n");
169 printf("TLB Parity Error\n");
171 /*flush_instruction_cache(); */
172 printf("I-Cache Parity Error\n");
175 printf("D-Cache Search Parity Error\n");
177 printf("D-Cache Flush Parity Error\n");
179 printf("Machine Check exception is imprecise\n");
182 mtspr(SPRN_MCSR, val);
185 #if defined(CONFIG_DDR_ECC) && defined(CONFIG_SDRAM_PPC4xx_IBM_DDR2)
187 * Read and print ECC status register/info:
188 * The faulting address is only known upon uncorrectable ECC
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));
198 #endif /* CONFIG_DDR_ECC ... */
200 #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
201 mfsdram(DDR0_00, val) ;
202 printf("DDR0: DDR0_00 %lx\n", val);
203 val = (val >> 16) & 0xff;
205 printf("DDR0: At least one interrupt active\n");
207 printf("DDR0: DRAM initialization complete.\n");
209 printf("DDR0: Multiple uncorrectable ECC events.\n");
213 printf("DDR0: Single uncorrectable ECC event.\n");
217 printf("DDR0: Multiple correctable ECC events.\n");
221 printf("DDR0: Single correctable ECC event.\n");
225 printf("Multiple accesses outside the defined"
226 " physical memory space detected\n");
228 printf("DDR0: Single access outside the defined"
229 " physical memory space detected.\n");
231 mfsdram(DDR0_01, val);
232 val = (val >> 8) & 0x7;
235 printf("DDR0: Write Out-of-Range command\n");
238 printf("DDR0: Read Out-of-Range command\n");
241 printf("DDR0: Masked write Out-of-Range command\n");
244 printf("DDR0: Wrap write Out-of-Range command\n");
247 printf("DDR0: Wrap read Out-of-Range command\n");
250 mfsdram(DDR0_01, value2);
251 printf("DDR0: No DDR0 error know 0x%lx %x\n", val, value2);
253 mfsdram(DDR0_23, val);
254 if (((val >> 16) & 0xff) && corr_ecc)
255 printf("DDR0: Syndrome for correctable ECC event 0x%lx\n",
257 mfsdram(DDR0_23, val);
258 if (((val >> 8) & 0xff) && uncorr_ecc)
259 printf("DDR0: Syndrome for uncorrectable ECC event 0x%lx\n",
261 mfsdram(DDR0_33, val);
263 printf("DDR0: Address of command that caused an "
264 "Out-of-Range interrupt %lx\n", val);
265 mfsdram(DDR0_34, val);
266 if (val && uncorr_ecc)
267 printf("DDR0: Address of uncorrectable ECC event %lx\n", val);
268 mfsdram(DDR0_35, val);
269 if (val && uncorr_ecc)
270 printf("DDR0: Address of uncorrectable ECC event %lx\n", val);
271 mfsdram(DDR0_36, val);
272 if (val && uncorr_ecc)
273 printf("DDR0: Data of uncorrectable ECC event 0x%08lx\n", val);
274 mfsdram(DDR0_37, val);
275 if (val && uncorr_ecc)
276 printf("DDR0: Data of uncorrectable ECC event 0x%08lx\n", val);
277 mfsdram(DDR0_38, val);
279 printf("DDR0: Address of correctable ECC event %lx\n", val);
280 mfsdram(DDR0_39, val);
282 printf("DDR0: Address of correctable ECC event %lx\n", val);
283 mfsdram(DDR0_40, val);
285 printf("DDR0: Data of correctable ECC event 0x%08lx\n", val);
286 mfsdram(DDR0_41, val);
288 printf("DDR0: Data of correctable ECC event 0x%08lx\n", val);
289 #endif /* CONFIG_440EPX */
290 #endif /* CONFIG_440 */
292 print_backtrace((unsigned long *)regs->gpr[1]);
293 panic("machine check");
296 void AlignmentException(struct pt_regs *regs)
298 #if defined(CONFIG_CMD_KGDB)
299 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
304 print_backtrace((unsigned long *)regs->gpr[1]);
305 panic("Alignment Exception");
308 void ProgramCheckException(struct pt_regs *regs)
312 #if defined(CONFIG_CMD_KGDB)
313 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
320 if( esr_val & ESR_PIL )
321 printf( "** Illegal Instruction **\n" );
322 else if( esr_val & ESR_PPR )
323 printf( "** Privileged Instruction **\n" );
324 else if( esr_val & ESR_PTR )
325 printf( "** Trap Instruction **\n" );
327 print_backtrace((unsigned long *)regs->gpr[1]);
328 panic("Program Check Exception");
331 void DecrementerPITException(struct pt_regs *regs)
334 * Reset PIT interrupt
336 mtspr(SPRN_TSR, 0x08000000);
339 * Call timer_interrupt routine in interrupts.c
341 timer_interrupt(NULL);
345 void UnknownException(struct pt_regs *regs)
347 #if defined(CONFIG_CMD_KGDB)
348 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
352 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
353 regs->nip, regs->msr, regs->trap);
357 void DebugException(struct pt_regs *regs)
359 printf("Debugger trap at @ %lx\n", regs->nip );
361 #if defined(CONFIG_CMD_BEDBUG)
362 do_bedbug_breakpoint( regs );
366 /* Probe an address by reading. If not present, return -1, otherwise
370 addr_probe(uint *addr)
375 __asm__ __volatile__( \
376 "1: lwz %0,0(%1)\n" \
380 ".section .fixup,\"ax\"\n" \
383 ".section __ex_table,\"a\"\n" \
387 : "=r" (retval) : "r"(addr));