blob: 78c820ae7e3f2d7eba4a5cf8e961a56a42039e45 [file] [log] [blame]
wdenk359733b2003-03-31 17:27:09 +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
Jon Loeliger526e5ce2007-07-09 19:06:00 -050039#if defined(CONFIG_CMD_KGDB)
wdenk359733b2003-03-31 17:27:09 +000040int (*debugger_exception_handler)(struct pt_regs *) = 0;
41#endif
42
Jon Loeliger526e5ce2007-07-09 19:06:00 -050043#if defined(CONFIG_CMD_BEDBUG)
wdenk359733b2003-03-31 17:27:09 +000044extern 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 0x0001000
53
54
55/*
56 * Print stack backtrace
57 */
58void print_backtrace(unsigned long *sp)
59{
60 int cnt = 0;
61 unsigned long i;
62
63 printf("Call backtrace: ");
64 while (sp) {
65 if ((uint)sp > END_OF_MEM)
66 break;
67
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;
74 }
75 printf("\n");
76}
77
78/*
79 * Print current registers
80 */
81void show_regs(struct pt_regs * regs)
82{
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);
91
92 printf("\n");
93 for (i = 0; i < 32; i++) {
94 if ((i % 8) == 0)
95 {
96 printf("GPR%02d: ", i);
97 }
98
99 printf("%08lX ", regs->gpr[i]);
100 if ((i % 8) == 7)
101 {
102 printf("\n");
103 }
104 }
105}
106
107
108/*
109 * General exception handler routine
110 */
111void _exception(int signr, struct pt_regs *regs)
112{
113 show_regs(regs);
114 print_backtrace((unsigned long *)regs->gpr[1]);
115 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
116}
117
118/*
119 * Machine check exception handler routine
120 */
121void MachineCheckException(struct pt_regs *regs)
122{
123 unsigned long fixup;
124
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.
128 */
129 if ((fixup = search_exception_table(regs->nip)) != 0) {
130 regs->nip = fixup;
131 return;
132 }
133
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500134#if defined(CONFIG_CMD_KGDB)
wdenk359733b2003-03-31 17:27:09 +0000135 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
136 return;
137#endif
138
139 printf("Machine check in kernel mode.\n");
140 printf("Caused by (from msr): ");
141 printf("regs %p ",regs);
wdenke97d3d92004-02-23 22:22:28 +0000142 switch( regs->msr & 0x000F0000) {
143 case (0x80000000>>12):
wdenk359733b2003-03-31 17:27:09 +0000144 printf("Machine check signal\n");
145 break;
wdenke97d3d92004-02-23 22:22:28 +0000146 case (0x80000000>>13):
wdenk359733b2003-03-31 17:27:09 +0000147 printf("Transfer error ack signal\n");
148 break;
wdenke97d3d92004-02-23 22:22:28 +0000149 case (0x80000000>>14):
wdenk359733b2003-03-31 17:27:09 +0000150 printf("Data parity signal\n");
151 break;
wdenke97d3d92004-02-23 22:22:28 +0000152 case (0x80000000>>15):
wdenk359733b2003-03-31 17:27:09 +0000153 printf("Address parity signal\n");
154 break;
155 default:
156 printf("Unknown values in msr\n");
157 }
158 show_regs(regs);
159 print_backtrace((unsigned long *)regs->gpr[1]);
160 panic("machine check");
161}
162
163/*
164 * Alignment exception handler routine
165 */
166void AlignmentException(struct pt_regs *regs)
167{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500168#if defined(CONFIG_CMD_KGDB)
wdenk359733b2003-03-31 17:27:09 +0000169 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");
175}
176
177/*
178 * Program check exception handler routine
179 */
180void ProgramCheckException(struct pt_regs *regs)
181{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500182#if defined(CONFIG_CMD_KGDB)
wdenk359733b2003-03-31 17:27:09 +0000183 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");
189}
190
191/*
192 * Software emulation exception handler routine
193 */
194void SoftEmuException(struct pt_regs *regs)
195{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500196#if defined(CONFIG_CMD_KGDB)
wdenk359733b2003-03-31 17:27:09 +0000197 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");
203}
204
205
206/*
207 * Unknown exception handler routine
208 */
209void UnknownException(struct pt_regs *regs)
210{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500211#if defined(CONFIG_CMD_KGDB)
wdenk359733b2003-03-31 17:27:09 +0000212 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);
218}
219
220/*
221 * Debug exception handler routine
222 */
223void DebugException(struct pt_regs *regs)
224{
225 printf("Debugger trap at @ %lx\n", regs->nip );
Wolfgang Denka1be4762008-05-20 16:00:29 +0200226 show_regs(regs);
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500227#if defined(CONFIG_CMD_BEDBUG)
Wolfgang Denka1be4762008-05-20 16:00:29 +0200228 do_bedbug_breakpoint( regs );
wdenk359733b2003-03-31 17:27:09 +0000229#endif
230}