Rafal Jaworowski | 8993e54 | 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 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 8 | * |
| 9 | * Derived from the MPC83xx code. |
| 10 | */ |
| 11 | |
| 12 | /* |
| 13 | * This file handles the architecture-dependent parts of hardware |
| 14 | * exceptions |
| 15 | */ |
| 16 | |
| 17 | #include <common.h> |
Mike Frysinger | e39bf1e | 2010-02-08 15:30:16 -0500 | [diff] [blame] | 18 | #include <kgdb.h> |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 19 | #include <asm/processor.h> |
| 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
| 23 | extern unsigned long search_exception_table(unsigned long); |
| 24 | |
Becky Bruce | 9b124a6 | 2008-05-14 13:09:51 -0500 | [diff] [blame] | 25 | /* |
| 26 | * End of addressable memory. This may be less than the actual |
| 27 | * amount of memory on the system if we're unable to keep all |
| 28 | * the memory mapped in. |
| 29 | */ |
| 30 | extern ulong get_effective_memsize(void); |
| 31 | #define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize()) |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * Trap & Exception support |
| 35 | */ |
| 36 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 37 | static void print_backtrace(unsigned long *sp) |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 38 | { |
| 39 | int cnt = 0; |
| 40 | unsigned long i; |
| 41 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 42 | puts("Call backtrace: "); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 43 | while (sp) { |
| 44 | if ((uint)sp > END_OF_MEM) |
| 45 | break; |
| 46 | |
| 47 | i = sp[1]; |
| 48 | if (cnt++ % 7 == 0) |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 49 | putc('\n'); |
| 50 | printf("%08lX ", i); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 51 | if (cnt > 32) break; |
| 52 | sp = (unsigned long *) *sp; |
| 53 | } |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 54 | putc('\n'); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 55 | } |
| 56 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 57 | void show_regs(struct pt_regs *regs) |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 58 | { |
| 59 | int i; |
| 60 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 61 | printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n", |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 62 | regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar); |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 63 | printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n", |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 64 | regs->msr, regs->msr & MSR_EE ? 1 : 0, regs->msr & MSR_PR ? 1 : 0, |
| 65 | regs->msr & MSR_FP ? 1 : 0,regs->msr & MSR_ME ? 1 : 0, |
| 66 | regs->msr & MSR_IR ? 1 : 0, |
| 67 | regs->msr & MSR_DR ? 1 : 0); |
| 68 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 69 | putc('\n'); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 70 | for (i = 0; i < 32; i++) { |
| 71 | if ((i % 8) == 0) { |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 72 | printf("GPR%02d: ", i); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 73 | } |
| 74 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 75 | printf("%08lX ", regs->gpr[i]); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 76 | if ((i % 8) == 7) { |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 77 | putc('\n'); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 83 | static void _exception(int signr, struct pt_regs *regs) |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 84 | { |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 85 | show_regs(regs); |
| 86 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 87 | panic("Exception at pc %lx signal %d", regs->nip, signr); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 91 | void MachineCheckException(struct pt_regs *regs) |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 92 | { |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 93 | unsigned long fixup = search_exception_table(regs->nip); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 94 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 95 | if (fixup) { |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 96 | regs->nip = fixup; |
| 97 | return; |
| 98 | } |
| 99 | |
Wolfgang Denk | afaac86 | 2007-08-12 14:27:39 +0200 | [diff] [blame] | 100 | #ifdef CONFIG_CMD_KGDB |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 101 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 102 | return; |
| 103 | #endif |
| 104 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 105 | puts("Machine check.\nCaused by (from msr): "); |
| 106 | printf("regs %p ", regs); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 107 | switch (regs->msr & 0x00FF0000) { |
| 108 | case (0x80000000 >> 10): |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 109 | puts("Instruction cache parity signal\n"); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 110 | break; |
| 111 | case (0x80000000 >> 11): |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 112 | puts("Data cache parity signal\n"); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 113 | break; |
| 114 | case (0x80000000 >> 12): |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 115 | puts("Machine check signal\n"); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 116 | break; |
| 117 | case (0x80000000 >> 13): |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 118 | puts("Transfer error ack signal\n"); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 119 | break; |
| 120 | case (0x80000000 >> 14): |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 121 | puts("Data parity signal\n"); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 122 | break; |
| 123 | case (0x80000000 >> 15): |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 124 | puts("Address parity signal\n"); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 125 | break; |
| 126 | default: |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 127 | puts("Unknown values in msr\n"); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 128 | } |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 129 | show_regs(regs); |
| 130 | print_backtrace((unsigned long *)regs->gpr[1]); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 131 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 132 | panic("machine check"); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 133 | } |
| 134 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 135 | void AlignmentException(struct pt_regs *regs) |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 136 | { |
Wolfgang Denk | afaac86 | 2007-08-12 14:27:39 +0200 | [diff] [blame] | 137 | #ifdef CONFIG_CMD_KGDB |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 138 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 139 | return; |
| 140 | #endif |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 141 | show_regs(regs); |
| 142 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 143 | panic("Alignment Exception"); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 144 | } |
| 145 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 146 | void ProgramCheckException(struct pt_regs *regs) |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 147 | { |
Wolfgang Denk | afaac86 | 2007-08-12 14:27:39 +0200 | [diff] [blame] | 148 | #ifdef CONFIG_CMD_KGDB |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 149 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 150 | return; |
| 151 | #endif |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 152 | show_regs(regs); |
| 153 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 154 | panic("Program Check Exception"); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 155 | } |
| 156 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 157 | void SoftEmuException(struct pt_regs *regs) |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 158 | { |
Wolfgang Denk | afaac86 | 2007-08-12 14:27:39 +0200 | [diff] [blame] | 159 | #ifdef CONFIG_CMD_KGDB |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 160 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 161 | return; |
| 162 | #endif |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 163 | show_regs(regs); |
| 164 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 165 | panic("Software Emulation Exception"); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 169 | void UnknownException(struct pt_regs *regs) |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 170 | { |
Wolfgang Denk | afaac86 | 2007-08-12 14:27:39 +0200 | [diff] [blame] | 171 | #ifdef CONFIG_CMD_KGDB |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 172 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 173 | return; |
| 174 | #endif |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 175 | printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n", |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 176 | regs->nip, regs->msr, regs->trap); |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 177 | _exception(0, regs); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 178 | } |
| 179 | |
Wolfgang Denk | afaac86 | 2007-08-12 14:27:39 +0200 | [diff] [blame] | 180 | #ifdef CONFIG_CMD_BEDBUG |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 181 | extern void do_bedbug_breakpoint(struct pt_regs *); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 182 | #endif |
| 183 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 184 | void DebugException(struct pt_regs *regs) |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 185 | { |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 186 | printf("Debugger trap at @ %lx\n", regs->nip); |
| 187 | show_regs(regs); |
Wolfgang Denk | afaac86 | 2007-08-12 14:27:39 +0200 | [diff] [blame] | 188 | #ifdef CONFIG_CMD_BEDBUG |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 189 | do_bedbug_breakpoint(regs); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 190 | #endif |
| 191 | } |