blob: 1820187d1d0b621b2948dc0ac87027940ca83474 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jon Loeliger5c8aa972006-04-26 17:58:56 -05002/*
Jon Loeliger5c8aa972006-04-26 17:58:56 -05003 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
4 *
5 * Modified by Cort Dougan (cort@cs.nmt.edu)
6 * and Paul Mackerras (paulus@cs.anu.edu.au)
7 *
8 * (C) Copyright 2000
9 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Jon Loeliger5c8aa972006-04-26 17:58:56 -050010 */
11
12/*
13 * This file handles the architecture-dependent parts of hardware exceptions
14 */
15
16#include <common.h>
17#include <command.h>
Mike Frysinger629d88b2010-02-08 15:30:16 -050018#include <kgdb.h>
Jon Loeliger5c8aa972006-04-26 17:58:56 -050019#include <asm/processor.h>
20
Wolfgang Denkd112a2c2007-09-15 20:48:41 +020021DECLARE_GLOBAL_DATA_PTR;
22
Jon Loeliger5c8aa972006-04-26 17:58:56 -050023/* Returns 0 if exception not found and fixup otherwise. */
24extern unsigned long search_exception_table(unsigned long);
25
Becky Bruce6b3fbe42008-05-14 13:09:58 -050026/*
27 * End of addressable memory. This may be less than the actual
28 * amount of memory on the system if we're unable to keep all
29 * the memory mapped in.
30 */
Becky Bruce6b3fbe42008-05-14 13:09:58 -050031#define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize())
Jon Loeliger5c8aa972006-04-26 17:58:56 -050032
33/*
34 * Trap & Exception support
35 */
36
Kim Phillipse16737f2012-10-29 13:34:29 +000037static void print_backtrace(unsigned long *sp)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050038{
Jon Loeliger5c8aa972006-04-26 17:58:56 -050039 int cnt = 0;
40 unsigned long i;
41
42 printf("Call backtrace: ");
43 while (sp) {
Jon Loeligera1295442006-08-22 12:06:18 -050044 if ((uint) sp > END_OF_MEM)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050045 break;
46
47 i = sp[1];
48 if (cnt++ % 7 == 0)
49 printf("\n");
50 printf("%08lX ", i);
Jon Loeligera1295442006-08-22 12:06:18 -050051 if (cnt > 32)
52 break;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050053 sp = (unsigned long *)*sp;
54 }
55 printf("\n");
56}
57
Kim Phillipse16737f2012-10-29 13:34:29 +000058void show_regs(struct pt_regs *regs)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050059{
60 int i;
61
62 printf("NIP: %08lX XER: %08lX LR: %08lX REGS:"
63 " %p TRAP: %04lx DAR: %08lX\n",
64 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
65 printf("MSR: %08lx EE: %01x PR: %01x FP:"
66 " %01x ME: %01x IR/DR: %01x%01x\n",
Jon Loeligera1295442006-08-22 12:06:18 -050067 regs->msr, regs->msr & MSR_EE ? 1 : 0,
68 regs->msr & MSR_PR ? 1 : 0, regs->msr & MSR_FP ? 1 : 0,
69 regs->msr & MSR_ME ? 1 : 0, regs->msr & MSR_IR ? 1 : 0,
70 regs->msr & MSR_DR ? 1 : 0);
Jon Loeliger5c8aa972006-04-26 17:58:56 -050071
72 printf("\n");
Jon Loeligera1295442006-08-22 12:06:18 -050073 for (i = 0; i < 32; i++) {
74 if ((i % 8) == 0) {
Jon Loeliger5c8aa972006-04-26 17:58:56 -050075 printf("GPR%02d: ", i);
76 }
77
78 printf("%08lX ", regs->gpr[i]);
Jon Loeligera1295442006-08-22 12:06:18 -050079 if ((i % 8) == 7) {
Jon Loeliger5c8aa972006-04-26 17:58:56 -050080 printf("\n");
81 }
82 }
83}
84
85
Kim Phillipse16737f2012-10-29 13:34:29 +000086static void _exception(int signr, struct pt_regs *regs)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050087{
88 show_regs(regs);
89 print_backtrace((unsigned long *)regs->gpr[1]);
Jon Loeligera1295442006-08-22 12:06:18 -050090 panic("Exception in kernel pc %lx signal %d", regs->nip, signr);
Jon Loeliger5c8aa972006-04-26 17:58:56 -050091}
92
Kim Phillipse16737f2012-10-29 13:34:29 +000093void MachineCheckException(struct pt_regs *regs)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050094{
95 unsigned long fixup;
96
97 /* Probing PCI using config cycles cause this exception
98 * when a device is not present. Catch it and return to
99 * the PCI exception handler.
100 */
101 if ((fixup = search_exception_table(regs->nip)) != 0) {
102 regs->nip = fixup;
103 return;
104 }
105
Jon Loeliger07d53492007-06-13 13:23:15 -0500106#if defined(CONFIG_CMD_KGDB)
Jon Loeligera1295442006-08-22 12:06:18 -0500107 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500108 return;
109#endif
110
111 printf("Machine check in kernel mode.\n");
112 printf("Caused by (from msr): ");
Jon Loeligera1295442006-08-22 12:06:18 -0500113 printf("regs %p ", regs);
Jon Loeliger11c99582007-08-02 14:42:20 -0500114 switch ( regs->msr & 0x001F0000) {
115 case (0x80000000>>11):
116 printf("MSS error. MSSSR0: %08x\n", mfspr(SPRN_MSSSR0));
117 break;
118 case (0x80000000>>12):
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500119 printf("Machine check signal - probably due to mm fault\n"
Jon Loeligera1295442006-08-22 12:06:18 -0500120 "with mmu off\n");
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500121 break;
Jon Loeligera1295442006-08-22 12:06:18 -0500122 case (0x80000000 >> 13):
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500123 printf("Transfer error ack signal\n");
124 break;
Jon Loeligera1295442006-08-22 12:06:18 -0500125 case (0x80000000 >> 14):
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500126 printf("Data parity signal\n");
127 break;
Jon Loeligera1295442006-08-22 12:06:18 -0500128 case (0x80000000 >> 15):
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500129 printf("Address parity signal\n");
130 break;
131 default:
132 printf("Unknown values in msr\n");
133 }
134 show_regs(regs);
135 print_backtrace((unsigned long *)regs->gpr[1]);
136 panic("machine check");
137}
138
Kim Phillipse16737f2012-10-29 13:34:29 +0000139void AlignmentException(struct pt_regs *regs)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500140{
Jon Loeliger07d53492007-06-13 13:23:15 -0500141#if defined(CONFIG_CMD_KGDB)
Jon Loeligera1295442006-08-22 12:06:18 -0500142 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500143 return;
144#endif
145 show_regs(regs);
146 print_backtrace((unsigned long *)regs->gpr[1]);
147 panic("Alignment Exception");
148}
149
Kim Phillipse16737f2012-10-29 13:34:29 +0000150void ProgramCheckException(struct pt_regs *regs)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500151{
152 unsigned char *p = regs ? (unsigned char *)(regs->nip) : NULL;
153 int i, j;
154
Jon Loeliger07d53492007-06-13 13:23:15 -0500155#if defined(CONFIG_CMD_KGDB)
Jon Loeligera1295442006-08-22 12:06:18 -0500156 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500157 return;
158#endif
159 show_regs(regs);
160
Jon Loeligera1295442006-08-22 12:06:18 -0500161 p = (unsigned char *)((unsigned long)p & 0xFFFFFFE0);
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500162 p -= 32;
Jon Loeligera1295442006-08-22 12:06:18 -0500163 for (i = 0; i < 256; i += 16) {
164 printf("%08x: ", (unsigned int)p + i);
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500165 for (j = 0; j < 16; j++) {
Jon Loeligera1295442006-08-22 12:06:18 -0500166 printf("%02x ", p[i + j]);
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500167 }
168 printf("\n");
169 }
170
171 print_backtrace((unsigned long *)regs->gpr[1]);
172 panic("Program Check Exception");
173}
174
Kim Phillipse16737f2012-10-29 13:34:29 +0000175void SoftEmuException(struct pt_regs *regs)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500176{
Jon Loeliger07d53492007-06-13 13:23:15 -0500177#if defined(CONFIG_CMD_KGDB)
Jon Loeligera1295442006-08-22 12:06:18 -0500178 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500179 return;
180#endif
181 show_regs(regs);
182 print_backtrace((unsigned long *)regs->gpr[1]);
183 panic("Software Emulation Exception");
184}
185
Kim Phillipse16737f2012-10-29 13:34:29 +0000186void UnknownException(struct pt_regs *regs)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500187{
Jon Loeliger07d53492007-06-13 13:23:15 -0500188#if defined(CONFIG_CMD_KGDB)
Jon Loeligera1295442006-08-22 12:06:18 -0500189 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500190 return;
191#endif
Wolfgang Denk12cec0a2008-07-11 01:16:00 +0200192 printf("UnknownException regs@%lx\n", (ulong)regs);
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500193 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
194 regs->nip, regs->msr, regs->trap);
195 _exception(0, regs);
196}