blob: cbcf5336467ec53eeeac29976e3df7aa4a4867af [file] [log] [blame]
wdenkaffae2b2002-08-17 09:36:01 +00001/*
Stefan Roese88fbf932010-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 Denkd79de1d2013-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 <command.h>
Mike Frysinger629d88b2010-02-08 15:30:16 -050021#include <kgdb.h>
wdenkaffae2b2002-08-17 09:36:01 +000022#include <asm/processor.h>
wdenk56ed43e2004-02-22 23:46:08 +000023#include <asm/m8260_pci.h>
wdenkaffae2b2002-08-17 09:36:01 +000024
wdenkaffae2b2002-08-17 09:36:01 +000025/* Returns 0 if exception not found and fixup otherwise. */
26extern 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
Kim Phillipse16737f2012-10-29 13:34:29 +000036static void print_backtrace(unsigned long *sp)
wdenkaffae2b2002-08-17 09:36:01 +000037{
38 int cnt = 0;
39 unsigned long i;
40
wdenk42c05472004-03-23 22:14:11 +000041 puts ("Call backtrace: ");
wdenkaffae2b2002-08-17 09:36:01 +000042 while (sp) {
43 if ((uint)sp > END_OF_MEM)
44 break;
45
46 i = sp[1];
47 if (cnt++ % 7 == 0)
wdenk42c05472004-03-23 22:14:11 +000048 putc ('\n');
wdenkaffae2b2002-08-17 09:36:01 +000049 printf("%08lX ", i);
50 if (cnt > 32) break;
51 sp = (unsigned long *)*sp;
52 }
wdenk42c05472004-03-23 22:14:11 +000053 putc ('\n');
wdenkaffae2b2002-08-17 09:36:01 +000054}
55
Kim Phillipse16737f2012-10-29 13:34:29 +000056void show_regs(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +000057{
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
wdenk42c05472004-03-23 22:14:11 +000068 putc ('\n');
wdenkaffae2b2002-08-17 09:36:01 +000069 for (i = 0; i < 32; i++) {
wdenk56ed43e2004-02-22 23:46:08 +000070 if ((i % 8) == 0) {
wdenkaffae2b2002-08-17 09:36:01 +000071 printf("GPR%02d: ", i);
72 }
73
74 printf("%08lX ", regs->gpr[i]);
wdenk56ed43e2004-02-22 23:46:08 +000075 if ((i % 8) == 7) {
wdenk42c05472004-03-23 22:14:11 +000076 putc ('\n');
wdenkaffae2b2002-08-17 09:36:01 +000077 }
78 }
79}
80
81
Kim Phillipse16737f2012-10-29 13:34:29 +000082static void _exception(int signr, struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +000083{
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
wdenk56ed43e2004-02-22 23:46:08 +000089#ifdef CONFIG_PCI
90void dump_pci (void)
91{
92
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020093 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenk56ed43e2004-02-22 23:46:08 +000094
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
Kim Phillipse16737f2012-10-29 13:34:29 +0000107void MachineCheckException(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +0000108{
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 */
wdenk56ed43e2004-02-22 23:46:08 +0000115#ifdef CONFIG_PCI
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200116 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
wdenk56ed43e2004-02-22 23:46:08 +0000117#ifdef DEBUG
118 dump_pci();
119#endif
120 /* clear the error in the error status register */
wdenkeec9a3d2004-03-23 23:20:24 +0000121 if(immap->im_pci.pci_esr & cpu_to_le32(PCI_ERROR_PCI_NO_RSP)) {
wdenk56ed43e2004-02-22 23:46:08 +0000122 immap->im_pci.pci_esr = cpu_to_le32(PCI_ERROR_PCI_NO_RSP);
123 return;
124 }
125#endif
wdenkaffae2b2002-08-17 09:36:01 +0000126 if ((fixup = search_exception_table(regs->nip)) != 0) {
127 regs->nip = fixup;
128 return;
129 }
130
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500131#if defined(CONFIG_CMD_KGDB)
wdenkaffae2b2002-08-17 09:36:01 +0000132 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
133 return;
134#endif
135
wdenk42c05472004-03-23 22:14:11 +0000136 puts ("Machine check in kernel mode.\n"
137 "Caused by (from msr): ");
wdenkaffae2b2002-08-17 09:36:01 +0000138 printf("regs %p ",regs);
wdenke97d3d92004-02-23 22:22:28 +0000139 switch( regs->msr & 0x000F0000) {
140 case (0x80000000>>12):
wdenk42c05472004-03-23 22:14:11 +0000141 puts ("Machine check signal - probably due to mm fault\n"
wdenkaffae2b2002-08-17 09:36:01 +0000142 "with mmu off\n");
143 break;
wdenke97d3d92004-02-23 22:22:28 +0000144 case (0x80000000>>13):
wdenk42c05472004-03-23 22:14:11 +0000145 puts ("Transfer error ack signal\n");
wdenkaffae2b2002-08-17 09:36:01 +0000146 break;
wdenke97d3d92004-02-23 22:22:28 +0000147 case (0x80000000>>14):
wdenk42c05472004-03-23 22:14:11 +0000148 puts ("Data parity signal\n");
wdenkaffae2b2002-08-17 09:36:01 +0000149 break;
wdenke97d3d92004-02-23 22:22:28 +0000150 case (0x80000000>>15):
wdenk42c05472004-03-23 22:14:11 +0000151 puts ("Address parity signal\n");
wdenkaffae2b2002-08-17 09:36:01 +0000152 break;
153 default:
wdenk42c05472004-03-23 22:14:11 +0000154 puts ("Unknown values in msr\n");
wdenkaffae2b2002-08-17 09:36:01 +0000155 }
156 show_regs(regs);
157 print_backtrace((unsigned long *)regs->gpr[1]);
wdenk56ed43e2004-02-22 23:46:08 +0000158#ifdef CONFIG_PCI
159 dump_pci();
160#endif
wdenkaffae2b2002-08-17 09:36:01 +0000161 panic("machine check");
162}
163
Kim Phillipse16737f2012-10-29 13:34:29 +0000164void AlignmentException(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +0000165{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500166#if defined(CONFIG_CMD_KGDB)
wdenkaffae2b2002-08-17 09:36:01 +0000167 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
Kim Phillipse16737f2012-10-29 13:34:29 +0000175void ProgramCheckException(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +0000176{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500177#if defined(CONFIG_CMD_KGDB)
wdenkaffae2b2002-08-17 09:36:01 +0000178 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
Kim Phillipse16737f2012-10-29 13:34:29 +0000186void SoftEmuException(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +0000187{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500188#if defined(CONFIG_CMD_KGDB)
wdenkaffae2b2002-08-17 09:36:01 +0000189 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
Kim Phillipse16737f2012-10-29 13:34:29 +0000198void UnknownException(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +0000199{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500200#if defined(CONFIG_CMD_KGDB)
wdenkaffae2b2002-08-17 09:36:01 +0000201 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
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500209#if defined(CONFIG_CMD_BEDBUG)
wdenkaffae2b2002-08-17 09:36:01 +0000210extern void do_bedbug_breakpoint(struct pt_regs *);
211#endif
212
Kim Phillipse16737f2012-10-29 13:34:29 +0000213void DebugException(struct pt_regs *regs)
wdenkaffae2b2002-08-17 09:36:01 +0000214{
215
216 printf("Debugger trap at @ %lx\n", regs->nip );
217 show_regs(regs);
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500218#if defined(CONFIG_CMD_BEDBUG)
wdenkaffae2b2002-08-17 09:36:01 +0000219 do_bedbug_breakpoint( regs );
220#endif
221}
222
223/* Probe an address by reading. If not present, return -1, otherwise
224 * return 0.
225 */
Kim Phillipse16737f2012-10-29 13:34:29 +0000226int addr_probe(uint *addr)
wdenkaffae2b2002-08-17 09:36:01 +0000227{
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}