wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 1 | /* |
Stefan Roese | a47a12b | 2010-04-15 16:07:28 +0200 | [diff] [blame] | 2 | * linux/arch/powerpc/kernel/traps.c |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
| 5 | * |
| 6 | * Modified by Cort Dougan (cort@cs.nmt.edu) |
| 7 | * and Paul Mackerras (paulus@cs.anu.edu.au) |
wdenk | 63e73c9 | 2004-02-23 22:22:28 +0000 | [diff] [blame] | 8 | * fixed Machine Check Reasons by Reinhard Meyer (r.meyer@emk-elektronik.de) |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 9 | * |
| 10 | * (C) Copyright 2000-2003 |
| 11 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 12 | * |
| 13 | * See file CREDITS for list of people who contributed to this |
| 14 | * project. |
| 15 | * |
| 16 | * This program is free software; you can redistribute it and/or |
| 17 | * modify it under the terms of the GNU General Public License as |
| 18 | * published by the Free Software Foundation; either version 2 of |
| 19 | * the License, or (at your option) any later version. |
| 20 | * |
| 21 | * This program is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | * GNU General Public License for more details. |
| 25 | * |
| 26 | * You should have received a copy of the GNU General Public License |
| 27 | * along with this program; if not, write to the Free Software |
| 28 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 29 | * MA 02111-1307 USA |
| 30 | */ |
| 31 | |
| 32 | /* |
| 33 | * This file handles the architecture-dependent parts of hardware exceptions |
| 34 | */ |
| 35 | |
| 36 | #include <common.h> |
| 37 | #include <command.h> |
Mike Frysinger | e39bf1e | 2010-02-08 15:30:16 -0500 | [diff] [blame] | 38 | #include <kgdb.h> |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 39 | #include <asm/processor.h> |
| 40 | |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 41 | /* Returns 0 if exception not found and fixup otherwise. */ |
| 42 | extern unsigned long search_exception_table(unsigned long); |
| 43 | |
| 44 | /* THIS NEEDS CHANGING to use the board info structure. |
| 45 | */ |
| 46 | #define END_OF_MEM 0x02000000 |
| 47 | |
| 48 | /* |
| 49 | * Trap & Exception support |
| 50 | */ |
| 51 | |
| 52 | void |
| 53 | print_backtrace(unsigned long *sp) |
| 54 | { |
| 55 | int cnt = 0; |
| 56 | unsigned long i; |
| 57 | |
| 58 | printf("Call backtrace: "); |
| 59 | while (sp) { |
| 60 | if ((uint)sp > END_OF_MEM) |
| 61 | break; |
| 62 | |
| 63 | i = sp[1]; |
| 64 | if (cnt++ % 7 == 0) |
| 65 | printf("\n"); |
| 66 | printf("%08lX ", i); |
| 67 | if (cnt > 32) break; |
| 68 | sp = (unsigned long *)*sp; |
| 69 | } |
| 70 | printf("\n"); |
| 71 | } |
| 72 | |
| 73 | void show_regs(struct pt_regs * regs) |
| 74 | { |
| 75 | int i; |
| 76 | |
| 77 | printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n", |
| 78 | regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar); |
| 79 | printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n", |
| 80 | regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0, |
| 81 | regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0, |
| 82 | regs->msr&MSR_IR ? 1 : 0, |
| 83 | regs->msr&MSR_DR ? 1 : 0); |
| 84 | |
| 85 | printf("\n"); |
| 86 | for (i = 0; i < 32; i++) { |
| 87 | if ((i % 8) == 0) |
| 88 | { |
| 89 | printf("GPR%02d: ", i); |
| 90 | } |
| 91 | |
| 92 | printf("%08lX ", regs->gpr[i]); |
| 93 | if ((i % 8) == 7) |
| 94 | { |
| 95 | printf("\n"); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | |
| 101 | void |
| 102 | _exception(int signr, struct pt_regs *regs) |
| 103 | { |
| 104 | show_regs(regs); |
| 105 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 106 | panic("Exception in kernel pc %lx signal %d",regs->nip,signr); |
| 107 | } |
| 108 | |
| 109 | void |
| 110 | MachineCheckException(struct pt_regs *regs) |
| 111 | { |
| 112 | unsigned long fixup; |
| 113 | |
| 114 | /* Probing PCI using config cycles cause this exception |
| 115 | * when a device is not present. Catch it and return to |
| 116 | * the PCI exception handler. |
| 117 | */ |
| 118 | if ((fixup = search_exception_table(regs->nip)) != 0) { |
| 119 | regs->nip = fixup; |
| 120 | return; |
| 121 | } |
| 122 | |
Jon Loeliger | 4431283 | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 123 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 124 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 125 | return; |
| 126 | #endif |
| 127 | |
| 128 | printf("Machine check in kernel mode.\n"); |
| 129 | printf("Caused by (from msr): "); |
| 130 | printf("regs %p ",regs); |
wdenk | 63e73c9 | 2004-02-23 22:22:28 +0000 | [diff] [blame] | 131 | /* refer to 603e Manual (MPC603EUM/AD), chapter 4.5.2.1 */ |
| 132 | switch( regs->msr & 0x000F0000) |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 133 | { |
wdenk | 63e73c9 | 2004-02-23 22:22:28 +0000 | [diff] [blame] | 134 | case (0x80000000>>12) : |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 135 | printf("Machine check signal - probably due to mm fault\n" |
| 136 | "with mmu off\n"); |
| 137 | break; |
wdenk | 63e73c9 | 2004-02-23 22:22:28 +0000 | [diff] [blame] | 138 | case (0x80000000>>13) : |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 139 | printf("Transfer error ack signal\n"); |
| 140 | break; |
wdenk | 63e73c9 | 2004-02-23 22:22:28 +0000 | [diff] [blame] | 141 | case (0x80000000>>14) : |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 142 | printf("Data parity signal\n"); |
| 143 | break; |
wdenk | 63e73c9 | 2004-02-23 22:22:28 +0000 | [diff] [blame] | 144 | case (0x80000000>>15) : |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 145 | printf("Address parity signal\n"); |
| 146 | break; |
| 147 | default: |
| 148 | printf("Unknown values in msr\n"); |
| 149 | } |
| 150 | show_regs(regs); |
| 151 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 152 | panic("machine check"); |
| 153 | } |
| 154 | |
| 155 | void |
| 156 | AlignmentException(struct pt_regs *regs) |
| 157 | { |
Jon Loeliger | 4431283 | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 158 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 159 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 160 | return; |
| 161 | #endif |
| 162 | show_regs(regs); |
| 163 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 164 | panic("Alignment Exception"); |
| 165 | } |
| 166 | |
| 167 | void |
| 168 | ProgramCheckException(struct pt_regs *regs) |
| 169 | { |
Jon Loeliger | 4431283 | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 170 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 171 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 172 | return; |
| 173 | #endif |
| 174 | show_regs(regs); |
| 175 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 176 | panic("Program Check Exception"); |
| 177 | } |
| 178 | |
| 179 | void |
| 180 | SoftEmuException(struct pt_regs *regs) |
| 181 | { |
Jon Loeliger | 4431283 | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 182 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 183 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 184 | return; |
| 185 | #endif |
| 186 | show_regs(regs); |
| 187 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 188 | panic("Software Emulation Exception"); |
| 189 | } |
| 190 | |
| 191 | |
| 192 | void |
| 193 | UnknownException(struct pt_regs *regs) |
| 194 | { |
Jon Loeliger | 4431283 | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 195 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [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 | |
Jon Loeliger | 4431283 | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 204 | #if defined(CONFIG_CMD_BEDBUG) |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 205 | extern void do_bedbug_breakpoint(struct pt_regs *); |
| 206 | #endif |
| 207 | |
| 208 | void |
| 209 | DebugException(struct pt_regs *regs) |
| 210 | { |
| 211 | |
| 212 | printf("Debugger trap at @ %lx\n", regs->nip ); |
| 213 | show_regs(regs); |
Jon Loeliger | 4431283 | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 214 | #if defined(CONFIG_CMD_BEDBUG) |
wdenk | 945af8d | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 215 | do_bedbug_breakpoint( regs ); |
| 216 | #endif |
| 217 | } |
| 218 | |
| 219 | /* Probe an address by reading. If not present, return -1, otherwise |
| 220 | * return 0. |
| 221 | */ |
| 222 | int |
| 223 | addr_probe(uint *addr) |
| 224 | { |
| 225 | #if 0 |
| 226 | int retval; |
| 227 | |
| 228 | __asm__ __volatile__( \ |
| 229 | "1: lwz %0,0(%1)\n" \ |
| 230 | " eieio\n" \ |
| 231 | " li %0,0\n" \ |
| 232 | "2:\n" \ |
| 233 | ".section .fixup,\"ax\"\n" \ |
| 234 | "3: li %0,-1\n" \ |
| 235 | " b 2b\n" \ |
| 236 | ".section __ex_table,\"a\"\n" \ |
| 237 | " .align 2\n" \ |
| 238 | " .long 1b,3b\n" \ |
| 239 | ".text" \ |
| 240 | : "=r" (retval) : "r"(addr)); |
| 241 | |
| 242 | return (retval); |
| 243 | #endif |
| 244 | return 0; |
| 245 | } |