Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000 - 2007 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; either version 2 of |
| 10 | * the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 20 | * MA 02111-1307 USA |
| 21 | * |
| 22 | * Derived from the MPC83xx code. |
| 23 | */ |
| 24 | |
| 25 | /* |
| 26 | * This file handles the architecture-dependent parts of hardware |
| 27 | * exceptions |
| 28 | */ |
| 29 | |
| 30 | #include <common.h> |
Mike Frysinger | 629d88b | 2010-02-08 15:30:16 -0500 | [diff] [blame] | 31 | #include <kgdb.h> |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 32 | #include <asm/processor.h> |
| 33 | |
| 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
| 36 | extern unsigned long search_exception_table(unsigned long); |
| 37 | |
Becky Bruce | f095f5f | 2008-05-14 13:09:51 -0500 | [diff] [blame] | 38 | /* |
| 39 | * End of addressable memory. This may be less than the actual |
| 40 | * amount of memory on the system if we're unable to keep all |
| 41 | * the memory mapped in. |
| 42 | */ |
| 43 | extern ulong get_effective_memsize(void); |
| 44 | #define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize()) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 45 | |
| 46 | /* |
| 47 | * Trap & Exception support |
| 48 | */ |
| 49 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 50 | static void print_backtrace(unsigned long *sp) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 51 | { |
| 52 | int cnt = 0; |
| 53 | unsigned long i; |
| 54 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 55 | puts("Call backtrace: "); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 56 | while (sp) { |
| 57 | if ((uint)sp > END_OF_MEM) |
| 58 | break; |
| 59 | |
| 60 | i = sp[1]; |
| 61 | if (cnt++ % 7 == 0) |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 62 | putc('\n'); |
| 63 | printf("%08lX ", i); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 64 | if (cnt > 32) break; |
| 65 | sp = (unsigned long *) *sp; |
| 66 | } |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 67 | putc('\n'); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 68 | } |
| 69 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 70 | void show_regs(struct pt_regs *regs) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 71 | { |
| 72 | int i; |
| 73 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 74 | printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n", |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 75 | regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar); |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 76 | printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n", |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 77 | regs->msr, regs->msr & MSR_EE ? 1 : 0, regs->msr & MSR_PR ? 1 : 0, |
| 78 | regs->msr & MSR_FP ? 1 : 0,regs->msr & MSR_ME ? 1 : 0, |
| 79 | regs->msr & MSR_IR ? 1 : 0, |
| 80 | regs->msr & MSR_DR ? 1 : 0); |
| 81 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 82 | putc('\n'); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 83 | for (i = 0; i < 32; i++) { |
| 84 | if ((i % 8) == 0) { |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 85 | printf("GPR%02d: ", i); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 86 | } |
| 87 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 88 | printf("%08lX ", regs->gpr[i]); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 89 | if ((i % 8) == 7) { |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 90 | putc('\n'); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 96 | static void _exception(int signr, struct pt_regs *regs) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 97 | { |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 98 | show_regs(regs); |
| 99 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 100 | panic("Exception at pc %lx signal %d", regs->nip, signr); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 104 | void MachineCheckException(struct pt_regs *regs) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 105 | { |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 106 | unsigned long fixup = search_exception_table(regs->nip); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 107 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 108 | if (fixup) { |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 109 | regs->nip = fixup; |
| 110 | return; |
| 111 | } |
| 112 | |
Wolfgang Denk | 56cbd02 | 2007-08-12 14:27:39 +0200 | [diff] [blame] | 113 | #ifdef CONFIG_CMD_KGDB |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 114 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 115 | return; |
| 116 | #endif |
| 117 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 118 | puts("Machine check.\nCaused by (from msr): "); |
| 119 | printf("regs %p ", regs); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 120 | switch (regs->msr & 0x00FF0000) { |
| 121 | case (0x80000000 >> 10): |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 122 | puts("Instruction cache parity signal\n"); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 123 | break; |
| 124 | case (0x80000000 >> 11): |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 125 | puts("Data cache parity signal\n"); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 126 | break; |
| 127 | case (0x80000000 >> 12): |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 128 | puts("Machine check signal\n"); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 129 | break; |
| 130 | case (0x80000000 >> 13): |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 131 | puts("Transfer error ack signal\n"); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 132 | break; |
| 133 | case (0x80000000 >> 14): |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 134 | puts("Data parity signal\n"); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 135 | break; |
| 136 | case (0x80000000 >> 15): |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 137 | puts("Address parity signal\n"); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 138 | break; |
| 139 | default: |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 140 | puts("Unknown values in msr\n"); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 141 | } |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 142 | show_regs(regs); |
| 143 | print_backtrace((unsigned long *)regs->gpr[1]); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 144 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 145 | panic("machine check"); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 146 | } |
| 147 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 148 | void AlignmentException(struct pt_regs *regs) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 149 | { |
Wolfgang Denk | 56cbd02 | 2007-08-12 14:27:39 +0200 | [diff] [blame] | 150 | #ifdef CONFIG_CMD_KGDB |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 151 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 152 | return; |
| 153 | #endif |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 154 | show_regs(regs); |
| 155 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 156 | panic("Alignment Exception"); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 157 | } |
| 158 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 159 | void ProgramCheckException(struct pt_regs *regs) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 160 | { |
Wolfgang Denk | 56cbd02 | 2007-08-12 14:27:39 +0200 | [diff] [blame] | 161 | #ifdef CONFIG_CMD_KGDB |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 162 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 163 | return; |
| 164 | #endif |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 165 | show_regs(regs); |
| 166 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 167 | panic("Program Check Exception"); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 168 | } |
| 169 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 170 | void SoftEmuException(struct pt_regs *regs) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 171 | { |
Wolfgang Denk | 56cbd02 | 2007-08-12 14:27:39 +0200 | [diff] [blame] | 172 | #ifdef CONFIG_CMD_KGDB |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 173 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 174 | return; |
| 175 | #endif |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 176 | show_regs(regs); |
| 177 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 178 | panic("Software Emulation Exception"); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 182 | void UnknownException(struct pt_regs *regs) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 183 | { |
Wolfgang Denk | 56cbd02 | 2007-08-12 14:27:39 +0200 | [diff] [blame] | 184 | #ifdef CONFIG_CMD_KGDB |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 185 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 186 | return; |
| 187 | #endif |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 188 | printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n", |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 189 | regs->nip, regs->msr, regs->trap); |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 190 | _exception(0, regs); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 191 | } |
| 192 | |
Wolfgang Denk | 56cbd02 | 2007-08-12 14:27:39 +0200 | [diff] [blame] | 193 | #ifdef CONFIG_CMD_BEDBUG |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 194 | extern void do_bedbug_breakpoint(struct pt_regs *); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 195 | #endif |
| 196 | |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 197 | void DebugException(struct pt_regs *regs) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 198 | { |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 199 | printf("Debugger trap at @ %lx\n", regs->nip); |
| 200 | show_regs(regs); |
Wolfgang Denk | 56cbd02 | 2007-08-12 14:27:39 +0200 | [diff] [blame] | 201 | #ifdef CONFIG_CMD_BEDBUG |
Kim Phillips | e16737f | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 202 | do_bedbug_breakpoint(regs); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 203 | #endif |
| 204 | } |