blob: 85f2ea4cce904e2fa776e76e0db2906c358f12e7 [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);
167 switch( regs->msr & 0x0000F000)
168 {
169 case (1<<12) :
170 printf("Machine check signal - probably due to mm fault\n"
171 "with mmu off\n");
172 break;
173 case (1<<13) :
174 printf("Transfer error ack signal\n");
175 break;
176 case (1<<14) :
177 printf("Data parity signal\n");
178 break;
179 case (1<<15) :
180 printf("Address parity signal\n");
181 break;
182 default:
183 printf("Unknown values in msr\n");
184 }
185 show_regs(regs);
186 print_backtrace((unsigned long *)regs->gpr[1]);
187 panic("machine check");
188}
189
190void
191AlignmentException(struct pt_regs *regs)
192{
193#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
194 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
195 return;
196#endif
197
198 show_regs(regs);
199 print_backtrace((unsigned long *)regs->gpr[1]);
200 panic("Alignment Exception");
201}
202
203void
204ProgramCheckException(struct pt_regs *regs)
205{
206 long esr_val;
207
208#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
209 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
210 return;
211#endif
212
213 show_regs(regs);
214
215 esr_val = get_esr();
216 if( esr_val & ESR_PIL )
217 printf( "** Illegal Instruction **\n" );
218 else if( esr_val & ESR_PPR )
219 printf( "** Privileged Instruction **\n" );
220 else if( esr_val & ESR_PTR )
221 printf( "** Trap Instruction **\n" );
222
223 print_backtrace((unsigned long *)regs->gpr[1]);
224 panic("Program Check Exception");
225}
226
227void
228PITException(struct pt_regs *regs)
229{
230 /*
231 * Reset PIT interrupt
232 */
233 set_tsr(0x08000000);
234
235 /*
236 * Call timer_interrupt routine in interrupts.c
237 */
238 timer_interrupt(NULL);
239}
240
241
242void
243UnknownException(struct pt_regs *regs)
244{
245#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
246 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
247 return;
248#endif
249
250 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
251 regs->nip, regs->msr, regs->trap);
252 _exception(0, regs);
253}
254
255void
256DebugException(struct pt_regs *regs)
257{
258 printf("Debugger trap at @ %lx\n", regs->nip );
259 show_regs(regs);
260#if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
261 do_bedbug_breakpoint( regs );
262#endif
263}
264
265/* Probe an address by reading. If not present, return -1, otherwise
266 * return 0.
267 */
268int
269addr_probe(uint *addr)
270{
271#if 0
272 int retval;
273
274 __asm__ __volatile__( \
275 "1: lwz %0,0(%1)\n" \
276 " eieio\n" \
277 " li %0,0\n" \
278 "2:\n" \
279 ".section .fixup,\"ax\"\n" \
280 "3: li %0,-1\n" \
281 " b 2b\n" \
282 ".section __ex_table,\"a\"\n" \
283 " .align 2\n" \
284 " .long 1b,3b\n" \
285 ".text" \
286 : "=r" (retval) : "r"(addr));
287
288 return (retval);
289#endif
290 return 0;
291}