blob: e3ce11b2b3e34662967882ed5c09f76df3e98b4f [file] [log] [blame]
wdenk359733b2003-03-31 17:27:09 +00001/*
Stefan Roese88fbf932010-04-15 16:07:28 +02002 * linux/arch/powerpc/kernel/traps.c
wdenk359733b2003-03-31 17:27:09 +00003 *
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>
Mike Frysinger629d88b2010-02-08 15:30:16 -050037#include <kgdb.h>
wdenk359733b2003-03-31 17:27:09 +000038#include <asm/processor.h>
39
Jon Loeliger526e5ce2007-07-09 19:06:00 -050040#if defined(CONFIG_CMD_BEDBUG)
wdenk359733b2003-03-31 17:27:09 +000041extern void do_bedbug_breakpoint(struct pt_regs *);
42#endif
43
44/* Returns 0 if exception not found and fixup otherwise. */
45extern unsigned long search_exception_table(unsigned long);
46
47/* THIS NEEDS CHANGING to use the board info structure.
48*/
49#define END_OF_MEM 0x0001000
50
51
52/*
53 * Print stack backtrace
54 */
55void print_backtrace(unsigned long *sp)
56{
57 int cnt = 0;
58 unsigned long i;
59
60 printf("Call backtrace: ");
61 while (sp) {
62 if ((uint)sp > END_OF_MEM)
63 break;
64
65 i = sp[1];
66 if (cnt++ % 7 == 0)
67 printf("\n");
68 printf("%08lX ", i);
69 if (cnt > 32) break;
70 sp = (unsigned long *)*sp;
71 }
72 printf("\n");
73}
74
75/*
76 * Print current registers
77 */
78void show_regs(struct pt_regs * regs)
79{
80 int i;
81 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
82 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
83 printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
84 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
85 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
86 regs->msr&MSR_IR ? 1 : 0,
87 regs->msr&MSR_DR ? 1 : 0);
88
89 printf("\n");
90 for (i = 0; i < 32; i++) {
91 if ((i % 8) == 0)
92 {
93 printf("GPR%02d: ", i);
94 }
95
96 printf("%08lX ", regs->gpr[i]);
97 if ((i % 8) == 7)
98 {
99 printf("\n");
100 }
101 }
102}
103
104
105/*
106 * General exception handler routine
107 */
108void _exception(int signr, struct pt_regs *regs)
109{
110 show_regs(regs);
111 print_backtrace((unsigned long *)regs->gpr[1]);
112 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
113}
114
115/*
116 * Machine check exception handler routine
117 */
118void MachineCheckException(struct pt_regs *regs)
119{
120 unsigned long fixup;
121
122 /* Probing PCI using config cycles cause this exception
123 * when a device is not present. Catch it and return to
124 * the PCI exception handler.
125 */
126 if ((fixup = search_exception_table(regs->nip)) != 0) {
127 regs->nip = fixup;
128 return;
129 }
130
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500131#if defined(CONFIG_CMD_KGDB)
wdenk359733b2003-03-31 17:27:09 +0000132 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
133 return;
134#endif
135
136 printf("Machine check in kernel mode.\n");
137 printf("Caused by (from msr): ");
138 printf("regs %p ",regs);
wdenke97d3d92004-02-23 22:22:28 +0000139 switch( regs->msr & 0x000F0000) {
140 case (0x80000000>>12):
wdenk359733b2003-03-31 17:27:09 +0000141 printf("Machine check signal\n");
142 break;
wdenke97d3d92004-02-23 22:22:28 +0000143 case (0x80000000>>13):
wdenk359733b2003-03-31 17:27:09 +0000144 printf("Transfer error ack signal\n");
145 break;
wdenke97d3d92004-02-23 22:22:28 +0000146 case (0x80000000>>14):
wdenk359733b2003-03-31 17:27:09 +0000147 printf("Data parity signal\n");
148 break;
wdenke97d3d92004-02-23 22:22:28 +0000149 case (0x80000000>>15):
wdenk359733b2003-03-31 17:27:09 +0000150 printf("Address parity signal\n");
151 break;
152 default:
153 printf("Unknown values in msr\n");
154 }
155 show_regs(regs);
156 print_backtrace((unsigned long *)regs->gpr[1]);
157 panic("machine check");
158}
159
160/*
161 * Alignment exception handler routine
162 */
163void AlignmentException(struct pt_regs *regs)
164{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500165#if defined(CONFIG_CMD_KGDB)
wdenk359733b2003-03-31 17:27:09 +0000166 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
167 return;
168#endif
169 show_regs(regs);
170 print_backtrace((unsigned long *)regs->gpr[1]);
171 panic("Alignment Exception");
172}
173
174/*
175 * Program check exception handler routine
176 */
177void ProgramCheckException(struct pt_regs *regs)
178{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500179#if defined(CONFIG_CMD_KGDB)
wdenk359733b2003-03-31 17:27:09 +0000180 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
181 return;
182#endif
183 show_regs(regs);
184 print_backtrace((unsigned long *)regs->gpr[1]);
185 panic("Program Check Exception");
186}
187
188/*
189 * Software emulation exception handler routine
190 */
191void SoftEmuException(struct pt_regs *regs)
192{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500193#if defined(CONFIG_CMD_KGDB)
wdenk359733b2003-03-31 17:27:09 +0000194 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
195 return;
196#endif
197 show_regs(regs);
198 print_backtrace((unsigned long *)regs->gpr[1]);
199 panic("Software Emulation Exception");
200}
201
202
203/*
204 * Unknown exception handler routine
205 */
206void UnknownException(struct pt_regs *regs)
207{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500208#if defined(CONFIG_CMD_KGDB)
wdenk359733b2003-03-31 17:27:09 +0000209 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
210 return;
211#endif
212 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
213 regs->nip, regs->msr, regs->trap);
214 _exception(0, regs);
215}
216
217/*
218 * Debug exception handler routine
219 */
220void DebugException(struct pt_regs *regs)
221{
222 printf("Debugger trap at @ %lx\n", regs->nip );
Wolfgang Denka1be4762008-05-20 16:00:29 +0200223 show_regs(regs);
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500224#if defined(CONFIG_CMD_BEDBUG)
Wolfgang Denka1be4762008-05-20 16:00:29 +0200225 do_bedbug_breakpoint( regs );
wdenk359733b2003-03-31 17:27:09 +0000226#endif
227}