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