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 | |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 14 | #include <asm/global_data.h> |
Simon Glass | 6b9f010 | 2020-05-10 11:40:06 -0600 | [diff] [blame] | 15 | #include <asm/ptrace.h> |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 16 | #include <command.h> |
Mike Frysinger | 629d88b | 2010-02-08 15:30:16 -0500 | [diff] [blame] | 17 | #include <kgdb.h> |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 18 | #include <asm/processor.h> |
| 19 | #include <asm/mpc8349_pci.h> |
| 20 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 23 | /* Returns 0 if exception not found and fixup otherwise. */ |
| 24 | extern unsigned long search_exception_table(unsigned long); |
| 25 | |
Stefan Roese | a13a2aa | 2020-08-12 13:16:36 +0200 | [diff] [blame] | 26 | #define END_OF_MEM (gd->ram_base + gd->ram_size) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | * Trap & Exception support |
| 30 | */ |
| 31 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 32 | static void print_backtrace(unsigned long *sp) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 33 | { |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 34 | int cnt = 0; |
| 35 | unsigned long i; |
| 36 | |
| 37 | puts ("Call backtrace: "); |
| 38 | while (sp) { |
| 39 | if ((uint)sp > END_OF_MEM) |
| 40 | break; |
| 41 | |
| 42 | i = sp[1]; |
| 43 | if (cnt++ % 7 == 0) |
| 44 | putc ('\n'); |
| 45 | printf("%08lX ", i); |
| 46 | if (cnt > 32) break; |
| 47 | sp = (unsigned long *)*sp; |
| 48 | } |
| 49 | putc ('\n'); |
| 50 | } |
| 51 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 52 | void show_regs(struct pt_regs *regs) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 53 | { |
| 54 | int i; |
| 55 | |
| 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); |
| 63 | |
| 64 | putc ('\n'); |
| 65 | for (i = 0; i < 32; i++) { |
| 66 | if ((i % 8) == 0) { |
| 67 | printf("GPR%02d: ", i); |
| 68 | } |
| 69 | |
| 70 | printf("%08lX ", regs->gpr[i]); |
| 71 | if ((i % 8) == 7) { |
| 72 | putc ('\n'); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 77 | static void _exception(int signr, struct pt_regs *regs) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 78 | { |
| 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 |
| 85 | void dump_pci (void) |
| 86 | { |
| 87 | /* |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 88 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 89 | 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 Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 101 | void MachineCheckException(struct pt_regs *regs) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 102 | { |
| 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-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 111 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 112 | #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 Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 127 | #if defined(CONFIG_CMD_KGDB) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 128 | 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 Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 160 | void AlignmentException(struct pt_regs *regs) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 161 | { |
Jon Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 162 | #if defined(CONFIG_CMD_KGDB) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 163 | 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 Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 171 | void ProgramCheckException(struct pt_regs *regs) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 172 | { |
Jon Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 173 | #if defined(CONFIG_CMD_KGDB) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 174 | 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 Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 182 | void SoftEmuException(struct pt_regs *regs) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 183 | { |
Jon Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 184 | #if defined(CONFIG_CMD_KGDB) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 185 | 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 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 193 | void UnknownException(struct pt_regs *regs) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 194 | { |
Jon Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 195 | #if defined(CONFIG_CMD_KGDB) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 196 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 197 | return; |
| 198 | #endif |
| 199 | printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n", |
| 200 | regs->nip, regs->msr, regs->trap); |
| 201 | _exception(0, regs); |
| 202 | } |
| 203 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 204 | void DebugException(struct pt_regs *regs) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 205 | { |
| 206 | printf("Debugger trap at @ %lx\n", regs->nip ); |
| 207 | show_regs(regs); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 208 | } |