wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1 | /* |
Stefan Roese | a47a12b | 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 | 1a45966 | 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 <asm/processor.h> |
| 21 | |
| 22 | /* Returns 0 if exception not found and fixup otherwise. */ |
| 23 | extern unsigned long search_exception_table(unsigned long); |
| 24 | |
| 25 | /* THIS NEEDS CHANGING to use the board info structure. |
| 26 | */ |
| 27 | #define END_OF_MEM 0x00400000 |
| 28 | |
| 29 | /* |
| 30 | * Trap & Exception support |
| 31 | */ |
| 32 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 33 | static void print_backtrace(unsigned long *sp) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 34 | { |
| 35 | int cnt = 0; |
| 36 | unsigned long i; |
| 37 | |
| 38 | printf("Call backtrace: "); |
| 39 | while (sp) { |
| 40 | if ((uint)sp > END_OF_MEM) |
| 41 | break; |
| 42 | |
| 43 | i = sp[1]; |
| 44 | if (cnt++ % 7 == 0) |
| 45 | printf("\n"); |
| 46 | printf("%08lX ", i); |
| 47 | if (cnt > 32) break; |
| 48 | sp = (unsigned long *)*sp; |
| 49 | } |
| 50 | printf("\n"); |
| 51 | } |
| 52 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 53 | void show_regs(struct pt_regs *regs) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 54 | { |
| 55 | int i; |
| 56 | |
| 57 | printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n", |
| 58 | regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar); |
| 59 | printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n", |
| 60 | regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0, |
| 61 | regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0, |
| 62 | regs->msr&MSR_IR ? 1 : 0, |
| 63 | regs->msr&MSR_DR ? 1 : 0); |
| 64 | |
| 65 | printf("\n"); |
| 66 | for (i = 0; i < 32; i++) { |
| 67 | if ((i % 8) == 0) |
| 68 | { |
| 69 | printf("GPR%02d: ", i); |
| 70 | } |
| 71 | |
| 72 | printf("%08lX ", regs->gpr[i]); |
| 73 | if ((i % 8) == 7) |
| 74 | { |
| 75 | printf("\n"); |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 81 | static void _exception(int signr, struct pt_regs *regs) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 82 | { |
| 83 | show_regs(regs); |
| 84 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 85 | panic("Exception in kernel pc %lx signal %d",regs->nip,signr); |
| 86 | } |
| 87 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 88 | void MachineCheckException(struct pt_regs *regs) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 89 | { |
| 90 | unsigned long fixup; |
| 91 | |
| 92 | /* Probing PCI using config cycles cause this exception |
| 93 | * when a device is not present. Catch it and return to |
| 94 | * the PCI exception handler. |
| 95 | */ |
| 96 | if ((fixup = search_exception_table(regs->nip)) != 0) { |
| 97 | regs->nip = fixup; |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | printf("Machine check in kernel mode.\n"); |
| 102 | printf("Caused by (from msr): "); |
| 103 | printf("regs %p ",regs); |
wdenk | 63e73c9 | 2004-02-23 22:22:28 +0000 | [diff] [blame] | 104 | switch( regs->msr & 0x000F0000) { |
| 105 | case (0x80000000>>12): |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 106 | printf("Machine check signal - probably due to mm fault\n" |
| 107 | "with mmu off\n"); |
| 108 | break; |
wdenk | 63e73c9 | 2004-02-23 22:22:28 +0000 | [diff] [blame] | 109 | case (0x80000000>>13): |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 110 | printf("Transfer error ack signal\n"); |
| 111 | break; |
wdenk | 63e73c9 | 2004-02-23 22:22:28 +0000 | [diff] [blame] | 112 | case (0x80000000>>14): |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 113 | printf("Data parity signal\n"); |
| 114 | break; |
wdenk | 63e73c9 | 2004-02-23 22:22:28 +0000 | [diff] [blame] | 115 | case (0x80000000>>15): |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 116 | printf("Address parity signal\n"); |
| 117 | break; |
| 118 | default: |
| 119 | printf("Unknown values in msr\n"); |
| 120 | } |
| 121 | show_regs(regs); |
| 122 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 123 | panic("machine check"); |
| 124 | } |
| 125 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 126 | void AlignmentException(struct pt_regs *regs) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 127 | { |
| 128 | show_regs(regs); |
| 129 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 130 | panic("Alignment Exception"); |
| 131 | } |
| 132 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 133 | void ProgramCheckException(struct pt_regs *regs) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 134 | { |
| 135 | show_regs(regs); |
| 136 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 137 | panic("Program Check Exception"); |
| 138 | } |
| 139 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 140 | void SoftEmuException(struct pt_regs *regs) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 141 | { |
| 142 | show_regs(regs); |
| 143 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 144 | panic("Software Emulation Exception"); |
| 145 | } |
| 146 | |
| 147 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 148 | void UnknownException(struct pt_regs *regs) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 149 | { |
| 150 | printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n", |
| 151 | regs->nip, regs->msr, regs->trap); |
| 152 | _exception(0, regs); |
| 153 | } |
| 154 | |
Jon Loeliger | 4431283 | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 155 | #if defined(CONFIG_CMD_BEDBUG) |
wdenk | 43d9616 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 156 | extern void do_bedbug_breakpoint(struct pt_regs *); |
| 157 | #endif |
| 158 | |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 159 | void DebugException(struct pt_regs *regs) |
wdenk | 43d9616 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 160 | { |
| 161 | |
| 162 | printf("Debugger trap at @ %lx\n", regs->nip ); |
| 163 | show_regs(regs); |
Jon Loeliger | 4431283 | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 164 | #if defined(CONFIG_CMD_BEDBUG) |
wdenk | 43d9616 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 165 | do_bedbug_breakpoint( regs ); |
| 166 | #endif |
| 167 | } |
| 168 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 169 | /* Probe an address by reading. If not present, return -1, otherwise |
| 170 | * return 0. |
| 171 | */ |
Kim Phillips | 20051f2 | 2012-10-29 13:34:29 +0000 | [diff] [blame] | 172 | int addr_probe(uint *addr) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 173 | { |
| 174 | #if 0 |
| 175 | int retval; |
| 176 | |
| 177 | __asm__ __volatile__( \ |
| 178 | "1: lwz %0,0(%1)\n" \ |
| 179 | " eieio\n" \ |
| 180 | " li %0,0\n" \ |
| 181 | "2:\n" \ |
| 182 | ".section .fixup,\"ax\"\n" \ |
| 183 | "3: li %0,-1\n" \ |
| 184 | " b 2b\n" \ |
| 185 | ".section __ex_table,\"a\"\n" \ |
| 186 | " .align 2\n" \ |
| 187 | " .long 1b,3b\n" \ |
| 188 | ".text" \ |
| 189 | : "=r" (retval) : "r"(addr)); |
| 190 | |
| 191 | return (retval); |
| 192 | #endif |
| 193 | return 0; |
| 194 | } |