blob: d2bbf3e9968640131072768f0edd5f97d7532844 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Christophe Leroy907208c2017-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 Leroy907208c2017-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>
19#include <command.h>
20#include <asm/processor.h>
21
22/* Returns 0 if exception not found and fixup otherwise. */
23extern unsigned long search_exception_table(unsigned long);
24
25/* THIS NEEDS CHANGING to use the board info structure.
26*/
27#define END_OF_MEM 0x02000000
28
29/*
30 * Trap & Exception support
31 */
32
33static void print_backtrace(unsigned long *sp)
34{
35 int cnt = 0;
36 unsigned long i;
37
38 printf("Call backtrace: ");
39 while (sp) {
40 if ((uint)sp > END_OF_MEM)
41 break;
42
43 i = sp[1];
44 if (cnt++ % 7 == 0)
45 printf("\n");
46 printf("%08lX ", i);
Christophe Leroy70fd0712017-07-06 10:33:17 +020047 if (cnt > 32)
48 break;
Christophe Leroy907208c2017-07-06 10:23:22 +020049 sp = (unsigned long *)*sp;
50 }
51 printf("\n");
52}
53
Christophe Leroy08dd9882017-07-13 15:10:08 +020054static void show_regs(struct pt_regs *regs)
Christophe Leroy907208c2017-07-06 10:23:22 +020055{
56 int i;
57
58 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
59 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
60 printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
Christophe Leroy70fd0712017-07-06 10:33:17 +020061 regs->msr, regs->msr & MSR_EE ? 1 : 0,
62 regs->msr & MSR_PR ? 1 : 0, regs->msr & MSR_FP ? 1 : 0,
63 regs->msr & MSR_ME ? 1 : 0, regs->msr & MSR_IR ? 1 : 0,
64 regs->msr & MSR_DR ? 1 : 0);
Christophe Leroy907208c2017-07-06 10:23:22 +020065
66 printf("\n");
67 for (i = 0; i < 32; i++) {
68 if ((i % 8) == 0)
Christophe Leroy907208c2017-07-06 10:23:22 +020069 printf("GPR%02d: ", i);
Christophe Leroy907208c2017-07-06 10:23:22 +020070
71 printf("%08lX ", regs->gpr[i]);
72 if ((i % 8) == 7)
Christophe Leroy907208c2017-07-06 10:23:22 +020073 printf("\n");
Christophe Leroy907208c2017-07-06 10:23:22 +020074 }
75}
76
77
78static void _exception(int signr, struct pt_regs *regs)
79{
80 show_regs(regs);
81 print_backtrace((unsigned long *)regs->gpr[1]);
Christophe Leroy70fd0712017-07-06 10:33:17 +020082 panic("Exception in kernel pc %lx signal %d", regs->nip, signr);
Christophe Leroy907208c2017-07-06 10:23:22 +020083}
84
85void MachineCheckException(struct pt_regs *regs)
86{
Christophe Leroy70fd0712017-07-06 10:33:17 +020087 unsigned long fixup = search_exception_table(regs->nip);
Christophe Leroy907208c2017-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 Leroy70fd0712017-07-06 10:33:17 +020093 if (fixup != 0) {
Christophe Leroy907208c2017-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 Leroy70fd0712017-07-06 10:33:17 +0200100 printf("regs %p ", regs);
101 switch (regs->msr & 0x000F0000) {
102 case (0x80000000 >> 12):
Christophe Leroy907208c2017-07-06 10:23:22 +0200103 printf("Machine check signal - probably due to mm fault\n"
104 "with mmu off\n");
105 break;
Christophe Leroy70fd0712017-07-06 10:33:17 +0200106 case (0x80000000 >> 13):
Christophe Leroy907208c2017-07-06 10:23:22 +0200107 printf("Transfer error ack signal\n");
108 break;
Christophe Leroy70fd0712017-07-06 10:33:17 +0200109 case (0x80000000 >> 14):
Christophe Leroy907208c2017-07-06 10:23:22 +0200110 printf("Data parity signal\n");
111 break;
Christophe Leroy70fd0712017-07-06 10:33:17 +0200112 case (0x80000000 >> 15):
Christophe Leroy907208c2017-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
144
145void UnknownException(struct pt_regs *regs)
146{
147 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
148 regs->nip, regs->msr, regs->trap);
149 _exception(0, regs);
150}
151
152void DebugException(struct pt_regs *regs)
153{
Christophe Leroy70fd0712017-07-06 10:33:17 +0200154 printf("Debugger trap at @ %lx\n", regs->nip);
155 show_regs(regs);
Christophe Leroy907208c2017-07-06 10:23:22 +0200156}