wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/ppc/kernel/traps.c |
| 3 | * |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 4 | * Copyright 2007 Freescale Semiconductor. |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 5 | * Copyright (C) 2003 Motorola |
| 6 | * Modified by Xianghua Xiao(x.xiao@motorola.com) |
| 7 | * |
| 8 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
| 9 | * |
| 10 | * Modified by Cort Dougan (cort@cs.nmt.edu) |
| 11 | * and Paul Mackerras (paulus@cs.anu.edu.au) |
| 12 | * |
| 13 | * (C) Copyright 2000 |
| 14 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 15 | * |
| 16 | * See file CREDITS for list of people who contributed to this |
| 17 | * project. |
| 18 | * |
| 19 | * This program is free software; you can redistribute it and/or |
| 20 | * modify it under the terms of the GNU General Public License as |
| 21 | * published by the Free Software Foundation; either version 2 of |
| 22 | * the License, or (at your option) any later version. |
| 23 | * |
| 24 | * This program is distributed in the hope that it will be useful, |
| 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 27 | * GNU General Public License for more details. |
| 28 | * |
| 29 | * You should have received a copy of the GNU General Public License |
| 30 | * along with this program; if not, write to the Free Software |
| 31 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 32 | * MA 02111-1307 USA |
| 33 | */ |
| 34 | |
| 35 | /* |
| 36 | * This file handles the architecture-dependent parts of hardware exceptions |
| 37 | */ |
| 38 | |
| 39 | #include <common.h> |
| 40 | #include <command.h> |
| 41 | #include <asm/processor.h> |
| 42 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 43 | DECLARE_GLOBAL_DATA_PTR; |
| 44 | |
Jon Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 45 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 46 | int (*debugger_exception_handler)(struct pt_regs *) = 0; |
| 47 | #endif |
| 48 | |
| 49 | /* Returns 0 if exception not found and fixup otherwise. */ |
| 50 | extern unsigned long search_exception_table(unsigned long); |
| 51 | |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 52 | /* |
| 53 | * End of memory as shown by board info and determined by DDR setup. |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 54 | */ |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 55 | #define END_OF_MEM (gd->bd->bi_memstart + gd->bd->bi_memsize) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 56 | |
| 57 | |
| 58 | static __inline__ void set_tsr(unsigned long val) |
| 59 | { |
| 60 | asm volatile("mtspr 0x150, %0" : : "r" (val)); |
| 61 | } |
| 62 | |
| 63 | static __inline__ unsigned long get_esr(void) |
| 64 | { |
| 65 | unsigned long val; |
| 66 | asm volatile("mfspr %0, 0x03e" : "=r" (val) :); |
| 67 | return val; |
| 68 | } |
| 69 | |
| 70 | #define ESR_MCI 0x80000000 |
| 71 | #define ESR_PIL 0x08000000 |
| 72 | #define ESR_PPR 0x04000000 |
| 73 | #define ESR_PTR 0x02000000 |
| 74 | #define ESR_DST 0x00800000 |
| 75 | #define ESR_DIZ 0x00400000 |
| 76 | #define ESR_U0F 0x00008000 |
| 77 | |
Jon Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 78 | #if defined(CONFIG_CMD_BEDBUG) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 79 | extern void do_bedbug_breakpoint(struct pt_regs *); |
| 80 | #endif |
| 81 | |
| 82 | /* |
| 83 | * Trap & Exception support |
| 84 | */ |
| 85 | |
| 86 | void |
| 87 | print_backtrace(unsigned long *sp) |
| 88 | { |
| 89 | int cnt = 0; |
| 90 | unsigned long i; |
| 91 | |
| 92 | printf("Call backtrace: "); |
| 93 | while (sp) { |
| 94 | if ((uint)sp > END_OF_MEM) |
| 95 | break; |
| 96 | |
| 97 | i = sp[1]; |
| 98 | if (cnt++ % 7 == 0) |
| 99 | printf("\n"); |
| 100 | printf("%08lX ", i); |
| 101 | if (cnt > 32) break; |
| 102 | sp = (unsigned long *)*sp; |
| 103 | } |
| 104 | printf("\n"); |
| 105 | } |
| 106 | |
| 107 | void show_regs(struct pt_regs * regs) |
| 108 | { |
| 109 | int i; |
| 110 | |
| 111 | printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n", |
| 112 | regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar); |
| 113 | printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n", |
| 114 | regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0, |
| 115 | regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0, |
| 116 | regs->msr&MSR_IR ? 1 : 0, |
| 117 | regs->msr&MSR_DR ? 1 : 0); |
| 118 | |
| 119 | printf("\n"); |
| 120 | for (i = 0; i < 32; i++) { |
| 121 | if ((i % 8) == 0) |
| 122 | { |
| 123 | printf("GPR%02d: ", i); |
| 124 | } |
| 125 | |
| 126 | printf("%08lX ", regs->gpr[i]); |
| 127 | if ((i % 8) == 7) |
| 128 | { |
| 129 | printf("\n"); |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | |
| 135 | void |
| 136 | _exception(int signr, struct pt_regs *regs) |
| 137 | { |
| 138 | show_regs(regs); |
| 139 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 140 | panic("Exception in kernel pc %lx signal %d",regs->nip,signr); |
| 141 | } |
| 142 | |
| 143 | void |
| 144 | CritcalInputException(struct pt_regs *regs) |
| 145 | { |
| 146 | panic("Critical Input Exception"); |
| 147 | } |
| 148 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 149 | int machinecheck_count = 0; |
| 150 | int machinecheck_error = 0; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 151 | void |
| 152 | MachineCheckException(struct pt_regs *regs) |
| 153 | { |
| 154 | unsigned long fixup; |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 155 | unsigned int mcsr, mcsrr0, mcsrr1, mcar; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 156 | |
| 157 | /* Probing PCI using config cycles cause this exception |
| 158 | * when a device is not present. Catch it and return to |
| 159 | * the PCI exception handler. |
| 160 | */ |
| 161 | if ((fixup = search_exception_table(regs->nip)) != 0) { |
| 162 | regs->nip = fixup; |
| 163 | return; |
| 164 | } |
| 165 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 166 | mcsrr0 = mfspr(SPRN_MCSRR0); |
| 167 | mcsrr1 = mfspr(SPRN_MCSRR1); |
| 168 | mcsr = mfspr(SPRN_MCSR); |
| 169 | mcar = mfspr(SPRN_MCAR); |
| 170 | |
| 171 | machinecheck_count++; |
| 172 | machinecheck_error=1; |
| 173 | |
Jon Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 174 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 175 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 176 | return; |
| 177 | #endif |
| 178 | |
| 179 | printf("Machine check in kernel mode.\n"); |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 180 | printf("Caused by (from mcsr): "); |
| 181 | printf("mcsr = 0x%08x\n", mcsr); |
| 182 | if (mcsr & 0x80000000) |
| 183 | printf("Machine check input pin\n"); |
| 184 | if (mcsr & 0x40000000) |
| 185 | printf("Instruction cache parity error\n"); |
| 186 | if (mcsr & 0x20000000) |
| 187 | printf("Data cache push parity error\n"); |
| 188 | if (mcsr & 0x10000000) |
| 189 | printf("Data cache parity error\n"); |
| 190 | if (mcsr & 0x00000080) |
| 191 | printf("Bus instruction address error\n"); |
| 192 | if (mcsr & 0x00000040) |
| 193 | printf("Bus Read address error\n"); |
| 194 | if (mcsr & 0x00000020) |
| 195 | printf("Bus Write address error\n"); |
| 196 | if (mcsr & 0x00000010) |
| 197 | printf("Bus Instruction data bus error\n"); |
| 198 | if (mcsr & 0x00000008) |
| 199 | printf("Bus Read data bus error\n"); |
| 200 | if (mcsr & 0x00000004) |
| 201 | printf("Bus Write bus error\n"); |
| 202 | if (mcsr & 0x00000002) |
| 203 | printf("Bus Instruction parity error\n"); |
| 204 | if (mcsr & 0x00000001) |
| 205 | printf("Bus Read parity error\n"); |
| 206 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 207 | show_regs(regs); |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 208 | printf("MCSR=0x%08x \tMCSRR0=0x%08x \nMCSRR1=0x%08x \tMCAR=0x%08x\n", |
| 209 | mcsr, mcsrr0, mcsrr1, mcar); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 210 | print_backtrace((unsigned long *)regs->gpr[1]); |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 211 | if (machinecheck_count > 10) { |
| 212 | panic("machine check count too high\n"); |
| 213 | } |
| 214 | |
| 215 | if (machinecheck_count > 1) { |
| 216 | regs->nip += 4; /* skip offending instruction */ |
| 217 | printf("Skipping current instr, Returning to 0x%08x\n", |
| 218 | regs->nip); |
| 219 | } else { |
| 220 | printf("Returning back to 0x%08x\n",regs->nip); |
| 221 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | void |
| 225 | AlignmentException(struct pt_regs *regs) |
| 226 | { |
Jon Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 227 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 228 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 229 | return; |
| 230 | #endif |
| 231 | |
| 232 | show_regs(regs); |
| 233 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 234 | panic("Alignment Exception"); |
| 235 | } |
| 236 | |
| 237 | void |
| 238 | ProgramCheckException(struct pt_regs *regs) |
| 239 | { |
| 240 | long esr_val; |
| 241 | |
Jon Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 242 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 243 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 244 | return; |
| 245 | #endif |
| 246 | |
| 247 | show_regs(regs); |
| 248 | |
| 249 | esr_val = get_esr(); |
| 250 | if( esr_val & ESR_PIL ) |
| 251 | printf( "** Illegal Instruction **\n" ); |
| 252 | else if( esr_val & ESR_PPR ) |
| 253 | printf( "** Privileged Instruction **\n" ); |
| 254 | else if( esr_val & ESR_PTR ) |
| 255 | printf( "** Trap Instruction **\n" ); |
| 256 | |
| 257 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 258 | panic("Program Check Exception"); |
| 259 | } |
| 260 | |
| 261 | void |
| 262 | PITException(struct pt_regs *regs) |
| 263 | { |
| 264 | /* |
| 265 | * Reset PIT interrupt |
| 266 | */ |
| 267 | set_tsr(0x0c000000); |
| 268 | |
| 269 | /* |
| 270 | * Call timer_interrupt routine in interrupts.c |
| 271 | */ |
| 272 | timer_interrupt(NULL); |
| 273 | } |
| 274 | |
| 275 | |
| 276 | void |
| 277 | UnknownException(struct pt_regs *regs) |
| 278 | { |
Jon Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 279 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 280 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 281 | return; |
| 282 | #endif |
| 283 | |
| 284 | printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n", |
| 285 | regs->nip, regs->msr, regs->trap); |
| 286 | _exception(0, regs); |
| 287 | } |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 288 | void |
| 289 | ExtIntException(struct pt_regs *regs) |
| 290 | { |
Kumar Gala | 0a7a097 | 2007-11-29 02:10:09 -0600 | [diff] [blame] | 291 | volatile ccsr_pic_t *pic = (void *)(CFG_MPC85xx_PIC_ADDR); |
| 292 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 293 | uint vect; |
| 294 | |
| 295 | #if defined(CONFIG_CMD_KGDB) |
| 296 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 297 | return; |
| 298 | #endif |
| 299 | |
| 300 | printf("External Interrupt Exception at PC: %lx, SR: %lx, vector=%lx", |
| 301 | regs->nip, regs->msr, regs->trap); |
| 302 | vect = pic->iack0; |
| 303 | printf(" irq IACK0@%05x=%d\n",&pic->iack0,vect); |
| 304 | show_regs(regs); |
| 305 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 306 | machinecheck_count++; |
| 307 | #ifdef EXTINT_NOSKIP |
| 308 | printf("Returning back to 0x%08x\n",regs->nip); |
| 309 | #else |
| 310 | regs->nip += 4; /* skip offending instruction */ |
| 311 | printf("Skipping current instr, Returning to 0x%08x\n",regs->nip); |
| 312 | #endif |
| 313 | |
| 314 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 315 | |
| 316 | void |
| 317 | DebugException(struct pt_regs *regs) |
| 318 | { |
| 319 | printf("Debugger trap at @ %lx\n", regs->nip ); |
| 320 | show_regs(regs); |
Jon Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 321 | #if defined(CONFIG_CMD_BEDBUG) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 322 | do_bedbug_breakpoint( regs ); |
| 323 | #endif |
| 324 | } |
| 325 | |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 326 | /* Probe an address by reading. If not present, return -1, otherwise |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 327 | * return 0. |
| 328 | */ |
| 329 | int |
| 330 | addr_probe(uint *addr) |
| 331 | { |
| 332 | return 0; |
| 333 | } |