blob: 22f2f5878e33476c5bf9e15cdd6f23e0e9e58aa3 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Christophe Leroy069fa832017-07-06 10:23:22 +02002/*
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.
Christophe Leroy069fa832017-07-06 10:23:22 +020012 */
13
14/*
15 * This file handles the architecture-dependent parts of hardware exceptions
16 */
17
Christophe Leroy98a58c82023-11-06 19:12:04 +010018#include <vsprintf.h>
Simon Glass6b9f0102020-05-10 11:40:06 -060019#include <asm/ptrace.h>
Christophe Leroy069fa832017-07-06 10:23:22 +020020#include <command.h>
21#include <asm/processor.h>
22
23/* Returns 0 if exception not found and fixup otherwise. */
24extern 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
34static 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);
Christophe Leroy48f896d2017-07-06 10:33:17 +020048 if (cnt > 32)
49 break;
Christophe Leroy069fa832017-07-06 10:23:22 +020050 sp = (unsigned long *)*sp;
51 }
52 printf("\n");
53}
54
Tom Rini4d88ed02020-01-29 11:07:19 -050055void show_regs(struct pt_regs *regs)
Christophe Leroy069fa832017-07-06 10:23:22 +020056{
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",
Christophe Leroy48f896d2017-07-06 10:33:17 +020062 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);
Christophe Leroy069fa832017-07-06 10:23:22 +020066
67 printf("\n");
68 for (i = 0; i < 32; i++) {
69 if ((i % 8) == 0)
Christophe Leroy069fa832017-07-06 10:23:22 +020070 printf("GPR%02d: ", i);
Christophe Leroy069fa832017-07-06 10:23:22 +020071
72 printf("%08lX ", regs->gpr[i]);
73 if ((i % 8) == 7)
Christophe Leroy069fa832017-07-06 10:23:22 +020074 printf("\n");
Christophe Leroy069fa832017-07-06 10:23:22 +020075 }
76}
77
Christophe Leroy069fa832017-07-06 10:23:22 +020078static void _exception(int signr, struct pt_regs *regs)
79{
80 show_regs(regs);
81 print_backtrace((unsigned long *)regs->gpr[1]);
Christophe Leroy48f896d2017-07-06 10:33:17 +020082 panic("Exception in kernel pc %lx signal %d", regs->nip, signr);
Christophe Leroy069fa832017-07-06 10:23:22 +020083}
84
85void MachineCheckException(struct pt_regs *regs)
86{
Christophe Leroy48f896d2017-07-06 10:33:17 +020087 unsigned long fixup = search_exception_table(regs->nip);
Christophe Leroy069fa832017-07-06 10:23:22 +020088
89 /* Probing PCI using config cycles cause this exception
90 * when a device is not present. Catch it and return to
91 * the PCI exception handler.
92 */
Christophe Leroy48f896d2017-07-06 10:33:17 +020093 if (fixup != 0) {
Christophe Leroy069fa832017-07-06 10:23:22 +020094 regs->nip = fixup;
95 return;
96 }
97
98 printf("Machine check in kernel mode.\n");
99 printf("Caused by (from msr): ");
Christophe Leroy48f896d2017-07-06 10:33:17 +0200100 printf("regs %p ", regs);
101 switch (regs->msr & 0x000F0000) {
102 case (0x80000000 >> 12):
Christophe Leroy069fa832017-07-06 10:23:22 +0200103 printf("Machine check signal - probably due to mm fault\n"
104 "with mmu off\n");
105 break;
Christophe Leroy48f896d2017-07-06 10:33:17 +0200106 case (0x80000000 >> 13):
Christophe Leroy069fa832017-07-06 10:23:22 +0200107 printf("Transfer error ack signal\n");
108 break;
Christophe Leroy48f896d2017-07-06 10:33:17 +0200109 case (0x80000000 >> 14):
Christophe Leroy069fa832017-07-06 10:23:22 +0200110 printf("Data parity signal\n");
111 break;
Christophe Leroy48f896d2017-07-06 10:33:17 +0200112 case (0x80000000 >> 15):
Christophe Leroy069fa832017-07-06 10:23:22 +0200113 printf("Address parity signal\n");
114 break;
115 default:
116 printf("Unknown values in msr\n");
117 }
118 show_regs(regs);
119 print_backtrace((unsigned long *)regs->gpr[1]);
120 panic("machine check");
121}
122
123void AlignmentException(struct pt_regs *regs)
124{
125 show_regs(regs);
126 print_backtrace((unsigned long *)regs->gpr[1]);
127 panic("Alignment Exception");
128}
129
130void ProgramCheckException(struct pt_regs *regs)
131{
132 show_regs(regs);
133 print_backtrace((unsigned long *)regs->gpr[1]);
134 panic("Program Check Exception");
135}
136
137void SoftEmuException(struct pt_regs *regs)
138{
139 show_regs(regs);
140 print_backtrace((unsigned long *)regs->gpr[1]);
141 panic("Software Emulation Exception");
142}
143
Christophe Leroy069fa832017-07-06 10:23:22 +0200144void UnknownException(struct pt_regs *regs)
145{
146 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
147 regs->nip, regs->msr, regs->trap);
148 _exception(0, regs);
149}
150
151void DebugException(struct pt_regs *regs)
152{
Christophe Leroy48f896d2017-07-06 10:33:17 +0200153 printf("Debugger trap at @ %lx\n", regs->nip);
154 show_regs(regs);
Christophe Leroy069fa832017-07-06 10:23:22 +0200155}