Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 2 | /* |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 3 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
| 4 | * |
| 5 | * Modified by Cort Dougan (cort@cs.nmt.edu) |
| 6 | * and Paul Mackerras (paulus@cs.anu.edu.au) |
| 7 | * |
| 8 | * (C) Copyright 2000 |
| 9 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | /* |
| 13 | * This file handles the architecture-dependent parts of hardware exceptions |
| 14 | */ |
| 15 | |
| 16 | #include <common.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 17 | #include <asm/global_data.h> |
Simon Glass | 25a5818 | 2020-05-10 11:40:06 -0600 | [diff] [blame] | 18 | #include <asm/ptrace.h> |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 19 | #include <command.h> |
Simon Glass | 9b4a205 | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 20 | #include <init.h> |
Mike Frysinger | e39bf1e | 2010-02-08 15:30:16 -0500 | [diff] [blame] | 21 | #include <kgdb.h> |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 22 | #include <asm/processor.h> |
| 23 | |
Wolfgang Denk | 1218abf | 2007-09-15 20:48:41 +0200 | [diff] [blame] | 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 26 | /* Returns 0 if exception not found and fixup otherwise. */ |
| 27 | extern unsigned long search_exception_table(unsigned long); |
| 28 | |
Becky Bruce | 279726b | 2008-05-14 13:09:58 -0500 | [diff] [blame] | 29 | /* |
| 30 | * End of addressable memory. This may be less than the actual |
| 31 | * amount of memory on the system if we're unable to keep all |
| 32 | * the memory mapped in. |
| 33 | */ |
Stefan Roese | e207f22 | 2020-08-12 13:16:36 +0200 | [diff] [blame] | 34 | #define END_OF_MEM (gd->ram_base + get_effective_memsize()) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | * Trap & Exception support |
| 38 | */ |
| 39 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 40 | static void print_backtrace(unsigned long *sp) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 41 | { |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 42 | int cnt = 0; |
| 43 | unsigned long i; |
| 44 | |
| 45 | printf("Call backtrace: "); |
| 46 | while (sp) { |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 47 | if ((uint) sp > END_OF_MEM) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 48 | break; |
| 49 | |
| 50 | i = sp[1]; |
| 51 | if (cnt++ % 7 == 0) |
| 52 | printf("\n"); |
| 53 | printf("%08lX ", i); |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 54 | if (cnt > 32) |
| 55 | break; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 56 | sp = (unsigned long *)*sp; |
| 57 | } |
| 58 | printf("\n"); |
| 59 | } |
| 60 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 61 | void show_regs(struct pt_regs *regs) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 62 | { |
| 63 | int i; |
| 64 | |
| 65 | printf("NIP: %08lX XER: %08lX LR: %08lX REGS:" |
| 66 | " %p TRAP: %04lx DAR: %08lX\n", |
| 67 | regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar); |
| 68 | printf("MSR: %08lx EE: %01x PR: %01x FP:" |
| 69 | " %01x ME: %01x IR/DR: %01x%01x\n", |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 70 | regs->msr, regs->msr & MSR_EE ? 1 : 0, |
| 71 | regs->msr & MSR_PR ? 1 : 0, regs->msr & MSR_FP ? 1 : 0, |
| 72 | regs->msr & MSR_ME ? 1 : 0, regs->msr & MSR_IR ? 1 : 0, |
| 73 | regs->msr & MSR_DR ? 1 : 0); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 74 | |
| 75 | printf("\n"); |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 76 | for (i = 0; i < 32; i++) { |
| 77 | if ((i % 8) == 0) { |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 78 | printf("GPR%02d: ", i); |
| 79 | } |
| 80 | |
| 81 | printf("%08lX ", regs->gpr[i]); |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 82 | if ((i % 8) == 7) { |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 83 | printf("\n"); |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 89 | static void _exception(int signr, struct pt_regs *regs) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 90 | { |
| 91 | show_regs(regs); |
| 92 | print_backtrace((unsigned long *)regs->gpr[1]); |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 93 | panic("Exception in kernel pc %lx signal %d", regs->nip, signr); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 94 | } |
| 95 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 96 | void MachineCheckException(struct pt_regs *regs) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 97 | { |
| 98 | unsigned long fixup; |
| 99 | |
| 100 | /* Probing PCI using config cycles cause this exception |
| 101 | * when a device is not present. Catch it and return to |
| 102 | * the PCI exception handler. |
| 103 | */ |
| 104 | if ((fixup = search_exception_table(regs->nip)) != 0) { |
| 105 | regs->nip = fixup; |
| 106 | return; |
| 107 | } |
| 108 | |
Jon Loeliger | b24629f | 2007-06-13 13:23:15 -0500 | [diff] [blame] | 109 | #if defined(CONFIG_CMD_KGDB) |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 110 | if (debugger_exception_handler && (*debugger_exception_handler) (regs)) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 111 | return; |
| 112 | #endif |
| 113 | |
| 114 | printf("Machine check in kernel mode.\n"); |
| 115 | printf("Caused by (from msr): "); |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 116 | printf("regs %p ", regs); |
Jon Loeliger | cfc7a7f | 2007-08-02 14:42:20 -0500 | [diff] [blame] | 117 | switch ( regs->msr & 0x001F0000) { |
| 118 | case (0x80000000>>11): |
| 119 | printf("MSS error. MSSSR0: %08x\n", mfspr(SPRN_MSSSR0)); |
| 120 | break; |
| 121 | case (0x80000000>>12): |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 122 | printf("Machine check signal - probably due to mm fault\n" |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 123 | "with mmu off\n"); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 124 | break; |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 125 | case (0x80000000 >> 13): |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 126 | printf("Transfer error ack signal\n"); |
| 127 | break; |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 128 | case (0x80000000 >> 14): |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 129 | printf("Data parity signal\n"); |
| 130 | break; |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 131 | case (0x80000000 >> 15): |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 132 | printf("Address parity signal\n"); |
| 133 | break; |
| 134 | default: |
| 135 | printf("Unknown values in msr\n"); |
| 136 | } |
| 137 | show_regs(regs); |
| 138 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 139 | panic("machine check"); |
| 140 | } |
| 141 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 142 | void AlignmentException(struct pt_regs *regs) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 143 | { |
Jon Loeliger | b24629f | 2007-06-13 13:23:15 -0500 | [diff] [blame] | 144 | #if defined(CONFIG_CMD_KGDB) |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 145 | if (debugger_exception_handler && (*debugger_exception_handler) (regs)) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 146 | return; |
| 147 | #endif |
| 148 | show_regs(regs); |
| 149 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 150 | panic("Alignment Exception"); |
| 151 | } |
| 152 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 153 | void ProgramCheckException(struct pt_regs *regs) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 154 | { |
| 155 | unsigned char *p = regs ? (unsigned char *)(regs->nip) : NULL; |
| 156 | int i, j; |
| 157 | |
Jon Loeliger | b24629f | 2007-06-13 13:23:15 -0500 | [diff] [blame] | 158 | #if defined(CONFIG_CMD_KGDB) |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 159 | if (debugger_exception_handler && (*debugger_exception_handler) (regs)) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 160 | return; |
| 161 | #endif |
| 162 | show_regs(regs); |
| 163 | |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 164 | p = (unsigned char *)((unsigned long)p & 0xFFFFFFE0); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 165 | p -= 32; |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 166 | for (i = 0; i < 256; i += 16) { |
| 167 | printf("%08x: ", (unsigned int)p + i); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 168 | for (j = 0; j < 16; j++) { |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 169 | printf("%02x ", p[i + j]); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 170 | } |
| 171 | printf("\n"); |
| 172 | } |
| 173 | |
| 174 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 175 | panic("Program Check Exception"); |
| 176 | } |
| 177 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 178 | void SoftEmuException(struct pt_regs *regs) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 179 | { |
Jon Loeliger | b24629f | 2007-06-13 13:23:15 -0500 | [diff] [blame] | 180 | #if defined(CONFIG_CMD_KGDB) |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 181 | if (debugger_exception_handler && (*debugger_exception_handler) (regs)) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 182 | return; |
| 183 | #endif |
| 184 | show_regs(regs); |
| 185 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 186 | panic("Software Emulation Exception"); |
| 187 | } |
| 188 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 189 | void UnknownException(struct pt_regs *regs) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 190 | { |
Jon Loeliger | b24629f | 2007-06-13 13:23:15 -0500 | [diff] [blame] | 191 | #if defined(CONFIG_CMD_KGDB) |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 192 | if (debugger_exception_handler && (*debugger_exception_handler) (regs)) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 193 | return; |
| 194 | #endif |
Wolfgang Denk | 9b55a25 | 2008-07-11 01:16:00 +0200 | [diff] [blame] | 195 | printf("UnknownException regs@%lx\n", (ulong)regs); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 196 | printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n", |
| 197 | regs->nip, regs->msr, regs->trap); |
| 198 | _exception(0, regs); |
| 199 | } |