blob: 8000fabd4ade826f19401cfc71942e56384c8535 [file] [log] [blame]
Rafal Jaworowski8993e542007-07-27 14:43:59 +02001/*
2 * (C) Copyright 2000 - 2007
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 *
22 * Derived from the MPC83xx code.
23 */
24
25/*
26 * This file handles the architecture-dependent parts of hardware
27 * exceptions
28 */
29
30#include <common.h>
31#include <asm/processor.h>
32
33DECLARE_GLOBAL_DATA_PTR;
34
35extern unsigned long search_exception_table(unsigned long);
36
Becky Bruce9b124a62008-05-14 13:09:51 -050037/*
38 * End of addressable memory. This may be less than the actual
39 * amount of memory on the system if we're unable to keep all
40 * the memory mapped in.
41 */
42extern ulong get_effective_memsize(void);
43#define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize())
Rafal Jaworowski8993e542007-07-27 14:43:59 +020044
45/*
46 * Trap & Exception support
47 */
48
49void
50print_backtrace (unsigned long *sp)
51{
52 int cnt = 0;
53 unsigned long i;
54
55 puts ("Call backtrace: ");
56 while (sp) {
57 if ((uint)sp > END_OF_MEM)
58 break;
59
60 i = sp[1];
61 if (cnt++ % 7 == 0)
62 putc ('\n');
63 printf ("%08lX ", i);
64 if (cnt > 32) break;
65 sp = (unsigned long *) *sp;
66 }
67 putc ('\n');
68}
69
70void show_regs (struct pt_regs * regs)
71{
72 int i;
73
74 printf ("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
75 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
76 printf ("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
77 regs->msr, regs->msr & MSR_EE ? 1 : 0, regs->msr & MSR_PR ? 1 : 0,
78 regs->msr & MSR_FP ? 1 : 0,regs->msr & MSR_ME ? 1 : 0,
79 regs->msr & MSR_IR ? 1 : 0,
80 regs->msr & MSR_DR ? 1 : 0);
81
82 putc ('\n');
83 for (i = 0; i < 32; i++) {
84 if ((i % 8) == 0) {
85 printf ("GPR%02d: ", i);
86 }
87
88 printf ("%08lX ", regs->gpr[i]);
89 if ((i % 8) == 7) {
90 putc ('\n');
91 }
92 }
93}
94
95
96void
97_exception (int signr, struct pt_regs *regs)
98{
99 show_regs (regs);
100 print_backtrace ((unsigned long *)regs->gpr[1]);
101 panic ("Exception at pc %lx signal %d", regs->nip,signr);
102}
103
104
105void
106MachineCheckException (struct pt_regs *regs)
107{
108 unsigned long fixup;
109
110 if ((fixup = search_exception_table (regs->nip)) != 0) {
111 regs->nip = fixup;
112 return;
113 }
114
Wolfgang Denkafaac862007-08-12 14:27:39 +0200115#ifdef CONFIG_CMD_KGDB
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200116 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
117 return;
118#endif
119
120 puts ("Machine check.\nCaused by (from msr): ");
121 printf ("regs %p ",regs);
122 switch (regs->msr & 0x00FF0000) {
123 case (0x80000000 >> 10):
124 puts ("Instruction cache parity signal\n");
125 break;
126 case (0x80000000 >> 11):
127 puts ("Data cache parity signal\n");
128 break;
129 case (0x80000000 >> 12):
130 puts ("Machine check signal\n");
131 break;
132 case (0x80000000 >> 13):
133 puts ("Transfer error ack signal\n");
134 break;
135 case (0x80000000 >> 14):
136 puts ("Data parity signal\n");
137 break;
138 case (0x80000000 >> 15):
139 puts ("Address parity signal\n");
140 break;
141 default:
142 puts ("Unknown values in msr\n");
143 }
144 show_regs (regs);
145 print_backtrace ((unsigned long *)regs->gpr[1]);
146
147 panic ("machine check");
148}
149
150void
151AlignmentException (struct pt_regs *regs)
152{
Wolfgang Denkafaac862007-08-12 14:27:39 +0200153#ifdef CONFIG_CMD_KGDB
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200154 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
155 return;
156#endif
157 show_regs (regs);
158 print_backtrace ((unsigned long *)regs->gpr[1]);
159 panic ("Alignment Exception");
160}
161
162void
163ProgramCheckException (struct pt_regs *regs)
164{
Wolfgang Denkafaac862007-08-12 14:27:39 +0200165#ifdef CONFIG_CMD_KGDB
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200166 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 ("Program Check Exception");
172}
173
174void
175SoftEmuException (struct pt_regs *regs)
176{
Wolfgang Denkafaac862007-08-12 14:27:39 +0200177#ifdef CONFIG_CMD_KGDB
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200178 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
187void
188UnknownException (struct pt_regs *regs)
189{
Wolfgang Denkafaac862007-08-12 14:27:39 +0200190#ifdef CONFIG_CMD_KGDB
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200191 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
192 return;
193#endif
194 printf ("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
195 regs->nip, regs->msr, regs->trap);
196 _exception (0, regs);
197}
198
Wolfgang Denkafaac862007-08-12 14:27:39 +0200199#ifdef CONFIG_CMD_BEDBUG
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200200extern void do_bedbug_breakpoint (struct pt_regs *);
201#endif
202
203void
204DebugException (struct pt_regs *regs)
205{
206 printf ("Debugger trap at @ %lx\n", regs->nip );
207 show_regs (regs);
Wolfgang Denkafaac862007-08-12 14:27:39 +0200208#ifdef CONFIG_CMD_BEDBUG
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200209 do_bedbug_breakpoint (regs);
210#endif
211}