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