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