blob: 8113dfbcc35994edf658be0486c309925c9eafce [file] [log] [blame]
Jon Loeligerdebb7352006-04-26 17:58:56 -05001/*
Jon Loeligerdebb7352006-04-26 17:58:56 -05002 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
3 *
4 * Modified by Cort Dougan (cort@cs.nmt.edu)
5 * and Paul Mackerras (paulus@cs.anu.edu.au)
6 *
7 * (C) Copyright 2000
8 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 *
10 * See file CREDITS for list of people who contributed to this
11 * project.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 * MA 02111-1307 USA
27 */
28
29/*
30 * This file handles the architecture-dependent parts of hardware exceptions
31 */
32
33#include <common.h>
34#include <command.h>
35#include <asm/processor.h>
36
37#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
38int (*debugger_exception_handler)(struct pt_regs *) = 0;
39#endif
40
41/* Returns 0 if exception not found and fixup otherwise. */
42extern unsigned long search_exception_table(unsigned long);
43
44#define END_OF_MEM (gd->bd->bi_memstart + gd->bd->bi_memsize)
45
46/*
47 * Trap & Exception support
48 */
49
50void
51print_backtrace(unsigned long *sp)
52{
53 DECLARE_GLOBAL_DATA_PTR;
54
55 int cnt = 0;
56 unsigned long i;
57
58 printf("Call backtrace: ");
59 while (sp) {
60 if ((uint)sp > END_OF_MEM)
61 break;
62
63 i = sp[1];
64 if (cnt++ % 7 == 0)
65 printf("\n");
66 printf("%08lX ", i);
67 if (cnt > 32) break;
68 sp = (unsigned long *)*sp;
69 }
70 printf("\n");
71}
72
73void
74show_regs(struct pt_regs * regs)
75{
76 int i;
77
78 printf("NIP: %08lX XER: %08lX LR: %08lX REGS:"
79 " %p TRAP: %04lx DAR: %08lX\n",
80 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
81 printf("MSR: %08lx EE: %01x PR: %01x FP:"
82 " %01x ME: %01x IR/DR: %01x%01x\n",
83 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
84 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
85 regs->msr&MSR_IR ? 1 : 0,
86 regs->msr&MSR_DR ? 1 : 0);
87
88 printf("\n");
89 for (i = 0; i < 32; i++) {
90 if ((i % 8) == 0)
91 {
92 printf("GPR%02d: ", i);
93 }
94
95 printf("%08lX ", regs->gpr[i]);
96 if ((i % 8) == 7)
97 {
98 printf("\n");
99 }
100 }
101}
102
103
104void
105_exception(int signr, struct pt_regs *regs)
106{
107 show_regs(regs);
108 print_backtrace((unsigned long *)regs->gpr[1]);
109 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
110}
111
112void
113MachineCheckException(struct pt_regs *regs)
114{
115 unsigned long fixup;
116
117 /* Probing PCI using config cycles cause this exception
118 * when a device is not present. Catch it and return to
119 * the PCI exception handler.
120 */
121 if ((fixup = search_exception_table(regs->nip)) != 0) {
122 regs->nip = fixup;
123 return;
124 }
125
126#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
127 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
128 return;
129#endif
130
131 printf("Machine check in kernel mode.\n");
132 printf("Caused by (from msr): ");
133 printf("regs %p ",regs);
134 switch( regs->msr & 0x000F0000) {
135 case (0x80000000>>12):
136 printf("Machine check signal - probably due to mm fault\n"
137 "with mmu off\n");
138 break;
139 case (0x80000000>>13):
140 printf("Transfer error ack signal\n");
141 break;
142 case (0x80000000>>14):
143 printf("Data parity signal\n");
144 break;
145 case (0x80000000>>15):
146 printf("Address parity signal\n");
147 break;
148 default:
149 printf("Unknown values in msr\n");
150 }
151 show_regs(regs);
152 print_backtrace((unsigned long *)regs->gpr[1]);
153 panic("machine check");
154}
155
156void
157AlignmentException(struct pt_regs *regs)
158{
159#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
160 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
161 return;
162#endif
163 show_regs(regs);
164 print_backtrace((unsigned long *)regs->gpr[1]);
165 panic("Alignment Exception");
166}
167
168void
169ProgramCheckException(struct pt_regs *regs)
170{
171 unsigned char *p = regs ? (unsigned char *)(regs->nip) : NULL;
172 int i, j;
173
174#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
175 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
176 return;
177#endif
178 show_regs(regs);
179
180 p = (unsigned char *) ((unsigned long)p & 0xFFFFFFE0);
181 p -= 32;
182 for (i = 0; i < 256; i+=16) {
183 printf("%08x: ", (unsigned int)p+i);
184 for (j = 0; j < 16; j++) {
185 printf("%02x ", p[i+j]);
186 }
187 printf("\n");
188 }
189
190 print_backtrace((unsigned long *)regs->gpr[1]);
191 panic("Program Check Exception");
192}
193
194void
195SoftEmuException(struct pt_regs *regs)
196{
197#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
198 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
199 return;
200#endif
201 show_regs(regs);
202 print_backtrace((unsigned long *)regs->gpr[1]);
203 panic("Software Emulation Exception");
204}
205
206
207void
208UnknownException(struct pt_regs *regs)
209{
210#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
211 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
212 return;
213#endif
214 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
215 regs->nip, regs->msr, regs->trap);
216 _exception(0, regs);
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}
246
247
248
249
250
251