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 #define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize())
35 * Trap & Exception support
38 static void print_backtrace(unsigned long *sp)
43 printf("Call backtrace: ");
45 if ((uint) sp > END_OF_MEM)
54 sp = (unsigned long *)*sp;
59 void show_regs(struct pt_regs *regs)
63 printf("NIP: %08lX XER: %08lX LR: %08lX REGS:"
64 " %p TRAP: %04lx DAR: %08lX\n",
65 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
66 printf("MSR: %08lx EE: %01x PR: %01x FP:"
67 " %01x ME: %01x IR/DR: %01x%01x\n",
68 regs->msr, regs->msr & MSR_EE ? 1 : 0,
69 regs->msr & MSR_PR ? 1 : 0, regs->msr & MSR_FP ? 1 : 0,
70 regs->msr & MSR_ME ? 1 : 0, regs->msr & MSR_IR ? 1 : 0,
71 regs->msr & MSR_DR ? 1 : 0);
74 for (i = 0; i < 32; i++) {
76 printf("GPR%02d: ", i);
79 printf("%08lX ", regs->gpr[i]);
87 static void _exception(int signr, struct pt_regs *regs)
90 print_backtrace((unsigned long *)regs->gpr[1]);
91 panic("Exception in kernel pc %lx signal %d", regs->nip, signr);
94 void MachineCheckException(struct pt_regs *regs)
98 /* Probing PCI using config cycles cause this exception
99 * when a device is not present. Catch it and return to
100 * the PCI exception handler.
102 if ((fixup = search_exception_table(regs->nip)) != 0) {
107 #if defined(CONFIG_CMD_KGDB)
108 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
112 printf("Machine check in kernel mode.\n");
113 printf("Caused by (from msr): ");
114 printf("regs %p ", regs);
115 switch ( regs->msr & 0x001F0000) {
116 case (0x80000000>>11):
117 printf("MSS error. MSSSR0: %08x\n", mfspr(SPRN_MSSSR0));
119 case (0x80000000>>12):
120 printf("Machine check signal - probably due to mm fault\n"
123 case (0x80000000 >> 13):
124 printf("Transfer error ack signal\n");
126 case (0x80000000 >> 14):
127 printf("Data parity signal\n");
129 case (0x80000000 >> 15):
130 printf("Address parity signal\n");
133 printf("Unknown values in msr\n");
136 print_backtrace((unsigned long *)regs->gpr[1]);
137 panic("machine check");
140 void AlignmentException(struct pt_regs *regs)
142 #if defined(CONFIG_CMD_KGDB)
143 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
147 print_backtrace((unsigned long *)regs->gpr[1]);
148 panic("Alignment Exception");
151 void ProgramCheckException(struct pt_regs *regs)
153 unsigned char *p = regs ? (unsigned char *)(regs->nip) : NULL;
156 #if defined(CONFIG_CMD_KGDB)
157 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
162 p = (unsigned char *)((unsigned long)p & 0xFFFFFFE0);
164 for (i = 0; i < 256; i += 16) {
165 printf("%08x: ", (unsigned int)p + i);
166 for (j = 0; j < 16; j++) {
167 printf("%02x ", p[i + j]);
172 print_backtrace((unsigned long *)regs->gpr[1]);
173 panic("Program Check Exception");
176 void SoftEmuException(struct pt_regs *regs)
178 #if defined(CONFIG_CMD_KGDB)
179 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
183 print_backtrace((unsigned long *)regs->gpr[1]);
184 panic("Software Emulation Exception");
187 void UnknownException(struct pt_regs *regs)
189 #if defined(CONFIG_CMD_KGDB)
190 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
193 printf("UnknownException regs@%lx\n", (ulong)regs);
194 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
195 regs->nip, regs->msr, regs->trap);
200 * Probe an address by reading.
201 * If not present, return -1,
202 * otherwise return 0.
204 int addr_probe(uint *addr)