powerpc: Partialy restore core of mpc8xx
[platform/kernel/u-boot.git] / arch / powerpc / cpu / mpc8xx / traps.c
1 /*
2  * linux/arch/powerpc/kernel/traps.c
3  *
4  * Copyright (C) 1995-1996  Gary Thomas (gdt@linuxppc.org)
5  *
6  * Modified by Cort Dougan (cort@cs.nmt.edu)
7  * and Paul Mackerras (paulus@cs.anu.edu.au)
8  *
9  * (C) Copyright 2000
10  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
11  *
12  * SPDX-License-Identifier:     GPL-2.0+
13  */
14
15 /*
16  * This file handles the architecture-dependent parts of hardware exceptions
17  */
18
19 #include <common.h>
20 #include <command.h>
21 #include <asm/processor.h>
22
23 /* Returns 0 if exception not found and fixup otherwise.  */
24 extern unsigned long search_exception_table(unsigned long);
25
26 /* THIS NEEDS CHANGING to use the board info structure.
27 */
28 #define END_OF_MEM      0x02000000
29
30 /*
31  * Trap & Exception support
32  */
33
34 static void print_backtrace(unsigned long *sp)
35 {
36         int cnt = 0;
37         unsigned long i;
38
39         printf("Call backtrace: ");
40         while (sp) {
41                 if ((uint)sp > END_OF_MEM)
42                         break;
43
44                 i = sp[1];
45                 if (cnt++ % 7 == 0)
46                         printf("\n");
47                 printf("%08lX ", i);
48                 if (cnt > 32) break;
49                 sp = (unsigned long *)*sp;
50         }
51         printf("\n");
52 }
53
54 void show_regs(struct pt_regs *regs)
55 {
56         int i;
57
58         printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
59                regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
60         printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
61                regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
62                regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
63                regs->msr&MSR_IR ? 1 : 0,
64                regs->msr&MSR_DR ? 1 : 0);
65
66         printf("\n");
67         for (i = 0;  i < 32;  i++) {
68                 if ((i % 8) == 0)
69                 {
70                         printf("GPR%02d: ", i);
71                 }
72
73                 printf("%08lX ", regs->gpr[i]);
74                 if ((i % 8) == 7)
75                 {
76                         printf("\n");
77                 }
78         }
79 }
80
81
82 static void _exception(int signr, struct pt_regs *regs)
83 {
84         show_regs(regs);
85         print_backtrace((unsigned long *)regs->gpr[1]);
86         panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
87 }
88
89 void MachineCheckException(struct pt_regs *regs)
90 {
91         unsigned long fixup;
92
93         /* Probing PCI using config cycles cause this exception
94          * when a device is not present.  Catch it and return to
95          * the PCI exception handler.
96          */
97         if ((fixup = search_exception_table(regs->nip)) != 0) {
98                 regs->nip = fixup;
99                 return;
100         }
101
102         printf("Machine check in kernel mode.\n");
103         printf("Caused by (from msr): ");
104         printf("regs %p ",regs);
105         switch( regs->msr & 0x000F0000) {
106         case (0x80000000>>12):
107                 printf("Machine check signal - probably due to mm fault\n"
108                         "with mmu off\n");
109                 break;
110         case (0x80000000>>13):
111                 printf("Transfer error ack signal\n");
112                 break;
113         case (0x80000000>>14):
114                 printf("Data parity signal\n");
115                 break;
116         case (0x80000000>>15):
117                 printf("Address parity signal\n");
118                 break;
119         default:
120                 printf("Unknown values in msr\n");
121         }
122         show_regs(regs);
123         print_backtrace((unsigned long *)regs->gpr[1]);
124         panic("machine check");
125 }
126
127 void AlignmentException(struct pt_regs *regs)
128 {
129         show_regs(regs);
130         print_backtrace((unsigned long *)regs->gpr[1]);
131         panic("Alignment Exception");
132 }
133
134 void ProgramCheckException(struct pt_regs *regs)
135 {
136         show_regs(regs);
137         print_backtrace((unsigned long *)regs->gpr[1]);
138         panic("Program Check Exception");
139 }
140
141 void SoftEmuException(struct pt_regs *regs)
142 {
143         show_regs(regs);
144         print_backtrace((unsigned long *)regs->gpr[1]);
145         panic("Software Emulation Exception");
146 }
147
148
149 void UnknownException(struct pt_regs *regs)
150 {
151         printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
152                regs->nip, regs->msr, regs->trap);
153         _exception(0, regs);
154 }
155
156 void DebugException(struct pt_regs *regs)
157 {
158   printf("Debugger trap at @ %lx\n", regs->nip );
159   show_regs(regs);
160 }
161
162 /* Probe an address by reading.  If not present, return -1, otherwise
163  * return 0.
164  */
165 int addr_probe(uint *addr)
166 {
167         return 0;
168 }