blob: c432be6030c0bd9293e8b345fa449cb5365ac2d1 [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#if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
44extern void do_bedbug_breakpoint(struct pt_regs *);
45#endif
46
47/* Returns 0 if exception not found and fixup otherwise. */
48extern unsigned long search_exception_table(unsigned long);
49
50/* THIS NEEDS CHANGING to use the board info structure.
51*/
52#define END_OF_MEM 0x02000000
53
54/*
55 * Trap & Exception support
56 */
57
58void
59print_backtrace(unsigned long *sp)
60{
61 int cnt = 0;
62 unsigned long i;
63
64 printf("Call backtrace: ");
65 while (sp) {
66 if ((uint)sp > END_OF_MEM)
67 break;
68
69 i = sp[1];
70 if (cnt++ % 7 == 0)
71 printf("\n");
72 printf("%08lX ", i);
73 if (cnt > 32) break;
74 sp = (unsigned long *)*sp;
75 }
76 printf("\n");
77}
78
79void show_regs(struct pt_regs * regs)
80{
81 int i;
82
83 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
84 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
85 printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
86 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
87 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
88 regs->msr&MSR_IR ? 1 : 0,
89 regs->msr&MSR_DR ? 1 : 0);
90
91 printf("\n");
92 for (i = 0; i < 32; i++) {
93 if ((i % 8) == 0)
94 {
95 printf("GPR%02d: ", i);
96 }
97
98 printf("%08lX ", regs->gpr[i]);
99 if ((i % 8) == 7)
100 {
101 printf("\n");
102 }
103 }
104}
105
106
107void
108_exception(int signr, struct pt_regs *regs)
109{
110 show_regs(regs);
111 print_backtrace((unsigned long *)regs->gpr[1]);
112 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
113}
114
115void
116MachineCheckException(struct pt_regs *regs)
117{
118 unsigned long fixup;
119
120 /* Probing PCI using config cycles cause this exception
121 * when a device is not present. Catch it and return to
122 * the PCI exception handler.
123 */
124 if ((fixup = search_exception_table(regs->nip)) != 0) {
125 regs->nip = fixup;
126 return;
127 }
128
129#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
130 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
131 return;
132#endif
133
134 printf("Machine check in kernel mode.\n");
135 printf("Caused by (from msr): ");
136 printf("regs %p ",regs);
137 switch( regs->msr & 0x0000F000)
138 {
139 case (1<<12) :
140 printf("Machine check signal - probably due to mm fault\n"
141 "with mmu off\n");
142 break;
143 case (1<<13) :
144 printf("Transfer error ack signal\n");
145 break;
146 case (1<<14) :
147 printf("Data parity signal\n");
148 break;
149 case (1<<15) :
150 printf("Address parity signal\n");
151 break;
152 default:
153 printf("Unknown values in msr\n");
154 }
155 show_regs(regs);
156 print_backtrace((unsigned long *)regs->gpr[1]);
157 panic("machine check");
158}
159
160void
161AlignmentException(struct pt_regs *regs)
162{
163#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
164 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
165 return;
166#endif
167 show_regs(regs);
168 print_backtrace((unsigned long *)regs->gpr[1]);
169 panic("Alignment Exception");
170}
171
172void
173ProgramCheckException(struct pt_regs *regs)
174{
175#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
176 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
177 return;
178#endif
179 show_regs(regs);
180 print_backtrace((unsigned long *)regs->gpr[1]);
181 panic("Program Check Exception");
182}
183
184void
185SoftEmuException(struct pt_regs *regs)
186{
187#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
188 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
189 return;
190#endif
191 show_regs(regs);
192 print_backtrace((unsigned long *)regs->gpr[1]);
193 panic("Software Emulation Exception");
194}
195
196
197void
198UnknownException(struct pt_regs *regs)
199{
200#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
201 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
202 return;
203#endif
204 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
205 regs->nip, regs->msr, regs->trap);
206 _exception(0, regs);
207}
208
209void
210DebugException(struct pt_regs *regs)
211{
212 printf("Debugger trap at @ %lx\n", regs->nip );
213 show_regs(regs);
214#if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
215 do_bedbug_breakpoint( regs );
216#endif
217}
218
219/* Probe an address by reading. If not present, return -1, otherwise
220 * return 0.
221 */
222int
223addr_probe(uint *addr)
224{
225#if 0
226 int retval;
227
228 __asm__ __volatile__( \
229 "1: lwz %0,0(%1)\n" \
230 " eieio\n" \
231 " li %0,0\n" \
232 "2:\n" \
233 ".section .fixup,\"ax\"\n" \
234 "3: li %0,-1\n" \
235 " b 2b\n" \
236 ".section __ex_table,\"a\"\n" \
237 " .align 2\n" \
238 " .long 1b,3b\n" \
239 ".text" \
240 : "=r" (retval) : "r"(addr));
241
242 return (retval);
243#endif
244 return 0;
245}