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