xref: /openbmc/u-boot/arch/powerpc/cpu/mpc86xx/traps.c (revision 70ad375e)
1 /*
2  * Copyright (C) 1995-1996  Gary Thomas (gdt@linuxppc.org)
3  *
4  * Modified by Cort Dougan (cort@cs.nmt.edu)
5  * and Paul Mackerras (paulus@cs.anu.edu.au)
6  *
7  * (C) Copyright 2000
8  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9  *
10  * SPDX-License-Identifier:	GPL-2.0+
11  */
12 
13 /*
14  * This file handles the architecture-dependent parts of hardware exceptions
15  */
16 
17 #include <common.h>
18 #include <command.h>
19 #include <kgdb.h>
20 #include <asm/processor.h>
21 
22 DECLARE_GLOBAL_DATA_PTR;
23 
24 /* Returns 0 if exception not found and fixup otherwise.  */
25 extern unsigned long search_exception_table(unsigned long);
26 
27 /*
28  * End of addressable memory.  This may be less than the actual
29  * amount of memory on the system if we're unable to keep all
30  * the memory mapped in.
31  */
32 #define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize())
33 
34 /*
35  * Trap & Exception support
36  */
37 
38 static void print_backtrace(unsigned long *sp)
39 {
40 	int cnt = 0;
41 	unsigned long i;
42 
43 	printf("Call backtrace: ");
44 	while (sp) {
45 		if ((uint) sp > END_OF_MEM)
46 			break;
47 
48 		i = sp[1];
49 		if (cnt++ % 7 == 0)
50 			printf("\n");
51 		printf("%08lX ", i);
52 		if (cnt > 32)
53 			break;
54 		sp = (unsigned long *)*sp;
55 	}
56 	printf("\n");
57 }
58 
59 void show_regs(struct pt_regs *regs)
60 {
61 	int i;
62 
63 	printf("NIP: %08lX XER: %08lX LR: %08lX REGS:"
64 	       " %p TRAP: %04lx DAR: %08lX\n",
65 	       regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
66 	printf("MSR: %08lx EE: %01x PR: %01x FP:"
67 	       " %01x ME: %01x IR/DR: %01x%01x\n",
68 	       regs->msr, regs->msr & MSR_EE ? 1 : 0,
69 	       regs->msr & MSR_PR ? 1 : 0, regs->msr & MSR_FP ? 1 : 0,
70 	       regs->msr & MSR_ME ? 1 : 0, regs->msr & MSR_IR ? 1 : 0,
71 	       regs->msr & MSR_DR ? 1 : 0);
72 
73 	printf("\n");
74 	for (i = 0; i < 32; i++) {
75 		if ((i % 8) == 0) {
76 			printf("GPR%02d: ", i);
77 		}
78 
79 		printf("%08lX ", regs->gpr[i]);
80 		if ((i % 8) == 7) {
81 			printf("\n");
82 		}
83 	}
84 }
85 
86 
87 static void _exception(int signr, struct pt_regs *regs)
88 {
89 	show_regs(regs);
90 	print_backtrace((unsigned long *)regs->gpr[1]);
91 	panic("Exception in kernel pc %lx signal %d", regs->nip, signr);
92 }
93 
94 void MachineCheckException(struct pt_regs *regs)
95 {
96 	unsigned long fixup;
97 
98 	/* Probing PCI using config cycles cause this exception
99 	 * when a device is not present.  Catch it and return to
100 	 * the PCI exception handler.
101 	 */
102 	if ((fixup = search_exception_table(regs->nip)) != 0) {
103 		regs->nip = fixup;
104 		return;
105 	}
106 
107 #if defined(CONFIG_CMD_KGDB)
108 	if (debugger_exception_handler && (*debugger_exception_handler) (regs))
109 		return;
110 #endif
111 
112 	printf("Machine check in kernel mode.\n");
113 	printf("Caused by (from msr): ");
114 	printf("regs %p ", regs);
115 	switch ( regs->msr & 0x001F0000) {
116 	case (0x80000000>>11):
117 		printf("MSS error. MSSSR0: %08x\n", mfspr(SPRN_MSSSR0));
118 		break;
119 	case (0x80000000>>12):
120 		printf("Machine check signal - probably due to mm fault\n"
121 		       "with mmu off\n");
122 		break;
123 	case (0x80000000 >> 13):
124 		printf("Transfer error ack signal\n");
125 		break;
126 	case (0x80000000 >> 14):
127 		printf("Data parity signal\n");
128 		break;
129 	case (0x80000000 >> 15):
130 		printf("Address parity signal\n");
131 		break;
132 	default:
133 		printf("Unknown values in msr\n");
134 	}
135 	show_regs(regs);
136 	print_backtrace((unsigned long *)regs->gpr[1]);
137 	panic("machine check");
138 }
139 
140 void AlignmentException(struct pt_regs *regs)
141 {
142 #if defined(CONFIG_CMD_KGDB)
143 	if (debugger_exception_handler && (*debugger_exception_handler) (regs))
144 		return;
145 #endif
146 	show_regs(regs);
147 	print_backtrace((unsigned long *)regs->gpr[1]);
148 	panic("Alignment Exception");
149 }
150 
151 void ProgramCheckException(struct pt_regs *regs)
152 {
153 	unsigned char *p = regs ? (unsigned char *)(regs->nip) : NULL;
154 	int i, j;
155 
156 #if defined(CONFIG_CMD_KGDB)
157 	if (debugger_exception_handler && (*debugger_exception_handler) (regs))
158 		return;
159 #endif
160 	show_regs(regs);
161 
162 	p = (unsigned char *)((unsigned long)p & 0xFFFFFFE0);
163 	p -= 32;
164 	for (i = 0; i < 256; i += 16) {
165 		printf("%08x: ", (unsigned int)p + i);
166 		for (j = 0; j < 16; j++) {
167 			printf("%02x ", p[i + j]);
168 		}
169 		printf("\n");
170 	}
171 
172 	print_backtrace((unsigned long *)regs->gpr[1]);
173 	panic("Program Check Exception");
174 }
175 
176 void SoftEmuException(struct pt_regs *regs)
177 {
178 #if defined(CONFIG_CMD_KGDB)
179 	if (debugger_exception_handler && (*debugger_exception_handler) (regs))
180 		return;
181 #endif
182 	show_regs(regs);
183 	print_backtrace((unsigned long *)regs->gpr[1]);
184 	panic("Software Emulation Exception");
185 }
186 
187 void UnknownException(struct pt_regs *regs)
188 {
189 #if defined(CONFIG_CMD_KGDB)
190 	if (debugger_exception_handler && (*debugger_exception_handler) (regs))
191 		return;
192 #endif
193 	printf("UnknownException regs@%lx\n", (ulong)regs);
194 	printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
195 	       regs->nip, regs->msr, regs->trap);
196 	_exception(0, regs);
197 }
198 
199 /*
200  * Probe an address by reading.
201  * If not present, return -1,
202  * otherwise return 0.
203  */
204 int addr_probe(uint *addr)
205 {
206 	return 0;
207 }
208