3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
7 * SPDX-License-Identifier: GPL-2.0+
11 * This file handles the architecture-dependent parts of hardware
18 #include <asm/processor.h>
19 #include <asm/mpc8349_pci.h>
21 DECLARE_GLOBAL_DATA_PTR;
23 /* Returns 0 if exception not found and fixup otherwise. */
24 extern unsigned long search_exception_table(unsigned long);
26 #define END_OF_MEM (gd->bd->bi_memstart + gd->bd->bi_memsize)
29 * Trap & Exception support
32 static void print_backtrace(unsigned long *sp)
37 puts ("Call backtrace: ");
39 if ((uint)sp > END_OF_MEM)
47 sp = (unsigned long *)*sp;
52 void show_regs(struct pt_regs *regs)
56 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
57 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
58 printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
59 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
60 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
61 regs->msr&MSR_IR ? 1 : 0,
62 regs->msr&MSR_DR ? 1 : 0);
65 for (i = 0; i < 32; i++) {
67 printf("GPR%02d: ", i);
70 printf("%08lX ", regs->gpr[i]);
78 static void _exception(int signr, struct pt_regs *regs)
81 print_backtrace((unsigned long *)regs->gpr[1]);
82 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
89 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
90 printf ("PCI: err status %x err mask %x err ctrl %x\n",
91 le32_to_cpu (immap->im_pci.pci_esr),
92 le32_to_cpu (immap->im_pci.pci_emr),
93 le32_to_cpu (immap->im_pci.pci_ecr));
94 printf (" error address %x error data %x ctrl %x\n",
95 le32_to_cpu (immap->im_pci.pci_eacr),
96 le32_to_cpu (immap->im_pci.pci_edcr),
97 le32_to_cpu (immap->im_pci.pci_eccr));
102 void MachineCheckException(struct pt_regs *regs)
106 /* Probing PCI using config cycles cause this exception
107 * when a device is not present. Catch it and return to
108 * the PCI exception handler.
112 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
116 /* clear the error in the error status register */
117 if(immap->im_pci.pci_esr & cpu_to_le32(PCI_ERROR_PCI_NO_RSP)) {
118 immap->im_pci.pci_esr = cpu_to_le32(PCI_ERROR_PCI_NO_RSP);
122 #endif /* CONFIG_PCI */
123 if ((fixup = search_exception_table(regs->nip)) != 0) {
128 #if defined(CONFIG_CMD_KGDB)
129 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
133 puts ("Machine check in kernel mode.\n"
134 "Caused by (from msr): ");
135 printf("regs %p ",regs);
136 switch( regs->msr & 0x000F0000) {
137 case (0x80000000>>12):
138 puts ("Machine check signal - probably due to mm fault\n"
141 case (0x80000000>>13):
142 puts ("Transfer error ack signal\n");
144 case (0x80000000>>14):
145 puts ("Data parity signal\n");
147 case (0x80000000>>15):
148 puts ("Address parity signal\n");
151 puts ("Unknown values in msr\n");
154 print_backtrace((unsigned long *)regs->gpr[1]);
158 panic("machine check");
161 void AlignmentException(struct pt_regs *regs)
163 #if defined(CONFIG_CMD_KGDB)
164 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
168 print_backtrace((unsigned long *)regs->gpr[1]);
169 panic("Alignment Exception");
172 void ProgramCheckException(struct pt_regs *regs)
174 #if defined(CONFIG_CMD_KGDB)
175 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
179 print_backtrace((unsigned long *)regs->gpr[1]);
180 panic("Program Check Exception");
183 void SoftEmuException(struct pt_regs *regs)
185 #if defined(CONFIG_CMD_KGDB)
186 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
190 print_backtrace((unsigned long *)regs->gpr[1]);
191 panic("Software Emulation Exception");
195 void UnknownException(struct pt_regs *regs)
197 #if defined(CONFIG_CMD_KGDB)
198 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
201 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
202 regs->nip, regs->msr, regs->trap);
206 #if defined(CONFIG_CMD_BEDBUG)
207 extern void do_bedbug_breakpoint(struct pt_regs *);
210 void DebugException(struct pt_regs *regs)
212 printf("Debugger trap at @ %lx\n", regs->nip );
214 #if defined(CONFIG_CMD_BEDBUG)
215 do_bedbug_breakpoint( regs );
219 /* Probe an address by reading. If not present, return -1, otherwise
222 int addr_probe(uint *addr)
227 __asm__ __volatile__( \
228 "1: lwz %0,0(%1)\n" \
232 ".section .fixup,\"ax\"\n" \
235 ".section __ex_table,\"a\"\n" \
239 : "=r" (retval) : "r"(addr));