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)
8 * fixed Machine Check Reasons by Reinhard Meyer (r.meyer@emk-elektronik.de)
10 * (C) Copyright 2000-2003
11 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
13 * SPDX-License-Identifier: GPL-2.0+
17 * This file handles the architecture-dependent parts of hardware exceptions
23 #include <asm/processor.h>
25 /* Returns 0 if exception not found and fixup otherwise. */
26 extern unsigned long search_exception_table(unsigned long);
28 /* THIS NEEDS CHANGING to use the board info structure.
30 #define END_OF_MEM 0x02000000
33 * Trap & Exception support
36 static void print_backtrace(unsigned long *sp)
41 printf("Call backtrace: ");
43 if ((uint)sp > END_OF_MEM)
51 sp = (unsigned long *)*sp;
56 void show_regs(struct pt_regs *regs)
60 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %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: %01x ME: %01x IR/DR: %01x%01x\n",
63 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
64 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
65 regs->msr&MSR_IR ? 1 : 0,
66 regs->msr&MSR_DR ? 1 : 0);
69 for (i = 0; i < 32; i++) {
72 printf("GPR%02d: ", i);
75 printf("%08lX ", regs->gpr[i]);
84 static void _exception(int signr, struct pt_regs *regs)
87 print_backtrace((unsigned long *)regs->gpr[1]);
88 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
91 void MachineCheckException(struct pt_regs *regs)
95 /* Probing PCI using config cycles cause this exception
96 * when a device is not present. Catch it and return to
97 * the PCI exception handler.
99 if ((fixup = search_exception_table(regs->nip)) != 0) {
104 #if defined(CONFIG_CMD_KGDB)
105 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
109 printf("Machine check in kernel mode.\n");
110 printf("Caused by (from msr): ");
111 printf("regs %p ",regs);
112 /* refer to 603e Manual (MPC603EUM/AD), chapter 4.5.2.1 */
113 switch( regs->msr & 0x000F0000)
115 case (0x80000000>>12) :
116 printf("Machine check signal - probably due to mm fault\n"
119 case (0x80000000>>13) :
120 printf("Transfer error ack signal\n");
122 case (0x80000000>>14) :
123 printf("Data parity signal\n");
125 case (0x80000000>>15) :
126 printf("Address parity signal\n");
129 printf("Unknown values in msr\n");
132 print_backtrace((unsigned long *)regs->gpr[1]);
133 panic("machine check");
136 void AlignmentException(struct pt_regs *regs)
138 #if defined(CONFIG_CMD_KGDB)
139 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
143 print_backtrace((unsigned long *)regs->gpr[1]);
144 panic("Alignment Exception");
147 void ProgramCheckException(struct pt_regs *regs)
149 #if defined(CONFIG_CMD_KGDB)
150 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
154 print_backtrace((unsigned long *)regs->gpr[1]);
155 panic("Program Check Exception");
158 void SoftEmuException(struct pt_regs *regs)
160 #if defined(CONFIG_CMD_KGDB)
161 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
165 print_backtrace((unsigned long *)regs->gpr[1]);
166 panic("Software Emulation Exception");
170 void UnknownException(struct pt_regs *regs)
172 #if defined(CONFIG_CMD_KGDB)
173 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
176 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
177 regs->nip, regs->msr, regs->trap);
181 #if defined(CONFIG_CMD_BEDBUG)
182 extern void do_bedbug_breakpoint(struct pt_regs *);
185 void DebugException(struct pt_regs *regs)
188 printf("Debugger trap at @ %lx\n", regs->nip );
190 #if defined(CONFIG_CMD_BEDBUG)
191 do_bedbug_breakpoint( regs );
195 /* Probe an address by reading. If not present, return -1, otherwise
198 int addr_probe(uint *addr)
203 __asm__ __volatile__( \
204 "1: lwz %0,0(%1)\n" \
208 ".section .fixup,\"ax\"\n" \
211 ".section __ex_table,\"a\"\n" \
215 : "=r" (retval) : "r"(addr));