2 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
4 * Modified by Cort Dougan (cort@cs.nmt.edu)
5 * and Paul Mackerras (paulus@cs.anu.edu.au)
8 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
10 * SPDX-License-Identifier: GPL-2.0+
14 * This file handles the architecture-dependent parts of hardware exceptions
20 #include <asm/processor.h>
22 DECLARE_GLOBAL_DATA_PTR;
24 /* Returns 0 if exception not found and fixup otherwise. */
25 extern unsigned long search_exception_table(unsigned long);
28 * End of addressable memory. This may be less than the actual
29 * amount of memory on the system if we're unable to keep all
30 * the memory mapped in.
32 extern ulong get_effective_memsize(void);
33 #define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize())
36 * Trap & Exception support
39 static void print_backtrace(unsigned long *sp)
44 printf("Call backtrace: ");
46 if ((uint) sp > END_OF_MEM)
55 sp = (unsigned long *)*sp;
60 void show_regs(struct pt_regs *regs)
64 printf("NIP: %08lX XER: %08lX LR: %08lX REGS:"
65 " %p TRAP: %04lx DAR: %08lX\n",
66 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
67 printf("MSR: %08lx EE: %01x PR: %01x FP:"
68 " %01x ME: %01x IR/DR: %01x%01x\n",
69 regs->msr, regs->msr & MSR_EE ? 1 : 0,
70 regs->msr & MSR_PR ? 1 : 0, regs->msr & MSR_FP ? 1 : 0,
71 regs->msr & MSR_ME ? 1 : 0, regs->msr & MSR_IR ? 1 : 0,
72 regs->msr & MSR_DR ? 1 : 0);
75 for (i = 0; i < 32; i++) {
77 printf("GPR%02d: ", i);
80 printf("%08lX ", regs->gpr[i]);
88 static void _exception(int signr, struct pt_regs *regs)
91 print_backtrace((unsigned long *)regs->gpr[1]);
92 panic("Exception in kernel pc %lx signal %d", regs->nip, signr);
95 void MachineCheckException(struct pt_regs *regs)
99 /* Probing PCI using config cycles cause this exception
100 * when a device is not present. Catch it and return to
101 * the PCI exception handler.
103 if ((fixup = search_exception_table(regs->nip)) != 0) {
108 #if defined(CONFIG_CMD_KGDB)
109 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
113 printf("Machine check in kernel mode.\n");
114 printf("Caused by (from msr): ");
115 printf("regs %p ", regs);
116 switch ( regs->msr & 0x001F0000) {
117 case (0x80000000>>11):
118 printf("MSS error. MSSSR0: %08x\n", mfspr(SPRN_MSSSR0));
120 case (0x80000000>>12):
121 printf("Machine check signal - probably due to mm fault\n"
124 case (0x80000000 >> 13):
125 printf("Transfer error ack signal\n");
127 case (0x80000000 >> 14):
128 printf("Data parity signal\n");
130 case (0x80000000 >> 15):
131 printf("Address parity signal\n");
134 printf("Unknown values in msr\n");
137 print_backtrace((unsigned long *)regs->gpr[1]);
138 panic("machine check");
141 void AlignmentException(struct pt_regs *regs)
143 #if defined(CONFIG_CMD_KGDB)
144 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
148 print_backtrace((unsigned long *)regs->gpr[1]);
149 panic("Alignment Exception");
152 void ProgramCheckException(struct pt_regs *regs)
154 unsigned char *p = regs ? (unsigned char *)(regs->nip) : NULL;
157 #if defined(CONFIG_CMD_KGDB)
158 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
163 p = (unsigned char *)((unsigned long)p & 0xFFFFFFE0);
165 for (i = 0; i < 256; i += 16) {
166 printf("%08x: ", (unsigned int)p + i);
167 for (j = 0; j < 16; j++) {
168 printf("%02x ", p[i + j]);
173 print_backtrace((unsigned long *)regs->gpr[1]);
174 panic("Program Check Exception");
177 void SoftEmuException(struct pt_regs *regs)
179 #if defined(CONFIG_CMD_KGDB)
180 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
184 print_backtrace((unsigned long *)regs->gpr[1]);
185 panic("Software Emulation Exception");
188 void UnknownException(struct pt_regs *regs)
190 #if defined(CONFIG_CMD_KGDB)
191 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
194 printf("UnknownException regs@%lx\n", (ulong)regs);
195 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
196 regs->nip, regs->msr, regs->trap);
201 * Probe an address by reading.
202 * If not present, return -1,
203 * otherwise return 0.
205 int addr_probe(uint *addr)