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