Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 2 | /* |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 3 | * (C) Copyright 2000 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 5 | * |
| 6 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * This file handles the architecture-dependent parts of hardware |
| 11 | * exceptions |
| 12 | */ |
| 13 | |
| 14 | #include <common.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Simon Glass | 6b9f010 | 2020-05-10 11:40:06 -0600 | [diff] [blame] | 16 | #include <asm/ptrace.h> |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 17 | #include <command.h> |
Mike Frysinger | 629d88b | 2010-02-08 15:30:16 -0500 | [diff] [blame] | 18 | #include <kgdb.h> |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 19 | #include <asm/processor.h> |
| 20 | #include <asm/mpc8349_pci.h> |
| 21 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 24 | /* Returns 0 if exception not found and fixup otherwise. */ |
| 25 | extern unsigned long search_exception_table(unsigned long); |
| 26 | |
Stefan Roese | a13a2aa | 2020-08-12 13:16:36 +0200 | [diff] [blame] | 27 | #define END_OF_MEM (gd->ram_base + gd->ram_size) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 28 | |
| 29 | /* |
| 30 | * Trap & Exception support |
| 31 | */ |
| 32 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 33 | static void print_backtrace(unsigned long *sp) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 34 | { |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 35 | 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 Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 53 | void show_regs(struct pt_regs *regs) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 54 | { |
| 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 Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 79 | static void _exception(int signr, struct pt_regs *regs) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 80 | { |
| 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 |
| 87 | void dump_pci (void) |
| 88 | { |
| 89 | /* |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 90 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 91 | 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 Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 103 | void MachineCheckException(struct pt_regs *regs) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 104 | { |
| 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-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 113 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 114 | #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 Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 129 | #if defined(CONFIG_CMD_KGDB) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 130 | 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 Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 162 | void AlignmentException(struct pt_regs *regs) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 163 | { |
Jon Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 164 | #if defined(CONFIG_CMD_KGDB) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 165 | 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 Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 173 | void ProgramCheckException(struct pt_regs *regs) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 174 | { |
Jon Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 175 | #if defined(CONFIG_CMD_KGDB) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 176 | 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 Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 184 | void SoftEmuException(struct pt_regs *regs) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 185 | { |
Jon Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 186 | #if defined(CONFIG_CMD_KGDB) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 187 | 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 Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 196 | void UnknownException(struct pt_regs *regs) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 197 | { |
Jon Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 198 | #if defined(CONFIG_CMD_KGDB) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 199 | 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 | |
Jon Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 207 | #if defined(CONFIG_CMD_BEDBUG) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 208 | extern void do_bedbug_breakpoint(struct pt_regs *); |
| 209 | #endif |
| 210 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 211 | void DebugException(struct pt_regs *regs) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 212 | { |
| 213 | printf("Debugger trap at @ %lx\n", regs->nip ); |
| 214 | show_regs(regs); |
Jon Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 215 | #if defined(CONFIG_CMD_BEDBUG) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 216 | do_bedbug_breakpoint( regs ); |
| 217 | #endif |
| 218 | } |