TEXT_BASE is in board/sandpoint/config.mk so say so...
[u-boot.git] / cpu / mpc83xx / traps.c
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
43 /* Returns 0 if exception not found and fixup otherwise.  */
44 extern unsigned long search_exception_table(unsigned long);
45
46 #define END_OF_MEM      (gd->bd->bi_memstart + gd->bd->bi_memsize)
47
48 /*
49  * Trap & Exception support
50  */
51
52 void
53 print_backtrace(unsigned long *sp)
54 {
55         DECLARE_GLOBAL_DATA_PTR;
56         int cnt = 0;
57         unsigned long i;
58
59         puts ("Call backtrace: ");
60         while (sp) {
61                 if ((uint)sp > END_OF_MEM)
62                         break;
63
64                 i = sp[1];
65                 if (cnt++ % 7 == 0)
66                         putc ('\n');
67                 printf("%08lX ", i);
68                 if (cnt > 32) break;
69                 sp = (unsigned long *)*sp;
70         }
71         putc ('\n');
72 }
73
74 void show_regs(struct pt_regs * regs)
75 {
76         int i;
77
78         printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
79                regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
80         printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
81                regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
82                regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
83                regs->msr&MSR_IR ? 1 : 0,
84                regs->msr&MSR_DR ? 1 : 0);
85
86         putc ('\n');
87         for (i = 0;  i < 32;  i++) {
88                 if ((i % 8) == 0) {
89                         printf("GPR%02d: ", i);
90                 }
91
92                 printf("%08lX ", regs->gpr[i]);
93                 if ((i % 8) == 7) {
94                         putc ('\n');
95                 }
96         }
97 }
98
99
100 void
101 _exception(int signr, struct pt_regs *regs)
102 {
103         show_regs(regs);
104         print_backtrace((unsigned long *)regs->gpr[1]);
105         panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
106 }
107
108 #ifdef CONFIG_PCI
109 void dump_pci (void)
110 {
111 /*
112         volatile immap_t *immap = (immap_t *) CFG_IMMR;
113         printf ("PCI: err status %x err mask %x err ctrl %x\n",
114                 le32_to_cpu (immap->im_pci.pci_esr),
115                 le32_to_cpu (immap->im_pci.pci_emr),
116                 le32_to_cpu (immap->im_pci.pci_ecr));
117         printf ("     error address %x error data %x ctrl %x\n",
118                 le32_to_cpu (immap->im_pci.pci_eacr),
119                 le32_to_cpu (immap->im_pci.pci_edcr),
120                 le32_to_cpu (immap->im_pci.pci_eccr));
121 */
122 }
123 #endif
124
125 void
126 MachineCheckException(struct pt_regs *regs)
127 {
128         unsigned long fixup;
129
130         /* Probing PCI using config cycles cause this exception
131          * when a device is not present.  Catch it and return to
132          * the PCI exception handler.
133          */
134 #ifdef CONFIG_PCI
135 #if 0
136         volatile immap_t *immap  = (immap_t *)CFG_IMMR;
137 #ifdef DEBUG
138         dump_pci();
139 #endif
140         /* clear the error in the error status register */
141         if(immap->im_pci.pci_esr & cpu_to_le32(PCI_ERROR_PCI_NO_RSP)) {
142                 immap->im_pci.pci_esr = cpu_to_le32(PCI_ERROR_PCI_NO_RSP);
143                 return;
144         }
145 #endif
146 #endif /* CONFIG_PCI */
147         if ((fixup = search_exception_table(regs->nip)) != 0) {
148                 regs->nip = fixup;
149                 return;
150         }
151
152 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
153         if (debugger_exception_handler && (*debugger_exception_handler)(regs))
154                 return;
155 #endif
156
157         puts ("Machine check in kernel mode.\n"
158                 "Caused by (from msr): ");
159         printf("regs %p ",regs);
160         switch( regs->msr & 0x000F0000) {
161         case (0x80000000>>12):
162                 puts ("Machine check signal - probably due to mm fault\n"
163                         "with mmu off\n");
164                 break;
165         case (0x80000000>>13):
166                 puts ("Transfer error ack signal\n");
167                 break;
168         case (0x80000000>>14):
169                 puts ("Data parity signal\n");
170                 break;
171         case (0x80000000>>15):
172                 puts ("Address parity signal\n");
173                 break;
174         default:
175                 puts ("Unknown values in msr\n");
176         }
177         show_regs(regs);
178         print_backtrace((unsigned long *)regs->gpr[1]);
179 #ifdef CONFIG_PCI
180         dump_pci();
181 #endif
182         panic("machine check");
183 }
184
185 void
186 AlignmentException(struct pt_regs *regs)
187 {
188 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
189         if (debugger_exception_handler && (*debugger_exception_handler)(regs))
190                 return;
191 #endif
192         show_regs(regs);
193         print_backtrace((unsigned long *)regs->gpr[1]);
194         panic("Alignment Exception");
195 }
196
197 void
198 ProgramCheckException(struct pt_regs *regs)
199 {
200 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
201         if (debugger_exception_handler && (*debugger_exception_handler)(regs))
202                 return;
203 #endif
204         show_regs(regs);
205         print_backtrace((unsigned long *)regs->gpr[1]);
206         panic("Program Check Exception");
207 }
208
209 void
210 SoftEmuException(struct pt_regs *regs)
211 {
212 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
213         if (debugger_exception_handler && (*debugger_exception_handler)(regs))
214                 return;
215 #endif
216         show_regs(regs);
217         print_backtrace((unsigned long *)regs->gpr[1]);
218         panic("Software Emulation Exception");
219 }
220
221
222 void
223 UnknownException(struct pt_regs *regs)
224 {
225 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
226         if (debugger_exception_handler && (*debugger_exception_handler)(regs))
227                 return;
228 #endif
229         printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
230                regs->nip, regs->msr, regs->trap);
231         _exception(0, regs);
232 }
233
234 #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
235 extern void do_bedbug_breakpoint(struct pt_regs *);
236 #endif
237
238 void
239 DebugException(struct pt_regs *regs)
240 {
241         printf("Debugger trap at @ %lx\n", regs->nip );
242         show_regs(regs);
243 #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
244         do_bedbug_breakpoint( regs );
245 #endif
246 }
247
248 /* Probe an address by reading.  If not present, return -1, otherwise
249  * return 0.
250  */
251 int
252 addr_probe(uint *addr)
253 {
254 #if 0
255         int     retval;
256
257         __asm__ __volatile__(                   \
258                 "1:     lwz %0,0(%1)\n"         \
259                 "       eieio\n"                \
260                 "       li %0,0\n"              \
261                 "2:\n"                          \
262                 ".section .fixup,\"ax\"\n"      \
263                 "3:     li %0,-1\n"             \
264                 "       b 2b\n"                 \
265                 ".section __ex_table,\"a\"\n"   \
266                 "       .align 2\n"             \
267                 "       .long 1b,3b\n"          \
268                 ".text"                         \
269                 : "=r" (retval) : "r"(addr));
270
271         return (retval);
272 #endif
273         return 0;
274 }