blob: 94e6323d73653980566d2978a01a0b4bafaa5c44 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Eran Liberty9095d4a2005-07-28 10:08:46 -05002/*
Timur Tabiff0215a2006-11-28 12:09:35 -06003 * (C) Copyright 2000
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
6 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
Eran Liberty9095d4a2005-07-28 10:08:46 -05007 */
8
9/*
10 * This file handles the architecture-dependent parts of hardware
11 * exceptions
12 */
13
14#include <common.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Simon Glass6b9f0102020-05-10 11:40:06 -060016#include <asm/ptrace.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050017#include <command.h>
Mike Frysinger629d88b2010-02-08 15:30:16 -050018#include <kgdb.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050019#include <asm/processor.h>
20#include <asm/mpc8349_pci.h>
21
Wolfgang Denk6405a152006-03-31 18:32:53 +020022DECLARE_GLOBAL_DATA_PTR;
23
Eran Liberty9095d4a2005-07-28 10:08:46 -050024/* Returns 0 if exception not found and fixup otherwise. */
25extern unsigned long search_exception_table(unsigned long);
26
Stefan Roesea13a2aa2020-08-12 13:16:36 +020027#define END_OF_MEM (gd->ram_base + gd->ram_size)
Eran Liberty9095d4a2005-07-28 10:08:46 -050028
29/*
30 * Trap & Exception support
31 */
32
Kim Phillipse16737f2012-10-29 13:34:29 +000033static void print_backtrace(unsigned long *sp)
Eran Liberty9095d4a2005-07-28 10:08:46 -050034{
Eran Liberty9095d4a2005-07-28 10:08:46 -050035 int cnt = 0;
36 unsigned long i;
37
38 puts ("Call backtrace: ");
39 while (sp) {
40 if ((uint)sp > END_OF_MEM)
41 break;
42
43 i = sp[1];
44 if (cnt++ % 7 == 0)
45 putc ('\n');
46 printf("%08lX ", i);
47 if (cnt > 32) break;
48 sp = (unsigned long *)*sp;
49 }
50 putc ('\n');
51}
52
Kim Phillipse16737f2012-10-29 13:34:29 +000053void show_regs(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -050054{
55 int i;
56
57 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
58 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
59 printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
60 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
61 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
62 regs->msr&MSR_IR ? 1 : 0,
63 regs->msr&MSR_DR ? 1 : 0);
64
65 putc ('\n');
66 for (i = 0; i < 32; i++) {
67 if ((i % 8) == 0) {
68 printf("GPR%02d: ", i);
69 }
70
71 printf("%08lX ", regs->gpr[i]);
72 if ((i % 8) == 7) {
73 putc ('\n');
74 }
75 }
76}
77
78
Kim Phillipse16737f2012-10-29 13:34:29 +000079static void _exception(int signr, struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -050080{
81 show_regs(regs);
82 print_backtrace((unsigned long *)regs->gpr[1]);
83 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
84}
85
86#ifdef CONFIG_PCI
87void dump_pci (void)
88{
89/*
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020090 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Eran Liberty9095d4a2005-07-28 10:08:46 -050091 printf ("PCI: err status %x err mask %x err ctrl %x\n",
92 le32_to_cpu (immap->im_pci.pci_esr),
93 le32_to_cpu (immap->im_pci.pci_emr),
94 le32_to_cpu (immap->im_pci.pci_ecr));
95 printf (" error address %x error data %x ctrl %x\n",
96 le32_to_cpu (immap->im_pci.pci_eacr),
97 le32_to_cpu (immap->im_pci.pci_edcr),
98 le32_to_cpu (immap->im_pci.pci_eccr));
99*/
100}
101#endif
102
Kim Phillipse16737f2012-10-29 13:34:29 +0000103void MachineCheckException(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500104{
105 unsigned long fixup;
106
107 /* Probing PCI using config cycles cause this exception
108 * when a device is not present. Catch it and return to
109 * the PCI exception handler.
110 */
111#ifdef CONFIG_PCI
112#if 0
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200113 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500114#ifdef DEBUG
115 dump_pci();
116#endif
117 /* clear the error in the error status register */
118 if(immap->im_pci.pci_esr & cpu_to_le32(PCI_ERROR_PCI_NO_RSP)) {
119 immap->im_pci.pci_esr = cpu_to_le32(PCI_ERROR_PCI_NO_RSP);
120 return;
121 }
122#endif
123#endif /* CONFIG_PCI */
124 if ((fixup = search_exception_table(regs->nip)) != 0) {
125 regs->nip = fixup;
126 return;
127 }
128
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500129#if defined(CONFIG_CMD_KGDB)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500130 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
131 return;
132#endif
133
134 puts ("Machine check in kernel mode.\n"
135 "Caused by (from msr): ");
136 printf("regs %p ",regs);
137 switch( regs->msr & 0x000F0000) {
138 case (0x80000000>>12):
139 puts ("Machine check signal - probably due to mm fault\n"
140 "with mmu off\n");
141 break;
142 case (0x80000000>>13):
143 puts ("Transfer error ack signal\n");
144 break;
145 case (0x80000000>>14):
146 puts ("Data parity signal\n");
147 break;
148 case (0x80000000>>15):
149 puts ("Address parity signal\n");
150 break;
151 default:
152 puts ("Unknown values in msr\n");
153 }
154 show_regs(regs);
155 print_backtrace((unsigned long *)regs->gpr[1]);
156#ifdef CONFIG_PCI
157 dump_pci();
158#endif
159 panic("machine check");
160}
161
Kim Phillipse16737f2012-10-29 13:34:29 +0000162void AlignmentException(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500163{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500164#if defined(CONFIG_CMD_KGDB)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500165 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
166 return;
167#endif
168 show_regs(regs);
169 print_backtrace((unsigned long *)regs->gpr[1]);
170 panic("Alignment Exception");
171}
172
Kim Phillipse16737f2012-10-29 13:34:29 +0000173void ProgramCheckException(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500174{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500175#if defined(CONFIG_CMD_KGDB)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500176 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
177 return;
178#endif
179 show_regs(regs);
180 print_backtrace((unsigned long *)regs->gpr[1]);
181 panic("Program Check Exception");
182}
183
Kim Phillipse16737f2012-10-29 13:34:29 +0000184void SoftEmuException(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500185{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500186#if defined(CONFIG_CMD_KGDB)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500187 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
188 return;
189#endif
190 show_regs(regs);
191 print_backtrace((unsigned long *)regs->gpr[1]);
192 panic("Software Emulation Exception");
193}
194
195
Kim Phillipse16737f2012-10-29 13:34:29 +0000196void UnknownException(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500197{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500198#if defined(CONFIG_CMD_KGDB)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500199 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
200 return;
201#endif
202 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
203 regs->nip, regs->msr, regs->trap);
204 _exception(0, regs);
205}
206
Kim Phillipse16737f2012-10-29 13:34:29 +0000207void DebugException(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500208{
209 printf("Debugger trap at @ %lx\n", regs->nip );
210 show_regs(regs);
Eran Liberty9095d4a2005-07-28 10:08:46 -0500211}