114cf11afSPaul Mackerras /* 214cf11afSPaul Mackerras * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) 3fe04b112SScott Wood * Copyright 2007-2010 Freescale Semiconductor, Inc. 414cf11afSPaul Mackerras * 514cf11afSPaul Mackerras * This program is free software; you can redistribute it and/or 614cf11afSPaul Mackerras * modify it under the terms of the GNU General Public License 714cf11afSPaul Mackerras * as published by the Free Software Foundation; either version 814cf11afSPaul Mackerras * 2 of the License, or (at your option) any later version. 914cf11afSPaul Mackerras * 1014cf11afSPaul Mackerras * Modified by Cort Dougan (cort@cs.nmt.edu) 1114cf11afSPaul Mackerras * and Paul Mackerras (paulus@samba.org) 1214cf11afSPaul Mackerras */ 1314cf11afSPaul Mackerras 1414cf11afSPaul Mackerras /* 1514cf11afSPaul Mackerras * This file handles the architecture-dependent parts of hardware exceptions 1614cf11afSPaul Mackerras */ 1714cf11afSPaul Mackerras 1814cf11afSPaul Mackerras #include <linux/errno.h> 1914cf11afSPaul Mackerras #include <linux/sched.h> 2014cf11afSPaul Mackerras #include <linux/kernel.h> 2114cf11afSPaul Mackerras #include <linux/mm.h> 2214cf11afSPaul Mackerras #include <linux/stddef.h> 2314cf11afSPaul Mackerras #include <linux/unistd.h> 248dad3f92SPaul Mackerras #include <linux/ptrace.h> 2514cf11afSPaul Mackerras #include <linux/user.h> 2614cf11afSPaul Mackerras #include <linux/interrupt.h> 2714cf11afSPaul Mackerras #include <linux/init.h> 2814cf11afSPaul Mackerras #include <linux/module.h> 298dad3f92SPaul Mackerras #include <linux/prctl.h> 3014cf11afSPaul Mackerras #include <linux/delay.h> 3114cf11afSPaul Mackerras #include <linux/kprobes.h> 32cc532915SMichael Ellerman #include <linux/kexec.h> 335474c120SMichael Hanselmann #include <linux/backlight.h> 3473c9ceabSJeremy Fitzhardinge #include <linux/bug.h> 351eeb66a1SChristoph Hellwig #include <linux/kdebug.h> 3680947e7cSGeert Uytterhoeven #include <linux/debugfs.h> 3776462232SChristian Dietrich #include <linux/ratelimit.h> 3814cf11afSPaul Mackerras 3980947e7cSGeert Uytterhoeven #include <asm/emulated_ops.h> 4014cf11afSPaul Mackerras #include <asm/pgtable.h> 4114cf11afSPaul Mackerras #include <asm/uaccess.h> 4214cf11afSPaul Mackerras #include <asm/io.h> 4386417780SPaul Mackerras #include <asm/machdep.h> 4486417780SPaul Mackerras #include <asm/rtas.h> 45f7f6f4feSDavid Gibson #include <asm/pmc.h> 46dc1c1ca3SStephen Rothwell #ifdef CONFIG_PPC32 4714cf11afSPaul Mackerras #include <asm/reg.h> 4886417780SPaul Mackerras #endif 4914cf11afSPaul Mackerras #ifdef CONFIG_PMAC_BACKLIGHT 5014cf11afSPaul Mackerras #include <asm/backlight.h> 5114cf11afSPaul Mackerras #endif 52dc1c1ca3SStephen Rothwell #ifdef CONFIG_PPC64 5386417780SPaul Mackerras #include <asm/firmware.h> 54dc1c1ca3SStephen Rothwell #include <asm/processor.h> 55dc1c1ca3SStephen Rothwell #endif 56c0ce7d08SDavid Wilder #include <asm/kexec.h> 5716c57b36SKumar Gala #include <asm/ppc-opcode.h> 58cce1f106SShaohui Xie #include <asm/rio.h> 59ebaeb5aeSMahesh Salgaonkar #include <asm/fadump.h> 60ae3a197eSDavid Howells #include <asm/switch_to.h> 61ae3a197eSDavid Howells #include <asm/debug.h> 62dc1c1ca3SStephen Rothwell 637dbb922cSOlof Johansson #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC) 645be3492fSAnton Blanchard int (*__debugger)(struct pt_regs *regs) __read_mostly; 655be3492fSAnton Blanchard int (*__debugger_ipi)(struct pt_regs *regs) __read_mostly; 665be3492fSAnton Blanchard int (*__debugger_bpt)(struct pt_regs *regs) __read_mostly; 675be3492fSAnton Blanchard int (*__debugger_sstep)(struct pt_regs *regs) __read_mostly; 685be3492fSAnton Blanchard int (*__debugger_iabr_match)(struct pt_regs *regs) __read_mostly; 695be3492fSAnton Blanchard int (*__debugger_dabr_match)(struct pt_regs *regs) __read_mostly; 705be3492fSAnton Blanchard int (*__debugger_fault_handler)(struct pt_regs *regs) __read_mostly; 7114cf11afSPaul Mackerras 7214cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger); 7314cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_ipi); 7414cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_bpt); 7514cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_sstep); 7614cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_iabr_match); 7714cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_dabr_match); 7814cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_fault_handler); 7914cf11afSPaul Mackerras #endif 8014cf11afSPaul Mackerras 8114cf11afSPaul Mackerras /* 8214cf11afSPaul Mackerras * Trap & Exception support 8314cf11afSPaul Mackerras */ 8414cf11afSPaul Mackerras 856031d9d9Santon@samba.org #ifdef CONFIG_PMAC_BACKLIGHT 866031d9d9Santon@samba.org static void pmac_backlight_unblank(void) 876031d9d9Santon@samba.org { 886031d9d9Santon@samba.org mutex_lock(&pmac_backlight_mutex); 896031d9d9Santon@samba.org if (pmac_backlight) { 906031d9d9Santon@samba.org struct backlight_properties *props; 916031d9d9Santon@samba.org 926031d9d9Santon@samba.org props = &pmac_backlight->props; 936031d9d9Santon@samba.org props->brightness = props->max_brightness; 946031d9d9Santon@samba.org props->power = FB_BLANK_UNBLANK; 956031d9d9Santon@samba.org backlight_update_status(pmac_backlight); 966031d9d9Santon@samba.org } 976031d9d9Santon@samba.org mutex_unlock(&pmac_backlight_mutex); 986031d9d9Santon@samba.org } 996031d9d9Santon@samba.org #else 1006031d9d9Santon@samba.org static inline void pmac_backlight_unblank(void) { } 1016031d9d9Santon@samba.org #endif 1026031d9d9Santon@samba.org 103760ca4dcSAnton Blanchard static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED; 104760ca4dcSAnton Blanchard static int die_owner = -1; 105760ca4dcSAnton Blanchard static unsigned int die_nest_count; 106c0ce7d08SDavid Wilder static int die_counter; 107760ca4dcSAnton Blanchard 108760ca4dcSAnton Blanchard static unsigned __kprobes long oops_begin(struct pt_regs *regs) 109760ca4dcSAnton Blanchard { 110760ca4dcSAnton Blanchard int cpu; 11134c2a14fSanton@samba.org unsigned long flags; 11214cf11afSPaul Mackerras 11314cf11afSPaul Mackerras if (debugger(regs)) 11414cf11afSPaul Mackerras return 1; 11514cf11afSPaul Mackerras 116293e4688Santon@samba.org oops_enter(); 117293e4688Santon@samba.org 118760ca4dcSAnton Blanchard /* racy, but better than risking deadlock. */ 119760ca4dcSAnton Blanchard raw_local_irq_save(flags); 120760ca4dcSAnton Blanchard cpu = smp_processor_id(); 121760ca4dcSAnton Blanchard if (!arch_spin_trylock(&die_lock)) { 122760ca4dcSAnton Blanchard if (cpu == die_owner) 123760ca4dcSAnton Blanchard /* nested oops. should stop eventually */; 124760ca4dcSAnton Blanchard else 125760ca4dcSAnton Blanchard arch_spin_lock(&die_lock); 126760ca4dcSAnton Blanchard } 127760ca4dcSAnton Blanchard die_nest_count++; 128760ca4dcSAnton Blanchard die_owner = cpu; 12914cf11afSPaul Mackerras console_verbose(); 13014cf11afSPaul Mackerras bust_spinlocks(1); 1316031d9d9Santon@samba.org if (machine_is(powermac)) 1326031d9d9Santon@samba.org pmac_backlight_unblank(); 133760ca4dcSAnton Blanchard return flags; 13434c2a14fSanton@samba.org } 1355474c120SMichael Hanselmann 136760ca4dcSAnton Blanchard static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, 137760ca4dcSAnton Blanchard int signr) 138760ca4dcSAnton Blanchard { 13914cf11afSPaul Mackerras bust_spinlocks(0); 140760ca4dcSAnton Blanchard die_owner = -1; 141bcdcd8e7SPavel Emelianov add_taint(TAINT_DIE); 142760ca4dcSAnton Blanchard die_nest_count--; 14358154c8cSAnton Blanchard oops_exit(); 14458154c8cSAnton Blanchard printk("\n"); 145760ca4dcSAnton Blanchard if (!die_nest_count) 146760ca4dcSAnton Blanchard /* Nest count reaches zero, release the lock. */ 147760ca4dcSAnton Blanchard arch_spin_unlock(&die_lock); 148760ca4dcSAnton Blanchard raw_local_irq_restore(flags); 149cc532915SMichael Ellerman 150ebaeb5aeSMahesh Salgaonkar crash_fadump(regs, "die oops"); 151ebaeb5aeSMahesh Salgaonkar 1529b00ac06SAnton Blanchard /* 1539b00ac06SAnton Blanchard * A system reset (0x100) is a request to dump, so we always send 1549b00ac06SAnton Blanchard * it through the crashdump code. 1559b00ac06SAnton Blanchard */ 1569b00ac06SAnton Blanchard if (kexec_should_crash(current) || (TRAP(regs) == 0x100)) { 157cc532915SMichael Ellerman crash_kexec(regs); 1589b00ac06SAnton Blanchard 1599b00ac06SAnton Blanchard /* 1609b00ac06SAnton Blanchard * We aren't the primary crash CPU. We need to send it 1619b00ac06SAnton Blanchard * to a holding pattern to avoid it ending up in the panic 1629b00ac06SAnton Blanchard * code. 1639b00ac06SAnton Blanchard */ 164c0ce7d08SDavid Wilder crash_kexec_secondary(regs); 1659b00ac06SAnton Blanchard } 16614cf11afSPaul Mackerras 167760ca4dcSAnton Blanchard if (!signr) 168760ca4dcSAnton Blanchard return; 169760ca4dcSAnton Blanchard 17058154c8cSAnton Blanchard /* 17158154c8cSAnton Blanchard * While our oops output is serialised by a spinlock, output 17258154c8cSAnton Blanchard * from panic() called below can race and corrupt it. If we 17358154c8cSAnton Blanchard * know we are going to panic, delay for 1 second so we have a 17458154c8cSAnton Blanchard * chance to get clean backtraces from all CPUs that are oopsing. 17558154c8cSAnton Blanchard */ 17658154c8cSAnton Blanchard if (in_interrupt() || panic_on_oops || !current->pid || 17758154c8cSAnton Blanchard is_global_init(current)) { 17858154c8cSAnton Blanchard mdelay(MSEC_PER_SEC); 17958154c8cSAnton Blanchard } 18058154c8cSAnton Blanchard 18114cf11afSPaul Mackerras if (in_interrupt()) 18214cf11afSPaul Mackerras panic("Fatal exception in interrupt"); 183cea6a4baSHorms if (panic_on_oops) 184012c437dSHorms panic("Fatal exception"); 185760ca4dcSAnton Blanchard do_exit(signr); 186760ca4dcSAnton Blanchard } 187cea6a4baSHorms 188760ca4dcSAnton Blanchard static int __kprobes __die(const char *str, struct pt_regs *regs, long err) 189760ca4dcSAnton Blanchard { 190760ca4dcSAnton Blanchard printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter); 191760ca4dcSAnton Blanchard #ifdef CONFIG_PREEMPT 192760ca4dcSAnton Blanchard printk("PREEMPT "); 193760ca4dcSAnton Blanchard #endif 194760ca4dcSAnton Blanchard #ifdef CONFIG_SMP 195760ca4dcSAnton Blanchard printk("SMP NR_CPUS=%d ", NR_CPUS); 196760ca4dcSAnton Blanchard #endif 197760ca4dcSAnton Blanchard #ifdef CONFIG_DEBUG_PAGEALLOC 198760ca4dcSAnton Blanchard printk("DEBUG_PAGEALLOC "); 199760ca4dcSAnton Blanchard #endif 200760ca4dcSAnton Blanchard #ifdef CONFIG_NUMA 201760ca4dcSAnton Blanchard printk("NUMA "); 202760ca4dcSAnton Blanchard #endif 203760ca4dcSAnton Blanchard printk("%s\n", ppc_md.name ? ppc_md.name : ""); 204760ca4dcSAnton Blanchard 205760ca4dcSAnton Blanchard if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV) == NOTIFY_STOP) 206760ca4dcSAnton Blanchard return 1; 207760ca4dcSAnton Blanchard 208760ca4dcSAnton Blanchard print_modules(); 209760ca4dcSAnton Blanchard show_regs(regs); 21014cf11afSPaul Mackerras 21114cf11afSPaul Mackerras return 0; 21214cf11afSPaul Mackerras } 21314cf11afSPaul Mackerras 214760ca4dcSAnton Blanchard void die(const char *str, struct pt_regs *regs, long err) 215760ca4dcSAnton Blanchard { 216760ca4dcSAnton Blanchard unsigned long flags = oops_begin(regs); 217760ca4dcSAnton Blanchard 218760ca4dcSAnton Blanchard if (__die(str, regs, err)) 219760ca4dcSAnton Blanchard err = 0; 220760ca4dcSAnton Blanchard oops_end(flags, regs, err); 221760ca4dcSAnton Blanchard } 222760ca4dcSAnton Blanchard 22325baa35bSOleg Nesterov void user_single_step_siginfo(struct task_struct *tsk, 22425baa35bSOleg Nesterov struct pt_regs *regs, siginfo_t *info) 22525baa35bSOleg Nesterov { 22625baa35bSOleg Nesterov memset(info, 0, sizeof(*info)); 22725baa35bSOleg Nesterov info->si_signo = SIGTRAP; 22825baa35bSOleg Nesterov info->si_code = TRAP_TRACE; 22925baa35bSOleg Nesterov info->si_addr = (void __user *)regs->nip; 23025baa35bSOleg Nesterov } 23125baa35bSOleg Nesterov 23214cf11afSPaul Mackerras void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr) 23314cf11afSPaul Mackerras { 23414cf11afSPaul Mackerras siginfo_t info; 235d0c3d534SOlof Johansson const char fmt32[] = KERN_INFO "%s[%d]: unhandled signal %d " \ 236d0c3d534SOlof Johansson "at %08lx nip %08lx lr %08lx code %x\n"; 237d0c3d534SOlof Johansson const char fmt64[] = KERN_INFO "%s[%d]: unhandled signal %d " \ 238d0c3d534SOlof Johansson "at %016lx nip %016lx lr %016lx code %x\n"; 23914cf11afSPaul Mackerras 24014cf11afSPaul Mackerras if (!user_mode(regs)) { 241760ca4dcSAnton Blanchard die("Exception in kernel mode", regs, signr); 24214cf11afSPaul Mackerras return; 243760ca4dcSAnton Blanchard } 244760ca4dcSAnton Blanchard 245760ca4dcSAnton Blanchard if (show_unhandled_signals && unhandled_signal(current, signr)) { 24676462232SChristian Dietrich printk_ratelimited(regs->msr & MSR_64BIT ? fmt64 : fmt32, 247d0c3d534SOlof Johansson current->comm, current->pid, signr, 248d0c3d534SOlof Johansson addr, regs->nip, regs->link, code); 24914cf11afSPaul Mackerras } 25014cf11afSPaul Mackerras 251a3512b2dSBenjamin Herrenschmidt if (arch_irqs_disabled() && !arch_irq_disabled_regs(regs)) 2529f2f79e3SBenjamin Herrenschmidt local_irq_enable(); 2539f2f79e3SBenjamin Herrenschmidt 25441ab5266SAnanth N Mavinakayanahalli current->thread.trap_nr = code; 25514cf11afSPaul Mackerras memset(&info, 0, sizeof(info)); 25614cf11afSPaul Mackerras info.si_signo = signr; 25714cf11afSPaul Mackerras info.si_code = code; 25814cf11afSPaul Mackerras info.si_addr = (void __user *) addr; 25914cf11afSPaul Mackerras force_sig_info(signr, &info, current); 26014cf11afSPaul Mackerras } 26114cf11afSPaul Mackerras 26214cf11afSPaul Mackerras #ifdef CONFIG_PPC64 26314cf11afSPaul Mackerras void system_reset_exception(struct pt_regs *regs) 26414cf11afSPaul Mackerras { 26514cf11afSPaul Mackerras /* See if any machine dependent calls */ 266c902be71SArnd Bergmann if (ppc_md.system_reset_exception) { 267c902be71SArnd Bergmann if (ppc_md.system_reset_exception(regs)) 268c902be71SArnd Bergmann return; 269c902be71SArnd Bergmann } 27014cf11afSPaul Mackerras 2718dad3f92SPaul Mackerras die("System Reset", regs, SIGABRT); 27214cf11afSPaul Mackerras 27314cf11afSPaul Mackerras /* Must die if the interrupt is not recoverable */ 27414cf11afSPaul Mackerras if (!(regs->msr & MSR_RI)) 27514cf11afSPaul Mackerras panic("Unrecoverable System Reset"); 27614cf11afSPaul Mackerras 27714cf11afSPaul Mackerras /* What should we do here? We could issue a shutdown or hard reset. */ 27814cf11afSPaul Mackerras } 27914cf11afSPaul Mackerras #endif 28014cf11afSPaul Mackerras 28114cf11afSPaul Mackerras /* 28214cf11afSPaul Mackerras * I/O accesses can cause machine checks on powermacs. 28314cf11afSPaul Mackerras * Check if the NIP corresponds to the address of a sync 28414cf11afSPaul Mackerras * instruction for which there is an entry in the exception 28514cf11afSPaul Mackerras * table. 28614cf11afSPaul Mackerras * Note that the 601 only takes a machine check on TEA 28714cf11afSPaul Mackerras * (transfer error ack) signal assertion, and does not 28814cf11afSPaul Mackerras * set any of the top 16 bits of SRR1. 28914cf11afSPaul Mackerras * -- paulus. 29014cf11afSPaul Mackerras */ 29114cf11afSPaul Mackerras static inline int check_io_access(struct pt_regs *regs) 29214cf11afSPaul Mackerras { 29368a64357SBenjamin Herrenschmidt #ifdef CONFIG_PPC32 29414cf11afSPaul Mackerras unsigned long msr = regs->msr; 29514cf11afSPaul Mackerras const struct exception_table_entry *entry; 29614cf11afSPaul Mackerras unsigned int *nip = (unsigned int *)regs->nip; 29714cf11afSPaul Mackerras 29814cf11afSPaul Mackerras if (((msr & 0xffff0000) == 0 || (msr & (0x80000 | 0x40000))) 29914cf11afSPaul Mackerras && (entry = search_exception_tables(regs->nip)) != NULL) { 30014cf11afSPaul Mackerras /* 30114cf11afSPaul Mackerras * Check that it's a sync instruction, or somewhere 30214cf11afSPaul Mackerras * in the twi; isync; nop sequence that inb/inw/inl uses. 30314cf11afSPaul Mackerras * As the address is in the exception table 30414cf11afSPaul Mackerras * we should be able to read the instr there. 30514cf11afSPaul Mackerras * For the debug message, we look at the preceding 30614cf11afSPaul Mackerras * load or store. 30714cf11afSPaul Mackerras */ 30814cf11afSPaul Mackerras if (*nip == 0x60000000) /* nop */ 30914cf11afSPaul Mackerras nip -= 2; 31014cf11afSPaul Mackerras else if (*nip == 0x4c00012c) /* isync */ 31114cf11afSPaul Mackerras --nip; 31214cf11afSPaul Mackerras if (*nip == 0x7c0004ac || (*nip >> 26) == 3) { 31314cf11afSPaul Mackerras /* sync or twi */ 31414cf11afSPaul Mackerras unsigned int rb; 31514cf11afSPaul Mackerras 31614cf11afSPaul Mackerras --nip; 31714cf11afSPaul Mackerras rb = (*nip >> 11) & 0x1f; 31814cf11afSPaul Mackerras printk(KERN_DEBUG "%s bad port %lx at %p\n", 31914cf11afSPaul Mackerras (*nip & 0x100)? "OUT to": "IN from", 32014cf11afSPaul Mackerras regs->gpr[rb] - _IO_BASE, nip); 32114cf11afSPaul Mackerras regs->msr |= MSR_RI; 32214cf11afSPaul Mackerras regs->nip = entry->fixup; 32314cf11afSPaul Mackerras return 1; 32414cf11afSPaul Mackerras } 32514cf11afSPaul Mackerras } 32668a64357SBenjamin Herrenschmidt #endif /* CONFIG_PPC32 */ 32714cf11afSPaul Mackerras return 0; 32814cf11afSPaul Mackerras } 32914cf11afSPaul Mackerras 330172ae2e7SDave Kleikamp #ifdef CONFIG_PPC_ADV_DEBUG_REGS 33114cf11afSPaul Mackerras /* On 4xx, the reason for the machine check or program exception 33214cf11afSPaul Mackerras is in the ESR. */ 33314cf11afSPaul Mackerras #define get_reason(regs) ((regs)->dsisr) 33414cf11afSPaul Mackerras #ifndef CONFIG_FSL_BOOKE 33514cf11afSPaul Mackerras #define get_mc_reason(regs) ((regs)->dsisr) 33614cf11afSPaul Mackerras #else 337fe04b112SScott Wood #define get_mc_reason(regs) (mfspr(SPRN_MCSR)) 33814cf11afSPaul Mackerras #endif 33914cf11afSPaul Mackerras #define REASON_FP ESR_FP 34014cf11afSPaul Mackerras #define REASON_ILLEGAL (ESR_PIL | ESR_PUO) 34114cf11afSPaul Mackerras #define REASON_PRIVILEGED ESR_PPR 34214cf11afSPaul Mackerras #define REASON_TRAP ESR_PTR 34314cf11afSPaul Mackerras 34414cf11afSPaul Mackerras /* single-step stuff */ 34514cf11afSPaul Mackerras #define single_stepping(regs) (current->thread.dbcr0 & DBCR0_IC) 34614cf11afSPaul Mackerras #define clear_single_step(regs) (current->thread.dbcr0 &= ~DBCR0_IC) 34714cf11afSPaul Mackerras 34814cf11afSPaul Mackerras #else 34914cf11afSPaul Mackerras /* On non-4xx, the reason for the machine check or program 35014cf11afSPaul Mackerras exception is in the MSR. */ 35114cf11afSPaul Mackerras #define get_reason(regs) ((regs)->msr) 35214cf11afSPaul Mackerras #define get_mc_reason(regs) ((regs)->msr) 35314cf11afSPaul Mackerras #define REASON_FP 0x100000 35414cf11afSPaul Mackerras #define REASON_ILLEGAL 0x80000 35514cf11afSPaul Mackerras #define REASON_PRIVILEGED 0x40000 35614cf11afSPaul Mackerras #define REASON_TRAP 0x20000 35714cf11afSPaul Mackerras 35814cf11afSPaul Mackerras #define single_stepping(regs) ((regs)->msr & MSR_SE) 35914cf11afSPaul Mackerras #define clear_single_step(regs) ((regs)->msr &= ~MSR_SE) 36014cf11afSPaul Mackerras #endif 36114cf11afSPaul Mackerras 36247c0bd1aSBenjamin Herrenschmidt #if defined(CONFIG_4xx) 36347c0bd1aSBenjamin Herrenschmidt int machine_check_4xx(struct pt_regs *regs) 36414cf11afSPaul Mackerras { 3651a6a4ffeSKumar Gala unsigned long reason = get_mc_reason(regs); 36614cf11afSPaul Mackerras 36714cf11afSPaul Mackerras if (reason & ESR_IMCP) { 36814cf11afSPaul Mackerras printk("Instruction"); 36914cf11afSPaul Mackerras mtspr(SPRN_ESR, reason & ~ESR_IMCP); 37014cf11afSPaul Mackerras } else 37114cf11afSPaul Mackerras printk("Data"); 37214cf11afSPaul Mackerras printk(" machine check in kernel mode.\n"); 37347c0bd1aSBenjamin Herrenschmidt 37447c0bd1aSBenjamin Herrenschmidt return 0; 37547c0bd1aSBenjamin Herrenschmidt } 37647c0bd1aSBenjamin Herrenschmidt 37747c0bd1aSBenjamin Herrenschmidt int machine_check_440A(struct pt_regs *regs) 37847c0bd1aSBenjamin Herrenschmidt { 37947c0bd1aSBenjamin Herrenschmidt unsigned long reason = get_mc_reason(regs); 38047c0bd1aSBenjamin Herrenschmidt 38114cf11afSPaul Mackerras printk("Machine check in kernel mode.\n"); 38214cf11afSPaul Mackerras if (reason & ESR_IMCP){ 38314cf11afSPaul Mackerras printk("Instruction Synchronous Machine Check exception\n"); 38414cf11afSPaul Mackerras mtspr(SPRN_ESR, reason & ~ESR_IMCP); 38514cf11afSPaul Mackerras } 38614cf11afSPaul Mackerras else { 38714cf11afSPaul Mackerras u32 mcsr = mfspr(SPRN_MCSR); 38814cf11afSPaul Mackerras if (mcsr & MCSR_IB) 38914cf11afSPaul Mackerras printk("Instruction Read PLB Error\n"); 39014cf11afSPaul Mackerras if (mcsr & MCSR_DRB) 39114cf11afSPaul Mackerras printk("Data Read PLB Error\n"); 39214cf11afSPaul Mackerras if (mcsr & MCSR_DWB) 39314cf11afSPaul Mackerras printk("Data Write PLB Error\n"); 39414cf11afSPaul Mackerras if (mcsr & MCSR_TLBP) 39514cf11afSPaul Mackerras printk("TLB Parity Error\n"); 39614cf11afSPaul Mackerras if (mcsr & MCSR_ICP){ 39714cf11afSPaul Mackerras flush_instruction_cache(); 39814cf11afSPaul Mackerras printk("I-Cache Parity Error\n"); 39914cf11afSPaul Mackerras } 40014cf11afSPaul Mackerras if (mcsr & MCSR_DCSP) 40114cf11afSPaul Mackerras printk("D-Cache Search Parity Error\n"); 40214cf11afSPaul Mackerras if (mcsr & MCSR_DCFP) 40314cf11afSPaul Mackerras printk("D-Cache Flush Parity Error\n"); 40414cf11afSPaul Mackerras if (mcsr & MCSR_IMPE) 40514cf11afSPaul Mackerras printk("Machine Check exception is imprecise\n"); 40614cf11afSPaul Mackerras 40714cf11afSPaul Mackerras /* Clear MCSR */ 40814cf11afSPaul Mackerras mtspr(SPRN_MCSR, mcsr); 40914cf11afSPaul Mackerras } 41047c0bd1aSBenjamin Herrenschmidt return 0; 41147c0bd1aSBenjamin Herrenschmidt } 412fc5e7097SDave Kleikamp 413fc5e7097SDave Kleikamp int machine_check_47x(struct pt_regs *regs) 414fc5e7097SDave Kleikamp { 415fc5e7097SDave Kleikamp unsigned long reason = get_mc_reason(regs); 416fc5e7097SDave Kleikamp u32 mcsr; 417fc5e7097SDave Kleikamp 418fc5e7097SDave Kleikamp printk(KERN_ERR "Machine check in kernel mode.\n"); 419fc5e7097SDave Kleikamp if (reason & ESR_IMCP) { 420fc5e7097SDave Kleikamp printk(KERN_ERR 421fc5e7097SDave Kleikamp "Instruction Synchronous Machine Check exception\n"); 422fc5e7097SDave Kleikamp mtspr(SPRN_ESR, reason & ~ESR_IMCP); 423fc5e7097SDave Kleikamp return 0; 424fc5e7097SDave Kleikamp } 425fc5e7097SDave Kleikamp mcsr = mfspr(SPRN_MCSR); 426fc5e7097SDave Kleikamp if (mcsr & MCSR_IB) 427fc5e7097SDave Kleikamp printk(KERN_ERR "Instruction Read PLB Error\n"); 428fc5e7097SDave Kleikamp if (mcsr & MCSR_DRB) 429fc5e7097SDave Kleikamp printk(KERN_ERR "Data Read PLB Error\n"); 430fc5e7097SDave Kleikamp if (mcsr & MCSR_DWB) 431fc5e7097SDave Kleikamp printk(KERN_ERR "Data Write PLB Error\n"); 432fc5e7097SDave Kleikamp if (mcsr & MCSR_TLBP) 433fc5e7097SDave Kleikamp printk(KERN_ERR "TLB Parity Error\n"); 434fc5e7097SDave Kleikamp if (mcsr & MCSR_ICP) { 435fc5e7097SDave Kleikamp flush_instruction_cache(); 436fc5e7097SDave Kleikamp printk(KERN_ERR "I-Cache Parity Error\n"); 437fc5e7097SDave Kleikamp } 438fc5e7097SDave Kleikamp if (mcsr & MCSR_DCSP) 439fc5e7097SDave Kleikamp printk(KERN_ERR "D-Cache Search Parity Error\n"); 440fc5e7097SDave Kleikamp if (mcsr & PPC47x_MCSR_GPR) 441fc5e7097SDave Kleikamp printk(KERN_ERR "GPR Parity Error\n"); 442fc5e7097SDave Kleikamp if (mcsr & PPC47x_MCSR_FPR) 443fc5e7097SDave Kleikamp printk(KERN_ERR "FPR Parity Error\n"); 444fc5e7097SDave Kleikamp if (mcsr & PPC47x_MCSR_IPR) 445fc5e7097SDave Kleikamp printk(KERN_ERR "Machine Check exception is imprecise\n"); 446fc5e7097SDave Kleikamp 447fc5e7097SDave Kleikamp /* Clear MCSR */ 448fc5e7097SDave Kleikamp mtspr(SPRN_MCSR, mcsr); 449fc5e7097SDave Kleikamp 450fc5e7097SDave Kleikamp return 0; 451fc5e7097SDave Kleikamp } 45214cf11afSPaul Mackerras #elif defined(CONFIG_E500) 453fe04b112SScott Wood int machine_check_e500mc(struct pt_regs *regs) 454fe04b112SScott Wood { 455fe04b112SScott Wood unsigned long mcsr = mfspr(SPRN_MCSR); 456fe04b112SScott Wood unsigned long reason = mcsr; 457fe04b112SScott Wood int recoverable = 1; 458fe04b112SScott Wood 45982a9a480SScott Wood if (reason & MCSR_LD) { 460cce1f106SShaohui Xie recoverable = fsl_rio_mcheck_exception(regs); 461cce1f106SShaohui Xie if (recoverable == 1) 462cce1f106SShaohui Xie goto silent_out; 463cce1f106SShaohui Xie } 464cce1f106SShaohui Xie 465fe04b112SScott Wood printk("Machine check in kernel mode.\n"); 466fe04b112SScott Wood printk("Caused by (from MCSR=%lx): ", reason); 467fe04b112SScott Wood 468fe04b112SScott Wood if (reason & MCSR_MCP) 469fe04b112SScott Wood printk("Machine Check Signal\n"); 470fe04b112SScott Wood 471fe04b112SScott Wood if (reason & MCSR_ICPERR) { 472fe04b112SScott Wood printk("Instruction Cache Parity Error\n"); 473fe04b112SScott Wood 474fe04b112SScott Wood /* 475fe04b112SScott Wood * This is recoverable by invalidating the i-cache. 476fe04b112SScott Wood */ 477fe04b112SScott Wood mtspr(SPRN_L1CSR1, mfspr(SPRN_L1CSR1) | L1CSR1_ICFI); 478fe04b112SScott Wood while (mfspr(SPRN_L1CSR1) & L1CSR1_ICFI) 479fe04b112SScott Wood ; 480fe04b112SScott Wood 481fe04b112SScott Wood /* 482fe04b112SScott Wood * This will generally be accompanied by an instruction 483fe04b112SScott Wood * fetch error report -- only treat MCSR_IF as fatal 484fe04b112SScott Wood * if it wasn't due to an L1 parity error. 485fe04b112SScott Wood */ 486fe04b112SScott Wood reason &= ~MCSR_IF; 487fe04b112SScott Wood } 488fe04b112SScott Wood 489fe04b112SScott Wood if (reason & MCSR_DCPERR_MC) { 490fe04b112SScott Wood printk("Data Cache Parity Error\n"); 49137caf9f2SKumar Gala 49237caf9f2SKumar Gala /* 49337caf9f2SKumar Gala * In write shadow mode we auto-recover from the error, but it 49437caf9f2SKumar Gala * may still get logged and cause a machine check. We should 49537caf9f2SKumar Gala * only treat the non-write shadow case as non-recoverable. 49637caf9f2SKumar Gala */ 49737caf9f2SKumar Gala if (!(mfspr(SPRN_L1CSR2) & L1CSR2_DCWS)) 498fe04b112SScott Wood recoverable = 0; 499fe04b112SScott Wood } 500fe04b112SScott Wood 501fe04b112SScott Wood if (reason & MCSR_L2MMU_MHIT) { 502fe04b112SScott Wood printk("Hit on multiple TLB entries\n"); 503fe04b112SScott Wood recoverable = 0; 504fe04b112SScott Wood } 505fe04b112SScott Wood 506fe04b112SScott Wood if (reason & MCSR_NMI) 507fe04b112SScott Wood printk("Non-maskable interrupt\n"); 508fe04b112SScott Wood 509fe04b112SScott Wood if (reason & MCSR_IF) { 510fe04b112SScott Wood printk("Instruction Fetch Error Report\n"); 511fe04b112SScott Wood recoverable = 0; 512fe04b112SScott Wood } 513fe04b112SScott Wood 514fe04b112SScott Wood if (reason & MCSR_LD) { 515fe04b112SScott Wood printk("Load Error Report\n"); 516fe04b112SScott Wood recoverable = 0; 517fe04b112SScott Wood } 518fe04b112SScott Wood 519fe04b112SScott Wood if (reason & MCSR_ST) { 520fe04b112SScott Wood printk("Store Error Report\n"); 521fe04b112SScott Wood recoverable = 0; 522fe04b112SScott Wood } 523fe04b112SScott Wood 524fe04b112SScott Wood if (reason & MCSR_LDG) { 525fe04b112SScott Wood printk("Guarded Load Error Report\n"); 526fe04b112SScott Wood recoverable = 0; 527fe04b112SScott Wood } 528fe04b112SScott Wood 529fe04b112SScott Wood if (reason & MCSR_TLBSYNC) 530fe04b112SScott Wood printk("Simultaneous tlbsync operations\n"); 531fe04b112SScott Wood 532fe04b112SScott Wood if (reason & MCSR_BSL2_ERR) { 533fe04b112SScott Wood printk("Level 2 Cache Error\n"); 534fe04b112SScott Wood recoverable = 0; 535fe04b112SScott Wood } 536fe04b112SScott Wood 537fe04b112SScott Wood if (reason & MCSR_MAV) { 538fe04b112SScott Wood u64 addr; 539fe04b112SScott Wood 540fe04b112SScott Wood addr = mfspr(SPRN_MCAR); 541fe04b112SScott Wood addr |= (u64)mfspr(SPRN_MCARU) << 32; 542fe04b112SScott Wood 543fe04b112SScott Wood printk("Machine Check %s Address: %#llx\n", 544fe04b112SScott Wood reason & MCSR_MEA ? "Effective" : "Physical", addr); 545fe04b112SScott Wood } 546fe04b112SScott Wood 547cce1f106SShaohui Xie silent_out: 548fe04b112SScott Wood mtspr(SPRN_MCSR, mcsr); 549fe04b112SScott Wood return mfspr(SPRN_MCSR) == 0 && recoverable; 550fe04b112SScott Wood } 551fe04b112SScott Wood 55247c0bd1aSBenjamin Herrenschmidt int machine_check_e500(struct pt_regs *regs) 55347c0bd1aSBenjamin Herrenschmidt { 55447c0bd1aSBenjamin Herrenschmidt unsigned long reason = get_mc_reason(regs); 55547c0bd1aSBenjamin Herrenschmidt 556cce1f106SShaohui Xie if (reason & MCSR_BUS_RBERR) { 557cce1f106SShaohui Xie if (fsl_rio_mcheck_exception(regs)) 558cce1f106SShaohui Xie return 1; 559cce1f106SShaohui Xie } 560cce1f106SShaohui Xie 56114cf11afSPaul Mackerras printk("Machine check in kernel mode.\n"); 56214cf11afSPaul Mackerras printk("Caused by (from MCSR=%lx): ", reason); 56314cf11afSPaul Mackerras 56414cf11afSPaul Mackerras if (reason & MCSR_MCP) 56514cf11afSPaul Mackerras printk("Machine Check Signal\n"); 56614cf11afSPaul Mackerras if (reason & MCSR_ICPERR) 56714cf11afSPaul Mackerras printk("Instruction Cache Parity Error\n"); 56814cf11afSPaul Mackerras if (reason & MCSR_DCP_PERR) 56914cf11afSPaul Mackerras printk("Data Cache Push Parity Error\n"); 57014cf11afSPaul Mackerras if (reason & MCSR_DCPERR) 57114cf11afSPaul Mackerras printk("Data Cache Parity Error\n"); 57214cf11afSPaul Mackerras if (reason & MCSR_BUS_IAERR) 57314cf11afSPaul Mackerras printk("Bus - Instruction Address Error\n"); 57414cf11afSPaul Mackerras if (reason & MCSR_BUS_RAERR) 57514cf11afSPaul Mackerras printk("Bus - Read Address Error\n"); 57614cf11afSPaul Mackerras if (reason & MCSR_BUS_WAERR) 57714cf11afSPaul Mackerras printk("Bus - Write Address Error\n"); 57814cf11afSPaul Mackerras if (reason & MCSR_BUS_IBERR) 57914cf11afSPaul Mackerras printk("Bus - Instruction Data Error\n"); 58014cf11afSPaul Mackerras if (reason & MCSR_BUS_RBERR) 58114cf11afSPaul Mackerras printk("Bus - Read Data Bus Error\n"); 58214cf11afSPaul Mackerras if (reason & MCSR_BUS_WBERR) 58314cf11afSPaul Mackerras printk("Bus - Read Data Bus Error\n"); 58414cf11afSPaul Mackerras if (reason & MCSR_BUS_IPERR) 58514cf11afSPaul Mackerras printk("Bus - Instruction Parity Error\n"); 58614cf11afSPaul Mackerras if (reason & MCSR_BUS_RPERR) 58714cf11afSPaul Mackerras printk("Bus - Read Parity Error\n"); 58847c0bd1aSBenjamin Herrenschmidt 58947c0bd1aSBenjamin Herrenschmidt return 0; 59047c0bd1aSBenjamin Herrenschmidt } 5914490c06bSKumar Gala 5924490c06bSKumar Gala int machine_check_generic(struct pt_regs *regs) 5934490c06bSKumar Gala { 5944490c06bSKumar Gala return 0; 5954490c06bSKumar Gala } 59614cf11afSPaul Mackerras #elif defined(CONFIG_E200) 59747c0bd1aSBenjamin Herrenschmidt int machine_check_e200(struct pt_regs *regs) 59847c0bd1aSBenjamin Herrenschmidt { 59947c0bd1aSBenjamin Herrenschmidt unsigned long reason = get_mc_reason(regs); 60047c0bd1aSBenjamin Herrenschmidt 60114cf11afSPaul Mackerras printk("Machine check in kernel mode.\n"); 60214cf11afSPaul Mackerras printk("Caused by (from MCSR=%lx): ", reason); 60314cf11afSPaul Mackerras 60414cf11afSPaul Mackerras if (reason & MCSR_MCP) 60514cf11afSPaul Mackerras printk("Machine Check Signal\n"); 60614cf11afSPaul Mackerras if (reason & MCSR_CP_PERR) 60714cf11afSPaul Mackerras printk("Cache Push Parity Error\n"); 60814cf11afSPaul Mackerras if (reason & MCSR_CPERR) 60914cf11afSPaul Mackerras printk("Cache Parity Error\n"); 61014cf11afSPaul Mackerras if (reason & MCSR_EXCP_ERR) 61114cf11afSPaul Mackerras printk("ISI, ITLB, or Bus Error on first instruction fetch for an exception handler\n"); 61214cf11afSPaul Mackerras if (reason & MCSR_BUS_IRERR) 61314cf11afSPaul Mackerras printk("Bus - Read Bus Error on instruction fetch\n"); 61414cf11afSPaul Mackerras if (reason & MCSR_BUS_DRERR) 61514cf11afSPaul Mackerras printk("Bus - Read Bus Error on data load\n"); 61614cf11afSPaul Mackerras if (reason & MCSR_BUS_WRERR) 61714cf11afSPaul Mackerras printk("Bus - Write Bus Error on buffered store or cache line push\n"); 61847c0bd1aSBenjamin Herrenschmidt 61947c0bd1aSBenjamin Herrenschmidt return 0; 62047c0bd1aSBenjamin Herrenschmidt } 62147c0bd1aSBenjamin Herrenschmidt #else 62247c0bd1aSBenjamin Herrenschmidt int machine_check_generic(struct pt_regs *regs) 62347c0bd1aSBenjamin Herrenschmidt { 62447c0bd1aSBenjamin Herrenschmidt unsigned long reason = get_mc_reason(regs); 62547c0bd1aSBenjamin Herrenschmidt 62614cf11afSPaul Mackerras printk("Machine check in kernel mode.\n"); 62714cf11afSPaul Mackerras printk("Caused by (from SRR1=%lx): ", reason); 62814cf11afSPaul Mackerras switch (reason & 0x601F0000) { 62914cf11afSPaul Mackerras case 0x80000: 63014cf11afSPaul Mackerras printk("Machine check signal\n"); 63114cf11afSPaul Mackerras break; 63214cf11afSPaul Mackerras case 0: /* for 601 */ 63314cf11afSPaul Mackerras case 0x40000: 63414cf11afSPaul Mackerras case 0x140000: /* 7450 MSS error and TEA */ 63514cf11afSPaul Mackerras printk("Transfer error ack signal\n"); 63614cf11afSPaul Mackerras break; 63714cf11afSPaul Mackerras case 0x20000: 63814cf11afSPaul Mackerras printk("Data parity error signal\n"); 63914cf11afSPaul Mackerras break; 64014cf11afSPaul Mackerras case 0x10000: 64114cf11afSPaul Mackerras printk("Address parity error signal\n"); 64214cf11afSPaul Mackerras break; 64314cf11afSPaul Mackerras case 0x20000000: 64414cf11afSPaul Mackerras printk("L1 Data Cache error\n"); 64514cf11afSPaul Mackerras break; 64614cf11afSPaul Mackerras case 0x40000000: 64714cf11afSPaul Mackerras printk("L1 Instruction Cache error\n"); 64814cf11afSPaul Mackerras break; 64914cf11afSPaul Mackerras case 0x00100000: 65014cf11afSPaul Mackerras printk("L2 data cache parity error\n"); 65114cf11afSPaul Mackerras break; 65214cf11afSPaul Mackerras default: 65314cf11afSPaul Mackerras printk("Unknown values in msr\n"); 65414cf11afSPaul Mackerras } 65575918a4bSOlof Johansson return 0; 65675918a4bSOlof Johansson } 65747c0bd1aSBenjamin Herrenschmidt #endif /* everything else */ 65875918a4bSOlof Johansson 65975918a4bSOlof Johansson void machine_check_exception(struct pt_regs *regs) 66075918a4bSOlof Johansson { 66175918a4bSOlof Johansson int recover = 0; 66275918a4bSOlof Johansson 66389713ed1SAnton Blanchard __get_cpu_var(irq_stat).mce_exceptions++; 66489713ed1SAnton Blanchard 66547c0bd1aSBenjamin Herrenschmidt /* See if any machine dependent calls. In theory, we would want 66647c0bd1aSBenjamin Herrenschmidt * to call the CPU first, and call the ppc_md. one if the CPU 66747c0bd1aSBenjamin Herrenschmidt * one returns a positive number. However there is existing code 66847c0bd1aSBenjamin Herrenschmidt * that assumes the board gets a first chance, so let's keep it 66947c0bd1aSBenjamin Herrenschmidt * that way for now and fix things later. --BenH. 67047c0bd1aSBenjamin Herrenschmidt */ 67175918a4bSOlof Johansson if (ppc_md.machine_check_exception) 67275918a4bSOlof Johansson recover = ppc_md.machine_check_exception(regs); 67347c0bd1aSBenjamin Herrenschmidt else if (cur_cpu_spec->machine_check) 67447c0bd1aSBenjamin Herrenschmidt recover = cur_cpu_spec->machine_check(regs); 67575918a4bSOlof Johansson 67647c0bd1aSBenjamin Herrenschmidt if (recover > 0) 67775918a4bSOlof Johansson return; 67875918a4bSOlof Johansson 67975918a4bSOlof Johansson #if defined(CONFIG_8xx) && defined(CONFIG_PCI) 68047c0bd1aSBenjamin Herrenschmidt /* the qspan pci read routines can cause machine checks -- Cort 68147c0bd1aSBenjamin Herrenschmidt * 68247c0bd1aSBenjamin Herrenschmidt * yuck !!! that totally needs to go away ! There are better ways 68347c0bd1aSBenjamin Herrenschmidt * to deal with that than having a wart in the mcheck handler. 68447c0bd1aSBenjamin Herrenschmidt * -- BenH 68547c0bd1aSBenjamin Herrenschmidt */ 68675918a4bSOlof Johansson bad_page_fault(regs, regs->dar, SIGBUS); 68775918a4bSOlof Johansson return; 68875918a4bSOlof Johansson #endif 68975918a4bSOlof Johansson 690a443506bSAnton Blanchard if (debugger_fault_handler(regs)) 69175918a4bSOlof Johansson return; 69275918a4bSOlof Johansson 69375918a4bSOlof Johansson if (check_io_access(regs)) 69475918a4bSOlof Johansson return; 69575918a4bSOlof Johansson 6968dad3f92SPaul Mackerras die("Machine check", regs, SIGBUS); 69714cf11afSPaul Mackerras 69814cf11afSPaul Mackerras /* Must die if the interrupt is not recoverable */ 69914cf11afSPaul Mackerras if (!(regs->msr & MSR_RI)) 70014cf11afSPaul Mackerras panic("Unrecoverable Machine check"); 70114cf11afSPaul Mackerras } 70214cf11afSPaul Mackerras 70314cf11afSPaul Mackerras void SMIException(struct pt_regs *regs) 70414cf11afSPaul Mackerras { 70514cf11afSPaul Mackerras die("System Management Interrupt", regs, SIGABRT); 70614cf11afSPaul Mackerras } 70714cf11afSPaul Mackerras 708dc1c1ca3SStephen Rothwell void unknown_exception(struct pt_regs *regs) 70914cf11afSPaul Mackerras { 71014cf11afSPaul Mackerras printk("Bad trap at PC: %lx, SR: %lx, vector=%lx\n", 71114cf11afSPaul Mackerras regs->nip, regs->msr, regs->trap); 71214cf11afSPaul Mackerras 71314cf11afSPaul Mackerras _exception(SIGTRAP, regs, 0, 0); 71414cf11afSPaul Mackerras } 71514cf11afSPaul Mackerras 716dc1c1ca3SStephen Rothwell void instruction_breakpoint_exception(struct pt_regs *regs) 71714cf11afSPaul Mackerras { 71814cf11afSPaul Mackerras if (notify_die(DIE_IABR_MATCH, "iabr_match", regs, 5, 71914cf11afSPaul Mackerras 5, SIGTRAP) == NOTIFY_STOP) 72014cf11afSPaul Mackerras return; 72114cf11afSPaul Mackerras if (debugger_iabr_match(regs)) 72214cf11afSPaul Mackerras return; 72314cf11afSPaul Mackerras _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip); 72414cf11afSPaul Mackerras } 72514cf11afSPaul Mackerras 72614cf11afSPaul Mackerras void RunModeException(struct pt_regs *regs) 72714cf11afSPaul Mackerras { 72814cf11afSPaul Mackerras _exception(SIGTRAP, regs, 0, 0); 72914cf11afSPaul Mackerras } 73014cf11afSPaul Mackerras 7318dad3f92SPaul Mackerras void __kprobes single_step_exception(struct pt_regs *regs) 73214cf11afSPaul Mackerras { 7332538c2d0SK.Prasad clear_single_step(regs); 73414cf11afSPaul Mackerras 73514cf11afSPaul Mackerras if (notify_die(DIE_SSTEP, "single_step", regs, 5, 73614cf11afSPaul Mackerras 5, SIGTRAP) == NOTIFY_STOP) 73714cf11afSPaul Mackerras return; 73814cf11afSPaul Mackerras if (debugger_sstep(regs)) 73914cf11afSPaul Mackerras return; 74014cf11afSPaul Mackerras 74114cf11afSPaul Mackerras _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip); 74214cf11afSPaul Mackerras } 74314cf11afSPaul Mackerras 74414cf11afSPaul Mackerras /* 74514cf11afSPaul Mackerras * After we have successfully emulated an instruction, we have to 74614cf11afSPaul Mackerras * check if the instruction was being single-stepped, and if so, 74714cf11afSPaul Mackerras * pretend we got a single-step exception. This was pointed out 74814cf11afSPaul Mackerras * by Kumar Gala. -- paulus 74914cf11afSPaul Mackerras */ 7508dad3f92SPaul Mackerras static void emulate_single_step(struct pt_regs *regs) 75114cf11afSPaul Mackerras { 7522538c2d0SK.Prasad if (single_stepping(regs)) 7532538c2d0SK.Prasad single_step_exception(regs); 75414cf11afSPaul Mackerras } 75514cf11afSPaul Mackerras 7565fad293bSKumar Gala static inline int __parse_fpscr(unsigned long fpscr) 757dc1c1ca3SStephen Rothwell { 7585fad293bSKumar Gala int ret = 0; 759dc1c1ca3SStephen Rothwell 760dc1c1ca3SStephen Rothwell /* Invalid operation */ 761dc1c1ca3SStephen Rothwell if ((fpscr & FPSCR_VE) && (fpscr & FPSCR_VX)) 7625fad293bSKumar Gala ret = FPE_FLTINV; 763dc1c1ca3SStephen Rothwell 764dc1c1ca3SStephen Rothwell /* Overflow */ 765dc1c1ca3SStephen Rothwell else if ((fpscr & FPSCR_OE) && (fpscr & FPSCR_OX)) 7665fad293bSKumar Gala ret = FPE_FLTOVF; 767dc1c1ca3SStephen Rothwell 768dc1c1ca3SStephen Rothwell /* Underflow */ 769dc1c1ca3SStephen Rothwell else if ((fpscr & FPSCR_UE) && (fpscr & FPSCR_UX)) 7705fad293bSKumar Gala ret = FPE_FLTUND; 771dc1c1ca3SStephen Rothwell 772dc1c1ca3SStephen Rothwell /* Divide by zero */ 773dc1c1ca3SStephen Rothwell else if ((fpscr & FPSCR_ZE) && (fpscr & FPSCR_ZX)) 7745fad293bSKumar Gala ret = FPE_FLTDIV; 775dc1c1ca3SStephen Rothwell 776dc1c1ca3SStephen Rothwell /* Inexact result */ 777dc1c1ca3SStephen Rothwell else if ((fpscr & FPSCR_XE) && (fpscr & FPSCR_XX)) 7785fad293bSKumar Gala ret = FPE_FLTRES; 7795fad293bSKumar Gala 7805fad293bSKumar Gala return ret; 7815fad293bSKumar Gala } 7825fad293bSKumar Gala 7835fad293bSKumar Gala static void parse_fpe(struct pt_regs *regs) 7845fad293bSKumar Gala { 7855fad293bSKumar Gala int code = 0; 7865fad293bSKumar Gala 7875fad293bSKumar Gala flush_fp_to_thread(current); 7885fad293bSKumar Gala 7895fad293bSKumar Gala code = __parse_fpscr(current->thread.fpscr.val); 790dc1c1ca3SStephen Rothwell 791dc1c1ca3SStephen Rothwell _exception(SIGFPE, regs, code, regs->nip); 792dc1c1ca3SStephen Rothwell } 793dc1c1ca3SStephen Rothwell 794dc1c1ca3SStephen Rothwell /* 795dc1c1ca3SStephen Rothwell * Illegal instruction emulation support. Originally written to 79614cf11afSPaul Mackerras * provide the PVR to user applications using the mfspr rd, PVR. 79714cf11afSPaul Mackerras * Return non-zero if we can't emulate, or -EFAULT if the associated 79814cf11afSPaul Mackerras * memory access caused an access fault. Return zero on success. 79914cf11afSPaul Mackerras * 80014cf11afSPaul Mackerras * There are a couple of ways to do this, either "decode" the instruction 80114cf11afSPaul Mackerras * or directly match lots of bits. In this case, matching lots of 80214cf11afSPaul Mackerras * bits is faster and easier. 80386417780SPaul Mackerras * 80414cf11afSPaul Mackerras */ 80514cf11afSPaul Mackerras static int emulate_string_inst(struct pt_regs *regs, u32 instword) 80614cf11afSPaul Mackerras { 80714cf11afSPaul Mackerras u8 rT = (instword >> 21) & 0x1f; 80814cf11afSPaul Mackerras u8 rA = (instword >> 16) & 0x1f; 80914cf11afSPaul Mackerras u8 NB_RB = (instword >> 11) & 0x1f; 81014cf11afSPaul Mackerras u32 num_bytes; 81114cf11afSPaul Mackerras unsigned long EA; 81214cf11afSPaul Mackerras int pos = 0; 81314cf11afSPaul Mackerras 81414cf11afSPaul Mackerras /* Early out if we are an invalid form of lswx */ 81516c57b36SKumar Gala if ((instword & PPC_INST_STRING_MASK) == PPC_INST_LSWX) 81614cf11afSPaul Mackerras if ((rT == rA) || (rT == NB_RB)) 81714cf11afSPaul Mackerras return -EINVAL; 81814cf11afSPaul Mackerras 81914cf11afSPaul Mackerras EA = (rA == 0) ? 0 : regs->gpr[rA]; 82014cf11afSPaul Mackerras 82116c57b36SKumar Gala switch (instword & PPC_INST_STRING_MASK) { 82216c57b36SKumar Gala case PPC_INST_LSWX: 82316c57b36SKumar Gala case PPC_INST_STSWX: 82414cf11afSPaul Mackerras EA += NB_RB; 82514cf11afSPaul Mackerras num_bytes = regs->xer & 0x7f; 82614cf11afSPaul Mackerras break; 82716c57b36SKumar Gala case PPC_INST_LSWI: 82816c57b36SKumar Gala case PPC_INST_STSWI: 82914cf11afSPaul Mackerras num_bytes = (NB_RB == 0) ? 32 : NB_RB; 83014cf11afSPaul Mackerras break; 83114cf11afSPaul Mackerras default: 83214cf11afSPaul Mackerras return -EINVAL; 83314cf11afSPaul Mackerras } 83414cf11afSPaul Mackerras 83514cf11afSPaul Mackerras while (num_bytes != 0) 83614cf11afSPaul Mackerras { 83714cf11afSPaul Mackerras u8 val; 83814cf11afSPaul Mackerras u32 shift = 8 * (3 - (pos & 0x3)); 83914cf11afSPaul Mackerras 84016c57b36SKumar Gala switch ((instword & PPC_INST_STRING_MASK)) { 84116c57b36SKumar Gala case PPC_INST_LSWX: 84216c57b36SKumar Gala case PPC_INST_LSWI: 84314cf11afSPaul Mackerras if (get_user(val, (u8 __user *)EA)) 84414cf11afSPaul Mackerras return -EFAULT; 84514cf11afSPaul Mackerras /* first time updating this reg, 84614cf11afSPaul Mackerras * zero it out */ 84714cf11afSPaul Mackerras if (pos == 0) 84814cf11afSPaul Mackerras regs->gpr[rT] = 0; 84914cf11afSPaul Mackerras regs->gpr[rT] |= val << shift; 85014cf11afSPaul Mackerras break; 85116c57b36SKumar Gala case PPC_INST_STSWI: 85216c57b36SKumar Gala case PPC_INST_STSWX: 85314cf11afSPaul Mackerras val = regs->gpr[rT] >> shift; 85414cf11afSPaul Mackerras if (put_user(val, (u8 __user *)EA)) 85514cf11afSPaul Mackerras return -EFAULT; 85614cf11afSPaul Mackerras break; 85714cf11afSPaul Mackerras } 85814cf11afSPaul Mackerras /* move EA to next address */ 85914cf11afSPaul Mackerras EA += 1; 86014cf11afSPaul Mackerras num_bytes--; 86114cf11afSPaul Mackerras 86214cf11afSPaul Mackerras /* manage our position within the register */ 86314cf11afSPaul Mackerras if (++pos == 4) { 86414cf11afSPaul Mackerras pos = 0; 86514cf11afSPaul Mackerras if (++rT == 32) 86614cf11afSPaul Mackerras rT = 0; 86714cf11afSPaul Mackerras } 86814cf11afSPaul Mackerras } 86914cf11afSPaul Mackerras 87014cf11afSPaul Mackerras return 0; 87114cf11afSPaul Mackerras } 87214cf11afSPaul Mackerras 873c3412dcbSWill Schmidt static int emulate_popcntb_inst(struct pt_regs *regs, u32 instword) 874c3412dcbSWill Schmidt { 875c3412dcbSWill Schmidt u32 ra,rs; 876c3412dcbSWill Schmidt unsigned long tmp; 877c3412dcbSWill Schmidt 878c3412dcbSWill Schmidt ra = (instword >> 16) & 0x1f; 879c3412dcbSWill Schmidt rs = (instword >> 21) & 0x1f; 880c3412dcbSWill Schmidt 881c3412dcbSWill Schmidt tmp = regs->gpr[rs]; 882c3412dcbSWill Schmidt tmp = tmp - ((tmp >> 1) & 0x5555555555555555ULL); 883c3412dcbSWill Schmidt tmp = (tmp & 0x3333333333333333ULL) + ((tmp >> 2) & 0x3333333333333333ULL); 884c3412dcbSWill Schmidt tmp = (tmp + (tmp >> 4)) & 0x0f0f0f0f0f0f0f0fULL; 885c3412dcbSWill Schmidt regs->gpr[ra] = tmp; 886c3412dcbSWill Schmidt 887c3412dcbSWill Schmidt return 0; 888c3412dcbSWill Schmidt } 889c3412dcbSWill Schmidt 890c1469f13SKumar Gala static int emulate_isel(struct pt_regs *regs, u32 instword) 891c1469f13SKumar Gala { 892c1469f13SKumar Gala u8 rT = (instword >> 21) & 0x1f; 893c1469f13SKumar Gala u8 rA = (instword >> 16) & 0x1f; 894c1469f13SKumar Gala u8 rB = (instword >> 11) & 0x1f; 895c1469f13SKumar Gala u8 BC = (instword >> 6) & 0x1f; 896c1469f13SKumar Gala u8 bit; 897c1469f13SKumar Gala unsigned long tmp; 898c1469f13SKumar Gala 899c1469f13SKumar Gala tmp = (rA == 0) ? 0 : regs->gpr[rA]; 900c1469f13SKumar Gala bit = (regs->ccr >> (31 - BC)) & 0x1; 901c1469f13SKumar Gala 902c1469f13SKumar Gala regs->gpr[rT] = bit ? tmp : regs->gpr[rB]; 903c1469f13SKumar Gala 904c1469f13SKumar Gala return 0; 905c1469f13SKumar Gala } 906c1469f13SKumar Gala 90714cf11afSPaul Mackerras static int emulate_instruction(struct pt_regs *regs) 90814cf11afSPaul Mackerras { 90914cf11afSPaul Mackerras u32 instword; 91014cf11afSPaul Mackerras u32 rd; 91114cf11afSPaul Mackerras 912fab5db97SPaul Mackerras if (!user_mode(regs) || (regs->msr & MSR_LE)) 91314cf11afSPaul Mackerras return -EINVAL; 91414cf11afSPaul Mackerras CHECK_FULL_REGS(regs); 91514cf11afSPaul Mackerras 91614cf11afSPaul Mackerras if (get_user(instword, (u32 __user *)(regs->nip))) 91714cf11afSPaul Mackerras return -EFAULT; 91814cf11afSPaul Mackerras 91914cf11afSPaul Mackerras /* Emulate the mfspr rD, PVR. */ 92016c57b36SKumar Gala if ((instword & PPC_INST_MFSPR_PVR_MASK) == PPC_INST_MFSPR_PVR) { 921eecff81dSAnton Blanchard PPC_WARN_EMULATED(mfpvr, regs); 92214cf11afSPaul Mackerras rd = (instword >> 21) & 0x1f; 92314cf11afSPaul Mackerras regs->gpr[rd] = mfspr(SPRN_PVR); 92414cf11afSPaul Mackerras return 0; 92514cf11afSPaul Mackerras } 92614cf11afSPaul Mackerras 92714cf11afSPaul Mackerras /* Emulating the dcba insn is just a no-op. */ 92880947e7cSGeert Uytterhoeven if ((instword & PPC_INST_DCBA_MASK) == PPC_INST_DCBA) { 929eecff81dSAnton Blanchard PPC_WARN_EMULATED(dcba, regs); 93014cf11afSPaul Mackerras return 0; 93180947e7cSGeert Uytterhoeven } 93214cf11afSPaul Mackerras 93314cf11afSPaul Mackerras /* Emulate the mcrxr insn. */ 93416c57b36SKumar Gala if ((instword & PPC_INST_MCRXR_MASK) == PPC_INST_MCRXR) { 93586417780SPaul Mackerras int shift = (instword >> 21) & 0x1c; 93614cf11afSPaul Mackerras unsigned long msk = 0xf0000000UL >> shift; 93714cf11afSPaul Mackerras 938eecff81dSAnton Blanchard PPC_WARN_EMULATED(mcrxr, regs); 93914cf11afSPaul Mackerras regs->ccr = (regs->ccr & ~msk) | ((regs->xer >> shift) & msk); 94014cf11afSPaul Mackerras regs->xer &= ~0xf0000000UL; 94114cf11afSPaul Mackerras return 0; 94214cf11afSPaul Mackerras } 94314cf11afSPaul Mackerras 94414cf11afSPaul Mackerras /* Emulate load/store string insn. */ 94580947e7cSGeert Uytterhoeven if ((instword & PPC_INST_STRING_GEN_MASK) == PPC_INST_STRING) { 946eecff81dSAnton Blanchard PPC_WARN_EMULATED(string, regs); 94714cf11afSPaul Mackerras return emulate_string_inst(regs, instword); 94880947e7cSGeert Uytterhoeven } 94914cf11afSPaul Mackerras 950c3412dcbSWill Schmidt /* Emulate the popcntb (Population Count Bytes) instruction. */ 95116c57b36SKumar Gala if ((instword & PPC_INST_POPCNTB_MASK) == PPC_INST_POPCNTB) { 952eecff81dSAnton Blanchard PPC_WARN_EMULATED(popcntb, regs); 953c3412dcbSWill Schmidt return emulate_popcntb_inst(regs, instword); 954c3412dcbSWill Schmidt } 955c3412dcbSWill Schmidt 956c1469f13SKumar Gala /* Emulate isel (Integer Select) instruction */ 95716c57b36SKumar Gala if ((instword & PPC_INST_ISEL_MASK) == PPC_INST_ISEL) { 958eecff81dSAnton Blanchard PPC_WARN_EMULATED(isel, regs); 959c1469f13SKumar Gala return emulate_isel(regs, instword); 960c1469f13SKumar Gala } 961c1469f13SKumar Gala 962efcac658SAlexey Kardashevskiy #ifdef CONFIG_PPC64 963efcac658SAlexey Kardashevskiy /* Emulate the mfspr rD, DSCR. */ 964efcac658SAlexey Kardashevskiy if (((instword & PPC_INST_MFSPR_DSCR_MASK) == PPC_INST_MFSPR_DSCR) && 965efcac658SAlexey Kardashevskiy cpu_has_feature(CPU_FTR_DSCR)) { 966efcac658SAlexey Kardashevskiy PPC_WARN_EMULATED(mfdscr, regs); 967efcac658SAlexey Kardashevskiy rd = (instword >> 21) & 0x1f; 968efcac658SAlexey Kardashevskiy regs->gpr[rd] = mfspr(SPRN_DSCR); 969efcac658SAlexey Kardashevskiy return 0; 970efcac658SAlexey Kardashevskiy } 971efcac658SAlexey Kardashevskiy /* Emulate the mtspr DSCR, rD. */ 972efcac658SAlexey Kardashevskiy if (((instword & PPC_INST_MTSPR_DSCR_MASK) == PPC_INST_MTSPR_DSCR) && 973efcac658SAlexey Kardashevskiy cpu_has_feature(CPU_FTR_DSCR)) { 974efcac658SAlexey Kardashevskiy PPC_WARN_EMULATED(mtdscr, regs); 975efcac658SAlexey Kardashevskiy rd = (instword >> 21) & 0x1f; 97600ca0de0SAnton Blanchard current->thread.dscr = regs->gpr[rd]; 977efcac658SAlexey Kardashevskiy current->thread.dscr_inherit = 1; 97800ca0de0SAnton Blanchard mtspr(SPRN_DSCR, current->thread.dscr); 979efcac658SAlexey Kardashevskiy return 0; 980efcac658SAlexey Kardashevskiy } 981efcac658SAlexey Kardashevskiy #endif 982efcac658SAlexey Kardashevskiy 98314cf11afSPaul Mackerras return -EINVAL; 98414cf11afSPaul Mackerras } 98514cf11afSPaul Mackerras 98673c9ceabSJeremy Fitzhardinge int is_valid_bugaddr(unsigned long addr) 98714cf11afSPaul Mackerras { 98873c9ceabSJeremy Fitzhardinge return is_kernel_addr(addr); 98914cf11afSPaul Mackerras } 99014cf11afSPaul Mackerras 9918dad3f92SPaul Mackerras void __kprobes program_check_exception(struct pt_regs *regs) 99214cf11afSPaul Mackerras { 99314cf11afSPaul Mackerras unsigned int reason = get_reason(regs); 99414cf11afSPaul Mackerras extern int do_mathemu(struct pt_regs *regs); 99514cf11afSPaul Mackerras 996aa42c69cSKim Phillips /* We can now get here via a FP Unavailable exception if the core 99704903a30SKumar Gala * has no FPU, in that case the reason flags will be 0 */ 99814cf11afSPaul Mackerras 99914cf11afSPaul Mackerras if (reason & REASON_FP) { 100014cf11afSPaul Mackerras /* IEEE FP exception */ 1001dc1c1ca3SStephen Rothwell parse_fpe(regs); 10028dad3f92SPaul Mackerras return; 10038dad3f92SPaul Mackerras } 10048dad3f92SPaul Mackerras if (reason & REASON_TRAP) { 1005ba797b28SJason Wessel /* Debugger is first in line to stop recursive faults in 1006ba797b28SJason Wessel * rcu_lock, notify_die, or atomic_notifier_call_chain */ 1007ba797b28SJason Wessel if (debugger_bpt(regs)) 1008ba797b28SJason Wessel return; 1009ba797b28SJason Wessel 101014cf11afSPaul Mackerras /* trap exception */ 1011dc1c1ca3SStephen Rothwell if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP) 1012dc1c1ca3SStephen Rothwell == NOTIFY_STOP) 1013dc1c1ca3SStephen Rothwell return; 101473c9ceabSJeremy Fitzhardinge 101573c9ceabSJeremy Fitzhardinge if (!(regs->msr & MSR_PR) && /* not user-mode */ 1016608e2619SHeiko Carstens report_bug(regs->nip, regs) == BUG_TRAP_TYPE_WARN) { 101714cf11afSPaul Mackerras regs->nip += 4; 101814cf11afSPaul Mackerras return; 101914cf11afSPaul Mackerras } 10208dad3f92SPaul Mackerras _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip); 10218dad3f92SPaul Mackerras return; 10228dad3f92SPaul Mackerras } 10238dad3f92SPaul Mackerras 1024a3512b2dSBenjamin Herrenschmidt /* We restore the interrupt state now */ 1025a3512b2dSBenjamin Herrenschmidt if (!arch_irq_disabled_regs(regs)) 1026cd8a5673SPaul Mackerras local_irq_enable(); 1027cd8a5673SPaul Mackerras 102804903a30SKumar Gala #ifdef CONFIG_MATH_EMULATION 102904903a30SKumar Gala /* (reason & REASON_ILLEGAL) would be the obvious thing here, 103004903a30SKumar Gala * but there seems to be a hardware bug on the 405GP (RevD) 103104903a30SKumar Gala * that means ESR is sometimes set incorrectly - either to 103204903a30SKumar Gala * ESR_DST (!?) or 0. In the process of chasing this with the 103304903a30SKumar Gala * hardware people - not sure if it can happen on any illegal 103404903a30SKumar Gala * instruction or only on FP instructions, whether there is a 103525985edcSLucas De Marchi * pattern to occurrences etc. -dgibson 31/Mar/2003 */ 10365fad293bSKumar Gala switch (do_mathemu(regs)) { 10375fad293bSKumar Gala case 0: 103804903a30SKumar Gala emulate_single_step(regs); 103904903a30SKumar Gala return; 10405fad293bSKumar Gala case 1: { 10415fad293bSKumar Gala int code = 0; 10425fad293bSKumar Gala code = __parse_fpscr(current->thread.fpscr.val); 10435fad293bSKumar Gala _exception(SIGFPE, regs, code, regs->nip); 10445fad293bSKumar Gala return; 104504903a30SKumar Gala } 10465fad293bSKumar Gala case -EFAULT: 10475fad293bSKumar Gala _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip); 10485fad293bSKumar Gala return; 10495fad293bSKumar Gala } 10505fad293bSKumar Gala /* fall through on any other errors */ 105104903a30SKumar Gala #endif /* CONFIG_MATH_EMULATION */ 105204903a30SKumar Gala 10538dad3f92SPaul Mackerras /* Try to emulate it if we should. */ 10548dad3f92SPaul Mackerras if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED)) { 105514cf11afSPaul Mackerras switch (emulate_instruction(regs)) { 105614cf11afSPaul Mackerras case 0: 105714cf11afSPaul Mackerras regs->nip += 4; 105814cf11afSPaul Mackerras emulate_single_step(regs); 10598dad3f92SPaul Mackerras return; 106014cf11afSPaul Mackerras case -EFAULT: 106114cf11afSPaul Mackerras _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip); 10628dad3f92SPaul Mackerras return; 10638dad3f92SPaul Mackerras } 10648dad3f92SPaul Mackerras } 10658dad3f92SPaul Mackerras 106614cf11afSPaul Mackerras if (reason & REASON_PRIVILEGED) 106714cf11afSPaul Mackerras _exception(SIGILL, regs, ILL_PRVOPC, regs->nip); 106814cf11afSPaul Mackerras else 106914cf11afSPaul Mackerras _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 107014cf11afSPaul Mackerras } 107114cf11afSPaul Mackerras 1072dc1c1ca3SStephen Rothwell void alignment_exception(struct pt_regs *regs) 107314cf11afSPaul Mackerras { 10744393c4f6SBenjamin Herrenschmidt int sig, code, fixed = 0; 107514cf11afSPaul Mackerras 1076a3512b2dSBenjamin Herrenschmidt /* We restore the interrupt state now */ 1077a3512b2dSBenjamin Herrenschmidt if (!arch_irq_disabled_regs(regs)) 1078a3512b2dSBenjamin Herrenschmidt local_irq_enable(); 1079a3512b2dSBenjamin Herrenschmidt 1080e9370ae1SPaul Mackerras /* we don't implement logging of alignment exceptions */ 1081e9370ae1SPaul Mackerras if (!(current->thread.align_ctl & PR_UNALIGN_SIGBUS)) 108214cf11afSPaul Mackerras fixed = fix_alignment(regs); 108314cf11afSPaul Mackerras 108414cf11afSPaul Mackerras if (fixed == 1) { 108514cf11afSPaul Mackerras regs->nip += 4; /* skip over emulated instruction */ 108614cf11afSPaul Mackerras emulate_single_step(regs); 108714cf11afSPaul Mackerras return; 108814cf11afSPaul Mackerras } 108914cf11afSPaul Mackerras 109014cf11afSPaul Mackerras /* Operand address was bad */ 109114cf11afSPaul Mackerras if (fixed == -EFAULT) { 10924393c4f6SBenjamin Herrenschmidt sig = SIGSEGV; 10934393c4f6SBenjamin Herrenschmidt code = SEGV_ACCERR; 10944393c4f6SBenjamin Herrenschmidt } else { 10954393c4f6SBenjamin Herrenschmidt sig = SIGBUS; 10964393c4f6SBenjamin Herrenschmidt code = BUS_ADRALN; 109714cf11afSPaul Mackerras } 10984393c4f6SBenjamin Herrenschmidt if (user_mode(regs)) 10994393c4f6SBenjamin Herrenschmidt _exception(sig, regs, code, regs->dar); 11004393c4f6SBenjamin Herrenschmidt else 11014393c4f6SBenjamin Herrenschmidt bad_page_fault(regs, regs->dar, sig); 110214cf11afSPaul Mackerras } 110314cf11afSPaul Mackerras 110414cf11afSPaul Mackerras void StackOverflow(struct pt_regs *regs) 110514cf11afSPaul Mackerras { 110614cf11afSPaul Mackerras printk(KERN_CRIT "Kernel stack overflow in process %p, r1=%lx\n", 110714cf11afSPaul Mackerras current, regs->gpr[1]); 110814cf11afSPaul Mackerras debugger(regs); 110914cf11afSPaul Mackerras show_regs(regs); 111014cf11afSPaul Mackerras panic("kernel stack overflow"); 111114cf11afSPaul Mackerras } 111214cf11afSPaul Mackerras 111314cf11afSPaul Mackerras void nonrecoverable_exception(struct pt_regs *regs) 111414cf11afSPaul Mackerras { 111514cf11afSPaul Mackerras printk(KERN_ERR "Non-recoverable exception at PC=%lx MSR=%lx\n", 111614cf11afSPaul Mackerras regs->nip, regs->msr); 111714cf11afSPaul Mackerras debugger(regs); 111814cf11afSPaul Mackerras die("nonrecoverable exception", regs, SIGKILL); 111914cf11afSPaul Mackerras } 112014cf11afSPaul Mackerras 112114cf11afSPaul Mackerras void trace_syscall(struct pt_regs *regs) 112214cf11afSPaul Mackerras { 112314cf11afSPaul Mackerras printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n", 112419c5870cSAlexey Dobriyan current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0], 112514cf11afSPaul Mackerras regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted()); 112614cf11afSPaul Mackerras } 112714cf11afSPaul Mackerras 1128dc1c1ca3SStephen Rothwell void kernel_fp_unavailable_exception(struct pt_regs *regs) 1129dc1c1ca3SStephen Rothwell { 1130dc1c1ca3SStephen Rothwell printk(KERN_EMERG "Unrecoverable FP Unavailable Exception " 1131dc1c1ca3SStephen Rothwell "%lx at %lx\n", regs->trap, regs->nip); 1132dc1c1ca3SStephen Rothwell die("Unrecoverable FP Unavailable Exception", regs, SIGABRT); 1133dc1c1ca3SStephen Rothwell } 1134dc1c1ca3SStephen Rothwell 1135dc1c1ca3SStephen Rothwell void altivec_unavailable_exception(struct pt_regs *regs) 1136dc1c1ca3SStephen Rothwell { 1137dc1c1ca3SStephen Rothwell if (user_mode(regs)) { 1138dc1c1ca3SStephen Rothwell /* A user program has executed an altivec instruction, 1139dc1c1ca3SStephen Rothwell but this kernel doesn't support altivec. */ 1140dc1c1ca3SStephen Rothwell _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 1141dc1c1ca3SStephen Rothwell return; 1142dc1c1ca3SStephen Rothwell } 11436c4841c2SAnton Blanchard 1144dc1c1ca3SStephen Rothwell printk(KERN_EMERG "Unrecoverable VMX/Altivec Unavailable Exception " 1145dc1c1ca3SStephen Rothwell "%lx at %lx\n", regs->trap, regs->nip); 1146dc1c1ca3SStephen Rothwell die("Unrecoverable VMX/Altivec Unavailable Exception", regs, SIGABRT); 1147dc1c1ca3SStephen Rothwell } 1148dc1c1ca3SStephen Rothwell 1149ce48b210SMichael Neuling void vsx_unavailable_exception(struct pt_regs *regs) 1150ce48b210SMichael Neuling { 1151ce48b210SMichael Neuling if (user_mode(regs)) { 1152ce48b210SMichael Neuling /* A user program has executed an vsx instruction, 1153ce48b210SMichael Neuling but this kernel doesn't support vsx. */ 1154ce48b210SMichael Neuling _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 1155ce48b210SMichael Neuling return; 1156ce48b210SMichael Neuling } 1157ce48b210SMichael Neuling 1158ce48b210SMichael Neuling printk(KERN_EMERG "Unrecoverable VSX Unavailable Exception " 1159ce48b210SMichael Neuling "%lx at %lx\n", regs->trap, regs->nip); 1160ce48b210SMichael Neuling die("Unrecoverable VSX Unavailable Exception", regs, SIGABRT); 1161ce48b210SMichael Neuling } 1162ce48b210SMichael Neuling 1163dc1c1ca3SStephen Rothwell void performance_monitor_exception(struct pt_regs *regs) 1164dc1c1ca3SStephen Rothwell { 116589713ed1SAnton Blanchard __get_cpu_var(irq_stat).pmu_irqs++; 116689713ed1SAnton Blanchard 1167dc1c1ca3SStephen Rothwell perf_irq(regs); 1168dc1c1ca3SStephen Rothwell } 1169dc1c1ca3SStephen Rothwell 11708dad3f92SPaul Mackerras #ifdef CONFIG_8xx 117114cf11afSPaul Mackerras void SoftwareEmulation(struct pt_regs *regs) 117214cf11afSPaul Mackerras { 117314cf11afSPaul Mackerras extern int do_mathemu(struct pt_regs *); 117414cf11afSPaul Mackerras extern int Soft_emulate_8xx(struct pt_regs *); 11755dd57a13SScott Wood #if defined(CONFIG_MATH_EMULATION) || defined(CONFIG_8XX_MINIMAL_FPEMU) 117614cf11afSPaul Mackerras int errcode; 11775dd57a13SScott Wood #endif 117814cf11afSPaul Mackerras 117914cf11afSPaul Mackerras CHECK_FULL_REGS(regs); 118014cf11afSPaul Mackerras 118114cf11afSPaul Mackerras if (!user_mode(regs)) { 118214cf11afSPaul Mackerras debugger(regs); 118314cf11afSPaul Mackerras die("Kernel Mode Software FPU Emulation", regs, SIGFPE); 118414cf11afSPaul Mackerras } 118514cf11afSPaul Mackerras 118614cf11afSPaul Mackerras #ifdef CONFIG_MATH_EMULATION 118714cf11afSPaul Mackerras errcode = do_mathemu(regs); 118880947e7cSGeert Uytterhoeven if (errcode >= 0) 1189eecff81dSAnton Blanchard PPC_WARN_EMULATED(math, regs); 11905fad293bSKumar Gala 11915fad293bSKumar Gala switch (errcode) { 11925fad293bSKumar Gala case 0: 11935fad293bSKumar Gala emulate_single_step(regs); 11945fad293bSKumar Gala return; 11955fad293bSKumar Gala case 1: { 11965fad293bSKumar Gala int code = 0; 11975fad293bSKumar Gala code = __parse_fpscr(current->thread.fpscr.val); 11985fad293bSKumar Gala _exception(SIGFPE, regs, code, regs->nip); 11995fad293bSKumar Gala return; 12005fad293bSKumar Gala } 12015fad293bSKumar Gala case -EFAULT: 12025fad293bSKumar Gala _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip); 12035fad293bSKumar Gala return; 12045fad293bSKumar Gala default: 12055fad293bSKumar Gala _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 12065fad293bSKumar Gala return; 12075fad293bSKumar Gala } 12085fad293bSKumar Gala 12095dd57a13SScott Wood #elif defined(CONFIG_8XX_MINIMAL_FPEMU) 121014cf11afSPaul Mackerras errcode = Soft_emulate_8xx(regs); 121180947e7cSGeert Uytterhoeven if (errcode >= 0) 1212eecff81dSAnton Blanchard PPC_WARN_EMULATED(8xx, regs); 121380947e7cSGeert Uytterhoeven 12145fad293bSKumar Gala switch (errcode) { 12155fad293bSKumar Gala case 0: 121614cf11afSPaul Mackerras emulate_single_step(regs); 12175fad293bSKumar Gala return; 12185fad293bSKumar Gala case 1: 12195fad293bSKumar Gala _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 12205fad293bSKumar Gala return; 12215fad293bSKumar Gala case -EFAULT: 12225fad293bSKumar Gala _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip); 12235fad293bSKumar Gala return; 12245fad293bSKumar Gala } 12255dd57a13SScott Wood #else 12265dd57a13SScott Wood _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 12275fad293bSKumar Gala #endif 122814cf11afSPaul Mackerras } 12298dad3f92SPaul Mackerras #endif /* CONFIG_8xx */ 123014cf11afSPaul Mackerras 1231172ae2e7SDave Kleikamp #ifdef CONFIG_PPC_ADV_DEBUG_REGS 12323bffb652SDave Kleikamp static void handle_debug(struct pt_regs *regs, unsigned long debug_status) 12333bffb652SDave Kleikamp { 12343bffb652SDave Kleikamp int changed = 0; 12353bffb652SDave Kleikamp /* 12363bffb652SDave Kleikamp * Determine the cause of the debug event, clear the 12373bffb652SDave Kleikamp * event flags and send a trap to the handler. Torez 12383bffb652SDave Kleikamp */ 12393bffb652SDave Kleikamp if (debug_status & (DBSR_DAC1R | DBSR_DAC1W)) { 12403bffb652SDave Kleikamp dbcr_dac(current) &= ~(DBCR_DAC1R | DBCR_DAC1W); 12413bffb652SDave Kleikamp #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE 12423bffb652SDave Kleikamp current->thread.dbcr2 &= ~DBCR2_DAC12MODE; 12433bffb652SDave Kleikamp #endif 12443bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_DAC1), debug_status, TRAP_HWBKPT, 12453bffb652SDave Kleikamp 5); 12463bffb652SDave Kleikamp changed |= 0x01; 12473bffb652SDave Kleikamp } else if (debug_status & (DBSR_DAC2R | DBSR_DAC2W)) { 12483bffb652SDave Kleikamp dbcr_dac(current) &= ~(DBCR_DAC2R | DBCR_DAC2W); 12493bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_DAC2), debug_status, TRAP_HWBKPT, 12503bffb652SDave Kleikamp 6); 12513bffb652SDave Kleikamp changed |= 0x01; 12523bffb652SDave Kleikamp } else if (debug_status & DBSR_IAC1) { 12533bffb652SDave Kleikamp current->thread.dbcr0 &= ~DBCR0_IAC1; 12543bffb652SDave Kleikamp dbcr_iac_range(current) &= ~DBCR_IAC12MODE; 12553bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_IAC1), debug_status, TRAP_HWBKPT, 12563bffb652SDave Kleikamp 1); 12573bffb652SDave Kleikamp changed |= 0x01; 12583bffb652SDave Kleikamp } else if (debug_status & DBSR_IAC2) { 12593bffb652SDave Kleikamp current->thread.dbcr0 &= ~DBCR0_IAC2; 12603bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_IAC2), debug_status, TRAP_HWBKPT, 12613bffb652SDave Kleikamp 2); 12623bffb652SDave Kleikamp changed |= 0x01; 12633bffb652SDave Kleikamp } else if (debug_status & DBSR_IAC3) { 12643bffb652SDave Kleikamp current->thread.dbcr0 &= ~DBCR0_IAC3; 12653bffb652SDave Kleikamp dbcr_iac_range(current) &= ~DBCR_IAC34MODE; 12663bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_IAC3), debug_status, TRAP_HWBKPT, 12673bffb652SDave Kleikamp 3); 12683bffb652SDave Kleikamp changed |= 0x01; 12693bffb652SDave Kleikamp } else if (debug_status & DBSR_IAC4) { 12703bffb652SDave Kleikamp current->thread.dbcr0 &= ~DBCR0_IAC4; 12713bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_IAC4), debug_status, TRAP_HWBKPT, 12723bffb652SDave Kleikamp 4); 12733bffb652SDave Kleikamp changed |= 0x01; 12743bffb652SDave Kleikamp } 12753bffb652SDave Kleikamp /* 12763bffb652SDave Kleikamp * At the point this routine was called, the MSR(DE) was turned off. 12773bffb652SDave Kleikamp * Check all other debug flags and see if that bit needs to be turned 12783bffb652SDave Kleikamp * back on or not. 12793bffb652SDave Kleikamp */ 12803bffb652SDave Kleikamp if (DBCR_ACTIVE_EVENTS(current->thread.dbcr0, current->thread.dbcr1)) 12813bffb652SDave Kleikamp regs->msr |= MSR_DE; 12823bffb652SDave Kleikamp else 12833bffb652SDave Kleikamp /* Make sure the IDM flag is off */ 12843bffb652SDave Kleikamp current->thread.dbcr0 &= ~DBCR0_IDM; 12853bffb652SDave Kleikamp 12863bffb652SDave Kleikamp if (changed & 0x01) 12873bffb652SDave Kleikamp mtspr(SPRN_DBCR0, current->thread.dbcr0); 12883bffb652SDave Kleikamp } 128914cf11afSPaul Mackerras 1290f8279621SKumar Gala void __kprobes DebugException(struct pt_regs *regs, unsigned long debug_status) 129114cf11afSPaul Mackerras { 12923bffb652SDave Kleikamp current->thread.dbsr = debug_status; 12933bffb652SDave Kleikamp 1294ec097c84SRoland McGrath /* Hack alert: On BookE, Branch Taken stops on the branch itself, while 1295ec097c84SRoland McGrath * on server, it stops on the target of the branch. In order to simulate 1296ec097c84SRoland McGrath * the server behaviour, we thus restart right away with a single step 1297ec097c84SRoland McGrath * instead of stopping here when hitting a BT 1298ec097c84SRoland McGrath */ 1299ec097c84SRoland McGrath if (debug_status & DBSR_BT) { 1300ec097c84SRoland McGrath regs->msr &= ~MSR_DE; 1301ec097c84SRoland McGrath 1302ec097c84SRoland McGrath /* Disable BT */ 1303ec097c84SRoland McGrath mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_BT); 1304ec097c84SRoland McGrath /* Clear the BT event */ 1305ec097c84SRoland McGrath mtspr(SPRN_DBSR, DBSR_BT); 1306ec097c84SRoland McGrath 1307ec097c84SRoland McGrath /* Do the single step trick only when coming from userspace */ 1308ec097c84SRoland McGrath if (user_mode(regs)) { 1309ec097c84SRoland McGrath current->thread.dbcr0 &= ~DBCR0_BT; 1310ec097c84SRoland McGrath current->thread.dbcr0 |= DBCR0_IDM | DBCR0_IC; 1311ec097c84SRoland McGrath regs->msr |= MSR_DE; 1312ec097c84SRoland McGrath return; 1313ec097c84SRoland McGrath } 1314ec097c84SRoland McGrath 1315ec097c84SRoland McGrath if (notify_die(DIE_SSTEP, "block_step", regs, 5, 1316ec097c84SRoland McGrath 5, SIGTRAP) == NOTIFY_STOP) { 1317ec097c84SRoland McGrath return; 1318ec097c84SRoland McGrath } 1319ec097c84SRoland McGrath if (debugger_sstep(regs)) 1320ec097c84SRoland McGrath return; 1321ec097c84SRoland McGrath } else if (debug_status & DBSR_IC) { /* Instruction complete */ 132214cf11afSPaul Mackerras regs->msr &= ~MSR_DE; 1323f8279621SKumar Gala 132414cf11afSPaul Mackerras /* Disable instruction completion */ 132514cf11afSPaul Mackerras mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_IC); 132614cf11afSPaul Mackerras /* Clear the instruction completion event */ 132714cf11afSPaul Mackerras mtspr(SPRN_DBSR, DBSR_IC); 1328f8279621SKumar Gala 1329f8279621SKumar Gala if (notify_die(DIE_SSTEP, "single_step", regs, 5, 1330f8279621SKumar Gala 5, SIGTRAP) == NOTIFY_STOP) { 133114cf11afSPaul Mackerras return; 133214cf11afSPaul Mackerras } 1333f8279621SKumar Gala 1334f8279621SKumar Gala if (debugger_sstep(regs)) 1335f8279621SKumar Gala return; 1336f8279621SKumar Gala 13373bffb652SDave Kleikamp if (user_mode(regs)) { 13383bffb652SDave Kleikamp current->thread.dbcr0 &= ~DBCR0_IC; 13393bffb652SDave Kleikamp if (DBCR_ACTIVE_EVENTS(current->thread.dbcr0, 13403bffb652SDave Kleikamp current->thread.dbcr1)) 13413bffb652SDave Kleikamp regs->msr |= MSR_DE; 13423bffb652SDave Kleikamp else 13433bffb652SDave Kleikamp /* Make sure the IDM bit is off */ 13443bffb652SDave Kleikamp current->thread.dbcr0 &= ~DBCR0_IDM; 13453bffb652SDave Kleikamp } 1346f8279621SKumar Gala 1347f8279621SKumar Gala _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip); 13483bffb652SDave Kleikamp } else 13493bffb652SDave Kleikamp handle_debug(regs, debug_status); 135014cf11afSPaul Mackerras } 1351172ae2e7SDave Kleikamp #endif /* CONFIG_PPC_ADV_DEBUG_REGS */ 135214cf11afSPaul Mackerras 135314cf11afSPaul Mackerras #if !defined(CONFIG_TAU_INT) 135414cf11afSPaul Mackerras void TAUException(struct pt_regs *regs) 135514cf11afSPaul Mackerras { 135614cf11afSPaul Mackerras printk("TAU trap at PC: %lx, MSR: %lx, vector=%lx %s\n", 135714cf11afSPaul Mackerras regs->nip, regs->msr, regs->trap, print_tainted()); 135814cf11afSPaul Mackerras } 135914cf11afSPaul Mackerras #endif /* CONFIG_INT_TAU */ 136014cf11afSPaul Mackerras 136114cf11afSPaul Mackerras #ifdef CONFIG_ALTIVEC 1362dc1c1ca3SStephen Rothwell void altivec_assist_exception(struct pt_regs *regs) 136314cf11afSPaul Mackerras { 136414cf11afSPaul Mackerras int err; 136514cf11afSPaul Mackerras 136614cf11afSPaul Mackerras if (!user_mode(regs)) { 136714cf11afSPaul Mackerras printk(KERN_EMERG "VMX/Altivec assist exception in kernel mode" 136814cf11afSPaul Mackerras " at %lx\n", regs->nip); 13698dad3f92SPaul Mackerras die("Kernel VMX/Altivec assist exception", regs, SIGILL); 137014cf11afSPaul Mackerras } 137114cf11afSPaul Mackerras 1372dc1c1ca3SStephen Rothwell flush_altivec_to_thread(current); 1373dc1c1ca3SStephen Rothwell 1374eecff81dSAnton Blanchard PPC_WARN_EMULATED(altivec, regs); 137514cf11afSPaul Mackerras err = emulate_altivec(regs); 137614cf11afSPaul Mackerras if (err == 0) { 137714cf11afSPaul Mackerras regs->nip += 4; /* skip emulated instruction */ 137814cf11afSPaul Mackerras emulate_single_step(regs); 137914cf11afSPaul Mackerras return; 138014cf11afSPaul Mackerras } 138114cf11afSPaul Mackerras 138214cf11afSPaul Mackerras if (err == -EFAULT) { 138314cf11afSPaul Mackerras /* got an error reading the instruction */ 138414cf11afSPaul Mackerras _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip); 138514cf11afSPaul Mackerras } else { 138614cf11afSPaul Mackerras /* didn't recognize the instruction */ 138714cf11afSPaul Mackerras /* XXX quick hack for now: set the non-Java bit in the VSCR */ 138876462232SChristian Dietrich printk_ratelimited(KERN_ERR "Unrecognized altivec instruction " 138914cf11afSPaul Mackerras "in %s at %lx\n", current->comm, regs->nip); 139014cf11afSPaul Mackerras current->thread.vscr.u[3] |= 0x10000; 139114cf11afSPaul Mackerras } 139214cf11afSPaul Mackerras } 139314cf11afSPaul Mackerras #endif /* CONFIG_ALTIVEC */ 139414cf11afSPaul Mackerras 1395ce48b210SMichael Neuling #ifdef CONFIG_VSX 1396ce48b210SMichael Neuling void vsx_assist_exception(struct pt_regs *regs) 1397ce48b210SMichael Neuling { 1398ce48b210SMichael Neuling if (!user_mode(regs)) { 1399ce48b210SMichael Neuling printk(KERN_EMERG "VSX assist exception in kernel mode" 1400ce48b210SMichael Neuling " at %lx\n", regs->nip); 1401ce48b210SMichael Neuling die("Kernel VSX assist exception", regs, SIGILL); 1402ce48b210SMichael Neuling } 1403ce48b210SMichael Neuling 1404ce48b210SMichael Neuling flush_vsx_to_thread(current); 1405ce48b210SMichael Neuling printk(KERN_INFO "VSX assist not supported at %lx\n", regs->nip); 1406ce48b210SMichael Neuling _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 1407ce48b210SMichael Neuling } 1408ce48b210SMichael Neuling #endif /* CONFIG_VSX */ 1409ce48b210SMichael Neuling 141014cf11afSPaul Mackerras #ifdef CONFIG_FSL_BOOKE 141114cf11afSPaul Mackerras void CacheLockingException(struct pt_regs *regs, unsigned long address, 141214cf11afSPaul Mackerras unsigned long error_code) 141314cf11afSPaul Mackerras { 141414cf11afSPaul Mackerras /* We treat cache locking instructions from the user 141514cf11afSPaul Mackerras * as priv ops, in the future we could try to do 141614cf11afSPaul Mackerras * something smarter 141714cf11afSPaul Mackerras */ 141814cf11afSPaul Mackerras if (error_code & (ESR_DLK|ESR_ILK)) 141914cf11afSPaul Mackerras _exception(SIGILL, regs, ILL_PRVOPC, regs->nip); 142014cf11afSPaul Mackerras return; 142114cf11afSPaul Mackerras } 142214cf11afSPaul Mackerras #endif /* CONFIG_FSL_BOOKE */ 142314cf11afSPaul Mackerras 142414cf11afSPaul Mackerras #ifdef CONFIG_SPE 142514cf11afSPaul Mackerras void SPEFloatingPointException(struct pt_regs *regs) 142614cf11afSPaul Mackerras { 14276a800f36SLiu Yu extern int do_spe_mathemu(struct pt_regs *regs); 142814cf11afSPaul Mackerras unsigned long spefscr; 142914cf11afSPaul Mackerras int fpexc_mode; 143014cf11afSPaul Mackerras int code = 0; 14316a800f36SLiu Yu int err; 14326a800f36SLiu Yu 1433685659eeSyu liu flush_spe_to_thread(current); 143414cf11afSPaul Mackerras 143514cf11afSPaul Mackerras spefscr = current->thread.spefscr; 143614cf11afSPaul Mackerras fpexc_mode = current->thread.fpexc_mode; 143714cf11afSPaul Mackerras 143814cf11afSPaul Mackerras if ((spefscr & SPEFSCR_FOVF) && (fpexc_mode & PR_FP_EXC_OVF)) { 143914cf11afSPaul Mackerras code = FPE_FLTOVF; 144014cf11afSPaul Mackerras } 144114cf11afSPaul Mackerras else if ((spefscr & SPEFSCR_FUNF) && (fpexc_mode & PR_FP_EXC_UND)) { 144214cf11afSPaul Mackerras code = FPE_FLTUND; 144314cf11afSPaul Mackerras } 144414cf11afSPaul Mackerras else if ((spefscr & SPEFSCR_FDBZ) && (fpexc_mode & PR_FP_EXC_DIV)) 144514cf11afSPaul Mackerras code = FPE_FLTDIV; 144614cf11afSPaul Mackerras else if ((spefscr & SPEFSCR_FINV) && (fpexc_mode & PR_FP_EXC_INV)) { 144714cf11afSPaul Mackerras code = FPE_FLTINV; 144814cf11afSPaul Mackerras } 144914cf11afSPaul Mackerras else if ((spefscr & (SPEFSCR_FG | SPEFSCR_FX)) && (fpexc_mode & PR_FP_EXC_RES)) 145014cf11afSPaul Mackerras code = FPE_FLTRES; 145114cf11afSPaul Mackerras 14526a800f36SLiu Yu err = do_spe_mathemu(regs); 14536a800f36SLiu Yu if (err == 0) { 14546a800f36SLiu Yu regs->nip += 4; /* skip emulated instruction */ 14556a800f36SLiu Yu emulate_single_step(regs); 145614cf11afSPaul Mackerras return; 145714cf11afSPaul Mackerras } 14586a800f36SLiu Yu 14596a800f36SLiu Yu if (err == -EFAULT) { 14606a800f36SLiu Yu /* got an error reading the instruction */ 14616a800f36SLiu Yu _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip); 14626a800f36SLiu Yu } else if (err == -EINVAL) { 14636a800f36SLiu Yu /* didn't recognize the instruction */ 14646a800f36SLiu Yu printk(KERN_ERR "unrecognized spe instruction " 14656a800f36SLiu Yu "in %s at %lx\n", current->comm, regs->nip); 14666a800f36SLiu Yu } else { 14676a800f36SLiu Yu _exception(SIGFPE, regs, code, regs->nip); 14686a800f36SLiu Yu } 14696a800f36SLiu Yu 14706a800f36SLiu Yu return; 14716a800f36SLiu Yu } 14726a800f36SLiu Yu 14736a800f36SLiu Yu void SPEFloatingPointRoundException(struct pt_regs *regs) 14746a800f36SLiu Yu { 14756a800f36SLiu Yu extern int speround_handler(struct pt_regs *regs); 14766a800f36SLiu Yu int err; 14776a800f36SLiu Yu 14786a800f36SLiu Yu preempt_disable(); 14796a800f36SLiu Yu if (regs->msr & MSR_SPE) 14806a800f36SLiu Yu giveup_spe(current); 14816a800f36SLiu Yu preempt_enable(); 14826a800f36SLiu Yu 14836a800f36SLiu Yu regs->nip -= 4; 14846a800f36SLiu Yu err = speround_handler(regs); 14856a800f36SLiu Yu if (err == 0) { 14866a800f36SLiu Yu regs->nip += 4; /* skip emulated instruction */ 14876a800f36SLiu Yu emulate_single_step(regs); 14886a800f36SLiu Yu return; 14896a800f36SLiu Yu } 14906a800f36SLiu Yu 14916a800f36SLiu Yu if (err == -EFAULT) { 14926a800f36SLiu Yu /* got an error reading the instruction */ 14936a800f36SLiu Yu _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip); 14946a800f36SLiu Yu } else if (err == -EINVAL) { 14956a800f36SLiu Yu /* didn't recognize the instruction */ 14966a800f36SLiu Yu printk(KERN_ERR "unrecognized spe instruction " 14976a800f36SLiu Yu "in %s at %lx\n", current->comm, regs->nip); 14986a800f36SLiu Yu } else { 14996a800f36SLiu Yu _exception(SIGFPE, regs, 0, regs->nip); 15006a800f36SLiu Yu return; 15016a800f36SLiu Yu } 15026a800f36SLiu Yu } 150314cf11afSPaul Mackerras #endif 150414cf11afSPaul Mackerras 1505dc1c1ca3SStephen Rothwell /* 1506dc1c1ca3SStephen Rothwell * We enter here if we get an unrecoverable exception, that is, one 1507dc1c1ca3SStephen Rothwell * that happened at a point where the RI (recoverable interrupt) bit 1508dc1c1ca3SStephen Rothwell * in the MSR is 0. This indicates that SRR0/1 are live, and that 1509dc1c1ca3SStephen Rothwell * we therefore lost state by taking this exception. 1510dc1c1ca3SStephen Rothwell */ 1511dc1c1ca3SStephen Rothwell void unrecoverable_exception(struct pt_regs *regs) 1512dc1c1ca3SStephen Rothwell { 1513dc1c1ca3SStephen Rothwell printk(KERN_EMERG "Unrecoverable exception %lx at %lx\n", 1514dc1c1ca3SStephen Rothwell regs->trap, regs->nip); 1515dc1c1ca3SStephen Rothwell die("Unrecoverable exception", regs, SIGABRT); 1516dc1c1ca3SStephen Rothwell } 1517dc1c1ca3SStephen Rothwell 1518*1e18c17aSJason Gunthorpe #if defined(CONFIG_BOOKE_WDT) || defined(CONFIG_40x) 151914cf11afSPaul Mackerras /* 152014cf11afSPaul Mackerras * Default handler for a Watchdog exception, 152114cf11afSPaul Mackerras * spins until a reboot occurs 152214cf11afSPaul Mackerras */ 152314cf11afSPaul Mackerras void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs) 152414cf11afSPaul Mackerras { 152514cf11afSPaul Mackerras /* Generic WatchdogHandler, implement your own */ 152614cf11afSPaul Mackerras mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE)); 152714cf11afSPaul Mackerras return; 152814cf11afSPaul Mackerras } 152914cf11afSPaul Mackerras 153014cf11afSPaul Mackerras void WatchdogException(struct pt_regs *regs) 153114cf11afSPaul Mackerras { 153214cf11afSPaul Mackerras printk (KERN_EMERG "PowerPC Book-E Watchdog Exception\n"); 153314cf11afSPaul Mackerras WatchdogHandler(regs); 153414cf11afSPaul Mackerras } 153514cf11afSPaul Mackerras #endif 1536dc1c1ca3SStephen Rothwell 1537dc1c1ca3SStephen Rothwell /* 1538dc1c1ca3SStephen Rothwell * We enter here if we discover during exception entry that we are 1539dc1c1ca3SStephen Rothwell * running in supervisor mode with a userspace value in the stack pointer. 1540dc1c1ca3SStephen Rothwell */ 1541dc1c1ca3SStephen Rothwell void kernel_bad_stack(struct pt_regs *regs) 1542dc1c1ca3SStephen Rothwell { 1543dc1c1ca3SStephen Rothwell printk(KERN_EMERG "Bad kernel stack pointer %lx at %lx\n", 1544dc1c1ca3SStephen Rothwell regs->gpr[1], regs->nip); 1545dc1c1ca3SStephen Rothwell die("Bad kernel stack pointer", regs, SIGABRT); 1546dc1c1ca3SStephen Rothwell } 154714cf11afSPaul Mackerras 154814cf11afSPaul Mackerras void __init trap_init(void) 154914cf11afSPaul Mackerras { 155014cf11afSPaul Mackerras } 155180947e7cSGeert Uytterhoeven 155280947e7cSGeert Uytterhoeven 155380947e7cSGeert Uytterhoeven #ifdef CONFIG_PPC_EMULATED_STATS 155480947e7cSGeert Uytterhoeven 155580947e7cSGeert Uytterhoeven #define WARN_EMULATED_SETUP(type) .type = { .name = #type } 155680947e7cSGeert Uytterhoeven 155780947e7cSGeert Uytterhoeven struct ppc_emulated ppc_emulated = { 155880947e7cSGeert Uytterhoeven #ifdef CONFIG_ALTIVEC 155980947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(altivec), 156080947e7cSGeert Uytterhoeven #endif 156180947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(dcba), 156280947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(dcbz), 156380947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(fp_pair), 156480947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(isel), 156580947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(mcrxr), 156680947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(mfpvr), 156780947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(multiple), 156880947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(popcntb), 156980947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(spe), 157080947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(string), 157180947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(unaligned), 157280947e7cSGeert Uytterhoeven #ifdef CONFIG_MATH_EMULATION 157380947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(math), 157480947e7cSGeert Uytterhoeven #elif defined(CONFIG_8XX_MINIMAL_FPEMU) 157580947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(8xx), 157680947e7cSGeert Uytterhoeven #endif 157780947e7cSGeert Uytterhoeven #ifdef CONFIG_VSX 157880947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(vsx), 157980947e7cSGeert Uytterhoeven #endif 1580efcac658SAlexey Kardashevskiy #ifdef CONFIG_PPC64 1581efcac658SAlexey Kardashevskiy WARN_EMULATED_SETUP(mfdscr), 1582efcac658SAlexey Kardashevskiy WARN_EMULATED_SETUP(mtdscr), 1583efcac658SAlexey Kardashevskiy #endif 158480947e7cSGeert Uytterhoeven }; 158580947e7cSGeert Uytterhoeven 158680947e7cSGeert Uytterhoeven u32 ppc_warn_emulated; 158780947e7cSGeert Uytterhoeven 158880947e7cSGeert Uytterhoeven void ppc_warn_emulated_print(const char *type) 158980947e7cSGeert Uytterhoeven { 159076462232SChristian Dietrich pr_warn_ratelimited("%s used emulated %s instruction\n", current->comm, 159180947e7cSGeert Uytterhoeven type); 159280947e7cSGeert Uytterhoeven } 159380947e7cSGeert Uytterhoeven 159480947e7cSGeert Uytterhoeven static int __init ppc_warn_emulated_init(void) 159580947e7cSGeert Uytterhoeven { 159680947e7cSGeert Uytterhoeven struct dentry *dir, *d; 159780947e7cSGeert Uytterhoeven unsigned int i; 159880947e7cSGeert Uytterhoeven struct ppc_emulated_entry *entries = (void *)&ppc_emulated; 159980947e7cSGeert Uytterhoeven 160080947e7cSGeert Uytterhoeven if (!powerpc_debugfs_root) 160180947e7cSGeert Uytterhoeven return -ENODEV; 160280947e7cSGeert Uytterhoeven 160380947e7cSGeert Uytterhoeven dir = debugfs_create_dir("emulated_instructions", 160480947e7cSGeert Uytterhoeven powerpc_debugfs_root); 160580947e7cSGeert Uytterhoeven if (!dir) 160680947e7cSGeert Uytterhoeven return -ENOMEM; 160780947e7cSGeert Uytterhoeven 160880947e7cSGeert Uytterhoeven d = debugfs_create_u32("do_warn", S_IRUGO | S_IWUSR, dir, 160980947e7cSGeert Uytterhoeven &ppc_warn_emulated); 161080947e7cSGeert Uytterhoeven if (!d) 161180947e7cSGeert Uytterhoeven goto fail; 161280947e7cSGeert Uytterhoeven 161380947e7cSGeert Uytterhoeven for (i = 0; i < sizeof(ppc_emulated)/sizeof(*entries); i++) { 161480947e7cSGeert Uytterhoeven d = debugfs_create_u32(entries[i].name, S_IRUGO | S_IWUSR, dir, 161580947e7cSGeert Uytterhoeven (u32 *)&entries[i].val.counter); 161680947e7cSGeert Uytterhoeven if (!d) 161780947e7cSGeert Uytterhoeven goto fail; 161880947e7cSGeert Uytterhoeven } 161980947e7cSGeert Uytterhoeven 162080947e7cSGeert Uytterhoeven return 0; 162180947e7cSGeert Uytterhoeven 162280947e7cSGeert Uytterhoeven fail: 162380947e7cSGeert Uytterhoeven debugfs_remove_recursive(dir); 162480947e7cSGeert Uytterhoeven return -ENOMEM; 162580947e7cSGeert Uytterhoeven } 162680947e7cSGeert Uytterhoeven 162780947e7cSGeert Uytterhoeven device_initcall(ppc_warn_emulated_init); 162880947e7cSGeert Uytterhoeven 162980947e7cSGeert Uytterhoeven #endif /* CONFIG_PPC_EMULATED_STATS */ 1630