blob: 6abf41d374d13506e37d664dd131617e918fc019 [file] [log] [blame]
wdenkaffae2b2002-08-17 09:36:01 +00001/*
Stefan Roesea47a12b2010-04-15 16:07:28 +02002 * linux/arch/powerpc/kernel/traps.c
wdenkaffae2b2002-08-17 09:36:01 +00003 *
4 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
5 *
6 * Modified by Cort Dougan (cort@cs.nmt.edu)
7 * and Paul Mackerras (paulus@cs.anu.edu.au)
8 *
9 * (C) Copyright 2000
10 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
11 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020012 * SPDX-License-Identifier: GPL-2.0+
wdenkaffae2b2002-08-17 09:36:01 +000013 */
14
15/*
16 * This file handles the architecture-dependent parts of hardware exceptions
17 */
18
19#include <common.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 0x00400000
28
29/*
30 * Trap & Exception support
31 */
32
Kim Phillips20051f22012-10-29 13:34:29 +000033static void print_backtrace(unsigned long *sp)
wdenkaffae2b2002-08-17 09:36:01 +000034{
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);
47 if (cnt > 32) break;
48 sp = (unsigned long *)*sp;
49 }
50 printf("\n");
51}
52
Kim Phillips20051f22012-10-29 13:34:29 +000053void show_regs(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +000054{
55 int i;
56
57 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
58 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
59 printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
60 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
61 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
62 regs->msr&MSR_IR ? 1 : 0,
63 regs->msr&MSR_DR ? 1 : 0);
64
65 printf("\n");
66 for (i = 0; i < 32; i++) {
67 if ((i % 8) == 0)
68 {
69 printf("GPR%02d: ", i);
70 }
71
72 printf("%08lX ", regs->gpr[i]);
73 if ((i % 8) == 7)
74 {
75 printf("\n");
76 }
77 }
78}
79
80
Kim Phillips20051f22012-10-29 13:34:29 +000081static void _exception(int signr, struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +000082{
83 show_regs(regs);
84 print_backtrace((unsigned long *)regs->gpr[1]);
85 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
86}
87
Kim Phillips20051f22012-10-29 13:34:29 +000088void MachineCheckException(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +000089{
90 unsigned long fixup;
91
92 /* Probing PCI using config cycles cause this exception
93 * when a device is not present. Catch it and return to
94 * the PCI exception handler.
95 */
96 if ((fixup = search_exception_table(regs->nip)) != 0) {
97 regs->nip = fixup;
98 return;
99 }
100
101 printf("Machine check in kernel mode.\n");
102 printf("Caused by (from msr): ");
103 printf("regs %p ",regs);
wdenk63e73c92004-02-23 22:22:28 +0000104 switch( regs->msr & 0x000F0000) {
105 case (0x80000000>>12):
wdenkaffae2b2002-08-17 09:36:01 +0000106 printf("Machine check signal - probably due to mm fault\n"
107 "with mmu off\n");
108 break;
wdenk63e73c92004-02-23 22:22:28 +0000109 case (0x80000000>>13):
wdenkaffae2b2002-08-17 09:36:01 +0000110 printf("Transfer error ack signal\n");
111 break;
wdenk63e73c92004-02-23 22:22:28 +0000112 case (0x80000000>>14):
wdenkaffae2b2002-08-17 09:36:01 +0000113 printf("Data parity signal\n");
114 break;
wdenk63e73c92004-02-23 22:22:28 +0000115 case (0x80000000>>15):
wdenkaffae2b2002-08-17 09:36:01 +0000116 printf("Address parity signal\n");
117 break;
118 default:
119 printf("Unknown values in msr\n");
120 }
121 show_regs(regs);
122 print_backtrace((unsigned long *)regs->gpr[1]);
123 panic("machine check");
124}
125
Kim Phillips20051f22012-10-29 13:34:29 +0000126void AlignmentException(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +0000127{
128 show_regs(regs);
129 print_backtrace((unsigned long *)regs->gpr[1]);
130 panic("Alignment Exception");
131}
132
Kim Phillips20051f22012-10-29 13:34:29 +0000133void ProgramCheckException(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +0000134{
135 show_regs(regs);
136 print_backtrace((unsigned long *)regs->gpr[1]);
137 panic("Program Check Exception");
138}
139
Kim Phillips20051f22012-10-29 13:34:29 +0000140void SoftEmuException(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +0000141{
142 show_regs(regs);
143 print_backtrace((unsigned long *)regs->gpr[1]);
144 panic("Software Emulation Exception");
145}
146
147
Kim Phillips20051f22012-10-29 13:34:29 +0000148void UnknownException(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +0000149{
150 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
151 regs->nip, regs->msr, regs->trap);
152 _exception(0, regs);
153}
154
Jon Loeliger44312832007-07-09 19:06:00 -0500155#if defined(CONFIG_CMD_BEDBUG)
wdenk43d96162003-03-06 00:02:04 +0000156extern void do_bedbug_breakpoint(struct pt_regs *);
157#endif
158
Kim Phillips20051f22012-10-29 13:34:29 +0000159void DebugException(struct pt_regs *regs)
wdenk43d96162003-03-06 00:02:04 +0000160{
161
162 printf("Debugger trap at @ %lx\n", regs->nip );
163 show_regs(regs);
Jon Loeliger44312832007-07-09 19:06:00 -0500164#if defined(CONFIG_CMD_BEDBUG)
wdenk43d96162003-03-06 00:02:04 +0000165 do_bedbug_breakpoint( regs );
166#endif
167}
168
wdenkaffae2b2002-08-17 09:36:01 +0000169/* Probe an address by reading. If not present, return -1, otherwise
170 * return 0.
171 */
Kim Phillips20051f22012-10-29 13:34:29 +0000172int addr_probe(uint *addr)
wdenkaffae2b2002-08-17 09:36:01 +0000173{
174#if 0
175 int retval;
176
177 __asm__ __volatile__( \
178 "1: lwz %0,0(%1)\n" \
179 " eieio\n" \
180 " li %0,0\n" \
181 "2:\n" \
182 ".section .fixup,\"ax\"\n" \
183 "3: li %0,-1\n" \
184 " b 2b\n" \
185 ".section __ex_table,\"a\"\n" \
186 " .align 2\n" \
187 " .long 1b,3b\n" \
188 ".text" \
189 : "=r" (retval) : "r"(addr));
190
191 return (retval);
192#endif
193 return 0;
194}