blob: 8455c92761b109b9d9130dddc5510c753e14c9e6 [file] [log] [blame]
Rafal Jaworowski8993e542007-07-27 14:43:59 +02001/*
2 * (C) Copyright 2000 - 2007
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 *
22 * Derived from the MPC83xx code.
23 */
24
25/*
26 * This file handles the architecture-dependent parts of hardware
27 * exceptions
28 */
29
30#include <common.h>
31#include <asm/processor.h>
32
33DECLARE_GLOBAL_DATA_PTR;
34
35extern unsigned long search_exception_table(unsigned long);
36
37#define END_OF_MEM (gd->bd->bi_memstart + gd->bd->bi_memsize)
38
39/*
40 * Trap & Exception support
41 */
42
43void
44print_backtrace (unsigned long *sp)
45{
46 int cnt = 0;
47 unsigned long i;
48
49 puts ("Call backtrace: ");
50 while (sp) {
51 if ((uint)sp > END_OF_MEM)
52 break;
53
54 i = sp[1];
55 if (cnt++ % 7 == 0)
56 putc ('\n');
57 printf ("%08lX ", i);
58 if (cnt > 32) break;
59 sp = (unsigned long *) *sp;
60 }
61 putc ('\n');
62}
63
64void show_regs (struct pt_regs * regs)
65{
66 int i;
67
68 printf ("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
69 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
70 printf ("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
71 regs->msr, regs->msr & MSR_EE ? 1 : 0, regs->msr & MSR_PR ? 1 : 0,
72 regs->msr & MSR_FP ? 1 : 0,regs->msr & MSR_ME ? 1 : 0,
73 regs->msr & MSR_IR ? 1 : 0,
74 regs->msr & MSR_DR ? 1 : 0);
75
76 putc ('\n');
77 for (i = 0; i < 32; i++) {
78 if ((i % 8) == 0) {
79 printf ("GPR%02d: ", i);
80 }
81
82 printf ("%08lX ", regs->gpr[i]);
83 if ((i % 8) == 7) {
84 putc ('\n');
85 }
86 }
87}
88
89
90void
91_exception (int signr, struct pt_regs *regs)
92{
93 show_regs (regs);
94 print_backtrace ((unsigned long *)regs->gpr[1]);
95 panic ("Exception at pc %lx signal %d", regs->nip,signr);
96}
97
98
99void
100MachineCheckException (struct pt_regs *regs)
101{
102 unsigned long fixup;
103
104 if ((fixup = search_exception_table (regs->nip)) != 0) {
105 regs->nip = fixup;
106 return;
107 }
108
Wolfgang Denkafaac862007-08-12 14:27:39 +0200109#ifdef CONFIG_CMD_KGDB
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200110 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
111 return;
112#endif
113
114 puts ("Machine check.\nCaused by (from msr): ");
115 printf ("regs %p ",regs);
116 switch (regs->msr & 0x00FF0000) {
117 case (0x80000000 >> 10):
118 puts ("Instruction cache parity signal\n");
119 break;
120 case (0x80000000 >> 11):
121 puts ("Data cache parity signal\n");
122 break;
123 case (0x80000000 >> 12):
124 puts ("Machine check signal\n");
125 break;
126 case (0x80000000 >> 13):
127 puts ("Transfer error ack signal\n");
128 break;
129 case (0x80000000 >> 14):
130 puts ("Data parity signal\n");
131 break;
132 case (0x80000000 >> 15):
133 puts ("Address parity signal\n");
134 break;
135 default:
136 puts ("Unknown values in msr\n");
137 }
138 show_regs (regs);
139 print_backtrace ((unsigned long *)regs->gpr[1]);
140
141 panic ("machine check");
142}
143
144void
145AlignmentException (struct pt_regs *regs)
146{
Wolfgang Denkafaac862007-08-12 14:27:39 +0200147#ifdef CONFIG_CMD_KGDB
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200148 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
149 return;
150#endif
151 show_regs (regs);
152 print_backtrace ((unsigned long *)regs->gpr[1]);
153 panic ("Alignment Exception");
154}
155
156void
157ProgramCheckException (struct pt_regs *regs)
158{
Wolfgang Denkafaac862007-08-12 14:27:39 +0200159#ifdef CONFIG_CMD_KGDB
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200160 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 ("Program Check Exception");
166}
167
168void
169SoftEmuException (struct pt_regs *regs)
170{
Wolfgang Denkafaac862007-08-12 14:27:39 +0200171#ifdef CONFIG_CMD_KGDB
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200172 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
173 return;
174#endif
175 show_regs (regs);
176 print_backtrace ((unsigned long *)regs->gpr[1]);
177 panic ("Software Emulation Exception");
178}
179
180
181void
182UnknownException (struct pt_regs *regs)
183{
Wolfgang Denkafaac862007-08-12 14:27:39 +0200184#ifdef CONFIG_CMD_KGDB
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200185 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
186 return;
187#endif
188 printf ("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
189 regs->nip, regs->msr, regs->trap);
190 _exception (0, regs);
191}
192
Wolfgang Denkafaac862007-08-12 14:27:39 +0200193#ifdef CONFIG_CMD_BEDBUG
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200194extern void do_bedbug_breakpoint (struct pt_regs *);
195#endif
196
197void
198DebugException (struct pt_regs *regs)
199{
200 printf ("Debugger trap at @ %lx\n", regs->nip );
201 show_regs (regs);
Wolfgang Denkafaac862007-08-12 14:27:39 +0200202#ifdef CONFIG_CMD_BEDBUG
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200203 do_bedbug_breakpoint (regs);
204#endif
205}