2 * linux/arch/powerpc/kernel/traps.c
4 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
6 * Modified by Cort Dougan (cort@cs.nmt.edu)
7 * and Paul Mackerras (paulus@cs.anu.edu.au)
10 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
12 * SPDX-License-Identifier: GPL-2.0+
16 * This file handles the architecture-dependent parts of hardware exceptions
22 #include <asm/processor.h>
23 #include <asm/m8260_pci.h>
25 /* Returns 0 if exception not found and fixup otherwise. */
26 extern unsigned long search_exception_table(unsigned long);
28 /* THIS NEEDS CHANGING to use the board info structure.
30 #define END_OF_MEM 0x02000000
33 * Trap & Exception support
36 static void print_backtrace(unsigned long *sp
)
41 puts ("Call backtrace: ");
43 if ((uint
)sp
> END_OF_MEM
)
51 sp
= (unsigned long *)*sp
;
56 void show_regs(struct pt_regs
*regs
)
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);
69 for (i
= 0; i
< 32; i
++) {
71 printf("GPR%02d: ", i
);
74 printf("%08lX ", regs
->gpr
[i
]);
82 static void _exception(int signr
, struct pt_regs
*regs
)
85 print_backtrace((unsigned long *)regs
->gpr
[1]);
86 panic("Exception in kernel pc %lx signal %d",regs
->nip
,signr
);
93 volatile immap_t
*immap
= (immap_t
*) CONFIG_SYS_IMMR
;
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
));
107 void MachineCheckException(struct pt_regs
*regs
)
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.
116 volatile immap_t
*immap
= (immap_t
*)CONFIG_SYS_IMMR
;
120 /* clear the error in the error status register */
121 if(immap
->im_pci
.pci_esr
& cpu_to_le32(PCI_ERROR_PCI_NO_RSP
)) {
122 immap
->im_pci
.pci_esr
= cpu_to_le32(PCI_ERROR_PCI_NO_RSP
);
126 if ((fixup
= search_exception_table(regs
->nip
)) != 0) {
131 #if defined(CONFIG_CMD_KGDB)
132 if (debugger_exception_handler
&& (*debugger_exception_handler
)(regs
))
136 puts ("Machine check in kernel mode.\n"
137 "Caused by (from msr): ");
138 printf("regs %p ",regs
);
139 switch( regs
->msr
& 0x000F0000) {
140 case (0x80000000>>12):
141 puts ("Machine check signal - probably due to mm fault\n"
144 case (0x80000000>>13):
145 puts ("Transfer error ack signal\n");
147 case (0x80000000>>14):
148 puts ("Data parity signal\n");
150 case (0x80000000>>15):
151 puts ("Address parity signal\n");
154 puts ("Unknown values in msr\n");
157 print_backtrace((unsigned long *)regs
->gpr
[1]);
161 panic("machine check");
164 void AlignmentException(struct pt_regs
*regs
)
166 #if defined(CONFIG_CMD_KGDB)
167 if (debugger_exception_handler
&& (*debugger_exception_handler
)(regs
))
171 print_backtrace((unsigned long *)regs
->gpr
[1]);
172 panic("Alignment Exception");
175 void ProgramCheckException(struct pt_regs
*regs
)
177 #if defined(CONFIG_CMD_KGDB)
178 if (debugger_exception_handler
&& (*debugger_exception_handler
)(regs
))
182 print_backtrace((unsigned long *)regs
->gpr
[1]);
183 panic("Program Check Exception");
186 void SoftEmuException(struct pt_regs
*regs
)
188 #if defined(CONFIG_CMD_KGDB)
189 if (debugger_exception_handler
&& (*debugger_exception_handler
)(regs
))
193 print_backtrace((unsigned long *)regs
->gpr
[1]);
194 panic("Software Emulation Exception");
198 void UnknownException(struct pt_regs
*regs
)
200 #if defined(CONFIG_CMD_KGDB)
201 if (debugger_exception_handler
&& (*debugger_exception_handler
)(regs
))
204 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
205 regs
->nip
, regs
->msr
, regs
->trap
);
209 #if defined(CONFIG_CMD_BEDBUG)
210 extern void do_bedbug_breakpoint(struct pt_regs
*);
213 void DebugException(struct pt_regs
*regs
)
216 printf("Debugger trap at @ %lx\n", regs
->nip
);
218 #if defined(CONFIG_CMD_BEDBUG)
219 do_bedbug_breakpoint( regs
);
223 /* Probe an address by reading. If not present, return -1, otherwise
226 int addr_probe(uint
*addr
)
231 __asm__
__volatile__( \
232 "1: lwz %0,0(%1)\n" \
236 ".section .fixup,\"ax\"\n" \
239 ".section __ex_table,\"a\"\n" \
243 : "=r" (retval
) : "r"(addr
));