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