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 #if defined(CONFIG_CMD_BEDBUG)
25 extern void do_bedbug_breakpoint(struct pt_regs *);
28 /* Returns 0 if exception not found and fixup otherwise. */
29 extern unsigned long search_exception_table(unsigned long);
31 /* THIS NEEDS CHANGING to use the board info structure.
33 #define END_OF_MEM 0x02000000
36 * Trap & Exception support
39 static void print_backtrace(unsigned long *sp)
44 printf("Call backtrace: ");
46 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: %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: %01x ME: %01x IR/DR: %01x%01x\n",
66 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
67 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
68 regs->msr&MSR_IR ? 1 : 0,
69 regs->msr&MSR_DR ? 1 : 0);
72 for (i = 0; i < 32; i++) {
75 printf("GPR%02d: ", i);
78 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 & 0x000F0000) {
116 case (0x80000000>>12):
117 printf("Machine check signal - probably due to mm fault\n"
120 case (0x80000000>>13):
121 printf("Transfer error ack signal\n");
123 case (0x80000000>>14):
124 printf("Data parity signal\n");
126 case (0x80000000>>15):
127 printf("Address parity signal\n");
130 printf("Unknown values in msr\n");
133 print_backtrace((unsigned long *)regs->gpr[1]);
134 panic("machine check");
137 void AlignmentException(struct pt_regs *regs)
139 #if defined(CONFIG_CMD_KGDB)
140 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
144 print_backtrace((unsigned long *)regs->gpr[1]);
145 panic("Alignment Exception");
148 void ProgramCheckException(struct pt_regs *regs)
150 #if defined(CONFIG_CMD_KGDB)
151 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
155 print_backtrace((unsigned long *)regs->gpr[1]);
156 panic("Program Check Exception");
159 void SoftEmuException(struct pt_regs *regs)
161 #if defined(CONFIG_CMD_KGDB)
162 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
166 print_backtrace((unsigned long *)regs->gpr[1]);
167 panic("Software Emulation Exception");
171 void UnknownException(struct pt_regs *regs)
173 #if defined(CONFIG_CMD_KGDB)
174 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
177 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
178 regs->nip, regs->msr, regs->trap);
182 void DebugException(struct pt_regs *regs)
184 printf("Debugger trap at @ %lx\n", regs->nip );
186 #if defined(CONFIG_CMD_BEDBUG)
187 do_bedbug_breakpoint( regs );
191 /* Probe an address by reading. If not present, return -1, otherwise
194 int addr_probe(uint *addr)
199 __asm__ __volatile__( \
200 "1: lwz %0,0(%1)\n" \
204 ".section .fixup,\"ax\"\n" \
207 ".section __ex_table,\"a\"\n" \
211 : "=r" (retval) : "r"(addr));