2 * linux/arch/ppc/kernel/traps.c
4 * Copyright 2007 Freescale Semiconductor.
5 * Copyright (C) 2003 Motorola
6 * Modified by Xianghua Xiao(x.xiao@motorola.com)
8 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
10 * Modified by Cort Dougan (cort@cs.nmt.edu)
11 * and Paul Mackerras (paulus@cs.anu.edu.au)
14 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
16 * See file CREDITS for list of people who contributed to this
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.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
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,
36 * This file handles the architecture-dependent parts of hardware exceptions
41 #include <asm/processor.h>
43 DECLARE_GLOBAL_DATA_PTR
;
45 #if defined(CONFIG_CMD_KGDB)
46 int (*debugger_exception_handler
)(struct pt_regs
*) = 0;
49 /* Returns 0 if exception not found and fixup otherwise. */
50 extern unsigned long search_exception_table(unsigned long);
53 * 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.
57 extern ulong
get_effective_memsize(void);
58 #define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize())
60 static __inline__
void set_tsr(unsigned long val
)
62 asm volatile("mtspr 0x150, %0" : : "r" (val
));
65 static __inline__
unsigned long get_esr(void)
68 asm volatile("mfspr %0, 0x03e" : "=r" (val
) :);
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
80 #if defined(CONFIG_CMD_BEDBUG)
81 extern void do_bedbug_breakpoint(struct pt_regs
*);
85 * Trap & Exception support
89 print_backtrace(unsigned long *sp
)
94 printf("Call backtrace: ");
96 if ((uint
)sp
> END_OF_MEM
)
104 sp
= (unsigned long *)*sp
;
109 void show_regs(struct pt_regs
* regs
)
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);
122 for (i
= 0; i
< 32; i
++) {
125 printf("GPR%02d: ", i
);
128 printf("%08lX ", regs
->gpr
[i
]);
138 _exception(int signr
, struct pt_regs
*regs
)
141 print_backtrace((unsigned long *)regs
->gpr
[1]);
142 panic("Exception in kernel pc %lx signal %d",regs
->nip
,signr
);
146 CritcalInputException(struct pt_regs
*regs
)
148 panic("Critical Input Exception");
151 int machinecheck_count
= 0;
152 int machinecheck_error
= 0;
154 MachineCheckException(struct pt_regs
*regs
)
157 unsigned int mcsr
, mcsrr0
, mcsrr1
, mcar
;
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.
163 if ((fixup
= search_exception_table(regs
->nip
)) != 0) {
168 mcsrr0
= mfspr(SPRN_MCSRR0
);
169 mcsrr1
= mfspr(SPRN_MCSRR1
);
170 mcsr
= mfspr(SPRN_MCSR
);
171 mcar
= mfspr(SPRN_MCAR
);
173 machinecheck_count
++;
174 machinecheck_error
=1;
176 #if defined(CONFIG_CMD_KGDB)
177 if (debugger_exception_handler
&& (*debugger_exception_handler
)(regs
))
181 printf("Machine check in kernel mode.\n");
182 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");
210 printf("MCSR=0x%08x \tMCSRR0=0x%08x \nMCSRR1=0x%08x \tMCAR=0x%08x\n",
211 mcsr
, mcsrr0
, mcsrr1
, mcar
);
212 print_backtrace((unsigned long *)regs
->gpr
[1]);
213 if (machinecheck_count
> 10) {
214 panic("machine check count too high\n");
217 if (machinecheck_count
> 1) {
218 regs
->nip
+= 4; /* skip offending instruction */
219 printf("Skipping current instr, Returning to 0x%08lx\n",
222 printf("Returning back to 0x%08lx\n",regs
->nip
);
227 AlignmentException(struct pt_regs
*regs
)
229 #if defined(CONFIG_CMD_KGDB)
230 if (debugger_exception_handler
&& (*debugger_exception_handler
)(regs
))
235 print_backtrace((unsigned long *)regs
->gpr
[1]);
236 panic("Alignment Exception");
240 ProgramCheckException(struct pt_regs
*regs
)
244 #if defined(CONFIG_CMD_KGDB)
245 if (debugger_exception_handler
&& (*debugger_exception_handler
)(regs
))
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" );
259 print_backtrace((unsigned long *)regs
->gpr
[1]);
260 panic("Program Check Exception");
264 PITException(struct pt_regs
*regs
)
267 * Reset PIT interrupt
272 * Call timer_interrupt routine in interrupts.c
274 timer_interrupt(NULL
);
279 UnknownException(struct pt_regs
*regs
)
281 #if defined(CONFIG_CMD_KGDB)
282 if (debugger_exception_handler
&& (*debugger_exception_handler
)(regs
))
286 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
287 regs
->nip
, regs
->msr
, regs
->trap
);
291 ExtIntException(struct pt_regs
*regs
)
293 volatile ccsr_pic_t
*pic
= (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR
);
297 #if defined(CONFIG_CMD_KGDB)
298 if (debugger_exception_handler
&& (*debugger_exception_handler
)(regs
))
302 printf("External Interrupt Exception at PC: %lx, SR: %lx, vector=%lx",
303 regs
->nip
, regs
->msr
, regs
->trap
);
305 printf(" irq IACK0@%05x=%d\n",(int)&pic
->iack0
,vect
);
307 print_backtrace((unsigned long *)regs
->gpr
[1]);
308 machinecheck_count
++;
310 printf("Returning back to 0x%08x\n",regs
->nip
);
312 regs
->nip
+= 4; /* skip offending instruction */
313 printf("Skipping current instr, Returning to 0x%08lx\n",regs
->nip
);
319 DebugException(struct pt_regs
*regs
)
321 printf("Debugger trap at @ %lx\n", regs
->nip
);
323 #if defined(CONFIG_CMD_BEDBUG)
324 do_bedbug_breakpoint( regs
);
328 /* Probe an address by reading. If not present, return -1, otherwise
332 addr_probe(uint
*addr
)