blob: 9d71b8b73008df9b7bcc5d7e4f9f76ec088e8936 [file] [log] [blame]
Eran Libertyf046ccd2005-07-28 10:08:46 -05001/*
Timur Tabie857a5b2006-11-28 12:09:35 -06002 * (C) Copyright 2000
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
Eran Libertyf046ccd2005-07-28 10:08:46 -05006 *
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
Eran Libertyf046ccd2005-07-28 10:08:46 -050021 */
22
23/*
24 * This file handles the architecture-dependent parts of hardware
25 * exceptions
26 */
27
28#include <common.h>
29#include <command.h>
Mike Frysingere39bf1e2010-02-08 15:30:16 -050030#include <kgdb.h>
Eran Libertyf046ccd2005-07-28 10:08:46 -050031#include <asm/processor.h>
32#include <asm/mpc8349_pci.h>
33
Wolfgang Denkd87080b2006-03-31 18:32:53 +020034DECLARE_GLOBAL_DATA_PTR;
35
Eran Libertyf046ccd2005-07-28 10:08:46 -050036/* Returns 0 if exception not found and fixup otherwise. */
37extern unsigned long search_exception_table(unsigned long);
38
39#define END_OF_MEM (gd->bd->bi_memstart + gd->bd->bi_memsize)
40
41/*
42 * Trap & Exception support
43 */
44
45void
46print_backtrace(unsigned long *sp)
47{
Eran Libertyf046ccd2005-07-28 10:08:46 -050048 int cnt = 0;
49 unsigned long i;
50
51 puts ("Call backtrace: ");
52 while (sp) {
53 if ((uint)sp > END_OF_MEM)
54 break;
55
56 i = sp[1];
57 if (cnt++ % 7 == 0)
58 putc ('\n');
59 printf("%08lX ", i);
60 if (cnt > 32) break;
61 sp = (unsigned long *)*sp;
62 }
63 putc ('\n');
64}
65
66void show_regs(struct pt_regs * regs)
67{
68 int i;
69
70 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
71 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
72 printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
73 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
74 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
75 regs->msr&MSR_IR ? 1 : 0,
76 regs->msr&MSR_DR ? 1 : 0);
77
78 putc ('\n');
79 for (i = 0; i < 32; i++) {
80 if ((i % 8) == 0) {
81 printf("GPR%02d: ", i);
82 }
83
84 printf("%08lX ", regs->gpr[i]);
85 if ((i % 8) == 7) {
86 putc ('\n');
87 }
88 }
89}
90
91
92void
93_exception(int signr, struct pt_regs *regs)
94{
95 show_regs(regs);
96 print_backtrace((unsigned long *)regs->gpr[1]);
97 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
98}
99
100#ifdef CONFIG_PCI
101void dump_pci (void)
102{
103/*
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200104 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500105 printf ("PCI: err status %x err mask %x err ctrl %x\n",
106 le32_to_cpu (immap->im_pci.pci_esr),
107 le32_to_cpu (immap->im_pci.pci_emr),
108 le32_to_cpu (immap->im_pci.pci_ecr));
109 printf (" error address %x error data %x ctrl %x\n",
110 le32_to_cpu (immap->im_pci.pci_eacr),
111 le32_to_cpu (immap->im_pci.pci_edcr),
112 le32_to_cpu (immap->im_pci.pci_eccr));
113*/
114}
115#endif
116
117void
118MachineCheckException(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#ifdef CONFIG_PCI
127#if 0
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200128 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500129#ifdef DEBUG
130 dump_pci();
131#endif
132 /* clear the error in the error status register */
133 if(immap->im_pci.pci_esr & cpu_to_le32(PCI_ERROR_PCI_NO_RSP)) {
134 immap->im_pci.pci_esr = cpu_to_le32(PCI_ERROR_PCI_NO_RSP);
135 return;
136 }
137#endif
138#endif /* CONFIG_PCI */
139 if ((fixup = search_exception_table(regs->nip)) != 0) {
140 regs->nip = fixup;
141 return;
142 }
143
Jon Loeliger44312832007-07-09 19:06:00 -0500144#if defined(CONFIG_CMD_KGDB)
Eran Libertyf046ccd2005-07-28 10:08:46 -0500145 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
146 return;
147#endif
148
149 puts ("Machine check in kernel mode.\n"
150 "Caused by (from msr): ");
151 printf("regs %p ",regs);
152 switch( regs->msr & 0x000F0000) {
153 case (0x80000000>>12):
154 puts ("Machine check signal - probably due to mm fault\n"
155 "with mmu off\n");
156 break;
157 case (0x80000000>>13):
158 puts ("Transfer error ack signal\n");
159 break;
160 case (0x80000000>>14):
161 puts ("Data parity signal\n");
162 break;
163 case (0x80000000>>15):
164 puts ("Address parity signal\n");
165 break;
166 default:
167 puts ("Unknown values in msr\n");
168 }
169 show_regs(regs);
170 print_backtrace((unsigned long *)regs->gpr[1]);
171#ifdef CONFIG_PCI
172 dump_pci();
173#endif
174 panic("machine check");
175}
176
177void
178AlignmentException(struct pt_regs *regs)
179{
Jon Loeliger44312832007-07-09 19:06:00 -0500180#if defined(CONFIG_CMD_KGDB)
Eran Libertyf046ccd2005-07-28 10:08:46 -0500181 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
182 return;
183#endif
184 show_regs(regs);
185 print_backtrace((unsigned long *)regs->gpr[1]);
186 panic("Alignment Exception");
187}
188
189void
190ProgramCheckException(struct pt_regs *regs)
191{
Jon Loeliger44312832007-07-09 19:06:00 -0500192#if defined(CONFIG_CMD_KGDB)
Eran Libertyf046ccd2005-07-28 10:08:46 -0500193 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
194 return;
195#endif
196 show_regs(regs);
197 print_backtrace((unsigned long *)regs->gpr[1]);
198 panic("Program Check Exception");
199}
200
201void
202SoftEmuException(struct pt_regs *regs)
203{
Jon Loeliger44312832007-07-09 19:06:00 -0500204#if defined(CONFIG_CMD_KGDB)
Eran Libertyf046ccd2005-07-28 10:08:46 -0500205 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
206 return;
207#endif
208 show_regs(regs);
209 print_backtrace((unsigned long *)regs->gpr[1]);
210 panic("Software Emulation Exception");
211}
212
213
214void
215UnknownException(struct pt_regs *regs)
216{
Jon Loeliger44312832007-07-09 19:06:00 -0500217#if defined(CONFIG_CMD_KGDB)
Eran Libertyf046ccd2005-07-28 10:08:46 -0500218 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
219 return;
220#endif
221 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
222 regs->nip, regs->msr, regs->trap);
223 _exception(0, regs);
224}
225
Jon Loeliger44312832007-07-09 19:06:00 -0500226#if defined(CONFIG_CMD_BEDBUG)
Eran Libertyf046ccd2005-07-28 10:08:46 -0500227extern void do_bedbug_breakpoint(struct pt_regs *);
228#endif
229
230void
231DebugException(struct pt_regs *regs)
232{
233 printf("Debugger trap at @ %lx\n", regs->nip );
234 show_regs(regs);
Jon Loeliger44312832007-07-09 19:06:00 -0500235#if defined(CONFIG_CMD_BEDBUG)
Eran Libertyf046ccd2005-07-28 10:08:46 -0500236 do_bedbug_breakpoint( regs );
237#endif
238}
239
240/* Probe an address by reading. If not present, return -1, otherwise
241 * return 0.
242 */
243int
244addr_probe(uint *addr)
245{
246#if 0
247 int retval;
248
249 __asm__ __volatile__( \
250 "1: lwz %0,0(%1)\n" \
251 " eieio\n" \
252 " li %0,0\n" \
253 "2:\n" \
254 ".section .fixup,\"ax\"\n" \
255 "3: li %0,-1\n" \
256 " b 2b\n" \
257 ".section __ex_table,\"a\"\n" \
258 " .align 2\n" \
259 " .long 1b,3b\n" \
260 ".text" \
261 : "=r" (retval) : "r"(addr));
262
263 return (retval);
264#endif
265 return 0;
266}