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 /* Returns 0 if exception not found and fixup otherwise. */
25 extern unsigned long search_exception_table(unsigned long);
27 /* THIS NEEDS CHANGING to use the board info structure.
29 #define END_OF_MEM 0x02000000
32 * Trap & Exception support
35 static void print_backtrace(unsigned long *sp)
40 printf("Call backtrace: ");
42 if ((uint)sp > END_OF_MEM)
50 sp = (unsigned long *)*sp;
55 void show_regs(struct pt_regs *regs)
59 printf("NIP: %08lX XER: %08lX LR: %08lX REGS:"
60 " %p TRAP: %04lx DAR: %08lX\n",
61 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
62 printf("MSR: %08lx EE: %01x PR: %01x FP:"
63 " %01x ME: %01x IR/DR: %01x%01x\n",
64 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
65 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
66 regs->msr&MSR_IR ? 1 : 0,
67 regs->msr&MSR_DR ? 1 : 0);
70 for (i = 0; i < 32; i++) {
73 printf("GPR%02d: ", i);
76 printf("%08lX ", regs->gpr[i]);
85 static void _exception(int signr, struct pt_regs *regs)
88 print_backtrace((unsigned long *)regs->gpr[1]);
89 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
92 void MachineCheckException(struct pt_regs *regs)
96 /* Probing PCI using config cycles cause this exception
97 * when a device is not present. Catch it and return to
98 * the PCI exception handler.
100 if ((fixup = search_exception_table(regs->nip)) != 0) {
105 #if defined(CONFIG_CMD_KGDB)
106 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
110 printf("Machine check in kernel mode.\n");
111 printf("Caused by (from msr): ");
112 printf("regs %p ",regs);
113 switch( regs->msr & 0x000F0000) {
114 case (0x80000000>>12):
115 printf("Machine check signal - probably due to mm fault\n"
118 case (0x80000000>>13):
119 printf("Transfer error ack signal\n");
121 case (0x80000000>>14):
122 printf("Data parity signal\n");
124 case (0x80000000>>15):
125 printf("Address parity signal\n");
128 printf("Unknown values in msr\n");
131 print_backtrace((unsigned long *)regs->gpr[1]);
132 panic("machine check");
135 void AlignmentException(struct pt_regs *regs)
137 #if defined(CONFIG_CMD_KGDB)
138 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
142 print_backtrace((unsigned long *)regs->gpr[1]);
143 panic("Alignment Exception");
146 void ProgramCheckException(struct pt_regs *regs)
148 unsigned char *p = regs ? (unsigned char *)(regs->nip) : NULL;
151 #if defined(CONFIG_CMD_KGDB)
152 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
157 p = (unsigned char *) ((unsigned long)p & 0xFFFFFFE0);
159 for (i = 0; i < 256; i+=16) {
160 printf("%08x: ", (unsigned int)p+i);
161 for (j = 0; j < 16; j++) {
162 printf("%02x ", p[i+j]);
167 print_backtrace((unsigned long *)regs->gpr[1]);
168 panic("Program Check Exception");
171 void SoftEmuException(struct pt_regs *regs)
173 #if defined(CONFIG_CMD_KGDB)
174 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
178 print_backtrace((unsigned long *)regs->gpr[1]);
179 panic("Software Emulation Exception");
182 void UnknownException(struct pt_regs *regs)
184 #if defined(CONFIG_CMD_KGDB)
185 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
188 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
189 regs->nip, regs->msr, regs->trap);
193 /* Probe an address by reading. If not present, return -1, otherwise
196 int addr_probe(uint *addr)
201 __asm__ __volatile__( \
202 "1: lwz %0,0(%1)\n" \
206 ".section .fixup,\"ax\"\n" \
209 ".section __ex_table,\"a\"\n" \
213 : "=r" (retval) : "r"(addr));