Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 2 | /* |
| 3 | * linux/arch/powerpc/kernel/traps.c |
| 4 | * |
| 5 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
| 6 | * |
| 7 | * Modified by Cort Dougan (cort@cs.nmt.edu) |
| 8 | * and Paul Mackerras (paulus@cs.anu.edu.au) |
| 9 | * |
| 10 | * (C) Copyright 2000 |
| 11 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | /* |
| 15 | * This file handles the architecture-dependent parts of hardware exceptions |
| 16 | */ |
| 17 | |
| 18 | #include <common.h> |
Simon Glass | 6b9f010 | 2020-05-10 11:40:06 -0600 | [diff] [blame] | 19 | #include <asm/ptrace.h> |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 20 | #include <command.h> |
| 21 | #include <asm/processor.h> |
| 22 | |
| 23 | /* Returns 0 if exception not found and fixup otherwise. */ |
| 24 | extern unsigned long search_exception_table(unsigned long); |
| 25 | |
| 26 | /* THIS NEEDS CHANGING to use the board info structure. |
| 27 | */ |
| 28 | #define END_OF_MEM 0x02000000 |
| 29 | |
| 30 | /* |
| 31 | * Trap & Exception support |
| 32 | */ |
| 33 | |
| 34 | static void print_backtrace(unsigned long *sp) |
| 35 | { |
| 36 | int cnt = 0; |
| 37 | unsigned long i; |
| 38 | |
| 39 | printf("Call backtrace: "); |
| 40 | while (sp) { |
| 41 | if ((uint)sp > END_OF_MEM) |
| 42 | break; |
| 43 | |
| 44 | i = sp[1]; |
| 45 | if (cnt++ % 7 == 0) |
| 46 | printf("\n"); |
| 47 | printf("%08lX ", i); |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 48 | if (cnt > 32) |
| 49 | break; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 50 | sp = (unsigned long *)*sp; |
| 51 | } |
| 52 | printf("\n"); |
| 53 | } |
| 54 | |
Tom Rini | 4d88ed0 | 2020-01-29 11:07:19 -0500 | [diff] [blame] | 55 | void show_regs(struct pt_regs *regs) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 56 | { |
| 57 | int i; |
| 58 | |
| 59 | printf("NIP: %08lX XER: %08lX LR: %08lX REGS: %p TRAP: %04lx DAR: %08lX\n", |
| 60 | regs->nip, regs->xer, regs->link, regs, regs->trap, regs->dar); |
| 61 | printf("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n", |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 62 | regs->msr, regs->msr & MSR_EE ? 1 : 0, |
| 63 | regs->msr & MSR_PR ? 1 : 0, regs->msr & MSR_FP ? 1 : 0, |
| 64 | regs->msr & MSR_ME ? 1 : 0, regs->msr & MSR_IR ? 1 : 0, |
| 65 | regs->msr & MSR_DR ? 1 : 0); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 66 | |
| 67 | printf("\n"); |
| 68 | for (i = 0; i < 32; i++) { |
| 69 | if ((i % 8) == 0) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 70 | printf("GPR%02d: ", i); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 71 | |
| 72 | printf("%08lX ", regs->gpr[i]); |
| 73 | if ((i % 8) == 7) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 74 | printf("\n"); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
| 78 | |
| 79 | static void _exception(int signr, struct pt_regs *regs) |
| 80 | { |
| 81 | show_regs(regs); |
| 82 | print_backtrace((unsigned long *)regs->gpr[1]); |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 83 | panic("Exception in kernel pc %lx signal %d", regs->nip, signr); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void MachineCheckException(struct pt_regs *regs) |
| 87 | { |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 88 | unsigned long fixup = search_exception_table(regs->nip); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 89 | |
| 90 | /* Probing PCI using config cycles cause this exception |
| 91 | * when a device is not present. Catch it and return to |
| 92 | * the PCI exception handler. |
| 93 | */ |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 94 | if (fixup != 0) { |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 95 | regs->nip = fixup; |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | printf("Machine check in kernel mode.\n"); |
| 100 | printf("Caused by (from msr): "); |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 101 | printf("regs %p ", regs); |
| 102 | switch (regs->msr & 0x000F0000) { |
| 103 | case (0x80000000 >> 12): |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 104 | printf("Machine check signal - probably due to mm fault\n" |
| 105 | "with mmu off\n"); |
| 106 | break; |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 107 | case (0x80000000 >> 13): |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 108 | printf("Transfer error ack signal\n"); |
| 109 | break; |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 110 | case (0x80000000 >> 14): |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 111 | printf("Data parity signal\n"); |
| 112 | break; |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 113 | case (0x80000000 >> 15): |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 114 | printf("Address parity signal\n"); |
| 115 | break; |
| 116 | default: |
| 117 | printf("Unknown values in msr\n"); |
| 118 | } |
| 119 | show_regs(regs); |
| 120 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 121 | panic("machine check"); |
| 122 | } |
| 123 | |
| 124 | void AlignmentException(struct pt_regs *regs) |
| 125 | { |
| 126 | show_regs(regs); |
| 127 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 128 | panic("Alignment Exception"); |
| 129 | } |
| 130 | |
| 131 | void ProgramCheckException(struct pt_regs *regs) |
| 132 | { |
| 133 | show_regs(regs); |
| 134 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 135 | panic("Program Check Exception"); |
| 136 | } |
| 137 | |
| 138 | void SoftEmuException(struct pt_regs *regs) |
| 139 | { |
| 140 | show_regs(regs); |
| 141 | print_backtrace((unsigned long *)regs->gpr[1]); |
| 142 | panic("Software Emulation Exception"); |
| 143 | } |
| 144 | |
| 145 | |
| 146 | void UnknownException(struct pt_regs *regs) |
| 147 | { |
| 148 | printf("Bad trap at PC: %lx, SR: %lx, vector=%lx\n", |
| 149 | regs->nip, regs->msr, regs->trap); |
| 150 | _exception(0, regs); |
| 151 | } |
| 152 | |
| 153 | void DebugException(struct pt_regs *regs) |
| 154 | { |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 155 | printf("Debugger trap at @ %lx\n", regs->nip); |
| 156 | show_regs(regs); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 157 | } |