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> 20b17b0153SIngo Molnar #include <linux/sched/debug.h> 2114cf11afSPaul Mackerras #include <linux/kernel.h> 2214cf11afSPaul Mackerras #include <linux/mm.h> 2314cf11afSPaul Mackerras #include <linux/stddef.h> 2414cf11afSPaul Mackerras #include <linux/unistd.h> 258dad3f92SPaul Mackerras #include <linux/ptrace.h> 2614cf11afSPaul Mackerras #include <linux/user.h> 2714cf11afSPaul Mackerras #include <linux/interrupt.h> 2814cf11afSPaul Mackerras #include <linux/init.h> 298a39b05fSPaul Gortmaker #include <linux/extable.h> 308a39b05fSPaul Gortmaker #include <linux/module.h> /* print_modules */ 318dad3f92SPaul Mackerras #include <linux/prctl.h> 3214cf11afSPaul Mackerras #include <linux/delay.h> 3314cf11afSPaul Mackerras #include <linux/kprobes.h> 34cc532915SMichael Ellerman #include <linux/kexec.h> 355474c120SMichael Hanselmann #include <linux/backlight.h> 3673c9ceabSJeremy Fitzhardinge #include <linux/bug.h> 371eeb66a1SChristoph Hellwig #include <linux/kdebug.h> 3876462232SChristian Dietrich #include <linux/ratelimit.h> 39ba12eedeSLi Zhong #include <linux/context_tracking.h> 4014cf11afSPaul Mackerras 4180947e7cSGeert Uytterhoeven #include <asm/emulated_ops.h> 4214cf11afSPaul Mackerras #include <asm/pgtable.h> 437c0f6ba6SLinus Torvalds #include <linux/uaccess.h> 447644d581SMichael Ellerman #include <asm/debugfs.h> 4514cf11afSPaul Mackerras #include <asm/io.h> 4686417780SPaul Mackerras #include <asm/machdep.h> 4786417780SPaul Mackerras #include <asm/rtas.h> 48f7f6f4feSDavid Gibson #include <asm/pmc.h> 4914cf11afSPaul Mackerras #include <asm/reg.h> 5014cf11afSPaul Mackerras #ifdef CONFIG_PMAC_BACKLIGHT 5114cf11afSPaul Mackerras #include <asm/backlight.h> 5214cf11afSPaul Mackerras #endif 53dc1c1ca3SStephen Rothwell #ifdef CONFIG_PPC64 5486417780SPaul Mackerras #include <asm/firmware.h> 55dc1c1ca3SStephen Rothwell #include <asm/processor.h> 566ce6c629SMichael Neuling #include <asm/tm.h> 57dc1c1ca3SStephen Rothwell #endif 58c0ce7d08SDavid Wilder #include <asm/kexec.h> 5916c57b36SKumar Gala #include <asm/ppc-opcode.h> 60cce1f106SShaohui Xie #include <asm/rio.h> 61ebaeb5aeSMahesh Salgaonkar #include <asm/fadump.h> 62ae3a197eSDavid Howells #include <asm/switch_to.h> 63f54db641SMichael Neuling #include <asm/tm.h> 64ae3a197eSDavid Howells #include <asm/debug.h> 6542f5b4caSDaniel Axtens #include <asm/asm-prototypes.h> 66fd7bacbcSMahesh Salgaonkar #include <asm/hmi.h> 674e0e3435SHongtao Jia #include <sysdev/fsl_pci.h> 686cc89badSNaveen N. Rao #include <asm/kprobes.h> 69dc1c1ca3SStephen Rothwell 70da665885SThiago Jung Bauermann #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC_CORE) 715be3492fSAnton Blanchard int (*__debugger)(struct pt_regs *regs) __read_mostly; 725be3492fSAnton Blanchard int (*__debugger_ipi)(struct pt_regs *regs) __read_mostly; 735be3492fSAnton Blanchard int (*__debugger_bpt)(struct pt_regs *regs) __read_mostly; 745be3492fSAnton Blanchard int (*__debugger_sstep)(struct pt_regs *regs) __read_mostly; 755be3492fSAnton Blanchard int (*__debugger_iabr_match)(struct pt_regs *regs) __read_mostly; 769422de3eSMichael Neuling int (*__debugger_break_match)(struct pt_regs *regs) __read_mostly; 775be3492fSAnton Blanchard int (*__debugger_fault_handler)(struct pt_regs *regs) __read_mostly; 7814cf11afSPaul Mackerras 7914cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger); 8014cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_ipi); 8114cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_bpt); 8214cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_sstep); 8314cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_iabr_match); 849422de3eSMichael Neuling EXPORT_SYMBOL(__debugger_break_match); 8514cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_fault_handler); 8614cf11afSPaul Mackerras #endif 8714cf11afSPaul Mackerras 888b3c34cfSMichael Neuling /* Transactional Memory trap debug */ 898b3c34cfSMichael Neuling #ifdef TM_DEBUG_SW 908b3c34cfSMichael Neuling #define TM_DEBUG(x...) printk(KERN_INFO x) 918b3c34cfSMichael Neuling #else 928b3c34cfSMichael Neuling #define TM_DEBUG(x...) do { } while(0) 938b3c34cfSMichael Neuling #endif 948b3c34cfSMichael Neuling 9514cf11afSPaul Mackerras /* 9614cf11afSPaul Mackerras * Trap & Exception support 9714cf11afSPaul Mackerras */ 9814cf11afSPaul Mackerras 996031d9d9Santon@samba.org #ifdef CONFIG_PMAC_BACKLIGHT 1006031d9d9Santon@samba.org static void pmac_backlight_unblank(void) 1016031d9d9Santon@samba.org { 1026031d9d9Santon@samba.org mutex_lock(&pmac_backlight_mutex); 1036031d9d9Santon@samba.org if (pmac_backlight) { 1046031d9d9Santon@samba.org struct backlight_properties *props; 1056031d9d9Santon@samba.org 1066031d9d9Santon@samba.org props = &pmac_backlight->props; 1076031d9d9Santon@samba.org props->brightness = props->max_brightness; 1086031d9d9Santon@samba.org props->power = FB_BLANK_UNBLANK; 1096031d9d9Santon@samba.org backlight_update_status(pmac_backlight); 1106031d9d9Santon@samba.org } 1116031d9d9Santon@samba.org mutex_unlock(&pmac_backlight_mutex); 1126031d9d9Santon@samba.org } 1136031d9d9Santon@samba.org #else 1146031d9d9Santon@samba.org static inline void pmac_backlight_unblank(void) { } 1156031d9d9Santon@samba.org #endif 1166031d9d9Santon@samba.org 117760ca4dcSAnton Blanchard static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED; 118760ca4dcSAnton Blanchard static int die_owner = -1; 119760ca4dcSAnton Blanchard static unsigned int die_nest_count; 120c0ce7d08SDavid Wilder static int die_counter; 121760ca4dcSAnton Blanchard 12203465f89SNicholas Piggin static unsigned long oops_begin(struct pt_regs *regs) 123760ca4dcSAnton Blanchard { 124760ca4dcSAnton Blanchard int cpu; 12534c2a14fSanton@samba.org unsigned long flags; 12614cf11afSPaul Mackerras 127293e4688Santon@samba.org oops_enter(); 128293e4688Santon@samba.org 129760ca4dcSAnton Blanchard /* racy, but better than risking deadlock. */ 130760ca4dcSAnton Blanchard raw_local_irq_save(flags); 131760ca4dcSAnton Blanchard cpu = smp_processor_id(); 132760ca4dcSAnton Blanchard if (!arch_spin_trylock(&die_lock)) { 133760ca4dcSAnton Blanchard if (cpu == die_owner) 134760ca4dcSAnton Blanchard /* nested oops. should stop eventually */; 135760ca4dcSAnton Blanchard else 136760ca4dcSAnton Blanchard arch_spin_lock(&die_lock); 137760ca4dcSAnton Blanchard } 138760ca4dcSAnton Blanchard die_nest_count++; 139760ca4dcSAnton Blanchard die_owner = cpu; 14014cf11afSPaul Mackerras console_verbose(); 14114cf11afSPaul Mackerras bust_spinlocks(1); 1426031d9d9Santon@samba.org if (machine_is(powermac)) 1436031d9d9Santon@samba.org pmac_backlight_unblank(); 144760ca4dcSAnton Blanchard return flags; 14534c2a14fSanton@samba.org } 14603465f89SNicholas Piggin NOKPROBE_SYMBOL(oops_begin); 1475474c120SMichael Hanselmann 14803465f89SNicholas Piggin static void oops_end(unsigned long flags, struct pt_regs *regs, 149760ca4dcSAnton Blanchard int signr) 150760ca4dcSAnton Blanchard { 15114cf11afSPaul Mackerras bust_spinlocks(0); 152373d4d09SRusty Russell add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE); 153760ca4dcSAnton Blanchard die_nest_count--; 15458154c8cSAnton Blanchard oops_exit(); 15558154c8cSAnton Blanchard printk("\n"); 1567458e8b2SNicholas Piggin if (!die_nest_count) { 157760ca4dcSAnton Blanchard /* Nest count reaches zero, release the lock. */ 1587458e8b2SNicholas Piggin die_owner = -1; 159760ca4dcSAnton Blanchard arch_spin_unlock(&die_lock); 1607458e8b2SNicholas Piggin } 161760ca4dcSAnton Blanchard raw_local_irq_restore(flags); 162cc532915SMichael Ellerman 163ebaeb5aeSMahesh Salgaonkar crash_fadump(regs, "die oops"); 164ebaeb5aeSMahesh Salgaonkar 1659b00ac06SAnton Blanchard /* 1669b00ac06SAnton Blanchard * A system reset (0x100) is a request to dump, so we always send 1679b00ac06SAnton Blanchard * it through the crashdump code. 1689b00ac06SAnton Blanchard */ 1699b00ac06SAnton Blanchard if (kexec_should_crash(current) || (TRAP(regs) == 0x100)) { 170cc532915SMichael Ellerman crash_kexec(regs); 1719b00ac06SAnton Blanchard 1729b00ac06SAnton Blanchard /* 1739b00ac06SAnton Blanchard * We aren't the primary crash CPU. We need to send it 1749b00ac06SAnton Blanchard * to a holding pattern to avoid it ending up in the panic 1759b00ac06SAnton Blanchard * code. 1769b00ac06SAnton Blanchard */ 177c0ce7d08SDavid Wilder crash_kexec_secondary(regs); 1789b00ac06SAnton Blanchard } 17914cf11afSPaul Mackerras 180760ca4dcSAnton Blanchard if (!signr) 181760ca4dcSAnton Blanchard return; 182760ca4dcSAnton Blanchard 18358154c8cSAnton Blanchard /* 18458154c8cSAnton Blanchard * While our oops output is serialised by a spinlock, output 18558154c8cSAnton Blanchard * from panic() called below can race and corrupt it. If we 18658154c8cSAnton Blanchard * know we are going to panic, delay for 1 second so we have a 18758154c8cSAnton Blanchard * chance to get clean backtraces from all CPUs that are oopsing. 18858154c8cSAnton Blanchard */ 18958154c8cSAnton Blanchard if (in_interrupt() || panic_on_oops || !current->pid || 19058154c8cSAnton Blanchard is_global_init(current)) { 19158154c8cSAnton Blanchard mdelay(MSEC_PER_SEC); 19258154c8cSAnton Blanchard } 19358154c8cSAnton Blanchard 19414cf11afSPaul Mackerras if (in_interrupt()) 19514cf11afSPaul Mackerras panic("Fatal exception in interrupt"); 196cea6a4baSHorms if (panic_on_oops) 197012c437dSHorms panic("Fatal exception"); 198760ca4dcSAnton Blanchard do_exit(signr); 199760ca4dcSAnton Blanchard } 20003465f89SNicholas Piggin NOKPROBE_SYMBOL(oops_end); 201cea6a4baSHorms 20203465f89SNicholas Piggin static int __die(const char *str, struct pt_regs *regs, long err) 203760ca4dcSAnton Blanchard { 204760ca4dcSAnton Blanchard printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter); 205760ca4dcSAnton Blanchard #ifdef CONFIG_PREEMPT 206760ca4dcSAnton Blanchard printk("PREEMPT "); 207760ca4dcSAnton Blanchard #endif 208760ca4dcSAnton Blanchard #ifdef CONFIG_SMP 209760ca4dcSAnton Blanchard printk("SMP NR_CPUS=%d ", NR_CPUS); 210760ca4dcSAnton Blanchard #endif 211e7df0d88SJoonsoo Kim if (debug_pagealloc_enabled()) 212760ca4dcSAnton Blanchard printk("DEBUG_PAGEALLOC "); 213760ca4dcSAnton Blanchard #ifdef CONFIG_NUMA 214760ca4dcSAnton Blanchard printk("NUMA "); 215760ca4dcSAnton Blanchard #endif 216760ca4dcSAnton Blanchard printk("%s\n", ppc_md.name ? ppc_md.name : ""); 217760ca4dcSAnton Blanchard 218760ca4dcSAnton Blanchard if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV) == NOTIFY_STOP) 219760ca4dcSAnton Blanchard return 1; 220760ca4dcSAnton Blanchard 221760ca4dcSAnton Blanchard print_modules(); 222760ca4dcSAnton Blanchard show_regs(regs); 22314cf11afSPaul Mackerras 22414cf11afSPaul Mackerras return 0; 22514cf11afSPaul Mackerras } 22603465f89SNicholas Piggin NOKPROBE_SYMBOL(__die); 22714cf11afSPaul Mackerras 228760ca4dcSAnton Blanchard void die(const char *str, struct pt_regs *regs, long err) 229760ca4dcSAnton Blanchard { 2306f44b20eSNicholas Piggin unsigned long flags; 231760ca4dcSAnton Blanchard 2326f44b20eSNicholas Piggin if (debugger(regs)) 2336f44b20eSNicholas Piggin return; 2346f44b20eSNicholas Piggin 2356f44b20eSNicholas Piggin flags = oops_begin(regs); 236760ca4dcSAnton Blanchard if (__die(str, regs, err)) 237760ca4dcSAnton Blanchard err = 0; 238760ca4dcSAnton Blanchard oops_end(flags, regs, err); 239760ca4dcSAnton Blanchard } 240*15770a13SNaveen N. Rao NOKPROBE_SYMBOL(die); 241760ca4dcSAnton Blanchard 24225baa35bSOleg Nesterov void user_single_step_siginfo(struct task_struct *tsk, 24325baa35bSOleg Nesterov struct pt_regs *regs, siginfo_t *info) 24425baa35bSOleg Nesterov { 24525baa35bSOleg Nesterov memset(info, 0, sizeof(*info)); 24625baa35bSOleg Nesterov info->si_signo = SIGTRAP; 24725baa35bSOleg Nesterov info->si_code = TRAP_TRACE; 24825baa35bSOleg Nesterov info->si_addr = (void __user *)regs->nip; 24925baa35bSOleg Nesterov } 25025baa35bSOleg Nesterov 25114cf11afSPaul Mackerras void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr) 25214cf11afSPaul Mackerras { 25314cf11afSPaul Mackerras siginfo_t info; 254d0c3d534SOlof Johansson const char fmt32[] = KERN_INFO "%s[%d]: unhandled signal %d " \ 255d0c3d534SOlof Johansson "at %08lx nip %08lx lr %08lx code %x\n"; 256d0c3d534SOlof Johansson const char fmt64[] = KERN_INFO "%s[%d]: unhandled signal %d " \ 257d0c3d534SOlof Johansson "at %016lx nip %016lx lr %016lx code %x\n"; 25814cf11afSPaul Mackerras 25914cf11afSPaul Mackerras if (!user_mode(regs)) { 260760ca4dcSAnton Blanchard die("Exception in kernel mode", regs, signr); 26114cf11afSPaul Mackerras return; 262760ca4dcSAnton Blanchard } 263760ca4dcSAnton Blanchard 264760ca4dcSAnton Blanchard if (show_unhandled_signals && unhandled_signal(current, signr)) { 26576462232SChristian Dietrich printk_ratelimited(regs->msr & MSR_64BIT ? fmt64 : fmt32, 266d0c3d534SOlof Johansson current->comm, current->pid, signr, 267d0c3d534SOlof Johansson addr, regs->nip, regs->link, code); 26814cf11afSPaul Mackerras } 26914cf11afSPaul Mackerras 270a3512b2dSBenjamin Herrenschmidt if (arch_irqs_disabled() && !arch_irq_disabled_regs(regs)) 2719f2f79e3SBenjamin Herrenschmidt local_irq_enable(); 2729f2f79e3SBenjamin Herrenschmidt 27341ab5266SAnanth N Mavinakayanahalli current->thread.trap_nr = code; 27414cf11afSPaul Mackerras memset(&info, 0, sizeof(info)); 27514cf11afSPaul Mackerras info.si_signo = signr; 27614cf11afSPaul Mackerras info.si_code = code; 27714cf11afSPaul Mackerras info.si_addr = (void __user *) addr; 27814cf11afSPaul Mackerras force_sig_info(signr, &info, current); 27914cf11afSPaul Mackerras } 28014cf11afSPaul Mackerras 28114cf11afSPaul Mackerras void system_reset_exception(struct pt_regs *regs) 28214cf11afSPaul Mackerras { 2832b4f3ac5SNicholas Piggin /* 2842b4f3ac5SNicholas Piggin * Avoid crashes in case of nested NMI exceptions. Recoverability 2852b4f3ac5SNicholas Piggin * is determined by RI and in_nmi 2862b4f3ac5SNicholas Piggin */ 2872b4f3ac5SNicholas Piggin bool nested = in_nmi(); 2882b4f3ac5SNicholas Piggin if (!nested) 2892b4f3ac5SNicholas Piggin nmi_enter(); 2902b4f3ac5SNicholas Piggin 29114cf11afSPaul Mackerras /* See if any machine dependent calls */ 292c902be71SArnd Bergmann if (ppc_md.system_reset_exception) { 293c902be71SArnd Bergmann if (ppc_md.system_reset_exception(regs)) 294c4f3b52cSNicholas Piggin goto out; 295c902be71SArnd Bergmann } 29614cf11afSPaul Mackerras 2978dad3f92SPaul Mackerras die("System Reset", regs, SIGABRT); 29814cf11afSPaul Mackerras 299c4f3b52cSNicholas Piggin out: 300c4f3b52cSNicholas Piggin #ifdef CONFIG_PPC_BOOK3S_64 301c4f3b52cSNicholas Piggin BUG_ON(get_paca()->in_nmi == 0); 302c4f3b52cSNicholas Piggin if (get_paca()->in_nmi > 1) 303c4f3b52cSNicholas Piggin panic("Unrecoverable nested System Reset"); 304c4f3b52cSNicholas Piggin #endif 30514cf11afSPaul Mackerras /* Must die if the interrupt is not recoverable */ 30614cf11afSPaul Mackerras if (!(regs->msr & MSR_RI)) 30714cf11afSPaul Mackerras panic("Unrecoverable System Reset"); 30814cf11afSPaul Mackerras 3092b4f3ac5SNicholas Piggin if (!nested) 3102b4f3ac5SNicholas Piggin nmi_exit(); 3112b4f3ac5SNicholas Piggin 31214cf11afSPaul Mackerras /* What should we do here? We could issue a shutdown or hard reset. */ 31314cf11afSPaul Mackerras } 3141e9b4507SMahesh Salgaonkar 315f307939fSChristophe Leroy #ifdef CONFIG_PPC64 3161e9b4507SMahesh Salgaonkar /* 3171e9b4507SMahesh Salgaonkar * This function is called in real mode. Strictly no printk's please. 3181e9b4507SMahesh Salgaonkar * 3191e9b4507SMahesh Salgaonkar * regs->nip and regs->msr contains srr0 and ssr1. 3201e9b4507SMahesh Salgaonkar */ 3211e9b4507SMahesh Salgaonkar long machine_check_early(struct pt_regs *regs) 3221e9b4507SMahesh Salgaonkar { 3234c703416SMahesh Salgaonkar long handled = 0; 3244c703416SMahesh Salgaonkar 32569111bacSChristoph Lameter __this_cpu_inc(irq_stat.mce_exceptions); 326e6654d5bSMahesh Salgaonkar 3274c703416SMahesh Salgaonkar if (cur_cpu_spec && cur_cpu_spec->machine_check_early) 3284c703416SMahesh Salgaonkar handled = cur_cpu_spec->machine_check_early(regs); 3294c703416SMahesh Salgaonkar return handled; 3301e9b4507SMahesh Salgaonkar } 3311e9b4507SMahesh Salgaonkar 3320869b6fdSMahesh Salgaonkar long hmi_exception_realmode(struct pt_regs *regs) 3330869b6fdSMahesh Salgaonkar { 33469111bacSChristoph Lameter __this_cpu_inc(irq_stat.hmi_exceptions); 3350869b6fdSMahesh Salgaonkar 336fd7bacbcSMahesh Salgaonkar wait_for_subcore_guest_exit(); 337fd7bacbcSMahesh Salgaonkar 3380869b6fdSMahesh Salgaonkar if (ppc_md.hmi_exception_early) 3390869b6fdSMahesh Salgaonkar ppc_md.hmi_exception_early(regs); 3400869b6fdSMahesh Salgaonkar 341fd7bacbcSMahesh Salgaonkar wait_for_tb_resync(); 342fd7bacbcSMahesh Salgaonkar 3430869b6fdSMahesh Salgaonkar return 0; 3440869b6fdSMahesh Salgaonkar } 3450869b6fdSMahesh Salgaonkar 34614cf11afSPaul Mackerras #endif 34714cf11afSPaul Mackerras 34814cf11afSPaul Mackerras /* 34914cf11afSPaul Mackerras * I/O accesses can cause machine checks on powermacs. 35014cf11afSPaul Mackerras * Check if the NIP corresponds to the address of a sync 35114cf11afSPaul Mackerras * instruction for which there is an entry in the exception 35214cf11afSPaul Mackerras * table. 35314cf11afSPaul Mackerras * Note that the 601 only takes a machine check on TEA 35414cf11afSPaul Mackerras * (transfer error ack) signal assertion, and does not 35514cf11afSPaul Mackerras * set any of the top 16 bits of SRR1. 35614cf11afSPaul Mackerras * -- paulus. 35714cf11afSPaul Mackerras */ 35814cf11afSPaul Mackerras static inline int check_io_access(struct pt_regs *regs) 35914cf11afSPaul Mackerras { 36068a64357SBenjamin Herrenschmidt #ifdef CONFIG_PPC32 36114cf11afSPaul Mackerras unsigned long msr = regs->msr; 36214cf11afSPaul Mackerras const struct exception_table_entry *entry; 36314cf11afSPaul Mackerras unsigned int *nip = (unsigned int *)regs->nip; 36414cf11afSPaul Mackerras 36514cf11afSPaul Mackerras if (((msr & 0xffff0000) == 0 || (msr & (0x80000 | 0x40000))) 36614cf11afSPaul Mackerras && (entry = search_exception_tables(regs->nip)) != NULL) { 36714cf11afSPaul Mackerras /* 36814cf11afSPaul Mackerras * Check that it's a sync instruction, or somewhere 36914cf11afSPaul Mackerras * in the twi; isync; nop sequence that inb/inw/inl uses. 37014cf11afSPaul Mackerras * As the address is in the exception table 37114cf11afSPaul Mackerras * we should be able to read the instr there. 37214cf11afSPaul Mackerras * For the debug message, we look at the preceding 37314cf11afSPaul Mackerras * load or store. 37414cf11afSPaul Mackerras */ 375ddc6cd0dSChristophe Leroy if (*nip == PPC_INST_NOP) 37614cf11afSPaul Mackerras nip -= 2; 377ddc6cd0dSChristophe Leroy else if (*nip == PPC_INST_ISYNC) 37814cf11afSPaul Mackerras --nip; 379ddc6cd0dSChristophe Leroy if (*nip == PPC_INST_SYNC || (*nip >> 26) == OP_TRAP) { 38014cf11afSPaul Mackerras unsigned int rb; 38114cf11afSPaul Mackerras 38214cf11afSPaul Mackerras --nip; 38314cf11afSPaul Mackerras rb = (*nip >> 11) & 0x1f; 38414cf11afSPaul Mackerras printk(KERN_DEBUG "%s bad port %lx at %p\n", 38514cf11afSPaul Mackerras (*nip & 0x100)? "OUT to": "IN from", 38614cf11afSPaul Mackerras regs->gpr[rb] - _IO_BASE, nip); 38714cf11afSPaul Mackerras regs->msr |= MSR_RI; 38861a92f70SNicholas Piggin regs->nip = extable_fixup(entry); 38914cf11afSPaul Mackerras return 1; 39014cf11afSPaul Mackerras } 39114cf11afSPaul Mackerras } 39268a64357SBenjamin Herrenschmidt #endif /* CONFIG_PPC32 */ 39314cf11afSPaul Mackerras return 0; 39414cf11afSPaul Mackerras } 39514cf11afSPaul Mackerras 396172ae2e7SDave Kleikamp #ifdef CONFIG_PPC_ADV_DEBUG_REGS 39714cf11afSPaul Mackerras /* On 4xx, the reason for the machine check or program exception 39814cf11afSPaul Mackerras is in the ESR. */ 39914cf11afSPaul Mackerras #define get_reason(regs) ((regs)->dsisr) 40014cf11afSPaul Mackerras #ifndef CONFIG_FSL_BOOKE 40114cf11afSPaul Mackerras #define get_mc_reason(regs) ((regs)->dsisr) 40214cf11afSPaul Mackerras #else 403fe04b112SScott Wood #define get_mc_reason(regs) (mfspr(SPRN_MCSR)) 40414cf11afSPaul Mackerras #endif 40514cf11afSPaul Mackerras #define REASON_FP ESR_FP 40614cf11afSPaul Mackerras #define REASON_ILLEGAL (ESR_PIL | ESR_PUO) 40714cf11afSPaul Mackerras #define REASON_PRIVILEGED ESR_PPR 40814cf11afSPaul Mackerras #define REASON_TRAP ESR_PTR 40914cf11afSPaul Mackerras 41014cf11afSPaul Mackerras /* single-step stuff */ 41151ae8d4aSBharat Bhushan #define single_stepping(regs) (current->thread.debug.dbcr0 & DBCR0_IC) 41251ae8d4aSBharat Bhushan #define clear_single_step(regs) (current->thread.debug.dbcr0 &= ~DBCR0_IC) 41314cf11afSPaul Mackerras 41414cf11afSPaul Mackerras #else 41514cf11afSPaul Mackerras /* On non-4xx, the reason for the machine check or program 41614cf11afSPaul Mackerras exception is in the MSR. */ 41714cf11afSPaul Mackerras #define get_reason(regs) ((regs)->msr) 41814cf11afSPaul Mackerras #define get_mc_reason(regs) ((regs)->msr) 4198b3c34cfSMichael Neuling #define REASON_TM 0x200000 42014cf11afSPaul Mackerras #define REASON_FP 0x100000 42114cf11afSPaul Mackerras #define REASON_ILLEGAL 0x80000 42214cf11afSPaul Mackerras #define REASON_PRIVILEGED 0x40000 42314cf11afSPaul Mackerras #define REASON_TRAP 0x20000 42414cf11afSPaul Mackerras 42514cf11afSPaul Mackerras #define single_stepping(regs) ((regs)->msr & MSR_SE) 42614cf11afSPaul Mackerras #define clear_single_step(regs) ((regs)->msr &= ~MSR_SE) 42714cf11afSPaul Mackerras #endif 42814cf11afSPaul Mackerras 42947c0bd1aSBenjamin Herrenschmidt #if defined(CONFIG_4xx) 43047c0bd1aSBenjamin Herrenschmidt int machine_check_4xx(struct pt_regs *regs) 43114cf11afSPaul Mackerras { 4321a6a4ffeSKumar Gala unsigned long reason = get_mc_reason(regs); 43314cf11afSPaul Mackerras 43414cf11afSPaul Mackerras if (reason & ESR_IMCP) { 43514cf11afSPaul Mackerras printk("Instruction"); 43614cf11afSPaul Mackerras mtspr(SPRN_ESR, reason & ~ESR_IMCP); 43714cf11afSPaul Mackerras } else 43814cf11afSPaul Mackerras printk("Data"); 43914cf11afSPaul Mackerras printk(" machine check in kernel mode.\n"); 44047c0bd1aSBenjamin Herrenschmidt 44147c0bd1aSBenjamin Herrenschmidt return 0; 44247c0bd1aSBenjamin Herrenschmidt } 44347c0bd1aSBenjamin Herrenschmidt 44447c0bd1aSBenjamin Herrenschmidt int machine_check_440A(struct pt_regs *regs) 44547c0bd1aSBenjamin Herrenschmidt { 44647c0bd1aSBenjamin Herrenschmidt unsigned long reason = get_mc_reason(regs); 44747c0bd1aSBenjamin Herrenschmidt 44814cf11afSPaul Mackerras printk("Machine check in kernel mode.\n"); 44914cf11afSPaul Mackerras if (reason & ESR_IMCP){ 45014cf11afSPaul Mackerras printk("Instruction Synchronous Machine Check exception\n"); 45114cf11afSPaul Mackerras mtspr(SPRN_ESR, reason & ~ESR_IMCP); 45214cf11afSPaul Mackerras } 45314cf11afSPaul Mackerras else { 45414cf11afSPaul Mackerras u32 mcsr = mfspr(SPRN_MCSR); 45514cf11afSPaul Mackerras if (mcsr & MCSR_IB) 45614cf11afSPaul Mackerras printk("Instruction Read PLB Error\n"); 45714cf11afSPaul Mackerras if (mcsr & MCSR_DRB) 45814cf11afSPaul Mackerras printk("Data Read PLB Error\n"); 45914cf11afSPaul Mackerras if (mcsr & MCSR_DWB) 46014cf11afSPaul Mackerras printk("Data Write PLB Error\n"); 46114cf11afSPaul Mackerras if (mcsr & MCSR_TLBP) 46214cf11afSPaul Mackerras printk("TLB Parity Error\n"); 46314cf11afSPaul Mackerras if (mcsr & MCSR_ICP){ 46414cf11afSPaul Mackerras flush_instruction_cache(); 46514cf11afSPaul Mackerras printk("I-Cache Parity Error\n"); 46614cf11afSPaul Mackerras } 46714cf11afSPaul Mackerras if (mcsr & MCSR_DCSP) 46814cf11afSPaul Mackerras printk("D-Cache Search Parity Error\n"); 46914cf11afSPaul Mackerras if (mcsr & MCSR_DCFP) 47014cf11afSPaul Mackerras printk("D-Cache Flush Parity Error\n"); 47114cf11afSPaul Mackerras if (mcsr & MCSR_IMPE) 47214cf11afSPaul Mackerras printk("Machine Check exception is imprecise\n"); 47314cf11afSPaul Mackerras 47414cf11afSPaul Mackerras /* Clear MCSR */ 47514cf11afSPaul Mackerras mtspr(SPRN_MCSR, mcsr); 47614cf11afSPaul Mackerras } 47747c0bd1aSBenjamin Herrenschmidt return 0; 47847c0bd1aSBenjamin Herrenschmidt } 479fc5e7097SDave Kleikamp 480fc5e7097SDave Kleikamp int machine_check_47x(struct pt_regs *regs) 481fc5e7097SDave Kleikamp { 482fc5e7097SDave Kleikamp unsigned long reason = get_mc_reason(regs); 483fc5e7097SDave Kleikamp u32 mcsr; 484fc5e7097SDave Kleikamp 485fc5e7097SDave Kleikamp printk(KERN_ERR "Machine check in kernel mode.\n"); 486fc5e7097SDave Kleikamp if (reason & ESR_IMCP) { 487fc5e7097SDave Kleikamp printk(KERN_ERR 488fc5e7097SDave Kleikamp "Instruction Synchronous Machine Check exception\n"); 489fc5e7097SDave Kleikamp mtspr(SPRN_ESR, reason & ~ESR_IMCP); 490fc5e7097SDave Kleikamp return 0; 491fc5e7097SDave Kleikamp } 492fc5e7097SDave Kleikamp mcsr = mfspr(SPRN_MCSR); 493fc5e7097SDave Kleikamp if (mcsr & MCSR_IB) 494fc5e7097SDave Kleikamp printk(KERN_ERR "Instruction Read PLB Error\n"); 495fc5e7097SDave Kleikamp if (mcsr & MCSR_DRB) 496fc5e7097SDave Kleikamp printk(KERN_ERR "Data Read PLB Error\n"); 497fc5e7097SDave Kleikamp if (mcsr & MCSR_DWB) 498fc5e7097SDave Kleikamp printk(KERN_ERR "Data Write PLB Error\n"); 499fc5e7097SDave Kleikamp if (mcsr & MCSR_TLBP) 500fc5e7097SDave Kleikamp printk(KERN_ERR "TLB Parity Error\n"); 501fc5e7097SDave Kleikamp if (mcsr & MCSR_ICP) { 502fc5e7097SDave Kleikamp flush_instruction_cache(); 503fc5e7097SDave Kleikamp printk(KERN_ERR "I-Cache Parity Error\n"); 504fc5e7097SDave Kleikamp } 505fc5e7097SDave Kleikamp if (mcsr & MCSR_DCSP) 506fc5e7097SDave Kleikamp printk(KERN_ERR "D-Cache Search Parity Error\n"); 507fc5e7097SDave Kleikamp if (mcsr & PPC47x_MCSR_GPR) 508fc5e7097SDave Kleikamp printk(KERN_ERR "GPR Parity Error\n"); 509fc5e7097SDave Kleikamp if (mcsr & PPC47x_MCSR_FPR) 510fc5e7097SDave Kleikamp printk(KERN_ERR "FPR Parity Error\n"); 511fc5e7097SDave Kleikamp if (mcsr & PPC47x_MCSR_IPR) 512fc5e7097SDave Kleikamp printk(KERN_ERR "Machine Check exception is imprecise\n"); 513fc5e7097SDave Kleikamp 514fc5e7097SDave Kleikamp /* Clear MCSR */ 515fc5e7097SDave Kleikamp mtspr(SPRN_MCSR, mcsr); 516fc5e7097SDave Kleikamp 517fc5e7097SDave Kleikamp return 0; 518fc5e7097SDave Kleikamp } 51914cf11afSPaul Mackerras #elif defined(CONFIG_E500) 520fe04b112SScott Wood int machine_check_e500mc(struct pt_regs *regs) 521fe04b112SScott Wood { 522fe04b112SScott Wood unsigned long mcsr = mfspr(SPRN_MCSR); 523fe04b112SScott Wood unsigned long reason = mcsr; 524fe04b112SScott Wood int recoverable = 1; 525fe04b112SScott Wood 52682a9a480SScott Wood if (reason & MCSR_LD) { 527cce1f106SShaohui Xie recoverable = fsl_rio_mcheck_exception(regs); 528cce1f106SShaohui Xie if (recoverable == 1) 529cce1f106SShaohui Xie goto silent_out; 530cce1f106SShaohui Xie } 531cce1f106SShaohui Xie 532fe04b112SScott Wood printk("Machine check in kernel mode.\n"); 533fe04b112SScott Wood printk("Caused by (from MCSR=%lx): ", reason); 534fe04b112SScott Wood 535fe04b112SScott Wood if (reason & MCSR_MCP) 536fe04b112SScott Wood printk("Machine Check Signal\n"); 537fe04b112SScott Wood 538fe04b112SScott Wood if (reason & MCSR_ICPERR) { 539fe04b112SScott Wood printk("Instruction Cache Parity Error\n"); 540fe04b112SScott Wood 541fe04b112SScott Wood /* 542fe04b112SScott Wood * This is recoverable by invalidating the i-cache. 543fe04b112SScott Wood */ 544fe04b112SScott Wood mtspr(SPRN_L1CSR1, mfspr(SPRN_L1CSR1) | L1CSR1_ICFI); 545fe04b112SScott Wood while (mfspr(SPRN_L1CSR1) & L1CSR1_ICFI) 546fe04b112SScott Wood ; 547fe04b112SScott Wood 548fe04b112SScott Wood /* 549fe04b112SScott Wood * This will generally be accompanied by an instruction 550fe04b112SScott Wood * fetch error report -- only treat MCSR_IF as fatal 551fe04b112SScott Wood * if it wasn't due to an L1 parity error. 552fe04b112SScott Wood */ 553fe04b112SScott Wood reason &= ~MCSR_IF; 554fe04b112SScott Wood } 555fe04b112SScott Wood 556fe04b112SScott Wood if (reason & MCSR_DCPERR_MC) { 557fe04b112SScott Wood printk("Data Cache Parity Error\n"); 55837caf9f2SKumar Gala 55937caf9f2SKumar Gala /* 56037caf9f2SKumar Gala * In write shadow mode we auto-recover from the error, but it 56137caf9f2SKumar Gala * may still get logged and cause a machine check. We should 56237caf9f2SKumar Gala * only treat the non-write shadow case as non-recoverable. 56337caf9f2SKumar Gala */ 56437caf9f2SKumar Gala if (!(mfspr(SPRN_L1CSR2) & L1CSR2_DCWS)) 565fe04b112SScott Wood recoverable = 0; 566fe04b112SScott Wood } 567fe04b112SScott Wood 568fe04b112SScott Wood if (reason & MCSR_L2MMU_MHIT) { 569fe04b112SScott Wood printk("Hit on multiple TLB entries\n"); 570fe04b112SScott Wood recoverable = 0; 571fe04b112SScott Wood } 572fe04b112SScott Wood 573fe04b112SScott Wood if (reason & MCSR_NMI) 574fe04b112SScott Wood printk("Non-maskable interrupt\n"); 575fe04b112SScott Wood 576fe04b112SScott Wood if (reason & MCSR_IF) { 577fe04b112SScott Wood printk("Instruction Fetch Error Report\n"); 578fe04b112SScott Wood recoverable = 0; 579fe04b112SScott Wood } 580fe04b112SScott Wood 581fe04b112SScott Wood if (reason & MCSR_LD) { 582fe04b112SScott Wood printk("Load Error Report\n"); 583fe04b112SScott Wood recoverable = 0; 584fe04b112SScott Wood } 585fe04b112SScott Wood 586fe04b112SScott Wood if (reason & MCSR_ST) { 587fe04b112SScott Wood printk("Store Error Report\n"); 588fe04b112SScott Wood recoverable = 0; 589fe04b112SScott Wood } 590fe04b112SScott Wood 591fe04b112SScott Wood if (reason & MCSR_LDG) { 592fe04b112SScott Wood printk("Guarded Load Error Report\n"); 593fe04b112SScott Wood recoverable = 0; 594fe04b112SScott Wood } 595fe04b112SScott Wood 596fe04b112SScott Wood if (reason & MCSR_TLBSYNC) 597fe04b112SScott Wood printk("Simultaneous tlbsync operations\n"); 598fe04b112SScott Wood 599fe04b112SScott Wood if (reason & MCSR_BSL2_ERR) { 600fe04b112SScott Wood printk("Level 2 Cache Error\n"); 601fe04b112SScott Wood recoverable = 0; 602fe04b112SScott Wood } 603fe04b112SScott Wood 604fe04b112SScott Wood if (reason & MCSR_MAV) { 605fe04b112SScott Wood u64 addr; 606fe04b112SScott Wood 607fe04b112SScott Wood addr = mfspr(SPRN_MCAR); 608fe04b112SScott Wood addr |= (u64)mfspr(SPRN_MCARU) << 32; 609fe04b112SScott Wood 610fe04b112SScott Wood printk("Machine Check %s Address: %#llx\n", 611fe04b112SScott Wood reason & MCSR_MEA ? "Effective" : "Physical", addr); 612fe04b112SScott Wood } 613fe04b112SScott Wood 614cce1f106SShaohui Xie silent_out: 615fe04b112SScott Wood mtspr(SPRN_MCSR, mcsr); 616fe04b112SScott Wood return mfspr(SPRN_MCSR) == 0 && recoverable; 617fe04b112SScott Wood } 618fe04b112SScott Wood 61947c0bd1aSBenjamin Herrenschmidt int machine_check_e500(struct pt_regs *regs) 62047c0bd1aSBenjamin Herrenschmidt { 62147c0bd1aSBenjamin Herrenschmidt unsigned long reason = get_mc_reason(regs); 62247c0bd1aSBenjamin Herrenschmidt 623cce1f106SShaohui Xie if (reason & MCSR_BUS_RBERR) { 624cce1f106SShaohui Xie if (fsl_rio_mcheck_exception(regs)) 625cce1f106SShaohui Xie return 1; 6264e0e3435SHongtao Jia if (fsl_pci_mcheck_exception(regs)) 6274e0e3435SHongtao Jia return 1; 628cce1f106SShaohui Xie } 629cce1f106SShaohui Xie 63014cf11afSPaul Mackerras printk("Machine check in kernel mode.\n"); 63114cf11afSPaul Mackerras printk("Caused by (from MCSR=%lx): ", reason); 63214cf11afSPaul Mackerras 63314cf11afSPaul Mackerras if (reason & MCSR_MCP) 63414cf11afSPaul Mackerras printk("Machine Check Signal\n"); 63514cf11afSPaul Mackerras if (reason & MCSR_ICPERR) 63614cf11afSPaul Mackerras printk("Instruction Cache Parity Error\n"); 63714cf11afSPaul Mackerras if (reason & MCSR_DCP_PERR) 63814cf11afSPaul Mackerras printk("Data Cache Push Parity Error\n"); 63914cf11afSPaul Mackerras if (reason & MCSR_DCPERR) 64014cf11afSPaul Mackerras printk("Data Cache Parity Error\n"); 64114cf11afSPaul Mackerras if (reason & MCSR_BUS_IAERR) 64214cf11afSPaul Mackerras printk("Bus - Instruction Address Error\n"); 64314cf11afSPaul Mackerras if (reason & MCSR_BUS_RAERR) 64414cf11afSPaul Mackerras printk("Bus - Read Address Error\n"); 64514cf11afSPaul Mackerras if (reason & MCSR_BUS_WAERR) 64614cf11afSPaul Mackerras printk("Bus - Write Address Error\n"); 64714cf11afSPaul Mackerras if (reason & MCSR_BUS_IBERR) 64814cf11afSPaul Mackerras printk("Bus - Instruction Data Error\n"); 64914cf11afSPaul Mackerras if (reason & MCSR_BUS_RBERR) 65014cf11afSPaul Mackerras printk("Bus - Read Data Bus Error\n"); 65114cf11afSPaul Mackerras if (reason & MCSR_BUS_WBERR) 652c1528339SWladislav Wiebe printk("Bus - Write Data Bus Error\n"); 65314cf11afSPaul Mackerras if (reason & MCSR_BUS_IPERR) 65414cf11afSPaul Mackerras printk("Bus - Instruction Parity Error\n"); 65514cf11afSPaul Mackerras if (reason & MCSR_BUS_RPERR) 65614cf11afSPaul Mackerras printk("Bus - Read Parity Error\n"); 65747c0bd1aSBenjamin Herrenschmidt 65847c0bd1aSBenjamin Herrenschmidt return 0; 65947c0bd1aSBenjamin Herrenschmidt } 6604490c06bSKumar Gala 6614490c06bSKumar Gala int machine_check_generic(struct pt_regs *regs) 6624490c06bSKumar Gala { 6634490c06bSKumar Gala return 0; 6644490c06bSKumar Gala } 66514cf11afSPaul Mackerras #elif defined(CONFIG_E200) 66647c0bd1aSBenjamin Herrenschmidt int machine_check_e200(struct pt_regs *regs) 66747c0bd1aSBenjamin Herrenschmidt { 66847c0bd1aSBenjamin Herrenschmidt unsigned long reason = get_mc_reason(regs); 66947c0bd1aSBenjamin Herrenschmidt 67014cf11afSPaul Mackerras printk("Machine check in kernel mode.\n"); 67114cf11afSPaul Mackerras printk("Caused by (from MCSR=%lx): ", reason); 67214cf11afSPaul Mackerras 67314cf11afSPaul Mackerras if (reason & MCSR_MCP) 67414cf11afSPaul Mackerras printk("Machine Check Signal\n"); 67514cf11afSPaul Mackerras if (reason & MCSR_CP_PERR) 67614cf11afSPaul Mackerras printk("Cache Push Parity Error\n"); 67714cf11afSPaul Mackerras if (reason & MCSR_CPERR) 67814cf11afSPaul Mackerras printk("Cache Parity Error\n"); 67914cf11afSPaul Mackerras if (reason & MCSR_EXCP_ERR) 68014cf11afSPaul Mackerras printk("ISI, ITLB, or Bus Error on first instruction fetch for an exception handler\n"); 68114cf11afSPaul Mackerras if (reason & MCSR_BUS_IRERR) 68214cf11afSPaul Mackerras printk("Bus - Read Bus Error on instruction fetch\n"); 68314cf11afSPaul Mackerras if (reason & MCSR_BUS_DRERR) 68414cf11afSPaul Mackerras printk("Bus - Read Bus Error on data load\n"); 68514cf11afSPaul Mackerras if (reason & MCSR_BUS_WRERR) 68614cf11afSPaul Mackerras printk("Bus - Write Bus Error on buffered store or cache line push\n"); 68747c0bd1aSBenjamin Herrenschmidt 68847c0bd1aSBenjamin Herrenschmidt return 0; 68947c0bd1aSBenjamin Herrenschmidt } 690e627f8dcSChristophe Leroy #elif defined(CONFIG_PPC_8xx) 691e627f8dcSChristophe Leroy int machine_check_8xx(struct pt_regs *regs) 692e627f8dcSChristophe Leroy { 693e627f8dcSChristophe Leroy unsigned long reason = get_mc_reason(regs); 694e627f8dcSChristophe Leroy 695e627f8dcSChristophe Leroy pr_err("Machine check in kernel mode.\n"); 696e627f8dcSChristophe Leroy pr_err("Caused by (from SRR1=%lx): ", reason); 697e627f8dcSChristophe Leroy if (reason & 0x40000000) 698e627f8dcSChristophe Leroy pr_err("Fetch error at address %lx\n", regs->nip); 699e627f8dcSChristophe Leroy else 700e627f8dcSChristophe Leroy pr_err("Data access error at address %lx\n", regs->dar); 701e627f8dcSChristophe Leroy 702e627f8dcSChristophe Leroy #ifdef CONFIG_PCI 703e627f8dcSChristophe Leroy /* the qspan pci read routines can cause machine checks -- Cort 704e627f8dcSChristophe Leroy * 705e627f8dcSChristophe Leroy * yuck !!! that totally needs to go away ! There are better ways 706e627f8dcSChristophe Leroy * to deal with that than having a wart in the mcheck handler. 707e627f8dcSChristophe Leroy * -- BenH 708e627f8dcSChristophe Leroy */ 709e627f8dcSChristophe Leroy bad_page_fault(regs, regs->dar, SIGBUS); 710e627f8dcSChristophe Leroy return 1; 711e627f8dcSChristophe Leroy #else 712e627f8dcSChristophe Leroy return 0; 713e627f8dcSChristophe Leroy #endif 714e627f8dcSChristophe Leroy } 71547c0bd1aSBenjamin Herrenschmidt #else 71647c0bd1aSBenjamin Herrenschmidt int machine_check_generic(struct pt_regs *regs) 71747c0bd1aSBenjamin Herrenschmidt { 71847c0bd1aSBenjamin Herrenschmidt unsigned long reason = get_mc_reason(regs); 71947c0bd1aSBenjamin Herrenschmidt 72014cf11afSPaul Mackerras printk("Machine check in kernel mode.\n"); 72114cf11afSPaul Mackerras printk("Caused by (from SRR1=%lx): ", reason); 72214cf11afSPaul Mackerras switch (reason & 0x601F0000) { 72314cf11afSPaul Mackerras case 0x80000: 72414cf11afSPaul Mackerras printk("Machine check signal\n"); 72514cf11afSPaul Mackerras break; 72614cf11afSPaul Mackerras case 0: /* for 601 */ 72714cf11afSPaul Mackerras case 0x40000: 72814cf11afSPaul Mackerras case 0x140000: /* 7450 MSS error and TEA */ 72914cf11afSPaul Mackerras printk("Transfer error ack signal\n"); 73014cf11afSPaul Mackerras break; 73114cf11afSPaul Mackerras case 0x20000: 73214cf11afSPaul Mackerras printk("Data parity error signal\n"); 73314cf11afSPaul Mackerras break; 73414cf11afSPaul Mackerras case 0x10000: 73514cf11afSPaul Mackerras printk("Address parity error signal\n"); 73614cf11afSPaul Mackerras break; 73714cf11afSPaul Mackerras case 0x20000000: 73814cf11afSPaul Mackerras printk("L1 Data Cache error\n"); 73914cf11afSPaul Mackerras break; 74014cf11afSPaul Mackerras case 0x40000000: 74114cf11afSPaul Mackerras printk("L1 Instruction Cache error\n"); 74214cf11afSPaul Mackerras break; 74314cf11afSPaul Mackerras case 0x00100000: 74414cf11afSPaul Mackerras printk("L2 data cache parity error\n"); 74514cf11afSPaul Mackerras break; 74614cf11afSPaul Mackerras default: 74714cf11afSPaul Mackerras printk("Unknown values in msr\n"); 74814cf11afSPaul Mackerras } 74975918a4bSOlof Johansson return 0; 75075918a4bSOlof Johansson } 75147c0bd1aSBenjamin Herrenschmidt #endif /* everything else */ 75275918a4bSOlof Johansson 75375918a4bSOlof Johansson void machine_check_exception(struct pt_regs *regs) 75475918a4bSOlof Johansson { 755ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 75675918a4bSOlof Johansson int recover = 0; 75775918a4bSOlof Johansson 75869111bacSChristoph Lameter __this_cpu_inc(irq_stat.mce_exceptions); 75989713ed1SAnton Blanchard 760d93b0ac0SMahesh Salgaonkar add_taint(TAINT_MACHINE_CHECK, LOCKDEP_NOW_UNRELIABLE); 761d93b0ac0SMahesh Salgaonkar 76247c0bd1aSBenjamin Herrenschmidt /* See if any machine dependent calls. In theory, we would want 76347c0bd1aSBenjamin Herrenschmidt * to call the CPU first, and call the ppc_md. one if the CPU 76447c0bd1aSBenjamin Herrenschmidt * one returns a positive number. However there is existing code 76547c0bd1aSBenjamin Herrenschmidt * that assumes the board gets a first chance, so let's keep it 76647c0bd1aSBenjamin Herrenschmidt * that way for now and fix things later. --BenH. 76747c0bd1aSBenjamin Herrenschmidt */ 76875918a4bSOlof Johansson if (ppc_md.machine_check_exception) 76975918a4bSOlof Johansson recover = ppc_md.machine_check_exception(regs); 77047c0bd1aSBenjamin Herrenschmidt else if (cur_cpu_spec->machine_check) 77147c0bd1aSBenjamin Herrenschmidt recover = cur_cpu_spec->machine_check(regs); 77275918a4bSOlof Johansson 77347c0bd1aSBenjamin Herrenschmidt if (recover > 0) 774ba12eedeSLi Zhong goto bail; 77575918a4bSOlof Johansson 776a443506bSAnton Blanchard if (debugger_fault_handler(regs)) 777ba12eedeSLi Zhong goto bail; 77875918a4bSOlof Johansson 77975918a4bSOlof Johansson if (check_io_access(regs)) 780ba12eedeSLi Zhong goto bail; 78175918a4bSOlof Johansson 7828dad3f92SPaul Mackerras die("Machine check", regs, SIGBUS); 78314cf11afSPaul Mackerras 78414cf11afSPaul Mackerras /* Must die if the interrupt is not recoverable */ 78514cf11afSPaul Mackerras if (!(regs->msr & MSR_RI)) 78614cf11afSPaul Mackerras panic("Unrecoverable Machine check"); 787ba12eedeSLi Zhong 788ba12eedeSLi Zhong bail: 789ba12eedeSLi Zhong exception_exit(prev_state); 79014cf11afSPaul Mackerras } 79114cf11afSPaul Mackerras 79214cf11afSPaul Mackerras void SMIException(struct pt_regs *regs) 79314cf11afSPaul Mackerras { 79414cf11afSPaul Mackerras die("System Management Interrupt", regs, SIGABRT); 79514cf11afSPaul Mackerras } 79614cf11afSPaul Mackerras 7970869b6fdSMahesh Salgaonkar void handle_hmi_exception(struct pt_regs *regs) 7980869b6fdSMahesh Salgaonkar { 7990869b6fdSMahesh Salgaonkar struct pt_regs *old_regs; 8000869b6fdSMahesh Salgaonkar 8010869b6fdSMahesh Salgaonkar old_regs = set_irq_regs(regs); 8020869b6fdSMahesh Salgaonkar irq_enter(); 8030869b6fdSMahesh Salgaonkar 8040869b6fdSMahesh Salgaonkar if (ppc_md.handle_hmi_exception) 8050869b6fdSMahesh Salgaonkar ppc_md.handle_hmi_exception(regs); 8060869b6fdSMahesh Salgaonkar 8070869b6fdSMahesh Salgaonkar irq_exit(); 8080869b6fdSMahesh Salgaonkar set_irq_regs(old_regs); 8090869b6fdSMahesh Salgaonkar } 8100869b6fdSMahesh Salgaonkar 811dc1c1ca3SStephen Rothwell void unknown_exception(struct pt_regs *regs) 81214cf11afSPaul Mackerras { 813ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 814ba12eedeSLi Zhong 81514cf11afSPaul Mackerras printk("Bad trap at PC: %lx, SR: %lx, vector=%lx\n", 81614cf11afSPaul Mackerras regs->nip, regs->msr, regs->trap); 81714cf11afSPaul Mackerras 81814cf11afSPaul Mackerras _exception(SIGTRAP, regs, 0, 0); 819ba12eedeSLi Zhong 820ba12eedeSLi Zhong exception_exit(prev_state); 82114cf11afSPaul Mackerras } 82214cf11afSPaul Mackerras 823dc1c1ca3SStephen Rothwell void instruction_breakpoint_exception(struct pt_regs *regs) 82414cf11afSPaul Mackerras { 825ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 826ba12eedeSLi Zhong 82714cf11afSPaul Mackerras if (notify_die(DIE_IABR_MATCH, "iabr_match", regs, 5, 82814cf11afSPaul Mackerras 5, SIGTRAP) == NOTIFY_STOP) 829ba12eedeSLi Zhong goto bail; 83014cf11afSPaul Mackerras if (debugger_iabr_match(regs)) 831ba12eedeSLi Zhong goto bail; 83214cf11afSPaul Mackerras _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip); 833ba12eedeSLi Zhong 834ba12eedeSLi Zhong bail: 835ba12eedeSLi Zhong exception_exit(prev_state); 83614cf11afSPaul Mackerras } 83714cf11afSPaul Mackerras 83814cf11afSPaul Mackerras void RunModeException(struct pt_regs *regs) 83914cf11afSPaul Mackerras { 84014cf11afSPaul Mackerras _exception(SIGTRAP, regs, 0, 0); 84114cf11afSPaul Mackerras } 84214cf11afSPaul Mackerras 84303465f89SNicholas Piggin void single_step_exception(struct pt_regs *regs) 84414cf11afSPaul Mackerras { 845ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 846ba12eedeSLi Zhong 8472538c2d0SK.Prasad clear_single_step(regs); 84814cf11afSPaul Mackerras 8496cc89badSNaveen N. Rao if (kprobe_post_handler(regs)) 8506cc89badSNaveen N. Rao return; 8516cc89badSNaveen N. Rao 85214cf11afSPaul Mackerras if (notify_die(DIE_SSTEP, "single_step", regs, 5, 85314cf11afSPaul Mackerras 5, SIGTRAP) == NOTIFY_STOP) 854ba12eedeSLi Zhong goto bail; 85514cf11afSPaul Mackerras if (debugger_sstep(regs)) 856ba12eedeSLi Zhong goto bail; 85714cf11afSPaul Mackerras 85814cf11afSPaul Mackerras _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip); 859ba12eedeSLi Zhong 860ba12eedeSLi Zhong bail: 861ba12eedeSLi Zhong exception_exit(prev_state); 86214cf11afSPaul Mackerras } 86303465f89SNicholas Piggin NOKPROBE_SYMBOL(single_step_exception); 86414cf11afSPaul Mackerras 86514cf11afSPaul Mackerras /* 86614cf11afSPaul Mackerras * After we have successfully emulated an instruction, we have to 86714cf11afSPaul Mackerras * check if the instruction was being single-stepped, and if so, 86814cf11afSPaul Mackerras * pretend we got a single-step exception. This was pointed out 86914cf11afSPaul Mackerras * by Kumar Gala. -- paulus 87014cf11afSPaul Mackerras */ 8718dad3f92SPaul Mackerras static void emulate_single_step(struct pt_regs *regs) 87214cf11afSPaul Mackerras { 8732538c2d0SK.Prasad if (single_stepping(regs)) 8742538c2d0SK.Prasad single_step_exception(regs); 87514cf11afSPaul Mackerras } 87614cf11afSPaul Mackerras 8775fad293bSKumar Gala static inline int __parse_fpscr(unsigned long fpscr) 878dc1c1ca3SStephen Rothwell { 8795fad293bSKumar Gala int ret = 0; 880dc1c1ca3SStephen Rothwell 881dc1c1ca3SStephen Rothwell /* Invalid operation */ 882dc1c1ca3SStephen Rothwell if ((fpscr & FPSCR_VE) && (fpscr & FPSCR_VX)) 8835fad293bSKumar Gala ret = FPE_FLTINV; 884dc1c1ca3SStephen Rothwell 885dc1c1ca3SStephen Rothwell /* Overflow */ 886dc1c1ca3SStephen Rothwell else if ((fpscr & FPSCR_OE) && (fpscr & FPSCR_OX)) 8875fad293bSKumar Gala ret = FPE_FLTOVF; 888dc1c1ca3SStephen Rothwell 889dc1c1ca3SStephen Rothwell /* Underflow */ 890dc1c1ca3SStephen Rothwell else if ((fpscr & FPSCR_UE) && (fpscr & FPSCR_UX)) 8915fad293bSKumar Gala ret = FPE_FLTUND; 892dc1c1ca3SStephen Rothwell 893dc1c1ca3SStephen Rothwell /* Divide by zero */ 894dc1c1ca3SStephen Rothwell else if ((fpscr & FPSCR_ZE) && (fpscr & FPSCR_ZX)) 8955fad293bSKumar Gala ret = FPE_FLTDIV; 896dc1c1ca3SStephen Rothwell 897dc1c1ca3SStephen Rothwell /* Inexact result */ 898dc1c1ca3SStephen Rothwell else if ((fpscr & FPSCR_XE) && (fpscr & FPSCR_XX)) 8995fad293bSKumar Gala ret = FPE_FLTRES; 9005fad293bSKumar Gala 9015fad293bSKumar Gala return ret; 9025fad293bSKumar Gala } 9035fad293bSKumar Gala 9045fad293bSKumar Gala static void parse_fpe(struct pt_regs *regs) 9055fad293bSKumar Gala { 9065fad293bSKumar Gala int code = 0; 9075fad293bSKumar Gala 9085fad293bSKumar Gala flush_fp_to_thread(current); 9095fad293bSKumar Gala 910de79f7b9SPaul Mackerras code = __parse_fpscr(current->thread.fp_state.fpscr); 911dc1c1ca3SStephen Rothwell 912dc1c1ca3SStephen Rothwell _exception(SIGFPE, regs, code, regs->nip); 913dc1c1ca3SStephen Rothwell } 914dc1c1ca3SStephen Rothwell 915dc1c1ca3SStephen Rothwell /* 916dc1c1ca3SStephen Rothwell * Illegal instruction emulation support. Originally written to 91714cf11afSPaul Mackerras * provide the PVR to user applications using the mfspr rd, PVR. 91814cf11afSPaul Mackerras * Return non-zero if we can't emulate, or -EFAULT if the associated 91914cf11afSPaul Mackerras * memory access caused an access fault. Return zero on success. 92014cf11afSPaul Mackerras * 92114cf11afSPaul Mackerras * There are a couple of ways to do this, either "decode" the instruction 92214cf11afSPaul Mackerras * or directly match lots of bits. In this case, matching lots of 92314cf11afSPaul Mackerras * bits is faster and easier. 92486417780SPaul Mackerras * 92514cf11afSPaul Mackerras */ 92614cf11afSPaul Mackerras static int emulate_string_inst(struct pt_regs *regs, u32 instword) 92714cf11afSPaul Mackerras { 92814cf11afSPaul Mackerras u8 rT = (instword >> 21) & 0x1f; 92914cf11afSPaul Mackerras u8 rA = (instword >> 16) & 0x1f; 93014cf11afSPaul Mackerras u8 NB_RB = (instword >> 11) & 0x1f; 93114cf11afSPaul Mackerras u32 num_bytes; 93214cf11afSPaul Mackerras unsigned long EA; 93314cf11afSPaul Mackerras int pos = 0; 93414cf11afSPaul Mackerras 93514cf11afSPaul Mackerras /* Early out if we are an invalid form of lswx */ 93616c57b36SKumar Gala if ((instword & PPC_INST_STRING_MASK) == PPC_INST_LSWX) 93714cf11afSPaul Mackerras if ((rT == rA) || (rT == NB_RB)) 93814cf11afSPaul Mackerras return -EINVAL; 93914cf11afSPaul Mackerras 94014cf11afSPaul Mackerras EA = (rA == 0) ? 0 : regs->gpr[rA]; 94114cf11afSPaul Mackerras 94216c57b36SKumar Gala switch (instword & PPC_INST_STRING_MASK) { 94316c57b36SKumar Gala case PPC_INST_LSWX: 94416c57b36SKumar Gala case PPC_INST_STSWX: 94514cf11afSPaul Mackerras EA += NB_RB; 94614cf11afSPaul Mackerras num_bytes = regs->xer & 0x7f; 94714cf11afSPaul Mackerras break; 94816c57b36SKumar Gala case PPC_INST_LSWI: 94916c57b36SKumar Gala case PPC_INST_STSWI: 95014cf11afSPaul Mackerras num_bytes = (NB_RB == 0) ? 32 : NB_RB; 95114cf11afSPaul Mackerras break; 95214cf11afSPaul Mackerras default: 95314cf11afSPaul Mackerras return -EINVAL; 95414cf11afSPaul Mackerras } 95514cf11afSPaul Mackerras 95614cf11afSPaul Mackerras while (num_bytes != 0) 95714cf11afSPaul Mackerras { 95814cf11afSPaul Mackerras u8 val; 95914cf11afSPaul Mackerras u32 shift = 8 * (3 - (pos & 0x3)); 96014cf11afSPaul Mackerras 96180aa0fb4SJames Yang /* if process is 32-bit, clear upper 32 bits of EA */ 96280aa0fb4SJames Yang if ((regs->msr & MSR_64BIT) == 0) 96380aa0fb4SJames Yang EA &= 0xFFFFFFFF; 96480aa0fb4SJames Yang 96516c57b36SKumar Gala switch ((instword & PPC_INST_STRING_MASK)) { 96616c57b36SKumar Gala case PPC_INST_LSWX: 96716c57b36SKumar Gala case PPC_INST_LSWI: 96814cf11afSPaul Mackerras if (get_user(val, (u8 __user *)EA)) 96914cf11afSPaul Mackerras return -EFAULT; 97014cf11afSPaul Mackerras /* first time updating this reg, 97114cf11afSPaul Mackerras * zero it out */ 97214cf11afSPaul Mackerras if (pos == 0) 97314cf11afSPaul Mackerras regs->gpr[rT] = 0; 97414cf11afSPaul Mackerras regs->gpr[rT] |= val << shift; 97514cf11afSPaul Mackerras break; 97616c57b36SKumar Gala case PPC_INST_STSWI: 97716c57b36SKumar Gala case PPC_INST_STSWX: 97814cf11afSPaul Mackerras val = regs->gpr[rT] >> shift; 97914cf11afSPaul Mackerras if (put_user(val, (u8 __user *)EA)) 98014cf11afSPaul Mackerras return -EFAULT; 98114cf11afSPaul Mackerras break; 98214cf11afSPaul Mackerras } 98314cf11afSPaul Mackerras /* move EA to next address */ 98414cf11afSPaul Mackerras EA += 1; 98514cf11afSPaul Mackerras num_bytes--; 98614cf11afSPaul Mackerras 98714cf11afSPaul Mackerras /* manage our position within the register */ 98814cf11afSPaul Mackerras if (++pos == 4) { 98914cf11afSPaul Mackerras pos = 0; 99014cf11afSPaul Mackerras if (++rT == 32) 99114cf11afSPaul Mackerras rT = 0; 99214cf11afSPaul Mackerras } 99314cf11afSPaul Mackerras } 99414cf11afSPaul Mackerras 99514cf11afSPaul Mackerras return 0; 99614cf11afSPaul Mackerras } 99714cf11afSPaul Mackerras 998c3412dcbSWill Schmidt static int emulate_popcntb_inst(struct pt_regs *regs, u32 instword) 999c3412dcbSWill Schmidt { 1000c3412dcbSWill Schmidt u32 ra,rs; 1001c3412dcbSWill Schmidt unsigned long tmp; 1002c3412dcbSWill Schmidt 1003c3412dcbSWill Schmidt ra = (instword >> 16) & 0x1f; 1004c3412dcbSWill Schmidt rs = (instword >> 21) & 0x1f; 1005c3412dcbSWill Schmidt 1006c3412dcbSWill Schmidt tmp = regs->gpr[rs]; 1007c3412dcbSWill Schmidt tmp = tmp - ((tmp >> 1) & 0x5555555555555555ULL); 1008c3412dcbSWill Schmidt tmp = (tmp & 0x3333333333333333ULL) + ((tmp >> 2) & 0x3333333333333333ULL); 1009c3412dcbSWill Schmidt tmp = (tmp + (tmp >> 4)) & 0x0f0f0f0f0f0f0f0fULL; 1010c3412dcbSWill Schmidt regs->gpr[ra] = tmp; 1011c3412dcbSWill Schmidt 1012c3412dcbSWill Schmidt return 0; 1013c3412dcbSWill Schmidt } 1014c3412dcbSWill Schmidt 1015c1469f13SKumar Gala static int emulate_isel(struct pt_regs *regs, u32 instword) 1016c1469f13SKumar Gala { 1017c1469f13SKumar Gala u8 rT = (instword >> 21) & 0x1f; 1018c1469f13SKumar Gala u8 rA = (instword >> 16) & 0x1f; 1019c1469f13SKumar Gala u8 rB = (instword >> 11) & 0x1f; 1020c1469f13SKumar Gala u8 BC = (instword >> 6) & 0x1f; 1021c1469f13SKumar Gala u8 bit; 1022c1469f13SKumar Gala unsigned long tmp; 1023c1469f13SKumar Gala 1024c1469f13SKumar Gala tmp = (rA == 0) ? 0 : regs->gpr[rA]; 1025c1469f13SKumar Gala bit = (regs->ccr >> (31 - BC)) & 0x1; 1026c1469f13SKumar Gala 1027c1469f13SKumar Gala regs->gpr[rT] = bit ? tmp : regs->gpr[rB]; 1028c1469f13SKumar Gala 1029c1469f13SKumar Gala return 0; 1030c1469f13SKumar Gala } 1031c1469f13SKumar Gala 10326ce6c629SMichael Neuling #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 10336ce6c629SMichael Neuling static inline bool tm_abort_check(struct pt_regs *regs, int cause) 10346ce6c629SMichael Neuling { 10356ce6c629SMichael Neuling /* If we're emulating a load/store in an active transaction, we cannot 10366ce6c629SMichael Neuling * emulate it as the kernel operates in transaction suspended context. 10376ce6c629SMichael Neuling * We need to abort the transaction. This creates a persistent TM 10386ce6c629SMichael Neuling * abort so tell the user what caused it with a new code. 10396ce6c629SMichael Neuling */ 10406ce6c629SMichael Neuling if (MSR_TM_TRANSACTIONAL(regs->msr)) { 10416ce6c629SMichael Neuling tm_enable(); 10426ce6c629SMichael Neuling tm_abort(cause); 10436ce6c629SMichael Neuling return true; 10446ce6c629SMichael Neuling } 10456ce6c629SMichael Neuling return false; 10466ce6c629SMichael Neuling } 10476ce6c629SMichael Neuling #else 10486ce6c629SMichael Neuling static inline bool tm_abort_check(struct pt_regs *regs, int reason) 10496ce6c629SMichael Neuling { 10506ce6c629SMichael Neuling return false; 10516ce6c629SMichael Neuling } 10526ce6c629SMichael Neuling #endif 10536ce6c629SMichael Neuling 105414cf11afSPaul Mackerras static int emulate_instruction(struct pt_regs *regs) 105514cf11afSPaul Mackerras { 105614cf11afSPaul Mackerras u32 instword; 105714cf11afSPaul Mackerras u32 rd; 105814cf11afSPaul Mackerras 10594288e343SAnton Blanchard if (!user_mode(regs)) 106014cf11afSPaul Mackerras return -EINVAL; 106114cf11afSPaul Mackerras CHECK_FULL_REGS(regs); 106214cf11afSPaul Mackerras 106314cf11afSPaul Mackerras if (get_user(instword, (u32 __user *)(regs->nip))) 106414cf11afSPaul Mackerras return -EFAULT; 106514cf11afSPaul Mackerras 106614cf11afSPaul Mackerras /* Emulate the mfspr rD, PVR. */ 106716c57b36SKumar Gala if ((instword & PPC_INST_MFSPR_PVR_MASK) == PPC_INST_MFSPR_PVR) { 1068eecff81dSAnton Blanchard PPC_WARN_EMULATED(mfpvr, regs); 106914cf11afSPaul Mackerras rd = (instword >> 21) & 0x1f; 107014cf11afSPaul Mackerras regs->gpr[rd] = mfspr(SPRN_PVR); 107114cf11afSPaul Mackerras return 0; 107214cf11afSPaul Mackerras } 107314cf11afSPaul Mackerras 107414cf11afSPaul Mackerras /* Emulating the dcba insn is just a no-op. */ 107580947e7cSGeert Uytterhoeven if ((instword & PPC_INST_DCBA_MASK) == PPC_INST_DCBA) { 1076eecff81dSAnton Blanchard PPC_WARN_EMULATED(dcba, regs); 107714cf11afSPaul Mackerras return 0; 107880947e7cSGeert Uytterhoeven } 107914cf11afSPaul Mackerras 108014cf11afSPaul Mackerras /* Emulate the mcrxr insn. */ 108116c57b36SKumar Gala if ((instword & PPC_INST_MCRXR_MASK) == PPC_INST_MCRXR) { 108286417780SPaul Mackerras int shift = (instword >> 21) & 0x1c; 108314cf11afSPaul Mackerras unsigned long msk = 0xf0000000UL >> shift; 108414cf11afSPaul Mackerras 1085eecff81dSAnton Blanchard PPC_WARN_EMULATED(mcrxr, regs); 108614cf11afSPaul Mackerras regs->ccr = (regs->ccr & ~msk) | ((regs->xer >> shift) & msk); 108714cf11afSPaul Mackerras regs->xer &= ~0xf0000000UL; 108814cf11afSPaul Mackerras return 0; 108914cf11afSPaul Mackerras } 109014cf11afSPaul Mackerras 109114cf11afSPaul Mackerras /* Emulate load/store string insn. */ 109280947e7cSGeert Uytterhoeven if ((instword & PPC_INST_STRING_GEN_MASK) == PPC_INST_STRING) { 10936ce6c629SMichael Neuling if (tm_abort_check(regs, 10946ce6c629SMichael Neuling TM_CAUSE_EMULATE | TM_CAUSE_PERSISTENT)) 10956ce6c629SMichael Neuling return -EINVAL; 1096eecff81dSAnton Blanchard PPC_WARN_EMULATED(string, regs); 109714cf11afSPaul Mackerras return emulate_string_inst(regs, instword); 109880947e7cSGeert Uytterhoeven } 109914cf11afSPaul Mackerras 1100c3412dcbSWill Schmidt /* Emulate the popcntb (Population Count Bytes) instruction. */ 110116c57b36SKumar Gala if ((instword & PPC_INST_POPCNTB_MASK) == PPC_INST_POPCNTB) { 1102eecff81dSAnton Blanchard PPC_WARN_EMULATED(popcntb, regs); 1103c3412dcbSWill Schmidt return emulate_popcntb_inst(regs, instword); 1104c3412dcbSWill Schmidt } 1105c3412dcbSWill Schmidt 1106c1469f13SKumar Gala /* Emulate isel (Integer Select) instruction */ 110716c57b36SKumar Gala if ((instword & PPC_INST_ISEL_MASK) == PPC_INST_ISEL) { 1108eecff81dSAnton Blanchard PPC_WARN_EMULATED(isel, regs); 1109c1469f13SKumar Gala return emulate_isel(regs, instword); 1110c1469f13SKumar Gala } 1111c1469f13SKumar Gala 11129863c28aSJames Yang /* Emulate sync instruction variants */ 11139863c28aSJames Yang if ((instword & PPC_INST_SYNC_MASK) == PPC_INST_SYNC) { 11149863c28aSJames Yang PPC_WARN_EMULATED(sync, regs); 11159863c28aSJames Yang asm volatile("sync"); 11169863c28aSJames Yang return 0; 11179863c28aSJames Yang } 11189863c28aSJames Yang 1119efcac658SAlexey Kardashevskiy #ifdef CONFIG_PPC64 1120efcac658SAlexey Kardashevskiy /* Emulate the mfspr rD, DSCR. */ 112173d2fb75SAnton Blanchard if ((((instword & PPC_INST_MFSPR_DSCR_USER_MASK) == 112273d2fb75SAnton Blanchard PPC_INST_MFSPR_DSCR_USER) || 112373d2fb75SAnton Blanchard ((instword & PPC_INST_MFSPR_DSCR_MASK) == 112473d2fb75SAnton Blanchard PPC_INST_MFSPR_DSCR)) && 1125efcac658SAlexey Kardashevskiy cpu_has_feature(CPU_FTR_DSCR)) { 1126efcac658SAlexey Kardashevskiy PPC_WARN_EMULATED(mfdscr, regs); 1127efcac658SAlexey Kardashevskiy rd = (instword >> 21) & 0x1f; 1128efcac658SAlexey Kardashevskiy regs->gpr[rd] = mfspr(SPRN_DSCR); 1129efcac658SAlexey Kardashevskiy return 0; 1130efcac658SAlexey Kardashevskiy } 1131efcac658SAlexey Kardashevskiy /* Emulate the mtspr DSCR, rD. */ 113273d2fb75SAnton Blanchard if ((((instword & PPC_INST_MTSPR_DSCR_USER_MASK) == 113373d2fb75SAnton Blanchard PPC_INST_MTSPR_DSCR_USER) || 113473d2fb75SAnton Blanchard ((instword & PPC_INST_MTSPR_DSCR_MASK) == 113573d2fb75SAnton Blanchard PPC_INST_MTSPR_DSCR)) && 1136efcac658SAlexey Kardashevskiy cpu_has_feature(CPU_FTR_DSCR)) { 1137efcac658SAlexey Kardashevskiy PPC_WARN_EMULATED(mtdscr, regs); 1138efcac658SAlexey Kardashevskiy rd = (instword >> 21) & 0x1f; 113900ca0de0SAnton Blanchard current->thread.dscr = regs->gpr[rd]; 1140efcac658SAlexey Kardashevskiy current->thread.dscr_inherit = 1; 114100ca0de0SAnton Blanchard mtspr(SPRN_DSCR, current->thread.dscr); 1142efcac658SAlexey Kardashevskiy return 0; 1143efcac658SAlexey Kardashevskiy } 1144efcac658SAlexey Kardashevskiy #endif 1145efcac658SAlexey Kardashevskiy 114614cf11afSPaul Mackerras return -EINVAL; 114714cf11afSPaul Mackerras } 114814cf11afSPaul Mackerras 114973c9ceabSJeremy Fitzhardinge int is_valid_bugaddr(unsigned long addr) 115014cf11afSPaul Mackerras { 115173c9ceabSJeremy Fitzhardinge return is_kernel_addr(addr); 115214cf11afSPaul Mackerras } 115314cf11afSPaul Mackerras 11543a3b5aa6SKevin Hao #ifdef CONFIG_MATH_EMULATION 11553a3b5aa6SKevin Hao static int emulate_math(struct pt_regs *regs) 11563a3b5aa6SKevin Hao { 11573a3b5aa6SKevin Hao int ret; 11583a3b5aa6SKevin Hao extern int do_mathemu(struct pt_regs *regs); 11593a3b5aa6SKevin Hao 11603a3b5aa6SKevin Hao ret = do_mathemu(regs); 11613a3b5aa6SKevin Hao if (ret >= 0) 11623a3b5aa6SKevin Hao PPC_WARN_EMULATED(math, regs); 11633a3b5aa6SKevin Hao 11643a3b5aa6SKevin Hao switch (ret) { 11653a3b5aa6SKevin Hao case 0: 11663a3b5aa6SKevin Hao emulate_single_step(regs); 11673a3b5aa6SKevin Hao return 0; 11683a3b5aa6SKevin Hao case 1: { 11693a3b5aa6SKevin Hao int code = 0; 1170de79f7b9SPaul Mackerras code = __parse_fpscr(current->thread.fp_state.fpscr); 11713a3b5aa6SKevin Hao _exception(SIGFPE, regs, code, regs->nip); 11723a3b5aa6SKevin Hao return 0; 11733a3b5aa6SKevin Hao } 11743a3b5aa6SKevin Hao case -EFAULT: 11753a3b5aa6SKevin Hao _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip); 11763a3b5aa6SKevin Hao return 0; 11773a3b5aa6SKevin Hao } 11783a3b5aa6SKevin Hao 11793a3b5aa6SKevin Hao return -1; 11803a3b5aa6SKevin Hao } 11813a3b5aa6SKevin Hao #else 11823a3b5aa6SKevin Hao static inline int emulate_math(struct pt_regs *regs) { return -1; } 11833a3b5aa6SKevin Hao #endif 11843a3b5aa6SKevin Hao 118503465f89SNicholas Piggin void program_check_exception(struct pt_regs *regs) 118614cf11afSPaul Mackerras { 1187ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 118814cf11afSPaul Mackerras unsigned int reason = get_reason(regs); 118914cf11afSPaul Mackerras 1190aa42c69cSKim Phillips /* We can now get here via a FP Unavailable exception if the core 119104903a30SKumar Gala * has no FPU, in that case the reason flags will be 0 */ 119214cf11afSPaul Mackerras 119314cf11afSPaul Mackerras if (reason & REASON_FP) { 119414cf11afSPaul Mackerras /* IEEE FP exception */ 1195dc1c1ca3SStephen Rothwell parse_fpe(regs); 1196ba12eedeSLi Zhong goto bail; 11978dad3f92SPaul Mackerras } 11988dad3f92SPaul Mackerras if (reason & REASON_TRAP) { 1199a4c3f909SBalbir Singh unsigned long bugaddr; 1200ba797b28SJason Wessel /* Debugger is first in line to stop recursive faults in 1201ba797b28SJason Wessel * rcu_lock, notify_die, or atomic_notifier_call_chain */ 1202ba797b28SJason Wessel if (debugger_bpt(regs)) 1203ba12eedeSLi Zhong goto bail; 1204ba797b28SJason Wessel 12056cc89badSNaveen N. Rao if (kprobe_handler(regs)) 12066cc89badSNaveen N. Rao goto bail; 12076cc89badSNaveen N. Rao 120814cf11afSPaul Mackerras /* trap exception */ 1209dc1c1ca3SStephen Rothwell if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP) 1210dc1c1ca3SStephen Rothwell == NOTIFY_STOP) 1211ba12eedeSLi Zhong goto bail; 121273c9ceabSJeremy Fitzhardinge 1213a4c3f909SBalbir Singh bugaddr = regs->nip; 1214a4c3f909SBalbir Singh /* 1215a4c3f909SBalbir Singh * Fixup bugaddr for BUG_ON() in real mode 1216a4c3f909SBalbir Singh */ 1217a4c3f909SBalbir Singh if (!is_kernel_addr(bugaddr) && !(regs->msr & MSR_IR)) 1218a4c3f909SBalbir Singh bugaddr += PAGE_OFFSET; 1219a4c3f909SBalbir Singh 122073c9ceabSJeremy Fitzhardinge if (!(regs->msr & MSR_PR) && /* not user-mode */ 1221a4c3f909SBalbir Singh report_bug(bugaddr, regs) == BUG_TRAP_TYPE_WARN) { 122214cf11afSPaul Mackerras regs->nip += 4; 1223ba12eedeSLi Zhong goto bail; 122414cf11afSPaul Mackerras } 12258dad3f92SPaul Mackerras _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip); 1226ba12eedeSLi Zhong goto bail; 12278dad3f92SPaul Mackerras } 1228bc2a9408SMichael Neuling #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 1229bc2a9408SMichael Neuling if (reason & REASON_TM) { 1230bc2a9408SMichael Neuling /* This is a TM "Bad Thing Exception" program check. 1231bc2a9408SMichael Neuling * This occurs when: 1232bc2a9408SMichael Neuling * - An rfid/hrfid/mtmsrd attempts to cause an illegal 1233bc2a9408SMichael Neuling * transition in TM states. 1234bc2a9408SMichael Neuling * - A trechkpt is attempted when transactional. 1235bc2a9408SMichael Neuling * - A treclaim is attempted when non transactional. 1236bc2a9408SMichael Neuling * - A tend is illegally attempted. 1237bc2a9408SMichael Neuling * - writing a TM SPR when transactional. 1238bc2a9408SMichael Neuling */ 1239bc2a9408SMichael Neuling if (!user_mode(regs) && 1240bc2a9408SMichael Neuling report_bug(regs->nip, regs) == BUG_TRAP_TYPE_WARN) { 1241bc2a9408SMichael Neuling regs->nip += 4; 1242ba12eedeSLi Zhong goto bail; 1243bc2a9408SMichael Neuling } 1244bc2a9408SMichael Neuling /* If usermode caused this, it's done something illegal and 1245bc2a9408SMichael Neuling * gets a SIGILL slap on the wrist. We call it an illegal 1246bc2a9408SMichael Neuling * operand to distinguish from the instruction just being bad 1247bc2a9408SMichael Neuling * (e.g. executing a 'tend' on a CPU without TM!); it's an 1248bc2a9408SMichael Neuling * illegal /placement/ of a valid instruction. 1249bc2a9408SMichael Neuling */ 1250bc2a9408SMichael Neuling if (user_mode(regs)) { 1251bc2a9408SMichael Neuling _exception(SIGILL, regs, ILL_ILLOPN, regs->nip); 1252ba12eedeSLi Zhong goto bail; 1253bc2a9408SMichael Neuling } else { 1254bc2a9408SMichael Neuling printk(KERN_EMERG "Unexpected TM Bad Thing exception " 1255bc2a9408SMichael Neuling "at %lx (msr 0x%x)\n", regs->nip, reason); 1256bc2a9408SMichael Neuling die("Unrecoverable exception", regs, SIGABRT); 1257bc2a9408SMichael Neuling } 1258bc2a9408SMichael Neuling } 1259bc2a9408SMichael Neuling #endif 12608dad3f92SPaul Mackerras 1261b3f6a459SMichael Ellerman /* 1262b3f6a459SMichael Ellerman * If we took the program check in the kernel skip down to sending a 1263b3f6a459SMichael Ellerman * SIGILL. The subsequent cases all relate to emulating instructions 1264b3f6a459SMichael Ellerman * which we should only do for userspace. We also do not want to enable 1265b3f6a459SMichael Ellerman * interrupts for kernel faults because that might lead to further 1266b3f6a459SMichael Ellerman * faults, and loose the context of the original exception. 1267b3f6a459SMichael Ellerman */ 1268b3f6a459SMichael Ellerman if (!user_mode(regs)) 1269b3f6a459SMichael Ellerman goto sigill; 1270b3f6a459SMichael Ellerman 1271a3512b2dSBenjamin Herrenschmidt /* We restore the interrupt state now */ 1272a3512b2dSBenjamin Herrenschmidt if (!arch_irq_disabled_regs(regs)) 1273cd8a5673SPaul Mackerras local_irq_enable(); 1274cd8a5673SPaul Mackerras 127504903a30SKumar Gala /* (reason & REASON_ILLEGAL) would be the obvious thing here, 127604903a30SKumar Gala * but there seems to be a hardware bug on the 405GP (RevD) 127704903a30SKumar Gala * that means ESR is sometimes set incorrectly - either to 127804903a30SKumar Gala * ESR_DST (!?) or 0. In the process of chasing this with the 127904903a30SKumar Gala * hardware people - not sure if it can happen on any illegal 128004903a30SKumar Gala * instruction or only on FP instructions, whether there is a 12814e63f8edSBenjamin Herrenschmidt * pattern to occurrences etc. -dgibson 31/Mar/2003 12824e63f8edSBenjamin Herrenschmidt */ 12833a3b5aa6SKevin Hao if (!emulate_math(regs)) 1284ba12eedeSLi Zhong goto bail; 128504903a30SKumar Gala 12868dad3f92SPaul Mackerras /* Try to emulate it if we should. */ 12878dad3f92SPaul Mackerras if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED)) { 128814cf11afSPaul Mackerras switch (emulate_instruction(regs)) { 128914cf11afSPaul Mackerras case 0: 129014cf11afSPaul Mackerras regs->nip += 4; 129114cf11afSPaul Mackerras emulate_single_step(regs); 1292ba12eedeSLi Zhong goto bail; 129314cf11afSPaul Mackerras case -EFAULT: 129414cf11afSPaul Mackerras _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip); 1295ba12eedeSLi Zhong goto bail; 12968dad3f92SPaul Mackerras } 12978dad3f92SPaul Mackerras } 12988dad3f92SPaul Mackerras 1299b3f6a459SMichael Ellerman sigill: 130014cf11afSPaul Mackerras if (reason & REASON_PRIVILEGED) 130114cf11afSPaul Mackerras _exception(SIGILL, regs, ILL_PRVOPC, regs->nip); 130214cf11afSPaul Mackerras else 130314cf11afSPaul Mackerras _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 1304ba12eedeSLi Zhong 1305ba12eedeSLi Zhong bail: 1306ba12eedeSLi Zhong exception_exit(prev_state); 130714cf11afSPaul Mackerras } 130803465f89SNicholas Piggin NOKPROBE_SYMBOL(program_check_exception); 130914cf11afSPaul Mackerras 1310bf593907SPaul Mackerras /* 1311bf593907SPaul Mackerras * This occurs when running in hypervisor mode on POWER6 or later 1312bf593907SPaul Mackerras * and an illegal instruction is encountered. 1313bf593907SPaul Mackerras */ 131403465f89SNicholas Piggin void emulation_assist_interrupt(struct pt_regs *regs) 1315bf593907SPaul Mackerras { 1316bf593907SPaul Mackerras regs->msr |= REASON_ILLEGAL; 1317bf593907SPaul Mackerras program_check_exception(regs); 1318bf593907SPaul Mackerras } 131903465f89SNicholas Piggin NOKPROBE_SYMBOL(emulation_assist_interrupt); 1320bf593907SPaul Mackerras 1321dc1c1ca3SStephen Rothwell void alignment_exception(struct pt_regs *regs) 132214cf11afSPaul Mackerras { 1323ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 13244393c4f6SBenjamin Herrenschmidt int sig, code, fixed = 0; 132514cf11afSPaul Mackerras 1326a3512b2dSBenjamin Herrenschmidt /* We restore the interrupt state now */ 1327a3512b2dSBenjamin Herrenschmidt if (!arch_irq_disabled_regs(regs)) 1328a3512b2dSBenjamin Herrenschmidt local_irq_enable(); 1329a3512b2dSBenjamin Herrenschmidt 13306ce6c629SMichael Neuling if (tm_abort_check(regs, TM_CAUSE_ALIGNMENT | TM_CAUSE_PERSISTENT)) 13316ce6c629SMichael Neuling goto bail; 13326ce6c629SMichael Neuling 1333e9370ae1SPaul Mackerras /* we don't implement logging of alignment exceptions */ 1334e9370ae1SPaul Mackerras if (!(current->thread.align_ctl & PR_UNALIGN_SIGBUS)) 133514cf11afSPaul Mackerras fixed = fix_alignment(regs); 133614cf11afSPaul Mackerras 133714cf11afSPaul Mackerras if (fixed == 1) { 133814cf11afSPaul Mackerras regs->nip += 4; /* skip over emulated instruction */ 133914cf11afSPaul Mackerras emulate_single_step(regs); 1340ba12eedeSLi Zhong goto bail; 134114cf11afSPaul Mackerras } 134214cf11afSPaul Mackerras 134314cf11afSPaul Mackerras /* Operand address was bad */ 134414cf11afSPaul Mackerras if (fixed == -EFAULT) { 13454393c4f6SBenjamin Herrenschmidt sig = SIGSEGV; 13464393c4f6SBenjamin Herrenschmidt code = SEGV_ACCERR; 13474393c4f6SBenjamin Herrenschmidt } else { 13484393c4f6SBenjamin Herrenschmidt sig = SIGBUS; 13494393c4f6SBenjamin Herrenschmidt code = BUS_ADRALN; 135014cf11afSPaul Mackerras } 13514393c4f6SBenjamin Herrenschmidt if (user_mode(regs)) 13524393c4f6SBenjamin Herrenschmidt _exception(sig, regs, code, regs->dar); 13534393c4f6SBenjamin Herrenschmidt else 13544393c4f6SBenjamin Herrenschmidt bad_page_fault(regs, regs->dar, sig); 1355ba12eedeSLi Zhong 1356ba12eedeSLi Zhong bail: 1357ba12eedeSLi Zhong exception_exit(prev_state); 135814cf11afSPaul Mackerras } 135914cf11afSPaul Mackerras 1360f0f558b1SPaul Mackerras void slb_miss_bad_addr(struct pt_regs *regs) 1361f0f558b1SPaul Mackerras { 1362f0f558b1SPaul Mackerras enum ctx_state prev_state = exception_enter(); 1363f0f558b1SPaul Mackerras 1364f0f558b1SPaul Mackerras if (user_mode(regs)) 1365f0f558b1SPaul Mackerras _exception(SIGSEGV, regs, SEGV_BNDERR, regs->dar); 1366f0f558b1SPaul Mackerras else 1367f0f558b1SPaul Mackerras bad_page_fault(regs, regs->dar, SIGSEGV); 1368f0f558b1SPaul Mackerras 1369f0f558b1SPaul Mackerras exception_exit(prev_state); 1370f0f558b1SPaul Mackerras } 1371f0f558b1SPaul Mackerras 137214cf11afSPaul Mackerras void StackOverflow(struct pt_regs *regs) 137314cf11afSPaul Mackerras { 137414cf11afSPaul Mackerras printk(KERN_CRIT "Kernel stack overflow in process %p, r1=%lx\n", 137514cf11afSPaul Mackerras current, regs->gpr[1]); 137614cf11afSPaul Mackerras debugger(regs); 137714cf11afSPaul Mackerras show_regs(regs); 137814cf11afSPaul Mackerras panic("kernel stack overflow"); 137914cf11afSPaul Mackerras } 138014cf11afSPaul Mackerras 138114cf11afSPaul Mackerras void nonrecoverable_exception(struct pt_regs *regs) 138214cf11afSPaul Mackerras { 138314cf11afSPaul Mackerras printk(KERN_ERR "Non-recoverable exception at PC=%lx MSR=%lx\n", 138414cf11afSPaul Mackerras regs->nip, regs->msr); 138514cf11afSPaul Mackerras debugger(regs); 138614cf11afSPaul Mackerras die("nonrecoverable exception", regs, SIGKILL); 138714cf11afSPaul Mackerras } 138814cf11afSPaul Mackerras 1389dc1c1ca3SStephen Rothwell void kernel_fp_unavailable_exception(struct pt_regs *regs) 1390dc1c1ca3SStephen Rothwell { 1391ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 1392ba12eedeSLi Zhong 1393dc1c1ca3SStephen Rothwell printk(KERN_EMERG "Unrecoverable FP Unavailable Exception " 1394dc1c1ca3SStephen Rothwell "%lx at %lx\n", regs->trap, regs->nip); 1395dc1c1ca3SStephen Rothwell die("Unrecoverable FP Unavailable Exception", regs, SIGABRT); 1396ba12eedeSLi Zhong 1397ba12eedeSLi Zhong exception_exit(prev_state); 1398dc1c1ca3SStephen Rothwell } 1399dc1c1ca3SStephen Rothwell 1400dc1c1ca3SStephen Rothwell void altivec_unavailable_exception(struct pt_regs *regs) 1401dc1c1ca3SStephen Rothwell { 1402ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 1403ba12eedeSLi Zhong 1404dc1c1ca3SStephen Rothwell if (user_mode(regs)) { 1405dc1c1ca3SStephen Rothwell /* A user program has executed an altivec instruction, 1406dc1c1ca3SStephen Rothwell but this kernel doesn't support altivec. */ 1407dc1c1ca3SStephen Rothwell _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 1408ba12eedeSLi Zhong goto bail; 1409dc1c1ca3SStephen Rothwell } 14106c4841c2SAnton Blanchard 1411dc1c1ca3SStephen Rothwell printk(KERN_EMERG "Unrecoverable VMX/Altivec Unavailable Exception " 1412dc1c1ca3SStephen Rothwell "%lx at %lx\n", regs->trap, regs->nip); 1413dc1c1ca3SStephen Rothwell die("Unrecoverable VMX/Altivec Unavailable Exception", regs, SIGABRT); 1414ba12eedeSLi Zhong 1415ba12eedeSLi Zhong bail: 1416ba12eedeSLi Zhong exception_exit(prev_state); 1417dc1c1ca3SStephen Rothwell } 1418dc1c1ca3SStephen Rothwell 1419ce48b210SMichael Neuling void vsx_unavailable_exception(struct pt_regs *regs) 1420ce48b210SMichael Neuling { 1421ce48b210SMichael Neuling if (user_mode(regs)) { 1422ce48b210SMichael Neuling /* A user program has executed an vsx instruction, 1423ce48b210SMichael Neuling but this kernel doesn't support vsx. */ 1424ce48b210SMichael Neuling _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 1425ce48b210SMichael Neuling return; 1426ce48b210SMichael Neuling } 1427ce48b210SMichael Neuling 1428ce48b210SMichael Neuling printk(KERN_EMERG "Unrecoverable VSX Unavailable Exception " 1429ce48b210SMichael Neuling "%lx at %lx\n", regs->trap, regs->nip); 1430ce48b210SMichael Neuling die("Unrecoverable VSX Unavailable Exception", regs, SIGABRT); 1431ce48b210SMichael Neuling } 1432ce48b210SMichael Neuling 14332517617eSMichael Neuling #ifdef CONFIG_PPC64 1434172f7aaaSCyril Bur static void tm_unavailable(struct pt_regs *regs) 1435172f7aaaSCyril Bur { 14365d176f75SCyril Bur #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 14375d176f75SCyril Bur if (user_mode(regs)) { 14385d176f75SCyril Bur current->thread.load_tm++; 14395d176f75SCyril Bur regs->msr |= MSR_TM; 14405d176f75SCyril Bur tm_enable(); 14415d176f75SCyril Bur tm_restore_sprs(¤t->thread); 14425d176f75SCyril Bur return; 14435d176f75SCyril Bur } 14445d176f75SCyril Bur #endif 1445172f7aaaSCyril Bur pr_emerg("Unrecoverable TM Unavailable Exception " 1446172f7aaaSCyril Bur "%lx at %lx\n", regs->trap, regs->nip); 1447172f7aaaSCyril Bur die("Unrecoverable TM Unavailable Exception", regs, SIGABRT); 1448172f7aaaSCyril Bur } 1449172f7aaaSCyril Bur 1450021424a1SMichael Ellerman void facility_unavailable_exception(struct pt_regs *regs) 1451d0c0c9a1SMichael Neuling { 1452021424a1SMichael Ellerman static char *facility_strings[] = { 14532517617eSMichael Neuling [FSCR_FP_LG] = "FPU", 14542517617eSMichael Neuling [FSCR_VECVSX_LG] = "VMX/VSX", 14552517617eSMichael Neuling [FSCR_DSCR_LG] = "DSCR", 14562517617eSMichael Neuling [FSCR_PM_LG] = "PMU SPRs", 14572517617eSMichael Neuling [FSCR_BHRB_LG] = "BHRB", 14582517617eSMichael Neuling [FSCR_TM_LG] = "TM", 14592517617eSMichael Neuling [FSCR_EBB_LG] = "EBB", 14602517617eSMichael Neuling [FSCR_TAR_LG] = "TAR", 1461794464f4SNicholas Piggin [FSCR_MSGP_LG] = "MSGP", 14629b7ff0c6SNicholas Piggin [FSCR_SCV_LG] = "SCV", 1463021424a1SMichael Ellerman }; 14642517617eSMichael Neuling char *facility = "unknown"; 1465021424a1SMichael Ellerman u64 value; 1466c952c1c4SAnshuman Khandual u32 instword, rd; 14672517617eSMichael Neuling u8 status; 14682517617eSMichael Neuling bool hv; 1469021424a1SMichael Ellerman 14702517617eSMichael Neuling hv = (regs->trap == 0xf80); 14712517617eSMichael Neuling if (hv) 1472b14b6260SMichael Ellerman value = mfspr(SPRN_HFSCR); 14732517617eSMichael Neuling else 14742517617eSMichael Neuling value = mfspr(SPRN_FSCR); 14752517617eSMichael Neuling 14762517617eSMichael Neuling status = value >> 56; 14772517617eSMichael Neuling if (status == FSCR_DSCR_LG) { 1478c952c1c4SAnshuman Khandual /* 1479c952c1c4SAnshuman Khandual * User is accessing the DSCR register using the problem 1480c952c1c4SAnshuman Khandual * state only SPR number (0x03) either through a mfspr or 1481c952c1c4SAnshuman Khandual * a mtspr instruction. If it is a write attempt through 1482c952c1c4SAnshuman Khandual * a mtspr, then we set the inherit bit. This also allows 1483c952c1c4SAnshuman Khandual * the user to write or read the register directly in the 1484c952c1c4SAnshuman Khandual * future by setting via the FSCR DSCR bit. But in case it 1485c952c1c4SAnshuman Khandual * is a read DSCR attempt through a mfspr instruction, we 1486c952c1c4SAnshuman Khandual * just emulate the instruction instead. This code path will 1487c952c1c4SAnshuman Khandual * always emulate all the mfspr instructions till the user 1488c952c1c4SAnshuman Khandual * has attempted at least one mtspr instruction. This way it 1489c952c1c4SAnshuman Khandual * preserves the same behaviour when the user is accessing 1490c952c1c4SAnshuman Khandual * the DSCR through privilege level only SPR number (0x11) 1491c952c1c4SAnshuman Khandual * which is emulated through illegal instruction exception. 1492c952c1c4SAnshuman Khandual * We always leave HFSCR DSCR set. 14932517617eSMichael Neuling */ 1494c952c1c4SAnshuman Khandual if (get_user(instword, (u32 __user *)(regs->nip))) { 1495c952c1c4SAnshuman Khandual pr_err("Failed to fetch the user instruction\n"); 1496c952c1c4SAnshuman Khandual return; 1497c952c1c4SAnshuman Khandual } 1498c952c1c4SAnshuman Khandual 1499c952c1c4SAnshuman Khandual /* Write into DSCR (mtspr 0x03, RS) */ 1500c952c1c4SAnshuman Khandual if ((instword & PPC_INST_MTSPR_DSCR_USER_MASK) 1501c952c1c4SAnshuman Khandual == PPC_INST_MTSPR_DSCR_USER) { 1502c952c1c4SAnshuman Khandual rd = (instword >> 21) & 0x1f; 1503c952c1c4SAnshuman Khandual current->thread.dscr = regs->gpr[rd]; 15042517617eSMichael Neuling current->thread.dscr_inherit = 1; 1505b57bd2deSMichael Neuling current->thread.fscr |= FSCR_DSCR; 1506b57bd2deSMichael Neuling mtspr(SPRN_FSCR, current->thread.fscr); 1507c952c1c4SAnshuman Khandual } 1508c952c1c4SAnshuman Khandual 1509c952c1c4SAnshuman Khandual /* Read from DSCR (mfspr RT, 0x03) */ 1510c952c1c4SAnshuman Khandual if ((instword & PPC_INST_MFSPR_DSCR_USER_MASK) 1511c952c1c4SAnshuman Khandual == PPC_INST_MFSPR_DSCR_USER) { 1512c952c1c4SAnshuman Khandual if (emulate_instruction(regs)) { 1513c952c1c4SAnshuman Khandual pr_err("DSCR based mfspr emulation failed\n"); 1514c952c1c4SAnshuman Khandual return; 1515c952c1c4SAnshuman Khandual } 1516c952c1c4SAnshuman Khandual regs->nip += 4; 1517c952c1c4SAnshuman Khandual emulate_single_step(regs); 1518c952c1c4SAnshuman Khandual } 15192517617eSMichael Neuling return; 1520b14b6260SMichael Ellerman } 1521b14b6260SMichael Ellerman 1522172f7aaaSCyril Bur if (status == FSCR_TM_LG) { 1523172f7aaaSCyril Bur /* 1524172f7aaaSCyril Bur * If we're here then the hardware is TM aware because it 1525172f7aaaSCyril Bur * generated an exception with FSRM_TM set. 1526172f7aaaSCyril Bur * 1527172f7aaaSCyril Bur * If cpu_has_feature(CPU_FTR_TM) is false, then either firmware 1528172f7aaaSCyril Bur * told us not to do TM, or the kernel is not built with TM 1529172f7aaaSCyril Bur * support. 1530172f7aaaSCyril Bur * 1531172f7aaaSCyril Bur * If both of those things are true, then userspace can spam the 1532172f7aaaSCyril Bur * console by triggering the printk() below just by continually 1533172f7aaaSCyril Bur * doing tbegin (or any TM instruction). So in that case just 1534172f7aaaSCyril Bur * send the process a SIGILL immediately. 1535172f7aaaSCyril Bur */ 1536172f7aaaSCyril Bur if (!cpu_has_feature(CPU_FTR_TM)) 1537172f7aaaSCyril Bur goto out; 1538172f7aaaSCyril Bur 1539172f7aaaSCyril Bur tm_unavailable(regs); 1540172f7aaaSCyril Bur return; 1541172f7aaaSCyril Bur } 1542172f7aaaSCyril Bur 154393c2ec0fSBalbir Singh if ((hv || status >= 2) && 154493c2ec0fSBalbir Singh (status < ARRAY_SIZE(facility_strings)) && 15452517617eSMichael Neuling facility_strings[status]) 15462517617eSMichael Neuling facility = facility_strings[status]; 1547021424a1SMichael Ellerman 1548d0c0c9a1SMichael Neuling /* We restore the interrupt state now */ 1549d0c0c9a1SMichael Neuling if (!arch_irq_disabled_regs(regs)) 1550d0c0c9a1SMichael Neuling local_irq_enable(); 1551d0c0c9a1SMichael Neuling 155293c2ec0fSBalbir Singh pr_err_ratelimited("%sFacility '%s' unavailable (%d), exception at 0x%lx, MSR=%lx\n", 155393c2ec0fSBalbir Singh hv ? "Hypervisor " : "", facility, status, regs->nip, regs->msr); 1554d0c0c9a1SMichael Neuling 1555172f7aaaSCyril Bur out: 1556d0c0c9a1SMichael Neuling if (user_mode(regs)) { 1557d0c0c9a1SMichael Neuling _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 1558d0c0c9a1SMichael Neuling return; 1559d0c0c9a1SMichael Neuling } 1560d0c0c9a1SMichael Neuling 1561021424a1SMichael Ellerman die("Unexpected facility unavailable exception", regs, SIGABRT); 1562d0c0c9a1SMichael Neuling } 15632517617eSMichael Neuling #endif 1564d0c0c9a1SMichael Neuling 1565f54db641SMichael Neuling #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 1566f54db641SMichael Neuling 1567f54db641SMichael Neuling void fp_unavailable_tm(struct pt_regs *regs) 1568f54db641SMichael Neuling { 1569f54db641SMichael Neuling /* Note: This does not handle any kind of FP laziness. */ 1570f54db641SMichael Neuling 1571f54db641SMichael Neuling TM_DEBUG("FP Unavailable trap whilst transactional at 0x%lx, MSR=%lx\n", 1572f54db641SMichael Neuling regs->nip, regs->msr); 1573f54db641SMichael Neuling 1574f54db641SMichael Neuling /* We can only have got here if the task started using FP after 1575f54db641SMichael Neuling * beginning the transaction. So, the transactional regs are just a 1576f54db641SMichael Neuling * copy of the checkpointed ones. But, we still need to recheckpoint 1577f54db641SMichael Neuling * as we're enabling FP for the process; it will return, abort the 1578f54db641SMichael Neuling * transaction, and probably retry but now with FP enabled. So the 1579f54db641SMichael Neuling * checkpointed FP registers need to be loaded. 1580f54db641SMichael Neuling */ 1581d31626f7SPaul Mackerras tm_reclaim_current(TM_CAUSE_FAC_UNAV); 1582f54db641SMichael Neuling /* Reclaim didn't save out any FPRs to transact_fprs. */ 1583f54db641SMichael Neuling 1584f54db641SMichael Neuling /* Enable FP for the task: */ 1585f54db641SMichael Neuling regs->msr |= (MSR_FP | current->thread.fpexc_mode); 1586f54db641SMichael Neuling 1587f54db641SMichael Neuling /* This loads and recheckpoints the FP registers from 1588f54db641SMichael Neuling * thread.fpr[]. They will remain in registers after the 1589f54db641SMichael Neuling * checkpoint so we don't need to reload them after. 15903ac8ff1cSPaul Mackerras * If VMX is in use, the VRs now hold checkpointed values, 15913ac8ff1cSPaul Mackerras * so we don't want to load the VRs from the thread_struct. 1592f54db641SMichael Neuling */ 15933ac8ff1cSPaul Mackerras tm_recheckpoint(¤t->thread, MSR_FP); 15943ac8ff1cSPaul Mackerras 15953ac8ff1cSPaul Mackerras /* If VMX is in use, get the transactional values back */ 15963ac8ff1cSPaul Mackerras if (regs->msr & MSR_VEC) { 1597dc310669SCyril Bur msr_check_and_set(MSR_VEC); 1598dc310669SCyril Bur load_vr_state(¤t->thread.vr_state); 15993ac8ff1cSPaul Mackerras /* At this point all the VSX state is loaded, so enable it */ 16003ac8ff1cSPaul Mackerras regs->msr |= MSR_VSX; 16013ac8ff1cSPaul Mackerras } 1602f54db641SMichael Neuling } 1603f54db641SMichael Neuling 1604f54db641SMichael Neuling void altivec_unavailable_tm(struct pt_regs *regs) 1605f54db641SMichael Neuling { 1606f54db641SMichael Neuling /* See the comments in fp_unavailable_tm(). This function operates 1607f54db641SMichael Neuling * the same way. 1608f54db641SMichael Neuling */ 1609f54db641SMichael Neuling 1610f54db641SMichael Neuling TM_DEBUG("Vector Unavailable trap whilst transactional at 0x%lx," 1611f54db641SMichael Neuling "MSR=%lx\n", 1612f54db641SMichael Neuling regs->nip, regs->msr); 1613d31626f7SPaul Mackerras tm_reclaim_current(TM_CAUSE_FAC_UNAV); 1614f54db641SMichael Neuling regs->msr |= MSR_VEC; 16153ac8ff1cSPaul Mackerras tm_recheckpoint(¤t->thread, MSR_VEC); 1616f54db641SMichael Neuling current->thread.used_vr = 1; 1617f54db641SMichael Neuling 16183ac8ff1cSPaul Mackerras if (regs->msr & MSR_FP) { 1619dc310669SCyril Bur msr_check_and_set(MSR_FP); 1620dc310669SCyril Bur load_fp_state(¤t->thread.fp_state); 16213ac8ff1cSPaul Mackerras regs->msr |= MSR_VSX; 16223ac8ff1cSPaul Mackerras } 16233ac8ff1cSPaul Mackerras } 16243ac8ff1cSPaul Mackerras 1625f54db641SMichael Neuling void vsx_unavailable_tm(struct pt_regs *regs) 1626f54db641SMichael Neuling { 16273ac8ff1cSPaul Mackerras unsigned long orig_msr = regs->msr; 16283ac8ff1cSPaul Mackerras 1629f54db641SMichael Neuling /* See the comments in fp_unavailable_tm(). This works similarly, 1630f54db641SMichael Neuling * though we're loading both FP and VEC registers in here. 1631f54db641SMichael Neuling * 1632f54db641SMichael Neuling * If FP isn't in use, load FP regs. If VEC isn't in use, load VEC 1633f54db641SMichael Neuling * regs. Either way, set MSR_VSX. 1634f54db641SMichael Neuling */ 1635f54db641SMichael Neuling 1636f54db641SMichael Neuling TM_DEBUG("VSX Unavailable trap whilst transactional at 0x%lx," 1637f54db641SMichael Neuling "MSR=%lx\n", 1638f54db641SMichael Neuling regs->nip, regs->msr); 1639f54db641SMichael Neuling 16403ac8ff1cSPaul Mackerras current->thread.used_vsr = 1; 16413ac8ff1cSPaul Mackerras 16423ac8ff1cSPaul Mackerras /* If FP and VMX are already loaded, we have all the state we need */ 16433ac8ff1cSPaul Mackerras if ((orig_msr & (MSR_FP | MSR_VEC)) == (MSR_FP | MSR_VEC)) { 16443ac8ff1cSPaul Mackerras regs->msr |= MSR_VSX; 16453ac8ff1cSPaul Mackerras return; 16463ac8ff1cSPaul Mackerras } 16473ac8ff1cSPaul Mackerras 1648f54db641SMichael Neuling /* This reclaims FP and/or VR regs if they're already enabled */ 1649d31626f7SPaul Mackerras tm_reclaim_current(TM_CAUSE_FAC_UNAV); 1650f54db641SMichael Neuling 1651f54db641SMichael Neuling regs->msr |= MSR_VEC | MSR_FP | current->thread.fpexc_mode | 1652f54db641SMichael Neuling MSR_VSX; 16533ac8ff1cSPaul Mackerras 16543ac8ff1cSPaul Mackerras /* This loads & recheckpoints FP and VRs; but we have 16553ac8ff1cSPaul Mackerras * to be sure not to overwrite previously-valid state. 16563ac8ff1cSPaul Mackerras */ 16573ac8ff1cSPaul Mackerras tm_recheckpoint(¤t->thread, regs->msr & ~orig_msr); 16583ac8ff1cSPaul Mackerras 1659dc310669SCyril Bur msr_check_and_set(orig_msr & (MSR_FP | MSR_VEC)); 1660dc310669SCyril Bur 16613ac8ff1cSPaul Mackerras if (orig_msr & MSR_FP) 1662dc310669SCyril Bur load_fp_state(¤t->thread.fp_state); 16633ac8ff1cSPaul Mackerras if (orig_msr & MSR_VEC) 1664dc310669SCyril Bur load_vr_state(¤t->thread.vr_state); 1665f54db641SMichael Neuling } 1666f54db641SMichael Neuling #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ 1667f54db641SMichael Neuling 1668dc1c1ca3SStephen Rothwell void performance_monitor_exception(struct pt_regs *regs) 1669dc1c1ca3SStephen Rothwell { 167069111bacSChristoph Lameter __this_cpu_inc(irq_stat.pmu_irqs); 167189713ed1SAnton Blanchard 1672dc1c1ca3SStephen Rothwell perf_irq(regs); 1673dc1c1ca3SStephen Rothwell } 1674dc1c1ca3SStephen Rothwell 16758dad3f92SPaul Mackerras #ifdef CONFIG_8xx 167614cf11afSPaul Mackerras void SoftwareEmulation(struct pt_regs *regs) 167714cf11afSPaul Mackerras { 167814cf11afSPaul Mackerras CHECK_FULL_REGS(regs); 167914cf11afSPaul Mackerras 168014cf11afSPaul Mackerras if (!user_mode(regs)) { 168114cf11afSPaul Mackerras debugger(regs); 16821eb2819dSLEROY Christophe die("Kernel Mode Unimplemented Instruction or SW FPU Emulation", 16831eb2819dSLEROY Christophe regs, SIGFPE); 168414cf11afSPaul Mackerras } 168514cf11afSPaul Mackerras 16863a3b5aa6SKevin Hao if (!emulate_math(regs)) 16873a3b5aa6SKevin Hao return; 16885fad293bSKumar Gala 16895fad293bSKumar Gala _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 169014cf11afSPaul Mackerras } 16918dad3f92SPaul Mackerras #endif /* CONFIG_8xx */ 169214cf11afSPaul Mackerras 1693172ae2e7SDave Kleikamp #ifdef CONFIG_PPC_ADV_DEBUG_REGS 16943bffb652SDave Kleikamp static void handle_debug(struct pt_regs *regs, unsigned long debug_status) 16953bffb652SDave Kleikamp { 16963bffb652SDave Kleikamp int changed = 0; 16973bffb652SDave Kleikamp /* 16983bffb652SDave Kleikamp * Determine the cause of the debug event, clear the 16993bffb652SDave Kleikamp * event flags and send a trap to the handler. Torez 17003bffb652SDave Kleikamp */ 17013bffb652SDave Kleikamp if (debug_status & (DBSR_DAC1R | DBSR_DAC1W)) { 17023bffb652SDave Kleikamp dbcr_dac(current) &= ~(DBCR_DAC1R | DBCR_DAC1W); 17033bffb652SDave Kleikamp #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE 170451ae8d4aSBharat Bhushan current->thread.debug.dbcr2 &= ~DBCR2_DAC12MODE; 17053bffb652SDave Kleikamp #endif 17063bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_DAC1), debug_status, TRAP_HWBKPT, 17073bffb652SDave Kleikamp 5); 17083bffb652SDave Kleikamp changed |= 0x01; 17093bffb652SDave Kleikamp } else if (debug_status & (DBSR_DAC2R | DBSR_DAC2W)) { 17103bffb652SDave Kleikamp dbcr_dac(current) &= ~(DBCR_DAC2R | DBCR_DAC2W); 17113bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_DAC2), debug_status, TRAP_HWBKPT, 17123bffb652SDave Kleikamp 6); 17133bffb652SDave Kleikamp changed |= 0x01; 17143bffb652SDave Kleikamp } else if (debug_status & DBSR_IAC1) { 171551ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IAC1; 17163bffb652SDave Kleikamp dbcr_iac_range(current) &= ~DBCR_IAC12MODE; 17173bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_IAC1), debug_status, TRAP_HWBKPT, 17183bffb652SDave Kleikamp 1); 17193bffb652SDave Kleikamp changed |= 0x01; 17203bffb652SDave Kleikamp } else if (debug_status & DBSR_IAC2) { 172151ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IAC2; 17223bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_IAC2), debug_status, TRAP_HWBKPT, 17233bffb652SDave Kleikamp 2); 17243bffb652SDave Kleikamp changed |= 0x01; 17253bffb652SDave Kleikamp } else if (debug_status & DBSR_IAC3) { 172651ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IAC3; 17273bffb652SDave Kleikamp dbcr_iac_range(current) &= ~DBCR_IAC34MODE; 17283bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_IAC3), debug_status, TRAP_HWBKPT, 17293bffb652SDave Kleikamp 3); 17303bffb652SDave Kleikamp changed |= 0x01; 17313bffb652SDave Kleikamp } else if (debug_status & DBSR_IAC4) { 173251ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IAC4; 17333bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_IAC4), debug_status, TRAP_HWBKPT, 17343bffb652SDave Kleikamp 4); 17353bffb652SDave Kleikamp changed |= 0x01; 17363bffb652SDave Kleikamp } 17373bffb652SDave Kleikamp /* 17383bffb652SDave Kleikamp * At the point this routine was called, the MSR(DE) was turned off. 17393bffb652SDave Kleikamp * Check all other debug flags and see if that bit needs to be turned 17403bffb652SDave Kleikamp * back on or not. 17413bffb652SDave Kleikamp */ 174251ae8d4aSBharat Bhushan if (DBCR_ACTIVE_EVENTS(current->thread.debug.dbcr0, 174351ae8d4aSBharat Bhushan current->thread.debug.dbcr1)) 17443bffb652SDave Kleikamp regs->msr |= MSR_DE; 17453bffb652SDave Kleikamp else 17463bffb652SDave Kleikamp /* Make sure the IDM flag is off */ 174751ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IDM; 17483bffb652SDave Kleikamp 17493bffb652SDave Kleikamp if (changed & 0x01) 175051ae8d4aSBharat Bhushan mtspr(SPRN_DBCR0, current->thread.debug.dbcr0); 17513bffb652SDave Kleikamp } 175214cf11afSPaul Mackerras 175303465f89SNicholas Piggin void DebugException(struct pt_regs *regs, unsigned long debug_status) 175414cf11afSPaul Mackerras { 175551ae8d4aSBharat Bhushan current->thread.debug.dbsr = debug_status; 17563bffb652SDave Kleikamp 1757ec097c84SRoland McGrath /* Hack alert: On BookE, Branch Taken stops on the branch itself, while 1758ec097c84SRoland McGrath * on server, it stops on the target of the branch. In order to simulate 1759ec097c84SRoland McGrath * the server behaviour, we thus restart right away with a single step 1760ec097c84SRoland McGrath * instead of stopping here when hitting a BT 1761ec097c84SRoland McGrath */ 1762ec097c84SRoland McGrath if (debug_status & DBSR_BT) { 1763ec097c84SRoland McGrath regs->msr &= ~MSR_DE; 1764ec097c84SRoland McGrath 1765ec097c84SRoland McGrath /* Disable BT */ 1766ec097c84SRoland McGrath mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_BT); 1767ec097c84SRoland McGrath /* Clear the BT event */ 1768ec097c84SRoland McGrath mtspr(SPRN_DBSR, DBSR_BT); 1769ec097c84SRoland McGrath 1770ec097c84SRoland McGrath /* Do the single step trick only when coming from userspace */ 1771ec097c84SRoland McGrath if (user_mode(regs)) { 177251ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_BT; 177351ae8d4aSBharat Bhushan current->thread.debug.dbcr0 |= DBCR0_IDM | DBCR0_IC; 1774ec097c84SRoland McGrath regs->msr |= MSR_DE; 1775ec097c84SRoland McGrath return; 1776ec097c84SRoland McGrath } 1777ec097c84SRoland McGrath 17786cc89badSNaveen N. Rao if (kprobe_post_handler(regs)) 17796cc89badSNaveen N. Rao return; 17806cc89badSNaveen N. Rao 1781ec097c84SRoland McGrath if (notify_die(DIE_SSTEP, "block_step", regs, 5, 1782ec097c84SRoland McGrath 5, SIGTRAP) == NOTIFY_STOP) { 1783ec097c84SRoland McGrath return; 1784ec097c84SRoland McGrath } 1785ec097c84SRoland McGrath if (debugger_sstep(regs)) 1786ec097c84SRoland McGrath return; 1787ec097c84SRoland McGrath } else if (debug_status & DBSR_IC) { /* Instruction complete */ 178814cf11afSPaul Mackerras regs->msr &= ~MSR_DE; 1789f8279621SKumar Gala 179014cf11afSPaul Mackerras /* Disable instruction completion */ 179114cf11afSPaul Mackerras mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_IC); 179214cf11afSPaul Mackerras /* Clear the instruction completion event */ 179314cf11afSPaul Mackerras mtspr(SPRN_DBSR, DBSR_IC); 1794f8279621SKumar Gala 17956cc89badSNaveen N. Rao if (kprobe_post_handler(regs)) 17966cc89badSNaveen N. Rao return; 17976cc89badSNaveen N. Rao 1798f8279621SKumar Gala if (notify_die(DIE_SSTEP, "single_step", regs, 5, 1799f8279621SKumar Gala 5, SIGTRAP) == NOTIFY_STOP) { 180014cf11afSPaul Mackerras return; 180114cf11afSPaul Mackerras } 1802f8279621SKumar Gala 1803f8279621SKumar Gala if (debugger_sstep(regs)) 1804f8279621SKumar Gala return; 1805f8279621SKumar Gala 18063bffb652SDave Kleikamp if (user_mode(regs)) { 180751ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IC; 180851ae8d4aSBharat Bhushan if (DBCR_ACTIVE_EVENTS(current->thread.debug.dbcr0, 180951ae8d4aSBharat Bhushan current->thread.debug.dbcr1)) 18103bffb652SDave Kleikamp regs->msr |= MSR_DE; 18113bffb652SDave Kleikamp else 18123bffb652SDave Kleikamp /* Make sure the IDM bit is off */ 181351ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IDM; 18143bffb652SDave Kleikamp } 1815f8279621SKumar Gala 1816f8279621SKumar Gala _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip); 18173bffb652SDave Kleikamp } else 18183bffb652SDave Kleikamp handle_debug(regs, debug_status); 181914cf11afSPaul Mackerras } 182003465f89SNicholas Piggin NOKPROBE_SYMBOL(DebugException); 1821172ae2e7SDave Kleikamp #endif /* CONFIG_PPC_ADV_DEBUG_REGS */ 182214cf11afSPaul Mackerras 182314cf11afSPaul Mackerras #if !defined(CONFIG_TAU_INT) 182414cf11afSPaul Mackerras void TAUException(struct pt_regs *regs) 182514cf11afSPaul Mackerras { 182614cf11afSPaul Mackerras printk("TAU trap at PC: %lx, MSR: %lx, vector=%lx %s\n", 182714cf11afSPaul Mackerras regs->nip, regs->msr, regs->trap, print_tainted()); 182814cf11afSPaul Mackerras } 182914cf11afSPaul Mackerras #endif /* CONFIG_INT_TAU */ 183014cf11afSPaul Mackerras 183114cf11afSPaul Mackerras #ifdef CONFIG_ALTIVEC 1832dc1c1ca3SStephen Rothwell void altivec_assist_exception(struct pt_regs *regs) 183314cf11afSPaul Mackerras { 183414cf11afSPaul Mackerras int err; 183514cf11afSPaul Mackerras 183614cf11afSPaul Mackerras if (!user_mode(regs)) { 183714cf11afSPaul Mackerras printk(KERN_EMERG "VMX/Altivec assist exception in kernel mode" 183814cf11afSPaul Mackerras " at %lx\n", regs->nip); 18398dad3f92SPaul Mackerras die("Kernel VMX/Altivec assist exception", regs, SIGILL); 184014cf11afSPaul Mackerras } 184114cf11afSPaul Mackerras 1842dc1c1ca3SStephen Rothwell flush_altivec_to_thread(current); 1843dc1c1ca3SStephen Rothwell 1844eecff81dSAnton Blanchard PPC_WARN_EMULATED(altivec, regs); 184514cf11afSPaul Mackerras err = emulate_altivec(regs); 184614cf11afSPaul Mackerras if (err == 0) { 184714cf11afSPaul Mackerras regs->nip += 4; /* skip emulated instruction */ 184814cf11afSPaul Mackerras emulate_single_step(regs); 184914cf11afSPaul Mackerras return; 185014cf11afSPaul Mackerras } 185114cf11afSPaul Mackerras 185214cf11afSPaul Mackerras if (err == -EFAULT) { 185314cf11afSPaul Mackerras /* got an error reading the instruction */ 185414cf11afSPaul Mackerras _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip); 185514cf11afSPaul Mackerras } else { 185614cf11afSPaul Mackerras /* didn't recognize the instruction */ 185714cf11afSPaul Mackerras /* XXX quick hack for now: set the non-Java bit in the VSCR */ 185876462232SChristian Dietrich printk_ratelimited(KERN_ERR "Unrecognized altivec instruction " 185914cf11afSPaul Mackerras "in %s at %lx\n", current->comm, regs->nip); 1860de79f7b9SPaul Mackerras current->thread.vr_state.vscr.u[3] |= 0x10000; 186114cf11afSPaul Mackerras } 186214cf11afSPaul Mackerras } 186314cf11afSPaul Mackerras #endif /* CONFIG_ALTIVEC */ 186414cf11afSPaul Mackerras 186514cf11afSPaul Mackerras #ifdef CONFIG_FSL_BOOKE 186614cf11afSPaul Mackerras void CacheLockingException(struct pt_regs *regs, unsigned long address, 186714cf11afSPaul Mackerras unsigned long error_code) 186814cf11afSPaul Mackerras { 186914cf11afSPaul Mackerras /* We treat cache locking instructions from the user 187014cf11afSPaul Mackerras * as priv ops, in the future we could try to do 187114cf11afSPaul Mackerras * something smarter 187214cf11afSPaul Mackerras */ 187314cf11afSPaul Mackerras if (error_code & (ESR_DLK|ESR_ILK)) 187414cf11afSPaul Mackerras _exception(SIGILL, regs, ILL_PRVOPC, regs->nip); 187514cf11afSPaul Mackerras return; 187614cf11afSPaul Mackerras } 187714cf11afSPaul Mackerras #endif /* CONFIG_FSL_BOOKE */ 187814cf11afSPaul Mackerras 187914cf11afSPaul Mackerras #ifdef CONFIG_SPE 188014cf11afSPaul Mackerras void SPEFloatingPointException(struct pt_regs *regs) 188114cf11afSPaul Mackerras { 18826a800f36SLiu Yu extern int do_spe_mathemu(struct pt_regs *regs); 188314cf11afSPaul Mackerras unsigned long spefscr; 188414cf11afSPaul Mackerras int fpexc_mode; 188514cf11afSPaul Mackerras int code = 0; 18866a800f36SLiu Yu int err; 18876a800f36SLiu Yu 1888685659eeSyu liu flush_spe_to_thread(current); 188914cf11afSPaul Mackerras 189014cf11afSPaul Mackerras spefscr = current->thread.spefscr; 189114cf11afSPaul Mackerras fpexc_mode = current->thread.fpexc_mode; 189214cf11afSPaul Mackerras 189314cf11afSPaul Mackerras if ((spefscr & SPEFSCR_FOVF) && (fpexc_mode & PR_FP_EXC_OVF)) { 189414cf11afSPaul Mackerras code = FPE_FLTOVF; 189514cf11afSPaul Mackerras } 189614cf11afSPaul Mackerras else if ((spefscr & SPEFSCR_FUNF) && (fpexc_mode & PR_FP_EXC_UND)) { 189714cf11afSPaul Mackerras code = FPE_FLTUND; 189814cf11afSPaul Mackerras } 189914cf11afSPaul Mackerras else if ((spefscr & SPEFSCR_FDBZ) && (fpexc_mode & PR_FP_EXC_DIV)) 190014cf11afSPaul Mackerras code = FPE_FLTDIV; 190114cf11afSPaul Mackerras else if ((spefscr & SPEFSCR_FINV) && (fpexc_mode & PR_FP_EXC_INV)) { 190214cf11afSPaul Mackerras code = FPE_FLTINV; 190314cf11afSPaul Mackerras } 190414cf11afSPaul Mackerras else if ((spefscr & (SPEFSCR_FG | SPEFSCR_FX)) && (fpexc_mode & PR_FP_EXC_RES)) 190514cf11afSPaul Mackerras code = FPE_FLTRES; 190614cf11afSPaul Mackerras 19076a800f36SLiu Yu err = do_spe_mathemu(regs); 19086a800f36SLiu Yu if (err == 0) { 19096a800f36SLiu Yu regs->nip += 4; /* skip emulated instruction */ 19106a800f36SLiu Yu emulate_single_step(regs); 191114cf11afSPaul Mackerras return; 191214cf11afSPaul Mackerras } 19136a800f36SLiu Yu 19146a800f36SLiu Yu if (err == -EFAULT) { 19156a800f36SLiu Yu /* got an error reading the instruction */ 19166a800f36SLiu Yu _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip); 19176a800f36SLiu Yu } else if (err == -EINVAL) { 19186a800f36SLiu Yu /* didn't recognize the instruction */ 19196a800f36SLiu Yu printk(KERN_ERR "unrecognized spe instruction " 19206a800f36SLiu Yu "in %s at %lx\n", current->comm, regs->nip); 19216a800f36SLiu Yu } else { 19226a800f36SLiu Yu _exception(SIGFPE, regs, code, regs->nip); 19236a800f36SLiu Yu } 19246a800f36SLiu Yu 19256a800f36SLiu Yu return; 19266a800f36SLiu Yu } 19276a800f36SLiu Yu 19286a800f36SLiu Yu void SPEFloatingPointRoundException(struct pt_regs *regs) 19296a800f36SLiu Yu { 19306a800f36SLiu Yu extern int speround_handler(struct pt_regs *regs); 19316a800f36SLiu Yu int err; 19326a800f36SLiu Yu 19336a800f36SLiu Yu preempt_disable(); 19346a800f36SLiu Yu if (regs->msr & MSR_SPE) 19356a800f36SLiu Yu giveup_spe(current); 19366a800f36SLiu Yu preempt_enable(); 19376a800f36SLiu Yu 19386a800f36SLiu Yu regs->nip -= 4; 19396a800f36SLiu Yu err = speround_handler(regs); 19406a800f36SLiu Yu if (err == 0) { 19416a800f36SLiu Yu regs->nip += 4; /* skip emulated instruction */ 19426a800f36SLiu Yu emulate_single_step(regs); 19436a800f36SLiu Yu return; 19446a800f36SLiu Yu } 19456a800f36SLiu Yu 19466a800f36SLiu Yu if (err == -EFAULT) { 19476a800f36SLiu Yu /* got an error reading the instruction */ 19486a800f36SLiu Yu _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip); 19496a800f36SLiu Yu } else if (err == -EINVAL) { 19506a800f36SLiu Yu /* didn't recognize the instruction */ 19516a800f36SLiu Yu printk(KERN_ERR "unrecognized spe instruction " 19526a800f36SLiu Yu "in %s at %lx\n", current->comm, regs->nip); 19536a800f36SLiu Yu } else { 19546a800f36SLiu Yu _exception(SIGFPE, regs, 0, regs->nip); 19556a800f36SLiu Yu return; 19566a800f36SLiu Yu } 19576a800f36SLiu Yu } 195814cf11afSPaul Mackerras #endif 195914cf11afSPaul Mackerras 1960dc1c1ca3SStephen Rothwell /* 1961dc1c1ca3SStephen Rothwell * We enter here if we get an unrecoverable exception, that is, one 1962dc1c1ca3SStephen Rothwell * that happened at a point where the RI (recoverable interrupt) bit 1963dc1c1ca3SStephen Rothwell * in the MSR is 0. This indicates that SRR0/1 are live, and that 1964dc1c1ca3SStephen Rothwell * we therefore lost state by taking this exception. 1965dc1c1ca3SStephen Rothwell */ 1966dc1c1ca3SStephen Rothwell void unrecoverable_exception(struct pt_regs *regs) 1967dc1c1ca3SStephen Rothwell { 1968dc1c1ca3SStephen Rothwell printk(KERN_EMERG "Unrecoverable exception %lx at %lx\n", 1969dc1c1ca3SStephen Rothwell regs->trap, regs->nip); 1970dc1c1ca3SStephen Rothwell die("Unrecoverable exception", regs, SIGABRT); 1971dc1c1ca3SStephen Rothwell } 1972*15770a13SNaveen N. Rao NOKPROBE_SYMBOL(unrecoverable_exception); 1973dc1c1ca3SStephen Rothwell 19741e18c17aSJason Gunthorpe #if defined(CONFIG_BOOKE_WDT) || defined(CONFIG_40x) 197514cf11afSPaul Mackerras /* 197614cf11afSPaul Mackerras * Default handler for a Watchdog exception, 197714cf11afSPaul Mackerras * spins until a reboot occurs 197814cf11afSPaul Mackerras */ 197914cf11afSPaul Mackerras void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs) 198014cf11afSPaul Mackerras { 198114cf11afSPaul Mackerras /* Generic WatchdogHandler, implement your own */ 198214cf11afSPaul Mackerras mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE)); 198314cf11afSPaul Mackerras return; 198414cf11afSPaul Mackerras } 198514cf11afSPaul Mackerras 198614cf11afSPaul Mackerras void WatchdogException(struct pt_regs *regs) 198714cf11afSPaul Mackerras { 198814cf11afSPaul Mackerras printk (KERN_EMERG "PowerPC Book-E Watchdog Exception\n"); 198914cf11afSPaul Mackerras WatchdogHandler(regs); 199014cf11afSPaul Mackerras } 199114cf11afSPaul Mackerras #endif 1992dc1c1ca3SStephen Rothwell 1993dc1c1ca3SStephen Rothwell /* 1994dc1c1ca3SStephen Rothwell * We enter here if we discover during exception entry that we are 1995dc1c1ca3SStephen Rothwell * running in supervisor mode with a userspace value in the stack pointer. 1996dc1c1ca3SStephen Rothwell */ 1997dc1c1ca3SStephen Rothwell void kernel_bad_stack(struct pt_regs *regs) 1998dc1c1ca3SStephen Rothwell { 1999dc1c1ca3SStephen Rothwell printk(KERN_EMERG "Bad kernel stack pointer %lx at %lx\n", 2000dc1c1ca3SStephen Rothwell regs->gpr[1], regs->nip); 2001dc1c1ca3SStephen Rothwell die("Bad kernel stack pointer", regs, SIGABRT); 2002dc1c1ca3SStephen Rothwell } 2003*15770a13SNaveen N. Rao NOKPROBE_SYMBOL(kernel_bad_stack); 200414cf11afSPaul Mackerras 200514cf11afSPaul Mackerras void __init trap_init(void) 200614cf11afSPaul Mackerras { 200714cf11afSPaul Mackerras } 200880947e7cSGeert Uytterhoeven 200980947e7cSGeert Uytterhoeven 201080947e7cSGeert Uytterhoeven #ifdef CONFIG_PPC_EMULATED_STATS 201180947e7cSGeert Uytterhoeven 201280947e7cSGeert Uytterhoeven #define WARN_EMULATED_SETUP(type) .type = { .name = #type } 201380947e7cSGeert Uytterhoeven 201480947e7cSGeert Uytterhoeven struct ppc_emulated ppc_emulated = { 201580947e7cSGeert Uytterhoeven #ifdef CONFIG_ALTIVEC 201680947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(altivec), 201780947e7cSGeert Uytterhoeven #endif 201880947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(dcba), 201980947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(dcbz), 202080947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(fp_pair), 202180947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(isel), 202280947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(mcrxr), 202380947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(mfpvr), 202480947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(multiple), 202580947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(popcntb), 202680947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(spe), 202780947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(string), 2028a3821b2aSScott Wood WARN_EMULATED_SETUP(sync), 202980947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(unaligned), 203080947e7cSGeert Uytterhoeven #ifdef CONFIG_MATH_EMULATION 203180947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(math), 203280947e7cSGeert Uytterhoeven #endif 203380947e7cSGeert Uytterhoeven #ifdef CONFIG_VSX 203480947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(vsx), 203580947e7cSGeert Uytterhoeven #endif 2036efcac658SAlexey Kardashevskiy #ifdef CONFIG_PPC64 2037efcac658SAlexey Kardashevskiy WARN_EMULATED_SETUP(mfdscr), 2038efcac658SAlexey Kardashevskiy WARN_EMULATED_SETUP(mtdscr), 2039f83319d7SAnton Blanchard WARN_EMULATED_SETUP(lq_stq), 2040efcac658SAlexey Kardashevskiy #endif 204180947e7cSGeert Uytterhoeven }; 204280947e7cSGeert Uytterhoeven 204380947e7cSGeert Uytterhoeven u32 ppc_warn_emulated; 204480947e7cSGeert Uytterhoeven 204580947e7cSGeert Uytterhoeven void ppc_warn_emulated_print(const char *type) 204680947e7cSGeert Uytterhoeven { 204776462232SChristian Dietrich pr_warn_ratelimited("%s used emulated %s instruction\n", current->comm, 204880947e7cSGeert Uytterhoeven type); 204980947e7cSGeert Uytterhoeven } 205080947e7cSGeert Uytterhoeven 205180947e7cSGeert Uytterhoeven static int __init ppc_warn_emulated_init(void) 205280947e7cSGeert Uytterhoeven { 205380947e7cSGeert Uytterhoeven struct dentry *dir, *d; 205480947e7cSGeert Uytterhoeven unsigned int i; 205580947e7cSGeert Uytterhoeven struct ppc_emulated_entry *entries = (void *)&ppc_emulated; 205680947e7cSGeert Uytterhoeven 205780947e7cSGeert Uytterhoeven if (!powerpc_debugfs_root) 205880947e7cSGeert Uytterhoeven return -ENODEV; 205980947e7cSGeert Uytterhoeven 206080947e7cSGeert Uytterhoeven dir = debugfs_create_dir("emulated_instructions", 206180947e7cSGeert Uytterhoeven powerpc_debugfs_root); 206280947e7cSGeert Uytterhoeven if (!dir) 206380947e7cSGeert Uytterhoeven return -ENOMEM; 206480947e7cSGeert Uytterhoeven 206580947e7cSGeert Uytterhoeven d = debugfs_create_u32("do_warn", S_IRUGO | S_IWUSR, dir, 206680947e7cSGeert Uytterhoeven &ppc_warn_emulated); 206780947e7cSGeert Uytterhoeven if (!d) 206880947e7cSGeert Uytterhoeven goto fail; 206980947e7cSGeert Uytterhoeven 207080947e7cSGeert Uytterhoeven for (i = 0; i < sizeof(ppc_emulated)/sizeof(*entries); i++) { 207180947e7cSGeert Uytterhoeven d = debugfs_create_u32(entries[i].name, S_IRUGO | S_IWUSR, dir, 207280947e7cSGeert Uytterhoeven (u32 *)&entries[i].val.counter); 207380947e7cSGeert Uytterhoeven if (!d) 207480947e7cSGeert Uytterhoeven goto fail; 207580947e7cSGeert Uytterhoeven } 207680947e7cSGeert Uytterhoeven 207780947e7cSGeert Uytterhoeven return 0; 207880947e7cSGeert Uytterhoeven 207980947e7cSGeert Uytterhoeven fail: 208080947e7cSGeert Uytterhoeven debugfs_remove_recursive(dir); 208180947e7cSGeert Uytterhoeven return -ENOMEM; 208280947e7cSGeert Uytterhoeven } 208380947e7cSGeert Uytterhoeven 208480947e7cSGeert Uytterhoeven device_initcall(ppc_warn_emulated_init); 208580947e7cSGeert Uytterhoeven 208680947e7cSGeert Uytterhoeven #endif /* CONFIG_PPC_EMULATED_STATS */ 2087