1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35#include <common.h>
36#include <command.h>
37#include <asm/processor.h>
38
39#if defined(CONFIG_CMD_KGDB)
40int (*debugger_exception_handler)(struct pt_regs *) = 0;
41#endif
42
43#if defined(CONFIG_CMD_BEDBUG)
44extern void do_bedbug_breakpoint(struct pt_regs *);
45#endif
46
47
48extern unsigned long search_exception_table(unsigned long);
49
50
51
52#define END_OF_MEM 0x0001000
53
54
55
56
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
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
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
120
121void MachineCheckException(struct pt_regs *regs)
122{
123 unsigned long fixup;
124
125
126
127
128
129 if ((fixup = search_exception_table(regs->nip)) != 0) {
130 regs->nip = fixup;
131 return;
132 }
133
134#if defined(CONFIG_CMD_KGDB)
135 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);
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");
157 }
158 show_regs(regs);
159 print_backtrace((unsigned long *)regs->gpr[1]);
160 panic("machine check");
161}
162
163
164
165
166void AlignmentException(struct pt_regs *regs)
167{
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");
175}
176
177
178
179
180void ProgramCheckException(struct pt_regs *regs)
181{
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");
189}
190
191
192
193
194void SoftEmuException(struct pt_regs *regs)
195{
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");
203}
204
205
206
207
208
209void UnknownException(struct pt_regs *regs)
210{
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);
218}
219
220
221
222
223void DebugException(struct pt_regs *regs)
224{
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
230}
231