MINI2440: Updated early nand loader
[u-boot-openmoko/mini2440.git] / cpu / mpc5xx / traps.c
blobd22b89a1f52563de7e2c4d54ea0b1c558d6a602f
1 /*
2 * linux/arch/ppc/kernel/traps.c
4 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
6 * Modified by Cort Dougan (cort@cs.nmt.edu)
7 * and Paul Mackerras (paulus@cs.anu.edu.au)
9 * (C) Copyright 2000
10 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
12 * See file CREDITS for list of people who contributed to this
13 * project.
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.
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.
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
32 * This file handles the architecture-dependent parts of hardware exceptions
35 #include <common.h>
36 #include <command.h>
37 #include <asm/processor.h>
39 #if defined(CONFIG_CMD_KGDB)
40 int (*debugger_exception_handler)(struct pt_regs *) = 0;
41 #endif
43 #if defined(CONFIG_CMD_BEDBUG)
44 extern void do_bedbug_breakpoint(struct pt_regs *);
45 #endif
47 /* Returns 0 if exception not found and fixup otherwise. */
48 extern unsigned long search_exception_table(unsigned long);
50 /* THIS NEEDS CHANGING to use the board info structure.
52 #define END_OF_MEM 0x0001000
56 * Print stack backtrace
58 void print_backtrace(unsigned long *sp)
60 int cnt = 0;
61 unsigned long i;
63 printf("Call backtrace: ");
64 while (sp) {
65 if ((uint)sp > END_OF_MEM)
66 break;
68 i = sp[1];
69 if (cnt++ % 7 == 0)
70 printf("\n");
71 printf("%08lX ", i);
72 if (cnt > 32) break;
73 sp = (unsigned long *)*sp;
75 printf("\n");
79 * Print current registers
81 void show_regs(struct pt_regs * regs)
83 int i;
84 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
85 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
86 printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
87 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
88 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
89 regs->msr&MSR_IR ? 1 : 0,
90 regs->msr&MSR_DR ? 1 : 0);
92 printf("\n");
93 for (i = 0; i < 32; i++) {
94 if ((i % 8) == 0)
96 printf("GPR%02d: ", i);
99 printf("%08lX ", regs->gpr[i]);
100 if ((i % 8) == 7)
102 printf("\n");
109 * General exception handler routine
111 void _exception(int signr, struct pt_regs *regs)
113 show_regs(regs);
114 print_backtrace((unsigned long *)regs->gpr[1]);
115 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
119 * Machine check exception handler routine
121 void MachineCheckException(struct pt_regs *regs)
123 unsigned long fixup;
125 /* Probing PCI using config cycles cause this exception
126 * when a device is not present. Catch it and return to
127 * the PCI exception handler.
129 if ((fixup = search_exception_table(regs->nip)) != 0) {
130 regs->nip = fixup;
131 return;
134 #if defined(CONFIG_CMD_KGDB)
135 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
136 return;
137 #endif
139 printf("Machine check in kernel mode.\n");
140 printf("Caused by (from msr): ");
141 printf("regs %p ",regs);
142 switch( regs->msr & 0x000F0000) {
143 case (0x80000000>>12):
144 printf("Machine check signal\n");
145 break;
146 case (0x80000000>>13):
147 printf("Transfer error ack signal\n");
148 break;
149 case (0x80000000>>14):
150 printf("Data parity signal\n");
151 break;
152 case (0x80000000>>15):
153 printf("Address parity signal\n");
154 break;
155 default:
156 printf("Unknown values in msr\n");
158 show_regs(regs);
159 print_backtrace((unsigned long *)regs->gpr[1]);
160 panic("machine check");
164 * Alignment exception handler routine
166 void AlignmentException(struct pt_regs *regs)
168 #if defined(CONFIG_CMD_KGDB)
169 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
170 return;
171 #endif
172 show_regs(regs);
173 print_backtrace((unsigned long *)regs->gpr[1]);
174 panic("Alignment Exception");
178 * Program check exception handler routine
180 void ProgramCheckException(struct pt_regs *regs)
182 #if defined(CONFIG_CMD_KGDB)
183 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
184 return;
185 #endif
186 show_regs(regs);
187 print_backtrace((unsigned long *)regs->gpr[1]);
188 panic("Program Check Exception");
192 * Software emulation exception handler routine
194 void SoftEmuException(struct pt_regs *regs)
196 #if defined(CONFIG_CMD_KGDB)
197 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
198 return;
199 #endif
200 show_regs(regs);
201 print_backtrace((unsigned long *)regs->gpr[1]);
202 panic("Software Emulation Exception");
207 * Unknown exception handler routine
209 void UnknownException(struct pt_regs *regs)
211 #if defined(CONFIG_CMD_KGDB)
212 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
213 return;
214 #endif
215 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
216 regs->nip, regs->msr, regs->trap);
217 _exception(0, regs);
221 * Debug exception handler routine
223 void DebugException(struct pt_regs *regs)
225 printf("Debugger trap at @ %lx\n", regs->nip );
226 show_regs(regs);
227 #if defined(CONFIG_CMD_BEDBUG)
228 do_bedbug_breakpoint( regs );
229 #endif