]> git.ipfire.org Git - people/ms/u-boot.git/blame - arch/powerpc/cpu/mpc5xxx/traps.c
Move arch/ppc to arch/powerpc
[people/ms/u-boot.git] / arch / powerpc / cpu / mpc5xxx / traps.c
CommitLineData
945af8d7 1/*
a47a12be 2 * linux/arch/powerpc/kernel/traps.c
945af8d7
WD
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)
63e73c9a 8 * fixed Machine Check Reasons by Reinhard Meyer (r.meyer@emk-elektronik.de)
945af8d7
WD
9 *
10 * (C) Copyright 2000-2003
11 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
12 *
13 * See file CREDITS for list of people who contributed to this
14 * project.
15 *
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of
19 * the License, or (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
30 */
31
32/*
33 * This file handles the architecture-dependent parts of hardware exceptions
34 */
35
36#include <common.h>
37#include <command.h>
e39bf1e2 38#include <kgdb.h>
945af8d7
WD
39#include <asm/processor.h>
40
945af8d7
WD
41/* Returns 0 if exception not found and fixup otherwise. */
42extern unsigned long search_exception_table(unsigned long);
43
44/* THIS NEEDS CHANGING to use the board info structure.
45*/
46#define END_OF_MEM 0x02000000
47
48/*
49 * Trap & Exception support
50 */
51
52void
53print_backtrace(unsigned long *sp)
54{
55 int cnt = 0;
56 unsigned long i;
57
58 printf("Call backtrace: ");
59 while (sp) {
60 if ((uint)sp > END_OF_MEM)
61 break;
62
63 i = sp[1];
64 if (cnt++ % 7 == 0)
65 printf("\n");
66 printf("%08lX ", i);
67 if (cnt > 32) break;
68 sp = (unsigned long *)*sp;
69 }
70 printf("\n");
71}
72
73void show_regs(struct pt_regs * regs)
74{
75 int i;
76
77 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
78 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
79 printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
80 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
81 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
82 regs->msr&MSR_IR ? 1 : 0,
83 regs->msr&MSR_DR ? 1 : 0);
84
85 printf("\n");
86 for (i = 0; i < 32; i++) {
87 if ((i % 8) == 0)
88 {
89 printf("GPR%02d: ", i);
90 }
91
92 printf("%08lX ", regs->gpr[i]);
93 if ((i % 8) == 7)
94 {
95 printf("\n");
96 }
97 }
98}
99
100
101void
102_exception(int signr, struct pt_regs *regs)
103{
104 show_regs(regs);
105 print_backtrace((unsigned long *)regs->gpr[1]);
106 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
107}
108
109void
110MachineCheckException(struct pt_regs *regs)
111{
112 unsigned long fixup;
113
114 /* Probing PCI using config cycles cause this exception
115 * when a device is not present. Catch it and return to
116 * the PCI exception handler.
117 */
118 if ((fixup = search_exception_table(regs->nip)) != 0) {
119 regs->nip = fixup;
120 return;
121 }
122
4431283c 123#if defined(CONFIG_CMD_KGDB)
945af8d7
WD
124 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
125 return;
126#endif
127
128 printf("Machine check in kernel mode.\n");
129 printf("Caused by (from msr): ");
130 printf("regs %p ",regs);
63e73c9a
WD
131 /* refer to 603e Manual (MPC603EUM/AD), chapter 4.5.2.1 */
132 switch( regs->msr & 0x000F0000)
945af8d7 133 {
63e73c9a 134 case (0x80000000>>12) :
945af8d7
WD
135 printf("Machine check signal - probably due to mm fault\n"
136 "with mmu off\n");
137 break;
63e73c9a 138 case (0x80000000>>13) :
945af8d7
WD
139 printf("Transfer error ack signal\n");
140 break;
63e73c9a 141 case (0x80000000>>14) :
945af8d7
WD
142 printf("Data parity signal\n");
143 break;
63e73c9a 144 case (0x80000000>>15) :
945af8d7
WD
145 printf("Address parity signal\n");
146 break;
147 default:
148 printf("Unknown values in msr\n");
149 }
150 show_regs(regs);
151 print_backtrace((unsigned long *)regs->gpr[1]);
152 panic("machine check");
153}
154
155void
156AlignmentException(struct pt_regs *regs)
157{
4431283c 158#if defined(CONFIG_CMD_KGDB)
945af8d7
WD
159 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
160 return;
161#endif
162 show_regs(regs);
163 print_backtrace((unsigned long *)regs->gpr[1]);
164 panic("Alignment Exception");
165}
166
167void
168ProgramCheckException(struct pt_regs *regs)
169{
4431283c 170#if defined(CONFIG_CMD_KGDB)
945af8d7
WD
171 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
172 return;
173#endif
174 show_regs(regs);
175 print_backtrace((unsigned long *)regs->gpr[1]);
176 panic("Program Check Exception");
177}
178
179void
180SoftEmuException(struct pt_regs *regs)
181{
4431283c 182#if defined(CONFIG_CMD_KGDB)
945af8d7
WD
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("Software Emulation Exception");
189}
190
191
192void
193UnknownException(struct pt_regs *regs)
194{
4431283c 195#if defined(CONFIG_CMD_KGDB)
945af8d7
WD
196 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
197 return;
198#endif
199 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
200 regs->nip, regs->msr, regs->trap);
201 _exception(0, regs);
202}
203
4431283c 204#if defined(CONFIG_CMD_BEDBUG)
945af8d7
WD
205extern void do_bedbug_breakpoint(struct pt_regs *);
206#endif
207
208void
209DebugException(struct pt_regs *regs)
210{
211
212 printf("Debugger trap at @ %lx\n", regs->nip );
213 show_regs(regs);
4431283c 214#if defined(CONFIG_CMD_BEDBUG)
945af8d7
WD
215 do_bedbug_breakpoint( regs );
216#endif
217}
218
219/* Probe an address by reading. If not present, return -1, otherwise
220 * return 0.
221 */
222int
223addr_probe(uint *addr)
224{
225#if 0
226 int retval;
227
228 __asm__ __volatile__( \
229 "1: lwz %0,0(%1)\n" \
230 " eieio\n" \
231 " li %0,0\n" \
232 "2:\n" \
233 ".section .fixup,\"ax\"\n" \
234 "3: li %0,-1\n" \
235 " b 2b\n" \
236 ".section __ex_table,\"a\"\n" \
237 " .align 2\n" \
238 " .long 1b,3b\n" \
239 ".text" \
240 : "=r" (retval) : "r"(addr));
241
242 return (retval);
243#endif
244 return 0;
245}