blob: 6f31d814936f1f779b45e43cecef6f41cc401f03 [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020012 * SPDX-License-Identifier: GPL-2.0+
wdenk359733b2003-03-31 17:27:09 +000013 */
14
15/*
16 * This file handles the architecture-dependent parts of hardware exceptions
17 */
18
19#include <common.h>
20#include <command.h>
Mike Frysinger629d88b2010-02-08 15:30:16 -050021#include <kgdb.h>
wdenk359733b2003-03-31 17:27:09 +000022#include <asm/processor.h>
23
Jon Loeliger526e5ce2007-07-09 19:06:00 -050024#if defined(CONFIG_CMD_BEDBUG)
wdenk359733b2003-03-31 17:27:09 +000025extern void do_bedbug_breakpoint(struct pt_regs *);
26#endif
27
28/* Returns 0 if exception not found and fixup otherwise. */
29extern unsigned long search_exception_table(unsigned long);
30
31/* THIS NEEDS CHANGING to use the board info structure.
32*/
33#define END_OF_MEM 0x0001000
34
35
36/*
37 * Print stack backtrace
38 */
Kim Phillipse16737f2012-10-29 13:34:29 +000039static void print_backtrace(unsigned long *sp)
wdenk359733b2003-03-31 17:27:09 +000040{
41 int cnt = 0;
42 unsigned long i;
43
44 printf("Call backtrace: ");
45 while (sp) {
46 if ((uint)sp > END_OF_MEM)
47 break;
48
49 i = sp[1];
50 if (cnt++ % 7 == 0)
51 printf("\n");
52 printf("%08lX ", i);
53 if (cnt > 32) break;
54 sp = (unsigned long *)*sp;
55 }
56 printf("\n");
57}
58
59/*
60 * Print current registers
61 */
Kim Phillipse16737f2012-10-29 13:34:29 +000062void show_regs(struct pt_regs *regs)
wdenk359733b2003-03-31 17:27:09 +000063{
64 int i;
65 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
66 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
67 printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
68 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
69 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
70 regs->msr&MSR_IR ? 1 : 0,
71 regs->msr&MSR_DR ? 1 : 0);
72
73 printf("\n");
74 for (i = 0; i < 32; i++) {
75 if ((i % 8) == 0)
76 {
77 printf("GPR%02d: ", i);
78 }
79
80 printf("%08lX ", regs->gpr[i]);
81 if ((i % 8) == 7)
82 {
83 printf("\n");
84 }
85 }
86}
87
88
89/*
90 * General exception handler routine
91 */
Kim Phillipse16737f2012-10-29 13:34:29 +000092static void _exception(int signr, struct pt_regs *regs)
wdenk359733b2003-03-31 17:27:09 +000093{
94 show_regs(regs);
95 print_backtrace((unsigned long *)regs->gpr[1]);
96 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
97}
98
99/*
100 * Machine check exception handler routine
101 */
102void MachineCheckException(struct pt_regs *regs)
103{
104 unsigned long fixup;
105
106 /* Probing PCI using config cycles cause this exception
107 * when a device is not present. Catch it and return to
108 * the PCI exception handler.
109 */
110 if ((fixup = search_exception_table(regs->nip)) != 0) {
111 regs->nip = fixup;
112 return;
113 }
114
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500115#if defined(CONFIG_CMD_KGDB)
wdenk359733b2003-03-31 17:27:09 +0000116 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
117 return;
118#endif
119
120 printf("Machine check in kernel mode.\n");
121 printf("Caused by (from msr): ");
122 printf("regs %p ",regs);
wdenke97d3d92004-02-23 22:22:28 +0000123 switch( regs->msr & 0x000F0000) {
124 case (0x80000000>>12):
wdenk359733b2003-03-31 17:27:09 +0000125 printf("Machine check signal\n");
126 break;
wdenke97d3d92004-02-23 22:22:28 +0000127 case (0x80000000>>13):
wdenk359733b2003-03-31 17:27:09 +0000128 printf("Transfer error ack signal\n");
129 break;
wdenke97d3d92004-02-23 22:22:28 +0000130 case (0x80000000>>14):
wdenk359733b2003-03-31 17:27:09 +0000131 printf("Data parity signal\n");
132 break;
wdenke97d3d92004-02-23 22:22:28 +0000133 case (0x80000000>>15):
wdenk359733b2003-03-31 17:27:09 +0000134 printf("Address parity signal\n");
135 break;
136 default:
137 printf("Unknown values in msr\n");
138 }
139 show_regs(regs);
140 print_backtrace((unsigned long *)regs->gpr[1]);
141 panic("machine check");
142}
143
144/*
145 * Alignment exception handler routine
146 */
147void AlignmentException(struct pt_regs *regs)
148{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500149#if defined(CONFIG_CMD_KGDB)
wdenk359733b2003-03-31 17:27:09 +0000150 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
151 return;
152#endif
153 show_regs(regs);
154 print_backtrace((unsigned long *)regs->gpr[1]);
155 panic("Alignment Exception");
156}
157
158/*
159 * Program check exception handler routine
160 */
161void ProgramCheckException(struct pt_regs *regs)
162{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500163#if defined(CONFIG_CMD_KGDB)
wdenk359733b2003-03-31 17:27:09 +0000164 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
165 return;
166#endif
167 show_regs(regs);
168 print_backtrace((unsigned long *)regs->gpr[1]);
169 panic("Program Check Exception");
170}
171
172/*
173 * Software emulation exception handler routine
174 */
175void SoftEmuException(struct pt_regs *regs)
176{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500177#if defined(CONFIG_CMD_KGDB)
wdenk359733b2003-03-31 17:27:09 +0000178 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
179 return;
180#endif
181 show_regs(regs);
182 print_backtrace((unsigned long *)regs->gpr[1]);
183 panic("Software Emulation Exception");
184}
185
186
187/*
188 * Unknown exception handler routine
189 */
190void UnknownException(struct pt_regs *regs)
191{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500192#if defined(CONFIG_CMD_KGDB)
wdenk359733b2003-03-31 17:27:09 +0000193 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
194 return;
195#endif
196 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
197 regs->nip, regs->msr, regs->trap);
198 _exception(0, regs);
199}
200
201/*
202 * Debug exception handler routine
203 */
204void DebugException(struct pt_regs *regs)
205{
206 printf("Debugger trap at @ %lx\n", regs->nip );
Wolfgang Denka1be4762008-05-20 16:00:29 +0200207 show_regs(regs);
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500208#if defined(CONFIG_CMD_BEDBUG)
Wolfgang Denka1be4762008-05-20 16:00:29 +0200209 do_bedbug_breakpoint( regs );
wdenk359733b2003-03-31 17:27:09 +0000210#endif
211}