114cf11afSPaul Mackerras /* 214cf11afSPaul Mackerras * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) 3fe04b112SScott Wood * Copyright 2007-2010 Freescale Semiconductor, Inc. 414cf11afSPaul Mackerras * 514cf11afSPaul Mackerras * This program is free software; you can redistribute it and/or 614cf11afSPaul Mackerras * modify it under the terms of the GNU General Public License 714cf11afSPaul Mackerras * as published by the Free Software Foundation; either version 814cf11afSPaul Mackerras * 2 of the License, or (at your option) any later version. 914cf11afSPaul Mackerras * 1014cf11afSPaul Mackerras * Modified by Cort Dougan (cort@cs.nmt.edu) 1114cf11afSPaul Mackerras * and Paul Mackerras (paulus@samba.org) 1214cf11afSPaul Mackerras */ 1314cf11afSPaul Mackerras 1414cf11afSPaul Mackerras /* 1514cf11afSPaul Mackerras * This file handles the architecture-dependent parts of hardware exceptions 1614cf11afSPaul Mackerras */ 1714cf11afSPaul Mackerras 1814cf11afSPaul Mackerras #include <linux/errno.h> 1914cf11afSPaul Mackerras #include <linux/sched.h> 2014cf11afSPaul Mackerras #include <linux/kernel.h> 2114cf11afSPaul Mackerras #include <linux/mm.h> 2214cf11afSPaul Mackerras #include <linux/stddef.h> 2314cf11afSPaul Mackerras #include <linux/unistd.h> 248dad3f92SPaul Mackerras #include <linux/ptrace.h> 2514cf11afSPaul Mackerras #include <linux/user.h> 2614cf11afSPaul Mackerras #include <linux/interrupt.h> 2714cf11afSPaul Mackerras #include <linux/init.h> 288a39b05fSPaul Gortmaker #include <linux/extable.h> 298a39b05fSPaul Gortmaker #include <linux/module.h> /* print_modules */ 308dad3f92SPaul Mackerras #include <linux/prctl.h> 3114cf11afSPaul Mackerras #include <linux/delay.h> 3214cf11afSPaul Mackerras #include <linux/kprobes.h> 33cc532915SMichael Ellerman #include <linux/kexec.h> 345474c120SMichael Hanselmann #include <linux/backlight.h> 3573c9ceabSJeremy Fitzhardinge #include <linux/bug.h> 361eeb66a1SChristoph Hellwig #include <linux/kdebug.h> 3780947e7cSGeert Uytterhoeven #include <linux/debugfs.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> 4314cf11afSPaul Mackerras #include <asm/uaccess.h> 4414cf11afSPaul Mackerras #include <asm/io.h> 4586417780SPaul Mackerras #include <asm/machdep.h> 4686417780SPaul Mackerras #include <asm/rtas.h> 47f7f6f4feSDavid Gibson #include <asm/pmc.h> 4814cf11afSPaul Mackerras #include <asm/reg.h> 4914cf11afSPaul Mackerras #ifdef CONFIG_PMAC_BACKLIGHT 5014cf11afSPaul Mackerras #include <asm/backlight.h> 5114cf11afSPaul Mackerras #endif 52dc1c1ca3SStephen Rothwell #ifdef CONFIG_PPC64 5386417780SPaul Mackerras #include <asm/firmware.h> 54dc1c1ca3SStephen Rothwell #include <asm/processor.h> 556ce6c629SMichael Neuling #include <asm/tm.h> 56dc1c1ca3SStephen Rothwell #endif 57c0ce7d08SDavid Wilder #include <asm/kexec.h> 5816c57b36SKumar Gala #include <asm/ppc-opcode.h> 59cce1f106SShaohui Xie #include <asm/rio.h> 60ebaeb5aeSMahesh Salgaonkar #include <asm/fadump.h> 61ae3a197eSDavid Howells #include <asm/switch_to.h> 62f54db641SMichael Neuling #include <asm/tm.h> 63ae3a197eSDavid Howells #include <asm/debug.h> 6442f5b4caSDaniel Axtens #include <asm/asm-prototypes.h> 65fd7bacbcSMahesh Salgaonkar #include <asm/hmi.h> 664e0e3435SHongtao Jia #include <sysdev/fsl_pci.h> 67*6cc89badSNaveen N. Rao #include <asm/kprobes.h> 68dc1c1ca3SStephen Rothwell 697dbb922cSOlof Johansson #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC) 705be3492fSAnton Blanchard int (*__debugger)(struct pt_regs *regs) __read_mostly; 715be3492fSAnton Blanchard int (*__debugger_ipi)(struct pt_regs *regs) __read_mostly; 725be3492fSAnton Blanchard int (*__debugger_bpt)(struct pt_regs *regs) __read_mostly; 735be3492fSAnton Blanchard int (*__debugger_sstep)(struct pt_regs *regs) __read_mostly; 745be3492fSAnton Blanchard int (*__debugger_iabr_match)(struct pt_regs *regs) __read_mostly; 759422de3eSMichael Neuling int (*__debugger_break_match)(struct pt_regs *regs) __read_mostly; 765be3492fSAnton Blanchard int (*__debugger_fault_handler)(struct pt_regs *regs) __read_mostly; 7714cf11afSPaul Mackerras 7814cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger); 7914cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_ipi); 8014cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_bpt); 8114cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_sstep); 8214cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_iabr_match); 839422de3eSMichael Neuling EXPORT_SYMBOL(__debugger_break_match); 8414cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_fault_handler); 8514cf11afSPaul Mackerras #endif 8614cf11afSPaul Mackerras 878b3c34cfSMichael Neuling /* Transactional Memory trap debug */ 888b3c34cfSMichael Neuling #ifdef TM_DEBUG_SW 898b3c34cfSMichael Neuling #define TM_DEBUG(x...) printk(KERN_INFO x) 908b3c34cfSMichael Neuling #else 918b3c34cfSMichael Neuling #define TM_DEBUG(x...) do { } while(0) 928b3c34cfSMichael Neuling #endif 938b3c34cfSMichael Neuling 9414cf11afSPaul Mackerras /* 9514cf11afSPaul Mackerras * Trap & Exception support 9614cf11afSPaul Mackerras */ 9714cf11afSPaul Mackerras 986031d9d9Santon@samba.org #ifdef CONFIG_PMAC_BACKLIGHT 996031d9d9Santon@samba.org static void pmac_backlight_unblank(void) 1006031d9d9Santon@samba.org { 1016031d9d9Santon@samba.org mutex_lock(&pmac_backlight_mutex); 1026031d9d9Santon@samba.org if (pmac_backlight) { 1036031d9d9Santon@samba.org struct backlight_properties *props; 1046031d9d9Santon@samba.org 1056031d9d9Santon@samba.org props = &pmac_backlight->props; 1066031d9d9Santon@samba.org props->brightness = props->max_brightness; 1076031d9d9Santon@samba.org props->power = FB_BLANK_UNBLANK; 1086031d9d9Santon@samba.org backlight_update_status(pmac_backlight); 1096031d9d9Santon@samba.org } 1106031d9d9Santon@samba.org mutex_unlock(&pmac_backlight_mutex); 1116031d9d9Santon@samba.org } 1126031d9d9Santon@samba.org #else 1136031d9d9Santon@samba.org static inline void pmac_backlight_unblank(void) { } 1146031d9d9Santon@samba.org #endif 1156031d9d9Santon@samba.org 116760ca4dcSAnton Blanchard static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED; 117760ca4dcSAnton Blanchard static int die_owner = -1; 118760ca4dcSAnton Blanchard static unsigned int die_nest_count; 119c0ce7d08SDavid Wilder static int die_counter; 120760ca4dcSAnton Blanchard 12103465f89SNicholas Piggin static unsigned long oops_begin(struct pt_regs *regs) 122760ca4dcSAnton Blanchard { 123760ca4dcSAnton Blanchard int cpu; 12434c2a14fSanton@samba.org unsigned long flags; 12514cf11afSPaul Mackerras 126293e4688Santon@samba.org oops_enter(); 127293e4688Santon@samba.org 128760ca4dcSAnton Blanchard /* racy, but better than risking deadlock. */ 129760ca4dcSAnton Blanchard raw_local_irq_save(flags); 130760ca4dcSAnton Blanchard cpu = smp_processor_id(); 131760ca4dcSAnton Blanchard if (!arch_spin_trylock(&die_lock)) { 132760ca4dcSAnton Blanchard if (cpu == die_owner) 133760ca4dcSAnton Blanchard /* nested oops. should stop eventually */; 134760ca4dcSAnton Blanchard else 135760ca4dcSAnton Blanchard arch_spin_lock(&die_lock); 136760ca4dcSAnton Blanchard } 137760ca4dcSAnton Blanchard die_nest_count++; 138760ca4dcSAnton Blanchard die_owner = cpu; 13914cf11afSPaul Mackerras console_verbose(); 14014cf11afSPaul Mackerras bust_spinlocks(1); 1416031d9d9Santon@samba.org if (machine_is(powermac)) 1426031d9d9Santon@samba.org pmac_backlight_unblank(); 143760ca4dcSAnton Blanchard return flags; 14434c2a14fSanton@samba.org } 14503465f89SNicholas Piggin NOKPROBE_SYMBOL(oops_begin); 1465474c120SMichael Hanselmann 14703465f89SNicholas Piggin static void oops_end(unsigned long flags, struct pt_regs *regs, 148760ca4dcSAnton Blanchard int signr) 149760ca4dcSAnton Blanchard { 15014cf11afSPaul Mackerras bust_spinlocks(0); 151373d4d09SRusty Russell add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE); 152760ca4dcSAnton Blanchard die_nest_count--; 15358154c8cSAnton Blanchard oops_exit(); 15458154c8cSAnton Blanchard printk("\n"); 1557458e8b2SNicholas Piggin if (!die_nest_count) { 156760ca4dcSAnton Blanchard /* Nest count reaches zero, release the lock. */ 1577458e8b2SNicholas Piggin die_owner = -1; 158760ca4dcSAnton Blanchard arch_spin_unlock(&die_lock); 1597458e8b2SNicholas Piggin } 160760ca4dcSAnton Blanchard raw_local_irq_restore(flags); 161cc532915SMichael Ellerman 162ebaeb5aeSMahesh Salgaonkar crash_fadump(regs, "die oops"); 163ebaeb5aeSMahesh Salgaonkar 1649b00ac06SAnton Blanchard /* 1659b00ac06SAnton Blanchard * A system reset (0x100) is a request to dump, so we always send 1669b00ac06SAnton Blanchard * it through the crashdump code. 1679b00ac06SAnton Blanchard */ 1689b00ac06SAnton Blanchard if (kexec_should_crash(current) || (TRAP(regs) == 0x100)) { 169cc532915SMichael Ellerman crash_kexec(regs); 1709b00ac06SAnton Blanchard 1719b00ac06SAnton Blanchard /* 1729b00ac06SAnton Blanchard * We aren't the primary crash CPU. We need to send it 1739b00ac06SAnton Blanchard * to a holding pattern to avoid it ending up in the panic 1749b00ac06SAnton Blanchard * code. 1759b00ac06SAnton Blanchard */ 176c0ce7d08SDavid Wilder crash_kexec_secondary(regs); 1779b00ac06SAnton Blanchard } 17814cf11afSPaul Mackerras 179760ca4dcSAnton Blanchard if (!signr) 180760ca4dcSAnton Blanchard return; 181760ca4dcSAnton Blanchard 18258154c8cSAnton Blanchard /* 18358154c8cSAnton Blanchard * While our oops output is serialised by a spinlock, output 18458154c8cSAnton Blanchard * from panic() called below can race and corrupt it. If we 18558154c8cSAnton Blanchard * know we are going to panic, delay for 1 second so we have a 18658154c8cSAnton Blanchard * chance to get clean backtraces from all CPUs that are oopsing. 18758154c8cSAnton Blanchard */ 18858154c8cSAnton Blanchard if (in_interrupt() || panic_on_oops || !current->pid || 18958154c8cSAnton Blanchard is_global_init(current)) { 19058154c8cSAnton Blanchard mdelay(MSEC_PER_SEC); 19158154c8cSAnton Blanchard } 19258154c8cSAnton Blanchard 19314cf11afSPaul Mackerras if (in_interrupt()) 19414cf11afSPaul Mackerras panic("Fatal exception in interrupt"); 195cea6a4baSHorms if (panic_on_oops) 196012c437dSHorms panic("Fatal exception"); 197760ca4dcSAnton Blanchard do_exit(signr); 198760ca4dcSAnton Blanchard } 19903465f89SNicholas Piggin NOKPROBE_SYMBOL(oops_end); 200cea6a4baSHorms 20103465f89SNicholas Piggin static int __die(const char *str, struct pt_regs *regs, long err) 202760ca4dcSAnton Blanchard { 203760ca4dcSAnton Blanchard printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter); 204760ca4dcSAnton Blanchard #ifdef CONFIG_PREEMPT 205760ca4dcSAnton Blanchard printk("PREEMPT "); 206760ca4dcSAnton Blanchard #endif 207760ca4dcSAnton Blanchard #ifdef CONFIG_SMP 208760ca4dcSAnton Blanchard printk("SMP NR_CPUS=%d ", NR_CPUS); 209760ca4dcSAnton Blanchard #endif 210e7df0d88SJoonsoo Kim if (debug_pagealloc_enabled()) 211760ca4dcSAnton Blanchard printk("DEBUG_PAGEALLOC "); 212760ca4dcSAnton Blanchard #ifdef CONFIG_NUMA 213760ca4dcSAnton Blanchard printk("NUMA "); 214760ca4dcSAnton Blanchard #endif 215760ca4dcSAnton Blanchard printk("%s\n", ppc_md.name ? ppc_md.name : ""); 216760ca4dcSAnton Blanchard 217760ca4dcSAnton Blanchard if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV) == NOTIFY_STOP) 218760ca4dcSAnton Blanchard return 1; 219760ca4dcSAnton Blanchard 220760ca4dcSAnton Blanchard print_modules(); 221760ca4dcSAnton Blanchard show_regs(regs); 22214cf11afSPaul Mackerras 22314cf11afSPaul Mackerras return 0; 22414cf11afSPaul Mackerras } 22503465f89SNicholas Piggin NOKPROBE_SYMBOL(__die); 22614cf11afSPaul Mackerras 227760ca4dcSAnton Blanchard void die(const char *str, struct pt_regs *regs, long err) 228760ca4dcSAnton Blanchard { 2296f44b20eSNicholas Piggin unsigned long flags; 230760ca4dcSAnton Blanchard 2316f44b20eSNicholas Piggin if (debugger(regs)) 2326f44b20eSNicholas Piggin return; 2336f44b20eSNicholas Piggin 2346f44b20eSNicholas Piggin flags = oops_begin(regs); 235760ca4dcSAnton Blanchard if (__die(str, regs, err)) 236760ca4dcSAnton Blanchard err = 0; 237760ca4dcSAnton Blanchard oops_end(flags, regs, err); 238760ca4dcSAnton Blanchard } 239760ca4dcSAnton Blanchard 24025baa35bSOleg Nesterov void user_single_step_siginfo(struct task_struct *tsk, 24125baa35bSOleg Nesterov struct pt_regs *regs, siginfo_t *info) 24225baa35bSOleg Nesterov { 24325baa35bSOleg Nesterov memset(info, 0, sizeof(*info)); 24425baa35bSOleg Nesterov info->si_signo = SIGTRAP; 24525baa35bSOleg Nesterov info->si_code = TRAP_TRACE; 24625baa35bSOleg Nesterov info->si_addr = (void __user *)regs->nip; 24725baa35bSOleg Nesterov } 24825baa35bSOleg Nesterov 24914cf11afSPaul Mackerras void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr) 25014cf11afSPaul Mackerras { 25114cf11afSPaul Mackerras siginfo_t info; 252d0c3d534SOlof Johansson const char fmt32[] = KERN_INFO "%s[%d]: unhandled signal %d " \ 253d0c3d534SOlof Johansson "at %08lx nip %08lx lr %08lx code %x\n"; 254d0c3d534SOlof Johansson const char fmt64[] = KERN_INFO "%s[%d]: unhandled signal %d " \ 255d0c3d534SOlof Johansson "at %016lx nip %016lx lr %016lx code %x\n"; 25614cf11afSPaul Mackerras 25714cf11afSPaul Mackerras if (!user_mode(regs)) { 258760ca4dcSAnton Blanchard die("Exception in kernel mode", regs, signr); 25914cf11afSPaul Mackerras return; 260760ca4dcSAnton Blanchard } 261760ca4dcSAnton Blanchard 262760ca4dcSAnton Blanchard if (show_unhandled_signals && unhandled_signal(current, signr)) { 26376462232SChristian Dietrich printk_ratelimited(regs->msr & MSR_64BIT ? fmt64 : fmt32, 264d0c3d534SOlof Johansson current->comm, current->pid, signr, 265d0c3d534SOlof Johansson addr, regs->nip, regs->link, code); 26614cf11afSPaul Mackerras } 26714cf11afSPaul Mackerras 268a3512b2dSBenjamin Herrenschmidt if (arch_irqs_disabled() && !arch_irq_disabled_regs(regs)) 2699f2f79e3SBenjamin Herrenschmidt local_irq_enable(); 2709f2f79e3SBenjamin Herrenschmidt 27141ab5266SAnanth N Mavinakayanahalli current->thread.trap_nr = code; 27214cf11afSPaul Mackerras memset(&info, 0, sizeof(info)); 27314cf11afSPaul Mackerras info.si_signo = signr; 27414cf11afSPaul Mackerras info.si_code = code; 27514cf11afSPaul Mackerras info.si_addr = (void __user *) addr; 27614cf11afSPaul Mackerras force_sig_info(signr, &info, current); 27714cf11afSPaul Mackerras } 27814cf11afSPaul Mackerras 27914cf11afSPaul Mackerras void system_reset_exception(struct pt_regs *regs) 28014cf11afSPaul Mackerras { 28114cf11afSPaul Mackerras /* See if any machine dependent calls */ 282c902be71SArnd Bergmann if (ppc_md.system_reset_exception) { 283c902be71SArnd Bergmann if (ppc_md.system_reset_exception(regs)) 284c902be71SArnd Bergmann return; 285c902be71SArnd Bergmann } 28614cf11afSPaul Mackerras 2878dad3f92SPaul Mackerras die("System Reset", regs, SIGABRT); 28814cf11afSPaul Mackerras 28914cf11afSPaul Mackerras /* Must die if the interrupt is not recoverable */ 29014cf11afSPaul Mackerras if (!(regs->msr & MSR_RI)) 29114cf11afSPaul Mackerras panic("Unrecoverable System Reset"); 29214cf11afSPaul Mackerras 29314cf11afSPaul Mackerras /* What should we do here? We could issue a shutdown or hard reset. */ 29414cf11afSPaul Mackerras } 2951e9b4507SMahesh Salgaonkar 296f307939fSChristophe Leroy #ifdef CONFIG_PPC64 2971e9b4507SMahesh Salgaonkar /* 2981e9b4507SMahesh Salgaonkar * This function is called in real mode. Strictly no printk's please. 2991e9b4507SMahesh Salgaonkar * 3001e9b4507SMahesh Salgaonkar * regs->nip and regs->msr contains srr0 and ssr1. 3011e9b4507SMahesh Salgaonkar */ 3021e9b4507SMahesh Salgaonkar long machine_check_early(struct pt_regs *regs) 3031e9b4507SMahesh Salgaonkar { 3044c703416SMahesh Salgaonkar long handled = 0; 3054c703416SMahesh Salgaonkar 30669111bacSChristoph Lameter __this_cpu_inc(irq_stat.mce_exceptions); 307e6654d5bSMahesh Salgaonkar 30827ea2c42SDaniel Axtens add_taint(TAINT_MACHINE_CHECK, LOCKDEP_NOW_UNRELIABLE); 30927ea2c42SDaniel Axtens 3104c703416SMahesh Salgaonkar if (cur_cpu_spec && cur_cpu_spec->machine_check_early) 3114c703416SMahesh Salgaonkar handled = cur_cpu_spec->machine_check_early(regs); 3124c703416SMahesh Salgaonkar return handled; 3131e9b4507SMahesh Salgaonkar } 3141e9b4507SMahesh Salgaonkar 3150869b6fdSMahesh Salgaonkar long hmi_exception_realmode(struct pt_regs *regs) 3160869b6fdSMahesh Salgaonkar { 31769111bacSChristoph Lameter __this_cpu_inc(irq_stat.hmi_exceptions); 3180869b6fdSMahesh Salgaonkar 319fd7bacbcSMahesh Salgaonkar wait_for_subcore_guest_exit(); 320fd7bacbcSMahesh Salgaonkar 3210869b6fdSMahesh Salgaonkar if (ppc_md.hmi_exception_early) 3220869b6fdSMahesh Salgaonkar ppc_md.hmi_exception_early(regs); 3230869b6fdSMahesh Salgaonkar 324fd7bacbcSMahesh Salgaonkar wait_for_tb_resync(); 325fd7bacbcSMahesh Salgaonkar 3260869b6fdSMahesh Salgaonkar return 0; 3270869b6fdSMahesh Salgaonkar } 3280869b6fdSMahesh Salgaonkar 32914cf11afSPaul Mackerras #endif 33014cf11afSPaul Mackerras 33114cf11afSPaul Mackerras /* 33214cf11afSPaul Mackerras * I/O accesses can cause machine checks on powermacs. 33314cf11afSPaul Mackerras * Check if the NIP corresponds to the address of a sync 33414cf11afSPaul Mackerras * instruction for which there is an entry in the exception 33514cf11afSPaul Mackerras * table. 33614cf11afSPaul Mackerras * Note that the 601 only takes a machine check on TEA 33714cf11afSPaul Mackerras * (transfer error ack) signal assertion, and does not 33814cf11afSPaul Mackerras * set any of the top 16 bits of SRR1. 33914cf11afSPaul Mackerras * -- paulus. 34014cf11afSPaul Mackerras */ 34114cf11afSPaul Mackerras static inline int check_io_access(struct pt_regs *regs) 34214cf11afSPaul Mackerras { 34368a64357SBenjamin Herrenschmidt #ifdef CONFIG_PPC32 34414cf11afSPaul Mackerras unsigned long msr = regs->msr; 34514cf11afSPaul Mackerras const struct exception_table_entry *entry; 34614cf11afSPaul Mackerras unsigned int *nip = (unsigned int *)regs->nip; 34714cf11afSPaul Mackerras 34814cf11afSPaul Mackerras if (((msr & 0xffff0000) == 0 || (msr & (0x80000 | 0x40000))) 34914cf11afSPaul Mackerras && (entry = search_exception_tables(regs->nip)) != NULL) { 35014cf11afSPaul Mackerras /* 35114cf11afSPaul Mackerras * Check that it's a sync instruction, or somewhere 35214cf11afSPaul Mackerras * in the twi; isync; nop sequence that inb/inw/inl uses. 35314cf11afSPaul Mackerras * As the address is in the exception table 35414cf11afSPaul Mackerras * we should be able to read the instr there. 35514cf11afSPaul Mackerras * For the debug message, we look at the preceding 35614cf11afSPaul Mackerras * load or store. 35714cf11afSPaul Mackerras */ 358ddc6cd0dSChristophe Leroy if (*nip == PPC_INST_NOP) 35914cf11afSPaul Mackerras nip -= 2; 360ddc6cd0dSChristophe Leroy else if (*nip == PPC_INST_ISYNC) 36114cf11afSPaul Mackerras --nip; 362ddc6cd0dSChristophe Leroy if (*nip == PPC_INST_SYNC || (*nip >> 26) == OP_TRAP) { 36314cf11afSPaul Mackerras unsigned int rb; 36414cf11afSPaul Mackerras 36514cf11afSPaul Mackerras --nip; 36614cf11afSPaul Mackerras rb = (*nip >> 11) & 0x1f; 36714cf11afSPaul Mackerras printk(KERN_DEBUG "%s bad port %lx at %p\n", 36814cf11afSPaul Mackerras (*nip & 0x100)? "OUT to": "IN from", 36914cf11afSPaul Mackerras regs->gpr[rb] - _IO_BASE, nip); 37014cf11afSPaul Mackerras regs->msr |= MSR_RI; 37161a92f70SNicholas Piggin regs->nip = extable_fixup(entry); 37214cf11afSPaul Mackerras return 1; 37314cf11afSPaul Mackerras } 37414cf11afSPaul Mackerras } 37568a64357SBenjamin Herrenschmidt #endif /* CONFIG_PPC32 */ 37614cf11afSPaul Mackerras return 0; 37714cf11afSPaul Mackerras } 37814cf11afSPaul Mackerras 379172ae2e7SDave Kleikamp #ifdef CONFIG_PPC_ADV_DEBUG_REGS 38014cf11afSPaul Mackerras /* On 4xx, the reason for the machine check or program exception 38114cf11afSPaul Mackerras is in the ESR. */ 38214cf11afSPaul Mackerras #define get_reason(regs) ((regs)->dsisr) 38314cf11afSPaul Mackerras #ifndef CONFIG_FSL_BOOKE 38414cf11afSPaul Mackerras #define get_mc_reason(regs) ((regs)->dsisr) 38514cf11afSPaul Mackerras #else 386fe04b112SScott Wood #define get_mc_reason(regs) (mfspr(SPRN_MCSR)) 38714cf11afSPaul Mackerras #endif 38814cf11afSPaul Mackerras #define REASON_FP ESR_FP 38914cf11afSPaul Mackerras #define REASON_ILLEGAL (ESR_PIL | ESR_PUO) 39014cf11afSPaul Mackerras #define REASON_PRIVILEGED ESR_PPR 39114cf11afSPaul Mackerras #define REASON_TRAP ESR_PTR 39214cf11afSPaul Mackerras 39314cf11afSPaul Mackerras /* single-step stuff */ 39451ae8d4aSBharat Bhushan #define single_stepping(regs) (current->thread.debug.dbcr0 & DBCR0_IC) 39551ae8d4aSBharat Bhushan #define clear_single_step(regs) (current->thread.debug.dbcr0 &= ~DBCR0_IC) 39614cf11afSPaul Mackerras 39714cf11afSPaul Mackerras #else 39814cf11afSPaul Mackerras /* On non-4xx, the reason for the machine check or program 39914cf11afSPaul Mackerras exception is in the MSR. */ 40014cf11afSPaul Mackerras #define get_reason(regs) ((regs)->msr) 40114cf11afSPaul Mackerras #define get_mc_reason(regs) ((regs)->msr) 4028b3c34cfSMichael Neuling #define REASON_TM 0x200000 40314cf11afSPaul Mackerras #define REASON_FP 0x100000 40414cf11afSPaul Mackerras #define REASON_ILLEGAL 0x80000 40514cf11afSPaul Mackerras #define REASON_PRIVILEGED 0x40000 40614cf11afSPaul Mackerras #define REASON_TRAP 0x20000 40714cf11afSPaul Mackerras 40814cf11afSPaul Mackerras #define single_stepping(regs) ((regs)->msr & MSR_SE) 40914cf11afSPaul Mackerras #define clear_single_step(regs) ((regs)->msr &= ~MSR_SE) 41014cf11afSPaul Mackerras #endif 41114cf11afSPaul Mackerras 41247c0bd1aSBenjamin Herrenschmidt #if defined(CONFIG_4xx) 41347c0bd1aSBenjamin Herrenschmidt int machine_check_4xx(struct pt_regs *regs) 41414cf11afSPaul Mackerras { 4151a6a4ffeSKumar Gala unsigned long reason = get_mc_reason(regs); 41614cf11afSPaul Mackerras 41714cf11afSPaul Mackerras if (reason & ESR_IMCP) { 41814cf11afSPaul Mackerras printk("Instruction"); 41914cf11afSPaul Mackerras mtspr(SPRN_ESR, reason & ~ESR_IMCP); 42014cf11afSPaul Mackerras } else 42114cf11afSPaul Mackerras printk("Data"); 42214cf11afSPaul Mackerras printk(" machine check in kernel mode.\n"); 42347c0bd1aSBenjamin Herrenschmidt 42447c0bd1aSBenjamin Herrenschmidt return 0; 42547c0bd1aSBenjamin Herrenschmidt } 42647c0bd1aSBenjamin Herrenschmidt 42747c0bd1aSBenjamin Herrenschmidt int machine_check_440A(struct pt_regs *regs) 42847c0bd1aSBenjamin Herrenschmidt { 42947c0bd1aSBenjamin Herrenschmidt unsigned long reason = get_mc_reason(regs); 43047c0bd1aSBenjamin Herrenschmidt 43114cf11afSPaul Mackerras printk("Machine check in kernel mode.\n"); 43214cf11afSPaul Mackerras if (reason & ESR_IMCP){ 43314cf11afSPaul Mackerras printk("Instruction Synchronous Machine Check exception\n"); 43414cf11afSPaul Mackerras mtspr(SPRN_ESR, reason & ~ESR_IMCP); 43514cf11afSPaul Mackerras } 43614cf11afSPaul Mackerras else { 43714cf11afSPaul Mackerras u32 mcsr = mfspr(SPRN_MCSR); 43814cf11afSPaul Mackerras if (mcsr & MCSR_IB) 43914cf11afSPaul Mackerras printk("Instruction Read PLB Error\n"); 44014cf11afSPaul Mackerras if (mcsr & MCSR_DRB) 44114cf11afSPaul Mackerras printk("Data Read PLB Error\n"); 44214cf11afSPaul Mackerras if (mcsr & MCSR_DWB) 44314cf11afSPaul Mackerras printk("Data Write PLB Error\n"); 44414cf11afSPaul Mackerras if (mcsr & MCSR_TLBP) 44514cf11afSPaul Mackerras printk("TLB Parity Error\n"); 44614cf11afSPaul Mackerras if (mcsr & MCSR_ICP){ 44714cf11afSPaul Mackerras flush_instruction_cache(); 44814cf11afSPaul Mackerras printk("I-Cache Parity Error\n"); 44914cf11afSPaul Mackerras } 45014cf11afSPaul Mackerras if (mcsr & MCSR_DCSP) 45114cf11afSPaul Mackerras printk("D-Cache Search Parity Error\n"); 45214cf11afSPaul Mackerras if (mcsr & MCSR_DCFP) 45314cf11afSPaul Mackerras printk("D-Cache Flush Parity Error\n"); 45414cf11afSPaul Mackerras if (mcsr & MCSR_IMPE) 45514cf11afSPaul Mackerras printk("Machine Check exception is imprecise\n"); 45614cf11afSPaul Mackerras 45714cf11afSPaul Mackerras /* Clear MCSR */ 45814cf11afSPaul Mackerras mtspr(SPRN_MCSR, mcsr); 45914cf11afSPaul Mackerras } 46047c0bd1aSBenjamin Herrenschmidt return 0; 46147c0bd1aSBenjamin Herrenschmidt } 462fc5e7097SDave Kleikamp 463fc5e7097SDave Kleikamp int machine_check_47x(struct pt_regs *regs) 464fc5e7097SDave Kleikamp { 465fc5e7097SDave Kleikamp unsigned long reason = get_mc_reason(regs); 466fc5e7097SDave Kleikamp u32 mcsr; 467fc5e7097SDave Kleikamp 468fc5e7097SDave Kleikamp printk(KERN_ERR "Machine check in kernel mode.\n"); 469fc5e7097SDave Kleikamp if (reason & ESR_IMCP) { 470fc5e7097SDave Kleikamp printk(KERN_ERR 471fc5e7097SDave Kleikamp "Instruction Synchronous Machine Check exception\n"); 472fc5e7097SDave Kleikamp mtspr(SPRN_ESR, reason & ~ESR_IMCP); 473fc5e7097SDave Kleikamp return 0; 474fc5e7097SDave Kleikamp } 475fc5e7097SDave Kleikamp mcsr = mfspr(SPRN_MCSR); 476fc5e7097SDave Kleikamp if (mcsr & MCSR_IB) 477fc5e7097SDave Kleikamp printk(KERN_ERR "Instruction Read PLB Error\n"); 478fc5e7097SDave Kleikamp if (mcsr & MCSR_DRB) 479fc5e7097SDave Kleikamp printk(KERN_ERR "Data Read PLB Error\n"); 480fc5e7097SDave Kleikamp if (mcsr & MCSR_DWB) 481fc5e7097SDave Kleikamp printk(KERN_ERR "Data Write PLB Error\n"); 482fc5e7097SDave Kleikamp if (mcsr & MCSR_TLBP) 483fc5e7097SDave Kleikamp printk(KERN_ERR "TLB Parity Error\n"); 484fc5e7097SDave Kleikamp if (mcsr & MCSR_ICP) { 485fc5e7097SDave Kleikamp flush_instruction_cache(); 486fc5e7097SDave Kleikamp printk(KERN_ERR "I-Cache Parity Error\n"); 487fc5e7097SDave Kleikamp } 488fc5e7097SDave Kleikamp if (mcsr & MCSR_DCSP) 489fc5e7097SDave Kleikamp printk(KERN_ERR "D-Cache Search Parity Error\n"); 490fc5e7097SDave Kleikamp if (mcsr & PPC47x_MCSR_GPR) 491fc5e7097SDave Kleikamp printk(KERN_ERR "GPR Parity Error\n"); 492fc5e7097SDave Kleikamp if (mcsr & PPC47x_MCSR_FPR) 493fc5e7097SDave Kleikamp printk(KERN_ERR "FPR Parity Error\n"); 494fc5e7097SDave Kleikamp if (mcsr & PPC47x_MCSR_IPR) 495fc5e7097SDave Kleikamp printk(KERN_ERR "Machine Check exception is imprecise\n"); 496fc5e7097SDave Kleikamp 497fc5e7097SDave Kleikamp /* Clear MCSR */ 498fc5e7097SDave Kleikamp mtspr(SPRN_MCSR, mcsr); 499fc5e7097SDave Kleikamp 500fc5e7097SDave Kleikamp return 0; 501fc5e7097SDave Kleikamp } 50214cf11afSPaul Mackerras #elif defined(CONFIG_E500) 503fe04b112SScott Wood int machine_check_e500mc(struct pt_regs *regs) 504fe04b112SScott Wood { 505fe04b112SScott Wood unsigned long mcsr = mfspr(SPRN_MCSR); 506fe04b112SScott Wood unsigned long reason = mcsr; 507fe04b112SScott Wood int recoverable = 1; 508fe04b112SScott Wood 50982a9a480SScott Wood if (reason & MCSR_LD) { 510cce1f106SShaohui Xie recoverable = fsl_rio_mcheck_exception(regs); 511cce1f106SShaohui Xie if (recoverable == 1) 512cce1f106SShaohui Xie goto silent_out; 513cce1f106SShaohui Xie } 514cce1f106SShaohui Xie 515fe04b112SScott Wood printk("Machine check in kernel mode.\n"); 516fe04b112SScott Wood printk("Caused by (from MCSR=%lx): ", reason); 517fe04b112SScott Wood 518fe04b112SScott Wood if (reason & MCSR_MCP) 519fe04b112SScott Wood printk("Machine Check Signal\n"); 520fe04b112SScott Wood 521fe04b112SScott Wood if (reason & MCSR_ICPERR) { 522fe04b112SScott Wood printk("Instruction Cache Parity Error\n"); 523fe04b112SScott Wood 524fe04b112SScott Wood /* 525fe04b112SScott Wood * This is recoverable by invalidating the i-cache. 526fe04b112SScott Wood */ 527fe04b112SScott Wood mtspr(SPRN_L1CSR1, mfspr(SPRN_L1CSR1) | L1CSR1_ICFI); 528fe04b112SScott Wood while (mfspr(SPRN_L1CSR1) & L1CSR1_ICFI) 529fe04b112SScott Wood ; 530fe04b112SScott Wood 531fe04b112SScott Wood /* 532fe04b112SScott Wood * This will generally be accompanied by an instruction 533fe04b112SScott Wood * fetch error report -- only treat MCSR_IF as fatal 534fe04b112SScott Wood * if it wasn't due to an L1 parity error. 535fe04b112SScott Wood */ 536fe04b112SScott Wood reason &= ~MCSR_IF; 537fe04b112SScott Wood } 538fe04b112SScott Wood 539fe04b112SScott Wood if (reason & MCSR_DCPERR_MC) { 540fe04b112SScott Wood printk("Data Cache Parity Error\n"); 54137caf9f2SKumar Gala 54237caf9f2SKumar Gala /* 54337caf9f2SKumar Gala * In write shadow mode we auto-recover from the error, but it 54437caf9f2SKumar Gala * may still get logged and cause a machine check. We should 54537caf9f2SKumar Gala * only treat the non-write shadow case as non-recoverable. 54637caf9f2SKumar Gala */ 54737caf9f2SKumar Gala if (!(mfspr(SPRN_L1CSR2) & L1CSR2_DCWS)) 548fe04b112SScott Wood recoverable = 0; 549fe04b112SScott Wood } 550fe04b112SScott Wood 551fe04b112SScott Wood if (reason & MCSR_L2MMU_MHIT) { 552fe04b112SScott Wood printk("Hit on multiple TLB entries\n"); 553fe04b112SScott Wood recoverable = 0; 554fe04b112SScott Wood } 555fe04b112SScott Wood 556fe04b112SScott Wood if (reason & MCSR_NMI) 557fe04b112SScott Wood printk("Non-maskable interrupt\n"); 558fe04b112SScott Wood 559fe04b112SScott Wood if (reason & MCSR_IF) { 560fe04b112SScott Wood printk("Instruction Fetch Error Report\n"); 561fe04b112SScott Wood recoverable = 0; 562fe04b112SScott Wood } 563fe04b112SScott Wood 564fe04b112SScott Wood if (reason & MCSR_LD) { 565fe04b112SScott Wood printk("Load Error Report\n"); 566fe04b112SScott Wood recoverable = 0; 567fe04b112SScott Wood } 568fe04b112SScott Wood 569fe04b112SScott Wood if (reason & MCSR_ST) { 570fe04b112SScott Wood printk("Store Error Report\n"); 571fe04b112SScott Wood recoverable = 0; 572fe04b112SScott Wood } 573fe04b112SScott Wood 574fe04b112SScott Wood if (reason & MCSR_LDG) { 575fe04b112SScott Wood printk("Guarded Load Error Report\n"); 576fe04b112SScott Wood recoverable = 0; 577fe04b112SScott Wood } 578fe04b112SScott Wood 579fe04b112SScott Wood if (reason & MCSR_TLBSYNC) 580fe04b112SScott Wood printk("Simultaneous tlbsync operations\n"); 581fe04b112SScott Wood 582fe04b112SScott Wood if (reason & MCSR_BSL2_ERR) { 583fe04b112SScott Wood printk("Level 2 Cache Error\n"); 584fe04b112SScott Wood recoverable = 0; 585fe04b112SScott Wood } 586fe04b112SScott Wood 587fe04b112SScott Wood if (reason & MCSR_MAV) { 588fe04b112SScott Wood u64 addr; 589fe04b112SScott Wood 590fe04b112SScott Wood addr = mfspr(SPRN_MCAR); 591fe04b112SScott Wood addr |= (u64)mfspr(SPRN_MCARU) << 32; 592fe04b112SScott Wood 593fe04b112SScott Wood printk("Machine Check %s Address: %#llx\n", 594fe04b112SScott Wood reason & MCSR_MEA ? "Effective" : "Physical", addr); 595fe04b112SScott Wood } 596fe04b112SScott Wood 597cce1f106SShaohui Xie silent_out: 598fe04b112SScott Wood mtspr(SPRN_MCSR, mcsr); 599fe04b112SScott Wood return mfspr(SPRN_MCSR) == 0 && recoverable; 600fe04b112SScott Wood } 601fe04b112SScott Wood 60247c0bd1aSBenjamin Herrenschmidt int machine_check_e500(struct pt_regs *regs) 60347c0bd1aSBenjamin Herrenschmidt { 60447c0bd1aSBenjamin Herrenschmidt unsigned long reason = get_mc_reason(regs); 60547c0bd1aSBenjamin Herrenschmidt 606cce1f106SShaohui Xie if (reason & MCSR_BUS_RBERR) { 607cce1f106SShaohui Xie if (fsl_rio_mcheck_exception(regs)) 608cce1f106SShaohui Xie return 1; 6094e0e3435SHongtao Jia if (fsl_pci_mcheck_exception(regs)) 6104e0e3435SHongtao Jia return 1; 611cce1f106SShaohui Xie } 612cce1f106SShaohui Xie 61314cf11afSPaul Mackerras printk("Machine check in kernel mode.\n"); 61414cf11afSPaul Mackerras printk("Caused by (from MCSR=%lx): ", reason); 61514cf11afSPaul Mackerras 61614cf11afSPaul Mackerras if (reason & MCSR_MCP) 61714cf11afSPaul Mackerras printk("Machine Check Signal\n"); 61814cf11afSPaul Mackerras if (reason & MCSR_ICPERR) 61914cf11afSPaul Mackerras printk("Instruction Cache Parity Error\n"); 62014cf11afSPaul Mackerras if (reason & MCSR_DCP_PERR) 62114cf11afSPaul Mackerras printk("Data Cache Push Parity Error\n"); 62214cf11afSPaul Mackerras if (reason & MCSR_DCPERR) 62314cf11afSPaul Mackerras printk("Data Cache Parity Error\n"); 62414cf11afSPaul Mackerras if (reason & MCSR_BUS_IAERR) 62514cf11afSPaul Mackerras printk("Bus - Instruction Address Error\n"); 62614cf11afSPaul Mackerras if (reason & MCSR_BUS_RAERR) 62714cf11afSPaul Mackerras printk("Bus - Read Address Error\n"); 62814cf11afSPaul Mackerras if (reason & MCSR_BUS_WAERR) 62914cf11afSPaul Mackerras printk("Bus - Write Address Error\n"); 63014cf11afSPaul Mackerras if (reason & MCSR_BUS_IBERR) 63114cf11afSPaul Mackerras printk("Bus - Instruction Data Error\n"); 63214cf11afSPaul Mackerras if (reason & MCSR_BUS_RBERR) 63314cf11afSPaul Mackerras printk("Bus - Read Data Bus Error\n"); 63414cf11afSPaul Mackerras if (reason & MCSR_BUS_WBERR) 635c1528339SWladislav Wiebe printk("Bus - Write Data Bus Error\n"); 63614cf11afSPaul Mackerras if (reason & MCSR_BUS_IPERR) 63714cf11afSPaul Mackerras printk("Bus - Instruction Parity Error\n"); 63814cf11afSPaul Mackerras if (reason & MCSR_BUS_RPERR) 63914cf11afSPaul Mackerras printk("Bus - Read Parity Error\n"); 64047c0bd1aSBenjamin Herrenschmidt 64147c0bd1aSBenjamin Herrenschmidt return 0; 64247c0bd1aSBenjamin Herrenschmidt } 6434490c06bSKumar Gala 6444490c06bSKumar Gala int machine_check_generic(struct pt_regs *regs) 6454490c06bSKumar Gala { 6464490c06bSKumar Gala return 0; 6474490c06bSKumar Gala } 64814cf11afSPaul Mackerras #elif defined(CONFIG_E200) 64947c0bd1aSBenjamin Herrenschmidt int machine_check_e200(struct pt_regs *regs) 65047c0bd1aSBenjamin Herrenschmidt { 65147c0bd1aSBenjamin Herrenschmidt unsigned long reason = get_mc_reason(regs); 65247c0bd1aSBenjamin Herrenschmidt 65314cf11afSPaul Mackerras printk("Machine check in kernel mode.\n"); 65414cf11afSPaul Mackerras printk("Caused by (from MCSR=%lx): ", reason); 65514cf11afSPaul Mackerras 65614cf11afSPaul Mackerras if (reason & MCSR_MCP) 65714cf11afSPaul Mackerras printk("Machine Check Signal\n"); 65814cf11afSPaul Mackerras if (reason & MCSR_CP_PERR) 65914cf11afSPaul Mackerras printk("Cache Push Parity Error\n"); 66014cf11afSPaul Mackerras if (reason & MCSR_CPERR) 66114cf11afSPaul Mackerras printk("Cache Parity Error\n"); 66214cf11afSPaul Mackerras if (reason & MCSR_EXCP_ERR) 66314cf11afSPaul Mackerras printk("ISI, ITLB, or Bus Error on first instruction fetch for an exception handler\n"); 66414cf11afSPaul Mackerras if (reason & MCSR_BUS_IRERR) 66514cf11afSPaul Mackerras printk("Bus - Read Bus Error on instruction fetch\n"); 66614cf11afSPaul Mackerras if (reason & MCSR_BUS_DRERR) 66714cf11afSPaul Mackerras printk("Bus - Read Bus Error on data load\n"); 66814cf11afSPaul Mackerras if (reason & MCSR_BUS_WRERR) 66914cf11afSPaul Mackerras printk("Bus - Write Bus Error on buffered store or cache line push\n"); 67047c0bd1aSBenjamin Herrenschmidt 67147c0bd1aSBenjamin Herrenschmidt return 0; 67247c0bd1aSBenjamin Herrenschmidt } 673e627f8dcSChristophe Leroy #elif defined(CONFIG_PPC_8xx) 674e627f8dcSChristophe Leroy int machine_check_8xx(struct pt_regs *regs) 675e627f8dcSChristophe Leroy { 676e627f8dcSChristophe Leroy unsigned long reason = get_mc_reason(regs); 677e627f8dcSChristophe Leroy 678e627f8dcSChristophe Leroy pr_err("Machine check in kernel mode.\n"); 679e627f8dcSChristophe Leroy pr_err("Caused by (from SRR1=%lx): ", reason); 680e627f8dcSChristophe Leroy if (reason & 0x40000000) 681e627f8dcSChristophe Leroy pr_err("Fetch error at address %lx\n", regs->nip); 682e627f8dcSChristophe Leroy else 683e627f8dcSChristophe Leroy pr_err("Data access error at address %lx\n", regs->dar); 684e627f8dcSChristophe Leroy 685e627f8dcSChristophe Leroy #ifdef CONFIG_PCI 686e627f8dcSChristophe Leroy /* the qspan pci read routines can cause machine checks -- Cort 687e627f8dcSChristophe Leroy * 688e627f8dcSChristophe Leroy * yuck !!! that totally needs to go away ! There are better ways 689e627f8dcSChristophe Leroy * to deal with that than having a wart in the mcheck handler. 690e627f8dcSChristophe Leroy * -- BenH 691e627f8dcSChristophe Leroy */ 692e627f8dcSChristophe Leroy bad_page_fault(regs, regs->dar, SIGBUS); 693e627f8dcSChristophe Leroy return 1; 694e627f8dcSChristophe Leroy #else 695e627f8dcSChristophe Leroy return 0; 696e627f8dcSChristophe Leroy #endif 697e627f8dcSChristophe Leroy } 69847c0bd1aSBenjamin Herrenschmidt #else 69947c0bd1aSBenjamin Herrenschmidt int machine_check_generic(struct pt_regs *regs) 70047c0bd1aSBenjamin Herrenschmidt { 70147c0bd1aSBenjamin Herrenschmidt unsigned long reason = get_mc_reason(regs); 70247c0bd1aSBenjamin Herrenschmidt 70314cf11afSPaul Mackerras printk("Machine check in kernel mode.\n"); 70414cf11afSPaul Mackerras printk("Caused by (from SRR1=%lx): ", reason); 70514cf11afSPaul Mackerras switch (reason & 0x601F0000) { 70614cf11afSPaul Mackerras case 0x80000: 70714cf11afSPaul Mackerras printk("Machine check signal\n"); 70814cf11afSPaul Mackerras break; 70914cf11afSPaul Mackerras case 0: /* for 601 */ 71014cf11afSPaul Mackerras case 0x40000: 71114cf11afSPaul Mackerras case 0x140000: /* 7450 MSS error and TEA */ 71214cf11afSPaul Mackerras printk("Transfer error ack signal\n"); 71314cf11afSPaul Mackerras break; 71414cf11afSPaul Mackerras case 0x20000: 71514cf11afSPaul Mackerras printk("Data parity error signal\n"); 71614cf11afSPaul Mackerras break; 71714cf11afSPaul Mackerras case 0x10000: 71814cf11afSPaul Mackerras printk("Address parity error signal\n"); 71914cf11afSPaul Mackerras break; 72014cf11afSPaul Mackerras case 0x20000000: 72114cf11afSPaul Mackerras printk("L1 Data Cache error\n"); 72214cf11afSPaul Mackerras break; 72314cf11afSPaul Mackerras case 0x40000000: 72414cf11afSPaul Mackerras printk("L1 Instruction Cache error\n"); 72514cf11afSPaul Mackerras break; 72614cf11afSPaul Mackerras case 0x00100000: 72714cf11afSPaul Mackerras printk("L2 data cache parity error\n"); 72814cf11afSPaul Mackerras break; 72914cf11afSPaul Mackerras default: 73014cf11afSPaul Mackerras printk("Unknown values in msr\n"); 73114cf11afSPaul Mackerras } 73275918a4bSOlof Johansson return 0; 73375918a4bSOlof Johansson } 73447c0bd1aSBenjamin Herrenschmidt #endif /* everything else */ 73575918a4bSOlof Johansson 73675918a4bSOlof Johansson void machine_check_exception(struct pt_regs *regs) 73775918a4bSOlof Johansson { 738ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 73975918a4bSOlof Johansson int recover = 0; 74075918a4bSOlof Johansson 74169111bacSChristoph Lameter __this_cpu_inc(irq_stat.mce_exceptions); 74289713ed1SAnton Blanchard 74347c0bd1aSBenjamin Herrenschmidt /* See if any machine dependent calls. In theory, we would want 74447c0bd1aSBenjamin Herrenschmidt * to call the CPU first, and call the ppc_md. one if the CPU 74547c0bd1aSBenjamin Herrenschmidt * one returns a positive number. However there is existing code 74647c0bd1aSBenjamin Herrenschmidt * that assumes the board gets a first chance, so let's keep it 74747c0bd1aSBenjamin Herrenschmidt * that way for now and fix things later. --BenH. 74847c0bd1aSBenjamin Herrenschmidt */ 74975918a4bSOlof Johansson if (ppc_md.machine_check_exception) 75075918a4bSOlof Johansson recover = ppc_md.machine_check_exception(regs); 75147c0bd1aSBenjamin Herrenschmidt else if (cur_cpu_spec->machine_check) 75247c0bd1aSBenjamin Herrenschmidt recover = cur_cpu_spec->machine_check(regs); 75375918a4bSOlof Johansson 75447c0bd1aSBenjamin Herrenschmidt if (recover > 0) 755ba12eedeSLi Zhong goto bail; 75675918a4bSOlof Johansson 757a443506bSAnton Blanchard if (debugger_fault_handler(regs)) 758ba12eedeSLi Zhong goto bail; 75975918a4bSOlof Johansson 76075918a4bSOlof Johansson if (check_io_access(regs)) 761ba12eedeSLi Zhong goto bail; 76275918a4bSOlof Johansson 7638dad3f92SPaul Mackerras die("Machine check", regs, SIGBUS); 76414cf11afSPaul Mackerras 76514cf11afSPaul Mackerras /* Must die if the interrupt is not recoverable */ 76614cf11afSPaul Mackerras if (!(regs->msr & MSR_RI)) 76714cf11afSPaul Mackerras panic("Unrecoverable Machine check"); 768ba12eedeSLi Zhong 769ba12eedeSLi Zhong bail: 770ba12eedeSLi Zhong exception_exit(prev_state); 77114cf11afSPaul Mackerras } 77214cf11afSPaul Mackerras 77314cf11afSPaul Mackerras void SMIException(struct pt_regs *regs) 77414cf11afSPaul Mackerras { 77514cf11afSPaul Mackerras die("System Management Interrupt", regs, SIGABRT); 77614cf11afSPaul Mackerras } 77714cf11afSPaul Mackerras 7780869b6fdSMahesh Salgaonkar void handle_hmi_exception(struct pt_regs *regs) 7790869b6fdSMahesh Salgaonkar { 7800869b6fdSMahesh Salgaonkar struct pt_regs *old_regs; 7810869b6fdSMahesh Salgaonkar 7820869b6fdSMahesh Salgaonkar old_regs = set_irq_regs(regs); 7830869b6fdSMahesh Salgaonkar irq_enter(); 7840869b6fdSMahesh Salgaonkar 7850869b6fdSMahesh Salgaonkar if (ppc_md.handle_hmi_exception) 7860869b6fdSMahesh Salgaonkar ppc_md.handle_hmi_exception(regs); 7870869b6fdSMahesh Salgaonkar 7880869b6fdSMahesh Salgaonkar irq_exit(); 7890869b6fdSMahesh Salgaonkar set_irq_regs(old_regs); 7900869b6fdSMahesh Salgaonkar } 7910869b6fdSMahesh Salgaonkar 792dc1c1ca3SStephen Rothwell void unknown_exception(struct pt_regs *regs) 79314cf11afSPaul Mackerras { 794ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 795ba12eedeSLi Zhong 79614cf11afSPaul Mackerras printk("Bad trap at PC: %lx, SR: %lx, vector=%lx\n", 79714cf11afSPaul Mackerras regs->nip, regs->msr, regs->trap); 79814cf11afSPaul Mackerras 79914cf11afSPaul Mackerras _exception(SIGTRAP, regs, 0, 0); 800ba12eedeSLi Zhong 801ba12eedeSLi Zhong exception_exit(prev_state); 80214cf11afSPaul Mackerras } 80314cf11afSPaul Mackerras 804dc1c1ca3SStephen Rothwell void instruction_breakpoint_exception(struct pt_regs *regs) 80514cf11afSPaul Mackerras { 806ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 807ba12eedeSLi Zhong 80814cf11afSPaul Mackerras if (notify_die(DIE_IABR_MATCH, "iabr_match", regs, 5, 80914cf11afSPaul Mackerras 5, SIGTRAP) == NOTIFY_STOP) 810ba12eedeSLi Zhong goto bail; 81114cf11afSPaul Mackerras if (debugger_iabr_match(regs)) 812ba12eedeSLi Zhong goto bail; 81314cf11afSPaul Mackerras _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip); 814ba12eedeSLi Zhong 815ba12eedeSLi Zhong bail: 816ba12eedeSLi Zhong exception_exit(prev_state); 81714cf11afSPaul Mackerras } 81814cf11afSPaul Mackerras 81914cf11afSPaul Mackerras void RunModeException(struct pt_regs *regs) 82014cf11afSPaul Mackerras { 82114cf11afSPaul Mackerras _exception(SIGTRAP, regs, 0, 0); 82214cf11afSPaul Mackerras } 82314cf11afSPaul Mackerras 82403465f89SNicholas Piggin void single_step_exception(struct pt_regs *regs) 82514cf11afSPaul Mackerras { 826ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 827ba12eedeSLi Zhong 8282538c2d0SK.Prasad clear_single_step(regs); 82914cf11afSPaul Mackerras 830*6cc89badSNaveen N. Rao if (kprobe_post_handler(regs)) 831*6cc89badSNaveen N. Rao return; 832*6cc89badSNaveen N. Rao 83314cf11afSPaul Mackerras if (notify_die(DIE_SSTEP, "single_step", regs, 5, 83414cf11afSPaul Mackerras 5, SIGTRAP) == NOTIFY_STOP) 835ba12eedeSLi Zhong goto bail; 83614cf11afSPaul Mackerras if (debugger_sstep(regs)) 837ba12eedeSLi Zhong goto bail; 83814cf11afSPaul Mackerras 83914cf11afSPaul Mackerras _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip); 840ba12eedeSLi Zhong 841ba12eedeSLi Zhong bail: 842ba12eedeSLi Zhong exception_exit(prev_state); 84314cf11afSPaul Mackerras } 84403465f89SNicholas Piggin NOKPROBE_SYMBOL(single_step_exception); 84514cf11afSPaul Mackerras 84614cf11afSPaul Mackerras /* 84714cf11afSPaul Mackerras * After we have successfully emulated an instruction, we have to 84814cf11afSPaul Mackerras * check if the instruction was being single-stepped, and if so, 84914cf11afSPaul Mackerras * pretend we got a single-step exception. This was pointed out 85014cf11afSPaul Mackerras * by Kumar Gala. -- paulus 85114cf11afSPaul Mackerras */ 8528dad3f92SPaul Mackerras static void emulate_single_step(struct pt_regs *regs) 85314cf11afSPaul Mackerras { 8542538c2d0SK.Prasad if (single_stepping(regs)) 8552538c2d0SK.Prasad single_step_exception(regs); 85614cf11afSPaul Mackerras } 85714cf11afSPaul Mackerras 8585fad293bSKumar Gala static inline int __parse_fpscr(unsigned long fpscr) 859dc1c1ca3SStephen Rothwell { 8605fad293bSKumar Gala int ret = 0; 861dc1c1ca3SStephen Rothwell 862dc1c1ca3SStephen Rothwell /* Invalid operation */ 863dc1c1ca3SStephen Rothwell if ((fpscr & FPSCR_VE) && (fpscr & FPSCR_VX)) 8645fad293bSKumar Gala ret = FPE_FLTINV; 865dc1c1ca3SStephen Rothwell 866dc1c1ca3SStephen Rothwell /* Overflow */ 867dc1c1ca3SStephen Rothwell else if ((fpscr & FPSCR_OE) && (fpscr & FPSCR_OX)) 8685fad293bSKumar Gala ret = FPE_FLTOVF; 869dc1c1ca3SStephen Rothwell 870dc1c1ca3SStephen Rothwell /* Underflow */ 871dc1c1ca3SStephen Rothwell else if ((fpscr & FPSCR_UE) && (fpscr & FPSCR_UX)) 8725fad293bSKumar Gala ret = FPE_FLTUND; 873dc1c1ca3SStephen Rothwell 874dc1c1ca3SStephen Rothwell /* Divide by zero */ 875dc1c1ca3SStephen Rothwell else if ((fpscr & FPSCR_ZE) && (fpscr & FPSCR_ZX)) 8765fad293bSKumar Gala ret = FPE_FLTDIV; 877dc1c1ca3SStephen Rothwell 878dc1c1ca3SStephen Rothwell /* Inexact result */ 879dc1c1ca3SStephen Rothwell else if ((fpscr & FPSCR_XE) && (fpscr & FPSCR_XX)) 8805fad293bSKumar Gala ret = FPE_FLTRES; 8815fad293bSKumar Gala 8825fad293bSKumar Gala return ret; 8835fad293bSKumar Gala } 8845fad293bSKumar Gala 8855fad293bSKumar Gala static void parse_fpe(struct pt_regs *regs) 8865fad293bSKumar Gala { 8875fad293bSKumar Gala int code = 0; 8885fad293bSKumar Gala 8895fad293bSKumar Gala flush_fp_to_thread(current); 8905fad293bSKumar Gala 891de79f7b9SPaul Mackerras code = __parse_fpscr(current->thread.fp_state.fpscr); 892dc1c1ca3SStephen Rothwell 893dc1c1ca3SStephen Rothwell _exception(SIGFPE, regs, code, regs->nip); 894dc1c1ca3SStephen Rothwell } 895dc1c1ca3SStephen Rothwell 896dc1c1ca3SStephen Rothwell /* 897dc1c1ca3SStephen Rothwell * Illegal instruction emulation support. Originally written to 89814cf11afSPaul Mackerras * provide the PVR to user applications using the mfspr rd, PVR. 89914cf11afSPaul Mackerras * Return non-zero if we can't emulate, or -EFAULT if the associated 90014cf11afSPaul Mackerras * memory access caused an access fault. Return zero on success. 90114cf11afSPaul Mackerras * 90214cf11afSPaul Mackerras * There are a couple of ways to do this, either "decode" the instruction 90314cf11afSPaul Mackerras * or directly match lots of bits. In this case, matching lots of 90414cf11afSPaul Mackerras * bits is faster and easier. 90586417780SPaul Mackerras * 90614cf11afSPaul Mackerras */ 90714cf11afSPaul Mackerras static int emulate_string_inst(struct pt_regs *regs, u32 instword) 90814cf11afSPaul Mackerras { 90914cf11afSPaul Mackerras u8 rT = (instword >> 21) & 0x1f; 91014cf11afSPaul Mackerras u8 rA = (instword >> 16) & 0x1f; 91114cf11afSPaul Mackerras u8 NB_RB = (instword >> 11) & 0x1f; 91214cf11afSPaul Mackerras u32 num_bytes; 91314cf11afSPaul Mackerras unsigned long EA; 91414cf11afSPaul Mackerras int pos = 0; 91514cf11afSPaul Mackerras 91614cf11afSPaul Mackerras /* Early out if we are an invalid form of lswx */ 91716c57b36SKumar Gala if ((instword & PPC_INST_STRING_MASK) == PPC_INST_LSWX) 91814cf11afSPaul Mackerras if ((rT == rA) || (rT == NB_RB)) 91914cf11afSPaul Mackerras return -EINVAL; 92014cf11afSPaul Mackerras 92114cf11afSPaul Mackerras EA = (rA == 0) ? 0 : regs->gpr[rA]; 92214cf11afSPaul Mackerras 92316c57b36SKumar Gala switch (instword & PPC_INST_STRING_MASK) { 92416c57b36SKumar Gala case PPC_INST_LSWX: 92516c57b36SKumar Gala case PPC_INST_STSWX: 92614cf11afSPaul Mackerras EA += NB_RB; 92714cf11afSPaul Mackerras num_bytes = regs->xer & 0x7f; 92814cf11afSPaul Mackerras break; 92916c57b36SKumar Gala case PPC_INST_LSWI: 93016c57b36SKumar Gala case PPC_INST_STSWI: 93114cf11afSPaul Mackerras num_bytes = (NB_RB == 0) ? 32 : NB_RB; 93214cf11afSPaul Mackerras break; 93314cf11afSPaul Mackerras default: 93414cf11afSPaul Mackerras return -EINVAL; 93514cf11afSPaul Mackerras } 93614cf11afSPaul Mackerras 93714cf11afSPaul Mackerras while (num_bytes != 0) 93814cf11afSPaul Mackerras { 93914cf11afSPaul Mackerras u8 val; 94014cf11afSPaul Mackerras u32 shift = 8 * (3 - (pos & 0x3)); 94114cf11afSPaul Mackerras 94280aa0fb4SJames Yang /* if process is 32-bit, clear upper 32 bits of EA */ 94380aa0fb4SJames Yang if ((regs->msr & MSR_64BIT) == 0) 94480aa0fb4SJames Yang EA &= 0xFFFFFFFF; 94580aa0fb4SJames Yang 94616c57b36SKumar Gala switch ((instword & PPC_INST_STRING_MASK)) { 94716c57b36SKumar Gala case PPC_INST_LSWX: 94816c57b36SKumar Gala case PPC_INST_LSWI: 94914cf11afSPaul Mackerras if (get_user(val, (u8 __user *)EA)) 95014cf11afSPaul Mackerras return -EFAULT; 95114cf11afSPaul Mackerras /* first time updating this reg, 95214cf11afSPaul Mackerras * zero it out */ 95314cf11afSPaul Mackerras if (pos == 0) 95414cf11afSPaul Mackerras regs->gpr[rT] = 0; 95514cf11afSPaul Mackerras regs->gpr[rT] |= val << shift; 95614cf11afSPaul Mackerras break; 95716c57b36SKumar Gala case PPC_INST_STSWI: 95816c57b36SKumar Gala case PPC_INST_STSWX: 95914cf11afSPaul Mackerras val = regs->gpr[rT] >> shift; 96014cf11afSPaul Mackerras if (put_user(val, (u8 __user *)EA)) 96114cf11afSPaul Mackerras return -EFAULT; 96214cf11afSPaul Mackerras break; 96314cf11afSPaul Mackerras } 96414cf11afSPaul Mackerras /* move EA to next address */ 96514cf11afSPaul Mackerras EA += 1; 96614cf11afSPaul Mackerras num_bytes--; 96714cf11afSPaul Mackerras 96814cf11afSPaul Mackerras /* manage our position within the register */ 96914cf11afSPaul Mackerras if (++pos == 4) { 97014cf11afSPaul Mackerras pos = 0; 97114cf11afSPaul Mackerras if (++rT == 32) 97214cf11afSPaul Mackerras rT = 0; 97314cf11afSPaul Mackerras } 97414cf11afSPaul Mackerras } 97514cf11afSPaul Mackerras 97614cf11afSPaul Mackerras return 0; 97714cf11afSPaul Mackerras } 97814cf11afSPaul Mackerras 979c3412dcbSWill Schmidt static int emulate_popcntb_inst(struct pt_regs *regs, u32 instword) 980c3412dcbSWill Schmidt { 981c3412dcbSWill Schmidt u32 ra,rs; 982c3412dcbSWill Schmidt unsigned long tmp; 983c3412dcbSWill Schmidt 984c3412dcbSWill Schmidt ra = (instword >> 16) & 0x1f; 985c3412dcbSWill Schmidt rs = (instword >> 21) & 0x1f; 986c3412dcbSWill Schmidt 987c3412dcbSWill Schmidt tmp = regs->gpr[rs]; 988c3412dcbSWill Schmidt tmp = tmp - ((tmp >> 1) & 0x5555555555555555ULL); 989c3412dcbSWill Schmidt tmp = (tmp & 0x3333333333333333ULL) + ((tmp >> 2) & 0x3333333333333333ULL); 990c3412dcbSWill Schmidt tmp = (tmp + (tmp >> 4)) & 0x0f0f0f0f0f0f0f0fULL; 991c3412dcbSWill Schmidt regs->gpr[ra] = tmp; 992c3412dcbSWill Schmidt 993c3412dcbSWill Schmidt return 0; 994c3412dcbSWill Schmidt } 995c3412dcbSWill Schmidt 996c1469f13SKumar Gala static int emulate_isel(struct pt_regs *regs, u32 instword) 997c1469f13SKumar Gala { 998c1469f13SKumar Gala u8 rT = (instword >> 21) & 0x1f; 999c1469f13SKumar Gala u8 rA = (instword >> 16) & 0x1f; 1000c1469f13SKumar Gala u8 rB = (instword >> 11) & 0x1f; 1001c1469f13SKumar Gala u8 BC = (instword >> 6) & 0x1f; 1002c1469f13SKumar Gala u8 bit; 1003c1469f13SKumar Gala unsigned long tmp; 1004c1469f13SKumar Gala 1005c1469f13SKumar Gala tmp = (rA == 0) ? 0 : regs->gpr[rA]; 1006c1469f13SKumar Gala bit = (regs->ccr >> (31 - BC)) & 0x1; 1007c1469f13SKumar Gala 1008c1469f13SKumar Gala regs->gpr[rT] = bit ? tmp : regs->gpr[rB]; 1009c1469f13SKumar Gala 1010c1469f13SKumar Gala return 0; 1011c1469f13SKumar Gala } 1012c1469f13SKumar Gala 10136ce6c629SMichael Neuling #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 10146ce6c629SMichael Neuling static inline bool tm_abort_check(struct pt_regs *regs, int cause) 10156ce6c629SMichael Neuling { 10166ce6c629SMichael Neuling /* If we're emulating a load/store in an active transaction, we cannot 10176ce6c629SMichael Neuling * emulate it as the kernel operates in transaction suspended context. 10186ce6c629SMichael Neuling * We need to abort the transaction. This creates a persistent TM 10196ce6c629SMichael Neuling * abort so tell the user what caused it with a new code. 10206ce6c629SMichael Neuling */ 10216ce6c629SMichael Neuling if (MSR_TM_TRANSACTIONAL(regs->msr)) { 10226ce6c629SMichael Neuling tm_enable(); 10236ce6c629SMichael Neuling tm_abort(cause); 10246ce6c629SMichael Neuling return true; 10256ce6c629SMichael Neuling } 10266ce6c629SMichael Neuling return false; 10276ce6c629SMichael Neuling } 10286ce6c629SMichael Neuling #else 10296ce6c629SMichael Neuling static inline bool tm_abort_check(struct pt_regs *regs, int reason) 10306ce6c629SMichael Neuling { 10316ce6c629SMichael Neuling return false; 10326ce6c629SMichael Neuling } 10336ce6c629SMichael Neuling #endif 10346ce6c629SMichael Neuling 103514cf11afSPaul Mackerras static int emulate_instruction(struct pt_regs *regs) 103614cf11afSPaul Mackerras { 103714cf11afSPaul Mackerras u32 instword; 103814cf11afSPaul Mackerras u32 rd; 103914cf11afSPaul Mackerras 10404288e343SAnton Blanchard if (!user_mode(regs)) 104114cf11afSPaul Mackerras return -EINVAL; 104214cf11afSPaul Mackerras CHECK_FULL_REGS(regs); 104314cf11afSPaul Mackerras 104414cf11afSPaul Mackerras if (get_user(instword, (u32 __user *)(regs->nip))) 104514cf11afSPaul Mackerras return -EFAULT; 104614cf11afSPaul Mackerras 104714cf11afSPaul Mackerras /* Emulate the mfspr rD, PVR. */ 104816c57b36SKumar Gala if ((instword & PPC_INST_MFSPR_PVR_MASK) == PPC_INST_MFSPR_PVR) { 1049eecff81dSAnton Blanchard PPC_WARN_EMULATED(mfpvr, regs); 105014cf11afSPaul Mackerras rd = (instword >> 21) & 0x1f; 105114cf11afSPaul Mackerras regs->gpr[rd] = mfspr(SPRN_PVR); 105214cf11afSPaul Mackerras return 0; 105314cf11afSPaul Mackerras } 105414cf11afSPaul Mackerras 105514cf11afSPaul Mackerras /* Emulating the dcba insn is just a no-op. */ 105680947e7cSGeert Uytterhoeven if ((instword & PPC_INST_DCBA_MASK) == PPC_INST_DCBA) { 1057eecff81dSAnton Blanchard PPC_WARN_EMULATED(dcba, regs); 105814cf11afSPaul Mackerras return 0; 105980947e7cSGeert Uytterhoeven } 106014cf11afSPaul Mackerras 106114cf11afSPaul Mackerras /* Emulate the mcrxr insn. */ 106216c57b36SKumar Gala if ((instword & PPC_INST_MCRXR_MASK) == PPC_INST_MCRXR) { 106386417780SPaul Mackerras int shift = (instword >> 21) & 0x1c; 106414cf11afSPaul Mackerras unsigned long msk = 0xf0000000UL >> shift; 106514cf11afSPaul Mackerras 1066eecff81dSAnton Blanchard PPC_WARN_EMULATED(mcrxr, regs); 106714cf11afSPaul Mackerras regs->ccr = (regs->ccr & ~msk) | ((regs->xer >> shift) & msk); 106814cf11afSPaul Mackerras regs->xer &= ~0xf0000000UL; 106914cf11afSPaul Mackerras return 0; 107014cf11afSPaul Mackerras } 107114cf11afSPaul Mackerras 107214cf11afSPaul Mackerras /* Emulate load/store string insn. */ 107380947e7cSGeert Uytterhoeven if ((instword & PPC_INST_STRING_GEN_MASK) == PPC_INST_STRING) { 10746ce6c629SMichael Neuling if (tm_abort_check(regs, 10756ce6c629SMichael Neuling TM_CAUSE_EMULATE | TM_CAUSE_PERSISTENT)) 10766ce6c629SMichael Neuling return -EINVAL; 1077eecff81dSAnton Blanchard PPC_WARN_EMULATED(string, regs); 107814cf11afSPaul Mackerras return emulate_string_inst(regs, instword); 107980947e7cSGeert Uytterhoeven } 108014cf11afSPaul Mackerras 1081c3412dcbSWill Schmidt /* Emulate the popcntb (Population Count Bytes) instruction. */ 108216c57b36SKumar Gala if ((instword & PPC_INST_POPCNTB_MASK) == PPC_INST_POPCNTB) { 1083eecff81dSAnton Blanchard PPC_WARN_EMULATED(popcntb, regs); 1084c3412dcbSWill Schmidt return emulate_popcntb_inst(regs, instword); 1085c3412dcbSWill Schmidt } 1086c3412dcbSWill Schmidt 1087c1469f13SKumar Gala /* Emulate isel (Integer Select) instruction */ 108816c57b36SKumar Gala if ((instword & PPC_INST_ISEL_MASK) == PPC_INST_ISEL) { 1089eecff81dSAnton Blanchard PPC_WARN_EMULATED(isel, regs); 1090c1469f13SKumar Gala return emulate_isel(regs, instword); 1091c1469f13SKumar Gala } 1092c1469f13SKumar Gala 10939863c28aSJames Yang /* Emulate sync instruction variants */ 10949863c28aSJames Yang if ((instword & PPC_INST_SYNC_MASK) == PPC_INST_SYNC) { 10959863c28aSJames Yang PPC_WARN_EMULATED(sync, regs); 10969863c28aSJames Yang asm volatile("sync"); 10979863c28aSJames Yang return 0; 10989863c28aSJames Yang } 10999863c28aSJames Yang 1100efcac658SAlexey Kardashevskiy #ifdef CONFIG_PPC64 1101efcac658SAlexey Kardashevskiy /* Emulate the mfspr rD, DSCR. */ 110273d2fb75SAnton Blanchard if ((((instword & PPC_INST_MFSPR_DSCR_USER_MASK) == 110373d2fb75SAnton Blanchard PPC_INST_MFSPR_DSCR_USER) || 110473d2fb75SAnton Blanchard ((instword & PPC_INST_MFSPR_DSCR_MASK) == 110573d2fb75SAnton Blanchard PPC_INST_MFSPR_DSCR)) && 1106efcac658SAlexey Kardashevskiy cpu_has_feature(CPU_FTR_DSCR)) { 1107efcac658SAlexey Kardashevskiy PPC_WARN_EMULATED(mfdscr, regs); 1108efcac658SAlexey Kardashevskiy rd = (instword >> 21) & 0x1f; 1109efcac658SAlexey Kardashevskiy regs->gpr[rd] = mfspr(SPRN_DSCR); 1110efcac658SAlexey Kardashevskiy return 0; 1111efcac658SAlexey Kardashevskiy } 1112efcac658SAlexey Kardashevskiy /* Emulate the mtspr DSCR, rD. */ 111373d2fb75SAnton Blanchard if ((((instword & PPC_INST_MTSPR_DSCR_USER_MASK) == 111473d2fb75SAnton Blanchard PPC_INST_MTSPR_DSCR_USER) || 111573d2fb75SAnton Blanchard ((instword & PPC_INST_MTSPR_DSCR_MASK) == 111673d2fb75SAnton Blanchard PPC_INST_MTSPR_DSCR)) && 1117efcac658SAlexey Kardashevskiy cpu_has_feature(CPU_FTR_DSCR)) { 1118efcac658SAlexey Kardashevskiy PPC_WARN_EMULATED(mtdscr, regs); 1119efcac658SAlexey Kardashevskiy rd = (instword >> 21) & 0x1f; 112000ca0de0SAnton Blanchard current->thread.dscr = regs->gpr[rd]; 1121efcac658SAlexey Kardashevskiy current->thread.dscr_inherit = 1; 112200ca0de0SAnton Blanchard mtspr(SPRN_DSCR, current->thread.dscr); 1123efcac658SAlexey Kardashevskiy return 0; 1124efcac658SAlexey Kardashevskiy } 1125efcac658SAlexey Kardashevskiy #endif 1126efcac658SAlexey Kardashevskiy 112714cf11afSPaul Mackerras return -EINVAL; 112814cf11afSPaul Mackerras } 112914cf11afSPaul Mackerras 113073c9ceabSJeremy Fitzhardinge int is_valid_bugaddr(unsigned long addr) 113114cf11afSPaul Mackerras { 113273c9ceabSJeremy Fitzhardinge return is_kernel_addr(addr); 113314cf11afSPaul Mackerras } 113414cf11afSPaul Mackerras 11353a3b5aa6SKevin Hao #ifdef CONFIG_MATH_EMULATION 11363a3b5aa6SKevin Hao static int emulate_math(struct pt_regs *regs) 11373a3b5aa6SKevin Hao { 11383a3b5aa6SKevin Hao int ret; 11393a3b5aa6SKevin Hao extern int do_mathemu(struct pt_regs *regs); 11403a3b5aa6SKevin Hao 11413a3b5aa6SKevin Hao ret = do_mathemu(regs); 11423a3b5aa6SKevin Hao if (ret >= 0) 11433a3b5aa6SKevin Hao PPC_WARN_EMULATED(math, regs); 11443a3b5aa6SKevin Hao 11453a3b5aa6SKevin Hao switch (ret) { 11463a3b5aa6SKevin Hao case 0: 11473a3b5aa6SKevin Hao emulate_single_step(regs); 11483a3b5aa6SKevin Hao return 0; 11493a3b5aa6SKevin Hao case 1: { 11503a3b5aa6SKevin Hao int code = 0; 1151de79f7b9SPaul Mackerras code = __parse_fpscr(current->thread.fp_state.fpscr); 11523a3b5aa6SKevin Hao _exception(SIGFPE, regs, code, regs->nip); 11533a3b5aa6SKevin Hao return 0; 11543a3b5aa6SKevin Hao } 11553a3b5aa6SKevin Hao case -EFAULT: 11563a3b5aa6SKevin Hao _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip); 11573a3b5aa6SKevin Hao return 0; 11583a3b5aa6SKevin Hao } 11593a3b5aa6SKevin Hao 11603a3b5aa6SKevin Hao return -1; 11613a3b5aa6SKevin Hao } 11623a3b5aa6SKevin Hao #else 11633a3b5aa6SKevin Hao static inline int emulate_math(struct pt_regs *regs) { return -1; } 11643a3b5aa6SKevin Hao #endif 11653a3b5aa6SKevin Hao 116603465f89SNicholas Piggin void program_check_exception(struct pt_regs *regs) 116714cf11afSPaul Mackerras { 1168ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 116914cf11afSPaul Mackerras unsigned int reason = get_reason(regs); 117014cf11afSPaul Mackerras 1171aa42c69cSKim Phillips /* We can now get here via a FP Unavailable exception if the core 117204903a30SKumar Gala * has no FPU, in that case the reason flags will be 0 */ 117314cf11afSPaul Mackerras 117414cf11afSPaul Mackerras if (reason & REASON_FP) { 117514cf11afSPaul Mackerras /* IEEE FP exception */ 1176dc1c1ca3SStephen Rothwell parse_fpe(regs); 1177ba12eedeSLi Zhong goto bail; 11788dad3f92SPaul Mackerras } 11798dad3f92SPaul Mackerras if (reason & REASON_TRAP) { 1180a4c3f909SBalbir Singh unsigned long bugaddr; 1181ba797b28SJason Wessel /* Debugger is first in line to stop recursive faults in 1182ba797b28SJason Wessel * rcu_lock, notify_die, or atomic_notifier_call_chain */ 1183ba797b28SJason Wessel if (debugger_bpt(regs)) 1184ba12eedeSLi Zhong goto bail; 1185ba797b28SJason Wessel 1186*6cc89badSNaveen N. Rao if (kprobe_handler(regs)) 1187*6cc89badSNaveen N. Rao goto bail; 1188*6cc89badSNaveen N. Rao 118914cf11afSPaul Mackerras /* trap exception */ 1190dc1c1ca3SStephen Rothwell if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP) 1191dc1c1ca3SStephen Rothwell == NOTIFY_STOP) 1192ba12eedeSLi Zhong goto bail; 119373c9ceabSJeremy Fitzhardinge 1194a4c3f909SBalbir Singh bugaddr = regs->nip; 1195a4c3f909SBalbir Singh /* 1196a4c3f909SBalbir Singh * Fixup bugaddr for BUG_ON() in real mode 1197a4c3f909SBalbir Singh */ 1198a4c3f909SBalbir Singh if (!is_kernel_addr(bugaddr) && !(regs->msr & MSR_IR)) 1199a4c3f909SBalbir Singh bugaddr += PAGE_OFFSET; 1200a4c3f909SBalbir Singh 120173c9ceabSJeremy Fitzhardinge if (!(regs->msr & MSR_PR) && /* not user-mode */ 1202a4c3f909SBalbir Singh report_bug(bugaddr, regs) == BUG_TRAP_TYPE_WARN) { 120314cf11afSPaul Mackerras regs->nip += 4; 1204ba12eedeSLi Zhong goto bail; 120514cf11afSPaul Mackerras } 12068dad3f92SPaul Mackerras _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip); 1207ba12eedeSLi Zhong goto bail; 12088dad3f92SPaul Mackerras } 1209bc2a9408SMichael Neuling #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 1210bc2a9408SMichael Neuling if (reason & REASON_TM) { 1211bc2a9408SMichael Neuling /* This is a TM "Bad Thing Exception" program check. 1212bc2a9408SMichael Neuling * This occurs when: 1213bc2a9408SMichael Neuling * - An rfid/hrfid/mtmsrd attempts to cause an illegal 1214bc2a9408SMichael Neuling * transition in TM states. 1215bc2a9408SMichael Neuling * - A trechkpt is attempted when transactional. 1216bc2a9408SMichael Neuling * - A treclaim is attempted when non transactional. 1217bc2a9408SMichael Neuling * - A tend is illegally attempted. 1218bc2a9408SMichael Neuling * - writing a TM SPR when transactional. 1219bc2a9408SMichael Neuling */ 1220bc2a9408SMichael Neuling if (!user_mode(regs) && 1221bc2a9408SMichael Neuling report_bug(regs->nip, regs) == BUG_TRAP_TYPE_WARN) { 1222bc2a9408SMichael Neuling regs->nip += 4; 1223ba12eedeSLi Zhong goto bail; 1224bc2a9408SMichael Neuling } 1225bc2a9408SMichael Neuling /* If usermode caused this, it's done something illegal and 1226bc2a9408SMichael Neuling * gets a SIGILL slap on the wrist. We call it an illegal 1227bc2a9408SMichael Neuling * operand to distinguish from the instruction just being bad 1228bc2a9408SMichael Neuling * (e.g. executing a 'tend' on a CPU without TM!); it's an 1229bc2a9408SMichael Neuling * illegal /placement/ of a valid instruction. 1230bc2a9408SMichael Neuling */ 1231bc2a9408SMichael Neuling if (user_mode(regs)) { 1232bc2a9408SMichael Neuling _exception(SIGILL, regs, ILL_ILLOPN, regs->nip); 1233ba12eedeSLi Zhong goto bail; 1234bc2a9408SMichael Neuling } else { 1235bc2a9408SMichael Neuling printk(KERN_EMERG "Unexpected TM Bad Thing exception " 1236bc2a9408SMichael Neuling "at %lx (msr 0x%x)\n", regs->nip, reason); 1237bc2a9408SMichael Neuling die("Unrecoverable exception", regs, SIGABRT); 1238bc2a9408SMichael Neuling } 1239bc2a9408SMichael Neuling } 1240bc2a9408SMichael Neuling #endif 12418dad3f92SPaul Mackerras 1242b3f6a459SMichael Ellerman /* 1243b3f6a459SMichael Ellerman * If we took the program check in the kernel skip down to sending a 1244b3f6a459SMichael Ellerman * SIGILL. The subsequent cases all relate to emulating instructions 1245b3f6a459SMichael Ellerman * which we should only do for userspace. We also do not want to enable 1246b3f6a459SMichael Ellerman * interrupts for kernel faults because that might lead to further 1247b3f6a459SMichael Ellerman * faults, and loose the context of the original exception. 1248b3f6a459SMichael Ellerman */ 1249b3f6a459SMichael Ellerman if (!user_mode(regs)) 1250b3f6a459SMichael Ellerman goto sigill; 1251b3f6a459SMichael Ellerman 1252a3512b2dSBenjamin Herrenschmidt /* We restore the interrupt state now */ 1253a3512b2dSBenjamin Herrenschmidt if (!arch_irq_disabled_regs(regs)) 1254cd8a5673SPaul Mackerras local_irq_enable(); 1255cd8a5673SPaul Mackerras 125604903a30SKumar Gala /* (reason & REASON_ILLEGAL) would be the obvious thing here, 125704903a30SKumar Gala * but there seems to be a hardware bug on the 405GP (RevD) 125804903a30SKumar Gala * that means ESR is sometimes set incorrectly - either to 125904903a30SKumar Gala * ESR_DST (!?) or 0. In the process of chasing this with the 126004903a30SKumar Gala * hardware people - not sure if it can happen on any illegal 126104903a30SKumar Gala * instruction or only on FP instructions, whether there is a 12624e63f8edSBenjamin Herrenschmidt * pattern to occurrences etc. -dgibson 31/Mar/2003 12634e63f8edSBenjamin Herrenschmidt */ 12643a3b5aa6SKevin Hao if (!emulate_math(regs)) 1265ba12eedeSLi Zhong goto bail; 126604903a30SKumar Gala 12678dad3f92SPaul Mackerras /* Try to emulate it if we should. */ 12688dad3f92SPaul Mackerras if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED)) { 126914cf11afSPaul Mackerras switch (emulate_instruction(regs)) { 127014cf11afSPaul Mackerras case 0: 127114cf11afSPaul Mackerras regs->nip += 4; 127214cf11afSPaul Mackerras emulate_single_step(regs); 1273ba12eedeSLi Zhong goto bail; 127414cf11afSPaul Mackerras case -EFAULT: 127514cf11afSPaul Mackerras _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip); 1276ba12eedeSLi Zhong goto bail; 12778dad3f92SPaul Mackerras } 12788dad3f92SPaul Mackerras } 12798dad3f92SPaul Mackerras 1280b3f6a459SMichael Ellerman sigill: 128114cf11afSPaul Mackerras if (reason & REASON_PRIVILEGED) 128214cf11afSPaul Mackerras _exception(SIGILL, regs, ILL_PRVOPC, regs->nip); 128314cf11afSPaul Mackerras else 128414cf11afSPaul Mackerras _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 1285ba12eedeSLi Zhong 1286ba12eedeSLi Zhong bail: 1287ba12eedeSLi Zhong exception_exit(prev_state); 128814cf11afSPaul Mackerras } 128903465f89SNicholas Piggin NOKPROBE_SYMBOL(program_check_exception); 129014cf11afSPaul Mackerras 1291bf593907SPaul Mackerras /* 1292bf593907SPaul Mackerras * This occurs when running in hypervisor mode on POWER6 or later 1293bf593907SPaul Mackerras * and an illegal instruction is encountered. 1294bf593907SPaul Mackerras */ 129503465f89SNicholas Piggin void emulation_assist_interrupt(struct pt_regs *regs) 1296bf593907SPaul Mackerras { 1297bf593907SPaul Mackerras regs->msr |= REASON_ILLEGAL; 1298bf593907SPaul Mackerras program_check_exception(regs); 1299bf593907SPaul Mackerras } 130003465f89SNicholas Piggin NOKPROBE_SYMBOL(emulation_assist_interrupt); 1301bf593907SPaul Mackerras 1302dc1c1ca3SStephen Rothwell void alignment_exception(struct pt_regs *regs) 130314cf11afSPaul Mackerras { 1304ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 13054393c4f6SBenjamin Herrenschmidt int sig, code, fixed = 0; 130614cf11afSPaul Mackerras 1307a3512b2dSBenjamin Herrenschmidt /* We restore the interrupt state now */ 1308a3512b2dSBenjamin Herrenschmidt if (!arch_irq_disabled_regs(regs)) 1309a3512b2dSBenjamin Herrenschmidt local_irq_enable(); 1310a3512b2dSBenjamin Herrenschmidt 13116ce6c629SMichael Neuling if (tm_abort_check(regs, TM_CAUSE_ALIGNMENT | TM_CAUSE_PERSISTENT)) 13126ce6c629SMichael Neuling goto bail; 13136ce6c629SMichael Neuling 1314e9370ae1SPaul Mackerras /* we don't implement logging of alignment exceptions */ 1315e9370ae1SPaul Mackerras if (!(current->thread.align_ctl & PR_UNALIGN_SIGBUS)) 131614cf11afSPaul Mackerras fixed = fix_alignment(regs); 131714cf11afSPaul Mackerras 131814cf11afSPaul Mackerras if (fixed == 1) { 131914cf11afSPaul Mackerras regs->nip += 4; /* skip over emulated instruction */ 132014cf11afSPaul Mackerras emulate_single_step(regs); 1321ba12eedeSLi Zhong goto bail; 132214cf11afSPaul Mackerras } 132314cf11afSPaul Mackerras 132414cf11afSPaul Mackerras /* Operand address was bad */ 132514cf11afSPaul Mackerras if (fixed == -EFAULT) { 13264393c4f6SBenjamin Herrenschmidt sig = SIGSEGV; 13274393c4f6SBenjamin Herrenschmidt code = SEGV_ACCERR; 13284393c4f6SBenjamin Herrenschmidt } else { 13294393c4f6SBenjamin Herrenschmidt sig = SIGBUS; 13304393c4f6SBenjamin Herrenschmidt code = BUS_ADRALN; 133114cf11afSPaul Mackerras } 13324393c4f6SBenjamin Herrenschmidt if (user_mode(regs)) 13334393c4f6SBenjamin Herrenschmidt _exception(sig, regs, code, regs->dar); 13344393c4f6SBenjamin Herrenschmidt else 13354393c4f6SBenjamin Herrenschmidt bad_page_fault(regs, regs->dar, sig); 1336ba12eedeSLi Zhong 1337ba12eedeSLi Zhong bail: 1338ba12eedeSLi Zhong exception_exit(prev_state); 133914cf11afSPaul Mackerras } 134014cf11afSPaul Mackerras 1341f0f558b1SPaul Mackerras void slb_miss_bad_addr(struct pt_regs *regs) 1342f0f558b1SPaul Mackerras { 1343f0f558b1SPaul Mackerras enum ctx_state prev_state = exception_enter(); 1344f0f558b1SPaul Mackerras 1345f0f558b1SPaul Mackerras if (user_mode(regs)) 1346f0f558b1SPaul Mackerras _exception(SIGSEGV, regs, SEGV_BNDERR, regs->dar); 1347f0f558b1SPaul Mackerras else 1348f0f558b1SPaul Mackerras bad_page_fault(regs, regs->dar, SIGSEGV); 1349f0f558b1SPaul Mackerras 1350f0f558b1SPaul Mackerras exception_exit(prev_state); 1351f0f558b1SPaul Mackerras } 1352f0f558b1SPaul Mackerras 135314cf11afSPaul Mackerras void StackOverflow(struct pt_regs *regs) 135414cf11afSPaul Mackerras { 135514cf11afSPaul Mackerras printk(KERN_CRIT "Kernel stack overflow in process %p, r1=%lx\n", 135614cf11afSPaul Mackerras current, regs->gpr[1]); 135714cf11afSPaul Mackerras debugger(regs); 135814cf11afSPaul Mackerras show_regs(regs); 135914cf11afSPaul Mackerras panic("kernel stack overflow"); 136014cf11afSPaul Mackerras } 136114cf11afSPaul Mackerras 136214cf11afSPaul Mackerras void nonrecoverable_exception(struct pt_regs *regs) 136314cf11afSPaul Mackerras { 136414cf11afSPaul Mackerras printk(KERN_ERR "Non-recoverable exception at PC=%lx MSR=%lx\n", 136514cf11afSPaul Mackerras regs->nip, regs->msr); 136614cf11afSPaul Mackerras debugger(regs); 136714cf11afSPaul Mackerras die("nonrecoverable exception", regs, SIGKILL); 136814cf11afSPaul Mackerras } 136914cf11afSPaul Mackerras 1370dc1c1ca3SStephen Rothwell void kernel_fp_unavailable_exception(struct pt_regs *regs) 1371dc1c1ca3SStephen Rothwell { 1372ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 1373ba12eedeSLi Zhong 1374dc1c1ca3SStephen Rothwell printk(KERN_EMERG "Unrecoverable FP Unavailable Exception " 1375dc1c1ca3SStephen Rothwell "%lx at %lx\n", regs->trap, regs->nip); 1376dc1c1ca3SStephen Rothwell die("Unrecoverable FP Unavailable Exception", regs, SIGABRT); 1377ba12eedeSLi Zhong 1378ba12eedeSLi Zhong exception_exit(prev_state); 1379dc1c1ca3SStephen Rothwell } 1380dc1c1ca3SStephen Rothwell 1381dc1c1ca3SStephen Rothwell void altivec_unavailable_exception(struct pt_regs *regs) 1382dc1c1ca3SStephen Rothwell { 1383ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 1384ba12eedeSLi Zhong 1385dc1c1ca3SStephen Rothwell if (user_mode(regs)) { 1386dc1c1ca3SStephen Rothwell /* A user program has executed an altivec instruction, 1387dc1c1ca3SStephen Rothwell but this kernel doesn't support altivec. */ 1388dc1c1ca3SStephen Rothwell _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 1389ba12eedeSLi Zhong goto bail; 1390dc1c1ca3SStephen Rothwell } 13916c4841c2SAnton Blanchard 1392dc1c1ca3SStephen Rothwell printk(KERN_EMERG "Unrecoverable VMX/Altivec Unavailable Exception " 1393dc1c1ca3SStephen Rothwell "%lx at %lx\n", regs->trap, regs->nip); 1394dc1c1ca3SStephen Rothwell die("Unrecoverable VMX/Altivec Unavailable Exception", regs, SIGABRT); 1395ba12eedeSLi Zhong 1396ba12eedeSLi Zhong bail: 1397ba12eedeSLi Zhong exception_exit(prev_state); 1398dc1c1ca3SStephen Rothwell } 1399dc1c1ca3SStephen Rothwell 1400ce48b210SMichael Neuling void vsx_unavailable_exception(struct pt_regs *regs) 1401ce48b210SMichael Neuling { 1402ce48b210SMichael Neuling if (user_mode(regs)) { 1403ce48b210SMichael Neuling /* A user program has executed an vsx instruction, 1404ce48b210SMichael Neuling but this kernel doesn't support vsx. */ 1405ce48b210SMichael Neuling _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 1406ce48b210SMichael Neuling return; 1407ce48b210SMichael Neuling } 1408ce48b210SMichael Neuling 1409ce48b210SMichael Neuling printk(KERN_EMERG "Unrecoverable VSX Unavailable Exception " 1410ce48b210SMichael Neuling "%lx at %lx\n", regs->trap, regs->nip); 1411ce48b210SMichael Neuling die("Unrecoverable VSX Unavailable Exception", regs, SIGABRT); 1412ce48b210SMichael Neuling } 1413ce48b210SMichael Neuling 14142517617eSMichael Neuling #ifdef CONFIG_PPC64 1415172f7aaaSCyril Bur static void tm_unavailable(struct pt_regs *regs) 1416172f7aaaSCyril Bur { 14175d176f75SCyril Bur #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 14185d176f75SCyril Bur if (user_mode(regs)) { 14195d176f75SCyril Bur current->thread.load_tm++; 14205d176f75SCyril Bur regs->msr |= MSR_TM; 14215d176f75SCyril Bur tm_enable(); 14225d176f75SCyril Bur tm_restore_sprs(¤t->thread); 14235d176f75SCyril Bur return; 14245d176f75SCyril Bur } 14255d176f75SCyril Bur #endif 1426172f7aaaSCyril Bur pr_emerg("Unrecoverable TM Unavailable Exception " 1427172f7aaaSCyril Bur "%lx at %lx\n", regs->trap, regs->nip); 1428172f7aaaSCyril Bur die("Unrecoverable TM Unavailable Exception", regs, SIGABRT); 1429172f7aaaSCyril Bur } 1430172f7aaaSCyril Bur 1431021424a1SMichael Ellerman void facility_unavailable_exception(struct pt_regs *regs) 1432d0c0c9a1SMichael Neuling { 1433021424a1SMichael Ellerman static char *facility_strings[] = { 14342517617eSMichael Neuling [FSCR_FP_LG] = "FPU", 14352517617eSMichael Neuling [FSCR_VECVSX_LG] = "VMX/VSX", 14362517617eSMichael Neuling [FSCR_DSCR_LG] = "DSCR", 14372517617eSMichael Neuling [FSCR_PM_LG] = "PMU SPRs", 14382517617eSMichael Neuling [FSCR_BHRB_LG] = "BHRB", 14392517617eSMichael Neuling [FSCR_TM_LG] = "TM", 14402517617eSMichael Neuling [FSCR_EBB_LG] = "EBB", 14412517617eSMichael Neuling [FSCR_TAR_LG] = "TAR", 1442021424a1SMichael Ellerman }; 14432517617eSMichael Neuling char *facility = "unknown"; 1444021424a1SMichael Ellerman u64 value; 1445c952c1c4SAnshuman Khandual u32 instword, rd; 14462517617eSMichael Neuling u8 status; 14472517617eSMichael Neuling bool hv; 1448021424a1SMichael Ellerman 14492517617eSMichael Neuling hv = (regs->trap == 0xf80); 14502517617eSMichael Neuling if (hv) 1451b14b6260SMichael Ellerman value = mfspr(SPRN_HFSCR); 14522517617eSMichael Neuling else 14532517617eSMichael Neuling value = mfspr(SPRN_FSCR); 14542517617eSMichael Neuling 14552517617eSMichael Neuling status = value >> 56; 14562517617eSMichael Neuling if (status == FSCR_DSCR_LG) { 1457c952c1c4SAnshuman Khandual /* 1458c952c1c4SAnshuman Khandual * User is accessing the DSCR register using the problem 1459c952c1c4SAnshuman Khandual * state only SPR number (0x03) either through a mfspr or 1460c952c1c4SAnshuman Khandual * a mtspr instruction. If it is a write attempt through 1461c952c1c4SAnshuman Khandual * a mtspr, then we set the inherit bit. This also allows 1462c952c1c4SAnshuman Khandual * the user to write or read the register directly in the 1463c952c1c4SAnshuman Khandual * future by setting via the FSCR DSCR bit. But in case it 1464c952c1c4SAnshuman Khandual * is a read DSCR attempt through a mfspr instruction, we 1465c952c1c4SAnshuman Khandual * just emulate the instruction instead. This code path will 1466c952c1c4SAnshuman Khandual * always emulate all the mfspr instructions till the user 1467c952c1c4SAnshuman Khandual * has attempted at least one mtspr instruction. This way it 1468c952c1c4SAnshuman Khandual * preserves the same behaviour when the user is accessing 1469c952c1c4SAnshuman Khandual * the DSCR through privilege level only SPR number (0x11) 1470c952c1c4SAnshuman Khandual * which is emulated through illegal instruction exception. 1471c952c1c4SAnshuman Khandual * We always leave HFSCR DSCR set. 14722517617eSMichael Neuling */ 1473c952c1c4SAnshuman Khandual if (get_user(instword, (u32 __user *)(regs->nip))) { 1474c952c1c4SAnshuman Khandual pr_err("Failed to fetch the user instruction\n"); 1475c952c1c4SAnshuman Khandual return; 1476c952c1c4SAnshuman Khandual } 1477c952c1c4SAnshuman Khandual 1478c952c1c4SAnshuman Khandual /* Write into DSCR (mtspr 0x03, RS) */ 1479c952c1c4SAnshuman Khandual if ((instword & PPC_INST_MTSPR_DSCR_USER_MASK) 1480c952c1c4SAnshuman Khandual == PPC_INST_MTSPR_DSCR_USER) { 1481c952c1c4SAnshuman Khandual rd = (instword >> 21) & 0x1f; 1482c952c1c4SAnshuman Khandual current->thread.dscr = regs->gpr[rd]; 14832517617eSMichael Neuling current->thread.dscr_inherit = 1; 1484b57bd2deSMichael Neuling current->thread.fscr |= FSCR_DSCR; 1485b57bd2deSMichael Neuling mtspr(SPRN_FSCR, current->thread.fscr); 1486c952c1c4SAnshuman Khandual } 1487c952c1c4SAnshuman Khandual 1488c952c1c4SAnshuman Khandual /* Read from DSCR (mfspr RT, 0x03) */ 1489c952c1c4SAnshuman Khandual if ((instword & PPC_INST_MFSPR_DSCR_USER_MASK) 1490c952c1c4SAnshuman Khandual == PPC_INST_MFSPR_DSCR_USER) { 1491c952c1c4SAnshuman Khandual if (emulate_instruction(regs)) { 1492c952c1c4SAnshuman Khandual pr_err("DSCR based mfspr emulation failed\n"); 1493c952c1c4SAnshuman Khandual return; 1494c952c1c4SAnshuman Khandual } 1495c952c1c4SAnshuman Khandual regs->nip += 4; 1496c952c1c4SAnshuman Khandual emulate_single_step(regs); 1497c952c1c4SAnshuman Khandual } 14982517617eSMichael Neuling return; 1499b14b6260SMichael Ellerman } 1500b14b6260SMichael Ellerman 1501172f7aaaSCyril Bur if (status == FSCR_TM_LG) { 1502172f7aaaSCyril Bur /* 1503172f7aaaSCyril Bur * If we're here then the hardware is TM aware because it 1504172f7aaaSCyril Bur * generated an exception with FSRM_TM set. 1505172f7aaaSCyril Bur * 1506172f7aaaSCyril Bur * If cpu_has_feature(CPU_FTR_TM) is false, then either firmware 1507172f7aaaSCyril Bur * told us not to do TM, or the kernel is not built with TM 1508172f7aaaSCyril Bur * support. 1509172f7aaaSCyril Bur * 1510172f7aaaSCyril Bur * If both of those things are true, then userspace can spam the 1511172f7aaaSCyril Bur * console by triggering the printk() below just by continually 1512172f7aaaSCyril Bur * doing tbegin (or any TM instruction). So in that case just 1513172f7aaaSCyril Bur * send the process a SIGILL immediately. 1514172f7aaaSCyril Bur */ 1515172f7aaaSCyril Bur if (!cpu_has_feature(CPU_FTR_TM)) 1516172f7aaaSCyril Bur goto out; 1517172f7aaaSCyril Bur 1518172f7aaaSCyril Bur tm_unavailable(regs); 1519172f7aaaSCyril Bur return; 1520172f7aaaSCyril Bur } 1521172f7aaaSCyril Bur 15222517617eSMichael Neuling if ((status < ARRAY_SIZE(facility_strings)) && 15232517617eSMichael Neuling facility_strings[status]) 15242517617eSMichael Neuling facility = facility_strings[status]; 1525021424a1SMichael Ellerman 1526d0c0c9a1SMichael Neuling /* We restore the interrupt state now */ 1527d0c0c9a1SMichael Neuling if (!arch_irq_disabled_regs(regs)) 1528d0c0c9a1SMichael Neuling local_irq_enable(); 1529d0c0c9a1SMichael Neuling 1530ee4ed6faSMichael Neuling pr_err_ratelimited( 1531ee4ed6faSMichael Neuling "%sFacility '%s' unavailable, exception at 0x%lx, MSR=%lx\n", 15322517617eSMichael Neuling hv ? "Hypervisor " : "", facility, regs->nip, regs->msr); 1533d0c0c9a1SMichael Neuling 1534172f7aaaSCyril Bur out: 1535d0c0c9a1SMichael Neuling if (user_mode(regs)) { 1536d0c0c9a1SMichael Neuling _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 1537d0c0c9a1SMichael Neuling return; 1538d0c0c9a1SMichael Neuling } 1539d0c0c9a1SMichael Neuling 1540021424a1SMichael Ellerman die("Unexpected facility unavailable exception", regs, SIGABRT); 1541d0c0c9a1SMichael Neuling } 15422517617eSMichael Neuling #endif 1543d0c0c9a1SMichael Neuling 1544f54db641SMichael Neuling #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 1545f54db641SMichael Neuling 1546f54db641SMichael Neuling void fp_unavailable_tm(struct pt_regs *regs) 1547f54db641SMichael Neuling { 1548f54db641SMichael Neuling /* Note: This does not handle any kind of FP laziness. */ 1549f54db641SMichael Neuling 1550f54db641SMichael Neuling TM_DEBUG("FP Unavailable trap whilst transactional at 0x%lx, MSR=%lx\n", 1551f54db641SMichael Neuling regs->nip, regs->msr); 1552f54db641SMichael Neuling 1553f54db641SMichael Neuling /* We can only have got here if the task started using FP after 1554f54db641SMichael Neuling * beginning the transaction. So, the transactional regs are just a 1555f54db641SMichael Neuling * copy of the checkpointed ones. But, we still need to recheckpoint 1556f54db641SMichael Neuling * as we're enabling FP for the process; it will return, abort the 1557f54db641SMichael Neuling * transaction, and probably retry but now with FP enabled. So the 1558f54db641SMichael Neuling * checkpointed FP registers need to be loaded. 1559f54db641SMichael Neuling */ 1560d31626f7SPaul Mackerras tm_reclaim_current(TM_CAUSE_FAC_UNAV); 1561f54db641SMichael Neuling /* Reclaim didn't save out any FPRs to transact_fprs. */ 1562f54db641SMichael Neuling 1563f54db641SMichael Neuling /* Enable FP for the task: */ 1564f54db641SMichael Neuling regs->msr |= (MSR_FP | current->thread.fpexc_mode); 1565f54db641SMichael Neuling 1566f54db641SMichael Neuling /* This loads and recheckpoints the FP registers from 1567f54db641SMichael Neuling * thread.fpr[]. They will remain in registers after the 1568f54db641SMichael Neuling * checkpoint so we don't need to reload them after. 15693ac8ff1cSPaul Mackerras * If VMX is in use, the VRs now hold checkpointed values, 15703ac8ff1cSPaul Mackerras * so we don't want to load the VRs from the thread_struct. 1571f54db641SMichael Neuling */ 15723ac8ff1cSPaul Mackerras tm_recheckpoint(¤t->thread, MSR_FP); 15733ac8ff1cSPaul Mackerras 15743ac8ff1cSPaul Mackerras /* If VMX is in use, get the transactional values back */ 15753ac8ff1cSPaul Mackerras if (regs->msr & MSR_VEC) { 1576dc310669SCyril Bur msr_check_and_set(MSR_VEC); 1577dc310669SCyril Bur load_vr_state(¤t->thread.vr_state); 15783ac8ff1cSPaul Mackerras /* At this point all the VSX state is loaded, so enable it */ 15793ac8ff1cSPaul Mackerras regs->msr |= MSR_VSX; 15803ac8ff1cSPaul Mackerras } 1581f54db641SMichael Neuling } 1582f54db641SMichael Neuling 1583f54db641SMichael Neuling void altivec_unavailable_tm(struct pt_regs *regs) 1584f54db641SMichael Neuling { 1585f54db641SMichael Neuling /* See the comments in fp_unavailable_tm(). This function operates 1586f54db641SMichael Neuling * the same way. 1587f54db641SMichael Neuling */ 1588f54db641SMichael Neuling 1589f54db641SMichael Neuling TM_DEBUG("Vector Unavailable trap whilst transactional at 0x%lx," 1590f54db641SMichael Neuling "MSR=%lx\n", 1591f54db641SMichael Neuling regs->nip, regs->msr); 1592d31626f7SPaul Mackerras tm_reclaim_current(TM_CAUSE_FAC_UNAV); 1593f54db641SMichael Neuling regs->msr |= MSR_VEC; 15943ac8ff1cSPaul Mackerras tm_recheckpoint(¤t->thread, MSR_VEC); 1595f54db641SMichael Neuling current->thread.used_vr = 1; 1596f54db641SMichael Neuling 15973ac8ff1cSPaul Mackerras if (regs->msr & MSR_FP) { 1598dc310669SCyril Bur msr_check_and_set(MSR_FP); 1599dc310669SCyril Bur load_fp_state(¤t->thread.fp_state); 16003ac8ff1cSPaul Mackerras regs->msr |= MSR_VSX; 16013ac8ff1cSPaul Mackerras } 16023ac8ff1cSPaul Mackerras } 16033ac8ff1cSPaul Mackerras 1604f54db641SMichael Neuling void vsx_unavailable_tm(struct pt_regs *regs) 1605f54db641SMichael Neuling { 16063ac8ff1cSPaul Mackerras unsigned long orig_msr = regs->msr; 16073ac8ff1cSPaul Mackerras 1608f54db641SMichael Neuling /* See the comments in fp_unavailable_tm(). This works similarly, 1609f54db641SMichael Neuling * though we're loading both FP and VEC registers in here. 1610f54db641SMichael Neuling * 1611f54db641SMichael Neuling * If FP isn't in use, load FP regs. If VEC isn't in use, load VEC 1612f54db641SMichael Neuling * regs. Either way, set MSR_VSX. 1613f54db641SMichael Neuling */ 1614f54db641SMichael Neuling 1615f54db641SMichael Neuling TM_DEBUG("VSX Unavailable trap whilst transactional at 0x%lx," 1616f54db641SMichael Neuling "MSR=%lx\n", 1617f54db641SMichael Neuling regs->nip, regs->msr); 1618f54db641SMichael Neuling 16193ac8ff1cSPaul Mackerras current->thread.used_vsr = 1; 16203ac8ff1cSPaul Mackerras 16213ac8ff1cSPaul Mackerras /* If FP and VMX are already loaded, we have all the state we need */ 16223ac8ff1cSPaul Mackerras if ((orig_msr & (MSR_FP | MSR_VEC)) == (MSR_FP | MSR_VEC)) { 16233ac8ff1cSPaul Mackerras regs->msr |= MSR_VSX; 16243ac8ff1cSPaul Mackerras return; 16253ac8ff1cSPaul Mackerras } 16263ac8ff1cSPaul Mackerras 1627f54db641SMichael Neuling /* This reclaims FP and/or VR regs if they're already enabled */ 1628d31626f7SPaul Mackerras tm_reclaim_current(TM_CAUSE_FAC_UNAV); 1629f54db641SMichael Neuling 1630f54db641SMichael Neuling regs->msr |= MSR_VEC | MSR_FP | current->thread.fpexc_mode | 1631f54db641SMichael Neuling MSR_VSX; 16323ac8ff1cSPaul Mackerras 16333ac8ff1cSPaul Mackerras /* This loads & recheckpoints FP and VRs; but we have 16343ac8ff1cSPaul Mackerras * to be sure not to overwrite previously-valid state. 16353ac8ff1cSPaul Mackerras */ 16363ac8ff1cSPaul Mackerras tm_recheckpoint(¤t->thread, regs->msr & ~orig_msr); 16373ac8ff1cSPaul Mackerras 1638dc310669SCyril Bur msr_check_and_set(orig_msr & (MSR_FP | MSR_VEC)); 1639dc310669SCyril Bur 16403ac8ff1cSPaul Mackerras if (orig_msr & MSR_FP) 1641dc310669SCyril Bur load_fp_state(¤t->thread.fp_state); 16423ac8ff1cSPaul Mackerras if (orig_msr & MSR_VEC) 1643dc310669SCyril Bur load_vr_state(¤t->thread.vr_state); 1644f54db641SMichael Neuling } 1645f54db641SMichael Neuling #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ 1646f54db641SMichael Neuling 1647dc1c1ca3SStephen Rothwell void performance_monitor_exception(struct pt_regs *regs) 1648dc1c1ca3SStephen Rothwell { 164969111bacSChristoph Lameter __this_cpu_inc(irq_stat.pmu_irqs); 165089713ed1SAnton Blanchard 1651dc1c1ca3SStephen Rothwell perf_irq(regs); 1652dc1c1ca3SStephen Rothwell } 1653dc1c1ca3SStephen Rothwell 16548dad3f92SPaul Mackerras #ifdef CONFIG_8xx 165514cf11afSPaul Mackerras void SoftwareEmulation(struct pt_regs *regs) 165614cf11afSPaul Mackerras { 165714cf11afSPaul Mackerras CHECK_FULL_REGS(regs); 165814cf11afSPaul Mackerras 165914cf11afSPaul Mackerras if (!user_mode(regs)) { 166014cf11afSPaul Mackerras debugger(regs); 16611eb2819dSLEROY Christophe die("Kernel Mode Unimplemented Instruction or SW FPU Emulation", 16621eb2819dSLEROY Christophe regs, SIGFPE); 166314cf11afSPaul Mackerras } 166414cf11afSPaul Mackerras 16653a3b5aa6SKevin Hao if (!emulate_math(regs)) 16663a3b5aa6SKevin Hao return; 16675fad293bSKumar Gala 16685fad293bSKumar Gala _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 166914cf11afSPaul Mackerras } 16708dad3f92SPaul Mackerras #endif /* CONFIG_8xx */ 167114cf11afSPaul Mackerras 1672172ae2e7SDave Kleikamp #ifdef CONFIG_PPC_ADV_DEBUG_REGS 16733bffb652SDave Kleikamp static void handle_debug(struct pt_regs *regs, unsigned long debug_status) 16743bffb652SDave Kleikamp { 16753bffb652SDave Kleikamp int changed = 0; 16763bffb652SDave Kleikamp /* 16773bffb652SDave Kleikamp * Determine the cause of the debug event, clear the 16783bffb652SDave Kleikamp * event flags and send a trap to the handler. Torez 16793bffb652SDave Kleikamp */ 16803bffb652SDave Kleikamp if (debug_status & (DBSR_DAC1R | DBSR_DAC1W)) { 16813bffb652SDave Kleikamp dbcr_dac(current) &= ~(DBCR_DAC1R | DBCR_DAC1W); 16823bffb652SDave Kleikamp #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE 168351ae8d4aSBharat Bhushan current->thread.debug.dbcr2 &= ~DBCR2_DAC12MODE; 16843bffb652SDave Kleikamp #endif 16853bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_DAC1), debug_status, TRAP_HWBKPT, 16863bffb652SDave Kleikamp 5); 16873bffb652SDave Kleikamp changed |= 0x01; 16883bffb652SDave Kleikamp } else if (debug_status & (DBSR_DAC2R | DBSR_DAC2W)) { 16893bffb652SDave Kleikamp dbcr_dac(current) &= ~(DBCR_DAC2R | DBCR_DAC2W); 16903bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_DAC2), debug_status, TRAP_HWBKPT, 16913bffb652SDave Kleikamp 6); 16923bffb652SDave Kleikamp changed |= 0x01; 16933bffb652SDave Kleikamp } else if (debug_status & DBSR_IAC1) { 169451ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IAC1; 16953bffb652SDave Kleikamp dbcr_iac_range(current) &= ~DBCR_IAC12MODE; 16963bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_IAC1), debug_status, TRAP_HWBKPT, 16973bffb652SDave Kleikamp 1); 16983bffb652SDave Kleikamp changed |= 0x01; 16993bffb652SDave Kleikamp } else if (debug_status & DBSR_IAC2) { 170051ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IAC2; 17013bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_IAC2), debug_status, TRAP_HWBKPT, 17023bffb652SDave Kleikamp 2); 17033bffb652SDave Kleikamp changed |= 0x01; 17043bffb652SDave Kleikamp } else if (debug_status & DBSR_IAC3) { 170551ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IAC3; 17063bffb652SDave Kleikamp dbcr_iac_range(current) &= ~DBCR_IAC34MODE; 17073bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_IAC3), debug_status, TRAP_HWBKPT, 17083bffb652SDave Kleikamp 3); 17093bffb652SDave Kleikamp changed |= 0x01; 17103bffb652SDave Kleikamp } else if (debug_status & DBSR_IAC4) { 171151ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IAC4; 17123bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_IAC4), debug_status, TRAP_HWBKPT, 17133bffb652SDave Kleikamp 4); 17143bffb652SDave Kleikamp changed |= 0x01; 17153bffb652SDave Kleikamp } 17163bffb652SDave Kleikamp /* 17173bffb652SDave Kleikamp * At the point this routine was called, the MSR(DE) was turned off. 17183bffb652SDave Kleikamp * Check all other debug flags and see if that bit needs to be turned 17193bffb652SDave Kleikamp * back on or not. 17203bffb652SDave Kleikamp */ 172151ae8d4aSBharat Bhushan if (DBCR_ACTIVE_EVENTS(current->thread.debug.dbcr0, 172251ae8d4aSBharat Bhushan current->thread.debug.dbcr1)) 17233bffb652SDave Kleikamp regs->msr |= MSR_DE; 17243bffb652SDave Kleikamp else 17253bffb652SDave Kleikamp /* Make sure the IDM flag is off */ 172651ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IDM; 17273bffb652SDave Kleikamp 17283bffb652SDave Kleikamp if (changed & 0x01) 172951ae8d4aSBharat Bhushan mtspr(SPRN_DBCR0, current->thread.debug.dbcr0); 17303bffb652SDave Kleikamp } 173114cf11afSPaul Mackerras 173203465f89SNicholas Piggin void DebugException(struct pt_regs *regs, unsigned long debug_status) 173314cf11afSPaul Mackerras { 173451ae8d4aSBharat Bhushan current->thread.debug.dbsr = debug_status; 17353bffb652SDave Kleikamp 1736ec097c84SRoland McGrath /* Hack alert: On BookE, Branch Taken stops on the branch itself, while 1737ec097c84SRoland McGrath * on server, it stops on the target of the branch. In order to simulate 1738ec097c84SRoland McGrath * the server behaviour, we thus restart right away with a single step 1739ec097c84SRoland McGrath * instead of stopping here when hitting a BT 1740ec097c84SRoland McGrath */ 1741ec097c84SRoland McGrath if (debug_status & DBSR_BT) { 1742ec097c84SRoland McGrath regs->msr &= ~MSR_DE; 1743ec097c84SRoland McGrath 1744ec097c84SRoland McGrath /* Disable BT */ 1745ec097c84SRoland McGrath mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_BT); 1746ec097c84SRoland McGrath /* Clear the BT event */ 1747ec097c84SRoland McGrath mtspr(SPRN_DBSR, DBSR_BT); 1748ec097c84SRoland McGrath 1749ec097c84SRoland McGrath /* Do the single step trick only when coming from userspace */ 1750ec097c84SRoland McGrath if (user_mode(regs)) { 175151ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_BT; 175251ae8d4aSBharat Bhushan current->thread.debug.dbcr0 |= DBCR0_IDM | DBCR0_IC; 1753ec097c84SRoland McGrath regs->msr |= MSR_DE; 1754ec097c84SRoland McGrath return; 1755ec097c84SRoland McGrath } 1756ec097c84SRoland McGrath 1757*6cc89badSNaveen N. Rao if (kprobe_post_handler(regs)) 1758*6cc89badSNaveen N. Rao return; 1759*6cc89badSNaveen N. Rao 1760ec097c84SRoland McGrath if (notify_die(DIE_SSTEP, "block_step", regs, 5, 1761ec097c84SRoland McGrath 5, SIGTRAP) == NOTIFY_STOP) { 1762ec097c84SRoland McGrath return; 1763ec097c84SRoland McGrath } 1764ec097c84SRoland McGrath if (debugger_sstep(regs)) 1765ec097c84SRoland McGrath return; 1766ec097c84SRoland McGrath } else if (debug_status & DBSR_IC) { /* Instruction complete */ 176714cf11afSPaul Mackerras regs->msr &= ~MSR_DE; 1768f8279621SKumar Gala 176914cf11afSPaul Mackerras /* Disable instruction completion */ 177014cf11afSPaul Mackerras mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_IC); 177114cf11afSPaul Mackerras /* Clear the instruction completion event */ 177214cf11afSPaul Mackerras mtspr(SPRN_DBSR, DBSR_IC); 1773f8279621SKumar Gala 1774*6cc89badSNaveen N. Rao if (kprobe_post_handler(regs)) 1775*6cc89badSNaveen N. Rao return; 1776*6cc89badSNaveen N. Rao 1777f8279621SKumar Gala if (notify_die(DIE_SSTEP, "single_step", regs, 5, 1778f8279621SKumar Gala 5, SIGTRAP) == NOTIFY_STOP) { 177914cf11afSPaul Mackerras return; 178014cf11afSPaul Mackerras } 1781f8279621SKumar Gala 1782f8279621SKumar Gala if (debugger_sstep(regs)) 1783f8279621SKumar Gala return; 1784f8279621SKumar Gala 17853bffb652SDave Kleikamp if (user_mode(regs)) { 178651ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IC; 178751ae8d4aSBharat Bhushan if (DBCR_ACTIVE_EVENTS(current->thread.debug.dbcr0, 178851ae8d4aSBharat Bhushan current->thread.debug.dbcr1)) 17893bffb652SDave Kleikamp regs->msr |= MSR_DE; 17903bffb652SDave Kleikamp else 17913bffb652SDave Kleikamp /* Make sure the IDM bit is off */ 179251ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IDM; 17933bffb652SDave Kleikamp } 1794f8279621SKumar Gala 1795f8279621SKumar Gala _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip); 17963bffb652SDave Kleikamp } else 17973bffb652SDave Kleikamp handle_debug(regs, debug_status); 179814cf11afSPaul Mackerras } 179903465f89SNicholas Piggin NOKPROBE_SYMBOL(DebugException); 1800172ae2e7SDave Kleikamp #endif /* CONFIG_PPC_ADV_DEBUG_REGS */ 180114cf11afSPaul Mackerras 180214cf11afSPaul Mackerras #if !defined(CONFIG_TAU_INT) 180314cf11afSPaul Mackerras void TAUException(struct pt_regs *regs) 180414cf11afSPaul Mackerras { 180514cf11afSPaul Mackerras printk("TAU trap at PC: %lx, MSR: %lx, vector=%lx %s\n", 180614cf11afSPaul Mackerras regs->nip, regs->msr, regs->trap, print_tainted()); 180714cf11afSPaul Mackerras } 180814cf11afSPaul Mackerras #endif /* CONFIG_INT_TAU */ 180914cf11afSPaul Mackerras 181014cf11afSPaul Mackerras #ifdef CONFIG_ALTIVEC 1811dc1c1ca3SStephen Rothwell void altivec_assist_exception(struct pt_regs *regs) 181214cf11afSPaul Mackerras { 181314cf11afSPaul Mackerras int err; 181414cf11afSPaul Mackerras 181514cf11afSPaul Mackerras if (!user_mode(regs)) { 181614cf11afSPaul Mackerras printk(KERN_EMERG "VMX/Altivec assist exception in kernel mode" 181714cf11afSPaul Mackerras " at %lx\n", regs->nip); 18188dad3f92SPaul Mackerras die("Kernel VMX/Altivec assist exception", regs, SIGILL); 181914cf11afSPaul Mackerras } 182014cf11afSPaul Mackerras 1821dc1c1ca3SStephen Rothwell flush_altivec_to_thread(current); 1822dc1c1ca3SStephen Rothwell 1823eecff81dSAnton Blanchard PPC_WARN_EMULATED(altivec, regs); 182414cf11afSPaul Mackerras err = emulate_altivec(regs); 182514cf11afSPaul Mackerras if (err == 0) { 182614cf11afSPaul Mackerras regs->nip += 4; /* skip emulated instruction */ 182714cf11afSPaul Mackerras emulate_single_step(regs); 182814cf11afSPaul Mackerras return; 182914cf11afSPaul Mackerras } 183014cf11afSPaul Mackerras 183114cf11afSPaul Mackerras if (err == -EFAULT) { 183214cf11afSPaul Mackerras /* got an error reading the instruction */ 183314cf11afSPaul Mackerras _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip); 183414cf11afSPaul Mackerras } else { 183514cf11afSPaul Mackerras /* didn't recognize the instruction */ 183614cf11afSPaul Mackerras /* XXX quick hack for now: set the non-Java bit in the VSCR */ 183776462232SChristian Dietrich printk_ratelimited(KERN_ERR "Unrecognized altivec instruction " 183814cf11afSPaul Mackerras "in %s at %lx\n", current->comm, regs->nip); 1839de79f7b9SPaul Mackerras current->thread.vr_state.vscr.u[3] |= 0x10000; 184014cf11afSPaul Mackerras } 184114cf11afSPaul Mackerras } 184214cf11afSPaul Mackerras #endif /* CONFIG_ALTIVEC */ 184314cf11afSPaul Mackerras 184414cf11afSPaul Mackerras #ifdef CONFIG_FSL_BOOKE 184514cf11afSPaul Mackerras void CacheLockingException(struct pt_regs *regs, unsigned long address, 184614cf11afSPaul Mackerras unsigned long error_code) 184714cf11afSPaul Mackerras { 184814cf11afSPaul Mackerras /* We treat cache locking instructions from the user 184914cf11afSPaul Mackerras * as priv ops, in the future we could try to do 185014cf11afSPaul Mackerras * something smarter 185114cf11afSPaul Mackerras */ 185214cf11afSPaul Mackerras if (error_code & (ESR_DLK|ESR_ILK)) 185314cf11afSPaul Mackerras _exception(SIGILL, regs, ILL_PRVOPC, regs->nip); 185414cf11afSPaul Mackerras return; 185514cf11afSPaul Mackerras } 185614cf11afSPaul Mackerras #endif /* CONFIG_FSL_BOOKE */ 185714cf11afSPaul Mackerras 185814cf11afSPaul Mackerras #ifdef CONFIG_SPE 185914cf11afSPaul Mackerras void SPEFloatingPointException(struct pt_regs *regs) 186014cf11afSPaul Mackerras { 18616a800f36SLiu Yu extern int do_spe_mathemu(struct pt_regs *regs); 186214cf11afSPaul Mackerras unsigned long spefscr; 186314cf11afSPaul Mackerras int fpexc_mode; 186414cf11afSPaul Mackerras int code = 0; 18656a800f36SLiu Yu int err; 18666a800f36SLiu Yu 1867685659eeSyu liu flush_spe_to_thread(current); 186814cf11afSPaul Mackerras 186914cf11afSPaul Mackerras spefscr = current->thread.spefscr; 187014cf11afSPaul Mackerras fpexc_mode = current->thread.fpexc_mode; 187114cf11afSPaul Mackerras 187214cf11afSPaul Mackerras if ((spefscr & SPEFSCR_FOVF) && (fpexc_mode & PR_FP_EXC_OVF)) { 187314cf11afSPaul Mackerras code = FPE_FLTOVF; 187414cf11afSPaul Mackerras } 187514cf11afSPaul Mackerras else if ((spefscr & SPEFSCR_FUNF) && (fpexc_mode & PR_FP_EXC_UND)) { 187614cf11afSPaul Mackerras code = FPE_FLTUND; 187714cf11afSPaul Mackerras } 187814cf11afSPaul Mackerras else if ((spefscr & SPEFSCR_FDBZ) && (fpexc_mode & PR_FP_EXC_DIV)) 187914cf11afSPaul Mackerras code = FPE_FLTDIV; 188014cf11afSPaul Mackerras else if ((spefscr & SPEFSCR_FINV) && (fpexc_mode & PR_FP_EXC_INV)) { 188114cf11afSPaul Mackerras code = FPE_FLTINV; 188214cf11afSPaul Mackerras } 188314cf11afSPaul Mackerras else if ((spefscr & (SPEFSCR_FG | SPEFSCR_FX)) && (fpexc_mode & PR_FP_EXC_RES)) 188414cf11afSPaul Mackerras code = FPE_FLTRES; 188514cf11afSPaul Mackerras 18866a800f36SLiu Yu err = do_spe_mathemu(regs); 18876a800f36SLiu Yu if (err == 0) { 18886a800f36SLiu Yu regs->nip += 4; /* skip emulated instruction */ 18896a800f36SLiu Yu emulate_single_step(regs); 189014cf11afSPaul Mackerras return; 189114cf11afSPaul Mackerras } 18926a800f36SLiu Yu 18936a800f36SLiu Yu if (err == -EFAULT) { 18946a800f36SLiu Yu /* got an error reading the instruction */ 18956a800f36SLiu Yu _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip); 18966a800f36SLiu Yu } else if (err == -EINVAL) { 18976a800f36SLiu Yu /* didn't recognize the instruction */ 18986a800f36SLiu Yu printk(KERN_ERR "unrecognized spe instruction " 18996a800f36SLiu Yu "in %s at %lx\n", current->comm, regs->nip); 19006a800f36SLiu Yu } else { 19016a800f36SLiu Yu _exception(SIGFPE, regs, code, regs->nip); 19026a800f36SLiu Yu } 19036a800f36SLiu Yu 19046a800f36SLiu Yu return; 19056a800f36SLiu Yu } 19066a800f36SLiu Yu 19076a800f36SLiu Yu void SPEFloatingPointRoundException(struct pt_regs *regs) 19086a800f36SLiu Yu { 19096a800f36SLiu Yu extern int speround_handler(struct pt_regs *regs); 19106a800f36SLiu Yu int err; 19116a800f36SLiu Yu 19126a800f36SLiu Yu preempt_disable(); 19136a800f36SLiu Yu if (regs->msr & MSR_SPE) 19146a800f36SLiu Yu giveup_spe(current); 19156a800f36SLiu Yu preempt_enable(); 19166a800f36SLiu Yu 19176a800f36SLiu Yu regs->nip -= 4; 19186a800f36SLiu Yu err = speround_handler(regs); 19196a800f36SLiu Yu if (err == 0) { 19206a800f36SLiu Yu regs->nip += 4; /* skip emulated instruction */ 19216a800f36SLiu Yu emulate_single_step(regs); 19226a800f36SLiu Yu return; 19236a800f36SLiu Yu } 19246a800f36SLiu Yu 19256a800f36SLiu Yu if (err == -EFAULT) { 19266a800f36SLiu Yu /* got an error reading the instruction */ 19276a800f36SLiu Yu _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip); 19286a800f36SLiu Yu } else if (err == -EINVAL) { 19296a800f36SLiu Yu /* didn't recognize the instruction */ 19306a800f36SLiu Yu printk(KERN_ERR "unrecognized spe instruction " 19316a800f36SLiu Yu "in %s at %lx\n", current->comm, regs->nip); 19326a800f36SLiu Yu } else { 19336a800f36SLiu Yu _exception(SIGFPE, regs, 0, regs->nip); 19346a800f36SLiu Yu return; 19356a800f36SLiu Yu } 19366a800f36SLiu Yu } 193714cf11afSPaul Mackerras #endif 193814cf11afSPaul Mackerras 1939dc1c1ca3SStephen Rothwell /* 1940dc1c1ca3SStephen Rothwell * We enter here if we get an unrecoverable exception, that is, one 1941dc1c1ca3SStephen Rothwell * that happened at a point where the RI (recoverable interrupt) bit 1942dc1c1ca3SStephen Rothwell * in the MSR is 0. This indicates that SRR0/1 are live, and that 1943dc1c1ca3SStephen Rothwell * we therefore lost state by taking this exception. 1944dc1c1ca3SStephen Rothwell */ 1945dc1c1ca3SStephen Rothwell void unrecoverable_exception(struct pt_regs *regs) 1946dc1c1ca3SStephen Rothwell { 1947dc1c1ca3SStephen Rothwell printk(KERN_EMERG "Unrecoverable exception %lx at %lx\n", 1948dc1c1ca3SStephen Rothwell regs->trap, regs->nip); 1949dc1c1ca3SStephen Rothwell die("Unrecoverable exception", regs, SIGABRT); 1950dc1c1ca3SStephen Rothwell } 1951dc1c1ca3SStephen Rothwell 19521e18c17aSJason Gunthorpe #if defined(CONFIG_BOOKE_WDT) || defined(CONFIG_40x) 195314cf11afSPaul Mackerras /* 195414cf11afSPaul Mackerras * Default handler for a Watchdog exception, 195514cf11afSPaul Mackerras * spins until a reboot occurs 195614cf11afSPaul Mackerras */ 195714cf11afSPaul Mackerras void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs) 195814cf11afSPaul Mackerras { 195914cf11afSPaul Mackerras /* Generic WatchdogHandler, implement your own */ 196014cf11afSPaul Mackerras mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE)); 196114cf11afSPaul Mackerras return; 196214cf11afSPaul Mackerras } 196314cf11afSPaul Mackerras 196414cf11afSPaul Mackerras void WatchdogException(struct pt_regs *regs) 196514cf11afSPaul Mackerras { 196614cf11afSPaul Mackerras printk (KERN_EMERG "PowerPC Book-E Watchdog Exception\n"); 196714cf11afSPaul Mackerras WatchdogHandler(regs); 196814cf11afSPaul Mackerras } 196914cf11afSPaul Mackerras #endif 1970dc1c1ca3SStephen Rothwell 1971dc1c1ca3SStephen Rothwell /* 1972dc1c1ca3SStephen Rothwell * We enter here if we discover during exception entry that we are 1973dc1c1ca3SStephen Rothwell * running in supervisor mode with a userspace value in the stack pointer. 1974dc1c1ca3SStephen Rothwell */ 1975dc1c1ca3SStephen Rothwell void kernel_bad_stack(struct pt_regs *regs) 1976dc1c1ca3SStephen Rothwell { 1977dc1c1ca3SStephen Rothwell printk(KERN_EMERG "Bad kernel stack pointer %lx at %lx\n", 1978dc1c1ca3SStephen Rothwell regs->gpr[1], regs->nip); 1979dc1c1ca3SStephen Rothwell die("Bad kernel stack pointer", regs, SIGABRT); 1980dc1c1ca3SStephen Rothwell } 198114cf11afSPaul Mackerras 198214cf11afSPaul Mackerras void __init trap_init(void) 198314cf11afSPaul Mackerras { 198414cf11afSPaul Mackerras } 198580947e7cSGeert Uytterhoeven 198680947e7cSGeert Uytterhoeven 198780947e7cSGeert Uytterhoeven #ifdef CONFIG_PPC_EMULATED_STATS 198880947e7cSGeert Uytterhoeven 198980947e7cSGeert Uytterhoeven #define WARN_EMULATED_SETUP(type) .type = { .name = #type } 199080947e7cSGeert Uytterhoeven 199180947e7cSGeert Uytterhoeven struct ppc_emulated ppc_emulated = { 199280947e7cSGeert Uytterhoeven #ifdef CONFIG_ALTIVEC 199380947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(altivec), 199480947e7cSGeert Uytterhoeven #endif 199580947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(dcba), 199680947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(dcbz), 199780947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(fp_pair), 199880947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(isel), 199980947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(mcrxr), 200080947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(mfpvr), 200180947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(multiple), 200280947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(popcntb), 200380947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(spe), 200480947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(string), 2005a3821b2aSScott Wood WARN_EMULATED_SETUP(sync), 200680947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(unaligned), 200780947e7cSGeert Uytterhoeven #ifdef CONFIG_MATH_EMULATION 200880947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(math), 200980947e7cSGeert Uytterhoeven #endif 201080947e7cSGeert Uytterhoeven #ifdef CONFIG_VSX 201180947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(vsx), 201280947e7cSGeert Uytterhoeven #endif 2013efcac658SAlexey Kardashevskiy #ifdef CONFIG_PPC64 2014efcac658SAlexey Kardashevskiy WARN_EMULATED_SETUP(mfdscr), 2015efcac658SAlexey Kardashevskiy WARN_EMULATED_SETUP(mtdscr), 2016f83319d7SAnton Blanchard WARN_EMULATED_SETUP(lq_stq), 2017efcac658SAlexey Kardashevskiy #endif 201880947e7cSGeert Uytterhoeven }; 201980947e7cSGeert Uytterhoeven 202080947e7cSGeert Uytterhoeven u32 ppc_warn_emulated; 202180947e7cSGeert Uytterhoeven 202280947e7cSGeert Uytterhoeven void ppc_warn_emulated_print(const char *type) 202380947e7cSGeert Uytterhoeven { 202476462232SChristian Dietrich pr_warn_ratelimited("%s used emulated %s instruction\n", current->comm, 202580947e7cSGeert Uytterhoeven type); 202680947e7cSGeert Uytterhoeven } 202780947e7cSGeert Uytterhoeven 202880947e7cSGeert Uytterhoeven static int __init ppc_warn_emulated_init(void) 202980947e7cSGeert Uytterhoeven { 203080947e7cSGeert Uytterhoeven struct dentry *dir, *d; 203180947e7cSGeert Uytterhoeven unsigned int i; 203280947e7cSGeert Uytterhoeven struct ppc_emulated_entry *entries = (void *)&ppc_emulated; 203380947e7cSGeert Uytterhoeven 203480947e7cSGeert Uytterhoeven if (!powerpc_debugfs_root) 203580947e7cSGeert Uytterhoeven return -ENODEV; 203680947e7cSGeert Uytterhoeven 203780947e7cSGeert Uytterhoeven dir = debugfs_create_dir("emulated_instructions", 203880947e7cSGeert Uytterhoeven powerpc_debugfs_root); 203980947e7cSGeert Uytterhoeven if (!dir) 204080947e7cSGeert Uytterhoeven return -ENOMEM; 204180947e7cSGeert Uytterhoeven 204280947e7cSGeert Uytterhoeven d = debugfs_create_u32("do_warn", S_IRUGO | S_IWUSR, dir, 204380947e7cSGeert Uytterhoeven &ppc_warn_emulated); 204480947e7cSGeert Uytterhoeven if (!d) 204580947e7cSGeert Uytterhoeven goto fail; 204680947e7cSGeert Uytterhoeven 204780947e7cSGeert Uytterhoeven for (i = 0; i < sizeof(ppc_emulated)/sizeof(*entries); i++) { 204880947e7cSGeert Uytterhoeven d = debugfs_create_u32(entries[i].name, S_IRUGO | S_IWUSR, dir, 204980947e7cSGeert Uytterhoeven (u32 *)&entries[i].val.counter); 205080947e7cSGeert Uytterhoeven if (!d) 205180947e7cSGeert Uytterhoeven goto fail; 205280947e7cSGeert Uytterhoeven } 205380947e7cSGeert Uytterhoeven 205480947e7cSGeert Uytterhoeven return 0; 205580947e7cSGeert Uytterhoeven 205680947e7cSGeert Uytterhoeven fail: 205780947e7cSGeert Uytterhoeven debugfs_remove_recursive(dir); 205880947e7cSGeert Uytterhoeven return -ENOMEM; 205980947e7cSGeert Uytterhoeven } 206080947e7cSGeert Uytterhoeven 206180947e7cSGeert Uytterhoeven device_initcall(ppc_warn_emulated_init); 206280947e7cSGeert Uytterhoeven 206380947e7cSGeert Uytterhoeven #endif /* CONFIG_PPC_EMULATED_STATS */ 2064