Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1 | /* |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 2 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
Scott Wood | fe04b11 | 2010-04-08 00:38:22 -0500 | [diff] [blame] | 3 | * Copyright 2007-2010 Freescale Semiconductor, Inc. |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version |
| 8 | * 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * Modified by Cort Dougan (cort@cs.nmt.edu) |
| 11 | * and Paul Mackerras (paulus@samba.org) |
| 12 | */ |
| 13 | |
| 14 | /* |
| 15 | * This file handles the architecture-dependent parts of hardware exceptions |
| 16 | */ |
| 17 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 18 | #include <linux/errno.h> |
| 19 | #include <linux/sched.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/mm.h> |
| 22 | #include <linux/stddef.h> |
| 23 | #include <linux/unistd.h> |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 24 | #include <linux/ptrace.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 25 | #include <linux/user.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 26 | #include <linux/interrupt.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 27 | #include <linux/init.h> |
| 28 | #include <linux/module.h> |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 29 | #include <linux/prctl.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 30 | #include <linux/delay.h> |
| 31 | #include <linux/kprobes.h> |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 32 | #include <linux/kexec.h> |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 33 | #include <linux/backlight.h> |
Jeremy Fitzhardinge | 73c9cea | 2006-12-08 03:30:41 -0800 | [diff] [blame] | 34 | #include <linux/bug.h> |
Christoph Hellwig | 1eeb66a | 2007-05-08 00:27:03 -0700 | [diff] [blame] | 35 | #include <linux/kdebug.h> |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 36 | #include <linux/debugfs.h> |
Christian Dietrich | 7646223 | 2011-06-04 05:36:54 +0000 | [diff] [blame] | 37 | #include <linux/ratelimit.h> |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 38 | #include <linux/context_tracking.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 39 | |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 40 | #include <asm/emulated_ops.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 41 | #include <asm/pgtable.h> |
| 42 | #include <asm/uaccess.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 43 | #include <asm/io.h> |
Paul Mackerras | 8641778 | 2005-10-10 22:37:57 +1000 | [diff] [blame] | 44 | #include <asm/machdep.h> |
| 45 | #include <asm/rtas.h> |
David Gibson | f7f6f4f | 2005-10-19 14:53:32 +1000 | [diff] [blame] | 46 | #include <asm/pmc.h> |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 47 | #ifdef CONFIG_PPC32 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 48 | #include <asm/reg.h> |
Paul Mackerras | 8641778 | 2005-10-10 22:37:57 +1000 | [diff] [blame] | 49 | #endif |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 50 | #ifdef CONFIG_PMAC_BACKLIGHT |
| 51 | #include <asm/backlight.h> |
| 52 | #endif |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 53 | #ifdef CONFIG_PPC64 |
Paul Mackerras | 8641778 | 2005-10-10 22:37:57 +1000 | [diff] [blame] | 54 | #include <asm/firmware.h> |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 55 | #include <asm/processor.h> |
Michael Neuling | 6ce6c62 | 2013-05-26 18:09:39 +0000 | [diff] [blame] | 56 | #include <asm/tm.h> |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 57 | #endif |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 58 | #include <asm/kexec.h> |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 59 | #include <asm/ppc-opcode.h> |
Shaohui Xie | cce1f10 | 2010-11-18 14:57:32 +0800 | [diff] [blame] | 60 | #include <asm/rio.h> |
Mahesh Salgaonkar | ebaeb5a | 2012-02-16 01:14:45 +0000 | [diff] [blame] | 61 | #include <asm/fadump.h> |
David Howells | ae3a197 | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 62 | #include <asm/switch_to.h> |
Michael Neuling | f54db64 | 2013-02-13 16:21:39 +0000 | [diff] [blame] | 63 | #include <asm/tm.h> |
David Howells | ae3a197 | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 64 | #include <asm/debug.h> |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 65 | |
Olof Johansson | 7dbb922 | 2008-01-31 14:34:47 +1100 | [diff] [blame] | 66 | #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC) |
Anton Blanchard | 5be3492 | 2010-01-12 00:50:14 +0000 | [diff] [blame] | 67 | int (*__debugger)(struct pt_regs *regs) __read_mostly; |
| 68 | int (*__debugger_ipi)(struct pt_regs *regs) __read_mostly; |
| 69 | int (*__debugger_bpt)(struct pt_regs *regs) __read_mostly; |
| 70 | int (*__debugger_sstep)(struct pt_regs *regs) __read_mostly; |
| 71 | int (*__debugger_iabr_match)(struct pt_regs *regs) __read_mostly; |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 72 | int (*__debugger_break_match)(struct pt_regs *regs) __read_mostly; |
Anton Blanchard | 5be3492 | 2010-01-12 00:50:14 +0000 | [diff] [blame] | 73 | int (*__debugger_fault_handler)(struct pt_regs *regs) __read_mostly; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 74 | |
| 75 | EXPORT_SYMBOL(__debugger); |
| 76 | EXPORT_SYMBOL(__debugger_ipi); |
| 77 | EXPORT_SYMBOL(__debugger_bpt); |
| 78 | EXPORT_SYMBOL(__debugger_sstep); |
| 79 | EXPORT_SYMBOL(__debugger_iabr_match); |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 80 | EXPORT_SYMBOL(__debugger_break_match); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 81 | EXPORT_SYMBOL(__debugger_fault_handler); |
| 82 | #endif |
| 83 | |
Michael Neuling | 8b3c34c | 2013-02-13 16:21:32 +0000 | [diff] [blame] | 84 | /* Transactional Memory trap debug */ |
| 85 | #ifdef TM_DEBUG_SW |
| 86 | #define TM_DEBUG(x...) printk(KERN_INFO x) |
| 87 | #else |
| 88 | #define TM_DEBUG(x...) do { } while(0) |
| 89 | #endif |
| 90 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 91 | /* |
| 92 | * Trap & Exception support |
| 93 | */ |
| 94 | |
anton@samba.org | 6031d9d | 2007-03-20 20:38:12 -0500 | [diff] [blame] | 95 | #ifdef CONFIG_PMAC_BACKLIGHT |
| 96 | static void pmac_backlight_unblank(void) |
| 97 | { |
| 98 | mutex_lock(&pmac_backlight_mutex); |
| 99 | if (pmac_backlight) { |
| 100 | struct backlight_properties *props; |
| 101 | |
| 102 | props = &pmac_backlight->props; |
| 103 | props->brightness = props->max_brightness; |
| 104 | props->power = FB_BLANK_UNBLANK; |
| 105 | backlight_update_status(pmac_backlight); |
| 106 | } |
| 107 | mutex_unlock(&pmac_backlight_mutex); |
| 108 | } |
| 109 | #else |
| 110 | static inline void pmac_backlight_unblank(void) { } |
| 111 | #endif |
| 112 | |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 113 | static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED; |
| 114 | static int die_owner = -1; |
| 115 | static unsigned int die_nest_count; |
| 116 | static int die_counter; |
| 117 | |
| 118 | static unsigned __kprobes long oops_begin(struct pt_regs *regs) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 119 | { |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 120 | int cpu; |
anton@samba.org | 34c2a14 | 2007-03-20 20:38:13 -0500 | [diff] [blame] | 121 | unsigned long flags; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 122 | |
| 123 | if (debugger(regs)) |
| 124 | return 1; |
| 125 | |
anton@samba.org | 293e468 | 2007-03-20 20:38:11 -0500 | [diff] [blame] | 126 | oops_enter(); |
| 127 | |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 128 | /* racy, but better than risking deadlock. */ |
| 129 | raw_local_irq_save(flags); |
| 130 | cpu = smp_processor_id(); |
| 131 | if (!arch_spin_trylock(&die_lock)) { |
| 132 | if (cpu == die_owner) |
| 133 | /* nested oops. should stop eventually */; |
| 134 | else |
| 135 | arch_spin_lock(&die_lock); |
anton@samba.org | 34c2a14 | 2007-03-20 20:38:13 -0500 | [diff] [blame] | 136 | } |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 137 | die_nest_count++; |
| 138 | die_owner = cpu; |
| 139 | console_verbose(); |
| 140 | bust_spinlocks(1); |
| 141 | if (machine_is(powermac)) |
| 142 | pmac_backlight_unblank(); |
| 143 | return flags; |
| 144 | } |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 145 | |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 146 | static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, |
| 147 | int signr) |
| 148 | { |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 149 | bust_spinlocks(0); |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 150 | die_owner = -1; |
Rusty Russell | 373d4d09 | 2013-01-21 17:17:39 +1030 | [diff] [blame] | 151 | add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE); |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 152 | die_nest_count--; |
Anton Blanchard | 58154c8 | 2011-11-30 00:23:09 +0000 | [diff] [blame] | 153 | oops_exit(); |
| 154 | printk("\n"); |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 155 | if (!die_nest_count) |
| 156 | /* Nest count reaches zero, release the lock. */ |
| 157 | arch_spin_unlock(&die_lock); |
| 158 | raw_local_irq_restore(flags); |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 159 | |
Mahesh Salgaonkar | ebaeb5a | 2012-02-16 01:14:45 +0000 | [diff] [blame] | 160 | crash_fadump(regs, "die oops"); |
| 161 | |
Anton Blanchard | 9b00ac0 | 2011-11-30 00:23:10 +0000 | [diff] [blame] | 162 | /* |
| 163 | * A system reset (0x100) is a request to dump, so we always send |
| 164 | * it through the crashdump code. |
| 165 | */ |
| 166 | if (kexec_should_crash(current) || (TRAP(regs) == 0x100)) { |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 167 | crash_kexec(regs); |
Anton Blanchard | 9b00ac0 | 2011-11-30 00:23:10 +0000 | [diff] [blame] | 168 | |
| 169 | /* |
| 170 | * We aren't the primary crash CPU. We need to send it |
| 171 | * to a holding pattern to avoid it ending up in the panic |
| 172 | * code. |
| 173 | */ |
| 174 | crash_kexec_secondary(regs); |
| 175 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 176 | |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 177 | if (!signr) |
| 178 | return; |
| 179 | |
Anton Blanchard | 58154c8 | 2011-11-30 00:23:09 +0000 | [diff] [blame] | 180 | /* |
| 181 | * While our oops output is serialised by a spinlock, output |
| 182 | * from panic() called below can race and corrupt it. If we |
| 183 | * know we are going to panic, delay for 1 second so we have a |
| 184 | * chance to get clean backtraces from all CPUs that are oopsing. |
| 185 | */ |
| 186 | if (in_interrupt() || panic_on_oops || !current->pid || |
| 187 | is_global_init(current)) { |
| 188 | mdelay(MSEC_PER_SEC); |
| 189 | } |
| 190 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 191 | if (in_interrupt()) |
| 192 | panic("Fatal exception in interrupt"); |
Horms | cea6a4b | 2006-07-30 03:03:34 -0700 | [diff] [blame] | 193 | if (panic_on_oops) |
Horms | 012c437 | 2006-08-13 23:24:22 -0700 | [diff] [blame] | 194 | panic("Fatal exception"); |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 195 | do_exit(signr); |
| 196 | } |
Horms | cea6a4b | 2006-07-30 03:03:34 -0700 | [diff] [blame] | 197 | |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 198 | static int __kprobes __die(const char *str, struct pt_regs *regs, long err) |
| 199 | { |
| 200 | printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter); |
| 201 | #ifdef CONFIG_PREEMPT |
| 202 | printk("PREEMPT "); |
| 203 | #endif |
| 204 | #ifdef CONFIG_SMP |
| 205 | printk("SMP NR_CPUS=%d ", NR_CPUS); |
| 206 | #endif |
| 207 | #ifdef CONFIG_DEBUG_PAGEALLOC |
| 208 | printk("DEBUG_PAGEALLOC "); |
| 209 | #endif |
| 210 | #ifdef CONFIG_NUMA |
| 211 | printk("NUMA "); |
| 212 | #endif |
| 213 | printk("%s\n", ppc_md.name ? ppc_md.name : ""); |
| 214 | |
| 215 | if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV) == NOTIFY_STOP) |
| 216 | return 1; |
| 217 | |
| 218 | print_modules(); |
| 219 | show_regs(regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 220 | |
| 221 | return 0; |
| 222 | } |
| 223 | |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 224 | void die(const char *str, struct pt_regs *regs, long err) |
| 225 | { |
| 226 | unsigned long flags = oops_begin(regs); |
| 227 | |
| 228 | if (__die(str, regs, err)) |
| 229 | err = 0; |
| 230 | oops_end(flags, regs, err); |
| 231 | } |
| 232 | |
Oleg Nesterov | 25baa35 | 2009-12-15 16:47:18 -0800 | [diff] [blame] | 233 | void user_single_step_siginfo(struct task_struct *tsk, |
| 234 | struct pt_regs *regs, siginfo_t *info) |
| 235 | { |
| 236 | memset(info, 0, sizeof(*info)); |
| 237 | info->si_signo = SIGTRAP; |
| 238 | info->si_code = TRAP_TRACE; |
| 239 | info->si_addr = (void __user *)regs->nip; |
| 240 | } |
| 241 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 242 | void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr) |
| 243 | { |
| 244 | siginfo_t info; |
Olof Johansson | d0c3d53 | 2007-10-12 10:20:07 +1000 | [diff] [blame] | 245 | const char fmt32[] = KERN_INFO "%s[%d]: unhandled signal %d " \ |
| 246 | "at %08lx nip %08lx lr %08lx code %x\n"; |
| 247 | const char fmt64[] = KERN_INFO "%s[%d]: unhandled signal %d " \ |
| 248 | "at %016lx nip %016lx lr %016lx code %x\n"; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 249 | |
| 250 | if (!user_mode(regs)) { |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 251 | die("Exception in kernel mode", regs, signr); |
| 252 | return; |
| 253 | } |
| 254 | |
| 255 | if (show_unhandled_signals && unhandled_signal(current, signr)) { |
Christian Dietrich | 7646223 | 2011-06-04 05:36:54 +0000 | [diff] [blame] | 256 | printk_ratelimited(regs->msr & MSR_64BIT ? fmt64 : fmt32, |
| 257 | current->comm, current->pid, signr, |
| 258 | addr, regs->nip, regs->link, code); |
| 259 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 260 | |
Benjamin Herrenschmidt | a3512b2 | 2012-05-08 13:38:50 +1000 | [diff] [blame] | 261 | if (arch_irqs_disabled() && !arch_irq_disabled_regs(regs)) |
Benjamin Herrenschmidt | 9f2f79e | 2012-03-01 15:47:44 +1100 | [diff] [blame] | 262 | local_irq_enable(); |
| 263 | |
Ananth N Mavinakayanahalli | 41ab526 | 2012-08-23 21:27:09 +0000 | [diff] [blame] | 264 | current->thread.trap_nr = code; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 265 | memset(&info, 0, sizeof(info)); |
| 266 | info.si_signo = signr; |
| 267 | info.si_code = code; |
| 268 | info.si_addr = (void __user *) addr; |
| 269 | force_sig_info(signr, &info, current); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | #ifdef CONFIG_PPC64 |
| 273 | void system_reset_exception(struct pt_regs *regs) |
| 274 | { |
| 275 | /* See if any machine dependent calls */ |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 276 | if (ppc_md.system_reset_exception) { |
| 277 | if (ppc_md.system_reset_exception(regs)) |
| 278 | return; |
| 279 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 280 | |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 281 | die("System Reset", regs, SIGABRT); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 282 | |
| 283 | /* Must die if the interrupt is not recoverable */ |
| 284 | if (!(regs->msr & MSR_RI)) |
| 285 | panic("Unrecoverable System Reset"); |
| 286 | |
| 287 | /* What should we do here? We could issue a shutdown or hard reset. */ |
| 288 | } |
| 289 | #endif |
| 290 | |
| 291 | /* |
| 292 | * I/O accesses can cause machine checks on powermacs. |
| 293 | * Check if the NIP corresponds to the address of a sync |
| 294 | * instruction for which there is an entry in the exception |
| 295 | * table. |
| 296 | * Note that the 601 only takes a machine check on TEA |
| 297 | * (transfer error ack) signal assertion, and does not |
| 298 | * set any of the top 16 bits of SRR1. |
| 299 | * -- paulus. |
| 300 | */ |
| 301 | static inline int check_io_access(struct pt_regs *regs) |
| 302 | { |
Benjamin Herrenschmidt | 68a6435 | 2006-11-13 09:27:39 +1100 | [diff] [blame] | 303 | #ifdef CONFIG_PPC32 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 304 | unsigned long msr = regs->msr; |
| 305 | const struct exception_table_entry *entry; |
| 306 | unsigned int *nip = (unsigned int *)regs->nip; |
| 307 | |
| 308 | if (((msr & 0xffff0000) == 0 || (msr & (0x80000 | 0x40000))) |
| 309 | && (entry = search_exception_tables(regs->nip)) != NULL) { |
| 310 | /* |
| 311 | * Check that it's a sync instruction, or somewhere |
| 312 | * in the twi; isync; nop sequence that inb/inw/inl uses. |
| 313 | * As the address is in the exception table |
| 314 | * we should be able to read the instr there. |
| 315 | * For the debug message, we look at the preceding |
| 316 | * load or store. |
| 317 | */ |
| 318 | if (*nip == 0x60000000) /* nop */ |
| 319 | nip -= 2; |
| 320 | else if (*nip == 0x4c00012c) /* isync */ |
| 321 | --nip; |
| 322 | if (*nip == 0x7c0004ac || (*nip >> 26) == 3) { |
| 323 | /* sync or twi */ |
| 324 | unsigned int rb; |
| 325 | |
| 326 | --nip; |
| 327 | rb = (*nip >> 11) & 0x1f; |
| 328 | printk(KERN_DEBUG "%s bad port %lx at %p\n", |
| 329 | (*nip & 0x100)? "OUT to": "IN from", |
| 330 | regs->gpr[rb] - _IO_BASE, nip); |
| 331 | regs->msr |= MSR_RI; |
| 332 | regs->nip = entry->fixup; |
| 333 | return 1; |
| 334 | } |
| 335 | } |
Benjamin Herrenschmidt | 68a6435 | 2006-11-13 09:27:39 +1100 | [diff] [blame] | 336 | #endif /* CONFIG_PPC32 */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 337 | return 0; |
| 338 | } |
| 339 | |
Dave Kleikamp | 172ae2e | 2010-02-08 11:50:57 +0000 | [diff] [blame] | 340 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 341 | /* On 4xx, the reason for the machine check or program exception |
| 342 | is in the ESR. */ |
| 343 | #define get_reason(regs) ((regs)->dsisr) |
| 344 | #ifndef CONFIG_FSL_BOOKE |
| 345 | #define get_mc_reason(regs) ((regs)->dsisr) |
| 346 | #else |
Scott Wood | fe04b11 | 2010-04-08 00:38:22 -0500 | [diff] [blame] | 347 | #define get_mc_reason(regs) (mfspr(SPRN_MCSR)) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 348 | #endif |
| 349 | #define REASON_FP ESR_FP |
| 350 | #define REASON_ILLEGAL (ESR_PIL | ESR_PUO) |
| 351 | #define REASON_PRIVILEGED ESR_PPR |
| 352 | #define REASON_TRAP ESR_PTR |
| 353 | |
| 354 | /* single-step stuff */ |
| 355 | #define single_stepping(regs) (current->thread.dbcr0 & DBCR0_IC) |
| 356 | #define clear_single_step(regs) (current->thread.dbcr0 &= ~DBCR0_IC) |
| 357 | |
| 358 | #else |
| 359 | /* On non-4xx, the reason for the machine check or program |
| 360 | exception is in the MSR. */ |
| 361 | #define get_reason(regs) ((regs)->msr) |
| 362 | #define get_mc_reason(regs) ((regs)->msr) |
Michael Neuling | 8b3c34c | 2013-02-13 16:21:32 +0000 | [diff] [blame] | 363 | #define REASON_TM 0x200000 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 364 | #define REASON_FP 0x100000 |
| 365 | #define REASON_ILLEGAL 0x80000 |
| 366 | #define REASON_PRIVILEGED 0x40000 |
| 367 | #define REASON_TRAP 0x20000 |
| 368 | |
| 369 | #define single_stepping(regs) ((regs)->msr & MSR_SE) |
| 370 | #define clear_single_step(regs) ((regs)->msr &= ~MSR_SE) |
| 371 | #endif |
| 372 | |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 373 | #if defined(CONFIG_4xx) |
| 374 | int machine_check_4xx(struct pt_regs *regs) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 375 | { |
Kumar Gala | 1a6a4ff | 2006-03-30 21:11:15 -0600 | [diff] [blame] | 376 | unsigned long reason = get_mc_reason(regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 377 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 378 | if (reason & ESR_IMCP) { |
| 379 | printk("Instruction"); |
| 380 | mtspr(SPRN_ESR, reason & ~ESR_IMCP); |
| 381 | } else |
| 382 | printk("Data"); |
| 383 | printk(" machine check in kernel mode.\n"); |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 384 | |
| 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | int machine_check_440A(struct pt_regs *regs) |
| 389 | { |
| 390 | unsigned long reason = get_mc_reason(regs); |
| 391 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 392 | printk("Machine check in kernel mode.\n"); |
| 393 | if (reason & ESR_IMCP){ |
| 394 | printk("Instruction Synchronous Machine Check exception\n"); |
| 395 | mtspr(SPRN_ESR, reason & ~ESR_IMCP); |
| 396 | } |
| 397 | else { |
| 398 | u32 mcsr = mfspr(SPRN_MCSR); |
| 399 | if (mcsr & MCSR_IB) |
| 400 | printk("Instruction Read PLB Error\n"); |
| 401 | if (mcsr & MCSR_DRB) |
| 402 | printk("Data Read PLB Error\n"); |
| 403 | if (mcsr & MCSR_DWB) |
| 404 | printk("Data Write PLB Error\n"); |
| 405 | if (mcsr & MCSR_TLBP) |
| 406 | printk("TLB Parity Error\n"); |
| 407 | if (mcsr & MCSR_ICP){ |
| 408 | flush_instruction_cache(); |
| 409 | printk("I-Cache Parity Error\n"); |
| 410 | } |
| 411 | if (mcsr & MCSR_DCSP) |
| 412 | printk("D-Cache Search Parity Error\n"); |
| 413 | if (mcsr & MCSR_DCFP) |
| 414 | printk("D-Cache Flush Parity Error\n"); |
| 415 | if (mcsr & MCSR_IMPE) |
| 416 | printk("Machine Check exception is imprecise\n"); |
| 417 | |
| 418 | /* Clear MCSR */ |
| 419 | mtspr(SPRN_MCSR, mcsr); |
| 420 | } |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 421 | return 0; |
| 422 | } |
Dave Kleikamp | fc5e709 | 2010-03-05 03:43:18 +0000 | [diff] [blame] | 423 | |
| 424 | int machine_check_47x(struct pt_regs *regs) |
| 425 | { |
| 426 | unsigned long reason = get_mc_reason(regs); |
| 427 | u32 mcsr; |
| 428 | |
| 429 | printk(KERN_ERR "Machine check in kernel mode.\n"); |
| 430 | if (reason & ESR_IMCP) { |
| 431 | printk(KERN_ERR |
| 432 | "Instruction Synchronous Machine Check exception\n"); |
| 433 | mtspr(SPRN_ESR, reason & ~ESR_IMCP); |
| 434 | return 0; |
| 435 | } |
| 436 | mcsr = mfspr(SPRN_MCSR); |
| 437 | if (mcsr & MCSR_IB) |
| 438 | printk(KERN_ERR "Instruction Read PLB Error\n"); |
| 439 | if (mcsr & MCSR_DRB) |
| 440 | printk(KERN_ERR "Data Read PLB Error\n"); |
| 441 | if (mcsr & MCSR_DWB) |
| 442 | printk(KERN_ERR "Data Write PLB Error\n"); |
| 443 | if (mcsr & MCSR_TLBP) |
| 444 | printk(KERN_ERR "TLB Parity Error\n"); |
| 445 | if (mcsr & MCSR_ICP) { |
| 446 | flush_instruction_cache(); |
| 447 | printk(KERN_ERR "I-Cache Parity Error\n"); |
| 448 | } |
| 449 | if (mcsr & MCSR_DCSP) |
| 450 | printk(KERN_ERR "D-Cache Search Parity Error\n"); |
| 451 | if (mcsr & PPC47x_MCSR_GPR) |
| 452 | printk(KERN_ERR "GPR Parity Error\n"); |
| 453 | if (mcsr & PPC47x_MCSR_FPR) |
| 454 | printk(KERN_ERR "FPR Parity Error\n"); |
| 455 | if (mcsr & PPC47x_MCSR_IPR) |
| 456 | printk(KERN_ERR "Machine Check exception is imprecise\n"); |
| 457 | |
| 458 | /* Clear MCSR */ |
| 459 | mtspr(SPRN_MCSR, mcsr); |
| 460 | |
| 461 | return 0; |
| 462 | } |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 463 | #elif defined(CONFIG_E500) |
Scott Wood | fe04b11 | 2010-04-08 00:38:22 -0500 | [diff] [blame] | 464 | int machine_check_e500mc(struct pt_regs *regs) |
| 465 | { |
| 466 | unsigned long mcsr = mfspr(SPRN_MCSR); |
| 467 | unsigned long reason = mcsr; |
| 468 | int recoverable = 1; |
| 469 | |
Scott Wood | 82a9a48 | 2011-06-16 14:09:17 -0500 | [diff] [blame] | 470 | if (reason & MCSR_LD) { |
Shaohui Xie | cce1f10 | 2010-11-18 14:57:32 +0800 | [diff] [blame] | 471 | recoverable = fsl_rio_mcheck_exception(regs); |
| 472 | if (recoverable == 1) |
| 473 | goto silent_out; |
| 474 | } |
| 475 | |
Scott Wood | fe04b11 | 2010-04-08 00:38:22 -0500 | [diff] [blame] | 476 | printk("Machine check in kernel mode.\n"); |
| 477 | printk("Caused by (from MCSR=%lx): ", reason); |
| 478 | |
| 479 | if (reason & MCSR_MCP) |
| 480 | printk("Machine Check Signal\n"); |
| 481 | |
| 482 | if (reason & MCSR_ICPERR) { |
| 483 | printk("Instruction Cache Parity Error\n"); |
| 484 | |
| 485 | /* |
| 486 | * This is recoverable by invalidating the i-cache. |
| 487 | */ |
| 488 | mtspr(SPRN_L1CSR1, mfspr(SPRN_L1CSR1) | L1CSR1_ICFI); |
| 489 | while (mfspr(SPRN_L1CSR1) & L1CSR1_ICFI) |
| 490 | ; |
| 491 | |
| 492 | /* |
| 493 | * This will generally be accompanied by an instruction |
| 494 | * fetch error report -- only treat MCSR_IF as fatal |
| 495 | * if it wasn't due to an L1 parity error. |
| 496 | */ |
| 497 | reason &= ~MCSR_IF; |
| 498 | } |
| 499 | |
| 500 | if (reason & MCSR_DCPERR_MC) { |
| 501 | printk("Data Cache Parity Error\n"); |
Kumar Gala | 37caf9f | 2011-08-27 06:14:23 -0500 | [diff] [blame] | 502 | |
| 503 | /* |
| 504 | * In write shadow mode we auto-recover from the error, but it |
| 505 | * may still get logged and cause a machine check. We should |
| 506 | * only treat the non-write shadow case as non-recoverable. |
| 507 | */ |
| 508 | if (!(mfspr(SPRN_L1CSR2) & L1CSR2_DCWS)) |
| 509 | recoverable = 0; |
Scott Wood | fe04b11 | 2010-04-08 00:38:22 -0500 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | if (reason & MCSR_L2MMU_MHIT) { |
| 513 | printk("Hit on multiple TLB entries\n"); |
| 514 | recoverable = 0; |
| 515 | } |
| 516 | |
| 517 | if (reason & MCSR_NMI) |
| 518 | printk("Non-maskable interrupt\n"); |
| 519 | |
| 520 | if (reason & MCSR_IF) { |
| 521 | printk("Instruction Fetch Error Report\n"); |
| 522 | recoverable = 0; |
| 523 | } |
| 524 | |
| 525 | if (reason & MCSR_LD) { |
| 526 | printk("Load Error Report\n"); |
| 527 | recoverable = 0; |
| 528 | } |
| 529 | |
| 530 | if (reason & MCSR_ST) { |
| 531 | printk("Store Error Report\n"); |
| 532 | recoverable = 0; |
| 533 | } |
| 534 | |
| 535 | if (reason & MCSR_LDG) { |
| 536 | printk("Guarded Load Error Report\n"); |
| 537 | recoverable = 0; |
| 538 | } |
| 539 | |
| 540 | if (reason & MCSR_TLBSYNC) |
| 541 | printk("Simultaneous tlbsync operations\n"); |
| 542 | |
| 543 | if (reason & MCSR_BSL2_ERR) { |
| 544 | printk("Level 2 Cache Error\n"); |
| 545 | recoverable = 0; |
| 546 | } |
| 547 | |
| 548 | if (reason & MCSR_MAV) { |
| 549 | u64 addr; |
| 550 | |
| 551 | addr = mfspr(SPRN_MCAR); |
| 552 | addr |= (u64)mfspr(SPRN_MCARU) << 32; |
| 553 | |
| 554 | printk("Machine Check %s Address: %#llx\n", |
| 555 | reason & MCSR_MEA ? "Effective" : "Physical", addr); |
| 556 | } |
| 557 | |
Shaohui Xie | cce1f10 | 2010-11-18 14:57:32 +0800 | [diff] [blame] | 558 | silent_out: |
Scott Wood | fe04b11 | 2010-04-08 00:38:22 -0500 | [diff] [blame] | 559 | mtspr(SPRN_MCSR, mcsr); |
| 560 | return mfspr(SPRN_MCSR) == 0 && recoverable; |
| 561 | } |
| 562 | |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 563 | int machine_check_e500(struct pt_regs *regs) |
| 564 | { |
| 565 | unsigned long reason = get_mc_reason(regs); |
| 566 | |
Shaohui Xie | cce1f10 | 2010-11-18 14:57:32 +0800 | [diff] [blame] | 567 | if (reason & MCSR_BUS_RBERR) { |
| 568 | if (fsl_rio_mcheck_exception(regs)) |
| 569 | return 1; |
| 570 | } |
| 571 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 572 | printk("Machine check in kernel mode.\n"); |
| 573 | printk("Caused by (from MCSR=%lx): ", reason); |
| 574 | |
| 575 | if (reason & MCSR_MCP) |
| 576 | printk("Machine Check Signal\n"); |
| 577 | if (reason & MCSR_ICPERR) |
| 578 | printk("Instruction Cache Parity Error\n"); |
| 579 | if (reason & MCSR_DCP_PERR) |
| 580 | printk("Data Cache Push Parity Error\n"); |
| 581 | if (reason & MCSR_DCPERR) |
| 582 | printk("Data Cache Parity Error\n"); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 583 | if (reason & MCSR_BUS_IAERR) |
| 584 | printk("Bus - Instruction Address Error\n"); |
| 585 | if (reason & MCSR_BUS_RAERR) |
| 586 | printk("Bus - Read Address Error\n"); |
| 587 | if (reason & MCSR_BUS_WAERR) |
| 588 | printk("Bus - Write Address Error\n"); |
| 589 | if (reason & MCSR_BUS_IBERR) |
| 590 | printk("Bus - Instruction Data Error\n"); |
| 591 | if (reason & MCSR_BUS_RBERR) |
| 592 | printk("Bus - Read Data Bus Error\n"); |
| 593 | if (reason & MCSR_BUS_WBERR) |
| 594 | printk("Bus - Read Data Bus Error\n"); |
| 595 | if (reason & MCSR_BUS_IPERR) |
| 596 | printk("Bus - Instruction Parity Error\n"); |
| 597 | if (reason & MCSR_BUS_RPERR) |
| 598 | printk("Bus - Read Parity Error\n"); |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 599 | |
| 600 | return 0; |
| 601 | } |
Kumar Gala | 4490c06 | 2010-10-08 08:32:11 -0500 | [diff] [blame] | 602 | |
| 603 | int machine_check_generic(struct pt_regs *regs) |
| 604 | { |
| 605 | return 0; |
| 606 | } |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 607 | #elif defined(CONFIG_E200) |
| 608 | int machine_check_e200(struct pt_regs *regs) |
| 609 | { |
| 610 | unsigned long reason = get_mc_reason(regs); |
| 611 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 612 | printk("Machine check in kernel mode.\n"); |
| 613 | printk("Caused by (from MCSR=%lx): ", reason); |
| 614 | |
| 615 | if (reason & MCSR_MCP) |
| 616 | printk("Machine Check Signal\n"); |
| 617 | if (reason & MCSR_CP_PERR) |
| 618 | printk("Cache Push Parity Error\n"); |
| 619 | if (reason & MCSR_CPERR) |
| 620 | printk("Cache Parity Error\n"); |
| 621 | if (reason & MCSR_EXCP_ERR) |
| 622 | printk("ISI, ITLB, or Bus Error on first instruction fetch for an exception handler\n"); |
| 623 | if (reason & MCSR_BUS_IRERR) |
| 624 | printk("Bus - Read Bus Error on instruction fetch\n"); |
| 625 | if (reason & MCSR_BUS_DRERR) |
| 626 | printk("Bus - Read Bus Error on data load\n"); |
| 627 | if (reason & MCSR_BUS_WRERR) |
| 628 | printk("Bus - Write Bus Error on buffered store or cache line push\n"); |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 629 | |
| 630 | return 0; |
| 631 | } |
| 632 | #else |
| 633 | int machine_check_generic(struct pt_regs *regs) |
| 634 | { |
| 635 | unsigned long reason = get_mc_reason(regs); |
| 636 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 637 | printk("Machine check in kernel mode.\n"); |
| 638 | printk("Caused by (from SRR1=%lx): ", reason); |
| 639 | switch (reason & 0x601F0000) { |
| 640 | case 0x80000: |
| 641 | printk("Machine check signal\n"); |
| 642 | break; |
| 643 | case 0: /* for 601 */ |
| 644 | case 0x40000: |
| 645 | case 0x140000: /* 7450 MSS error and TEA */ |
| 646 | printk("Transfer error ack signal\n"); |
| 647 | break; |
| 648 | case 0x20000: |
| 649 | printk("Data parity error signal\n"); |
| 650 | break; |
| 651 | case 0x10000: |
| 652 | printk("Address parity error signal\n"); |
| 653 | break; |
| 654 | case 0x20000000: |
| 655 | printk("L1 Data Cache error\n"); |
| 656 | break; |
| 657 | case 0x40000000: |
| 658 | printk("L1 Instruction Cache error\n"); |
| 659 | break; |
| 660 | case 0x00100000: |
| 661 | printk("L2 data cache parity error\n"); |
| 662 | break; |
| 663 | default: |
| 664 | printk("Unknown values in msr\n"); |
| 665 | } |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 666 | return 0; |
| 667 | } |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 668 | #endif /* everything else */ |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 669 | |
| 670 | void machine_check_exception(struct pt_regs *regs) |
| 671 | { |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 672 | enum ctx_state prev_state = exception_enter(); |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 673 | int recover = 0; |
| 674 | |
Anton Blanchard | 89713ed | 2010-01-31 20:34:06 +0000 | [diff] [blame] | 675 | __get_cpu_var(irq_stat).mce_exceptions++; |
| 676 | |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 677 | /* See if any machine dependent calls. In theory, we would want |
| 678 | * to call the CPU first, and call the ppc_md. one if the CPU |
| 679 | * one returns a positive number. However there is existing code |
| 680 | * that assumes the board gets a first chance, so let's keep it |
| 681 | * that way for now and fix things later. --BenH. |
| 682 | */ |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 683 | if (ppc_md.machine_check_exception) |
| 684 | recover = ppc_md.machine_check_exception(regs); |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 685 | else if (cur_cpu_spec->machine_check) |
| 686 | recover = cur_cpu_spec->machine_check(regs); |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 687 | |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 688 | if (recover > 0) |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 689 | goto bail; |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 690 | |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 691 | #if defined(CONFIG_8xx) && defined(CONFIG_PCI) |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 692 | /* the qspan pci read routines can cause machine checks -- Cort |
| 693 | * |
| 694 | * yuck !!! that totally needs to go away ! There are better ways |
| 695 | * to deal with that than having a wart in the mcheck handler. |
| 696 | * -- BenH |
| 697 | */ |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 698 | bad_page_fault(regs, regs->dar, SIGBUS); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 699 | goto bail; |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 700 | #endif |
| 701 | |
Anton Blanchard | a443506 | 2011-01-11 19:45:31 +0000 | [diff] [blame] | 702 | if (debugger_fault_handler(regs)) |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 703 | goto bail; |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 704 | |
| 705 | if (check_io_access(regs)) |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 706 | goto bail; |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 707 | |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 708 | die("Machine check", regs, SIGBUS); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 709 | |
| 710 | /* Must die if the interrupt is not recoverable */ |
| 711 | if (!(regs->msr & MSR_RI)) |
| 712 | panic("Unrecoverable Machine check"); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 713 | |
| 714 | bail: |
| 715 | exception_exit(prev_state); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | void SMIException(struct pt_regs *regs) |
| 719 | { |
| 720 | die("System Management Interrupt", regs, SIGABRT); |
| 721 | } |
| 722 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 723 | void unknown_exception(struct pt_regs *regs) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 724 | { |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 725 | enum ctx_state prev_state = exception_enter(); |
| 726 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 727 | printk("Bad trap at PC: %lx, SR: %lx, vector=%lx\n", |
| 728 | regs->nip, regs->msr, regs->trap); |
| 729 | |
| 730 | _exception(SIGTRAP, regs, 0, 0); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 731 | |
| 732 | exception_exit(prev_state); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 733 | } |
| 734 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 735 | void instruction_breakpoint_exception(struct pt_regs *regs) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 736 | { |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 737 | enum ctx_state prev_state = exception_enter(); |
| 738 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 739 | if (notify_die(DIE_IABR_MATCH, "iabr_match", regs, 5, |
| 740 | 5, SIGTRAP) == NOTIFY_STOP) |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 741 | goto bail; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 742 | if (debugger_iabr_match(regs)) |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 743 | goto bail; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 744 | _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 745 | |
| 746 | bail: |
| 747 | exception_exit(prev_state); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | void RunModeException(struct pt_regs *regs) |
| 751 | { |
| 752 | _exception(SIGTRAP, regs, 0, 0); |
| 753 | } |
| 754 | |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 755 | void __kprobes single_step_exception(struct pt_regs *regs) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 756 | { |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 757 | enum ctx_state prev_state = exception_enter(); |
| 758 | |
K.Prasad | 2538c2d | 2010-06-15 11:35:31 +0530 | [diff] [blame] | 759 | clear_single_step(regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 760 | |
| 761 | if (notify_die(DIE_SSTEP, "single_step", regs, 5, |
| 762 | 5, SIGTRAP) == NOTIFY_STOP) |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 763 | goto bail; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 764 | if (debugger_sstep(regs)) |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 765 | goto bail; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 766 | |
| 767 | _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 768 | |
| 769 | bail: |
| 770 | exception_exit(prev_state); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | /* |
| 774 | * After we have successfully emulated an instruction, we have to |
| 775 | * check if the instruction was being single-stepped, and if so, |
| 776 | * pretend we got a single-step exception. This was pointed out |
| 777 | * by Kumar Gala. -- paulus |
| 778 | */ |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 779 | static void emulate_single_step(struct pt_regs *regs) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 780 | { |
K.Prasad | 2538c2d | 2010-06-15 11:35:31 +0530 | [diff] [blame] | 781 | if (single_stepping(regs)) |
| 782 | single_step_exception(regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 783 | } |
| 784 | |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 785 | static inline int __parse_fpscr(unsigned long fpscr) |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 786 | { |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 787 | int ret = 0; |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 788 | |
| 789 | /* Invalid operation */ |
| 790 | if ((fpscr & FPSCR_VE) && (fpscr & FPSCR_VX)) |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 791 | ret = FPE_FLTINV; |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 792 | |
| 793 | /* Overflow */ |
| 794 | else if ((fpscr & FPSCR_OE) && (fpscr & FPSCR_OX)) |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 795 | ret = FPE_FLTOVF; |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 796 | |
| 797 | /* Underflow */ |
| 798 | else if ((fpscr & FPSCR_UE) && (fpscr & FPSCR_UX)) |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 799 | ret = FPE_FLTUND; |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 800 | |
| 801 | /* Divide by zero */ |
| 802 | else if ((fpscr & FPSCR_ZE) && (fpscr & FPSCR_ZX)) |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 803 | ret = FPE_FLTDIV; |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 804 | |
| 805 | /* Inexact result */ |
| 806 | else if ((fpscr & FPSCR_XE) && (fpscr & FPSCR_XX)) |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 807 | ret = FPE_FLTRES; |
| 808 | |
| 809 | return ret; |
| 810 | } |
| 811 | |
| 812 | static void parse_fpe(struct pt_regs *regs) |
| 813 | { |
| 814 | int code = 0; |
| 815 | |
| 816 | flush_fp_to_thread(current); |
| 817 | |
| 818 | code = __parse_fpscr(current->thread.fpscr.val); |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 819 | |
| 820 | _exception(SIGFPE, regs, code, regs->nip); |
| 821 | } |
| 822 | |
| 823 | /* |
| 824 | * Illegal instruction emulation support. Originally written to |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 825 | * provide the PVR to user applications using the mfspr rd, PVR. |
| 826 | * Return non-zero if we can't emulate, or -EFAULT if the associated |
| 827 | * memory access caused an access fault. Return zero on success. |
| 828 | * |
| 829 | * There are a couple of ways to do this, either "decode" the instruction |
| 830 | * or directly match lots of bits. In this case, matching lots of |
| 831 | * bits is faster and easier. |
Paul Mackerras | 8641778 | 2005-10-10 22:37:57 +1000 | [diff] [blame] | 832 | * |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 833 | */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 834 | static int emulate_string_inst(struct pt_regs *regs, u32 instword) |
| 835 | { |
| 836 | u8 rT = (instword >> 21) & 0x1f; |
| 837 | u8 rA = (instword >> 16) & 0x1f; |
| 838 | u8 NB_RB = (instword >> 11) & 0x1f; |
| 839 | u32 num_bytes; |
| 840 | unsigned long EA; |
| 841 | int pos = 0; |
| 842 | |
| 843 | /* Early out if we are an invalid form of lswx */ |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 844 | if ((instword & PPC_INST_STRING_MASK) == PPC_INST_LSWX) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 845 | if ((rT == rA) || (rT == NB_RB)) |
| 846 | return -EINVAL; |
| 847 | |
| 848 | EA = (rA == 0) ? 0 : regs->gpr[rA]; |
| 849 | |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 850 | switch (instword & PPC_INST_STRING_MASK) { |
| 851 | case PPC_INST_LSWX: |
| 852 | case PPC_INST_STSWX: |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 853 | EA += NB_RB; |
| 854 | num_bytes = regs->xer & 0x7f; |
| 855 | break; |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 856 | case PPC_INST_LSWI: |
| 857 | case PPC_INST_STSWI: |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 858 | num_bytes = (NB_RB == 0) ? 32 : NB_RB; |
| 859 | break; |
| 860 | default: |
| 861 | return -EINVAL; |
| 862 | } |
| 863 | |
| 864 | while (num_bytes != 0) |
| 865 | { |
| 866 | u8 val; |
| 867 | u32 shift = 8 * (3 - (pos & 0x3)); |
| 868 | |
James Yang | 80aa0fb | 2013-06-25 11:41:05 -0500 | [diff] [blame] | 869 | /* if process is 32-bit, clear upper 32 bits of EA */ |
| 870 | if ((regs->msr & MSR_64BIT) == 0) |
| 871 | EA &= 0xFFFFFFFF; |
| 872 | |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 873 | switch ((instword & PPC_INST_STRING_MASK)) { |
| 874 | case PPC_INST_LSWX: |
| 875 | case PPC_INST_LSWI: |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 876 | if (get_user(val, (u8 __user *)EA)) |
| 877 | return -EFAULT; |
| 878 | /* first time updating this reg, |
| 879 | * zero it out */ |
| 880 | if (pos == 0) |
| 881 | regs->gpr[rT] = 0; |
| 882 | regs->gpr[rT] |= val << shift; |
| 883 | break; |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 884 | case PPC_INST_STSWI: |
| 885 | case PPC_INST_STSWX: |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 886 | val = regs->gpr[rT] >> shift; |
| 887 | if (put_user(val, (u8 __user *)EA)) |
| 888 | return -EFAULT; |
| 889 | break; |
| 890 | } |
| 891 | /* move EA to next address */ |
| 892 | EA += 1; |
| 893 | num_bytes--; |
| 894 | |
| 895 | /* manage our position within the register */ |
| 896 | if (++pos == 4) { |
| 897 | pos = 0; |
| 898 | if (++rT == 32) |
| 899 | rT = 0; |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | return 0; |
| 904 | } |
| 905 | |
Will Schmidt | c3412dc | 2006-08-30 13:11:38 -0500 | [diff] [blame] | 906 | static int emulate_popcntb_inst(struct pt_regs *regs, u32 instword) |
| 907 | { |
| 908 | u32 ra,rs; |
| 909 | unsigned long tmp; |
| 910 | |
| 911 | ra = (instword >> 16) & 0x1f; |
| 912 | rs = (instword >> 21) & 0x1f; |
| 913 | |
| 914 | tmp = regs->gpr[rs]; |
| 915 | tmp = tmp - ((tmp >> 1) & 0x5555555555555555ULL); |
| 916 | tmp = (tmp & 0x3333333333333333ULL) + ((tmp >> 2) & 0x3333333333333333ULL); |
| 917 | tmp = (tmp + (tmp >> 4)) & 0x0f0f0f0f0f0f0f0fULL; |
| 918 | regs->gpr[ra] = tmp; |
| 919 | |
| 920 | return 0; |
| 921 | } |
| 922 | |
Kumar Gala | c1469f1 | 2007-11-19 21:35:29 -0600 | [diff] [blame] | 923 | static int emulate_isel(struct pt_regs *regs, u32 instword) |
| 924 | { |
| 925 | u8 rT = (instword >> 21) & 0x1f; |
| 926 | u8 rA = (instword >> 16) & 0x1f; |
| 927 | u8 rB = (instword >> 11) & 0x1f; |
| 928 | u8 BC = (instword >> 6) & 0x1f; |
| 929 | u8 bit; |
| 930 | unsigned long tmp; |
| 931 | |
| 932 | tmp = (rA == 0) ? 0 : regs->gpr[rA]; |
| 933 | bit = (regs->ccr >> (31 - BC)) & 0x1; |
| 934 | |
| 935 | regs->gpr[rT] = bit ? tmp : regs->gpr[rB]; |
| 936 | |
| 937 | return 0; |
| 938 | } |
| 939 | |
Michael Neuling | 6ce6c62 | 2013-05-26 18:09:39 +0000 | [diff] [blame] | 940 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
| 941 | static inline bool tm_abort_check(struct pt_regs *regs, int cause) |
| 942 | { |
| 943 | /* If we're emulating a load/store in an active transaction, we cannot |
| 944 | * emulate it as the kernel operates in transaction suspended context. |
| 945 | * We need to abort the transaction. This creates a persistent TM |
| 946 | * abort so tell the user what caused it with a new code. |
| 947 | */ |
| 948 | if (MSR_TM_TRANSACTIONAL(regs->msr)) { |
| 949 | tm_enable(); |
| 950 | tm_abort(cause); |
| 951 | return true; |
| 952 | } |
| 953 | return false; |
| 954 | } |
| 955 | #else |
| 956 | static inline bool tm_abort_check(struct pt_regs *regs, int reason) |
| 957 | { |
| 958 | return false; |
| 959 | } |
| 960 | #endif |
| 961 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 962 | static int emulate_instruction(struct pt_regs *regs) |
| 963 | { |
| 964 | u32 instword; |
| 965 | u32 rd; |
| 966 | |
Paul Mackerras | fab5db9 | 2006-06-07 16:14:40 +1000 | [diff] [blame] | 967 | if (!user_mode(regs) || (regs->msr & MSR_LE)) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 968 | return -EINVAL; |
| 969 | CHECK_FULL_REGS(regs); |
| 970 | |
| 971 | if (get_user(instword, (u32 __user *)(regs->nip))) |
| 972 | return -EFAULT; |
| 973 | |
| 974 | /* Emulate the mfspr rD, PVR. */ |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 975 | if ((instword & PPC_INST_MFSPR_PVR_MASK) == PPC_INST_MFSPR_PVR) { |
Anton Blanchard | eecff81 | 2009-10-27 18:46:55 +0000 | [diff] [blame] | 976 | PPC_WARN_EMULATED(mfpvr, regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 977 | rd = (instword >> 21) & 0x1f; |
| 978 | regs->gpr[rd] = mfspr(SPRN_PVR); |
| 979 | return 0; |
| 980 | } |
| 981 | |
| 982 | /* Emulating the dcba insn is just a no-op. */ |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 983 | if ((instword & PPC_INST_DCBA_MASK) == PPC_INST_DCBA) { |
Anton Blanchard | eecff81 | 2009-10-27 18:46:55 +0000 | [diff] [blame] | 984 | PPC_WARN_EMULATED(dcba, regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 985 | return 0; |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 986 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 987 | |
| 988 | /* Emulate the mcrxr insn. */ |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 989 | if ((instword & PPC_INST_MCRXR_MASK) == PPC_INST_MCRXR) { |
Paul Mackerras | 8641778 | 2005-10-10 22:37:57 +1000 | [diff] [blame] | 990 | int shift = (instword >> 21) & 0x1c; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 991 | unsigned long msk = 0xf0000000UL >> shift; |
| 992 | |
Anton Blanchard | eecff81 | 2009-10-27 18:46:55 +0000 | [diff] [blame] | 993 | PPC_WARN_EMULATED(mcrxr, regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 994 | regs->ccr = (regs->ccr & ~msk) | ((regs->xer >> shift) & msk); |
| 995 | regs->xer &= ~0xf0000000UL; |
| 996 | return 0; |
| 997 | } |
| 998 | |
| 999 | /* Emulate load/store string insn. */ |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 1000 | if ((instword & PPC_INST_STRING_GEN_MASK) == PPC_INST_STRING) { |
Michael Neuling | 6ce6c62 | 2013-05-26 18:09:39 +0000 | [diff] [blame] | 1001 | if (tm_abort_check(regs, |
| 1002 | TM_CAUSE_EMULATE | TM_CAUSE_PERSISTENT)) |
| 1003 | return -EINVAL; |
Anton Blanchard | eecff81 | 2009-10-27 18:46:55 +0000 | [diff] [blame] | 1004 | PPC_WARN_EMULATED(string, regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1005 | return emulate_string_inst(regs, instword); |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 1006 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1007 | |
Will Schmidt | c3412dc | 2006-08-30 13:11:38 -0500 | [diff] [blame] | 1008 | /* Emulate the popcntb (Population Count Bytes) instruction. */ |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 1009 | if ((instword & PPC_INST_POPCNTB_MASK) == PPC_INST_POPCNTB) { |
Anton Blanchard | eecff81 | 2009-10-27 18:46:55 +0000 | [diff] [blame] | 1010 | PPC_WARN_EMULATED(popcntb, regs); |
Will Schmidt | c3412dc | 2006-08-30 13:11:38 -0500 | [diff] [blame] | 1011 | return emulate_popcntb_inst(regs, instword); |
| 1012 | } |
| 1013 | |
Kumar Gala | c1469f1 | 2007-11-19 21:35:29 -0600 | [diff] [blame] | 1014 | /* Emulate isel (Integer Select) instruction */ |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 1015 | if ((instword & PPC_INST_ISEL_MASK) == PPC_INST_ISEL) { |
Anton Blanchard | eecff81 | 2009-10-27 18:46:55 +0000 | [diff] [blame] | 1016 | PPC_WARN_EMULATED(isel, regs); |
Kumar Gala | c1469f1 | 2007-11-19 21:35:29 -0600 | [diff] [blame] | 1017 | return emulate_isel(regs, instword); |
| 1018 | } |
| 1019 | |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 1020 | #ifdef CONFIG_PPC64 |
| 1021 | /* Emulate the mfspr rD, DSCR. */ |
Anton Blanchard | 73d2fb7 | 2013-05-01 20:06:33 +0000 | [diff] [blame] | 1022 | if ((((instword & PPC_INST_MFSPR_DSCR_USER_MASK) == |
| 1023 | PPC_INST_MFSPR_DSCR_USER) || |
| 1024 | ((instword & PPC_INST_MFSPR_DSCR_MASK) == |
| 1025 | PPC_INST_MFSPR_DSCR)) && |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 1026 | cpu_has_feature(CPU_FTR_DSCR)) { |
| 1027 | PPC_WARN_EMULATED(mfdscr, regs); |
| 1028 | rd = (instword >> 21) & 0x1f; |
| 1029 | regs->gpr[rd] = mfspr(SPRN_DSCR); |
| 1030 | return 0; |
| 1031 | } |
| 1032 | /* Emulate the mtspr DSCR, rD. */ |
Anton Blanchard | 73d2fb7 | 2013-05-01 20:06:33 +0000 | [diff] [blame] | 1033 | if ((((instword & PPC_INST_MTSPR_DSCR_USER_MASK) == |
| 1034 | PPC_INST_MTSPR_DSCR_USER) || |
| 1035 | ((instword & PPC_INST_MTSPR_DSCR_MASK) == |
| 1036 | PPC_INST_MTSPR_DSCR)) && |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 1037 | cpu_has_feature(CPU_FTR_DSCR)) { |
| 1038 | PPC_WARN_EMULATED(mtdscr, regs); |
| 1039 | rd = (instword >> 21) & 0x1f; |
Anton Blanchard | 00ca0de | 2012-09-03 16:48:46 +0000 | [diff] [blame] | 1040 | current->thread.dscr = regs->gpr[rd]; |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 1041 | current->thread.dscr_inherit = 1; |
Anton Blanchard | 00ca0de | 2012-09-03 16:48:46 +0000 | [diff] [blame] | 1042 | mtspr(SPRN_DSCR, current->thread.dscr); |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 1043 | return 0; |
| 1044 | } |
| 1045 | #endif |
| 1046 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1047 | return -EINVAL; |
| 1048 | } |
| 1049 | |
Jeremy Fitzhardinge | 73c9cea | 2006-12-08 03:30:41 -0800 | [diff] [blame] | 1050 | int is_valid_bugaddr(unsigned long addr) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1051 | { |
Jeremy Fitzhardinge | 73c9cea | 2006-12-08 03:30:41 -0800 | [diff] [blame] | 1052 | return is_kernel_addr(addr); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1053 | } |
| 1054 | |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 1055 | void __kprobes program_check_exception(struct pt_regs *regs) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1056 | { |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1057 | enum ctx_state prev_state = exception_enter(); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1058 | unsigned int reason = get_reason(regs); |
| 1059 | extern int do_mathemu(struct pt_regs *regs); |
| 1060 | |
Kim Phillips | aa42c69 | 2006-12-08 02:43:30 -0600 | [diff] [blame] | 1061 | /* We can now get here via a FP Unavailable exception if the core |
Kumar Gala | 04903a3 | 2007-02-07 01:13:32 -0600 | [diff] [blame] | 1062 | * has no FPU, in that case the reason flags will be 0 */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1063 | |
| 1064 | if (reason & REASON_FP) { |
| 1065 | /* IEEE FP exception */ |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1066 | parse_fpe(regs); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1067 | goto bail; |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 1068 | } |
| 1069 | if (reason & REASON_TRAP) { |
Jason Wessel | ba797b2 | 2010-05-20 21:04:25 -0500 | [diff] [blame] | 1070 | /* Debugger is first in line to stop recursive faults in |
| 1071 | * rcu_lock, notify_die, or atomic_notifier_call_chain */ |
| 1072 | if (debugger_bpt(regs)) |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1073 | goto bail; |
Jason Wessel | ba797b2 | 2010-05-20 21:04:25 -0500 | [diff] [blame] | 1074 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1075 | /* trap exception */ |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1076 | if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP) |
| 1077 | == NOTIFY_STOP) |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1078 | goto bail; |
Jeremy Fitzhardinge | 73c9cea | 2006-12-08 03:30:41 -0800 | [diff] [blame] | 1079 | |
| 1080 | if (!(regs->msr & MSR_PR) && /* not user-mode */ |
Heiko Carstens | 608e261 | 2007-07-15 23:41:39 -0700 | [diff] [blame] | 1081 | report_bug(regs->nip, regs) == BUG_TRAP_TYPE_WARN) { |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1082 | regs->nip += 4; |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1083 | goto bail; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1084 | } |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 1085 | _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1086 | goto bail; |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 1087 | } |
Michael Neuling | bc2a940 | 2013-02-13 16:21:40 +0000 | [diff] [blame] | 1088 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
| 1089 | if (reason & REASON_TM) { |
| 1090 | /* This is a TM "Bad Thing Exception" program check. |
| 1091 | * This occurs when: |
| 1092 | * - An rfid/hrfid/mtmsrd attempts to cause an illegal |
| 1093 | * transition in TM states. |
| 1094 | * - A trechkpt is attempted when transactional. |
| 1095 | * - A treclaim is attempted when non transactional. |
| 1096 | * - A tend is illegally attempted. |
| 1097 | * - writing a TM SPR when transactional. |
| 1098 | */ |
| 1099 | if (!user_mode(regs) && |
| 1100 | report_bug(regs->nip, regs) == BUG_TRAP_TYPE_WARN) { |
| 1101 | regs->nip += 4; |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1102 | goto bail; |
Michael Neuling | bc2a940 | 2013-02-13 16:21:40 +0000 | [diff] [blame] | 1103 | } |
| 1104 | /* If usermode caused this, it's done something illegal and |
| 1105 | * gets a SIGILL slap on the wrist. We call it an illegal |
| 1106 | * operand to distinguish from the instruction just being bad |
| 1107 | * (e.g. executing a 'tend' on a CPU without TM!); it's an |
| 1108 | * illegal /placement/ of a valid instruction. |
| 1109 | */ |
| 1110 | if (user_mode(regs)) { |
| 1111 | _exception(SIGILL, regs, ILL_ILLOPN, regs->nip); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1112 | goto bail; |
Michael Neuling | bc2a940 | 2013-02-13 16:21:40 +0000 | [diff] [blame] | 1113 | } else { |
| 1114 | printk(KERN_EMERG "Unexpected TM Bad Thing exception " |
| 1115 | "at %lx (msr 0x%x)\n", regs->nip, reason); |
| 1116 | die("Unrecoverable exception", regs, SIGABRT); |
| 1117 | } |
| 1118 | } |
| 1119 | #endif |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 1120 | |
Benjamin Herrenschmidt | a3512b2 | 2012-05-08 13:38:50 +1000 | [diff] [blame] | 1121 | /* We restore the interrupt state now */ |
| 1122 | if (!arch_irq_disabled_regs(regs)) |
| 1123 | local_irq_enable(); |
Paul Mackerras | cd8a567 | 2006-03-03 17:11:40 +1100 | [diff] [blame] | 1124 | |
Kumar Gala | 04903a3 | 2007-02-07 01:13:32 -0600 | [diff] [blame] | 1125 | #ifdef CONFIG_MATH_EMULATION |
| 1126 | /* (reason & REASON_ILLEGAL) would be the obvious thing here, |
| 1127 | * but there seems to be a hardware bug on the 405GP (RevD) |
| 1128 | * that means ESR is sometimes set incorrectly - either to |
| 1129 | * ESR_DST (!?) or 0. In the process of chasing this with the |
| 1130 | * hardware people - not sure if it can happen on any illegal |
| 1131 | * instruction or only on FP instructions, whether there is a |
Benjamin Herrenschmidt | 4e63f8e | 2013-06-09 17:01:24 +1000 | [diff] [blame] | 1132 | * pattern to occurrences etc. -dgibson 31/Mar/2003 |
| 1133 | */ |
| 1134 | |
| 1135 | /* |
| 1136 | * If we support a HW FPU, we need to ensure the FP state |
| 1137 | * if flushed into the thread_struct before attempting |
| 1138 | * emulation |
| 1139 | */ |
| 1140 | #ifdef CONFIG_PPC_FPU |
| 1141 | flush_fp_to_thread(current); |
| 1142 | #endif |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 1143 | switch (do_mathemu(regs)) { |
| 1144 | case 0: |
Kumar Gala | 04903a3 | 2007-02-07 01:13:32 -0600 | [diff] [blame] | 1145 | emulate_single_step(regs); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1146 | goto bail; |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 1147 | case 1: { |
| 1148 | int code = 0; |
| 1149 | code = __parse_fpscr(current->thread.fpscr.val); |
| 1150 | _exception(SIGFPE, regs, code, regs->nip); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1151 | goto bail; |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 1152 | } |
| 1153 | case -EFAULT: |
| 1154 | _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1155 | goto bail; |
Kumar Gala | 04903a3 | 2007-02-07 01:13:32 -0600 | [diff] [blame] | 1156 | } |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 1157 | /* fall through on any other errors */ |
Kumar Gala | 04903a3 | 2007-02-07 01:13:32 -0600 | [diff] [blame] | 1158 | #endif /* CONFIG_MATH_EMULATION */ |
| 1159 | |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 1160 | /* Try to emulate it if we should. */ |
| 1161 | if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED)) { |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1162 | switch (emulate_instruction(regs)) { |
| 1163 | case 0: |
| 1164 | regs->nip += 4; |
| 1165 | emulate_single_step(regs); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1166 | goto bail; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1167 | case -EFAULT: |
| 1168 | _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1169 | goto bail; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1170 | } |
| 1171 | } |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 1172 | |
| 1173 | if (reason & REASON_PRIVILEGED) |
| 1174 | _exception(SIGILL, regs, ILL_PRVOPC, regs->nip); |
| 1175 | else |
| 1176 | _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1177 | |
| 1178 | bail: |
| 1179 | exception_exit(prev_state); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1180 | } |
| 1181 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1182 | void alignment_exception(struct pt_regs *regs) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1183 | { |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1184 | enum ctx_state prev_state = exception_enter(); |
Benjamin Herrenschmidt | 4393c4f | 2006-11-01 15:11:39 +1100 | [diff] [blame] | 1185 | int sig, code, fixed = 0; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1186 | |
Benjamin Herrenschmidt | a3512b2 | 2012-05-08 13:38:50 +1000 | [diff] [blame] | 1187 | /* We restore the interrupt state now */ |
| 1188 | if (!arch_irq_disabled_regs(regs)) |
| 1189 | local_irq_enable(); |
| 1190 | |
Michael Neuling | 6ce6c62 | 2013-05-26 18:09:39 +0000 | [diff] [blame] | 1191 | if (tm_abort_check(regs, TM_CAUSE_ALIGNMENT | TM_CAUSE_PERSISTENT)) |
| 1192 | goto bail; |
| 1193 | |
Paul Mackerras | e9370ae | 2006-06-07 16:15:39 +1000 | [diff] [blame] | 1194 | /* we don't implement logging of alignment exceptions */ |
| 1195 | if (!(current->thread.align_ctl & PR_UNALIGN_SIGBUS)) |
| 1196 | fixed = fix_alignment(regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1197 | |
| 1198 | if (fixed == 1) { |
| 1199 | regs->nip += 4; /* skip over emulated instruction */ |
| 1200 | emulate_single_step(regs); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1201 | goto bail; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1202 | } |
| 1203 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1204 | /* Operand address was bad */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1205 | if (fixed == -EFAULT) { |
Benjamin Herrenschmidt | 4393c4f | 2006-11-01 15:11:39 +1100 | [diff] [blame] | 1206 | sig = SIGSEGV; |
| 1207 | code = SEGV_ACCERR; |
| 1208 | } else { |
| 1209 | sig = SIGBUS; |
| 1210 | code = BUS_ADRALN; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1211 | } |
Benjamin Herrenschmidt | 4393c4f | 2006-11-01 15:11:39 +1100 | [diff] [blame] | 1212 | if (user_mode(regs)) |
| 1213 | _exception(sig, regs, code, regs->dar); |
| 1214 | else |
| 1215 | bad_page_fault(regs, regs->dar, sig); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1216 | |
| 1217 | bail: |
| 1218 | exception_exit(prev_state); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | void StackOverflow(struct pt_regs *regs) |
| 1222 | { |
| 1223 | printk(KERN_CRIT "Kernel stack overflow in process %p, r1=%lx\n", |
| 1224 | current, regs->gpr[1]); |
| 1225 | debugger(regs); |
| 1226 | show_regs(regs); |
| 1227 | panic("kernel stack overflow"); |
| 1228 | } |
| 1229 | |
| 1230 | void nonrecoverable_exception(struct pt_regs *regs) |
| 1231 | { |
| 1232 | printk(KERN_ERR "Non-recoverable exception at PC=%lx MSR=%lx\n", |
| 1233 | regs->nip, regs->msr); |
| 1234 | debugger(regs); |
| 1235 | die("nonrecoverable exception", regs, SIGKILL); |
| 1236 | } |
| 1237 | |
| 1238 | void trace_syscall(struct pt_regs *regs) |
| 1239 | { |
| 1240 | printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n", |
Alexey Dobriyan | 19c5870 | 2007-10-18 23:40:41 -0700 | [diff] [blame] | 1241 | current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0], |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1242 | regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted()); |
| 1243 | } |
| 1244 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1245 | void kernel_fp_unavailable_exception(struct pt_regs *regs) |
| 1246 | { |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1247 | enum ctx_state prev_state = exception_enter(); |
| 1248 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1249 | printk(KERN_EMERG "Unrecoverable FP Unavailable Exception " |
| 1250 | "%lx at %lx\n", regs->trap, regs->nip); |
| 1251 | die("Unrecoverable FP Unavailable Exception", regs, SIGABRT); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1252 | |
| 1253 | exception_exit(prev_state); |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1254 | } |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1255 | |
| 1256 | void altivec_unavailable_exception(struct pt_regs *regs) |
| 1257 | { |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1258 | enum ctx_state prev_state = exception_enter(); |
| 1259 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1260 | if (user_mode(regs)) { |
| 1261 | /* A user program has executed an altivec instruction, |
| 1262 | but this kernel doesn't support altivec. */ |
| 1263 | _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1264 | goto bail; |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1265 | } |
Anton Blanchard | 6c4841c | 2006-10-13 11:41:00 +1000 | [diff] [blame] | 1266 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1267 | printk(KERN_EMERG "Unrecoverable VMX/Altivec Unavailable Exception " |
| 1268 | "%lx at %lx\n", regs->trap, regs->nip); |
| 1269 | die("Unrecoverable VMX/Altivec Unavailable Exception", regs, SIGABRT); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1270 | |
| 1271 | bail: |
| 1272 | exception_exit(prev_state); |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1273 | } |
| 1274 | |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 1275 | void vsx_unavailable_exception(struct pt_regs *regs) |
| 1276 | { |
| 1277 | if (user_mode(regs)) { |
| 1278 | /* A user program has executed an vsx instruction, |
| 1279 | but this kernel doesn't support vsx. */ |
| 1280 | _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); |
| 1281 | return; |
| 1282 | } |
| 1283 | |
| 1284 | printk(KERN_EMERG "Unrecoverable VSX Unavailable Exception " |
| 1285 | "%lx at %lx\n", regs->trap, regs->nip); |
| 1286 | die("Unrecoverable VSX Unavailable Exception", regs, SIGABRT); |
| 1287 | } |
| 1288 | |
Michael Neuling | d0c0c9a | 2013-02-13 16:21:38 +0000 | [diff] [blame] | 1289 | void tm_unavailable_exception(struct pt_regs *regs) |
| 1290 | { |
| 1291 | /* We restore the interrupt state now */ |
| 1292 | if (!arch_irq_disabled_regs(regs)) |
| 1293 | local_irq_enable(); |
| 1294 | |
| 1295 | /* Currently we never expect a TMU exception. Catch |
| 1296 | * this and kill the process! |
| 1297 | */ |
| 1298 | printk(KERN_EMERG "Unexpected TM unavailable exception at %lx " |
| 1299 | "(msr %lx)\n", |
| 1300 | regs->nip, regs->msr); |
| 1301 | |
| 1302 | if (user_mode(regs)) { |
| 1303 | _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); |
| 1304 | return; |
| 1305 | } |
| 1306 | |
| 1307 | die("Unexpected TM unavailable exception", regs, SIGABRT); |
| 1308 | } |
| 1309 | |
Michael Neuling | f54db64 | 2013-02-13 16:21:39 +0000 | [diff] [blame] | 1310 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
| 1311 | |
| 1312 | extern void do_load_up_fpu(struct pt_regs *regs); |
| 1313 | |
| 1314 | void fp_unavailable_tm(struct pt_regs *regs) |
| 1315 | { |
| 1316 | /* Note: This does not handle any kind of FP laziness. */ |
| 1317 | |
| 1318 | TM_DEBUG("FP Unavailable trap whilst transactional at 0x%lx, MSR=%lx\n", |
| 1319 | regs->nip, regs->msr); |
| 1320 | tm_enable(); |
| 1321 | |
| 1322 | /* We can only have got here if the task started using FP after |
| 1323 | * beginning the transaction. So, the transactional regs are just a |
| 1324 | * copy of the checkpointed ones. But, we still need to recheckpoint |
| 1325 | * as we're enabling FP for the process; it will return, abort the |
| 1326 | * transaction, and probably retry but now with FP enabled. So the |
| 1327 | * checkpointed FP registers need to be loaded. |
| 1328 | */ |
| 1329 | tm_reclaim(¤t->thread, current->thread.regs->msr, |
| 1330 | TM_CAUSE_FAC_UNAV); |
| 1331 | /* Reclaim didn't save out any FPRs to transact_fprs. */ |
| 1332 | |
| 1333 | /* Enable FP for the task: */ |
| 1334 | regs->msr |= (MSR_FP | current->thread.fpexc_mode); |
| 1335 | |
| 1336 | /* This loads and recheckpoints the FP registers from |
| 1337 | * thread.fpr[]. They will remain in registers after the |
| 1338 | * checkpoint so we don't need to reload them after. |
| 1339 | */ |
| 1340 | tm_recheckpoint(¤t->thread, regs->msr); |
| 1341 | } |
| 1342 | |
| 1343 | #ifdef CONFIG_ALTIVEC |
| 1344 | extern void do_load_up_altivec(struct pt_regs *regs); |
| 1345 | |
| 1346 | void altivec_unavailable_tm(struct pt_regs *regs) |
| 1347 | { |
| 1348 | /* See the comments in fp_unavailable_tm(). This function operates |
| 1349 | * the same way. |
| 1350 | */ |
| 1351 | |
| 1352 | TM_DEBUG("Vector Unavailable trap whilst transactional at 0x%lx," |
| 1353 | "MSR=%lx\n", |
| 1354 | regs->nip, regs->msr); |
| 1355 | tm_enable(); |
| 1356 | tm_reclaim(¤t->thread, current->thread.regs->msr, |
| 1357 | TM_CAUSE_FAC_UNAV); |
| 1358 | regs->msr |= MSR_VEC; |
| 1359 | tm_recheckpoint(¤t->thread, regs->msr); |
| 1360 | current->thread.used_vr = 1; |
| 1361 | } |
| 1362 | #endif |
| 1363 | |
| 1364 | #ifdef CONFIG_VSX |
| 1365 | void vsx_unavailable_tm(struct pt_regs *regs) |
| 1366 | { |
| 1367 | /* See the comments in fp_unavailable_tm(). This works similarly, |
| 1368 | * though we're loading both FP and VEC registers in here. |
| 1369 | * |
| 1370 | * If FP isn't in use, load FP regs. If VEC isn't in use, load VEC |
| 1371 | * regs. Either way, set MSR_VSX. |
| 1372 | */ |
| 1373 | |
| 1374 | TM_DEBUG("VSX Unavailable trap whilst transactional at 0x%lx," |
| 1375 | "MSR=%lx\n", |
| 1376 | regs->nip, regs->msr); |
| 1377 | |
| 1378 | tm_enable(); |
| 1379 | /* This reclaims FP and/or VR regs if they're already enabled */ |
| 1380 | tm_reclaim(¤t->thread, current->thread.regs->msr, |
| 1381 | TM_CAUSE_FAC_UNAV); |
| 1382 | |
| 1383 | regs->msr |= MSR_VEC | MSR_FP | current->thread.fpexc_mode | |
| 1384 | MSR_VSX; |
| 1385 | /* This loads & recheckpoints FP and VRs. */ |
| 1386 | tm_recheckpoint(¤t->thread, regs->msr); |
| 1387 | current->thread.used_vsr = 1; |
| 1388 | } |
| 1389 | #endif |
| 1390 | #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ |
| 1391 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1392 | void performance_monitor_exception(struct pt_regs *regs) |
| 1393 | { |
Anton Blanchard | 89713ed | 2010-01-31 20:34:06 +0000 | [diff] [blame] | 1394 | __get_cpu_var(irq_stat).pmu_irqs++; |
| 1395 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1396 | perf_irq(regs); |
| 1397 | } |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1398 | |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 1399 | #ifdef CONFIG_8xx |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1400 | void SoftwareEmulation(struct pt_regs *regs) |
| 1401 | { |
| 1402 | extern int do_mathemu(struct pt_regs *); |
Benjamin Herrenschmidt | 968219f | 2013-06-09 17:04:58 +1000 | [diff] [blame] | 1403 | #if defined(CONFIG_MATH_EMULATION) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1404 | int errcode; |
Scott Wood | 5dd57a1 | 2007-09-18 15:29:35 -0500 | [diff] [blame] | 1405 | #endif |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1406 | |
| 1407 | CHECK_FULL_REGS(regs); |
| 1408 | |
| 1409 | if (!user_mode(regs)) { |
| 1410 | debugger(regs); |
| 1411 | die("Kernel Mode Software FPU Emulation", regs, SIGFPE); |
| 1412 | } |
| 1413 | |
| 1414 | #ifdef CONFIG_MATH_EMULATION |
| 1415 | errcode = do_mathemu(regs); |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 1416 | if (errcode >= 0) |
Anton Blanchard | eecff81 | 2009-10-27 18:46:55 +0000 | [diff] [blame] | 1417 | PPC_WARN_EMULATED(math, regs); |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 1418 | |
| 1419 | switch (errcode) { |
| 1420 | case 0: |
| 1421 | emulate_single_step(regs); |
| 1422 | return; |
| 1423 | case 1: { |
| 1424 | int code = 0; |
| 1425 | code = __parse_fpscr(current->thread.fpscr.val); |
| 1426 | _exception(SIGFPE, regs, code, regs->nip); |
| 1427 | return; |
| 1428 | } |
| 1429 | case -EFAULT: |
| 1430 | _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip); |
| 1431 | return; |
| 1432 | default: |
| 1433 | _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); |
| 1434 | return; |
| 1435 | } |
Scott Wood | 5dd57a1 | 2007-09-18 15:29:35 -0500 | [diff] [blame] | 1436 | #else |
| 1437 | _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 1438 | #endif |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1439 | } |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 1440 | #endif /* CONFIG_8xx */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1441 | |
Dave Kleikamp | 172ae2e | 2010-02-08 11:50:57 +0000 | [diff] [blame] | 1442 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1443 | static void handle_debug(struct pt_regs *regs, unsigned long debug_status) |
| 1444 | { |
| 1445 | int changed = 0; |
| 1446 | /* |
| 1447 | * Determine the cause of the debug event, clear the |
| 1448 | * event flags and send a trap to the handler. Torez |
| 1449 | */ |
| 1450 | if (debug_status & (DBSR_DAC1R | DBSR_DAC1W)) { |
| 1451 | dbcr_dac(current) &= ~(DBCR_DAC1R | DBCR_DAC1W); |
| 1452 | #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE |
| 1453 | current->thread.dbcr2 &= ~DBCR2_DAC12MODE; |
| 1454 | #endif |
| 1455 | do_send_trap(regs, mfspr(SPRN_DAC1), debug_status, TRAP_HWBKPT, |
| 1456 | 5); |
| 1457 | changed |= 0x01; |
| 1458 | } else if (debug_status & (DBSR_DAC2R | DBSR_DAC2W)) { |
| 1459 | dbcr_dac(current) &= ~(DBCR_DAC2R | DBCR_DAC2W); |
| 1460 | do_send_trap(regs, mfspr(SPRN_DAC2), debug_status, TRAP_HWBKPT, |
| 1461 | 6); |
| 1462 | changed |= 0x01; |
| 1463 | } else if (debug_status & DBSR_IAC1) { |
| 1464 | current->thread.dbcr0 &= ~DBCR0_IAC1; |
| 1465 | dbcr_iac_range(current) &= ~DBCR_IAC12MODE; |
| 1466 | do_send_trap(regs, mfspr(SPRN_IAC1), debug_status, TRAP_HWBKPT, |
| 1467 | 1); |
| 1468 | changed |= 0x01; |
| 1469 | } else if (debug_status & DBSR_IAC2) { |
| 1470 | current->thread.dbcr0 &= ~DBCR0_IAC2; |
| 1471 | do_send_trap(regs, mfspr(SPRN_IAC2), debug_status, TRAP_HWBKPT, |
| 1472 | 2); |
| 1473 | changed |= 0x01; |
| 1474 | } else if (debug_status & DBSR_IAC3) { |
| 1475 | current->thread.dbcr0 &= ~DBCR0_IAC3; |
| 1476 | dbcr_iac_range(current) &= ~DBCR_IAC34MODE; |
| 1477 | do_send_trap(regs, mfspr(SPRN_IAC3), debug_status, TRAP_HWBKPT, |
| 1478 | 3); |
| 1479 | changed |= 0x01; |
| 1480 | } else if (debug_status & DBSR_IAC4) { |
| 1481 | current->thread.dbcr0 &= ~DBCR0_IAC4; |
| 1482 | do_send_trap(regs, mfspr(SPRN_IAC4), debug_status, TRAP_HWBKPT, |
| 1483 | 4); |
| 1484 | changed |= 0x01; |
| 1485 | } |
| 1486 | /* |
| 1487 | * At the point this routine was called, the MSR(DE) was turned off. |
| 1488 | * Check all other debug flags and see if that bit needs to be turned |
| 1489 | * back on or not. |
| 1490 | */ |
| 1491 | if (DBCR_ACTIVE_EVENTS(current->thread.dbcr0, current->thread.dbcr1)) |
| 1492 | regs->msr |= MSR_DE; |
| 1493 | else |
| 1494 | /* Make sure the IDM flag is off */ |
| 1495 | current->thread.dbcr0 &= ~DBCR0_IDM; |
| 1496 | |
| 1497 | if (changed & 0x01) |
| 1498 | mtspr(SPRN_DBCR0, current->thread.dbcr0); |
| 1499 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1500 | |
Kumar Gala | f827962 | 2008-06-26 02:01:37 -0500 | [diff] [blame] | 1501 | void __kprobes DebugException(struct pt_regs *regs, unsigned long debug_status) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1502 | { |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1503 | current->thread.dbsr = debug_status; |
| 1504 | |
Roland McGrath | ec097c8 | 2009-05-28 21:26:38 +0000 | [diff] [blame] | 1505 | /* Hack alert: On BookE, Branch Taken stops on the branch itself, while |
| 1506 | * on server, it stops on the target of the branch. In order to simulate |
| 1507 | * the server behaviour, we thus restart right away with a single step |
| 1508 | * instead of stopping here when hitting a BT |
| 1509 | */ |
| 1510 | if (debug_status & DBSR_BT) { |
| 1511 | regs->msr &= ~MSR_DE; |
| 1512 | |
| 1513 | /* Disable BT */ |
| 1514 | mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_BT); |
| 1515 | /* Clear the BT event */ |
| 1516 | mtspr(SPRN_DBSR, DBSR_BT); |
| 1517 | |
| 1518 | /* Do the single step trick only when coming from userspace */ |
| 1519 | if (user_mode(regs)) { |
| 1520 | current->thread.dbcr0 &= ~DBCR0_BT; |
| 1521 | current->thread.dbcr0 |= DBCR0_IDM | DBCR0_IC; |
| 1522 | regs->msr |= MSR_DE; |
| 1523 | return; |
| 1524 | } |
| 1525 | |
| 1526 | if (notify_die(DIE_SSTEP, "block_step", regs, 5, |
| 1527 | 5, SIGTRAP) == NOTIFY_STOP) { |
| 1528 | return; |
| 1529 | } |
| 1530 | if (debugger_sstep(regs)) |
| 1531 | return; |
| 1532 | } else if (debug_status & DBSR_IC) { /* Instruction complete */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1533 | regs->msr &= ~MSR_DE; |
Kumar Gala | f827962 | 2008-06-26 02:01:37 -0500 | [diff] [blame] | 1534 | |
| 1535 | /* Disable instruction completion */ |
| 1536 | mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_IC); |
| 1537 | /* Clear the instruction completion event */ |
| 1538 | mtspr(SPRN_DBSR, DBSR_IC); |
| 1539 | |
| 1540 | if (notify_die(DIE_SSTEP, "single_step", regs, 5, |
| 1541 | 5, SIGTRAP) == NOTIFY_STOP) { |
| 1542 | return; |
| 1543 | } |
| 1544 | |
| 1545 | if (debugger_sstep(regs)) |
| 1546 | return; |
| 1547 | |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1548 | if (user_mode(regs)) { |
| 1549 | current->thread.dbcr0 &= ~DBCR0_IC; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1550 | if (DBCR_ACTIVE_EVENTS(current->thread.dbcr0, |
| 1551 | current->thread.dbcr1)) |
| 1552 | regs->msr |= MSR_DE; |
| 1553 | else |
| 1554 | /* Make sure the IDM bit is off */ |
| 1555 | current->thread.dbcr0 &= ~DBCR0_IDM; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1556 | } |
Kumar Gala | f827962 | 2008-06-26 02:01:37 -0500 | [diff] [blame] | 1557 | |
| 1558 | _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip); |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1559 | } else |
| 1560 | handle_debug(regs, debug_status); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1561 | } |
Dave Kleikamp | 172ae2e | 2010-02-08 11:50:57 +0000 | [diff] [blame] | 1562 | #endif /* CONFIG_PPC_ADV_DEBUG_REGS */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1563 | |
| 1564 | #if !defined(CONFIG_TAU_INT) |
| 1565 | void TAUException(struct pt_regs *regs) |
| 1566 | { |
| 1567 | printk("TAU trap at PC: %lx, MSR: %lx, vector=%lx %s\n", |
| 1568 | regs->nip, regs->msr, regs->trap, print_tainted()); |
| 1569 | } |
| 1570 | #endif /* CONFIG_INT_TAU */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1571 | |
| 1572 | #ifdef CONFIG_ALTIVEC |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1573 | void altivec_assist_exception(struct pt_regs *regs) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1574 | { |
| 1575 | int err; |
| 1576 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1577 | if (!user_mode(regs)) { |
| 1578 | printk(KERN_EMERG "VMX/Altivec assist exception in kernel mode" |
| 1579 | " at %lx\n", regs->nip); |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 1580 | die("Kernel VMX/Altivec assist exception", regs, SIGILL); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1581 | } |
| 1582 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1583 | flush_altivec_to_thread(current); |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1584 | |
Anton Blanchard | eecff81 | 2009-10-27 18:46:55 +0000 | [diff] [blame] | 1585 | PPC_WARN_EMULATED(altivec, regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1586 | err = emulate_altivec(regs); |
| 1587 | if (err == 0) { |
| 1588 | regs->nip += 4; /* skip emulated instruction */ |
| 1589 | emulate_single_step(regs); |
| 1590 | return; |
| 1591 | } |
| 1592 | |
| 1593 | if (err == -EFAULT) { |
| 1594 | /* got an error reading the instruction */ |
| 1595 | _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip); |
| 1596 | } else { |
| 1597 | /* didn't recognize the instruction */ |
| 1598 | /* XXX quick hack for now: set the non-Java bit in the VSCR */ |
Christian Dietrich | 7646223 | 2011-06-04 05:36:54 +0000 | [diff] [blame] | 1599 | printk_ratelimited(KERN_ERR "Unrecognized altivec instruction " |
| 1600 | "in %s at %lx\n", current->comm, regs->nip); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1601 | current->thread.vscr.u[3] |= 0x10000; |
| 1602 | } |
| 1603 | } |
| 1604 | #endif /* CONFIG_ALTIVEC */ |
| 1605 | |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 1606 | #ifdef CONFIG_VSX |
| 1607 | void vsx_assist_exception(struct pt_regs *regs) |
| 1608 | { |
| 1609 | if (!user_mode(regs)) { |
| 1610 | printk(KERN_EMERG "VSX assist exception in kernel mode" |
| 1611 | " at %lx\n", regs->nip); |
| 1612 | die("Kernel VSX assist exception", regs, SIGILL); |
| 1613 | } |
| 1614 | |
| 1615 | flush_vsx_to_thread(current); |
| 1616 | printk(KERN_INFO "VSX assist not supported at %lx\n", regs->nip); |
| 1617 | _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); |
| 1618 | } |
| 1619 | #endif /* CONFIG_VSX */ |
| 1620 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1621 | #ifdef CONFIG_FSL_BOOKE |
| 1622 | void CacheLockingException(struct pt_regs *regs, unsigned long address, |
| 1623 | unsigned long error_code) |
| 1624 | { |
| 1625 | /* We treat cache locking instructions from the user |
| 1626 | * as priv ops, in the future we could try to do |
| 1627 | * something smarter |
| 1628 | */ |
| 1629 | if (error_code & (ESR_DLK|ESR_ILK)) |
| 1630 | _exception(SIGILL, regs, ILL_PRVOPC, regs->nip); |
| 1631 | return; |
| 1632 | } |
| 1633 | #endif /* CONFIG_FSL_BOOKE */ |
| 1634 | |
| 1635 | #ifdef CONFIG_SPE |
| 1636 | void SPEFloatingPointException(struct pt_regs *regs) |
| 1637 | { |
Liu Yu | 6a800f3 | 2008-10-28 11:50:21 +0800 | [diff] [blame] | 1638 | extern int do_spe_mathemu(struct pt_regs *regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1639 | unsigned long spefscr; |
| 1640 | int fpexc_mode; |
| 1641 | int code = 0; |
Liu Yu | 6a800f3 | 2008-10-28 11:50:21 +0800 | [diff] [blame] | 1642 | int err; |
| 1643 | |
yu liu | 685659e | 2011-06-14 18:34:25 -0500 | [diff] [blame] | 1644 | flush_spe_to_thread(current); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1645 | |
| 1646 | spefscr = current->thread.spefscr; |
| 1647 | fpexc_mode = current->thread.fpexc_mode; |
| 1648 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1649 | if ((spefscr & SPEFSCR_FOVF) && (fpexc_mode & PR_FP_EXC_OVF)) { |
| 1650 | code = FPE_FLTOVF; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1651 | } |
| 1652 | else if ((spefscr & SPEFSCR_FUNF) && (fpexc_mode & PR_FP_EXC_UND)) { |
| 1653 | code = FPE_FLTUND; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1654 | } |
| 1655 | else if ((spefscr & SPEFSCR_FDBZ) && (fpexc_mode & PR_FP_EXC_DIV)) |
| 1656 | code = FPE_FLTDIV; |
| 1657 | else if ((spefscr & SPEFSCR_FINV) && (fpexc_mode & PR_FP_EXC_INV)) { |
| 1658 | code = FPE_FLTINV; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1659 | } |
| 1660 | else if ((spefscr & (SPEFSCR_FG | SPEFSCR_FX)) && (fpexc_mode & PR_FP_EXC_RES)) |
| 1661 | code = FPE_FLTRES; |
| 1662 | |
Liu Yu | 6a800f3 | 2008-10-28 11:50:21 +0800 | [diff] [blame] | 1663 | err = do_spe_mathemu(regs); |
| 1664 | if (err == 0) { |
| 1665 | regs->nip += 4; /* skip emulated instruction */ |
| 1666 | emulate_single_step(regs); |
| 1667 | return; |
| 1668 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1669 | |
Liu Yu | 6a800f3 | 2008-10-28 11:50:21 +0800 | [diff] [blame] | 1670 | if (err == -EFAULT) { |
| 1671 | /* got an error reading the instruction */ |
| 1672 | _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip); |
| 1673 | } else if (err == -EINVAL) { |
| 1674 | /* didn't recognize the instruction */ |
| 1675 | printk(KERN_ERR "unrecognized spe instruction " |
| 1676 | "in %s at %lx\n", current->comm, regs->nip); |
| 1677 | } else { |
| 1678 | _exception(SIGFPE, regs, code, regs->nip); |
| 1679 | } |
| 1680 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1681 | return; |
| 1682 | } |
Liu Yu | 6a800f3 | 2008-10-28 11:50:21 +0800 | [diff] [blame] | 1683 | |
| 1684 | void SPEFloatingPointRoundException(struct pt_regs *regs) |
| 1685 | { |
| 1686 | extern int speround_handler(struct pt_regs *regs); |
| 1687 | int err; |
| 1688 | |
| 1689 | preempt_disable(); |
| 1690 | if (regs->msr & MSR_SPE) |
| 1691 | giveup_spe(current); |
| 1692 | preempt_enable(); |
| 1693 | |
| 1694 | regs->nip -= 4; |
| 1695 | err = speround_handler(regs); |
| 1696 | if (err == 0) { |
| 1697 | regs->nip += 4; /* skip emulated instruction */ |
| 1698 | emulate_single_step(regs); |
| 1699 | return; |
| 1700 | } |
| 1701 | |
| 1702 | if (err == -EFAULT) { |
| 1703 | /* got an error reading the instruction */ |
| 1704 | _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip); |
| 1705 | } else if (err == -EINVAL) { |
| 1706 | /* didn't recognize the instruction */ |
| 1707 | printk(KERN_ERR "unrecognized spe instruction " |
| 1708 | "in %s at %lx\n", current->comm, regs->nip); |
| 1709 | } else { |
| 1710 | _exception(SIGFPE, regs, 0, regs->nip); |
| 1711 | return; |
| 1712 | } |
| 1713 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1714 | #endif |
| 1715 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1716 | /* |
| 1717 | * We enter here if we get an unrecoverable exception, that is, one |
| 1718 | * that happened at a point where the RI (recoverable interrupt) bit |
| 1719 | * in the MSR is 0. This indicates that SRR0/1 are live, and that |
| 1720 | * we therefore lost state by taking this exception. |
| 1721 | */ |
| 1722 | void unrecoverable_exception(struct pt_regs *regs) |
| 1723 | { |
| 1724 | printk(KERN_EMERG "Unrecoverable exception %lx at %lx\n", |
| 1725 | regs->trap, regs->nip); |
| 1726 | die("Unrecoverable exception", regs, SIGABRT); |
| 1727 | } |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1728 | |
Jason Gunthorpe | 1e18c17 | 2012-10-05 08:07:15 +0000 | [diff] [blame] | 1729 | #if defined(CONFIG_BOOKE_WDT) || defined(CONFIG_40x) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1730 | /* |
| 1731 | * Default handler for a Watchdog exception, |
| 1732 | * spins until a reboot occurs |
| 1733 | */ |
| 1734 | void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs) |
| 1735 | { |
| 1736 | /* Generic WatchdogHandler, implement your own */ |
| 1737 | mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE)); |
| 1738 | return; |
| 1739 | } |
| 1740 | |
| 1741 | void WatchdogException(struct pt_regs *regs) |
| 1742 | { |
| 1743 | printk (KERN_EMERG "PowerPC Book-E Watchdog Exception\n"); |
| 1744 | WatchdogHandler(regs); |
| 1745 | } |
| 1746 | #endif |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1747 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1748 | /* |
| 1749 | * We enter here if we discover during exception entry that we are |
| 1750 | * running in supervisor mode with a userspace value in the stack pointer. |
| 1751 | */ |
| 1752 | void kernel_bad_stack(struct pt_regs *regs) |
| 1753 | { |
| 1754 | printk(KERN_EMERG "Bad kernel stack pointer %lx at %lx\n", |
| 1755 | regs->gpr[1], regs->nip); |
| 1756 | die("Bad kernel stack pointer", regs, SIGABRT); |
| 1757 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1758 | |
| 1759 | void __init trap_init(void) |
| 1760 | { |
| 1761 | } |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 1762 | |
| 1763 | |
| 1764 | #ifdef CONFIG_PPC_EMULATED_STATS |
| 1765 | |
| 1766 | #define WARN_EMULATED_SETUP(type) .type = { .name = #type } |
| 1767 | |
| 1768 | struct ppc_emulated ppc_emulated = { |
| 1769 | #ifdef CONFIG_ALTIVEC |
| 1770 | WARN_EMULATED_SETUP(altivec), |
| 1771 | #endif |
| 1772 | WARN_EMULATED_SETUP(dcba), |
| 1773 | WARN_EMULATED_SETUP(dcbz), |
| 1774 | WARN_EMULATED_SETUP(fp_pair), |
| 1775 | WARN_EMULATED_SETUP(isel), |
| 1776 | WARN_EMULATED_SETUP(mcrxr), |
| 1777 | WARN_EMULATED_SETUP(mfpvr), |
| 1778 | WARN_EMULATED_SETUP(multiple), |
| 1779 | WARN_EMULATED_SETUP(popcntb), |
| 1780 | WARN_EMULATED_SETUP(spe), |
| 1781 | WARN_EMULATED_SETUP(string), |
| 1782 | WARN_EMULATED_SETUP(unaligned), |
| 1783 | #ifdef CONFIG_MATH_EMULATION |
| 1784 | WARN_EMULATED_SETUP(math), |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 1785 | #endif |
| 1786 | #ifdef CONFIG_VSX |
| 1787 | WARN_EMULATED_SETUP(vsx), |
| 1788 | #endif |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 1789 | #ifdef CONFIG_PPC64 |
| 1790 | WARN_EMULATED_SETUP(mfdscr), |
| 1791 | WARN_EMULATED_SETUP(mtdscr), |
| 1792 | #endif |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 1793 | }; |
| 1794 | |
| 1795 | u32 ppc_warn_emulated; |
| 1796 | |
| 1797 | void ppc_warn_emulated_print(const char *type) |
| 1798 | { |
Christian Dietrich | 7646223 | 2011-06-04 05:36:54 +0000 | [diff] [blame] | 1799 | pr_warn_ratelimited("%s used emulated %s instruction\n", current->comm, |
| 1800 | type); |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | static int __init ppc_warn_emulated_init(void) |
| 1804 | { |
| 1805 | struct dentry *dir, *d; |
| 1806 | unsigned int i; |
| 1807 | struct ppc_emulated_entry *entries = (void *)&ppc_emulated; |
| 1808 | |
| 1809 | if (!powerpc_debugfs_root) |
| 1810 | return -ENODEV; |
| 1811 | |
| 1812 | dir = debugfs_create_dir("emulated_instructions", |
| 1813 | powerpc_debugfs_root); |
| 1814 | if (!dir) |
| 1815 | return -ENOMEM; |
| 1816 | |
| 1817 | d = debugfs_create_u32("do_warn", S_IRUGO | S_IWUSR, dir, |
| 1818 | &ppc_warn_emulated); |
| 1819 | if (!d) |
| 1820 | goto fail; |
| 1821 | |
| 1822 | for (i = 0; i < sizeof(ppc_emulated)/sizeof(*entries); i++) { |
| 1823 | d = debugfs_create_u32(entries[i].name, S_IRUGO | S_IWUSR, dir, |
| 1824 | (u32 *)&entries[i].val.counter); |
| 1825 | if (!d) |
| 1826 | goto fail; |
| 1827 | } |
| 1828 | |
| 1829 | return 0; |
| 1830 | |
| 1831 | fail: |
| 1832 | debugfs_remove_recursive(dir); |
| 1833 | return -ENOMEM; |
| 1834 | } |
| 1835 | |
| 1836 | device_initcall(ppc_warn_emulated_init); |
| 1837 | |
| 1838 | #endif /* CONFIG_PPC_EMULATED_STATS */ |