1 // SPDX-License-Identifier: GPL-2.0+
3 * linux/arch/powerpc/kernel/traps.c
5 * Copyright 2007 Freescale Semiconductor.
6 * Copyright (C) 2003 Motorola
7 * Modified by Xianghua Xiao(x.xiao@motorola.com)
9 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
11 * Modified by Cort Dougan (cort@cs.nmt.edu)
12 * and Paul Mackerras (paulus@cs.anu.edu.au)
15 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
19 * This file handles the architecture-dependent parts of hardware exceptions
23 #include <asm/global_data.h>
24 #include <asm/ptrace.h>
29 #include <asm/processor.h>
31 DECLARE_GLOBAL_DATA_PTR;
33 /* Returns 0 if exception not found and fixup otherwise. */
34 extern unsigned long search_exception_table(unsigned long);
37 * End of addressable memory. This may be less than the actual
38 * amount of memory on the system if we're unable to keep all
39 * the memory mapped in.
41 #define END_OF_MEM (gd->ram_base + get_effective_memsize())
43 static __inline__ void set_tsr(unsigned long val)
45 asm volatile("mtspr 0x150, %0" : : "r" (val));
48 static __inline__ unsigned long get_esr(void)
51 asm volatile("mfspr %0, 0x03e" : "=r" (val) :);
55 #define ESR_MCI 0x80000000
56 #define ESR_PIL 0x08000000
57 #define ESR_PPR 0x04000000
58 #define ESR_PTR 0x02000000
59 #define ESR_DST 0x00800000
60 #define ESR_DIZ 0x00400000
61 #define ESR_U0F 0x00008000
64 * Trap & Exception support
67 static void print_backtrace(unsigned long *sp)
72 printf("Call backtrace: ");
74 if ((uint)sp > END_OF_MEM)
82 sp = (unsigned long *)*sp;
87 void show_regs(struct pt_regs *regs)
91 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
92 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
93 printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
94 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
95 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
96 regs->msr&MSR_IR ? 1 : 0,
97 regs->msr&MSR_DR ? 1 : 0);
100 for (i = 0; i < 32; i++) {
103 printf("GPR%02d: ", i);
106 printf("%08lX ", regs->gpr[i]);
114 static void _exception(int signr, struct pt_regs *regs)
117 print_backtrace((unsigned long *)regs->gpr[1]);
118 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
121 void CritcalInputException(struct pt_regs *regs)
123 panic("Critical Input Exception");
126 int machinecheck_count = 0;
127 int machinecheck_error = 0;
128 void MachineCheckException(struct pt_regs *regs)
131 unsigned int mcsr, mcsrr0, mcsrr1, mcar;
133 /* Probing PCI using config cycles cause this exception
134 * when a device is not present. Catch it and return to
135 * the PCI exception handler.
137 if ((fixup = search_exception_table(regs->nip)) != 0) {
142 mcsrr0 = mfspr(SPRN_MCSRR0);
143 mcsrr1 = mfspr(SPRN_MCSRR1);
144 mcsr = mfspr(SPRN_MCSR);
145 mcar = mfspr(SPRN_MCAR);
147 machinecheck_count++;
148 machinecheck_error=1;
150 #if defined(CONFIG_CMD_KGDB)
151 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
155 printf("Machine check in kernel mode.\n");
156 printf("Caused by (from mcsr): ");
157 printf("mcsr = 0x%08x\n", mcsr);
158 if (mcsr & 0x80000000)
159 printf("Machine check input pin\n");
160 if (mcsr & 0x40000000)
161 printf("Instruction cache parity error\n");
162 if (mcsr & 0x20000000)
163 printf("Data cache push parity error\n");
164 if (mcsr & 0x10000000)
165 printf("Data cache parity error\n");
166 if (mcsr & 0x00000080)
167 printf("Bus instruction address error\n");
168 if (mcsr & 0x00000040)
169 printf("Bus Read address error\n");
170 if (mcsr & 0x00000020)
171 printf("Bus Write address error\n");
172 if (mcsr & 0x00000010)
173 printf("Bus Instruction data bus error\n");
174 if (mcsr & 0x00000008)
175 printf("Bus Read data bus error\n");
176 if (mcsr & 0x00000004)
177 printf("Bus Write bus error\n");
178 if (mcsr & 0x00000002)
179 printf("Bus Instruction parity error\n");
180 if (mcsr & 0x00000001)
181 printf("Bus Read parity error\n");
184 printf("MCSR=0x%08x \tMCSRR0=0x%08x \nMCSRR1=0x%08x \tMCAR=0x%08x\n",
185 mcsr, mcsrr0, mcsrr1, mcar);
186 print_backtrace((unsigned long *)regs->gpr[1]);
187 if (machinecheck_count > 10) {
188 panic("machine check count too high\n");
191 if (machinecheck_count > 1) {
192 regs->nip += 4; /* skip offending instruction */
193 printf("Skipping current instr, Returning to 0x%08lx\n",
196 printf("Returning back to 0x%08lx\n",regs->nip);
200 void AlignmentException(struct pt_regs *regs)
202 #if defined(CONFIG_CMD_KGDB)
203 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
208 print_backtrace((unsigned long *)regs->gpr[1]);
209 panic("Alignment Exception");
212 void ProgramCheckException(struct pt_regs *regs)
216 #if defined(CONFIG_CMD_KGDB)
217 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
224 if( esr_val & ESR_PIL )
225 printf( "** Illegal Instruction **\n" );
226 else if( esr_val & ESR_PPR )
227 printf( "** Privileged Instruction **\n" );
228 else if( esr_val & ESR_PTR )
229 printf( "** Trap Instruction **\n" );
231 print_backtrace((unsigned long *)regs->gpr[1]);
232 panic("Program Check Exception");
235 void PITException(struct pt_regs *regs)
238 * Reset PIT interrupt
243 * Call timer_interrupt routine in interrupts.c
245 timer_interrupt(NULL);
248 void UnknownException(struct pt_regs *regs)
250 #if defined(CONFIG_CMD_KGDB)
251 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
255 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
256 regs->nip, regs->msr, regs->trap);
260 void ExtIntException(struct pt_regs *regs)
262 volatile ccsr_pic_t *pic = (void *)(CFG_SYS_MPC8xxx_PIC_ADDR);
266 #if defined(CONFIG_CMD_KGDB)
267 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
271 printf("External Interrupt Exception at PC: %lx, SR: %lx, vector=%lx",
272 regs->nip, regs->msr, regs->trap);
274 printf(" irq IACK0@%05x=%d\n",(int)&pic->iack0,vect);
276 print_backtrace((unsigned long *)regs->gpr[1]);
279 void DebugException(struct pt_regs *regs)
281 printf("Debugger trap at @ %lx\n", regs->nip );