blob: cb35faf081414d30526c74b3458ba0c93abda684 [file] [log] [blame]
wdenkaffae2b2002-08-17 09:36:01 +00001/*
2 * linux/arch/ppc/kernel/traps.c
3 *
4 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
5 *
6 * Modified by Cort Dougan (cort@cs.nmt.edu)
7 * and Paul Mackerras (paulus@cs.anu.edu.au)
8 *
9 * (C) Copyright 2000
10 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
11 *
12 * See file CREDITS for list of people who contributed to this
13 * project.
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
29 */
30
31/*
32 * This file handles the architecture-dependent parts of hardware exceptions
33 */
34
35#include <common.h>
36#include <command.h>
37#include <asm/processor.h>
38
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +020039DECLARE_GLOBAL_DATA_PTR;
40
wdenkaffae2b2002-08-17 09:36:01 +000041/* Returns 0 if exception not found and fixup otherwise. */
42extern unsigned long search_exception_table(unsigned long);
43
44/* THIS NEEDS CHANGING to use the board info structure.
45 */
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +020046#define END_OF_MEM (gd->bd->bi_memstart + gd->bd->bi_memsize)
wdenkaffae2b2002-08-17 09:36:01 +000047
48static __inline__ void set_tsr(unsigned long val)
49{
50#if defined(CONFIG_440)
51 asm volatile("mtspr 0x150, %0" : : "r" (val));
52#else
53 asm volatile("mttsr %0" : : "r" (val));
54#endif
55}
56
57static __inline__ unsigned long get_esr(void)
58{
59 unsigned long val;
60
61#if defined(CONFIG_440)
62 asm volatile("mfspr %0, 0x03e" : "=r" (val) :);
63#else
64 asm volatile("mfesr %0" : "=r" (val) :);
65#endif
66 return val;
67}
68
69#define ESR_MCI 0x80000000
70#define ESR_PIL 0x08000000
71#define ESR_PPR 0x04000000
72#define ESR_PTR 0x02000000
73#define ESR_DST 0x00800000
74#define ESR_DIZ 0x00400000
75#define ESR_U0F 0x00008000
76
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -050077#if defined(CONFIG_CMD_BEDBUG)
wdenkaffae2b2002-08-17 09:36:01 +000078extern void do_bedbug_breakpoint(struct pt_regs *);
79#endif
80
81/*
82 * Trap & Exception support
83 */
84
85void
86print_backtrace(unsigned long *sp)
87{
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +020088 int cnt = 0;
89 unsigned long i;
wdenkaffae2b2002-08-17 09:36:01 +000090
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +020091 printf("Call backtrace: ");
92 while (sp) {
93 if ((uint)sp > END_OF_MEM)
94 break;
wdenkaffae2b2002-08-17 09:36:01 +000095
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +020096 i = sp[1];
97 if (cnt++ % 7 == 0)
98 printf("\n");
99 printf("%08lX ", i);
100 if (cnt > 32) break;
101 sp = (unsigned long *)*sp;
102 }
103 printf("\n");
wdenkaffae2b2002-08-17 09:36:01 +0000104}
105
106void show_regs(struct pt_regs * regs)
107{
108 int i;
109
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +0200110 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DEAR: %08lX\n",
wdenkaffae2b2002-08-17 09:36:01 +0000111 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
112 printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
113 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
114 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
115 regs->msr&MSR_IR ? 1 : 0,
116 regs->msr&MSR_DR ? 1 : 0);
117
118 printf("\n");
119 for (i = 0; i < 32; i++) {
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +0200120 if ((i % 8) == 0) {
wdenkaffae2b2002-08-17 09:36:01 +0000121 printf("GPR%02d: ", i);
122 }
123
124 printf("%08lX ", regs->gpr[i]);
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +0200125 if ((i % 8) == 7) {
wdenkaffae2b2002-08-17 09:36:01 +0000126 printf("\n");
127 }
128 }
129}
130
131
132void
133_exception(int signr, struct pt_regs *regs)
134{
135 show_regs(regs);
136 print_backtrace((unsigned long *)regs->gpr[1]);
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +0200137 panic("Exception");
wdenkaffae2b2002-08-17 09:36:01 +0000138}
139
140void
141MachineCheckException(struct pt_regs *regs)
142{
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +0200143 unsigned long fixup, val;
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200144#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
145 u32 value2;
Stefan Roese27a528f2007-07-30 11:04:57 +0200146 int corr_ecc = 0;
147 int uncorr_ecc = 0;
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200148#endif
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +0200149
wdenkaffae2b2002-08-17 09:36:01 +0000150 if ((fixup = search_exception_table(regs->nip)) != 0) {
151 regs->nip = fixup;
Grzegorz Bernackic9240982007-07-31 18:51:48 +0200152 val = mfspr(MCSR);
153 /* Clear MCSR */
Stefan Roese9ca8d792007-08-02 08:33:56 +0200154 mtspr(SPRN_MCSR, val);
wdenkaffae2b2002-08-17 09:36:01 +0000155 return;
156 }
157
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -0500158#if defined(CONFIG_CMD_KGDB)
wdenkaffae2b2002-08-17 09:36:01 +0000159 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
160 return;
161#endif
162
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +0200163 printf("Machine Check Exception.\n");
wdenkaffae2b2002-08-17 09:36:01 +0000164 printf("Caused by (from msr): ");
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +0200165 printf("regs %p ", regs);
166
167 val = get_esr();
168
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700169#if !defined(CONFIG_440) && !defined(CONFIG_405EX)
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +0200170 if (val& ESR_IMCP) {
171 printf("Instruction");
172 mtspr(ESR, val & ~ESR_IMCP);
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +0200173 } else {
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +0200174 printf("Data");
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +0200175 }
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +0200176 printf(" machine check.\n");
177
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700178#elif defined(CONFIG_440) || defined(CONFIG_405EX)
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +0200179 if (val& ESR_IMCP){
180 printf("Instruction Synchronous Machine Check exception\n");
181 mtspr(SPRN_ESR, val & ~ESR_IMCP);
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +0200182 } else {
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +0200183 val = mfspr(MCSR);
184 if (val & MCSR_IB)
185 printf("Instruction Read PLB Error\n");
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700186#if defined(CONFIG_440)
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +0200187 if (val & MCSR_DRB)
188 printf("Data Read PLB Error\n");
189 if (val & MCSR_DWB)
190 printf("Data Write PLB Error\n");
Grant Ericksonc821b5f2008-05-22 14:44:14 -0700191#else
192 if (val & MCSR_DB)
193 printf("Data PLB Error\n");
194#endif
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +0200195 if (val & MCSR_TLBP)
196 printf("TLB Parity Error\n");
197 if (val & MCSR_ICP){
198 /*flush_instruction_cache(); */
199 printf("I-Cache Parity Error\n");
200 }
201 if (val & MCSR_DCSP)
202 printf("D-Cache Search Parity Error\n");
203 if (val & MCSR_DCFP)
204 printf("D-Cache Flush Parity Error\n");
205 if (val & MCSR_IMPE)
206 printf("Machine Check exception is imprecise\n");
207
208 /* Clear MCSR */
209 mtspr(SPRN_MCSR, val);
210 }
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200211#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
212 mfsdram(DDR0_00, val) ;
Stefan Roeseb0021442008-07-10 09:58:06 +0200213 printf("DDR0: DDR0_00 %lx\n", val);
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200214 val = (val >> 16) & 0xff;
215 if (val & 0x80)
216 printf("DDR0: At least one interrupt active\n");
217 if (val & 0x40)
218 printf("DDR0: DRAM initialization complete.\n");
Stefan Roese27a528f2007-07-30 11:04:57 +0200219 if (val & 0x20) {
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200220 printf("DDR0: Multiple uncorrectable ECC events.\n");
Stefan Roese27a528f2007-07-30 11:04:57 +0200221 uncorr_ecc = 1;
222 }
223 if (val & 0x10) {
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200224 printf("DDR0: Single uncorrectable ECC event.\n");
Stefan Roese27a528f2007-07-30 11:04:57 +0200225 uncorr_ecc = 1;
226 }
227 if (val & 0x08) {
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200228 printf("DDR0: Multiple correctable ECC events.\n");
Stefan Roese27a528f2007-07-30 11:04:57 +0200229 corr_ecc = 1;
230 }
231 if (val & 0x04) {
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200232 printf("DDR0: Single correctable ECC event.\n");
Stefan Roese27a528f2007-07-30 11:04:57 +0200233 corr_ecc = 1;
234 }
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200235 if (val & 0x02)
236 printf("Multiple accesses outside the defined"
237 " physical memory space detected\n");
238 if (val & 0x01)
239 printf("DDR0: Single access outside the defined"
240 " physical memory space detected.\n");
241
242 mfsdram(DDR0_01, val);
243 val = (val >> 8) & 0x7;
244 switch (val ) {
245 case 0:
246 printf("DDR0: Write Out-of-Range command\n");
247 break;
248 case 1:
249 printf("DDR0: Read Out-of-Range command\n");
250 break;
251 case 2:
252 printf("DDR0: Masked write Out-of-Range command\n");
253 break;
254 case 4:
255 printf("DDR0: Wrap write Out-of-Range command\n");
256 break;
257 case 5:
258 printf("DDR0: Wrap read Out-of-Range command\n");
259 break;
260 default:
261 mfsdram(DDR0_01, value2);
Stefan Roeseb0021442008-07-10 09:58:06 +0200262 printf("DDR0: No DDR0 error know 0x%lx %x\n", val, value2);
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200263 }
264 mfsdram(DDR0_23, val);
Stefan Roese27a528f2007-07-30 11:04:57 +0200265 if (((val >> 16) & 0xff) && corr_ecc)
Stefan Roeseb0021442008-07-10 09:58:06 +0200266 printf("DDR0: Syndrome for correctable ECC event 0x%lx\n",
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200267 (val >> 16) & 0xff);
268 mfsdram(DDR0_23, val);
Stefan Roese27a528f2007-07-30 11:04:57 +0200269 if (((val >> 8) & 0xff) && uncorr_ecc)
Stefan Roeseb0021442008-07-10 09:58:06 +0200270 printf("DDR0: Syndrome for uncorrectable ECC event 0x%lx\n",
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200271 (val >> 8) & 0xff);
272 mfsdram(DDR0_33, val);
273 if (val)
274 printf("DDR0: Address of command that caused an "
Stefan Roeseb0021442008-07-10 09:58:06 +0200275 "Out-of-Range interrupt %lx\n", val);
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200276 mfsdram(DDR0_34, val);
Stefan Roese27a528f2007-07-30 11:04:57 +0200277 if (val && uncorr_ecc)
Stefan Roeseb0021442008-07-10 09:58:06 +0200278 printf("DDR0: Address of uncorrectable ECC event %lx\n", val);
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200279 mfsdram(DDR0_35, val);
Stefan Roese27a528f2007-07-30 11:04:57 +0200280 if (val && uncorr_ecc)
Stefan Roeseb0021442008-07-10 09:58:06 +0200281 printf("DDR0: Address of uncorrectable ECC event %lx\n", val);
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200282 mfsdram(DDR0_36, val);
Stefan Roese27a528f2007-07-30 11:04:57 +0200283 if (val && uncorr_ecc)
Stefan Roeseb0021442008-07-10 09:58:06 +0200284 printf("DDR0: Data of uncorrectable ECC event 0x%08lx\n", val);
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200285 mfsdram(DDR0_37, val);
Stefan Roese27a528f2007-07-30 11:04:57 +0200286 if (val && uncorr_ecc)
Stefan Roeseb0021442008-07-10 09:58:06 +0200287 printf("DDR0: Data of uncorrectable ECC event 0x%08lx\n", val);
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200288 mfsdram(DDR0_38, val);
Stefan Roese27a528f2007-07-30 11:04:57 +0200289 if (val && corr_ecc)
Stefan Roeseb0021442008-07-10 09:58:06 +0200290 printf("DDR0: Address of correctable ECC event %lx\n", val);
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200291 mfsdram(DDR0_39, val);
Stefan Roese27a528f2007-07-30 11:04:57 +0200292 if (val && corr_ecc)
Stefan Roeseb0021442008-07-10 09:58:06 +0200293 printf("DDR0: Address of correctable ECC event %lx\n", val);
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200294 mfsdram(DDR0_40, val);
Stefan Roese27a528f2007-07-30 11:04:57 +0200295 if (val && corr_ecc)
Stefan Roeseb0021442008-07-10 09:58:06 +0200296 printf("DDR0: Data of correctable ECC event 0x%08lx\n", val);
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200297 mfsdram(DDR0_41, val);
Stefan Roese27a528f2007-07-30 11:04:57 +0200298 if (val && corr_ecc)
Stefan Roeseb0021442008-07-10 09:58:06 +0200299 printf("DDR0: Data of correctable ECC event 0x%08lx\n", val);
Niklaus Gigera1bd6202007-06-25 17:03:13 +0200300#endif /* CONFIG_440EPX */
301#endif /* CONFIG_440 */
wdenkaffae2b2002-08-17 09:36:01 +0000302 show_regs(regs);
303 print_backtrace((unsigned long *)regs->gpr[1]);
304 panic("machine check");
305}
306
307void
308AlignmentException(struct pt_regs *regs)
309{
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -0500310#if defined(CONFIG_CMD_KGDB)
wdenkaffae2b2002-08-17 09:36:01 +0000311 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
312 return;
313#endif
314
315 show_regs(regs);
316 print_backtrace((unsigned long *)regs->gpr[1]);
317 panic("Alignment Exception");
318}
319
320void
321ProgramCheckException(struct pt_regs *regs)
322{
wdenk8bde7f72003-06-27 21:31:46 +0000323 long esr_val;
wdenkaffae2b2002-08-17 09:36:01 +0000324
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -0500325#if defined(CONFIG_CMD_KGDB)
wdenkaffae2b2002-08-17 09:36:01 +0000326 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
327 return;
328#endif
329
330 show_regs(regs);
331
wdenk8bde7f72003-06-27 21:31:46 +0000332 esr_val = get_esr();
333 if( esr_val & ESR_PIL )
wdenkaffae2b2002-08-17 09:36:01 +0000334 printf( "** Illegal Instruction **\n" );
wdenk8bde7f72003-06-27 21:31:46 +0000335 else if( esr_val & ESR_PPR )
wdenkaffae2b2002-08-17 09:36:01 +0000336 printf( "** Privileged Instruction **\n" );
wdenk8bde7f72003-06-27 21:31:46 +0000337 else if( esr_val & ESR_PTR )
wdenkaffae2b2002-08-17 09:36:01 +0000338 printf( "** Trap Instruction **\n" );
339
340 print_backtrace((unsigned long *)regs->gpr[1]);
341 panic("Program Check Exception");
342}
343
344void
Grzegorz Bernackiefa35cf2007-06-15 11:19:28 +0200345DecrementerPITException(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +0000346{
wdenk8bde7f72003-06-27 21:31:46 +0000347 /*
348 * Reset PIT interrupt
349 */
350 set_tsr(0x08000000);
wdenkaffae2b2002-08-17 09:36:01 +0000351
wdenk8bde7f72003-06-27 21:31:46 +0000352 /*
353 * Call timer_interrupt routine in interrupts.c
354 */
355 timer_interrupt(NULL);
wdenkaffae2b2002-08-17 09:36:01 +0000356}
357
358
359void
360UnknownException(struct pt_regs *regs)
361{
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -0500362#if defined(CONFIG_CMD_KGDB)
wdenkaffae2b2002-08-17 09:36:01 +0000363 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
364 return;
365#endif
366
367 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
368 regs->nip, regs->msr, regs->trap);
369 _exception(0, regs);
370}
371
372void
373DebugException(struct pt_regs *regs)
374{
375 printf("Debugger trap at @ %lx\n", regs->nip );
376 show_regs(regs);
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -0500377#if defined(CONFIG_CMD_BEDBUG)
wdenkaffae2b2002-08-17 09:36:01 +0000378 do_bedbug_breakpoint( regs );
379#endif
380}
381
382/* Probe an address by reading. If not present, return -1, otherwise
383 * return 0.
384 */
385int
386addr_probe(uint *addr)
387{
388#if 0
389 int retval;
390
391 __asm__ __volatile__( \
392 "1: lwz %0,0(%1)\n" \
Wolfgang Denk83b4cfa2007-06-20 18:14:24 +0200393 " eieio\n" \
394 " li %0,0\n" \
395 "2:\n" \
396 ".section .fixup,\"ax\"\n" \
397 "3: li %0,-1\n" \
398 " b 2b\n" \
399 ".section __ex_table,\"a\"\n" \
400 " .align 2\n" \
401 " .long 1b,3b\n" \
402 ".text" \
403 : "=r" (retval) : "r"(addr));
wdenkaffae2b2002-08-17 09:36:01 +0000404
405 return (retval);
406#endif
407 return 0;
408}