1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2907208c4SChristophe Leroy /*
3907208c4SChristophe Leroy * linux/arch/powerpc/kernel/traps.c
4907208c4SChristophe Leroy *
5907208c4SChristophe Leroy * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
6907208c4SChristophe Leroy *
7907208c4SChristophe Leroy * Modified by Cort Dougan (cort@cs.nmt.edu)
8907208c4SChristophe Leroy * and Paul Mackerras (paulus@cs.anu.edu.au)
9907208c4SChristophe Leroy *
10907208c4SChristophe Leroy * (C) Copyright 2000
11907208c4SChristophe Leroy * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
12907208c4SChristophe Leroy */
13907208c4SChristophe Leroy
14907208c4SChristophe Leroy /*
15907208c4SChristophe Leroy * This file handles the architecture-dependent parts of hardware exceptions
16907208c4SChristophe Leroy */
17907208c4SChristophe Leroy
18907208c4SChristophe Leroy #include <common.h>
19907208c4SChristophe Leroy #include <command.h>
20907208c4SChristophe Leroy #include <asm/processor.h>
21907208c4SChristophe Leroy
22907208c4SChristophe Leroy /* Returns 0 if exception not found and fixup otherwise. */
23907208c4SChristophe Leroy extern unsigned long search_exception_table(unsigned long);
24907208c4SChristophe Leroy
25907208c4SChristophe Leroy /* THIS NEEDS CHANGING to use the board info structure.
26907208c4SChristophe Leroy */
27907208c4SChristophe Leroy #define END_OF_MEM 0x02000000
28907208c4SChristophe Leroy
29907208c4SChristophe Leroy /*
30907208c4SChristophe Leroy * Trap & Exception support
31907208c4SChristophe Leroy */
32907208c4SChristophe Leroy
print_backtrace(unsigned long * sp)33907208c4SChristophe Leroy static void print_backtrace(unsigned long *sp)
34907208c4SChristophe Leroy {
35907208c4SChristophe Leroy int cnt = 0;
36907208c4SChristophe Leroy unsigned long i;
37907208c4SChristophe Leroy
38907208c4SChristophe Leroy printf("Call backtrace: ");
39907208c4SChristophe Leroy while (sp) {
40907208c4SChristophe Leroy if ((uint)sp > END_OF_MEM)
41907208c4SChristophe Leroy break;
42907208c4SChristophe Leroy
43907208c4SChristophe Leroy i = sp[1];
44907208c4SChristophe Leroy if (cnt++ % 7 == 0)
45907208c4SChristophe Leroy printf("\n");
46907208c4SChristophe Leroy printf("%08lX ", i);
4770fd0710SChristophe Leroy if (cnt > 32)
4870fd0710SChristophe Leroy break;
49907208c4SChristophe Leroy sp = (unsigned long *)*sp;
50907208c4SChristophe Leroy }
51907208c4SChristophe Leroy printf("\n");
52907208c4SChristophe Leroy }
53907208c4SChristophe Leroy
show_regs(struct pt_regs * regs)5408dd988bSChristophe Leroy static void show_regs(struct pt_regs *regs)
55907208c4SChristophe Leroy {
56907208c4SChristophe Leroy int i;
57907208c4SChristophe Leroy
58907208c4SChristophe Leroy printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
59907208c4SChristophe Leroy regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
60907208c4SChristophe Leroy printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
6170fd0710SChristophe Leroy regs->msr, regs->msr & MSR_EE ? 1 : 0,
6270fd0710SChristophe Leroy regs->msr & MSR_PR ? 1 : 0, regs->msr & MSR_FP ? 1 : 0,
6370fd0710SChristophe Leroy regs->msr & MSR_ME ? 1 : 0, regs->msr & MSR_IR ? 1 : 0,
64907208c4SChristophe Leroy regs->msr & MSR_DR ? 1 : 0);
65907208c4SChristophe Leroy
66907208c4SChristophe Leroy printf("\n");
67907208c4SChristophe Leroy for (i = 0; i < 32; i++) {
68907208c4SChristophe Leroy if ((i % 8) == 0)
69907208c4SChristophe Leroy printf("GPR%02d: ", i);
70907208c4SChristophe Leroy
71907208c4SChristophe Leroy printf("%08lX ", regs->gpr[i]);
72907208c4SChristophe Leroy if ((i % 8) == 7)
73907208c4SChristophe Leroy printf("\n");
74907208c4SChristophe Leroy }
75907208c4SChristophe Leroy }
76907208c4SChristophe Leroy
77907208c4SChristophe Leroy
_exception(int signr,struct pt_regs * regs)78907208c4SChristophe Leroy static void _exception(int signr, struct pt_regs *regs)
79907208c4SChristophe Leroy {
80907208c4SChristophe Leroy show_regs(regs);
81907208c4SChristophe Leroy print_backtrace((unsigned long *)regs->gpr[1]);
82907208c4SChristophe Leroy panic("Exception in kernel pc %lx signal %d", regs->nip, signr);
83907208c4SChristophe Leroy }
84907208c4SChristophe Leroy
MachineCheckException(struct pt_regs * regs)85907208c4SChristophe Leroy void MachineCheckException(struct pt_regs *regs)
86907208c4SChristophe Leroy {
8770fd0710SChristophe Leroy unsigned long fixup = search_exception_table(regs->nip);
88907208c4SChristophe Leroy
89907208c4SChristophe Leroy /* Probing PCI using config cycles cause this exception
90907208c4SChristophe Leroy * when a device is not present. Catch it and return to
91907208c4SChristophe Leroy * the PCI exception handler.
92907208c4SChristophe Leroy */
9370fd0710SChristophe Leroy if (fixup != 0) {
94907208c4SChristophe Leroy regs->nip = fixup;
95907208c4SChristophe Leroy return;
96907208c4SChristophe Leroy }
97907208c4SChristophe Leroy
98907208c4SChristophe Leroy printf("Machine check in kernel mode.\n");
99907208c4SChristophe Leroy printf("Caused by (from msr): ");
100907208c4SChristophe Leroy printf("regs %p ", regs);
101907208c4SChristophe Leroy switch (regs->msr & 0x000F0000) {
102907208c4SChristophe Leroy case (0x80000000 >> 12):
103907208c4SChristophe Leroy printf("Machine check signal - probably due to mm fault\n"
104907208c4SChristophe Leroy "with mmu off\n");
105907208c4SChristophe Leroy break;
106907208c4SChristophe Leroy case (0x80000000 >> 13):
107907208c4SChristophe Leroy printf("Transfer error ack signal\n");
108907208c4SChristophe Leroy break;
109907208c4SChristophe Leroy case (0x80000000 >> 14):
110907208c4SChristophe Leroy printf("Data parity signal\n");
111907208c4SChristophe Leroy break;
112907208c4SChristophe Leroy case (0x80000000 >> 15):
113907208c4SChristophe Leroy printf("Address parity signal\n");
114907208c4SChristophe Leroy break;
115907208c4SChristophe Leroy default:
116907208c4SChristophe Leroy printf("Unknown values in msr\n");
117907208c4SChristophe Leroy }
118907208c4SChristophe Leroy show_regs(regs);
119907208c4SChristophe Leroy print_backtrace((unsigned long *)regs->gpr[1]);
120907208c4SChristophe Leroy panic("machine check");
121907208c4SChristophe Leroy }
122907208c4SChristophe Leroy
AlignmentException(struct pt_regs * regs)123907208c4SChristophe Leroy void AlignmentException(struct pt_regs *regs)
124907208c4SChristophe Leroy {
125907208c4SChristophe Leroy show_regs(regs);
126907208c4SChristophe Leroy print_backtrace((unsigned long *)regs->gpr[1]);
127907208c4SChristophe Leroy panic("Alignment Exception");
128907208c4SChristophe Leroy }
129907208c4SChristophe Leroy
ProgramCheckException(struct pt_regs * regs)130907208c4SChristophe Leroy void ProgramCheckException(struct pt_regs *regs)
131907208c4SChristophe Leroy {
132907208c4SChristophe Leroy show_regs(regs);
133907208c4SChristophe Leroy print_backtrace((unsigned long *)regs->gpr[1]);
134907208c4SChristophe Leroy panic("Program Check Exception");
135907208c4SChristophe Leroy }
136907208c4SChristophe Leroy
SoftEmuException(struct pt_regs * regs)137907208c4SChristophe Leroy void SoftEmuException(struct pt_regs *regs)
138907208c4SChristophe Leroy {
139907208c4SChristophe Leroy show_regs(regs);
140907208c4SChristophe Leroy print_backtrace((unsigned long *)regs->gpr[1]);
141907208c4SChristophe Leroy panic("Software Emulation Exception");
142907208c4SChristophe Leroy }
143907208c4SChristophe Leroy
144907208c4SChristophe Leroy
UnknownException(struct pt_regs * regs)145907208c4SChristophe Leroy void UnknownException(struct pt_regs *regs)
146907208c4SChristophe Leroy {
147907208c4SChristophe Leroy printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
148907208c4SChristophe Leroy regs->nip, regs->msr, regs->trap);
149907208c4SChristophe Leroy _exception(0, regs);
150907208c4SChristophe Leroy }
151907208c4SChristophe Leroy
DebugException(struct pt_regs * regs)152907208c4SChristophe Leroy void DebugException(struct pt_regs *regs)
153907208c4SChristophe Leroy {
154907208c4SChristophe Leroy printf("Debugger trap at @ %lx\n", regs->nip);
155907208c4SChristophe Leroy show_regs(regs);
156907208c4SChristophe Leroy }
157