blob: 241ebd5657c7b852b21e12131935a995615d7093 [file] [log] [blame]
wdenk42d1f032003-10-15 23:53:47 +00001/*
2 * linux/arch/ppc/kernel/traps.c
3 *
Andy Fleming61a21e92007-08-14 01:34:21 -05004 * Copyright 2007 Freescale Semiconductor.
wdenk42d1f032003-10-15 23:53:47 +00005 * Copyright (C) 2003 Motorola
6 * Modified by Xianghua Xiao(x.xiao@motorola.com)
7 *
8 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
9 *
10 * Modified by Cort Dougan (cort@cs.nmt.edu)
11 * and Paul Mackerras (paulus@cs.anu.edu.au)
12 *
13 * (C) Copyright 2000
14 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
15 *
16 * See file CREDITS for list of people who contributed to this
17 * project.
18 *
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License as
21 * published by the Free Software Foundation; either version 2 of
22 * the License, or (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wdenk9aea9532004-08-01 23:02:45 +000026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenk42d1f032003-10-15 23:53:47 +000027 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
33 */
34
35/*
36 * This file handles the architecture-dependent parts of hardware exceptions
37 */
38
39#include <common.h>
40#include <command.h>
41#include <asm/processor.h>
42
Wolfgang Denkd87080b2006-03-31 18:32:53 +020043DECLARE_GLOBAL_DATA_PTR;
44
wdenk42d1f032003-10-15 23:53:47 +000045/* Returns 0 if exception not found and fixup otherwise. */
46extern unsigned long search_exception_table(unsigned long);
47
wdenk9aea9532004-08-01 23:02:45 +000048/*
Becky Bruce3b9519f2008-05-14 13:10:04 -050049 * End of addressable memory. This may be less than the actual
50 * amount of memory on the system if we're unable to keep all
51 * the memory mapped in.
wdenk42d1f032003-10-15 23:53:47 +000052 */
Becky Bruce3b9519f2008-05-14 13:10:04 -050053extern ulong get_effective_memsize(void);
54#define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize())
wdenk42d1f032003-10-15 23:53:47 +000055
56static __inline__ void set_tsr(unsigned long val)
57{
58 asm volatile("mtspr 0x150, %0" : : "r" (val));
59}
60
61static __inline__ unsigned long get_esr(void)
62{
63 unsigned long val;
64 asm volatile("mfspr %0, 0x03e" : "=r" (val) :);
65 return val;
66}
67
68#define ESR_MCI 0x80000000
69#define ESR_PIL 0x08000000
70#define ESR_PPR 0x04000000
71#define ESR_PTR 0x02000000
72#define ESR_DST 0x00800000
73#define ESR_DIZ 0x00400000
74#define ESR_U0F 0x00008000
75
Jon Loeliger44312832007-07-09 19:06:00 -050076#if defined(CONFIG_CMD_BEDBUG)
wdenk42d1f032003-10-15 23:53:47 +000077extern void do_bedbug_breakpoint(struct pt_regs *);
78#endif
79
80/*
81 * Trap & Exception support
82 */
83
84void
85print_backtrace(unsigned long *sp)
86{
87 int cnt = 0;
88 unsigned long i;
89
90 printf("Call backtrace: ");
91 while (sp) {
92 if ((uint)sp > END_OF_MEM)
93 break;
94
95 i = sp[1];
96 if (cnt++ % 7 == 0)
97 printf("\n");
98 printf("%08lX ", i);
99 if (cnt > 32) break;
100 sp = (unsigned long *)*sp;
101 }
102 printf("\n");
103}
104
105void show_regs(struct pt_regs * regs)
106{
107 int i;
108
109 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
110 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
111 printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
112 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
113 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
114 regs->msr&MSR_IR ? 1 : 0,
115 regs->msr&MSR_DR ? 1 : 0);
116
117 printf("\n");
118 for (i = 0; i < 32; i++) {
119 if ((i % 8) == 0)
120 {
121 printf("GPR%02d: ", i);
122 }
123
124 printf("%08lX ", regs->gpr[i]);
125 if ((i % 8) == 7)
126 {
127 printf("\n");
128 }
129 }
130}
131
132
133void
134_exception(int signr, struct pt_regs *regs)
135{
136 show_regs(regs);
137 print_backtrace((unsigned long *)regs->gpr[1]);
138 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
139}
140
141void
142CritcalInputException(struct pt_regs *regs)
143{
144 panic("Critical Input Exception");
145}
146
Andy Fleming61a21e92007-08-14 01:34:21 -0500147int machinecheck_count = 0;
148int machinecheck_error = 0;
wdenk42d1f032003-10-15 23:53:47 +0000149void
150MachineCheckException(struct pt_regs *regs)
151{
152 unsigned long fixup;
Andy Fleming61a21e92007-08-14 01:34:21 -0500153 unsigned int mcsr, mcsrr0, mcsrr1, mcar;
wdenk42d1f032003-10-15 23:53:47 +0000154
155 /* Probing PCI using config cycles cause this exception
156 * when a device is not present. Catch it and return to
157 * the PCI exception handler.
158 */
159 if ((fixup = search_exception_table(regs->nip)) != 0) {
160 regs->nip = fixup;
161 return;
162 }
163
Andy Fleming61a21e92007-08-14 01:34:21 -0500164 mcsrr0 = mfspr(SPRN_MCSRR0);
165 mcsrr1 = mfspr(SPRN_MCSRR1);
166 mcsr = mfspr(SPRN_MCSR);
167 mcar = mfspr(SPRN_MCAR);
168
169 machinecheck_count++;
170 machinecheck_error=1;
171
Jon Loeliger44312832007-07-09 19:06:00 -0500172#if defined(CONFIG_CMD_KGDB)
wdenk42d1f032003-10-15 23:53:47 +0000173 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
174 return;
175#endif
176
177 printf("Machine check in kernel mode.\n");
Andy Fleming61a21e92007-08-14 01:34:21 -0500178 printf("Caused by (from mcsr): ");
179 printf("mcsr = 0x%08x\n", mcsr);
180 if (mcsr & 0x80000000)
181 printf("Machine check input pin\n");
182 if (mcsr & 0x40000000)
183 printf("Instruction cache parity error\n");
184 if (mcsr & 0x20000000)
185 printf("Data cache push parity error\n");
186 if (mcsr & 0x10000000)
187 printf("Data cache parity error\n");
188 if (mcsr & 0x00000080)
189 printf("Bus instruction address error\n");
190 if (mcsr & 0x00000040)
191 printf("Bus Read address error\n");
192 if (mcsr & 0x00000020)
193 printf("Bus Write address error\n");
194 if (mcsr & 0x00000010)
195 printf("Bus Instruction data bus error\n");
196 if (mcsr & 0x00000008)
197 printf("Bus Read data bus error\n");
198 if (mcsr & 0x00000004)
199 printf("Bus Write bus error\n");
200 if (mcsr & 0x00000002)
201 printf("Bus Instruction parity error\n");
202 if (mcsr & 0x00000001)
203 printf("Bus Read parity error\n");
204
wdenk42d1f032003-10-15 23:53:47 +0000205 show_regs(regs);
Andy Fleming61a21e92007-08-14 01:34:21 -0500206 printf("MCSR=0x%08x \tMCSRR0=0x%08x \nMCSRR1=0x%08x \tMCAR=0x%08x\n",
207 mcsr, mcsrr0, mcsrr1, mcar);
wdenk42d1f032003-10-15 23:53:47 +0000208 print_backtrace((unsigned long *)regs->gpr[1]);
Andy Fleming61a21e92007-08-14 01:34:21 -0500209 if (machinecheck_count > 10) {
210 panic("machine check count too high\n");
211 }
212
213 if (machinecheck_count > 1) {
214 regs->nip += 4; /* skip offending instruction */
Andrew Klossnerdc4b0b32008-07-07 06:41:14 -0700215 printf("Skipping current instr, Returning to 0x%08lx\n",
Andy Fleming61a21e92007-08-14 01:34:21 -0500216 regs->nip);
217 } else {
Andrew Klossnerdc4b0b32008-07-07 06:41:14 -0700218 printf("Returning back to 0x%08lx\n",regs->nip);
Andy Fleming61a21e92007-08-14 01:34:21 -0500219 }
wdenk42d1f032003-10-15 23:53:47 +0000220}
221
222void
223AlignmentException(struct pt_regs *regs)
224{
Jon Loeliger44312832007-07-09 19:06:00 -0500225#if defined(CONFIG_CMD_KGDB)
wdenk42d1f032003-10-15 23:53:47 +0000226 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
227 return;
228#endif
229
230 show_regs(regs);
231 print_backtrace((unsigned long *)regs->gpr[1]);
232 panic("Alignment Exception");
233}
234
235void
236ProgramCheckException(struct pt_regs *regs)
237{
238 long esr_val;
239
Jon Loeliger44312832007-07-09 19:06:00 -0500240#if defined(CONFIG_CMD_KGDB)
wdenk42d1f032003-10-15 23:53:47 +0000241 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
242 return;
243#endif
244
245 show_regs(regs);
246
247 esr_val = get_esr();
248 if( esr_val & ESR_PIL )
249 printf( "** Illegal Instruction **\n" );
250 else if( esr_val & ESR_PPR )
251 printf( "** Privileged Instruction **\n" );
252 else if( esr_val & ESR_PTR )
253 printf( "** Trap Instruction **\n" );
254
255 print_backtrace((unsigned long *)regs->gpr[1]);
256 panic("Program Check Exception");
257}
258
259void
260PITException(struct pt_regs *regs)
261{
262 /*
263 * Reset PIT interrupt
264 */
265 set_tsr(0x0c000000);
266
267 /*
268 * Call timer_interrupt routine in interrupts.c
269 */
270 timer_interrupt(NULL);
271}
272
273
274void
275UnknownException(struct pt_regs *regs)
276{
Jon Loeliger44312832007-07-09 19:06:00 -0500277#if defined(CONFIG_CMD_KGDB)
wdenk42d1f032003-10-15 23:53:47 +0000278 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
279 return;
280#endif
281
282 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
283 regs->nip, regs->msr, regs->trap);
284 _exception(0, regs);
285}
Scott Wood3e3c9c12009-08-20 17:45:00 -0500286
Andy Fleming61a21e92007-08-14 01:34:21 -0500287void
288ExtIntException(struct pt_regs *regs)
289{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200290 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
Kumar Gala04db4002007-11-29 02:10:09 -0600291
Andy Fleming61a21e92007-08-14 01:34:21 -0500292 uint vect;
293
294#if defined(CONFIG_CMD_KGDB)
295 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
296 return;
297#endif
298
299 printf("External Interrupt Exception at PC: %lx, SR: %lx, vector=%lx",
300 regs->nip, regs->msr, regs->trap);
301 vect = pic->iack0;
Andrew Klossnerdc4b0b32008-07-07 06:41:14 -0700302 printf(" irq IACK0@%05x=%d\n",(int)&pic->iack0,vect);
Andy Fleming61a21e92007-08-14 01:34:21 -0500303 show_regs(regs);
304 print_backtrace((unsigned long *)regs->gpr[1]);
Andy Fleming61a21e92007-08-14 01:34:21 -0500305}
wdenk42d1f032003-10-15 23:53:47 +0000306
307void
308DebugException(struct pt_regs *regs)
309{
310 printf("Debugger trap at @ %lx\n", regs->nip );
311 show_regs(regs);
Jon Loeliger44312832007-07-09 19:06:00 -0500312#if defined(CONFIG_CMD_BEDBUG)
wdenk42d1f032003-10-15 23:53:47 +0000313 do_bedbug_breakpoint( regs );
314#endif
315}
316
wdenk9aea9532004-08-01 23:02:45 +0000317/* Probe an address by reading. If not present, return -1, otherwise
wdenk42d1f032003-10-15 23:53:47 +0000318 * return 0.
319 */
320int
321addr_probe(uint *addr)
322{
323 return 0;
324}