wdenk | 359733b | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/ppc/kernel/traps.c |
| 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> |
| 37 | #include <asm/processor.h> |
| 38 | |
| 39 | #if (CONFIG_COMMANDS & CFG_CMD_KGDB) |
| 40 | int (*debugger_exception_handler)(struct pt_regs *) = 0; |
| 41 | #endif |
| 42 | |
| 43 | #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG) |
| 44 | extern void do_bedbug_breakpoint(struct pt_regs *); |
| 45 | #endif |
| 46 | |
| 47 | /* Returns 0 if exception not found and fixup otherwise. */ |
| 48 | extern unsigned long search_exception_table(unsigned long); |
| 49 | |
| 50 | /* THIS NEEDS CHANGING to use the board info structure. |
| 51 | */ |
| 52 | #define END_OF_MEM 0x0001000 |
| 53 | |
| 54 | |
| 55 | /* |
| 56 | * Print stack backtrace |
| 57 | */ |
| 58 | void print_backtrace(unsigned long *sp) |
| 59 | { |
| 60 | int cnt = 0; |
| 61 | unsigned long i; |
| 62 | |
| 63 | printf("Call backtrace: "); |
| 64 | while (sp) { |
| 65 | if ((uint)sp > END_OF_MEM) |
| 66 | break; |
| 67 | |
| 68 | i = sp[1]; |
| 69 | if (cnt++ % 7 == 0) |
| 70 | printf("\n"); |
| 71 | printf("%08lX ", i); |
| 72 | if (cnt > 32) break; |
| 73 | sp = (unsigned long *)*sp; |
| 74 | } |
| 75 | printf("\n"); |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * Print current registers |
| 80 | */ |
| 81 | void show_regs(struct pt_regs * regs) |
| 82 | { |
| 83 | int i; |
| 84 | printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n", |
| 85 | regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar); |
| 86 | printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n", |
| 87 | regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0, |
| 88 | regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0, |
| 89 | regs->msr&MSR_IR ? 1 : 0, |
| 90 | regs->msr&MSR_DR ? 1 : 0); |
| 91 | |
| 92 | printf("\n"); |
| 93 | for (i = 0; i < 32; i++) { |
| 94 | if ((i % 8) == 0) |
| 95 | { |
| 96 | printf("GPR%02d: ", i); |
| 97 | } |
| 98 | |
| 99 | printf("%08lX ", regs->gpr[i]); |
| 100 | if ((i % 8) == 7) |
| 101 | { |
| 102 | printf("\n"); |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | |
| 108 | /* |
| 109 | * General exception handler routine |
| 110 | */ |
| 111 | void _exception(int signr, struct pt_regs *regs) |
| 112 | { |
| 113 | show_regs(regs); |
| 114 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 115 | panic("Exception in kernel pc %lx signal %d",regs->nip,signr); |
| 116 | } |
| 117 | |
| 118 | /* |
| 119 | * Machine check exception handler routine |
| 120 | */ |
| 121 | void MachineCheckException(struct pt_regs *regs) |
| 122 | { |
| 123 | unsigned long fixup; |
| 124 | |
| 125 | /* Probing PCI using config cycles cause this exception |
| 126 | * when a device is not present. Catch it and return to |
| 127 | * the PCI exception handler. |
| 128 | */ |
| 129 | if ((fixup = search_exception_table(regs->nip)) != 0) { |
| 130 | regs->nip = fixup; |
| 131 | return; |
| 132 | } |
| 133 | |
| 134 | #if (CONFIG_COMMANDS & CFG_CMD_KGDB) |
| 135 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 136 | return; |
| 137 | #endif |
| 138 | |
| 139 | printf("Machine check in kernel mode.\n"); |
| 140 | printf("Caused by (from msr): "); |
| 141 | printf("regs %p ",regs); |
| 142 | switch( regs->msr & 0x0000F000) |
| 143 | { |
| 144 | case (1<<12) : |
| 145 | printf("Machine check signal\n"); |
| 146 | break; |
| 147 | case (1<<13) : |
| 148 | printf("Transfer error ack signal\n"); |
| 149 | break; |
| 150 | case (1<<14) : |
| 151 | printf("Data parity signal\n"); |
| 152 | break; |
| 153 | case (1<<15) : |
| 154 | printf("Address parity signal\n"); |
| 155 | break; |
| 156 | default: |
| 157 | printf("Unknown values in msr\n"); |
| 158 | } |
| 159 | show_regs(regs); |
| 160 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 161 | panic("machine check"); |
| 162 | } |
| 163 | |
| 164 | /* |
| 165 | * Alignment exception handler routine |
| 166 | */ |
| 167 | void AlignmentException(struct pt_regs *regs) |
| 168 | { |
| 169 | #if (CONFIG_COMMANDS & CFG_CMD_KGDB) |
| 170 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 171 | return; |
| 172 | #endif |
| 173 | show_regs(regs); |
| 174 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 175 | panic("Alignment Exception"); |
| 176 | } |
| 177 | |
| 178 | /* |
| 179 | * Program check exception handler routine |
| 180 | */ |
| 181 | void ProgramCheckException(struct pt_regs *regs) |
| 182 | { |
| 183 | #if (CONFIG_COMMANDS & CFG_CMD_KGDB) |
| 184 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 185 | return; |
| 186 | #endif |
| 187 | show_regs(regs); |
| 188 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 189 | panic("Program Check Exception"); |
| 190 | } |
| 191 | |
| 192 | /* |
| 193 | * Software emulation exception handler routine |
| 194 | */ |
| 195 | void SoftEmuException(struct pt_regs *regs) |
| 196 | { |
| 197 | #if (CONFIG_COMMANDS & CFG_CMD_KGDB) |
| 198 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 199 | return; |
| 200 | #endif |
| 201 | show_regs(regs); |
| 202 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 203 | panic("Software Emulation Exception"); |
| 204 | } |
| 205 | |
| 206 | |
| 207 | /* |
| 208 | * Unknown exception handler routine |
| 209 | */ |
| 210 | void UnknownException(struct pt_regs *regs) |
| 211 | { |
| 212 | #if (CONFIG_COMMANDS & CFG_CMD_KGDB) |
| 213 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 214 | return; |
| 215 | #endif |
| 216 | printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n", |
| 217 | regs->nip, regs->msr, regs->trap); |
| 218 | _exception(0, regs); |
| 219 | } |
| 220 | |
| 221 | /* |
| 222 | * Debug exception handler routine |
| 223 | */ |
| 224 | void DebugException(struct pt_regs *regs) |
| 225 | { |
| 226 | printf("Debugger trap at @ %lx\n", regs->nip ); |
| 227 | show_regs(regs); |
| 228 | #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG) |
| 229 | do_bedbug_breakpoint( regs ); |
| 230 | #endif |
| 231 | } |