blob: 904f0523396d631a0aa8de698da0b4b6d1ba0cfc [file] [log] [blame]
wdenk42d1f032003-10-15 23:53:47 +00001/*
2 * linux/arch/ppc/kernel/traps.c
3 *
4 * Copyright (C) 2003 Motorola
5 * Modified by Xianghua Xiao(x.xiao@motorola.com)
6 *
7 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
8 *
9 * Modified by Cort Dougan (cort@cs.nmt.edu)
10 * and Paul Mackerras (paulus@cs.anu.edu.au)
11 *
12 * (C) Copyright 2000
13 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
14 *
15 * See file CREDITS for list of people who contributed to this
16 * project.
17 *
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License as
20 * published by the Free Software Foundation; either version 2 of
21 * the License, or (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wdenk9aea9532004-08-01 23:02:45 +000025 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenk42d1f032003-10-15 23:53:47 +000026 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 * MA 02111-1307 USA
32 */
33
34/*
35 * This file handles the architecture-dependent parts of hardware exceptions
36 */
37
38#include <common.h>
39#include <command.h>
40#include <asm/processor.h>
41
Wolfgang Denkd87080b2006-03-31 18:32:53 +020042DECLARE_GLOBAL_DATA_PTR;
43
wdenk42d1f032003-10-15 23:53:47 +000044#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
45int (*debugger_exception_handler)(struct pt_regs *) = 0;
46#endif
47
48/* Returns 0 if exception not found and fixup otherwise. */
49extern unsigned long search_exception_table(unsigned long);
50
wdenk9aea9532004-08-01 23:02:45 +000051/*
52 * End of memory as shown by board info and determined by DDR setup.
wdenk42d1f032003-10-15 23:53:47 +000053 */
wdenk9aea9532004-08-01 23:02:45 +000054#define END_OF_MEM (gd->bd->bi_memstart + gd->bd->bi_memsize)
wdenk42d1f032003-10-15 23:53:47 +000055
56
57static __inline__ void set_tsr(unsigned long val)
58{
59 asm volatile("mtspr 0x150, %0" : : "r" (val));
60}
61
62static __inline__ unsigned long get_esr(void)
63{
64 unsigned long val;
65 asm volatile("mfspr %0, 0x03e" : "=r" (val) :);
66 return val;
67}
68
69#define ESR_MCI 0x80000000
70#define ESR_PIL 0x08000000
71#define ESR_PPR 0x04000000
72#define ESR_PTR 0x02000000
73#define ESR_DST 0x00800000
74#define ESR_DIZ 0x00400000
75#define ESR_U0F 0x00008000
76
77#if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
78extern void do_bedbug_breakpoint(struct pt_regs *);
79#endif
80
81/*
82 * Trap & Exception support
83 */
84
85void
86print_backtrace(unsigned long *sp)
87{
88 int cnt = 0;
89 unsigned long i;
90
91 printf("Call backtrace: ");
92 while (sp) {
93 if ((uint)sp > END_OF_MEM)
94 break;
95
96 i = sp[1];
97 if (cnt++ % 7 == 0)
98 printf("\n");
99 printf("%08lX ", i);
100 if (cnt > 32) break;
101 sp = (unsigned long *)*sp;
102 }
103 printf("\n");
104}
105
106void show_regs(struct pt_regs * regs)
107{
108 int i;
109
110 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
111 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
112 printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
113 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
114 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
115 regs->msr&MSR_IR ? 1 : 0,
116 regs->msr&MSR_DR ? 1 : 0);
117
118 printf("\n");
119 for (i = 0; i < 32; i++) {
120 if ((i % 8) == 0)
121 {
122 printf("GPR%02d: ", i);
123 }
124
125 printf("%08lX ", regs->gpr[i]);
126 if ((i % 8) == 7)
127 {
128 printf("\n");
129 }
130 }
131}
132
133
134void
135_exception(int signr, struct pt_regs *regs)
136{
137 show_regs(regs);
138 print_backtrace((unsigned long *)regs->gpr[1]);
139 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
140}
141
142void
143CritcalInputException(struct pt_regs *regs)
144{
145 panic("Critical Input Exception");
146}
147
148void
149MachineCheckException(struct pt_regs *regs)
150{
151 unsigned long fixup;
152
153 /* Probing PCI using config cycles cause this exception
154 * when a device is not present. Catch it and return to
155 * the PCI exception handler.
156 */
157 if ((fixup = search_exception_table(regs->nip)) != 0) {
158 regs->nip = fixup;
159 return;
160 }
161
162#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
163 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
164 return;
165#endif
166
167 printf("Machine check in kernel mode.\n");
168 printf("Caused by (from msr): ");
169 printf("regs %p ",regs);
wdenk63e73c92004-02-23 22:22:28 +0000170 switch( regs->msr & 0x000F0000) {
171 case (0x80000000>>12):
wdenk42d1f032003-10-15 23:53:47 +0000172 printf("Machine check signal - probably due to mm fault\n"
173 "with mmu off\n");
174 break;
wdenk63e73c92004-02-23 22:22:28 +0000175 case (0x80000000>>13):
wdenk42d1f032003-10-15 23:53:47 +0000176 printf("Transfer error ack signal\n");
177 break;
wdenk63e73c92004-02-23 22:22:28 +0000178 case (0x80000000>>14):
wdenk42d1f032003-10-15 23:53:47 +0000179 printf("Data parity signal\n");
180 break;
wdenk63e73c92004-02-23 22:22:28 +0000181 case (0x80000000>>15):
wdenk42d1f032003-10-15 23:53:47 +0000182 printf("Address parity signal\n");
183 break;
184 default:
185 printf("Unknown values in msr\n");
186 }
187 show_regs(regs);
188 print_backtrace((unsigned long *)regs->gpr[1]);
189 panic("machine check");
190}
191
192void
193AlignmentException(struct pt_regs *regs)
194{
195#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
196 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
197 return;
198#endif
199
200 show_regs(regs);
201 print_backtrace((unsigned long *)regs->gpr[1]);
202 panic("Alignment Exception");
203}
204
205void
206ProgramCheckException(struct pt_regs *regs)
207{
208 long esr_val;
209
210#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
211 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
212 return;
213#endif
214
215 show_regs(regs);
216
217 esr_val = get_esr();
218 if( esr_val & ESR_PIL )
219 printf( "** Illegal Instruction **\n" );
220 else if( esr_val & ESR_PPR )
221 printf( "** Privileged Instruction **\n" );
222 else if( esr_val & ESR_PTR )
223 printf( "** Trap Instruction **\n" );
224
225 print_backtrace((unsigned long *)regs->gpr[1]);
226 panic("Program Check Exception");
227}
228
229void
230PITException(struct pt_regs *regs)
231{
232 /*
233 * Reset PIT interrupt
234 */
235 set_tsr(0x0c000000);
236
237 /*
238 * Call timer_interrupt routine in interrupts.c
239 */
240 timer_interrupt(NULL);
241}
242
243
244void
245UnknownException(struct pt_regs *regs)
246{
247#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
248 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
249 return;
250#endif
251
252 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
253 regs->nip, regs->msr, regs->trap);
254 _exception(0, regs);
255}
256
257void
258DebugException(struct pt_regs *regs)
259{
260 printf("Debugger trap at @ %lx\n", regs->nip );
261 show_regs(regs);
262#if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
263 do_bedbug_breakpoint( regs );
264#endif
265}
266
wdenk9aea9532004-08-01 23:02:45 +0000267/* Probe an address by reading. If not present, return -1, otherwise
wdenk42d1f032003-10-15 23:53:47 +0000268 * return 0.
269 */
270int
271addr_probe(uint *addr)
272{
273 return 0;
274}