1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
5 * Modified by Cort Dougan (cort@cs.nmt.edu)
6 * and Paul Mackerras (paulus@cs.anu.edu.au)
9 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
13 * This file handles the architecture-dependent parts of hardware exceptions
19 #include <asm/processor.h>
21 DECLARE_GLOBAL_DATA_PTR;
23 /* Returns 0 if exception not found and fixup otherwise. */
24 extern unsigned long search_exception_table(unsigned long);
27 * End of addressable memory. This may be less than the actual
28 * amount of memory on the system if we're unable to keep all
29 * the memory mapped in.
31 #define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize())
34 * Trap & Exception support
37 static void print_backtrace(unsigned long *sp)
42 printf("Call backtrace: ");
44 if ((uint) sp > END_OF_MEM)
53 sp = (unsigned long *)*sp;
58 void show_regs(struct pt_regs *regs)
62 printf("NIP: %08lX XER: %08lX LR: %08lX REGS:"
63 " %p TRAP: %04lx DAR: %08lX\n",
64 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
65 printf("MSR: %08lx EE: %01x PR: %01x FP:"
66 " %01x ME: %01x IR/DR: %01x%01x\n",
67 regs->msr, regs->msr & MSR_EE ? 1 : 0,
68 regs->msr & MSR_PR ? 1 : 0, regs->msr & MSR_FP ? 1 : 0,
69 regs->msr & MSR_ME ? 1 : 0, regs->msr & MSR_IR ? 1 : 0,
70 regs->msr & MSR_DR ? 1 : 0);
73 for (i = 0; i < 32; i++) {
75 printf("GPR%02d: ", i);
78 printf("%08lX ", regs->gpr[i]);
86 static void _exception(int signr, struct pt_regs *regs)
89 print_backtrace((unsigned long *)regs->gpr[1]);
90 panic("Exception in kernel pc %lx signal %d", regs->nip, signr);
93 void MachineCheckException(struct pt_regs *regs)
97 /* Probing PCI using config cycles cause this exception
98 * when a device is not present. Catch it and return to
99 * the PCI exception handler.
101 if ((fixup = search_exception_table(regs->nip)) != 0) {
106 #if defined(CONFIG_CMD_KGDB)
107 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
111 printf("Machine check in kernel mode.\n");
112 printf("Caused by (from msr): ");
113 printf("regs %p ", regs);
114 switch ( regs->msr & 0x001F0000) {
115 case (0x80000000>>11):
116 printf("MSS error. MSSSR0: %08x\n", mfspr(SPRN_MSSSR0));
118 case (0x80000000>>12):
119 printf("Machine check signal - probably due to mm fault\n"
122 case (0x80000000 >> 13):
123 printf("Transfer error ack signal\n");
125 case (0x80000000 >> 14):
126 printf("Data parity signal\n");
128 case (0x80000000 >> 15):
129 printf("Address parity signal\n");
132 printf("Unknown values in msr\n");
135 print_backtrace((unsigned long *)regs->gpr[1]);
136 panic("machine check");
139 void AlignmentException(struct pt_regs *regs)
141 #if defined(CONFIG_CMD_KGDB)
142 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
146 print_backtrace((unsigned long *)regs->gpr[1]);
147 panic("Alignment Exception");
150 void ProgramCheckException(struct pt_regs *regs)
152 unsigned char *p = regs ? (unsigned char *)(regs->nip) : NULL;
155 #if defined(CONFIG_CMD_KGDB)
156 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
161 p = (unsigned char *)((unsigned long)p & 0xFFFFFFE0);
163 for (i = 0; i < 256; i += 16) {
164 printf("%08x: ", (unsigned int)p + i);
165 for (j = 0; j < 16; j++) {
166 printf("%02x ", p[i + j]);
171 print_backtrace((unsigned long *)regs->gpr[1]);
172 panic("Program Check Exception");
175 void SoftEmuException(struct pt_regs *regs)
177 #if defined(CONFIG_CMD_KGDB)
178 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
182 print_backtrace((unsigned long *)regs->gpr[1]);
183 panic("Software Emulation Exception");
186 void UnknownException(struct pt_regs *regs)
188 #if defined(CONFIG_CMD_KGDB)
189 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
192 printf("UnknownException regs@%lx\n", (ulong)regs);
193 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
194 regs->nip, regs->msr, regs->trap);