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