]> git.ipfire.org Git - people/ms/u-boot.git/blame - arch/powerpc/cpu/74xx_7xx/traps.c
Add GPL-2.0+ SPDX-License-Identifier to source files
[people/ms/u-boot.git] / arch / powerpc / cpu / 74xx_7xx / traps.c
CommitLineData
affae2bf 1/*
a47a12be 2 * linux/arch/powerpc/kernel/traps.c
affae2bf
WD
3 *
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 *
1a459660 12 * SPDX-License-Identifier: GPL-2.0+
affae2bf
WD
13 */
14
15/*
16 * This file handles the architecture-dependent parts of hardware exceptions
17 */
18
19#include <common.h>
20#include <command.h>
e39bf1e2 21#include <kgdb.h>
affae2bf
WD
22#include <asm/processor.h>
23
affae2bf
WD
24/* Returns 0 if exception not found and fixup otherwise. */
25extern unsigned long search_exception_table(unsigned long);
26
27/* THIS NEEDS CHANGING to use the board info structure.
28*/
29#define END_OF_MEM 0x02000000
30
31/*
32 * Trap & Exception support
33 */
34
20051f2a 35static void print_backtrace(unsigned long *sp)
affae2bf
WD
36{
37 int cnt = 0;
38 unsigned long i;
39
40 printf("Call backtrace: ");
41 while (sp) {
42 if ((uint)sp > END_OF_MEM)
43 break;
44
45 i = sp[1];
46 if (cnt++ % 7 == 0)
47 printf("\n");
48 printf("%08lX ", i);
49 if (cnt > 32) break;
50 sp = (unsigned long *)*sp;
51 }
52 printf("\n");
53}
54
20051f2a 55void show_regs(struct pt_regs *regs)
affae2bf
WD
56{
57 int i;
58
59 printf("NIP: %08lX XER: %08lX LR: %08lX REGS:"
60 " %p TRAP: %04lx DAR: %08lX\n",
61 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
62 printf("MSR: %08lx EE: %01x PR: %01x FP:"
63 " %01x ME: %01x IR/DR: %01x%01x\n",
64 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
65 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
66 regs->msr&MSR_IR ? 1 : 0,
67 regs->msr&MSR_DR ? 1 : 0);
68
69 printf("\n");
70 for (i = 0; i < 32; i++) {
71 if ((i % 8) == 0)
72 {
73 printf("GPR%02d: ", i);
74 }
75
76 printf("%08lX ", regs->gpr[i]);
77 if ((i % 8) == 7)
78 {
79 printf("\n");
80 }
81 }
82}
83
84
20051f2a 85static void _exception(int signr, struct pt_regs *regs)
affae2bf
WD
86{
87 show_regs(regs);
88 print_backtrace((unsigned long *)regs->gpr[1]);
89 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
90}
91
20051f2a 92void MachineCheckException(struct pt_regs *regs)
affae2bf
WD
93{
94 unsigned long fixup;
95
96 /* Probing PCI using config cycles cause this exception
97 * when a device is not present. Catch it and return to
98 * the PCI exception handler.
99 */
100 if ((fixup = search_exception_table(regs->nip)) != 0) {
101 regs->nip = fixup;
102 return;
103 }
104
3a1ed1e1 105#if defined(CONFIG_CMD_KGDB)
affae2bf
WD
106 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
107 return;
108#endif
109
110 printf("Machine check in kernel mode.\n");
111 printf("Caused by (from msr): ");
112 printf("regs %p ",regs);
63e73c9a
WD
113 switch( regs->msr & 0x000F0000) {
114 case (0x80000000>>12):
affae2bf
WD
115 printf("Machine check signal - probably due to mm fault\n"
116 "with mmu off\n");
117 break;
63e73c9a 118 case (0x80000000>>13):
affae2bf
WD
119 printf("Transfer error ack signal\n");
120 break;
63e73c9a 121 case (0x80000000>>14):
affae2bf
WD
122 printf("Data parity signal\n");
123 break;
63e73c9a 124 case (0x80000000>>15):
affae2bf
WD
125 printf("Address parity signal\n");
126 break;
127 default:
128 printf("Unknown values in msr\n");
129 }
130 show_regs(regs);
131 print_backtrace((unsigned long *)regs->gpr[1]);
132 panic("machine check");
133}
134
20051f2a 135void AlignmentException(struct pt_regs *regs)
affae2bf 136{
3a1ed1e1 137#if defined(CONFIG_CMD_KGDB)
affae2bf
WD
138 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
139 return;
140#endif
141 show_regs(regs);
142 print_backtrace((unsigned long *)regs->gpr[1]);
143 panic("Alignment Exception");
144}
145
20051f2a 146void ProgramCheckException(struct pt_regs *regs)
affae2bf 147{
c7de829c
WD
148 unsigned char *p = regs ? (unsigned char *)(regs->nip) : NULL;
149 int i, j;
150
3a1ed1e1 151#if defined(CONFIG_CMD_KGDB)
affae2bf
WD
152 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
153 return;
154#endif
155 show_regs(regs);
c7de829c
WD
156
157 p = (unsigned char *) ((unsigned long)p & 0xFFFFFFE0);
158 p -= 32;
159 for (i = 0; i < 256; i+=16) {
160 printf("%08x: ", (unsigned int)p+i);
161 for (j = 0; j < 16; j++) {
162 printf("%02x ", p[i+j]);
163 }
164 printf("\n");
165 }
166
affae2bf
WD
167 print_backtrace((unsigned long *)regs->gpr[1]);
168 panic("Program Check Exception");
169}
170
20051f2a 171void SoftEmuException(struct pt_regs *regs)
affae2bf 172{
3a1ed1e1 173#if defined(CONFIG_CMD_KGDB)
affae2bf
WD
174 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
175 return;
176#endif
177 show_regs(regs);
178 print_backtrace((unsigned long *)regs->gpr[1]);
179 panic("Software Emulation Exception");
180}
181
20051f2a 182void UnknownException(struct pt_regs *regs)
affae2bf 183{
3a1ed1e1 184#if defined(CONFIG_CMD_KGDB)
affae2bf
WD
185 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
186 return;
187#endif
188 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
189 regs->nip, regs->msr, regs->trap);
190 _exception(0, regs);
191}
192
193/* Probe an address by reading. If not present, return -1, otherwise
194 * return 0.
195 */
20051f2a 196int addr_probe(uint *addr)
affae2bf
WD
197{
198#if 0
199 int retval;
200
201 __asm__ __volatile__( \
202 "1: lwz %0,0(%1)\n" \
203 " eieio\n" \
204 " li %0,0\n" \
205 "2:\n" \
206 ".section .fixup,\"ax\"\n" \
207 "3: li %0,-1\n" \
208 " b 2b\n" \
209 ".section __ex_table,\"a\"\n" \
210 " .align 2\n" \
211 " .long 1b,3b\n" \
212 ".text" \
213 : "=r" (retval) : "r"(addr));
214
215 return (retval);
216#endif
217 return 0;
218}