blob: 9d16b9b55e7b058bd244791c06d1fc509da25a77 [file] [log] [blame]
wdenk9c53f402003-10-15 23:53:47 +00001/*
2 * linux/arch/ppc/kernel/traps.c
3 *
Andy Flemingf08233c2007-08-14 01:34:21 -05004 * Copyright 2007 Freescale Semiconductor.
wdenk9c53f402003-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
wdenk492b9e72004-08-01 23:02:45 +000026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenk9c53f402003-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 Denk6405a152006-03-31 18:32:53 +020043DECLARE_GLOBAL_DATA_PTR;
44
Jon Loeliger526e5ce2007-07-09 19:06:00 -050045#if defined(CONFIG_CMD_KGDB)
wdenk9c53f402003-10-15 23:53:47 +000046int (*debugger_exception_handler)(struct pt_regs *) = 0;
47#endif
48
49/* Returns 0 if exception not found and fixup otherwise. */
50extern unsigned long search_exception_table(unsigned long);
51
wdenk492b9e72004-08-01 23:02:45 +000052/*
Becky Bruce306b4e82008-05-14 13:10:04 -050053 * End of addressable memory. This may be less than the actual
54 * amount of memory on the system if we're unable to keep all
55 * the memory mapped in.
wdenk9c53f402003-10-15 23:53:47 +000056 */
Becky Bruce306b4e82008-05-14 13:10:04 -050057extern ulong get_effective_memsize(void);
58#define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize())
wdenk9c53f402003-10-15 23:53:47 +000059
60static __inline__ void set_tsr(unsigned long val)
61{
62 asm volatile("mtspr 0x150, %0" : : "r" (val));
63}
64
65static __inline__ unsigned long get_esr(void)
66{
67 unsigned long val;
68 asm volatile("mfspr %0, 0x03e" : "=r" (val) :);
69 return val;
70}
71
72#define ESR_MCI 0x80000000
73#define ESR_PIL 0x08000000
74#define ESR_PPR 0x04000000
75#define ESR_PTR 0x02000000
76#define ESR_DST 0x00800000
77#define ESR_DIZ 0x00400000
78#define ESR_U0F 0x00008000
79
Jon Loeliger526e5ce2007-07-09 19:06:00 -050080#if defined(CONFIG_CMD_BEDBUG)
wdenk9c53f402003-10-15 23:53:47 +000081extern void do_bedbug_breakpoint(struct pt_regs *);
82#endif
83
84/*
85 * Trap & Exception support
86 */
87
88void
89print_backtrace(unsigned long *sp)
90{
91 int cnt = 0;
92 unsigned long i;
93
94 printf("Call backtrace: ");
95 while (sp) {
96 if ((uint)sp > END_OF_MEM)
97 break;
98
99 i = sp[1];
100 if (cnt++ % 7 == 0)
101 printf("\n");
102 printf("%08lX ", i);
103 if (cnt > 32) break;
104 sp = (unsigned long *)*sp;
105 }
106 printf("\n");
107}
108
109void show_regs(struct pt_regs * regs)
110{
111 int i;
112
113 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
114 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
115 printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
116 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
117 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
118 regs->msr&MSR_IR ? 1 : 0,
119 regs->msr&MSR_DR ? 1 : 0);
120
121 printf("\n");
122 for (i = 0; i < 32; i++) {
123 if ((i % 8) == 0)
124 {
125 printf("GPR%02d: ", i);
126 }
127
128 printf("%08lX ", regs->gpr[i]);
129 if ((i % 8) == 7)
130 {
131 printf("\n");
132 }
133 }
134}
135
136
137void
138_exception(int signr, struct pt_regs *regs)
139{
140 show_regs(regs);
141 print_backtrace((unsigned long *)regs->gpr[1]);
142 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
143}
144
145void
146CritcalInputException(struct pt_regs *regs)
147{
148 panic("Critical Input Exception");
149}
150
Andy Flemingf08233c2007-08-14 01:34:21 -0500151int machinecheck_count = 0;
152int machinecheck_error = 0;
wdenk9c53f402003-10-15 23:53:47 +0000153void
154MachineCheckException(struct pt_regs *regs)
155{
156 unsigned long fixup;
Andy Flemingf08233c2007-08-14 01:34:21 -0500157 unsigned int mcsr, mcsrr0, mcsrr1, mcar;
wdenk9c53f402003-10-15 23:53:47 +0000158
159 /* Probing PCI using config cycles cause this exception
160 * when a device is not present. Catch it and return to
161 * the PCI exception handler.
162 */
163 if ((fixup = search_exception_table(regs->nip)) != 0) {
164 regs->nip = fixup;
165 return;
166 }
167
Andy Flemingf08233c2007-08-14 01:34:21 -0500168 mcsrr0 = mfspr(SPRN_MCSRR0);
169 mcsrr1 = mfspr(SPRN_MCSRR1);
170 mcsr = mfspr(SPRN_MCSR);
171 mcar = mfspr(SPRN_MCAR);
172
173 machinecheck_count++;
174 machinecheck_error=1;
175
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500176#if defined(CONFIG_CMD_KGDB)
wdenk9c53f402003-10-15 23:53:47 +0000177 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
178 return;
179#endif
180
181 printf("Machine check in kernel mode.\n");
Andy Flemingf08233c2007-08-14 01:34:21 -0500182 printf("Caused by (from mcsr): ");
183 printf("mcsr = 0x%08x\n", mcsr);
184 if (mcsr & 0x80000000)
185 printf("Machine check input pin\n");
186 if (mcsr & 0x40000000)
187 printf("Instruction cache parity error\n");
188 if (mcsr & 0x20000000)
189 printf("Data cache push parity error\n");
190 if (mcsr & 0x10000000)
191 printf("Data cache parity error\n");
192 if (mcsr & 0x00000080)
193 printf("Bus instruction address error\n");
194 if (mcsr & 0x00000040)
195 printf("Bus Read address error\n");
196 if (mcsr & 0x00000020)
197 printf("Bus Write address error\n");
198 if (mcsr & 0x00000010)
199 printf("Bus Instruction data bus error\n");
200 if (mcsr & 0x00000008)
201 printf("Bus Read data bus error\n");
202 if (mcsr & 0x00000004)
203 printf("Bus Write bus error\n");
204 if (mcsr & 0x00000002)
205 printf("Bus Instruction parity error\n");
206 if (mcsr & 0x00000001)
207 printf("Bus Read parity error\n");
208
wdenk9c53f402003-10-15 23:53:47 +0000209 show_regs(regs);
Andy Flemingf08233c2007-08-14 01:34:21 -0500210 printf("MCSR=0x%08x \tMCSRR0=0x%08x \nMCSRR1=0x%08x \tMCAR=0x%08x\n",
211 mcsr, mcsrr0, mcsrr1, mcar);
wdenk9c53f402003-10-15 23:53:47 +0000212 print_backtrace((unsigned long *)regs->gpr[1]);
Andy Flemingf08233c2007-08-14 01:34:21 -0500213 if (machinecheck_count > 10) {
214 panic("machine check count too high\n");
215 }
216
217 if (machinecheck_count > 1) {
218 regs->nip += 4; /* skip offending instruction */
Andrew Klossnere4ad4542008-07-07 06:41:14 -0700219 printf("Skipping current instr, Returning to 0x%08lx\n",
Andy Flemingf08233c2007-08-14 01:34:21 -0500220 regs->nip);
221 } else {
Andrew Klossnere4ad4542008-07-07 06:41:14 -0700222 printf("Returning back to 0x%08lx\n",regs->nip);
Andy Flemingf08233c2007-08-14 01:34:21 -0500223 }
wdenk9c53f402003-10-15 23:53:47 +0000224}
225
226void
227AlignmentException(struct pt_regs *regs)
228{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500229#if defined(CONFIG_CMD_KGDB)
wdenk9c53f402003-10-15 23:53:47 +0000230 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
231 return;
232#endif
233
234 show_regs(regs);
235 print_backtrace((unsigned long *)regs->gpr[1]);
236 panic("Alignment Exception");
237}
238
239void
240ProgramCheckException(struct pt_regs *regs)
241{
242 long esr_val;
243
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500244#if defined(CONFIG_CMD_KGDB)
wdenk9c53f402003-10-15 23:53:47 +0000245 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
246 return;
247#endif
248
249 show_regs(regs);
250
251 esr_val = get_esr();
252 if( esr_val & ESR_PIL )
253 printf( "** Illegal Instruction **\n" );
254 else if( esr_val & ESR_PPR )
255 printf( "** Privileged Instruction **\n" );
256 else if( esr_val & ESR_PTR )
257 printf( "** Trap Instruction **\n" );
258
259 print_backtrace((unsigned long *)regs->gpr[1]);
260 panic("Program Check Exception");
261}
262
263void
264PITException(struct pt_regs *regs)
265{
266 /*
267 * Reset PIT interrupt
268 */
269 set_tsr(0x0c000000);
270
271 /*
272 * Call timer_interrupt routine in interrupts.c
273 */
274 timer_interrupt(NULL);
275}
276
277
278void
279UnknownException(struct pt_regs *regs)
280{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500281#if defined(CONFIG_CMD_KGDB)
wdenk9c53f402003-10-15 23:53:47 +0000282 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
283 return;
284#endif
285
286 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
287 regs->nip, regs->msr, regs->trap);
288 _exception(0, regs);
289}
Scott Woode957bd72009-08-20 17:45:00 -0500290
Andy Flemingf08233c2007-08-14 01:34:21 -0500291void
292ExtIntException(struct pt_regs *regs)
293{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200294 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
Kumar Gala0a7a0972007-11-29 02:10:09 -0600295
Andy Flemingf08233c2007-08-14 01:34:21 -0500296 uint vect;
297
298#if defined(CONFIG_CMD_KGDB)
299 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
300 return;
301#endif
302
303 printf("External Interrupt Exception at PC: %lx, SR: %lx, vector=%lx",
304 regs->nip, regs->msr, regs->trap);
305 vect = pic->iack0;
Andrew Klossnere4ad4542008-07-07 06:41:14 -0700306 printf(" irq IACK0@%05x=%d\n",(int)&pic->iack0,vect);
Andy Flemingf08233c2007-08-14 01:34:21 -0500307 show_regs(regs);
308 print_backtrace((unsigned long *)regs->gpr[1]);
Andy Flemingf08233c2007-08-14 01:34:21 -0500309}
wdenk9c53f402003-10-15 23:53:47 +0000310
311void
312DebugException(struct pt_regs *regs)
313{
314 printf("Debugger trap at @ %lx\n", regs->nip );
315 show_regs(regs);
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500316#if defined(CONFIG_CMD_BEDBUG)
wdenk9c53f402003-10-15 23:53:47 +0000317 do_bedbug_breakpoint( regs );
318#endif
319}
320
wdenk492b9e72004-08-01 23:02:45 +0000321/* Probe an address by reading. If not present, return -1, otherwise
wdenk9c53f402003-10-15 23:53:47 +0000322 * return 0.
323 */
324int
325addr_probe(uint *addr)
326{
327 return 0;
328}