blob: 9baa7a16d1be2d6e29f3e865a79755b6ed722665 [file] [log] [blame]
wdenkaffae2b2002-08-17 09:36:01 +00001/*
Stefan Roese88fbf932010-04-15 16:07:28 +02002 * linux/arch/powerpc/kernel/traps.c
wdenkaffae2b2002-08-17 09:36:01 +00003 *
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>
Stefan Roese63b6c422010-01-26 13:33:29 +010037#include <kgdb.h>
wdenkaffae2b2002-08-17 09:36:01 +000038#include <asm/processor.h>
39
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +020040DECLARE_GLOBAL_DATA_PTR;
41
wdenkaffae2b2002-08-17 09:36:01 +000042/* Returns 0 if exception not found and fixup otherwise. */
43extern unsigned long search_exception_table(unsigned long);
44
45/* THIS NEEDS CHANGING to use the board info structure.
46 */
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +020047#define END_OF_MEM (gd->bd->bi_memstart + gd->bd->bi_memsize)
wdenkaffae2b2002-08-17 09:36:01 +000048
wdenkaffae2b2002-08-17 09:36:01 +000049static __inline__ unsigned long get_esr(void)
50{
51 unsigned long val;
52
53#if defined(CONFIG_440)
54 asm volatile("mfspr %0, 0x03e" : "=r" (val) :);
55#else
56 asm volatile("mfesr %0" : "=r" (val) :);
57#endif
58 return val;
59}
60
61#define ESR_MCI 0x80000000
62#define ESR_PIL 0x08000000
63#define ESR_PPR 0x04000000
64#define ESR_PTR 0x02000000
65#define ESR_DST 0x00800000
66#define ESR_DIZ 0x00400000
67#define ESR_U0F 0x00008000
68
Jon Loeligera5217742007-07-09 18:57:22 -050069#if defined(CONFIG_CMD_BEDBUG)
wdenkaffae2b2002-08-17 09:36:01 +000070extern void do_bedbug_breakpoint(struct pt_regs *);
71#endif
72
73/*
74 * Trap & Exception support
75 */
76
77void
78print_backtrace(unsigned long *sp)
79{
Wolfgang Denk09675ef2007-06-20 18:14:24 +020080 int cnt = 0;
81 unsigned long i;
wdenkaffae2b2002-08-17 09:36:01 +000082
Wolfgang Denk09675ef2007-06-20 18:14:24 +020083 printf("Call backtrace: ");
84 while (sp) {
85 if ((uint)sp > END_OF_MEM)
86 break;
wdenkaffae2b2002-08-17 09:36:01 +000087
Wolfgang Denk09675ef2007-06-20 18:14:24 +020088 i = sp[1];
89 if (cnt++ % 7 == 0)
90 printf("\n");
91 printf("%08lX ", i);
92 if (cnt > 32) break;
93 sp = (unsigned long *)*sp;
94 }
95 printf("\n");
wdenkaffae2b2002-08-17 09:36:01 +000096}
97
98void show_regs(struct pt_regs * regs)
99{
100 int i;
101
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200102 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DEAR: %08lX\n",
wdenkaffae2b2002-08-17 09:36:01 +0000103 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
104 printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
105 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
106 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
107 regs->msr&MSR_IR ? 1 : 0,
108 regs->msr&MSR_DR ? 1 : 0);
109
110 printf("\n");
111 for (i = 0; i < 32; i++) {
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200112 if ((i % 8) == 0) {
wdenkaffae2b2002-08-17 09:36:01 +0000113 printf("GPR%02d: ", i);
114 }
115
116 printf("%08lX ", regs->gpr[i]);
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200117 if ((i % 8) == 7) {
wdenkaffae2b2002-08-17 09:36:01 +0000118 printf("\n");
119 }
120 }
121}
122
123
124void
125_exception(int signr, struct pt_regs *regs)
126{
127 show_regs(regs);
128 print_backtrace((unsigned long *)regs->gpr[1]);
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200129 panic("Exception");
wdenkaffae2b2002-08-17 09:36:01 +0000130}
131
132void
133MachineCheckException(struct pt_regs *regs)
134{
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200135 unsigned long fixup, val;
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200136#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
137 u32 value2;
Stefan Roeseb55f2422007-07-30 11:04:57 +0200138 int corr_ecc = 0;
139 int uncorr_ecc = 0;
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200140#endif
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200141
wdenkaffae2b2002-08-17 09:36:01 +0000142 if ((fixup = search_exception_table(regs->nip)) != 0) {
143 regs->nip = fixup;
Grzegorz Bernackid84fe302007-07-31 18:51:48 +0200144 val = mfspr(MCSR);
145 /* Clear MCSR */
Stefan Roese083c8472007-08-02 08:33:56 +0200146 mtspr(SPRN_MCSR, val);
wdenkaffae2b2002-08-17 09:36:01 +0000147 return;
148 }
149
Jon Loeligera5217742007-07-09 18:57:22 -0500150#if defined(CONFIG_CMD_KGDB)
wdenkaffae2b2002-08-17 09:36:01 +0000151 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
152 return;
153#endif
154
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200155 printf("Machine Check Exception.\n");
wdenkaffae2b2002-08-17 09:36:01 +0000156 printf("Caused by (from msr): ");
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200157 printf("regs %p ", regs);
158
159 val = get_esr();
160
Grant Ericksonb6933412008-05-22 14:44:14 -0700161#if !defined(CONFIG_440) && !defined(CONFIG_405EX)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200162 if (val& ESR_IMCP) {
163 printf("Instruction");
164 mtspr(ESR, val & ~ESR_IMCP);
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200165 } else {
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200166 printf("Data");
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200167 }
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200168 printf(" machine check.\n");
169
Grant Ericksonb6933412008-05-22 14:44:14 -0700170#elif defined(CONFIG_440) || defined(CONFIG_405EX)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200171 if (val& ESR_IMCP){
172 printf("Instruction Synchronous Machine Check exception\n");
173 mtspr(SPRN_ESR, val & ~ESR_IMCP);
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200174 } else {
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200175 val = mfspr(MCSR);
176 if (val & MCSR_IB)
177 printf("Instruction Read PLB Error\n");
Grant Ericksonb6933412008-05-22 14:44:14 -0700178#if defined(CONFIG_440)
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200179 if (val & MCSR_DRB)
180 printf("Data Read PLB Error\n");
181 if (val & MCSR_DWB)
182 printf("Data Write PLB Error\n");
Grant Ericksonb6933412008-05-22 14:44:14 -0700183#else
184 if (val & MCSR_DB)
185 printf("Data PLB Error\n");
186#endif
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200187 if (val & MCSR_TLBP)
188 printf("TLB Parity Error\n");
189 if (val & MCSR_ICP){
190 /*flush_instruction_cache(); */
191 printf("I-Cache Parity Error\n");
192 }
193 if (val & MCSR_DCSP)
194 printf("D-Cache Search Parity Error\n");
195 if (val & MCSR_DCFP)
196 printf("D-Cache Flush Parity Error\n");
197 if (val & MCSR_IMPE)
198 printf("Machine Check exception is imprecise\n");
199
200 /* Clear MCSR */
201 mtspr(SPRN_MCSR, val);
wdenkaffae2b2002-08-17 09:36:01 +0000202 }
Stefan Roese79b6deb2010-07-21 19:06:26 +0200203
204#if defined(CONFIG_DDR_ECC) && defined(CONFIG_SDRAM_PPC4xx_IBM_DDR2)
205 /*
206 * Read and print ECC status register/info:
207 * The faulting address is only known upon uncorrectable ECC
208 * errors.
209 */
210 mfsdram(SDRAM_ECCES, val);
211 if (val & SDRAM_ECCES_CE)
212 printf("ECC: Correctable error\n");
213 if (val & SDRAM_ECCES_UE) {
214 printf("ECC: Uncorrectable error at 0x%02x%08x\n",
215 mfdcr(SDRAM_ERRADDULL), mfdcr(SDRAM_ERRADDLLL));
216 }
217#endif /* CONFIG_DDR_ECC ... */
218
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200219#if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
220 mfsdram(DDR0_00, val) ;
Stefan Roese251161b2008-07-10 09:58:06 +0200221 printf("DDR0: DDR0_00 %lx\n", val);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200222 val = (val >> 16) & 0xff;
223 if (val & 0x80)
224 printf("DDR0: At least one interrupt active\n");
225 if (val & 0x40)
226 printf("DDR0: DRAM initialization complete.\n");
Stefan Roeseb55f2422007-07-30 11:04:57 +0200227 if (val & 0x20) {
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200228 printf("DDR0: Multiple uncorrectable ECC events.\n");
Stefan Roeseb55f2422007-07-30 11:04:57 +0200229 uncorr_ecc = 1;
230 }
231 if (val & 0x10) {
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200232 printf("DDR0: Single uncorrectable ECC event.\n");
Stefan Roeseb55f2422007-07-30 11:04:57 +0200233 uncorr_ecc = 1;
234 }
235 if (val & 0x08) {
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200236 printf("DDR0: Multiple correctable ECC events.\n");
Stefan Roeseb55f2422007-07-30 11:04:57 +0200237 corr_ecc = 1;
238 }
239 if (val & 0x04) {
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200240 printf("DDR0: Single correctable ECC event.\n");
Stefan Roeseb55f2422007-07-30 11:04:57 +0200241 corr_ecc = 1;
242 }
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200243 if (val & 0x02)
244 printf("Multiple accesses outside the defined"
245 " physical memory space detected\n");
246 if (val & 0x01)
247 printf("DDR0: Single access outside the defined"
248 " physical memory space detected.\n");
249
250 mfsdram(DDR0_01, val);
251 val = (val >> 8) & 0x7;
252 switch (val ) {
253 case 0:
254 printf("DDR0: Write Out-of-Range command\n");
255 break;
256 case 1:
257 printf("DDR0: Read Out-of-Range command\n");
258 break;
259 case 2:
260 printf("DDR0: Masked write Out-of-Range command\n");
261 break;
262 case 4:
263 printf("DDR0: Wrap write Out-of-Range command\n");
264 break;
265 case 5:
266 printf("DDR0: Wrap read Out-of-Range command\n");
267 break;
268 default:
269 mfsdram(DDR0_01, value2);
Stefan Roese251161b2008-07-10 09:58:06 +0200270 printf("DDR0: No DDR0 error know 0x%lx %x\n", val, value2);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200271 }
272 mfsdram(DDR0_23, val);
Stefan Roeseb55f2422007-07-30 11:04:57 +0200273 if (((val >> 16) & 0xff) && corr_ecc)
Stefan Roese251161b2008-07-10 09:58:06 +0200274 printf("DDR0: Syndrome for correctable ECC event 0x%lx\n",
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200275 (val >> 16) & 0xff);
276 mfsdram(DDR0_23, val);
Stefan Roeseb55f2422007-07-30 11:04:57 +0200277 if (((val >> 8) & 0xff) && uncorr_ecc)
Stefan Roese251161b2008-07-10 09:58:06 +0200278 printf("DDR0: Syndrome for uncorrectable ECC event 0x%lx\n",
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200279 (val >> 8) & 0xff);
280 mfsdram(DDR0_33, val);
281 if (val)
282 printf("DDR0: Address of command that caused an "
Stefan Roese251161b2008-07-10 09:58:06 +0200283 "Out-of-Range interrupt %lx\n", val);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200284 mfsdram(DDR0_34, val);
Stefan Roeseb55f2422007-07-30 11:04:57 +0200285 if (val && uncorr_ecc)
Stefan Roese251161b2008-07-10 09:58:06 +0200286 printf("DDR0: Address of uncorrectable ECC event %lx\n", val);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200287 mfsdram(DDR0_35, val);
Stefan Roeseb55f2422007-07-30 11:04:57 +0200288 if (val && uncorr_ecc)
Stefan Roese251161b2008-07-10 09:58:06 +0200289 printf("DDR0: Address of uncorrectable ECC event %lx\n", val);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200290 mfsdram(DDR0_36, val);
Stefan Roeseb55f2422007-07-30 11:04:57 +0200291 if (val && uncorr_ecc)
Stefan Roese251161b2008-07-10 09:58:06 +0200292 printf("DDR0: Data of uncorrectable ECC event 0x%08lx\n", val);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200293 mfsdram(DDR0_37, val);
Stefan Roeseb55f2422007-07-30 11:04:57 +0200294 if (val && uncorr_ecc)
Stefan Roese251161b2008-07-10 09:58:06 +0200295 printf("DDR0: Data of uncorrectable ECC event 0x%08lx\n", val);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200296 mfsdram(DDR0_38, val);
Stefan Roeseb55f2422007-07-30 11:04:57 +0200297 if (val && corr_ecc)
Stefan Roese251161b2008-07-10 09:58:06 +0200298 printf("DDR0: Address of correctable ECC event %lx\n", val);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200299 mfsdram(DDR0_39, val);
Stefan Roeseb55f2422007-07-30 11:04:57 +0200300 if (val && corr_ecc)
Stefan Roese251161b2008-07-10 09:58:06 +0200301 printf("DDR0: Address of correctable ECC event %lx\n", val);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200302 mfsdram(DDR0_40, val);
Stefan Roeseb55f2422007-07-30 11:04:57 +0200303 if (val && corr_ecc)
Stefan Roese251161b2008-07-10 09:58:06 +0200304 printf("DDR0: Data of correctable ECC event 0x%08lx\n", val);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200305 mfsdram(DDR0_41, val);
Stefan Roeseb55f2422007-07-30 11:04:57 +0200306 if (val && corr_ecc)
Stefan Roese251161b2008-07-10 09:58:06 +0200307 printf("DDR0: Data of correctable ECC event 0x%08lx\n", val);
Niklaus Giger36e0f3a2007-06-25 17:03:13 +0200308#endif /* CONFIG_440EPX */
309#endif /* CONFIG_440 */
wdenkaffae2b2002-08-17 09:36:01 +0000310 show_regs(regs);
311 print_backtrace((unsigned long *)regs->gpr[1]);
312 panic("machine check");
313}
314
315void
316AlignmentException(struct pt_regs *regs)
317{
Jon Loeligera5217742007-07-09 18:57:22 -0500318#if defined(CONFIG_CMD_KGDB)
wdenkaffae2b2002-08-17 09:36:01 +0000319 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
320 return;
321#endif
322
323 show_regs(regs);
324 print_backtrace((unsigned long *)regs->gpr[1]);
325 panic("Alignment Exception");
326}
327
328void
329ProgramCheckException(struct pt_regs *regs)
330{
wdenk57b2d802003-06-27 21:31:46 +0000331 long esr_val;
wdenkaffae2b2002-08-17 09:36:01 +0000332
Jon Loeligera5217742007-07-09 18:57:22 -0500333#if defined(CONFIG_CMD_KGDB)
wdenkaffae2b2002-08-17 09:36:01 +0000334 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
335 return;
336#endif
337
338 show_regs(regs);
339
wdenk57b2d802003-06-27 21:31:46 +0000340 esr_val = get_esr();
341 if( esr_val & ESR_PIL )
wdenkaffae2b2002-08-17 09:36:01 +0000342 printf( "** Illegal Instruction **\n" );
wdenk57b2d802003-06-27 21:31:46 +0000343 else if( esr_val & ESR_PPR )
wdenkaffae2b2002-08-17 09:36:01 +0000344 printf( "** Privileged Instruction **\n" );
wdenk57b2d802003-06-27 21:31:46 +0000345 else if( esr_val & ESR_PTR )
wdenkaffae2b2002-08-17 09:36:01 +0000346 printf( "** Trap Instruction **\n" );
347
348 print_backtrace((unsigned long *)regs->gpr[1]);
349 panic("Program Check Exception");
350}
351
352void
Grzegorz Bernacki837bc5b2007-06-15 11:19:28 +0200353DecrementerPITException(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +0000354{
wdenk57b2d802003-06-27 21:31:46 +0000355 /*
356 * Reset PIT interrupt
357 */
Stefan Roese61138fe2010-10-04 11:09:40 +0200358 mtspr(SPRN_TSR, 0x08000000);
wdenkaffae2b2002-08-17 09:36:01 +0000359
wdenk57b2d802003-06-27 21:31:46 +0000360 /*
361 * Call timer_interrupt routine in interrupts.c
362 */
363 timer_interrupt(NULL);
wdenkaffae2b2002-08-17 09:36:01 +0000364}
365
366
367void
368UnknownException(struct pt_regs *regs)
369{
Jon Loeligera5217742007-07-09 18:57:22 -0500370#if defined(CONFIG_CMD_KGDB)
wdenkaffae2b2002-08-17 09:36:01 +0000371 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
372 return;
373#endif
374
375 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
376 regs->nip, regs->msr, regs->trap);
377 _exception(0, regs);
378}
379
380void
381DebugException(struct pt_regs *regs)
382{
383 printf("Debugger trap at @ %lx\n", regs->nip );
384 show_regs(regs);
Jon Loeligera5217742007-07-09 18:57:22 -0500385#if defined(CONFIG_CMD_BEDBUG)
wdenkaffae2b2002-08-17 09:36:01 +0000386 do_bedbug_breakpoint( regs );
387#endif
388}
389
390/* Probe an address by reading. If not present, return -1, otherwise
391 * return 0.
392 */
393int
394addr_probe(uint *addr)
395{
396#if 0
397 int retval;
398
399 __asm__ __volatile__( \
400 "1: lwz %0,0(%1)\n" \
Wolfgang Denk09675ef2007-06-20 18:14:24 +0200401 " eieio\n" \
402 " li %0,0\n" \
403 "2:\n" \
404 ".section .fixup,\"ax\"\n" \
405 "3: li %0,-1\n" \
406 " b 2b\n" \
407 ".section __ex_table,\"a\"\n" \
408 " .align 2\n" \
409 " .long 1b,3b\n" \
410 ".text" \
411 : "=r" (retval) : "r"(addr));
wdenkaffae2b2002-08-17 09:36:01 +0000412
413 return (retval);
414#endif
415 return 0;
416}