wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1 | /* |
Stefan Roese | a47a12b | 2010-04-15 16:07:28 +0200 | [diff] [blame] | 2 | * linux/arch/powerpc/kernel/traps.c |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 3 | * |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 4 | * Copyright 2007 Freescale Semiconductor. |
wdenk | 42d1f03 | 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 | 9aea953 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wdenk | 42d1f03 | 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> |
Mike Frysinger | e39bf1e | 2010-02-08 15:30:16 -0500 | [diff] [blame] | 41 | #include <kgdb.h> |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 42 | #include <asm/processor.h> |
| 43 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 44 | DECLARE_GLOBAL_DATA_PTR; |
| 45 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 46 | /* Returns 0 if exception not found and fixup otherwise. */ |
| 47 | extern unsigned long search_exception_table(unsigned long); |
| 48 | |
wdenk | 9aea953 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 49 | /* |
Becky Bruce | 3b9519f | 2008-05-14 13:10:04 -0500 | [diff] [blame] | 50 | * End of addressable memory. This may be less than the actual |
| 51 | * amount of memory on the system if we're unable to keep all |
| 52 | * the memory mapped in. |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 53 | */ |
Becky Bruce | 3b9519f | 2008-05-14 13:10:04 -0500 | [diff] [blame] | 54 | extern ulong get_effective_memsize(void); |
| 55 | #define END_OF_MEM (gd->bd->bi_memstart + get_effective_memsize()) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 56 | |
| 57 | static __inline__ void set_tsr(unsigned long val) |
| 58 | { |
| 59 | asm volatile("mtspr 0x150, %0" : : "r" (val)); |
| 60 | } |
| 61 | |
| 62 | static __inline__ unsigned long get_esr(void) |
| 63 | { |
| 64 | unsigned long val; |
| 65 | asm volatile("mfspr %0, 0x03e" : "=r" (val) :); |
| 66 | return val; |
| 67 | } |
| 68 | |
| 69 | #define ESR_MCI 0x80000000 |
| 70 | #define ESR_PIL 0x08000000 |
| 71 | #define ESR_PPR 0x04000000 |
| 72 | #define ESR_PTR 0x02000000 |
| 73 | #define ESR_DST 0x00800000 |
| 74 | #define ESR_DIZ 0x00400000 |
| 75 | #define ESR_U0F 0x00008000 |
| 76 | |
Jon Loeliger | 4431283 | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 77 | #if defined(CONFIG_CMD_BEDBUG) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 78 | extern void do_bedbug_breakpoint(struct pt_regs *); |
| 79 | #endif |
| 80 | |
| 81 | /* |
| 82 | * Trap & Exception support |
| 83 | */ |
| 84 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 85 | static void print_backtrace(unsigned long *sp) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 86 | { |
| 87 | int cnt = 0; |
| 88 | unsigned long i; |
| 89 | |
| 90 | printf("Call backtrace: "); |
| 91 | while (sp) { |
| 92 | if ((uint)sp > END_OF_MEM) |
| 93 | break; |
| 94 | |
| 95 | i = sp[1]; |
| 96 | if (cnt++ % 7 == 0) |
| 97 | printf("\n"); |
| 98 | printf("%08lX ", i); |
| 99 | if (cnt > 32) break; |
| 100 | sp = (unsigned long *)*sp; |
| 101 | } |
| 102 | printf("\n"); |
| 103 | } |
| 104 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 105 | void show_regs(struct pt_regs *regs) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 106 | { |
| 107 | int i; |
| 108 | |
| 109 | printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n", |
| 110 | regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar); |
| 111 | printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n", |
| 112 | regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0, |
| 113 | regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0, |
| 114 | regs->msr&MSR_IR ? 1 : 0, |
| 115 | regs->msr&MSR_DR ? 1 : 0); |
| 116 | |
| 117 | printf("\n"); |
| 118 | for (i = 0; i < 32; i++) { |
| 119 | if ((i % 8) == 0) |
| 120 | { |
| 121 | printf("GPR%02d: ", i); |
| 122 | } |
| 123 | |
| 124 | printf("%08lX ", regs->gpr[i]); |
| 125 | if ((i % 8) == 7) |
| 126 | { |
| 127 | printf("\n"); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 133 | static void _exception(int signr, struct pt_regs *regs) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 134 | { |
| 135 | show_regs(regs); |
| 136 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 137 | panic("Exception in kernel pc %lx signal %d",regs->nip,signr); |
| 138 | } |
| 139 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 140 | void CritcalInputException(struct pt_regs *regs) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 141 | { |
| 142 | panic("Critical Input Exception"); |
| 143 | } |
| 144 | |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 145 | int machinecheck_count = 0; |
| 146 | int machinecheck_error = 0; |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 147 | void MachineCheckException(struct pt_regs *regs) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 148 | { |
| 149 | unsigned long fixup; |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 150 | unsigned int mcsr, mcsrr0, mcsrr1, mcar; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 151 | |
| 152 | /* Probing PCI using config cycles cause this exception |
| 153 | * when a device is not present. Catch it and return to |
| 154 | * the PCI exception handler. |
| 155 | */ |
| 156 | if ((fixup = search_exception_table(regs->nip)) != 0) { |
| 157 | regs->nip = fixup; |
| 158 | return; |
| 159 | } |
| 160 | |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 161 | mcsrr0 = mfspr(SPRN_MCSRR0); |
| 162 | mcsrr1 = mfspr(SPRN_MCSRR1); |
| 163 | mcsr = mfspr(SPRN_MCSR); |
| 164 | mcar = mfspr(SPRN_MCAR); |
| 165 | |
| 166 | machinecheck_count++; |
| 167 | machinecheck_error=1; |
| 168 | |
Jon Loeliger | 4431283 | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 169 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 170 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 171 | return; |
| 172 | #endif |
| 173 | |
| 174 | printf("Machine check in kernel mode.\n"); |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 175 | printf("Caused by (from mcsr): "); |
| 176 | printf("mcsr = 0x%08x\n", mcsr); |
| 177 | if (mcsr & 0x80000000) |
| 178 | printf("Machine check input pin\n"); |
| 179 | if (mcsr & 0x40000000) |
| 180 | printf("Instruction cache parity error\n"); |
| 181 | if (mcsr & 0x20000000) |
| 182 | printf("Data cache push parity error\n"); |
| 183 | if (mcsr & 0x10000000) |
| 184 | printf("Data cache parity error\n"); |
| 185 | if (mcsr & 0x00000080) |
| 186 | printf("Bus instruction address error\n"); |
| 187 | if (mcsr & 0x00000040) |
| 188 | printf("Bus Read address error\n"); |
| 189 | if (mcsr & 0x00000020) |
| 190 | printf("Bus Write address error\n"); |
| 191 | if (mcsr & 0x00000010) |
| 192 | printf("Bus Instruction data bus error\n"); |
| 193 | if (mcsr & 0x00000008) |
| 194 | printf("Bus Read data bus error\n"); |
| 195 | if (mcsr & 0x00000004) |
| 196 | printf("Bus Write bus error\n"); |
| 197 | if (mcsr & 0x00000002) |
| 198 | printf("Bus Instruction parity error\n"); |
| 199 | if (mcsr & 0x00000001) |
| 200 | printf("Bus Read parity error\n"); |
| 201 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 202 | show_regs(regs); |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 203 | printf("MCSR=0x%08x \tMCSRR0=0x%08x \nMCSRR1=0x%08x \tMCAR=0x%08x\n", |
| 204 | mcsr, mcsrr0, mcsrr1, mcar); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 205 | print_backtrace((unsigned long *)regs->gpr[1]); |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 206 | if (machinecheck_count > 10) { |
| 207 | panic("machine check count too high\n"); |
| 208 | } |
| 209 | |
| 210 | if (machinecheck_count > 1) { |
| 211 | regs->nip += 4; /* skip offending instruction */ |
Andrew Klossner | dc4b0b3 | 2008-07-07 06:41:14 -0700 | [diff] [blame] | 212 | printf("Skipping current instr, Returning to 0x%08lx\n", |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 213 | regs->nip); |
| 214 | } else { |
Andrew Klossner | dc4b0b3 | 2008-07-07 06:41:14 -0700 | [diff] [blame] | 215 | printf("Returning back to 0x%08lx\n",regs->nip); |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 216 | } |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 219 | void AlignmentException(struct pt_regs *regs) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 220 | { |
Jon Loeliger | 4431283 | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 221 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 222 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 223 | return; |
| 224 | #endif |
| 225 | |
| 226 | show_regs(regs); |
| 227 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 228 | panic("Alignment Exception"); |
| 229 | } |
| 230 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 231 | void ProgramCheckException(struct pt_regs *regs) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 232 | { |
| 233 | long esr_val; |
| 234 | |
Jon Loeliger | 4431283 | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 235 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 236 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 237 | return; |
| 238 | #endif |
| 239 | |
| 240 | show_regs(regs); |
| 241 | |
| 242 | esr_val = get_esr(); |
| 243 | if( esr_val & ESR_PIL ) |
| 244 | printf( "** Illegal Instruction **\n" ); |
| 245 | else if( esr_val & ESR_PPR ) |
| 246 | printf( "** Privileged Instruction **\n" ); |
| 247 | else if( esr_val & ESR_PTR ) |
| 248 | printf( "** Trap Instruction **\n" ); |
| 249 | |
| 250 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 251 | panic("Program Check Exception"); |
| 252 | } |
| 253 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 254 | void PITException(struct pt_regs *regs) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 255 | { |
| 256 | /* |
| 257 | * Reset PIT interrupt |
| 258 | */ |
| 259 | set_tsr(0x0c000000); |
| 260 | |
| 261 | /* |
| 262 | * Call timer_interrupt routine in interrupts.c |
| 263 | */ |
| 264 | timer_interrupt(NULL); |
| 265 | } |
| 266 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 267 | void UnknownException(struct pt_regs *regs) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 268 | { |
Jon Loeliger | 4431283 | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 269 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 270 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 271 | return; |
| 272 | #endif |
| 273 | |
| 274 | printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n", |
| 275 | regs->nip, regs->msr, regs->trap); |
| 276 | _exception(0, regs); |
| 277 | } |
Scott Wood | 3e3c9c1 | 2009-08-20 17:45:00 -0500 | [diff] [blame] | 278 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 279 | void ExtIntException(struct pt_regs *regs) |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 280 | { |
Kim Phillips | 680c613 | 2010-08-09 18:39:57 -0500 | [diff] [blame] | 281 | volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR); |
Kumar Gala | 04db400 | 2007-11-29 02:10:09 -0600 | [diff] [blame] | 282 | |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 283 | uint vect; |
| 284 | |
| 285 | #if defined(CONFIG_CMD_KGDB) |
| 286 | if (debugger_exception_handler && (*debugger_exception_handler)(regs)) |
| 287 | return; |
| 288 | #endif |
| 289 | |
| 290 | printf("External Interrupt Exception at PC: %lx, SR: %lx, vector=%lx", |
| 291 | regs->nip, regs->msr, regs->trap); |
| 292 | vect = pic->iack0; |
Andrew Klossner | dc4b0b3 | 2008-07-07 06:41:14 -0700 | [diff] [blame] | 293 | printf(" irq IACK0@%05x=%d\n",(int)&pic->iack0,vect); |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 294 | show_regs(regs); |
| 295 | print_backtrace((unsigned long *)regs->gpr[1]); |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 296 | } |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 297 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 298 | void DebugException(struct pt_regs *regs) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 299 | { |
| 300 | printf("Debugger trap at @ %lx\n", regs->nip ); |
| 301 | show_regs(regs); |
Jon Loeliger | 4431283 | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 302 | #if defined(CONFIG_CMD_BEDBUG) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 303 | do_bedbug_breakpoint( regs ); |
| 304 | #endif |
| 305 | } |
| 306 | |
wdenk | 9aea953 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 307 | /* Probe an address by reading. If not present, return -1, otherwise |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 308 | * return 0. |
| 309 | */ |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 310 | int addr_probe(uint *addr) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 311 | { |
| 312 | return 0; |
| 313 | } |