]> git.ipfire.org Git - people/ms/u-boot.git/blame - cpu/mpc83xx/traps.c
GCC-4.x fixes: clean up global data pointer initialization for all boards.
[people/ms/u-boot.git] / cpu / mpc83xx / traps.c
CommitLineData
f046ccd1
EL
1/*
2 * linux/arch/ppc/kernel/traps.c
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
17 * MA 02111-1307 USA
18 *
19 * Change log:
20 *
21 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
22 *
23 * Modified by Cort Dougan (cort@cs.nmt.edu)
24 * and Paul Mackerras (paulus@cs.anu.edu.au)
25 *
26 * (C) Copyright 2000
27 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
28 *
29 * 20050101: Eran Liberty (liberty@freescale.com)
30 * Initial file creating (porting from 85XX & 8260)
31 */
32
33/*
34 * This file handles the architecture-dependent parts of hardware
35 * exceptions
36 */
37
38#include <common.h>
39#include <command.h>
40#include <asm/processor.h>
41#include <asm/mpc8349_pci.h>
42
d87080b7
WD
43DECLARE_GLOBAL_DATA_PTR;
44
f046ccd1
EL
45/* Returns 0 if exception not found and fixup otherwise. */
46extern unsigned long search_exception_table(unsigned long);
47
48#define END_OF_MEM (gd->bd->bi_memstart + gd->bd->bi_memsize)
49
50/*
51 * Trap & Exception support
52 */
53
54void
55print_backtrace(unsigned long *sp)
56{
f046ccd1
EL
57 int cnt = 0;
58 unsigned long i;
59
60 puts ("Call backtrace: ");
61 while (sp) {
62 if ((uint)sp > END_OF_MEM)
63 break;
64
65 i = sp[1];
66 if (cnt++ % 7 == 0)
67 putc ('\n');
68 printf("%08lX ", i);
69 if (cnt > 32) break;
70 sp = (unsigned long *)*sp;
71 }
72 putc ('\n');
73}
74
75void show_regs(struct pt_regs * regs)
76{
77 int i;
78
79 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
80 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
81 printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
82 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
83 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
84 regs->msr&MSR_IR ? 1 : 0,
85 regs->msr&MSR_DR ? 1 : 0);
86
87 putc ('\n');
88 for (i = 0; i < 32; i++) {
89 if ((i % 8) == 0) {
90 printf("GPR%02d: ", i);
91 }
92
93 printf("%08lX ", regs->gpr[i]);
94 if ((i % 8) == 7) {
95 putc ('\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
109#ifdef CONFIG_PCI
110void dump_pci (void)
111{
112/*
113 volatile immap_t *immap = (immap_t *) CFG_IMMR;
114 printf ("PCI: err status %x err mask %x err ctrl %x\n",
115 le32_to_cpu (immap->im_pci.pci_esr),
116 le32_to_cpu (immap->im_pci.pci_emr),
117 le32_to_cpu (immap->im_pci.pci_ecr));
118 printf (" error address %x error data %x ctrl %x\n",
119 le32_to_cpu (immap->im_pci.pci_eacr),
120 le32_to_cpu (immap->im_pci.pci_edcr),
121 le32_to_cpu (immap->im_pci.pci_eccr));
122*/
123}
124#endif
125
126void
127MachineCheckException(struct pt_regs *regs)
128{
129 unsigned long fixup;
130
131 /* Probing PCI using config cycles cause this exception
132 * when a device is not present. Catch it and return to
133 * the PCI exception handler.
134 */
135#ifdef CONFIG_PCI
136#if 0
137 volatile immap_t *immap = (immap_t *)CFG_IMMR;
138#ifdef DEBUG
139 dump_pci();
140#endif
141 /* clear the error in the error status register */
142 if(immap->im_pci.pci_esr & cpu_to_le32(PCI_ERROR_PCI_NO_RSP)) {
143 immap->im_pci.pci_esr = cpu_to_le32(PCI_ERROR_PCI_NO_RSP);
144 return;
145 }
146#endif
147#endif /* CONFIG_PCI */
148 if ((fixup = search_exception_table(regs->nip)) != 0) {
149 regs->nip = fixup;
150 return;
151 }
152
153#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
154 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
155 return;
156#endif
157
158 puts ("Machine check in kernel mode.\n"
159 "Caused by (from msr): ");
160 printf("regs %p ",regs);
161 switch( regs->msr & 0x000F0000) {
162 case (0x80000000>>12):
163 puts ("Machine check signal - probably due to mm fault\n"
164 "with mmu off\n");
165 break;
166 case (0x80000000>>13):
167 puts ("Transfer error ack signal\n");
168 break;
169 case (0x80000000>>14):
170 puts ("Data parity signal\n");
171 break;
172 case (0x80000000>>15):
173 puts ("Address parity signal\n");
174 break;
175 default:
176 puts ("Unknown values in msr\n");
177 }
178 show_regs(regs);
179 print_backtrace((unsigned long *)regs->gpr[1]);
180#ifdef CONFIG_PCI
181 dump_pci();
182#endif
183 panic("machine check");
184}
185
186void
187AlignmentException(struct pt_regs *regs)
188{
189#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
190 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
191 return;
192#endif
193 show_regs(regs);
194 print_backtrace((unsigned long *)regs->gpr[1]);
195 panic("Alignment Exception");
196}
197
198void
199ProgramCheckException(struct pt_regs *regs)
200{
201#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
202 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
203 return;
204#endif
205 show_regs(regs);
206 print_backtrace((unsigned long *)regs->gpr[1]);
207 panic("Program Check Exception");
208}
209
210void
211SoftEmuException(struct pt_regs *regs)
212{
213#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
214 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
215 return;
216#endif
217 show_regs(regs);
218 print_backtrace((unsigned long *)regs->gpr[1]);
219 panic("Software Emulation Exception");
220}
221
222
223void
224UnknownException(struct pt_regs *regs)
225{
226#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
227 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
228 return;
229#endif
230 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
231 regs->nip, regs->msr, regs->trap);
232 _exception(0, regs);
233}
234
235#if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
236extern void do_bedbug_breakpoint(struct pt_regs *);
237#endif
238
239void
240DebugException(struct pt_regs *regs)
241{
242 printf("Debugger trap at @ %lx\n", regs->nip );
243 show_regs(regs);
244#if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
245 do_bedbug_breakpoint( regs );
246#endif
247}
248
249/* Probe an address by reading. If not present, return -1, otherwise
250 * return 0.
251 */
252int
253addr_probe(uint *addr)
254{
255#if 0
256 int retval;
257
258 __asm__ __volatile__( \
259 "1: lwz %0,0(%1)\n" \
260 " eieio\n" \
261 " li %0,0\n" \
262 "2:\n" \
263 ".section .fixup,\"ax\"\n" \
264 "3: li %0,-1\n" \
265 " b 2b\n" \
266 ".section __ex_table,\"a\"\n" \
267 " .align 2\n" \
268 " .long 1b,3b\n" \
269 ".text" \
270 : "=r" (retval) : "r"(addr));
271
272 return (retval);
273#endif
274 return 0;
275}