114cf11afSPaul Mackerras /* 214cf11afSPaul Mackerras * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) 314cf11afSPaul Mackerras * 414cf11afSPaul Mackerras * This program is free software; you can redistribute it and/or 514cf11afSPaul Mackerras * modify it under the terms of the GNU General Public License 614cf11afSPaul Mackerras * as published by the Free Software Foundation; either version 714cf11afSPaul Mackerras * 2 of the License, or (at your option) any later version. 814cf11afSPaul Mackerras * 914cf11afSPaul Mackerras * Modified by Cort Dougan (cort@cs.nmt.edu) 1014cf11afSPaul Mackerras * and Paul Mackerras (paulus@samba.org) 1114cf11afSPaul Mackerras */ 1214cf11afSPaul Mackerras 1314cf11afSPaul Mackerras /* 1414cf11afSPaul Mackerras * This file handles the architecture-dependent parts of hardware exceptions 1514cf11afSPaul Mackerras */ 1614cf11afSPaul Mackerras 1714cf11afSPaul Mackerras #include <linux/errno.h> 1814cf11afSPaul Mackerras #include <linux/sched.h> 1914cf11afSPaul Mackerras #include <linux/kernel.h> 2014cf11afSPaul Mackerras #include <linux/mm.h> 2114cf11afSPaul Mackerras #include <linux/stddef.h> 2214cf11afSPaul Mackerras #include <linux/unistd.h> 238dad3f92SPaul Mackerras #include <linux/ptrace.h> 2414cf11afSPaul Mackerras #include <linux/slab.h> 2514cf11afSPaul Mackerras #include <linux/user.h> 2614cf11afSPaul Mackerras #include <linux/a.out.h> 2714cf11afSPaul Mackerras #include <linux/interrupt.h> 2814cf11afSPaul Mackerras #include <linux/init.h> 2914cf11afSPaul Mackerras #include <linux/module.h> 308dad3f92SPaul Mackerras #include <linux/prctl.h> 3114cf11afSPaul Mackerras #include <linux/delay.h> 3214cf11afSPaul Mackerras #include <linux/kprobes.h> 33cc532915SMichael Ellerman #include <linux/kexec.h> 345474c120SMichael Hanselmann #include <linux/backlight.h> 3573c9ceabSJeremy Fitzhardinge #include <linux/bug.h> 361eeb66a1SChristoph Hellwig #include <linux/kdebug.h> 3714cf11afSPaul Mackerras 3814cf11afSPaul Mackerras #include <asm/pgtable.h> 3914cf11afSPaul Mackerras #include <asm/uaccess.h> 4014cf11afSPaul Mackerras #include <asm/system.h> 4114cf11afSPaul Mackerras #include <asm/io.h> 4286417780SPaul Mackerras #include <asm/machdep.h> 4386417780SPaul Mackerras #include <asm/rtas.h> 44f7f6f4feSDavid Gibson #include <asm/pmc.h> 45dc1c1ca3SStephen Rothwell #ifdef CONFIG_PPC32 4614cf11afSPaul Mackerras #include <asm/reg.h> 4786417780SPaul Mackerras #endif 4814cf11afSPaul Mackerras #ifdef CONFIG_PMAC_BACKLIGHT 4914cf11afSPaul Mackerras #include <asm/backlight.h> 5014cf11afSPaul Mackerras #endif 51dc1c1ca3SStephen Rothwell #ifdef CONFIG_PPC64 5286417780SPaul Mackerras #include <asm/firmware.h> 53dc1c1ca3SStephen Rothwell #include <asm/processor.h> 54dc1c1ca3SStephen Rothwell #endif 55c0ce7d08SDavid Wilder #include <asm/kexec.h> 56dc1c1ca3SStephen Rothwell 5714cf11afSPaul Mackerras #ifdef CONFIG_DEBUGGER 5814cf11afSPaul Mackerras int (*__debugger)(struct pt_regs *regs); 5914cf11afSPaul Mackerras int (*__debugger_ipi)(struct pt_regs *regs); 6014cf11afSPaul Mackerras int (*__debugger_bpt)(struct pt_regs *regs); 6114cf11afSPaul Mackerras int (*__debugger_sstep)(struct pt_regs *regs); 6214cf11afSPaul Mackerras int (*__debugger_iabr_match)(struct pt_regs *regs); 6314cf11afSPaul Mackerras int (*__debugger_dabr_match)(struct pt_regs *regs); 6414cf11afSPaul Mackerras int (*__debugger_fault_handler)(struct pt_regs *regs); 6514cf11afSPaul Mackerras 6614cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger); 6714cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_ipi); 6814cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_bpt); 6914cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_sstep); 7014cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_iabr_match); 7114cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_dabr_match); 7214cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_fault_handler); 7314cf11afSPaul Mackerras #endif 7414cf11afSPaul Mackerras 7514cf11afSPaul Mackerras /* 7614cf11afSPaul Mackerras * Trap & Exception support 7714cf11afSPaul Mackerras */ 7814cf11afSPaul Mackerras 796031d9d9Santon@samba.org #ifdef CONFIG_PMAC_BACKLIGHT 806031d9d9Santon@samba.org static void pmac_backlight_unblank(void) 816031d9d9Santon@samba.org { 826031d9d9Santon@samba.org mutex_lock(&pmac_backlight_mutex); 836031d9d9Santon@samba.org if (pmac_backlight) { 846031d9d9Santon@samba.org struct backlight_properties *props; 856031d9d9Santon@samba.org 866031d9d9Santon@samba.org props = &pmac_backlight->props; 876031d9d9Santon@samba.org props->brightness = props->max_brightness; 886031d9d9Santon@samba.org props->power = FB_BLANK_UNBLANK; 896031d9d9Santon@samba.org backlight_update_status(pmac_backlight); 906031d9d9Santon@samba.org } 916031d9d9Santon@samba.org mutex_unlock(&pmac_backlight_mutex); 926031d9d9Santon@samba.org } 936031d9d9Santon@samba.org #else 946031d9d9Santon@samba.org static inline void pmac_backlight_unblank(void) { } 956031d9d9Santon@samba.org #endif 966031d9d9Santon@samba.org 9714cf11afSPaul Mackerras int die(const char *str, struct pt_regs *regs, long err) 9814cf11afSPaul Mackerras { 9934c2a14fSanton@samba.org static struct { 10034c2a14fSanton@samba.org spinlock_t lock; 10134c2a14fSanton@samba.org u32 lock_owner; 10234c2a14fSanton@samba.org int lock_owner_depth; 10334c2a14fSanton@samba.org } die = { 10434c2a14fSanton@samba.org .lock = __SPIN_LOCK_UNLOCKED(die.lock), 10534c2a14fSanton@samba.org .lock_owner = -1, 10634c2a14fSanton@samba.org .lock_owner_depth = 0 10734c2a14fSanton@samba.org }; 108c0ce7d08SDavid Wilder static int die_counter; 10934c2a14fSanton@samba.org unsigned long flags; 11014cf11afSPaul Mackerras 11114cf11afSPaul Mackerras if (debugger(regs)) 11214cf11afSPaul Mackerras return 1; 11314cf11afSPaul Mackerras 114293e4688Santon@samba.org oops_enter(); 115293e4688Santon@samba.org 11634c2a14fSanton@samba.org if (die.lock_owner != raw_smp_processor_id()) { 11714cf11afSPaul Mackerras console_verbose(); 11834c2a14fSanton@samba.org spin_lock_irqsave(&die.lock, flags); 11934c2a14fSanton@samba.org die.lock_owner = smp_processor_id(); 12034c2a14fSanton@samba.org die.lock_owner_depth = 0; 12114cf11afSPaul Mackerras bust_spinlocks(1); 1226031d9d9Santon@samba.org if (machine_is(powermac)) 1236031d9d9Santon@samba.org pmac_backlight_unblank(); 12434c2a14fSanton@samba.org } else { 12534c2a14fSanton@samba.org local_save_flags(flags); 12634c2a14fSanton@samba.org } 1275474c120SMichael Hanselmann 12834c2a14fSanton@samba.org if (++die.lock_owner_depth < 3) { 12914cf11afSPaul Mackerras printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter); 13014cf11afSPaul Mackerras #ifdef CONFIG_PREEMPT 13114cf11afSPaul Mackerras printk("PREEMPT "); 13214cf11afSPaul Mackerras #endif 13314cf11afSPaul Mackerras #ifdef CONFIG_SMP 13414cf11afSPaul Mackerras printk("SMP NR_CPUS=%d ", NR_CPUS); 13514cf11afSPaul Mackerras #endif 13614cf11afSPaul Mackerras #ifdef CONFIG_DEBUG_PAGEALLOC 13714cf11afSPaul Mackerras printk("DEBUG_PAGEALLOC "); 13814cf11afSPaul Mackerras #endif 13914cf11afSPaul Mackerras #ifdef CONFIG_NUMA 14014cf11afSPaul Mackerras printk("NUMA "); 14114cf11afSPaul Mackerras #endif 142ae7f4463Santon@samba.org printk("%s\n", ppc_md.name ? ppc_md.name : ""); 143e8222502SBenjamin Herrenschmidt 14414cf11afSPaul Mackerras print_modules(); 14514cf11afSPaul Mackerras show_regs(regs); 14634c2a14fSanton@samba.org } else { 14734c2a14fSanton@samba.org printk("Recursive die() failure, output suppressed\n"); 14834c2a14fSanton@samba.org } 14934c2a14fSanton@samba.org 15014cf11afSPaul Mackerras bust_spinlocks(0); 15134c2a14fSanton@samba.org die.lock_owner = -1; 152bcdcd8e7SPavel Emelianov add_taint(TAINT_DIE); 15334c2a14fSanton@samba.org spin_unlock_irqrestore(&die.lock, flags); 154cc532915SMichael Ellerman 155c0ce7d08SDavid Wilder if (kexec_should_crash(current) || 156c0ce7d08SDavid Wilder kexec_sr_activated(smp_processor_id())) 157cc532915SMichael Ellerman crash_kexec(regs); 158c0ce7d08SDavid Wilder crash_kexec_secondary(regs); 15914cf11afSPaul Mackerras 16014cf11afSPaul Mackerras if (in_interrupt()) 16114cf11afSPaul Mackerras panic("Fatal exception in interrupt"); 16214cf11afSPaul Mackerras 163cea6a4baSHorms if (panic_on_oops) 164012c437dSHorms panic("Fatal exception"); 165cea6a4baSHorms 166293e4688Santon@samba.org oops_exit(); 16714cf11afSPaul Mackerras do_exit(err); 16814cf11afSPaul Mackerras 16914cf11afSPaul Mackerras return 0; 17014cf11afSPaul Mackerras } 17114cf11afSPaul Mackerras 17214cf11afSPaul Mackerras void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr) 17314cf11afSPaul Mackerras { 17414cf11afSPaul Mackerras siginfo_t info; 17514cf11afSPaul Mackerras 17614cf11afSPaul Mackerras if (!user_mode(regs)) { 17714cf11afSPaul Mackerras if (die("Exception in kernel mode", regs, signr)) 17814cf11afSPaul Mackerras return; 17914cf11afSPaul Mackerras } 18014cf11afSPaul Mackerras 18114cf11afSPaul Mackerras memset(&info, 0, sizeof(info)); 18214cf11afSPaul Mackerras info.si_signo = signr; 18314cf11afSPaul Mackerras info.si_code = code; 18414cf11afSPaul Mackerras info.si_addr = (void __user *) addr; 18514cf11afSPaul Mackerras force_sig_info(signr, &info, current); 18614cf11afSPaul Mackerras 18714cf11afSPaul Mackerras /* 18814cf11afSPaul Mackerras * Init gets no signals that it doesn't have a handler for. 18914cf11afSPaul Mackerras * That's all very well, but if it has caused a synchronous 19014cf11afSPaul Mackerras * exception and we ignore the resulting signal, it will just 19114cf11afSPaul Mackerras * generate the same exception over and over again and we get 19214cf11afSPaul Mackerras * nowhere. Better to kill it and let the kernel panic. 19314cf11afSPaul Mackerras */ 19460bccbedSAkinobu Mita if (is_init(current)) { 19514cf11afSPaul Mackerras __sighandler_t handler; 19614cf11afSPaul Mackerras 19714cf11afSPaul Mackerras spin_lock_irq(¤t->sighand->siglock); 19814cf11afSPaul Mackerras handler = current->sighand->action[signr-1].sa.sa_handler; 19914cf11afSPaul Mackerras spin_unlock_irq(¤t->sighand->siglock); 20014cf11afSPaul Mackerras if (handler == SIG_DFL) { 20114cf11afSPaul Mackerras /* init has generated a synchronous exception 20214cf11afSPaul Mackerras and it doesn't have a handler for the signal */ 20314cf11afSPaul Mackerras printk(KERN_CRIT "init has generated signal %d " 20414cf11afSPaul Mackerras "but has no handler for it\n", signr); 20514cf11afSPaul Mackerras do_exit(signr); 20614cf11afSPaul Mackerras } 20714cf11afSPaul Mackerras } 20814cf11afSPaul Mackerras } 20914cf11afSPaul Mackerras 21014cf11afSPaul Mackerras #ifdef CONFIG_PPC64 21114cf11afSPaul Mackerras void system_reset_exception(struct pt_regs *regs) 21214cf11afSPaul Mackerras { 21314cf11afSPaul Mackerras /* See if any machine dependent calls */ 214c902be71SArnd Bergmann if (ppc_md.system_reset_exception) { 215c902be71SArnd Bergmann if (ppc_md.system_reset_exception(regs)) 216c902be71SArnd Bergmann return; 217c902be71SArnd Bergmann } 21814cf11afSPaul Mackerras 219c0ce7d08SDavid Wilder #ifdef CONFIG_KEXEC 220c0ce7d08SDavid Wilder cpu_set(smp_processor_id(), cpus_in_sr); 221c0ce7d08SDavid Wilder #endif 222c0ce7d08SDavid Wilder 2238dad3f92SPaul Mackerras die("System Reset", regs, SIGABRT); 22414cf11afSPaul Mackerras 225eac8392fSDavid Wilder /* 226eac8392fSDavid Wilder * Some CPUs when released from the debugger will execute this path. 227eac8392fSDavid Wilder * These CPUs entered the debugger via a soft-reset. If the CPU was 228eac8392fSDavid Wilder * hung before entering the debugger it will return to the hung 229eac8392fSDavid Wilder * state when exiting this function. This causes a problem in 230eac8392fSDavid Wilder * kdump since the hung CPU(s) will not respond to the IPI sent 231eac8392fSDavid Wilder * from kdump. To prevent the problem we call crash_kexec_secondary() 232eac8392fSDavid Wilder * here. If a kdump had not been initiated or we exit the debugger 233eac8392fSDavid Wilder * with the "exit and recover" command (x) crash_kexec_secondary() 234eac8392fSDavid Wilder * will return after 5ms and the CPU returns to its previous state. 235eac8392fSDavid Wilder */ 236eac8392fSDavid Wilder crash_kexec_secondary(regs); 237eac8392fSDavid Wilder 23814cf11afSPaul Mackerras /* Must die if the interrupt is not recoverable */ 23914cf11afSPaul Mackerras if (!(regs->msr & MSR_RI)) 24014cf11afSPaul Mackerras panic("Unrecoverable System Reset"); 24114cf11afSPaul Mackerras 24214cf11afSPaul Mackerras /* What should we do here? We could issue a shutdown or hard reset. */ 24314cf11afSPaul Mackerras } 24414cf11afSPaul Mackerras #endif 24514cf11afSPaul Mackerras 24614cf11afSPaul Mackerras /* 24714cf11afSPaul Mackerras * I/O accesses can cause machine checks on powermacs. 24814cf11afSPaul Mackerras * Check if the NIP corresponds to the address of a sync 24914cf11afSPaul Mackerras * instruction for which there is an entry in the exception 25014cf11afSPaul Mackerras * table. 25114cf11afSPaul Mackerras * Note that the 601 only takes a machine check on TEA 25214cf11afSPaul Mackerras * (transfer error ack) signal assertion, and does not 25314cf11afSPaul Mackerras * set any of the top 16 bits of SRR1. 25414cf11afSPaul Mackerras * -- paulus. 25514cf11afSPaul Mackerras */ 25614cf11afSPaul Mackerras static inline int check_io_access(struct pt_regs *regs) 25714cf11afSPaul Mackerras { 25868a64357SBenjamin Herrenschmidt #ifdef CONFIG_PPC32 25914cf11afSPaul Mackerras unsigned long msr = regs->msr; 26014cf11afSPaul Mackerras const struct exception_table_entry *entry; 26114cf11afSPaul Mackerras unsigned int *nip = (unsigned int *)regs->nip; 26214cf11afSPaul Mackerras 26314cf11afSPaul Mackerras if (((msr & 0xffff0000) == 0 || (msr & (0x80000 | 0x40000))) 26414cf11afSPaul Mackerras && (entry = search_exception_tables(regs->nip)) != NULL) { 26514cf11afSPaul Mackerras /* 26614cf11afSPaul Mackerras * Check that it's a sync instruction, or somewhere 26714cf11afSPaul Mackerras * in the twi; isync; nop sequence that inb/inw/inl uses. 26814cf11afSPaul Mackerras * As the address is in the exception table 26914cf11afSPaul Mackerras * we should be able to read the instr there. 27014cf11afSPaul Mackerras * For the debug message, we look at the preceding 27114cf11afSPaul Mackerras * load or store. 27214cf11afSPaul Mackerras */ 27314cf11afSPaul Mackerras if (*nip == 0x60000000) /* nop */ 27414cf11afSPaul Mackerras nip -= 2; 27514cf11afSPaul Mackerras else if (*nip == 0x4c00012c) /* isync */ 27614cf11afSPaul Mackerras --nip; 27714cf11afSPaul Mackerras if (*nip == 0x7c0004ac || (*nip >> 26) == 3) { 27814cf11afSPaul Mackerras /* sync or twi */ 27914cf11afSPaul Mackerras unsigned int rb; 28014cf11afSPaul Mackerras 28114cf11afSPaul Mackerras --nip; 28214cf11afSPaul Mackerras rb = (*nip >> 11) & 0x1f; 28314cf11afSPaul Mackerras printk(KERN_DEBUG "%s bad port %lx at %p\n", 28414cf11afSPaul Mackerras (*nip & 0x100)? "OUT to": "IN from", 28514cf11afSPaul Mackerras regs->gpr[rb] - _IO_BASE, nip); 28614cf11afSPaul Mackerras regs->msr |= MSR_RI; 28714cf11afSPaul Mackerras regs->nip = entry->fixup; 28814cf11afSPaul Mackerras return 1; 28914cf11afSPaul Mackerras } 29014cf11afSPaul Mackerras } 29168a64357SBenjamin Herrenschmidt #endif /* CONFIG_PPC32 */ 29214cf11afSPaul Mackerras return 0; 29314cf11afSPaul Mackerras } 29414cf11afSPaul Mackerras 29514cf11afSPaul Mackerras #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE) 29614cf11afSPaul Mackerras /* On 4xx, the reason for the machine check or program exception 29714cf11afSPaul Mackerras is in the ESR. */ 29814cf11afSPaul Mackerras #define get_reason(regs) ((regs)->dsisr) 29914cf11afSPaul Mackerras #ifndef CONFIG_FSL_BOOKE 30014cf11afSPaul Mackerras #define get_mc_reason(regs) ((regs)->dsisr) 30114cf11afSPaul Mackerras #else 30286d7a9a9SBecky Bruce #define get_mc_reason(regs) (mfspr(SPRN_MCSR) & MCSR_MASK) 30314cf11afSPaul Mackerras #endif 30414cf11afSPaul Mackerras #define REASON_FP ESR_FP 30514cf11afSPaul Mackerras #define REASON_ILLEGAL (ESR_PIL | ESR_PUO) 30614cf11afSPaul Mackerras #define REASON_PRIVILEGED ESR_PPR 30714cf11afSPaul Mackerras #define REASON_TRAP ESR_PTR 30814cf11afSPaul Mackerras 30914cf11afSPaul Mackerras /* single-step stuff */ 31014cf11afSPaul Mackerras #define single_stepping(regs) (current->thread.dbcr0 & DBCR0_IC) 31114cf11afSPaul Mackerras #define clear_single_step(regs) (current->thread.dbcr0 &= ~DBCR0_IC) 31214cf11afSPaul Mackerras 31314cf11afSPaul Mackerras #else 31414cf11afSPaul Mackerras /* On non-4xx, the reason for the machine check or program 31514cf11afSPaul Mackerras exception is in the MSR. */ 31614cf11afSPaul Mackerras #define get_reason(regs) ((regs)->msr) 31714cf11afSPaul Mackerras #define get_mc_reason(regs) ((regs)->msr) 31814cf11afSPaul Mackerras #define REASON_FP 0x100000 31914cf11afSPaul Mackerras #define REASON_ILLEGAL 0x80000 32014cf11afSPaul Mackerras #define REASON_PRIVILEGED 0x40000 32114cf11afSPaul Mackerras #define REASON_TRAP 0x20000 32214cf11afSPaul Mackerras 32314cf11afSPaul Mackerras #define single_stepping(regs) ((regs)->msr & MSR_SE) 32414cf11afSPaul Mackerras #define clear_single_step(regs) ((regs)->msr &= ~MSR_SE) 32514cf11afSPaul Mackerras #endif 32614cf11afSPaul Mackerras 32775918a4bSOlof Johansson static int generic_machine_check_exception(struct pt_regs *regs) 32814cf11afSPaul Mackerras { 3291a6a4ffeSKumar Gala unsigned long reason = get_mc_reason(regs); 33014cf11afSPaul Mackerras 33114cf11afSPaul Mackerras #if defined(CONFIG_4xx) && !defined(CONFIG_440A) 33214cf11afSPaul Mackerras if (reason & ESR_IMCP) { 33314cf11afSPaul Mackerras printk("Instruction"); 33414cf11afSPaul Mackerras mtspr(SPRN_ESR, reason & ~ESR_IMCP); 33514cf11afSPaul Mackerras } else 33614cf11afSPaul Mackerras printk("Data"); 33714cf11afSPaul Mackerras printk(" machine check in kernel mode.\n"); 33814cf11afSPaul Mackerras #elif defined(CONFIG_440A) 33914cf11afSPaul Mackerras printk("Machine check in kernel mode.\n"); 34014cf11afSPaul Mackerras if (reason & ESR_IMCP){ 34114cf11afSPaul Mackerras printk("Instruction Synchronous Machine Check exception\n"); 34214cf11afSPaul Mackerras mtspr(SPRN_ESR, reason & ~ESR_IMCP); 34314cf11afSPaul Mackerras } 34414cf11afSPaul Mackerras else { 34514cf11afSPaul Mackerras u32 mcsr = mfspr(SPRN_MCSR); 34614cf11afSPaul Mackerras if (mcsr & MCSR_IB) 34714cf11afSPaul Mackerras printk("Instruction Read PLB Error\n"); 34814cf11afSPaul Mackerras if (mcsr & MCSR_DRB) 34914cf11afSPaul Mackerras printk("Data Read PLB Error\n"); 35014cf11afSPaul Mackerras if (mcsr & MCSR_DWB) 35114cf11afSPaul Mackerras printk("Data Write PLB Error\n"); 35214cf11afSPaul Mackerras if (mcsr & MCSR_TLBP) 35314cf11afSPaul Mackerras printk("TLB Parity Error\n"); 35414cf11afSPaul Mackerras if (mcsr & MCSR_ICP){ 35514cf11afSPaul Mackerras flush_instruction_cache(); 35614cf11afSPaul Mackerras printk("I-Cache Parity Error\n"); 35714cf11afSPaul Mackerras } 35814cf11afSPaul Mackerras if (mcsr & MCSR_DCSP) 35914cf11afSPaul Mackerras printk("D-Cache Search Parity Error\n"); 36014cf11afSPaul Mackerras if (mcsr & MCSR_DCFP) 36114cf11afSPaul Mackerras printk("D-Cache Flush Parity Error\n"); 36214cf11afSPaul Mackerras if (mcsr & MCSR_IMPE) 36314cf11afSPaul Mackerras printk("Machine Check exception is imprecise\n"); 36414cf11afSPaul Mackerras 36514cf11afSPaul Mackerras /* Clear MCSR */ 36614cf11afSPaul Mackerras mtspr(SPRN_MCSR, mcsr); 36714cf11afSPaul Mackerras } 36814cf11afSPaul Mackerras #elif defined (CONFIG_E500) 36914cf11afSPaul Mackerras printk("Machine check in kernel mode.\n"); 37014cf11afSPaul Mackerras printk("Caused by (from MCSR=%lx): ", reason); 37114cf11afSPaul Mackerras 37214cf11afSPaul Mackerras if (reason & MCSR_MCP) 37314cf11afSPaul Mackerras printk("Machine Check Signal\n"); 37414cf11afSPaul Mackerras if (reason & MCSR_ICPERR) 37514cf11afSPaul Mackerras printk("Instruction Cache Parity Error\n"); 37614cf11afSPaul Mackerras if (reason & MCSR_DCP_PERR) 37714cf11afSPaul Mackerras printk("Data Cache Push Parity Error\n"); 37814cf11afSPaul Mackerras if (reason & MCSR_DCPERR) 37914cf11afSPaul Mackerras printk("Data Cache Parity Error\n"); 38014cf11afSPaul Mackerras if (reason & MCSR_BUS_IAERR) 38114cf11afSPaul Mackerras printk("Bus - Instruction Address Error\n"); 38214cf11afSPaul Mackerras if (reason & MCSR_BUS_RAERR) 38314cf11afSPaul Mackerras printk("Bus - Read Address Error\n"); 38414cf11afSPaul Mackerras if (reason & MCSR_BUS_WAERR) 38514cf11afSPaul Mackerras printk("Bus - Write Address Error\n"); 38614cf11afSPaul Mackerras if (reason & MCSR_BUS_IBERR) 38714cf11afSPaul Mackerras printk("Bus - Instruction Data Error\n"); 38814cf11afSPaul Mackerras if (reason & MCSR_BUS_RBERR) 38914cf11afSPaul Mackerras printk("Bus - Read Data Bus Error\n"); 39014cf11afSPaul Mackerras if (reason & MCSR_BUS_WBERR) 39114cf11afSPaul Mackerras printk("Bus - Read Data Bus Error\n"); 39214cf11afSPaul Mackerras if (reason & MCSR_BUS_IPERR) 39314cf11afSPaul Mackerras printk("Bus - Instruction Parity Error\n"); 39414cf11afSPaul Mackerras if (reason & MCSR_BUS_RPERR) 39514cf11afSPaul Mackerras printk("Bus - Read Parity Error\n"); 39614cf11afSPaul Mackerras #elif defined (CONFIG_E200) 39714cf11afSPaul Mackerras printk("Machine check in kernel mode.\n"); 39814cf11afSPaul Mackerras printk("Caused by (from MCSR=%lx): ", reason); 39914cf11afSPaul Mackerras 40014cf11afSPaul Mackerras if (reason & MCSR_MCP) 40114cf11afSPaul Mackerras printk("Machine Check Signal\n"); 40214cf11afSPaul Mackerras if (reason & MCSR_CP_PERR) 40314cf11afSPaul Mackerras printk("Cache Push Parity Error\n"); 40414cf11afSPaul Mackerras if (reason & MCSR_CPERR) 40514cf11afSPaul Mackerras printk("Cache Parity Error\n"); 40614cf11afSPaul Mackerras if (reason & MCSR_EXCP_ERR) 40714cf11afSPaul Mackerras printk("ISI, ITLB, or Bus Error on first instruction fetch for an exception handler\n"); 40814cf11afSPaul Mackerras if (reason & MCSR_BUS_IRERR) 40914cf11afSPaul Mackerras printk("Bus - Read Bus Error on instruction fetch\n"); 41014cf11afSPaul Mackerras if (reason & MCSR_BUS_DRERR) 41114cf11afSPaul Mackerras printk("Bus - Read Bus Error on data load\n"); 41214cf11afSPaul Mackerras if (reason & MCSR_BUS_WRERR) 41314cf11afSPaul Mackerras printk("Bus - Write Bus Error on buffered store or cache line push\n"); 41414cf11afSPaul Mackerras #else /* !CONFIG_4xx && !CONFIG_E500 && !CONFIG_E200 */ 41514cf11afSPaul Mackerras printk("Machine check in kernel mode.\n"); 41614cf11afSPaul Mackerras printk("Caused by (from SRR1=%lx): ", reason); 41714cf11afSPaul Mackerras switch (reason & 0x601F0000) { 41814cf11afSPaul Mackerras case 0x80000: 41914cf11afSPaul Mackerras printk("Machine check signal\n"); 42014cf11afSPaul Mackerras break; 42114cf11afSPaul Mackerras case 0: /* for 601 */ 42214cf11afSPaul Mackerras case 0x40000: 42314cf11afSPaul Mackerras case 0x140000: /* 7450 MSS error and TEA */ 42414cf11afSPaul Mackerras printk("Transfer error ack signal\n"); 42514cf11afSPaul Mackerras break; 42614cf11afSPaul Mackerras case 0x20000: 42714cf11afSPaul Mackerras printk("Data parity error signal\n"); 42814cf11afSPaul Mackerras break; 42914cf11afSPaul Mackerras case 0x10000: 43014cf11afSPaul Mackerras printk("Address parity error signal\n"); 43114cf11afSPaul Mackerras break; 43214cf11afSPaul Mackerras case 0x20000000: 43314cf11afSPaul Mackerras printk("L1 Data Cache error\n"); 43414cf11afSPaul Mackerras break; 43514cf11afSPaul Mackerras case 0x40000000: 43614cf11afSPaul Mackerras printk("L1 Instruction Cache error\n"); 43714cf11afSPaul Mackerras break; 43814cf11afSPaul Mackerras case 0x00100000: 43914cf11afSPaul Mackerras printk("L2 data cache parity error\n"); 44014cf11afSPaul Mackerras break; 44114cf11afSPaul Mackerras default: 44214cf11afSPaul Mackerras printk("Unknown values in msr\n"); 44314cf11afSPaul Mackerras } 44414cf11afSPaul Mackerras #endif /* CONFIG_4xx */ 44514cf11afSPaul Mackerras 44675918a4bSOlof Johansson return 0; 44775918a4bSOlof Johansson } 44875918a4bSOlof Johansson 44975918a4bSOlof Johansson void machine_check_exception(struct pt_regs *regs) 45075918a4bSOlof Johansson { 45175918a4bSOlof Johansson int recover = 0; 45275918a4bSOlof Johansson 45375918a4bSOlof Johansson /* See if any machine dependent calls */ 45475918a4bSOlof Johansson if (ppc_md.machine_check_exception) 45575918a4bSOlof Johansson recover = ppc_md.machine_check_exception(regs); 45675918a4bSOlof Johansson else 45775918a4bSOlof Johansson recover = generic_machine_check_exception(regs); 45875918a4bSOlof Johansson 45975918a4bSOlof Johansson if (recover) 46075918a4bSOlof Johansson return; 46175918a4bSOlof Johansson 46275918a4bSOlof Johansson if (user_mode(regs)) { 46375918a4bSOlof Johansson regs->msr |= MSR_RI; 46475918a4bSOlof Johansson _exception(SIGBUS, regs, BUS_ADRERR, regs->nip); 46575918a4bSOlof Johansson return; 46675918a4bSOlof Johansson } 46775918a4bSOlof Johansson 46875918a4bSOlof Johansson #if defined(CONFIG_8xx) && defined(CONFIG_PCI) 46975918a4bSOlof Johansson /* the qspan pci read routines can cause machine checks -- Cort */ 47075918a4bSOlof Johansson bad_page_fault(regs, regs->dar, SIGBUS); 47175918a4bSOlof Johansson return; 47275918a4bSOlof Johansson #endif 47375918a4bSOlof Johansson 47475918a4bSOlof Johansson if (debugger_fault_handler(regs)) { 47575918a4bSOlof Johansson regs->msr |= MSR_RI; 47675918a4bSOlof Johansson return; 47775918a4bSOlof Johansson } 47875918a4bSOlof Johansson 47975918a4bSOlof Johansson if (check_io_access(regs)) 48075918a4bSOlof Johansson return; 48175918a4bSOlof Johansson 48214cf11afSPaul Mackerras if (debugger_fault_handler(regs)) 48314cf11afSPaul Mackerras return; 4848dad3f92SPaul Mackerras die("Machine check", regs, SIGBUS); 48514cf11afSPaul Mackerras 48614cf11afSPaul Mackerras /* Must die if the interrupt is not recoverable */ 48714cf11afSPaul Mackerras if (!(regs->msr & MSR_RI)) 48814cf11afSPaul Mackerras panic("Unrecoverable Machine check"); 48914cf11afSPaul Mackerras } 49014cf11afSPaul Mackerras 49114cf11afSPaul Mackerras void SMIException(struct pt_regs *regs) 49214cf11afSPaul Mackerras { 49314cf11afSPaul Mackerras die("System Management Interrupt", regs, SIGABRT); 49414cf11afSPaul Mackerras } 49514cf11afSPaul Mackerras 496dc1c1ca3SStephen Rothwell void unknown_exception(struct pt_regs *regs) 49714cf11afSPaul Mackerras { 49814cf11afSPaul Mackerras printk("Bad trap at PC: %lx, SR: %lx, vector=%lx\n", 49914cf11afSPaul Mackerras regs->nip, regs->msr, regs->trap); 50014cf11afSPaul Mackerras 50114cf11afSPaul Mackerras _exception(SIGTRAP, regs, 0, 0); 50214cf11afSPaul Mackerras } 50314cf11afSPaul Mackerras 504dc1c1ca3SStephen Rothwell void instruction_breakpoint_exception(struct pt_regs *regs) 50514cf11afSPaul Mackerras { 50614cf11afSPaul Mackerras if (notify_die(DIE_IABR_MATCH, "iabr_match", regs, 5, 50714cf11afSPaul Mackerras 5, SIGTRAP) == NOTIFY_STOP) 50814cf11afSPaul Mackerras return; 50914cf11afSPaul Mackerras if (debugger_iabr_match(regs)) 51014cf11afSPaul Mackerras return; 51114cf11afSPaul Mackerras _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip); 51214cf11afSPaul Mackerras } 51314cf11afSPaul Mackerras 51414cf11afSPaul Mackerras void RunModeException(struct pt_regs *regs) 51514cf11afSPaul Mackerras { 51614cf11afSPaul Mackerras _exception(SIGTRAP, regs, 0, 0); 51714cf11afSPaul Mackerras } 51814cf11afSPaul Mackerras 5198dad3f92SPaul Mackerras void __kprobes single_step_exception(struct pt_regs *regs) 52014cf11afSPaul Mackerras { 52114cf11afSPaul Mackerras regs->msr &= ~(MSR_SE | MSR_BE); /* Turn off 'trace' bits */ 52214cf11afSPaul Mackerras 52314cf11afSPaul Mackerras if (notify_die(DIE_SSTEP, "single_step", regs, 5, 52414cf11afSPaul Mackerras 5, SIGTRAP) == NOTIFY_STOP) 52514cf11afSPaul Mackerras return; 52614cf11afSPaul Mackerras if (debugger_sstep(regs)) 52714cf11afSPaul Mackerras return; 52814cf11afSPaul Mackerras 52914cf11afSPaul Mackerras _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip); 53014cf11afSPaul Mackerras } 53114cf11afSPaul Mackerras 53214cf11afSPaul Mackerras /* 53314cf11afSPaul Mackerras * After we have successfully emulated an instruction, we have to 53414cf11afSPaul Mackerras * check if the instruction was being single-stepped, and if so, 53514cf11afSPaul Mackerras * pretend we got a single-step exception. This was pointed out 53614cf11afSPaul Mackerras * by Kumar Gala. -- paulus 53714cf11afSPaul Mackerras */ 5388dad3f92SPaul Mackerras static void emulate_single_step(struct pt_regs *regs) 53914cf11afSPaul Mackerras { 54014cf11afSPaul Mackerras if (single_stepping(regs)) { 54114cf11afSPaul Mackerras clear_single_step(regs); 54214cf11afSPaul Mackerras _exception(SIGTRAP, regs, TRAP_TRACE, 0); 54314cf11afSPaul Mackerras } 54414cf11afSPaul Mackerras } 54514cf11afSPaul Mackerras 5465fad293bSKumar Gala static inline int __parse_fpscr(unsigned long fpscr) 547dc1c1ca3SStephen Rothwell { 5485fad293bSKumar Gala int ret = 0; 549dc1c1ca3SStephen Rothwell 550dc1c1ca3SStephen Rothwell /* Invalid operation */ 551dc1c1ca3SStephen Rothwell if ((fpscr & FPSCR_VE) && (fpscr & FPSCR_VX)) 5525fad293bSKumar Gala ret = FPE_FLTINV; 553dc1c1ca3SStephen Rothwell 554dc1c1ca3SStephen Rothwell /* Overflow */ 555dc1c1ca3SStephen Rothwell else if ((fpscr & FPSCR_OE) && (fpscr & FPSCR_OX)) 5565fad293bSKumar Gala ret = FPE_FLTOVF; 557dc1c1ca3SStephen Rothwell 558dc1c1ca3SStephen Rothwell /* Underflow */ 559dc1c1ca3SStephen Rothwell else if ((fpscr & FPSCR_UE) && (fpscr & FPSCR_UX)) 5605fad293bSKumar Gala ret = FPE_FLTUND; 561dc1c1ca3SStephen Rothwell 562dc1c1ca3SStephen Rothwell /* Divide by zero */ 563dc1c1ca3SStephen Rothwell else if ((fpscr & FPSCR_ZE) && (fpscr & FPSCR_ZX)) 5645fad293bSKumar Gala ret = FPE_FLTDIV; 565dc1c1ca3SStephen Rothwell 566dc1c1ca3SStephen Rothwell /* Inexact result */ 567dc1c1ca3SStephen Rothwell else if ((fpscr & FPSCR_XE) && (fpscr & FPSCR_XX)) 5685fad293bSKumar Gala ret = FPE_FLTRES; 5695fad293bSKumar Gala 5705fad293bSKumar Gala return ret; 5715fad293bSKumar Gala } 5725fad293bSKumar Gala 5735fad293bSKumar Gala static void parse_fpe(struct pt_regs *regs) 5745fad293bSKumar Gala { 5755fad293bSKumar Gala int code = 0; 5765fad293bSKumar Gala 5775fad293bSKumar Gala flush_fp_to_thread(current); 5785fad293bSKumar Gala 5795fad293bSKumar Gala code = __parse_fpscr(current->thread.fpscr.val); 580dc1c1ca3SStephen Rothwell 581dc1c1ca3SStephen Rothwell _exception(SIGFPE, regs, code, regs->nip); 582dc1c1ca3SStephen Rothwell } 583dc1c1ca3SStephen Rothwell 584dc1c1ca3SStephen Rothwell /* 585dc1c1ca3SStephen Rothwell * Illegal instruction emulation support. Originally written to 58614cf11afSPaul Mackerras * provide the PVR to user applications using the mfspr rd, PVR. 58714cf11afSPaul Mackerras * Return non-zero if we can't emulate, or -EFAULT if the associated 58814cf11afSPaul Mackerras * memory access caused an access fault. Return zero on success. 58914cf11afSPaul Mackerras * 59014cf11afSPaul Mackerras * There are a couple of ways to do this, either "decode" the instruction 59114cf11afSPaul Mackerras * or directly match lots of bits. In this case, matching lots of 59214cf11afSPaul Mackerras * bits is faster and easier. 59386417780SPaul Mackerras * 59414cf11afSPaul Mackerras */ 59514cf11afSPaul Mackerras #define INST_MFSPR_PVR 0x7c1f42a6 59614cf11afSPaul Mackerras #define INST_MFSPR_PVR_MASK 0xfc1fffff 59714cf11afSPaul Mackerras 59814cf11afSPaul Mackerras #define INST_DCBA 0x7c0005ec 59987589f08SPaul Mackerras #define INST_DCBA_MASK 0xfc0007fe 60014cf11afSPaul Mackerras 60114cf11afSPaul Mackerras #define INST_MCRXR 0x7c000400 60287589f08SPaul Mackerras #define INST_MCRXR_MASK 0xfc0007fe 60314cf11afSPaul Mackerras 60414cf11afSPaul Mackerras #define INST_STRING 0x7c00042a 60587589f08SPaul Mackerras #define INST_STRING_MASK 0xfc0007fe 60687589f08SPaul Mackerras #define INST_STRING_GEN_MASK 0xfc00067e 60714cf11afSPaul Mackerras #define INST_LSWI 0x7c0004aa 60814cf11afSPaul Mackerras #define INST_LSWX 0x7c00042a 60914cf11afSPaul Mackerras #define INST_STSWI 0x7c0005aa 61014cf11afSPaul Mackerras #define INST_STSWX 0x7c00052a 61114cf11afSPaul Mackerras 612c3412dcbSWill Schmidt #define INST_POPCNTB 0x7c0000f4 613c3412dcbSWill Schmidt #define INST_POPCNTB_MASK 0xfc0007fe 614c3412dcbSWill Schmidt 61514cf11afSPaul Mackerras static int emulate_string_inst(struct pt_regs *regs, u32 instword) 61614cf11afSPaul Mackerras { 61714cf11afSPaul Mackerras u8 rT = (instword >> 21) & 0x1f; 61814cf11afSPaul Mackerras u8 rA = (instword >> 16) & 0x1f; 61914cf11afSPaul Mackerras u8 NB_RB = (instword >> 11) & 0x1f; 62014cf11afSPaul Mackerras u32 num_bytes; 62114cf11afSPaul Mackerras unsigned long EA; 62214cf11afSPaul Mackerras int pos = 0; 62314cf11afSPaul Mackerras 62414cf11afSPaul Mackerras /* Early out if we are an invalid form of lswx */ 62514cf11afSPaul Mackerras if ((instword & INST_STRING_MASK) == INST_LSWX) 62614cf11afSPaul Mackerras if ((rT == rA) || (rT == NB_RB)) 62714cf11afSPaul Mackerras return -EINVAL; 62814cf11afSPaul Mackerras 62914cf11afSPaul Mackerras EA = (rA == 0) ? 0 : regs->gpr[rA]; 63014cf11afSPaul Mackerras 63114cf11afSPaul Mackerras switch (instword & INST_STRING_MASK) { 63214cf11afSPaul Mackerras case INST_LSWX: 63314cf11afSPaul Mackerras case INST_STSWX: 63414cf11afSPaul Mackerras EA += NB_RB; 63514cf11afSPaul Mackerras num_bytes = regs->xer & 0x7f; 63614cf11afSPaul Mackerras break; 63714cf11afSPaul Mackerras case INST_LSWI: 63814cf11afSPaul Mackerras case INST_STSWI: 63914cf11afSPaul Mackerras num_bytes = (NB_RB == 0) ? 32 : NB_RB; 64014cf11afSPaul Mackerras break; 64114cf11afSPaul Mackerras default: 64214cf11afSPaul Mackerras return -EINVAL; 64314cf11afSPaul Mackerras } 64414cf11afSPaul Mackerras 64514cf11afSPaul Mackerras while (num_bytes != 0) 64614cf11afSPaul Mackerras { 64714cf11afSPaul Mackerras u8 val; 64814cf11afSPaul Mackerras u32 shift = 8 * (3 - (pos & 0x3)); 64914cf11afSPaul Mackerras 65014cf11afSPaul Mackerras switch ((instword & INST_STRING_MASK)) { 65114cf11afSPaul Mackerras case INST_LSWX: 65214cf11afSPaul Mackerras case INST_LSWI: 65314cf11afSPaul Mackerras if (get_user(val, (u8 __user *)EA)) 65414cf11afSPaul Mackerras return -EFAULT; 65514cf11afSPaul Mackerras /* first time updating this reg, 65614cf11afSPaul Mackerras * zero it out */ 65714cf11afSPaul Mackerras if (pos == 0) 65814cf11afSPaul Mackerras regs->gpr[rT] = 0; 65914cf11afSPaul Mackerras regs->gpr[rT] |= val << shift; 66014cf11afSPaul Mackerras break; 66114cf11afSPaul Mackerras case INST_STSWI: 66214cf11afSPaul Mackerras case INST_STSWX: 66314cf11afSPaul Mackerras val = regs->gpr[rT] >> shift; 66414cf11afSPaul Mackerras if (put_user(val, (u8 __user *)EA)) 66514cf11afSPaul Mackerras return -EFAULT; 66614cf11afSPaul Mackerras break; 66714cf11afSPaul Mackerras } 66814cf11afSPaul Mackerras /* move EA to next address */ 66914cf11afSPaul Mackerras EA += 1; 67014cf11afSPaul Mackerras num_bytes--; 67114cf11afSPaul Mackerras 67214cf11afSPaul Mackerras /* manage our position within the register */ 67314cf11afSPaul Mackerras if (++pos == 4) { 67414cf11afSPaul Mackerras pos = 0; 67514cf11afSPaul Mackerras if (++rT == 32) 67614cf11afSPaul Mackerras rT = 0; 67714cf11afSPaul Mackerras } 67814cf11afSPaul Mackerras } 67914cf11afSPaul Mackerras 68014cf11afSPaul Mackerras return 0; 68114cf11afSPaul Mackerras } 68214cf11afSPaul Mackerras 683c3412dcbSWill Schmidt static int emulate_popcntb_inst(struct pt_regs *regs, u32 instword) 684c3412dcbSWill Schmidt { 685c3412dcbSWill Schmidt u32 ra,rs; 686c3412dcbSWill Schmidt unsigned long tmp; 687c3412dcbSWill Schmidt 688c3412dcbSWill Schmidt ra = (instword >> 16) & 0x1f; 689c3412dcbSWill Schmidt rs = (instword >> 21) & 0x1f; 690c3412dcbSWill Schmidt 691c3412dcbSWill Schmidt tmp = regs->gpr[rs]; 692c3412dcbSWill Schmidt tmp = tmp - ((tmp >> 1) & 0x5555555555555555ULL); 693c3412dcbSWill Schmidt tmp = (tmp & 0x3333333333333333ULL) + ((tmp >> 2) & 0x3333333333333333ULL); 694c3412dcbSWill Schmidt tmp = (tmp + (tmp >> 4)) & 0x0f0f0f0f0f0f0f0fULL; 695c3412dcbSWill Schmidt regs->gpr[ra] = tmp; 696c3412dcbSWill Schmidt 697c3412dcbSWill Schmidt return 0; 698c3412dcbSWill Schmidt } 699c3412dcbSWill Schmidt 70014cf11afSPaul Mackerras static int emulate_instruction(struct pt_regs *regs) 70114cf11afSPaul Mackerras { 70214cf11afSPaul Mackerras u32 instword; 70314cf11afSPaul Mackerras u32 rd; 70414cf11afSPaul Mackerras 705fab5db97SPaul Mackerras if (!user_mode(regs) || (regs->msr & MSR_LE)) 70614cf11afSPaul Mackerras return -EINVAL; 70714cf11afSPaul Mackerras CHECK_FULL_REGS(regs); 70814cf11afSPaul Mackerras 70914cf11afSPaul Mackerras if (get_user(instword, (u32 __user *)(regs->nip))) 71014cf11afSPaul Mackerras return -EFAULT; 71114cf11afSPaul Mackerras 71214cf11afSPaul Mackerras /* Emulate the mfspr rD, PVR. */ 71314cf11afSPaul Mackerras if ((instword & INST_MFSPR_PVR_MASK) == INST_MFSPR_PVR) { 71414cf11afSPaul Mackerras rd = (instword >> 21) & 0x1f; 71514cf11afSPaul Mackerras regs->gpr[rd] = mfspr(SPRN_PVR); 71614cf11afSPaul Mackerras return 0; 71714cf11afSPaul Mackerras } 71814cf11afSPaul Mackerras 71914cf11afSPaul Mackerras /* Emulating the dcba insn is just a no-op. */ 7208dad3f92SPaul Mackerras if ((instword & INST_DCBA_MASK) == INST_DCBA) 72114cf11afSPaul Mackerras return 0; 72214cf11afSPaul Mackerras 72314cf11afSPaul Mackerras /* Emulate the mcrxr insn. */ 72414cf11afSPaul Mackerras if ((instword & INST_MCRXR_MASK) == INST_MCRXR) { 72586417780SPaul Mackerras int shift = (instword >> 21) & 0x1c; 72614cf11afSPaul Mackerras unsigned long msk = 0xf0000000UL >> shift; 72714cf11afSPaul Mackerras 72814cf11afSPaul Mackerras regs->ccr = (regs->ccr & ~msk) | ((regs->xer >> shift) & msk); 72914cf11afSPaul Mackerras regs->xer &= ~0xf0000000UL; 73014cf11afSPaul Mackerras return 0; 73114cf11afSPaul Mackerras } 73214cf11afSPaul Mackerras 73314cf11afSPaul Mackerras /* Emulate load/store string insn. */ 73414cf11afSPaul Mackerras if ((instword & INST_STRING_GEN_MASK) == INST_STRING) 73514cf11afSPaul Mackerras return emulate_string_inst(regs, instword); 73614cf11afSPaul Mackerras 737c3412dcbSWill Schmidt /* Emulate the popcntb (Population Count Bytes) instruction. */ 738c3412dcbSWill Schmidt if ((instword & INST_POPCNTB_MASK) == INST_POPCNTB) { 739c3412dcbSWill Schmidt return emulate_popcntb_inst(regs, instword); 740c3412dcbSWill Schmidt } 741c3412dcbSWill Schmidt 74214cf11afSPaul Mackerras return -EINVAL; 74314cf11afSPaul Mackerras } 74414cf11afSPaul Mackerras 74573c9ceabSJeremy Fitzhardinge int is_valid_bugaddr(unsigned long addr) 74614cf11afSPaul Mackerras { 74773c9ceabSJeremy Fitzhardinge return is_kernel_addr(addr); 74814cf11afSPaul Mackerras } 74914cf11afSPaul Mackerras 7508dad3f92SPaul Mackerras void __kprobes program_check_exception(struct pt_regs *regs) 75114cf11afSPaul Mackerras { 75214cf11afSPaul Mackerras unsigned int reason = get_reason(regs); 75314cf11afSPaul Mackerras extern int do_mathemu(struct pt_regs *regs); 75414cf11afSPaul Mackerras 755aa42c69cSKim Phillips /* We can now get here via a FP Unavailable exception if the core 75604903a30SKumar Gala * has no FPU, in that case the reason flags will be 0 */ 75714cf11afSPaul Mackerras 75814cf11afSPaul Mackerras if (reason & REASON_FP) { 75914cf11afSPaul Mackerras /* IEEE FP exception */ 760dc1c1ca3SStephen Rothwell parse_fpe(regs); 7618dad3f92SPaul Mackerras return; 7628dad3f92SPaul Mackerras } 7638dad3f92SPaul Mackerras if (reason & REASON_TRAP) { 76414cf11afSPaul Mackerras /* trap exception */ 765dc1c1ca3SStephen Rothwell if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP) 766dc1c1ca3SStephen Rothwell == NOTIFY_STOP) 767dc1c1ca3SStephen Rothwell return; 76814cf11afSPaul Mackerras if (debugger_bpt(regs)) 76914cf11afSPaul Mackerras return; 77073c9ceabSJeremy Fitzhardinge 77173c9ceabSJeremy Fitzhardinge if (!(regs->msr & MSR_PR) && /* not user-mode */ 772608e2619SHeiko Carstens report_bug(regs->nip, regs) == BUG_TRAP_TYPE_WARN) { 77314cf11afSPaul Mackerras regs->nip += 4; 77414cf11afSPaul Mackerras return; 77514cf11afSPaul Mackerras } 7768dad3f92SPaul Mackerras _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip); 7778dad3f92SPaul Mackerras return; 7788dad3f92SPaul Mackerras } 7798dad3f92SPaul Mackerras 780cd8a5673SPaul Mackerras local_irq_enable(); 781cd8a5673SPaul Mackerras 78204903a30SKumar Gala #ifdef CONFIG_MATH_EMULATION 78304903a30SKumar Gala /* (reason & REASON_ILLEGAL) would be the obvious thing here, 78404903a30SKumar Gala * but there seems to be a hardware bug on the 405GP (RevD) 78504903a30SKumar Gala * that means ESR is sometimes set incorrectly - either to 78604903a30SKumar Gala * ESR_DST (!?) or 0. In the process of chasing this with the 78704903a30SKumar Gala * hardware people - not sure if it can happen on any illegal 78804903a30SKumar Gala * instruction or only on FP instructions, whether there is a 78904903a30SKumar Gala * pattern to occurences etc. -dgibson 31/Mar/2003 */ 7905fad293bSKumar Gala switch (do_mathemu(regs)) { 7915fad293bSKumar Gala case 0: 79204903a30SKumar Gala emulate_single_step(regs); 79304903a30SKumar Gala return; 7945fad293bSKumar Gala case 1: { 7955fad293bSKumar Gala int code = 0; 7965fad293bSKumar Gala code = __parse_fpscr(current->thread.fpscr.val); 7975fad293bSKumar Gala _exception(SIGFPE, regs, code, regs->nip); 7985fad293bSKumar Gala return; 79904903a30SKumar Gala } 8005fad293bSKumar Gala case -EFAULT: 8015fad293bSKumar Gala _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip); 8025fad293bSKumar Gala return; 8035fad293bSKumar Gala } 8045fad293bSKumar Gala /* fall through on any other errors */ 80504903a30SKumar Gala #endif /* CONFIG_MATH_EMULATION */ 80604903a30SKumar Gala 8078dad3f92SPaul Mackerras /* Try to emulate it if we should. */ 8088dad3f92SPaul Mackerras if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED)) { 80914cf11afSPaul Mackerras switch (emulate_instruction(regs)) { 81014cf11afSPaul Mackerras case 0: 81114cf11afSPaul Mackerras regs->nip += 4; 81214cf11afSPaul Mackerras emulate_single_step(regs); 8138dad3f92SPaul Mackerras return; 81414cf11afSPaul Mackerras case -EFAULT: 81514cf11afSPaul Mackerras _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip); 8168dad3f92SPaul Mackerras return; 8178dad3f92SPaul Mackerras } 8188dad3f92SPaul Mackerras } 8198dad3f92SPaul Mackerras 82014cf11afSPaul Mackerras if (reason & REASON_PRIVILEGED) 82114cf11afSPaul Mackerras _exception(SIGILL, regs, ILL_PRVOPC, regs->nip); 82214cf11afSPaul Mackerras else 82314cf11afSPaul Mackerras _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 82414cf11afSPaul Mackerras } 82514cf11afSPaul Mackerras 826dc1c1ca3SStephen Rothwell void alignment_exception(struct pt_regs *regs) 82714cf11afSPaul Mackerras { 8284393c4f6SBenjamin Herrenschmidt int sig, code, fixed = 0; 82914cf11afSPaul Mackerras 830e9370ae1SPaul Mackerras /* we don't implement logging of alignment exceptions */ 831e9370ae1SPaul Mackerras if (!(current->thread.align_ctl & PR_UNALIGN_SIGBUS)) 83214cf11afSPaul Mackerras fixed = fix_alignment(regs); 83314cf11afSPaul Mackerras 83414cf11afSPaul Mackerras if (fixed == 1) { 83514cf11afSPaul Mackerras regs->nip += 4; /* skip over emulated instruction */ 83614cf11afSPaul Mackerras emulate_single_step(regs); 83714cf11afSPaul Mackerras return; 83814cf11afSPaul Mackerras } 83914cf11afSPaul Mackerras 84014cf11afSPaul Mackerras /* Operand address was bad */ 84114cf11afSPaul Mackerras if (fixed == -EFAULT) { 8424393c4f6SBenjamin Herrenschmidt sig = SIGSEGV; 8434393c4f6SBenjamin Herrenschmidt code = SEGV_ACCERR; 8444393c4f6SBenjamin Herrenschmidt } else { 8454393c4f6SBenjamin Herrenschmidt sig = SIGBUS; 8464393c4f6SBenjamin Herrenschmidt code = BUS_ADRALN; 84714cf11afSPaul Mackerras } 8484393c4f6SBenjamin Herrenschmidt if (user_mode(regs)) 8494393c4f6SBenjamin Herrenschmidt _exception(sig, regs, code, regs->dar); 8504393c4f6SBenjamin Herrenschmidt else 8514393c4f6SBenjamin Herrenschmidt bad_page_fault(regs, regs->dar, sig); 85214cf11afSPaul Mackerras } 85314cf11afSPaul Mackerras 85414cf11afSPaul Mackerras void StackOverflow(struct pt_regs *regs) 85514cf11afSPaul Mackerras { 85614cf11afSPaul Mackerras printk(KERN_CRIT "Kernel stack overflow in process %p, r1=%lx\n", 85714cf11afSPaul Mackerras current, regs->gpr[1]); 85814cf11afSPaul Mackerras debugger(regs); 85914cf11afSPaul Mackerras show_regs(regs); 86014cf11afSPaul Mackerras panic("kernel stack overflow"); 86114cf11afSPaul Mackerras } 86214cf11afSPaul Mackerras 86314cf11afSPaul Mackerras void nonrecoverable_exception(struct pt_regs *regs) 86414cf11afSPaul Mackerras { 86514cf11afSPaul Mackerras printk(KERN_ERR "Non-recoverable exception at PC=%lx MSR=%lx\n", 86614cf11afSPaul Mackerras regs->nip, regs->msr); 86714cf11afSPaul Mackerras debugger(regs); 86814cf11afSPaul Mackerras die("nonrecoverable exception", regs, SIGKILL); 86914cf11afSPaul Mackerras } 87014cf11afSPaul Mackerras 87114cf11afSPaul Mackerras void trace_syscall(struct pt_regs *regs) 87214cf11afSPaul Mackerras { 87314cf11afSPaul Mackerras printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n", 87414cf11afSPaul Mackerras current, current->pid, regs->nip, regs->link, regs->gpr[0], 87514cf11afSPaul Mackerras regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted()); 87614cf11afSPaul Mackerras } 87714cf11afSPaul Mackerras 878dc1c1ca3SStephen Rothwell void kernel_fp_unavailable_exception(struct pt_regs *regs) 879dc1c1ca3SStephen Rothwell { 880dc1c1ca3SStephen Rothwell printk(KERN_EMERG "Unrecoverable FP Unavailable Exception " 881dc1c1ca3SStephen Rothwell "%lx at %lx\n", regs->trap, regs->nip); 882dc1c1ca3SStephen Rothwell die("Unrecoverable FP Unavailable Exception", regs, SIGABRT); 883dc1c1ca3SStephen Rothwell } 884dc1c1ca3SStephen Rothwell 885dc1c1ca3SStephen Rothwell void altivec_unavailable_exception(struct pt_regs *regs) 886dc1c1ca3SStephen Rothwell { 887dc1c1ca3SStephen Rothwell if (user_mode(regs)) { 888dc1c1ca3SStephen Rothwell /* A user program has executed an altivec instruction, 889dc1c1ca3SStephen Rothwell but this kernel doesn't support altivec. */ 890dc1c1ca3SStephen Rothwell _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 891dc1c1ca3SStephen Rothwell return; 892dc1c1ca3SStephen Rothwell } 8936c4841c2SAnton Blanchard 894dc1c1ca3SStephen Rothwell printk(KERN_EMERG "Unrecoverable VMX/Altivec Unavailable Exception " 895dc1c1ca3SStephen Rothwell "%lx at %lx\n", regs->trap, regs->nip); 896dc1c1ca3SStephen Rothwell die("Unrecoverable VMX/Altivec Unavailable Exception", regs, SIGABRT); 897dc1c1ca3SStephen Rothwell } 898dc1c1ca3SStephen Rothwell 899dc1c1ca3SStephen Rothwell void performance_monitor_exception(struct pt_regs *regs) 900dc1c1ca3SStephen Rothwell { 901dc1c1ca3SStephen Rothwell perf_irq(regs); 902dc1c1ca3SStephen Rothwell } 903dc1c1ca3SStephen Rothwell 9048dad3f92SPaul Mackerras #ifdef CONFIG_8xx 90514cf11afSPaul Mackerras void SoftwareEmulation(struct pt_regs *regs) 90614cf11afSPaul Mackerras { 90714cf11afSPaul Mackerras extern int do_mathemu(struct pt_regs *); 90814cf11afSPaul Mackerras extern int Soft_emulate_8xx(struct pt_regs *); 909*5dd57a13SScott Wood #if defined(CONFIG_MATH_EMULATION) || defined(CONFIG_8XX_MINIMAL_FPEMU) 91014cf11afSPaul Mackerras int errcode; 911*5dd57a13SScott Wood #endif 91214cf11afSPaul Mackerras 91314cf11afSPaul Mackerras CHECK_FULL_REGS(regs); 91414cf11afSPaul Mackerras 91514cf11afSPaul Mackerras if (!user_mode(regs)) { 91614cf11afSPaul Mackerras debugger(regs); 91714cf11afSPaul Mackerras die("Kernel Mode Software FPU Emulation", regs, SIGFPE); 91814cf11afSPaul Mackerras } 91914cf11afSPaul Mackerras 92014cf11afSPaul Mackerras #ifdef CONFIG_MATH_EMULATION 92114cf11afSPaul Mackerras errcode = do_mathemu(regs); 9225fad293bSKumar Gala 9235fad293bSKumar Gala switch (errcode) { 9245fad293bSKumar Gala case 0: 9255fad293bSKumar Gala emulate_single_step(regs); 9265fad293bSKumar Gala return; 9275fad293bSKumar Gala case 1: { 9285fad293bSKumar Gala int code = 0; 9295fad293bSKumar Gala code = __parse_fpscr(current->thread.fpscr.val); 9305fad293bSKumar Gala _exception(SIGFPE, regs, code, regs->nip); 9315fad293bSKumar Gala return; 9325fad293bSKumar Gala } 9335fad293bSKumar Gala case -EFAULT: 9345fad293bSKumar Gala _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip); 9355fad293bSKumar Gala return; 9365fad293bSKumar Gala default: 9375fad293bSKumar Gala _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 9385fad293bSKumar Gala return; 9395fad293bSKumar Gala } 9405fad293bSKumar Gala 941*5dd57a13SScott Wood #elif defined(CONFIG_8XX_MINIMAL_FPEMU) 94214cf11afSPaul Mackerras errcode = Soft_emulate_8xx(regs); 9435fad293bSKumar Gala switch (errcode) { 9445fad293bSKumar Gala case 0: 94514cf11afSPaul Mackerras emulate_single_step(regs); 9465fad293bSKumar Gala return; 9475fad293bSKumar Gala case 1: 9485fad293bSKumar Gala _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 9495fad293bSKumar Gala return; 9505fad293bSKumar Gala case -EFAULT: 9515fad293bSKumar Gala _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip); 9525fad293bSKumar Gala return; 9535fad293bSKumar Gala } 954*5dd57a13SScott Wood #else 955*5dd57a13SScott Wood _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 9565fad293bSKumar Gala #endif 95714cf11afSPaul Mackerras } 9588dad3f92SPaul Mackerras #endif /* CONFIG_8xx */ 95914cf11afSPaul Mackerras 96014cf11afSPaul Mackerras #if defined(CONFIG_40x) || defined(CONFIG_BOOKE) 96114cf11afSPaul Mackerras 96214cf11afSPaul Mackerras void DebugException(struct pt_regs *regs, unsigned long debug_status) 96314cf11afSPaul Mackerras { 96414cf11afSPaul Mackerras if (debug_status & DBSR_IC) { /* instruction completion */ 96514cf11afSPaul Mackerras regs->msr &= ~MSR_DE; 96614cf11afSPaul Mackerras if (user_mode(regs)) { 96714cf11afSPaul Mackerras current->thread.dbcr0 &= ~DBCR0_IC; 96814cf11afSPaul Mackerras } else { 96914cf11afSPaul Mackerras /* Disable instruction completion */ 97014cf11afSPaul Mackerras mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_IC); 97114cf11afSPaul Mackerras /* Clear the instruction completion event */ 97214cf11afSPaul Mackerras mtspr(SPRN_DBSR, DBSR_IC); 97314cf11afSPaul Mackerras if (debugger_sstep(regs)) 97414cf11afSPaul Mackerras return; 97514cf11afSPaul Mackerras } 97614cf11afSPaul Mackerras _exception(SIGTRAP, regs, TRAP_TRACE, 0); 97714cf11afSPaul Mackerras } 97814cf11afSPaul Mackerras } 97914cf11afSPaul Mackerras #endif /* CONFIG_4xx || CONFIG_BOOKE */ 98014cf11afSPaul Mackerras 98114cf11afSPaul Mackerras #if !defined(CONFIG_TAU_INT) 98214cf11afSPaul Mackerras void TAUException(struct pt_regs *regs) 98314cf11afSPaul Mackerras { 98414cf11afSPaul Mackerras printk("TAU trap at PC: %lx, MSR: %lx, vector=%lx %s\n", 98514cf11afSPaul Mackerras regs->nip, regs->msr, regs->trap, print_tainted()); 98614cf11afSPaul Mackerras } 98714cf11afSPaul Mackerras #endif /* CONFIG_INT_TAU */ 98814cf11afSPaul Mackerras 98914cf11afSPaul Mackerras #ifdef CONFIG_ALTIVEC 990dc1c1ca3SStephen Rothwell void altivec_assist_exception(struct pt_regs *regs) 99114cf11afSPaul Mackerras { 99214cf11afSPaul Mackerras int err; 99314cf11afSPaul Mackerras 99414cf11afSPaul Mackerras if (!user_mode(regs)) { 99514cf11afSPaul Mackerras printk(KERN_EMERG "VMX/Altivec assist exception in kernel mode" 99614cf11afSPaul Mackerras " at %lx\n", regs->nip); 9978dad3f92SPaul Mackerras die("Kernel VMX/Altivec assist exception", regs, SIGILL); 99814cf11afSPaul Mackerras } 99914cf11afSPaul Mackerras 1000dc1c1ca3SStephen Rothwell flush_altivec_to_thread(current); 1001dc1c1ca3SStephen Rothwell 100214cf11afSPaul Mackerras err = emulate_altivec(regs); 100314cf11afSPaul Mackerras if (err == 0) { 100414cf11afSPaul Mackerras regs->nip += 4; /* skip emulated instruction */ 100514cf11afSPaul Mackerras emulate_single_step(regs); 100614cf11afSPaul Mackerras return; 100714cf11afSPaul Mackerras } 100814cf11afSPaul Mackerras 100914cf11afSPaul Mackerras if (err == -EFAULT) { 101014cf11afSPaul Mackerras /* got an error reading the instruction */ 101114cf11afSPaul Mackerras _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip); 101214cf11afSPaul Mackerras } else { 101314cf11afSPaul Mackerras /* didn't recognize the instruction */ 101414cf11afSPaul Mackerras /* XXX quick hack for now: set the non-Java bit in the VSCR */ 101514cf11afSPaul Mackerras if (printk_ratelimit()) 101614cf11afSPaul Mackerras printk(KERN_ERR "Unrecognized altivec instruction " 101714cf11afSPaul Mackerras "in %s at %lx\n", current->comm, regs->nip); 101814cf11afSPaul Mackerras current->thread.vscr.u[3] |= 0x10000; 101914cf11afSPaul Mackerras } 102014cf11afSPaul Mackerras } 102114cf11afSPaul Mackerras #endif /* CONFIG_ALTIVEC */ 102214cf11afSPaul Mackerras 102314cf11afSPaul Mackerras #ifdef CONFIG_FSL_BOOKE 102414cf11afSPaul Mackerras void CacheLockingException(struct pt_regs *regs, unsigned long address, 102514cf11afSPaul Mackerras unsigned long error_code) 102614cf11afSPaul Mackerras { 102714cf11afSPaul Mackerras /* We treat cache locking instructions from the user 102814cf11afSPaul Mackerras * as priv ops, in the future we could try to do 102914cf11afSPaul Mackerras * something smarter 103014cf11afSPaul Mackerras */ 103114cf11afSPaul Mackerras if (error_code & (ESR_DLK|ESR_ILK)) 103214cf11afSPaul Mackerras _exception(SIGILL, regs, ILL_PRVOPC, regs->nip); 103314cf11afSPaul Mackerras return; 103414cf11afSPaul Mackerras } 103514cf11afSPaul Mackerras #endif /* CONFIG_FSL_BOOKE */ 103614cf11afSPaul Mackerras 103714cf11afSPaul Mackerras #ifdef CONFIG_SPE 103814cf11afSPaul Mackerras void SPEFloatingPointException(struct pt_regs *regs) 103914cf11afSPaul Mackerras { 104014cf11afSPaul Mackerras unsigned long spefscr; 104114cf11afSPaul Mackerras int fpexc_mode; 104214cf11afSPaul Mackerras int code = 0; 104314cf11afSPaul Mackerras 104414cf11afSPaul Mackerras spefscr = current->thread.spefscr; 104514cf11afSPaul Mackerras fpexc_mode = current->thread.fpexc_mode; 104614cf11afSPaul Mackerras 104714cf11afSPaul Mackerras /* Hardware does not neccessarily set sticky 104814cf11afSPaul Mackerras * underflow/overflow/invalid flags */ 104914cf11afSPaul Mackerras if ((spefscr & SPEFSCR_FOVF) && (fpexc_mode & PR_FP_EXC_OVF)) { 105014cf11afSPaul Mackerras code = FPE_FLTOVF; 105114cf11afSPaul Mackerras spefscr |= SPEFSCR_FOVFS; 105214cf11afSPaul Mackerras } 105314cf11afSPaul Mackerras else if ((spefscr & SPEFSCR_FUNF) && (fpexc_mode & PR_FP_EXC_UND)) { 105414cf11afSPaul Mackerras code = FPE_FLTUND; 105514cf11afSPaul Mackerras spefscr |= SPEFSCR_FUNFS; 105614cf11afSPaul Mackerras } 105714cf11afSPaul Mackerras else if ((spefscr & SPEFSCR_FDBZ) && (fpexc_mode & PR_FP_EXC_DIV)) 105814cf11afSPaul Mackerras code = FPE_FLTDIV; 105914cf11afSPaul Mackerras else if ((spefscr & SPEFSCR_FINV) && (fpexc_mode & PR_FP_EXC_INV)) { 106014cf11afSPaul Mackerras code = FPE_FLTINV; 106114cf11afSPaul Mackerras spefscr |= SPEFSCR_FINVS; 106214cf11afSPaul Mackerras } 106314cf11afSPaul Mackerras else if ((spefscr & (SPEFSCR_FG | SPEFSCR_FX)) && (fpexc_mode & PR_FP_EXC_RES)) 106414cf11afSPaul Mackerras code = FPE_FLTRES; 106514cf11afSPaul Mackerras 106614cf11afSPaul Mackerras current->thread.spefscr = spefscr; 106714cf11afSPaul Mackerras 106814cf11afSPaul Mackerras _exception(SIGFPE, regs, code, regs->nip); 106914cf11afSPaul Mackerras return; 107014cf11afSPaul Mackerras } 107114cf11afSPaul Mackerras #endif 107214cf11afSPaul Mackerras 1073dc1c1ca3SStephen Rothwell /* 1074dc1c1ca3SStephen Rothwell * We enter here if we get an unrecoverable exception, that is, one 1075dc1c1ca3SStephen Rothwell * that happened at a point where the RI (recoverable interrupt) bit 1076dc1c1ca3SStephen Rothwell * in the MSR is 0. This indicates that SRR0/1 are live, and that 1077dc1c1ca3SStephen Rothwell * we therefore lost state by taking this exception. 1078dc1c1ca3SStephen Rothwell */ 1079dc1c1ca3SStephen Rothwell void unrecoverable_exception(struct pt_regs *regs) 1080dc1c1ca3SStephen Rothwell { 1081dc1c1ca3SStephen Rothwell printk(KERN_EMERG "Unrecoverable exception %lx at %lx\n", 1082dc1c1ca3SStephen Rothwell regs->trap, regs->nip); 1083dc1c1ca3SStephen Rothwell die("Unrecoverable exception", regs, SIGABRT); 1084dc1c1ca3SStephen Rothwell } 1085dc1c1ca3SStephen Rothwell 108614cf11afSPaul Mackerras #ifdef CONFIG_BOOKE_WDT 108714cf11afSPaul Mackerras /* 108814cf11afSPaul Mackerras * Default handler for a Watchdog exception, 108914cf11afSPaul Mackerras * spins until a reboot occurs 109014cf11afSPaul Mackerras */ 109114cf11afSPaul Mackerras void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs) 109214cf11afSPaul Mackerras { 109314cf11afSPaul Mackerras /* Generic WatchdogHandler, implement your own */ 109414cf11afSPaul Mackerras mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE)); 109514cf11afSPaul Mackerras return; 109614cf11afSPaul Mackerras } 109714cf11afSPaul Mackerras 109814cf11afSPaul Mackerras void WatchdogException(struct pt_regs *regs) 109914cf11afSPaul Mackerras { 110014cf11afSPaul Mackerras printk (KERN_EMERG "PowerPC Book-E Watchdog Exception\n"); 110114cf11afSPaul Mackerras WatchdogHandler(regs); 110214cf11afSPaul Mackerras } 110314cf11afSPaul Mackerras #endif 1104dc1c1ca3SStephen Rothwell 1105dc1c1ca3SStephen Rothwell /* 1106dc1c1ca3SStephen Rothwell * We enter here if we discover during exception entry that we are 1107dc1c1ca3SStephen Rothwell * running in supervisor mode with a userspace value in the stack pointer. 1108dc1c1ca3SStephen Rothwell */ 1109dc1c1ca3SStephen Rothwell void kernel_bad_stack(struct pt_regs *regs) 1110dc1c1ca3SStephen Rothwell { 1111dc1c1ca3SStephen Rothwell printk(KERN_EMERG "Bad kernel stack pointer %lx at %lx\n", 1112dc1c1ca3SStephen Rothwell regs->gpr[1], regs->nip); 1113dc1c1ca3SStephen Rothwell die("Bad kernel stack pointer", regs, SIGABRT); 1114dc1c1ca3SStephen Rothwell } 111514cf11afSPaul Mackerras 111614cf11afSPaul Mackerras void __init trap_init(void) 111714cf11afSPaul Mackerras { 111814cf11afSPaul Mackerras } 1119