blob: 56794b08a15558ede0429c3b44df557809e1e6dd [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
18#include <common.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
78
79static void _exception(int signr, struct pt_regs *regs)
80{
81 show_regs(regs);
82 print_backtrace((unsigned long *)regs->gpr[1]);
Christophe Leroy48f896d2017-07-06 10:33:17 +020083 panic("Exception in kernel pc %lx signal %d", regs->nip, signr);
Christophe Leroy069fa832017-07-06 10:23:22 +020084}
85
86void MachineCheckException(struct pt_regs *regs)
87{
Christophe Leroy48f896d2017-07-06 10:33:17 +020088 unsigned long fixup = search_exception_table(regs->nip);
Christophe Leroy069fa832017-07-06 10:23:22 +020089
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 */
Christophe Leroy48f896d2017-07-06 10:33:17 +020094 if (fixup != 0) {
Christophe Leroy069fa832017-07-06 10:23:22 +020095 regs->nip = fixup;
96 return;
97 }
98
99 printf("Machine check in kernel mode.\n");
100 printf("Caused by (from msr): ");
Christophe Leroy48f896d2017-07-06 10:33:17 +0200101 printf("regs %p ", regs);
102 switch (regs->msr & 0x000F0000) {
103 case (0x80000000 >> 12):
Christophe Leroy069fa832017-07-06 10:23:22 +0200104 printf("Machine check signal - probably due to mm fault\n"
105 "with mmu off\n");
106 break;
Christophe Leroy48f896d2017-07-06 10:33:17 +0200107 case (0x80000000 >> 13):
Christophe Leroy069fa832017-07-06 10:23:22 +0200108 printf("Transfer error ack signal\n");
109 break;
Christophe Leroy48f896d2017-07-06 10:33:17 +0200110 case (0x80000000 >> 14):
Christophe Leroy069fa832017-07-06 10:23:22 +0200111 printf("Data parity signal\n");
112 break;
Christophe Leroy48f896d2017-07-06 10:33:17 +0200113 case (0x80000000 >> 15):
Christophe Leroy069fa832017-07-06 10:23:22 +0200114 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
124void AlignmentException(struct pt_regs *regs)
125{
126 show_regs(regs);
127 print_backtrace((unsigned long *)regs->gpr[1]);
128 panic("Alignment Exception");
129}
130
131void 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
138void 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
146void 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
153void DebugException(struct pt_regs *regs)
154{
Christophe Leroy48f896d2017-07-06 10:33:17 +0200155 printf("Debugger trap at @ %lx\n", regs->nip);
156 show_regs(regs);
Christophe Leroy069fa832017-07-06 10:23:22 +0200157}