blob: 1c6c38b15f11ea26aa4bf66143c746dd8d693569 [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>
15#include <command.h>
Mike Frysinger629d88b2010-02-08 15:30:16 -050016#include <kgdb.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050017#include <asm/processor.h>
18#include <asm/mpc8349_pci.h>
19
Wolfgang Denk6405a152006-03-31 18:32:53 +020020DECLARE_GLOBAL_DATA_PTR;
21
Eran Liberty9095d4a2005-07-28 10:08:46 -050022/* Returns 0 if exception not found and fixup otherwise. */
23extern unsigned long search_exception_table(unsigned long);
24
25#define END_OF_MEM (gd->bd->bi_memstart + gd->bd->bi_memsize)
26
27/*
28 * Trap & Exception support
29 */
30
Kim Phillipse16737f2012-10-29 13:34:29 +000031static void print_backtrace(unsigned long *sp)
Eran Liberty9095d4a2005-07-28 10:08:46 -050032{
Eran Liberty9095d4a2005-07-28 10:08:46 -050033 int cnt = 0;
34 unsigned long i;
35
36 puts ("Call backtrace: ");
37 while (sp) {
38 if ((uint)sp > END_OF_MEM)
39 break;
40
41 i = sp[1];
42 if (cnt++ % 7 == 0)
43 putc ('\n');
44 printf("%08lX ", i);
45 if (cnt > 32) break;
46 sp = (unsigned long *)*sp;
47 }
48 putc ('\n');
49}
50
Kim Phillipse16737f2012-10-29 13:34:29 +000051void show_regs(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -050052{
53 int i;
54
55 printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n",
56 regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar);
57 printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
58 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
59 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
60 regs->msr&MSR_IR ? 1 : 0,
61 regs->msr&MSR_DR ? 1 : 0);
62
63 putc ('\n');
64 for (i = 0; i < 32; i++) {
65 if ((i % 8) == 0) {
66 printf("GPR%02d: ", i);
67 }
68
69 printf("%08lX ", regs->gpr[i]);
70 if ((i % 8) == 7) {
71 putc ('\n');
72 }
73 }
74}
75
76
Kim Phillipse16737f2012-10-29 13:34:29 +000077static void _exception(int signr, struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -050078{
79 show_regs(regs);
80 print_backtrace((unsigned long *)regs->gpr[1]);
81 panic("Exception in kernel pc %lx signal %d",regs->nip,signr);
82}
83
84#ifdef CONFIG_PCI
85void dump_pci (void)
86{
87/*
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020088 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Eran Liberty9095d4a2005-07-28 10:08:46 -050089 printf ("PCI: err status %x err mask %x err ctrl %x\n",
90 le32_to_cpu (immap->im_pci.pci_esr),
91 le32_to_cpu (immap->im_pci.pci_emr),
92 le32_to_cpu (immap->im_pci.pci_ecr));
93 printf (" error address %x error data %x ctrl %x\n",
94 le32_to_cpu (immap->im_pci.pci_eacr),
95 le32_to_cpu (immap->im_pci.pci_edcr),
96 le32_to_cpu (immap->im_pci.pci_eccr));
97*/
98}
99#endif
100
Kim Phillipse16737f2012-10-29 13:34:29 +0000101void MachineCheckException(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500102{
103 unsigned long fixup;
104
105 /* Probing PCI using config cycles cause this exception
106 * when a device is not present. Catch it and return to
107 * the PCI exception handler.
108 */
109#ifdef CONFIG_PCI
110#if 0
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200111 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500112#ifdef DEBUG
113 dump_pci();
114#endif
115 /* clear the error in the error status register */
116 if(immap->im_pci.pci_esr & cpu_to_le32(PCI_ERROR_PCI_NO_RSP)) {
117 immap->im_pci.pci_esr = cpu_to_le32(PCI_ERROR_PCI_NO_RSP);
118 return;
119 }
120#endif
121#endif /* CONFIG_PCI */
122 if ((fixup = search_exception_table(regs->nip)) != 0) {
123 regs->nip = fixup;
124 return;
125 }
126
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500127#if defined(CONFIG_CMD_KGDB)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500128 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
129 return;
130#endif
131
132 puts ("Machine check in kernel mode.\n"
133 "Caused by (from msr): ");
134 printf("regs %p ",regs);
135 switch( regs->msr & 0x000F0000) {
136 case (0x80000000>>12):
137 puts ("Machine check signal - probably due to mm fault\n"
138 "with mmu off\n");
139 break;
140 case (0x80000000>>13):
141 puts ("Transfer error ack signal\n");
142 break;
143 case (0x80000000>>14):
144 puts ("Data parity signal\n");
145 break;
146 case (0x80000000>>15):
147 puts ("Address parity signal\n");
148 break;
149 default:
150 puts ("Unknown values in msr\n");
151 }
152 show_regs(regs);
153 print_backtrace((unsigned long *)regs->gpr[1]);
154#ifdef CONFIG_PCI
155 dump_pci();
156#endif
157 panic("machine check");
158}
159
Kim Phillipse16737f2012-10-29 13:34:29 +0000160void AlignmentException(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500161{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500162#if defined(CONFIG_CMD_KGDB)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500163 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
164 return;
165#endif
166 show_regs(regs);
167 print_backtrace((unsigned long *)regs->gpr[1]);
168 panic("Alignment Exception");
169}
170
Kim Phillipse16737f2012-10-29 13:34:29 +0000171void ProgramCheckException(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500172{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500173#if defined(CONFIG_CMD_KGDB)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500174 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
175 return;
176#endif
177 show_regs(regs);
178 print_backtrace((unsigned long *)regs->gpr[1]);
179 panic("Program Check Exception");
180}
181
Kim Phillipse16737f2012-10-29 13:34:29 +0000182void SoftEmuException(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500183{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500184#if defined(CONFIG_CMD_KGDB)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500185 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
186 return;
187#endif
188 show_regs(regs);
189 print_backtrace((unsigned long *)regs->gpr[1]);
190 panic("Software Emulation Exception");
191}
192
193
Kim Phillipse16737f2012-10-29 13:34:29 +0000194void UnknownException(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500195{
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500196#if defined(CONFIG_CMD_KGDB)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500197 if (debugger_exception_handler && (*debugger_exception_handler)(regs))
198 return;
199#endif
200 printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
201 regs->nip, regs->msr, regs->trap);
202 _exception(0, regs);
203}
204
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500205#if defined(CONFIG_CMD_BEDBUG)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500206extern void do_bedbug_breakpoint(struct pt_regs *);
207#endif
208
Kim Phillipse16737f2012-10-29 13:34:29 +0000209void DebugException(struct pt_regs *regs)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500210{
211 printf("Debugger trap at @ %lx\n", regs->nip );
212 show_regs(regs);
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500213#if defined(CONFIG_CMD_BEDBUG)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500214 do_bedbug_breakpoint( regs );
215#endif
216}