blob: a1c111ec171bc3bc0bbeb0e4b1e92c310c6fdcc2 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk9c53f402003-10-15 23:53:47 +00002/*
Stefan Roese88fbf932010-04-15 16:07:28 +02003 * linux/arch/powerpc/kernel/traps.c
wdenk9c53f402003-10-15 23:53:47 +00004 *
Andy Flemingf08233c2007-08-14 01:34:21 -05005 * Copyright 2007 Freescale Semiconductor.
wdenk9c53f402003-10-15 23:53:47 +00006 * Copyright (C) 2003 Motorola
7 * Modified by Xianghua Xiao(x.xiao@motorola.com)
8 *
9 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
10 *
11 * Modified by Cort Dougan (cort@cs.nmt.edu)
12 * and Paul Mackerras (paulus@cs.anu.edu.au)
13 *
14 * (C) Copyright 2000
15 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk9c53f402003-10-15 23:53:47 +000016 */
17
18/*
19 * This file handles the architecture-dependent parts of hardware exceptions
20 */
21
Tom Rinidec7ea02024-05-20 13:35:03 -060022#include <asm/ppc.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060023#include <asm/global_data.h>
Simon Glass6b9f0102020-05-10 11:40:06 -060024#include <asm/ptrace.h>
wdenk9c53f402003-10-15 23:53:47 +000025#include <command.h>
Simon Glass8e16b1e2019-12-28 10:45:05 -070026#include <init.h>
Simon Glass9b61c7c2019-11-14 12:57:41 -070027#include <irq_func.h>
Mike Frysinger629d88b2010-02-08 15:30:16 -050028#include <kgdb.h>
wdenk9c53f402003-10-15 23:53:47 +000029#include <asm/processor.h>
30
Wolfgang Denk6405a152006-03-31 18:32:53 +020031DECLARE_GLOBAL_DATA_PTR;
32
wdenk9c53f402003-10-15 23:53:47 +000033/* Returns 0 if exception not found and fixup otherwise. */
34extern unsigned long search_exception_table(unsigned long);
35
wdenk492b9e72004-08-01 23:02:45 +000036/*
Becky Bruce306b4e82008-05-14 13:10:04 -050037 * 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.
wdenk9c53f402003-10-15 23:53:47 +000040 */
Stefan Roesea13a2aa2020-08-12 13:16:36 +020041#define END_OF_MEM (gd->ram_base + get_effective_memsize())
wdenk9c53f402003-10-15 23:53:47 +000042
43static __inline__ void set_tsr(unsigned long val)
44{
45 asm volatile("mtspr 0x150, %0" : : "r" (val));
46}
47
48static __inline__ unsigned long get_esr(void)
49{
50 unsigned long val;
51 asm volatile("mfspr %0, 0x03e" : "=r" (val) :);
52 return val;
53}
54
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
62
wdenk9c53f402003-10-15 23:53:47 +000063/*
64 * Trap & Exception support
65 */
66
Kim Phillipse16737f2012-10-29 13:34:29 +000067static void print_backtrace(unsigned long *sp)
wdenk9c53f402003-10-15 23:53:47 +000068{
69 int cnt = 0;
70 unsigned long i;
71
72 printf("Call backtrace: ");
73 while (sp) {
74 if ((uint)sp > END_OF_MEM)
75 break;
76
77 i = sp[1];
78 if (cnt++ % 7 == 0)
79 printf("\n");
80 printf("%08lX ", i);
81 if (cnt > 32) break;
82 sp = (unsigned long *)*sp;
83 }
84 printf("\n");
85}
86
Kim Phillipse16737f2012-10-29 13:34:29 +000087void show_regs(struct pt_regs *regs)
wdenk9c53f402003-10-15 23:53:47 +000088{
89 int i;
90
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);
98
99 printf("\n");
100 for (i = 0; i < 32; i++) {
101 if ((i % 8) == 0)
102 {
103 printf("GPR%02d: ", i);
104 }
105
106 printf("%08lX ", regs->gpr[i]);
107 if ((i % 8) == 7)
108 {
109 printf("\n");
110 }
111 }
112}
113
Kim Phillipse16737f2012-10-29 13:34:29 +0000114static void _exception(int signr, struct pt_regs *regs)
wdenk9c53f402003-10-15 23:53:47 +0000115{
116 show_regs(regs);
117 print_backtrace((unsigned long *)regs->gpr[1]);
118 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
119}
120
Kim Phillipse16737f2012-10-29 13:34:29 +0000121void CritcalInputException(struct pt_regs *regs)
wdenk9c53f402003-10-15 23:53:47 +0000122{
123 panic("Critical Input Exception");
124}
125
Andy Flemingf08233c2007-08-14 01:34:21 -0500126int machinecheck_count = 0;
127int machinecheck_error = 0;
Kim Phillipse16737f2012-10-29 13:34:29 +0000128void MachineCheckException(struct pt_regs *regs)
wdenk9c53f402003-10-15 23:53:47 +0000129{
130 unsigned long fixup;
Andy Flemingf08233c2007-08-14 01:34:21 -0500131 unsigned int mcsr, mcsrr0, mcsrr1, mcar;
wdenk9c53f402003-10-15 23:53:47 +0000132
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.
136 */
137 if ((fixup = search_exception_table(regs->nip)) != 0) {
138 regs->nip = fixup;
139 return;
140 }
141
Andy Flemingf08233c2007-08-14 01:34:21 -0500142 mcsrr0 = mfspr(SPRN_MCSRR0);
143 mcsrr1 = mfspr(SPRN_MCSRR1);
144 mcsr = mfspr(SPRN_MCSR);
145 mcar = mfspr(SPRN_MCAR);
146
147 machinecheck_count++;
148 machinecheck_error=1;
149
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500150#if defined(CONFIG_CMD_KGDB)
wdenk9c53f402003-10-15 23:53:47 +0000151 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
152 return;
153#endif
154
155 printf("Machine check in kernel mode.\n");
Andy Flemingf08233c2007-08-14 01:34:21 -0500156 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");
182
wdenk9c53f402003-10-15 23:53:47 +0000183 show_regs(regs);
Andy Flemingf08233c2007-08-14 01:34:21 -0500184 printf("MCSR=0x%08x \tMCSRR0=0x%08x \nMCSRR1=0x%08x \tMCAR=0x%08x\n",
185 mcsr, mcsrr0, mcsrr1, mcar);
wdenk9c53f402003-10-15 23:53:47 +0000186 print_backtrace((unsigned long *)regs->gpr[1]);
Andy Flemingf08233c2007-08-14 01:34:21 -0500187 if (machinecheck_count > 10) {
188 panic("machine check count too high\n");
189 }
190
191 if (machinecheck_count > 1) {
192 regs->nip += 4; /* skip offending instruction */
Andrew Klossnere4ad4542008-07-07 06:41:14 -0700193 printf("Skipping current instr, Returning to 0x%08lx\n",
Andy Flemingf08233c2007-08-14 01:34:21 -0500194 regs->nip);
195 } else {
Andrew Klossnere4ad4542008-07-07 06:41:14 -0700196 printf("Returning back to 0x%08lx\n",regs->nip);
Andy Flemingf08233c2007-08-14 01:34:21 -0500197 }
wdenk9c53f402003-10-15 23:53:47 +0000198}
199
Kim Phillipse16737f2012-10-29 13:34:29 +0000200void AlignmentException(struct pt_regs *regs)
wdenk9c53f402003-10-15 23:53:47 +0000201{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500202#if defined(CONFIG_CMD_KGDB)
wdenk9c53f402003-10-15 23:53:47 +0000203 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
204 return;
205#endif
206
207 show_regs(regs);
208 print_backtrace((unsigned long *)regs->gpr[1]);
209 panic("Alignment Exception");
210}
211
Kim Phillipse16737f2012-10-29 13:34:29 +0000212void ProgramCheckException(struct pt_regs *regs)
wdenk9c53f402003-10-15 23:53:47 +0000213{
214 long esr_val;
215
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500216#if defined(CONFIG_CMD_KGDB)
wdenk9c53f402003-10-15 23:53:47 +0000217 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
218 return;
219#endif
220
221 show_regs(regs);
222
223 esr_val = get_esr();
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" );
230
231 print_backtrace((unsigned long *)regs->gpr[1]);
232 panic("Program Check Exception");
233}
234
Kim Phillipse16737f2012-10-29 13:34:29 +0000235void PITException(struct pt_regs *regs)
wdenk9c53f402003-10-15 23:53:47 +0000236{
237 /*
238 * Reset PIT interrupt
239 */
240 set_tsr(0x0c000000);
241
242 /*
243 * Call timer_interrupt routine in interrupts.c
244 */
245 timer_interrupt(NULL);
246}
247
Kim Phillipse16737f2012-10-29 13:34:29 +0000248void UnknownException(struct pt_regs *regs)
wdenk9c53f402003-10-15 23:53:47 +0000249{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500250#if defined(CONFIG_CMD_KGDB)
wdenk9c53f402003-10-15 23:53:47 +0000251 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
252 return;
253#endif
254
255 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
256 regs->nip, regs->msr, regs->trap);
257 _exception(0, regs);
258}
Scott Woode957bd72009-08-20 17:45:00 -0500259
Kim Phillipse16737f2012-10-29 13:34:29 +0000260void ExtIntException(struct pt_regs *regs)
Andy Flemingf08233c2007-08-14 01:34:21 -0500261{
Tom Rinid5c3bf22022-10-28 20:27:12 -0400262 volatile ccsr_pic_t *pic = (void *)(CFG_SYS_MPC8xxx_PIC_ADDR);
Kumar Gala0a7a0972007-11-29 02:10:09 -0600263
Andy Flemingf08233c2007-08-14 01:34:21 -0500264 uint vect;
265
266#if defined(CONFIG_CMD_KGDB)
267 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
268 return;
269#endif
270
271 printf("External Interrupt Exception at PC: %lx, SR: %lx, vector=%lx",
272 regs->nip, regs->msr, regs->trap);
273 vect = pic->iack0;
Andrew Klossnere4ad4542008-07-07 06:41:14 -0700274 printf(" irq IACK0@%05x=%d\n",(int)&pic->iack0,vect);
Andy Flemingf08233c2007-08-14 01:34:21 -0500275 show_regs(regs);
276 print_backtrace((unsigned long *)regs->gpr[1]);
Andy Flemingf08233c2007-08-14 01:34:21 -0500277}
wdenk9c53f402003-10-15 23:53:47 +0000278
Kim Phillipse16737f2012-10-29 13:34:29 +0000279void DebugException(struct pt_regs *regs)
wdenk9c53f402003-10-15 23:53:47 +0000280{
281 printf("Debugger trap at @ %lx\n", regs->nip );
282 show_regs(regs);
wdenk9c53f402003-10-15 23:53:47 +0000283}