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