blob: 53a1062ea82aea35d5fe43bea922879680a00ce9 [file] [log] [blame]
Eran Liberty9095d4a2005-07-28 10:08:46 -05001/*
Timur Tabiff0215a2006-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 Liberty9095d4a2005-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 Liberty9095d4a2005-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 Frysinger629d88b2010-02-08 15:30:16 -050030#include <kgdb.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050031#include <asm/processor.h>
32#include <asm/mpc8349_pci.h>
33
Wolfgang Denk6405a152006-03-31 18:32:53 +020034DECLARE_GLOBAL_DATA_PTR;
35
Eran Liberty9095d4a2005-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
Kim Phillipse16737f2012-10-29 13:34:29 +000045static void print_backtrace(unsigned long *sp)
Eran Liberty9095d4a2005-07-28 10:08:46 -050046{
Eran Liberty9095d4a2005-07-28 10:08:46 -050047 int cnt = 0;
48 unsigned long i;
49
50 puts ("Call backtrace: ");
51 while (sp) {
52 if ((uint)sp > END_OF_MEM)
53 break;
54
55 i = sp[1];
56 if (cnt++ % 7 == 0)
57 putc ('\n');
58 printf("%08lX ", i);
59 if (cnt > 32) break;
60 sp = (unsigned long *)*sp;
61 }
62 putc ('\n');
63}
64
Kim Phillipse16737f2012-10-29 13:34:29 +000065void show_regs(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -050066{
67 int i;
68
69 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
70 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
71 printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
72 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
73 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
74 regs->msr&MSR_IR ? 1 : 0,
75 regs->msr&MSR_DR ? 1 : 0);
76
77 putc ('\n');
78 for (i = 0; i < 32; i++) {
79 if ((i % 8) == 0) {
80 printf("GPR%02d: ", i);
81 }
82
83 printf("%08lX ", regs->gpr[i]);
84 if ((i % 8) == 7) {
85 putc ('\n');
86 }
87 }
88}
89
90
Kim Phillipse16737f2012-10-29 13:34:29 +000091static void _exception(int signr, struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -050092{
93 show_regs(regs);
94 print_backtrace((unsigned long *)regs->gpr[1]);
95 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
96}
97
98#ifdef CONFIG_PCI
99void dump_pci (void)
100{
101/*
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200102 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500103 printf ("PCI: err status %x err mask %x err ctrl %x\n",
104 le32_to_cpu (immap->im_pci.pci_esr),
105 le32_to_cpu (immap->im_pci.pci_emr),
106 le32_to_cpu (immap->im_pci.pci_ecr));
107 printf (" error address %x error data %x ctrl %x\n",
108 le32_to_cpu (immap->im_pci.pci_eacr),
109 le32_to_cpu (immap->im_pci.pci_edcr),
110 le32_to_cpu (immap->im_pci.pci_eccr));
111*/
112}
113#endif
114
Kim Phillipse16737f2012-10-29 13:34:29 +0000115void MachineCheckException(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500116{
117 unsigned long fixup;
118
119 /* Probing PCI using config cycles cause this exception
120 * when a device is not present. Catch it and return to
121 * the PCI exception handler.
122 */
123#ifdef CONFIG_PCI
124#if 0
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200125 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500126#ifdef DEBUG
127 dump_pci();
128#endif
129 /* clear the error in the error status register */
130 if(immap->im_pci.pci_esr & cpu_to_le32(PCI_ERROR_PCI_NO_RSP)) {
131 immap->im_pci.pci_esr = cpu_to_le32(PCI_ERROR_PCI_NO_RSP);
132 return;
133 }
134#endif
135#endif /* CONFIG_PCI */
136 if ((fixup = search_exception_table(regs->nip)) != 0) {
137 regs->nip = fixup;
138 return;
139 }
140
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500141#if defined(CONFIG_CMD_KGDB)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500142 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
143 return;
144#endif
145
146 puts ("Machine check in kernel mode.\n"
147 "Caused by (from msr): ");
148 printf("regs %p ",regs);
149 switch( regs->msr & 0x000F0000) {
150 case (0x80000000>>12):
151 puts ("Machine check signal - probably due to mm fault\n"
152 "with mmu off\n");
153 break;
154 case (0x80000000>>13):
155 puts ("Transfer error ack signal\n");
156 break;
157 case (0x80000000>>14):
158 puts ("Data parity signal\n");
159 break;
160 case (0x80000000>>15):
161 puts ("Address parity signal\n");
162 break;
163 default:
164 puts ("Unknown values in msr\n");
165 }
166 show_regs(regs);
167 print_backtrace((unsigned long *)regs->gpr[1]);
168#ifdef CONFIG_PCI
169 dump_pci();
170#endif
171 panic("machine check");
172}
173
Kim Phillipse16737f2012-10-29 13:34:29 +0000174void AlignmentException(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500175{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500176#if defined(CONFIG_CMD_KGDB)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500177 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
178 return;
179#endif
180 show_regs(regs);
181 print_backtrace((unsigned long *)regs->gpr[1]);
182 panic("Alignment Exception");
183}
184
Kim Phillipse16737f2012-10-29 13:34:29 +0000185void ProgramCheckException(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500186{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500187#if defined(CONFIG_CMD_KGDB)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500188 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
189 return;
190#endif
191 show_regs(regs);
192 print_backtrace((unsigned long *)regs->gpr[1]);
193 panic("Program Check Exception");
194}
195
Kim Phillipse16737f2012-10-29 13:34:29 +0000196void SoftEmuException(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500197{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500198#if defined(CONFIG_CMD_KGDB)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500199 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
200 return;
201#endif
202 show_regs(regs);
203 print_backtrace((unsigned long *)regs->gpr[1]);
204 panic("Software Emulation Exception");
205}
206
207
Kim Phillipse16737f2012-10-29 13:34:29 +0000208void UnknownException(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500209{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500210#if defined(CONFIG_CMD_KGDB)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500211 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
212 return;
213#endif
214 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
215 regs->nip, regs->msr, regs->trap);
216 _exception(0, regs);
217}
218
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500219#if defined(CONFIG_CMD_BEDBUG)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500220extern void do_bedbug_breakpoint(struct pt_regs *);
221#endif
222
Kim Phillipse16737f2012-10-29 13:34:29 +0000223void DebugException(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500224{
225 printf("Debugger trap at @ %lx\n", regs->nip );
226 show_regs(regs);
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500227#if defined(CONFIG_CMD_BEDBUG)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500228 do_bedbug_breakpoint( regs );
229#endif
230}
231
232/* Probe an address by reading. If not present, return -1, otherwise
233 * return 0.
234 */
Kim Phillipse16737f2012-10-29 13:34:29 +0000235int addr_probe(uint *addr)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500236{
237#if 0
238 int retval;
239
240 __asm__ __volatile__( \
241 "1: lwz %0,0(%1)\n" \
242 " eieio\n" \
243 " li %0,0\n" \
244 "2:\n" \
245 ".section .fixup,\"ax\"\n" \
246 "3: li %0,-1\n" \
247 " b 2b\n" \
248 ".section __ex_table,\"a\"\n" \
249 " .align 2\n" \
250 " .long 1b,3b\n" \
251 ".text" \
252 : "=r" (retval) : "r"(addr));
253
254 return (retval);
255#endif
256 return 0;
257}