Merge branch 'origin'
[platform/kernel/u-boot.git] / cpu / mpc85xx / traps.c
1 /*
2  * linux/arch/ppc/kernel/traps.c
3  *
4  * Copyright (C) 2003 Motorola
5  * Modified by Xianghua Xiao(x.xiao@motorola.com)
6  *
7  * Copyright (C) 1995-1996  Gary Thomas (gdt@linuxppc.org)
8  *
9  * Modified by Cort Dougan (cort@cs.nmt.edu)
10  * and Paul Mackerras (paulus@cs.anu.edu.au)
11  *
12  * (C) Copyright 2000
13  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
14  *
15  * See file CREDITS for list of people who contributed to this
16  * project.
17  *
18  * This program is free software; you can redistribute it and/or
19  * modify it under the terms of the GNU General Public License as
20  * published by the Free Software Foundation; either version 2 of
21  * the License, or (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31  * MA 02111-1307 USA
32  */
33
34 /*
35  * This file handles the architecture-dependent parts of hardware exceptions
36  */
37
38 #include <common.h>
39 #include <command.h>
40 #include <asm/processor.h>
41
42 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
43 int (*debugger_exception_handler)(struct pt_regs *) = 0;
44 #endif
45
46 /* Returns 0 if exception not found and fixup otherwise.  */
47 extern unsigned long search_exception_table(unsigned long);
48
49 /*
50  * End of memory as shown by board info and determined by DDR setup.
51  */
52 #define END_OF_MEM      (gd->bd->bi_memstart + gd->bd->bi_memsize)
53
54
55 static __inline__ void set_tsr(unsigned long val)
56 {
57         asm volatile("mtspr 0x150, %0" : : "r" (val));
58 }
59
60 static __inline__ unsigned long get_esr(void)
61 {
62         unsigned long val;
63         asm volatile("mfspr %0, 0x03e" : "=r" (val) :);
64         return val;
65 }
66
67 #define ESR_MCI 0x80000000
68 #define ESR_PIL 0x08000000
69 #define ESR_PPR 0x04000000
70 #define ESR_PTR 0x02000000
71 #define ESR_DST 0x00800000
72 #define ESR_DIZ 0x00400000
73 #define ESR_U0F 0x00008000
74
75 #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
76 extern void do_bedbug_breakpoint(struct pt_regs *);
77 #endif
78
79 /*
80  * Trap & Exception support
81  */
82
83 void
84 print_backtrace(unsigned long *sp)
85 {
86         DECLARE_GLOBAL_DATA_PTR;
87         int cnt = 0;
88         unsigned long i;
89
90         printf("Call backtrace: ");
91         while (sp) {
92                 if ((uint)sp > END_OF_MEM)
93                         break;
94
95                 i = sp[1];
96                 if (cnt++ % 7 == 0)
97                         printf("\n");
98                 printf("%08lX ", i);
99                 if (cnt > 32) break;
100                 sp = (unsigned long *)*sp;
101         }
102         printf("\n");
103 }
104
105 void show_regs(struct pt_regs * regs)
106 {
107         int i;
108
109         printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
110                regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
111         printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
112                regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
113                regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
114                regs->msr&MSR_IR ? 1 : 0,
115                regs->msr&MSR_DR ? 1 : 0);
116
117         printf("\n");
118         for (i = 0;  i < 32;  i++) {
119                 if ((i % 8) == 0)
120                 {
121                         printf("GPR%02d: ", i);
122                 }
123
124                 printf("%08lX ", regs->gpr[i]);
125                 if ((i % 8) == 7)
126                 {
127                         printf("\n");
128                 }
129         }
130 }
131
132
133 void
134 _exception(int signr, struct pt_regs *regs)
135 {
136         show_regs(regs);
137         print_backtrace((unsigned long *)regs->gpr[1]);
138         panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
139 }
140
141 void
142 CritcalInputException(struct pt_regs *regs)
143 {
144         panic("Critical Input Exception");
145 }
146
147 void
148 MachineCheckException(struct pt_regs *regs)
149 {
150         unsigned long fixup;
151
152         /* Probing PCI using config cycles cause this exception
153          * when a device is not present.  Catch it and return to
154          * the PCI exception handler.
155          */
156         if ((fixup = search_exception_table(regs->nip)) != 0) {
157                 regs->nip = fixup;
158                 return;
159         }
160
161 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
162         if (debugger_exception_handler && (*debugger_exception_handler)(regs))
163                 return;
164 #endif
165
166         printf("Machine check in kernel mode.\n");
167         printf("Caused by (from msr): ");
168         printf("regs %p ",regs);
169         switch( regs->msr & 0x000F0000) {
170         case (0x80000000>>12):
171                 printf("Machine check signal - probably due to mm fault\n"
172                        "with mmu off\n");
173                 break;
174         case (0x80000000>>13):
175                 printf("Transfer error ack signal\n");
176                 break;
177         case (0x80000000>>14):
178                 printf("Data parity signal\n");
179                 break;
180         case (0x80000000>>15):
181                 printf("Address parity signal\n");
182                 break;
183         default:
184                 printf("Unknown values in msr\n");
185         }
186         show_regs(regs);
187         print_backtrace((unsigned long *)regs->gpr[1]);
188         panic("machine check");
189 }
190
191 void
192 AlignmentException(struct pt_regs *regs)
193 {
194 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
195         if (debugger_exception_handler && (*debugger_exception_handler)(regs))
196                 return;
197 #endif
198
199         show_regs(regs);
200         print_backtrace((unsigned long *)regs->gpr[1]);
201         panic("Alignment Exception");
202 }
203
204 void
205 ProgramCheckException(struct pt_regs *regs)
206 {
207         long esr_val;
208
209 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
210         if (debugger_exception_handler && (*debugger_exception_handler)(regs))
211                 return;
212 #endif
213
214         show_regs(regs);
215
216         esr_val = get_esr();
217         if( esr_val & ESR_PIL )
218                 printf( "** Illegal Instruction **\n" );
219         else if( esr_val & ESR_PPR )
220                 printf( "** Privileged Instruction **\n" );
221         else if( esr_val & ESR_PTR )
222                 printf( "** Trap Instruction **\n" );
223
224         print_backtrace((unsigned long *)regs->gpr[1]);
225         panic("Program Check Exception");
226 }
227
228 void
229 PITException(struct pt_regs *regs)
230 {
231         /*
232          * Reset PIT interrupt
233          */
234         set_tsr(0x0c000000);
235
236         /*
237          * Call timer_interrupt routine in interrupts.c
238          */
239         timer_interrupt(NULL);
240 }
241
242
243 void
244 UnknownException(struct pt_regs *regs)
245 {
246 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
247         if (debugger_exception_handler && (*debugger_exception_handler)(regs))
248                 return;
249 #endif
250
251         printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
252                regs->nip, regs->msr, regs->trap);
253         _exception(0, regs);
254 }
255
256 void
257 DebugException(struct pt_regs *regs)
258 {
259         printf("Debugger trap at @ %lx\n", regs->nip );
260         show_regs(regs);
261 #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
262         do_bedbug_breakpoint( regs );
263 #endif
264 }
265
266 /* Probe an address by reading.  If not present, return -1, otherwise
267  * return 0.
268  */
269 int
270 addr_probe(uint *addr)
271 {
272         return 0;
273 }