blob: 6aecca2db90b455f2624a1ee923ebffa95f7829c [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
39#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
40int (*debugger_exception_handler)(struct pt_regs *) = 0;
41#endif
42
43/* Returns 0 if exception not found and fixup otherwise. */
44extern unsigned long search_exception_table(unsigned long);
45
46/* THIS NEEDS CHANGING to use the board info structure.
47 */
48#define END_OF_MEM 0x00400000
49
50
51static __inline__ void set_tsr(unsigned long val)
52{
53#if defined(CONFIG_440)
54 asm volatile("mtspr 0x150, %0" : : "r" (val));
55#else
56 asm volatile("mttsr %0" : : "r" (val));
57#endif
58}
59
60static __inline__ unsigned long get_esr(void)
61{
62 unsigned long val;
63
64#if defined(CONFIG_440)
65 asm volatile("mfspr %0, 0x03e" : "=r" (val) :);
66#else
67 asm volatile("mfesr %0" : "=r" (val) :);
68#endif
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
80#if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
81extern 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
146MachineCheckException(struct pt_regs *regs)
147{
148 unsigned long fixup;
149
150 /* Probing PCI using config cycles cause this exception
151 * when a device is not present. Catch it and return to
152 * the PCI exception handler.
153 */
154 if ((fixup = search_exception_table(regs->nip)) != 0) {
155 regs->nip = fixup;
156 return;
157 }
158
159#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
160 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
161 return;
162#endif
163
164 printf("Machine check in kernel mode.\n");
165 printf("Caused by (from msr): ");
166 printf("regs %p ",regs);
wdenke97d3d92004-02-23 22:22:28 +0000167 switch( regs->msr & 0x000F0000) {
168 case (0x80000000>>12):
wdenkaffae2b2002-08-17 09:36:01 +0000169 printf("Machine check signal - probably due to mm fault\n"
170 "with mmu off\n");
171 break;
wdenke97d3d92004-02-23 22:22:28 +0000172 case (0x80000000>>13):
wdenkaffae2b2002-08-17 09:36:01 +0000173 printf("Transfer error ack signal\n");
174 break;
wdenke97d3d92004-02-23 22:22:28 +0000175 case (0x80000000>>14):
wdenkaffae2b2002-08-17 09:36:01 +0000176 printf("Data parity signal\n");
177 break;
wdenke97d3d92004-02-23 22:22:28 +0000178 case (0x80000000>>15):
wdenkaffae2b2002-08-17 09:36:01 +0000179 printf("Address parity signal\n");
180 break;
181 default:
182 printf("Unknown values in msr\n");
183 }
184 show_regs(regs);
185 print_backtrace((unsigned long *)regs->gpr[1]);
186 panic("machine check");
187}
188
189void
190AlignmentException(struct pt_regs *regs)
191{
192#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
193 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
194 return;
195#endif
196
197 show_regs(regs);
198 print_backtrace((unsigned long *)regs->gpr[1]);
199 panic("Alignment Exception");
200}
201
202void
203ProgramCheckException(struct pt_regs *regs)
204{
wdenk57b2d802003-06-27 21:31:46 +0000205 long esr_val;
wdenkaffae2b2002-08-17 09:36:01 +0000206
207#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
208 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
209 return;
210#endif
211
212 show_regs(regs);
213
wdenk57b2d802003-06-27 21:31:46 +0000214 esr_val = get_esr();
215 if( esr_val & ESR_PIL )
wdenkaffae2b2002-08-17 09:36:01 +0000216 printf( "** Illegal Instruction **\n" );
wdenk57b2d802003-06-27 21:31:46 +0000217 else if( esr_val & ESR_PPR )
wdenkaffae2b2002-08-17 09:36:01 +0000218 printf( "** Privileged Instruction **\n" );
wdenk57b2d802003-06-27 21:31:46 +0000219 else if( esr_val & ESR_PTR )
wdenkaffae2b2002-08-17 09:36:01 +0000220 printf( "** Trap Instruction **\n" );
221
222 print_backtrace((unsigned long *)regs->gpr[1]);
223 panic("Program Check Exception");
224}
225
226void
227PITException(struct pt_regs *regs)
228{
wdenk57b2d802003-06-27 21:31:46 +0000229 /*
230 * Reset PIT interrupt
231 */
232 set_tsr(0x08000000);
wdenkaffae2b2002-08-17 09:36:01 +0000233
wdenk57b2d802003-06-27 21:31:46 +0000234 /*
235 * Call timer_interrupt routine in interrupts.c
236 */
237 timer_interrupt(NULL);
wdenkaffae2b2002-08-17 09:36:01 +0000238}
239
240
241void
242UnknownException(struct pt_regs *regs)
243{
244#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
245 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
246 return;
247#endif
248
249 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
250 regs->nip, regs->msr, regs->trap);
251 _exception(0, regs);
252}
253
254void
255DebugException(struct pt_regs *regs)
256{
257 printf("Debugger trap at @ %lx\n", regs->nip );
258 show_regs(regs);
259#if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
260 do_bedbug_breakpoint( regs );
261#endif
262}
263
264/* Probe an address by reading. If not present, return -1, otherwise
265 * return 0.
266 */
267int
268addr_probe(uint *addr)
269{
270#if 0
271 int retval;
272
273 __asm__ __volatile__( \
274 "1: lwz %0,0(%1)\n" \
275 " eieio\n" \
276 " li %0,0\n" \
277 "2:\n" \
278 ".section .fixup,\"ax\"\n" \
279 "3: li %0,-1\n" \
280 " b 2b\n" \
281 ".section __ex_table,\"a\"\n" \
282 " .align 2\n" \
283 " .long 1b,3b\n" \
284 ".text" \
285 : "=r" (retval) : "r"(addr));
286
287 return (retval);
288#endif
289 return 0;
290}