blob: 92fb537453b5f6412c259acb033e018b69b78512 [file] [log] [blame]
Jon Loeligerdebb7352006-04-26 17:58:56 -05001/*
Jon Loeligerdebb7352006-04-26 17:58:56 -05002 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
3 *
4 * Modified by Cort Dougan (cort@cs.nmt.edu)
5 * and Paul Mackerras (paulus@cs.anu.edu.au)
6 *
7 * (C) Copyright 2000
8 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
Jon Loeligerdebb7352006-04-26 17:58:56 -050011 */
12
13/*
14 * This file handles the architecture-dependent parts of hardware exceptions
15 */
16
17#include <common.h>
18#include <command.h>
Mike Frysingere39bf1e2010-02-08 15:30:16 -050019#include <kgdb.h>
Jon Loeligerdebb7352006-04-26 17:58:56 -050020#include <asm/processor.h>
21
Wolfgang Denk1218abf2007-09-15 20:48:41 +020022DECLARE_GLOBAL_DATA_PTR;
23
Jon Loeligerdebb7352006-04-26 17:58:56 -050024/* Returns 0 if exception not found and fixup otherwise. */
25extern unsigned long search_exception_table(unsigned long);
26
Becky Bruce279726b2008-05-14 13:09:58 -050027/*
28 * End of addressable memory. This may be less than the actual
29 * amount of memory on the system if we're unable to keep all
30 * the memory mapped in.
31 */
Becky Bruce279726b2008-05-14 13:09:58 -050032#define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize())
Jon Loeligerdebb7352006-04-26 17:58:56 -050033
34/*
35 * Trap & Exception support
36 */
37
Kim Phillips20051f22012-10-29 13:34:29 +000038static void print_backtrace(unsigned long *sp)
Jon Loeligerdebb7352006-04-26 17:58:56 -050039{
Jon Loeligerdebb7352006-04-26 17:58:56 -050040 int cnt = 0;
41 unsigned long i;
42
43 printf("Call backtrace: ");
44 while (sp) {
Jon Loeligerffff3ae2006-08-22 12:06:18 -050045 if ((uint) sp > END_OF_MEM)
Jon Loeligerdebb7352006-04-26 17:58:56 -050046 break;
47
48 i = sp[1];
49 if (cnt++ % 7 == 0)
50 printf("\n");
51 printf("%08lX ", i);
Jon Loeligerffff3ae2006-08-22 12:06:18 -050052 if (cnt > 32)
53 break;
Jon Loeligerdebb7352006-04-26 17:58:56 -050054 sp = (unsigned long *)*sp;
55 }
56 printf("\n");
57}
58
Kim Phillips20051f22012-10-29 13:34:29 +000059void show_regs(struct pt_regs *regs)
Jon Loeligerdebb7352006-04-26 17:58:56 -050060{
61 int i;
62
63 printf("NIP: %08lX XER: %08lX LR: %08lX REGS:"
64 " %p TRAP: %04lx DAR: %08lX\n",
65 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
66 printf("MSR: %08lx EE: %01x PR: %01x FP:"
67 " %01x ME: %01x IR/DR: %01x%01x\n",
Jon Loeligerffff3ae2006-08-22 12:06:18 -050068 regs->msr, regs->msr & MSR_EE ? 1 : 0,
69 regs->msr & MSR_PR ? 1 : 0, regs->msr & MSR_FP ? 1 : 0,
70 regs->msr & MSR_ME ? 1 : 0, regs->msr & MSR_IR ? 1 : 0,
71 regs->msr & MSR_DR ? 1 : 0);
Jon Loeligerdebb7352006-04-26 17:58:56 -050072
73 printf("\n");
Jon Loeligerffff3ae2006-08-22 12:06:18 -050074 for (i = 0; i < 32; i++) {
75 if ((i % 8) == 0) {
Jon Loeligerdebb7352006-04-26 17:58:56 -050076 printf("GPR%02d: ", i);
77 }
78
79 printf("%08lX ", regs->gpr[i]);
Jon Loeligerffff3ae2006-08-22 12:06:18 -050080 if ((i % 8) == 7) {
Jon Loeligerdebb7352006-04-26 17:58:56 -050081 printf("\n");
82 }
83 }
84}
85
86
Kim Phillips20051f22012-10-29 13:34:29 +000087static void _exception(int signr, struct pt_regs *regs)
Jon Loeligerdebb7352006-04-26 17:58:56 -050088{
89 show_regs(regs);
90 print_backtrace((unsigned long *)regs->gpr[1]);
Jon Loeligerffff3ae2006-08-22 12:06:18 -050091 panic("Exception in kernel pc %lx signal %d", regs->nip, signr);
Jon Loeligerdebb7352006-04-26 17:58:56 -050092}
93
Kim Phillips20051f22012-10-29 13:34:29 +000094void MachineCheckException(struct pt_regs *regs)
Jon Loeligerdebb7352006-04-26 17:58:56 -050095{
96 unsigned long fixup;
97
98 /* Probing PCI using config cycles cause this exception
99 * when a device is not present. Catch it and return to
100 * the PCI exception handler.
101 */
102 if ((fixup = search_exception_table(regs->nip)) != 0) {
103 regs->nip = fixup;
104 return;
105 }
106
Jon Loeligerb24629f2007-06-13 13:23:15 -0500107#if defined(CONFIG_CMD_KGDB)
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500108 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
Jon Loeligerdebb7352006-04-26 17:58:56 -0500109 return;
110#endif
111
112 printf("Machine check in kernel mode.\n");
113 printf("Caused by (from msr): ");
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500114 printf("regs %p ", regs);
Jon Loeligercfc7a7f2007-08-02 14:42:20 -0500115 switch ( regs->msr & 0x001F0000) {
116 case (0x80000000>>11):
117 printf("MSS error. MSSSR0: %08x\n", mfspr(SPRN_MSSSR0));
118 break;
119 case (0x80000000>>12):
Jon Loeligerdebb7352006-04-26 17:58:56 -0500120 printf("Machine check signal - probably due to mm fault\n"
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500121 "with mmu off\n");
Jon Loeligerdebb7352006-04-26 17:58:56 -0500122 break;
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500123 case (0x80000000 >> 13):
Jon Loeligerdebb7352006-04-26 17:58:56 -0500124 printf("Transfer error ack signal\n");
125 break;
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500126 case (0x80000000 >> 14):
Jon Loeligerdebb7352006-04-26 17:58:56 -0500127 printf("Data parity signal\n");
128 break;
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500129 case (0x80000000 >> 15):
Jon Loeligerdebb7352006-04-26 17:58:56 -0500130 printf("Address parity signal\n");
131 break;
132 default:
133 printf("Unknown values in msr\n");
134 }
135 show_regs(regs);
136 print_backtrace((unsigned long *)regs->gpr[1]);
137 panic("machine check");
138}
139
Kim Phillips20051f22012-10-29 13:34:29 +0000140void AlignmentException(struct pt_regs *regs)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500141{
Jon Loeligerb24629f2007-06-13 13:23:15 -0500142#if defined(CONFIG_CMD_KGDB)
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500143 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
Jon Loeligerdebb7352006-04-26 17:58:56 -0500144 return;
145#endif
146 show_regs(regs);
147 print_backtrace((unsigned long *)regs->gpr[1]);
148 panic("Alignment Exception");
149}
150
Kim Phillips20051f22012-10-29 13:34:29 +0000151void ProgramCheckException(struct pt_regs *regs)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500152{
153 unsigned char *p = regs ? (unsigned char *)(regs->nip) : NULL;
154 int i, j;
155
Jon Loeligerb24629f2007-06-13 13:23:15 -0500156#if defined(CONFIG_CMD_KGDB)
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500157 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
Jon Loeligerdebb7352006-04-26 17:58:56 -0500158 return;
159#endif
160 show_regs(regs);
161
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500162 p = (unsigned char *)((unsigned long)p & 0xFFFFFFE0);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500163 p -= 32;
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500164 for (i = 0; i < 256; i += 16) {
165 printf("%08x: ", (unsigned int)p + i);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500166 for (j = 0; j < 16; j++) {
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500167 printf("%02x ", p[i + j]);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500168 }
169 printf("\n");
170 }
171
172 print_backtrace((unsigned long *)regs->gpr[1]);
173 panic("Program Check Exception");
174}
175
Kim Phillips20051f22012-10-29 13:34:29 +0000176void SoftEmuException(struct pt_regs *regs)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500177{
Jon Loeligerb24629f2007-06-13 13:23:15 -0500178#if defined(CONFIG_CMD_KGDB)
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500179 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
Jon Loeligerdebb7352006-04-26 17:58:56 -0500180 return;
181#endif
182 show_regs(regs);
183 print_backtrace((unsigned long *)regs->gpr[1]);
184 panic("Software Emulation Exception");
185}
186
Kim Phillips20051f22012-10-29 13:34:29 +0000187void UnknownException(struct pt_regs *regs)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500188{
Jon Loeligerb24629f2007-06-13 13:23:15 -0500189#if defined(CONFIG_CMD_KGDB)
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500190 if (debugger_exception_handler && (*debugger_exception_handler) (regs))
Jon Loeligerdebb7352006-04-26 17:58:56 -0500191 return;
192#endif
Wolfgang Denk9b55a252008-07-11 01:16:00 +0200193 printf("UnknownException regs@%lx\n", (ulong)regs);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500194 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
195 regs->nip, regs->msr, regs->trap);
196 _exception(0, regs);
197}
198
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500199/*
200 * Probe an address by reading.
201 * If not present, return -1,
202 * otherwise return 0.
Jon Loeligerdebb7352006-04-26 17:58:56 -0500203 */
Kim Phillips20051f22012-10-29 13:34:29 +0000204int addr_probe(uint *addr)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500205{
Jon Loeligerdebb7352006-04-26 17:58:56 -0500206 return 0;
207}