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