]>
Commit | Line | Data |
---|---|---|
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 | 22 | #include <asm/processor.h> |
3c74e32a | 23 | #include <asm/m8260_pci.h> |
affae2bf | 24 | |
affae2bf WD |
25 | /* Returns 0 if exception not found and fixup otherwise. */ |
26 | extern unsigned long search_exception_table(unsigned long); | |
27 | ||
28 | /* THIS NEEDS CHANGING to use the board info structure. | |
29 | */ | |
30 | #define END_OF_MEM 0x02000000 | |
31 | ||
32 | /* | |
33 | * Trap & Exception support | |
34 | */ | |
35 | ||
20051f2a | 36 | static void print_backtrace(unsigned long *sp) |
affae2bf WD |
37 | { |
38 | int cnt = 0; | |
39 | unsigned long i; | |
40 | ||
4b9206ed | 41 | puts ("Call backtrace: "); |
affae2bf WD |
42 | while (sp) { |
43 | if ((uint)sp > END_OF_MEM) | |
44 | break; | |
45 | ||
46 | i = sp[1]; | |
47 | if (cnt++ % 7 == 0) | |
4b9206ed | 48 | putc ('\n'); |
affae2bf WD |
49 | printf("%08lX ", i); |
50 | if (cnt > 32) break; | |
51 | sp = (unsigned long *)*sp; | |
52 | } | |
4b9206ed | 53 | putc ('\n'); |
affae2bf WD |
54 | } |
55 | ||
20051f2a | 56 | void show_regs(struct pt_regs *regs) |
affae2bf WD |
57 | { |
58 | int i; | |
59 | ||
60 | printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %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: %01x ME: %01x IR/DR: %01x%01x\n", | |
63 | regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0, | |
64 | regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0, | |
65 | regs->msr&MSR_IR ? 1 : 0, | |
66 | regs->msr&MSR_DR ? 1 : 0); | |
67 | ||
4b9206ed | 68 | putc ('\n'); |
affae2bf | 69 | for (i = 0; i < 32; i++) { |
3c74e32a | 70 | if ((i % 8) == 0) { |
affae2bf WD |
71 | printf("GPR%02d: ", i); |
72 | } | |
73 | ||
74 | printf("%08lX ", regs->gpr[i]); | |
3c74e32a | 75 | if ((i % 8) == 7) { |
4b9206ed | 76 | putc ('\n'); |
affae2bf WD |
77 | } |
78 | } | |
79 | } | |
80 | ||
81 | ||
20051f2a | 82 | static void _exception(int signr, struct pt_regs *regs) |
affae2bf WD |
83 | { |
84 | show_regs(regs); | |
85 | print_backtrace((unsigned long *)regs->gpr[1]); | |
86 | panic("Exception in kernel pc %lx signal %d",regs->nip,signr); | |
87 | } | |
88 | ||
3c74e32a WD |
89 | #ifdef CONFIG_PCI |
90 | void dump_pci (void) | |
91 | { | |
92 | ||
6d0f6bcf | 93 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
3c74e32a WD |
94 | |
95 | printf ("PCI: err status %x err mask %x err ctrl %x\n", | |
96 | le32_to_cpu (immap->im_pci.pci_esr), | |
97 | le32_to_cpu (immap->im_pci.pci_emr), | |
98 | le32_to_cpu (immap->im_pci.pci_ecr)); | |
99 | printf (" error address %x error data %x ctrl %x\n", | |
100 | le32_to_cpu (immap->im_pci.pci_eacr), | |
101 | le32_to_cpu (immap->im_pci.pci_edcr), | |
102 | le32_to_cpu (immap->im_pci.pci_eccr)); | |
103 | ||
104 | } | |
105 | #endif | |
106 | ||
20051f2a | 107 | void MachineCheckException(struct pt_regs *regs) |
affae2bf WD |
108 | { |
109 | unsigned long fixup; | |
110 | ||
111 | /* Probing PCI using config cycles cause this exception | |
112 | * when a device is not present. Catch it and return to | |
113 | * the PCI exception handler. | |
114 | */ | |
3c74e32a | 115 | #ifdef CONFIG_PCI |
6d0f6bcf | 116 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
3c74e32a WD |
117 | #ifdef DEBUG |
118 | dump_pci(); | |
119 | #endif | |
120 | /* clear the error in the error status register */ | |
6fb6af6d | 121 | if(immap->im_pci.pci_esr & cpu_to_le32(PCI_ERROR_PCI_NO_RSP)) { |
3c74e32a WD |
122 | immap->im_pci.pci_esr = cpu_to_le32(PCI_ERROR_PCI_NO_RSP); |
123 | return; | |
124 | } | |
125 | #endif | |
affae2bf WD |
126 | if ((fixup = search_exception_table(regs->nip)) != 0) { |
127 | regs->nip = fixup; | |
128 | return; | |
129 | } | |
130 | ||
4431283c | 131 | #if defined(CONFIG_CMD_KGDB) |
affae2bf WD |
132 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
133 | return; | |
134 | #endif | |
135 | ||
4b9206ed WD |
136 | puts ("Machine check in kernel mode.\n" |
137 | "Caused by (from msr): "); | |
affae2bf | 138 | printf("regs %p ",regs); |
63e73c9a WD |
139 | switch( regs->msr & 0x000F0000) { |
140 | case (0x80000000>>12): | |
4b9206ed | 141 | puts ("Machine check signal - probably due to mm fault\n" |
affae2bf WD |
142 | "with mmu off\n"); |
143 | break; | |
63e73c9a | 144 | case (0x80000000>>13): |
4b9206ed | 145 | puts ("Transfer error ack signal\n"); |
affae2bf | 146 | break; |
63e73c9a | 147 | case (0x80000000>>14): |
4b9206ed | 148 | puts ("Data parity signal\n"); |
affae2bf | 149 | break; |
63e73c9a | 150 | case (0x80000000>>15): |
4b9206ed | 151 | puts ("Address parity signal\n"); |
affae2bf WD |
152 | break; |
153 | default: | |
4b9206ed | 154 | puts ("Unknown values in msr\n"); |
affae2bf WD |
155 | } |
156 | show_regs(regs); | |
157 | print_backtrace((unsigned long *)regs->gpr[1]); | |
3c74e32a WD |
158 | #ifdef CONFIG_PCI |
159 | dump_pci(); | |
160 | #endif | |
affae2bf WD |
161 | panic("machine check"); |
162 | } | |
163 | ||
20051f2a | 164 | void AlignmentException(struct pt_regs *regs) |
affae2bf | 165 | { |
4431283c | 166 | #if defined(CONFIG_CMD_KGDB) |
affae2bf WD |
167 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
168 | return; | |
169 | #endif | |
170 | show_regs(regs); | |
171 | print_backtrace((unsigned long *)regs->gpr[1]); | |
172 | panic("Alignment Exception"); | |
173 | } | |
174 | ||
20051f2a | 175 | void ProgramCheckException(struct pt_regs *regs) |
affae2bf | 176 | { |
4431283c | 177 | #if defined(CONFIG_CMD_KGDB) |
affae2bf WD |
178 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
179 | return; | |
180 | #endif | |
181 | show_regs(regs); | |
182 | print_backtrace((unsigned long *)regs->gpr[1]); | |
183 | panic("Program Check Exception"); | |
184 | } | |
185 | ||
20051f2a | 186 | void SoftEmuException(struct pt_regs *regs) |
affae2bf | 187 | { |
4431283c | 188 | #if defined(CONFIG_CMD_KGDB) |
affae2bf WD |
189 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
190 | return; | |
191 | #endif | |
192 | show_regs(regs); | |
193 | print_backtrace((unsigned long *)regs->gpr[1]); | |
194 | panic("Software Emulation Exception"); | |
195 | } | |
196 | ||
197 | ||
20051f2a | 198 | void UnknownException(struct pt_regs *regs) |
affae2bf | 199 | { |
4431283c | 200 | #if defined(CONFIG_CMD_KGDB) |
affae2bf WD |
201 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
202 | return; | |
203 | #endif | |
204 | printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n", | |
205 | regs->nip, regs->msr, regs->trap); | |
206 | _exception(0, regs); | |
207 | } | |
208 | ||
4431283c | 209 | #if defined(CONFIG_CMD_BEDBUG) |
affae2bf WD |
210 | extern void do_bedbug_breakpoint(struct pt_regs *); |
211 | #endif | |
212 | ||
20051f2a | 213 | void DebugException(struct pt_regs *regs) |
affae2bf WD |
214 | { |
215 | ||
216 | printf("Debugger trap at @ %lx\n", regs->nip ); | |
217 | show_regs(regs); | |
4431283c | 218 | #if defined(CONFIG_CMD_BEDBUG) |
affae2bf WD |
219 | do_bedbug_breakpoint( regs ); |
220 | #endif | |
221 | } | |
222 | ||
223 | /* Probe an address by reading. If not present, return -1, otherwise | |
224 | * return 0. | |
225 | */ | |
20051f2a | 226 | int addr_probe(uint *addr) |
affae2bf WD |
227 | { |
228 | #if 0 | |
229 | int retval; | |
230 | ||
231 | __asm__ __volatile__( \ | |
232 | "1: lwz %0,0(%1)\n" \ | |
233 | " eieio\n" \ | |
234 | " li %0,0\n" \ | |
235 | "2:\n" \ | |
236 | ".section .fixup,\"ax\"\n" \ | |
237 | "3: li %0,-1\n" \ | |
238 | " b 2b\n" \ | |
239 | ".section __ex_table,\"a\"\n" \ | |
240 | " .align 2\n" \ | |
241 | " .long 1b,3b\n" \ | |
242 | ".text" \ | |
243 | : "=r" (retval) : "r"(addr)); | |
244 | ||
245 | return (retval); | |
246 | #endif | |
247 | return 0; | |
248 | } |