Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * S390 version |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 3 | * Copyright IBM Corp. 1999, 2000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com), |
| 5 | * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com), |
| 6 | * |
| 7 | * Derived from "arch/i386/kernel/traps.c" |
| 8 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * 'Traps.c' handles hardware traps and faults after we have saved some |
| 13 | * state in 'asm.s'. |
| 14 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/sched.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/string.h> |
| 18 | #include <linux/errno.h> |
Martin Schwidefsky | 73b7d40 | 2011-07-24 10:48:33 +0200 | [diff] [blame] | 19 | #include <linux/ptrace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/timer.h> |
| 21 | #include <linux/mm.h> |
| 22 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/init.h> |
| 24 | #include <linux/interrupt.h> |
Eric W. Biederman | df5f831 | 2008-02-08 04:18:33 -0800 | [diff] [blame] | 25 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/delay.h> |
| 27 | #include <linux/module.h> |
Christoph Hellwig | 1eeb66a | 2007-05-08 00:27:03 -0700 | [diff] [blame] | 28 | #include <linux/kdebug.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/kallsyms.h> |
Heiko Carstens | 5d3f229 | 2005-08-01 21:11:33 -0700 | [diff] [blame] | 30 | #include <linux/reboot.h> |
Michael Grundy | 4ba069b | 2006-09-20 15:58:39 +0200 | [diff] [blame] | 31 | #include <linux/kprobes.h> |
Heiko Carstens | c0007f1 | 2007-04-27 16:01:42 +0200 | [diff] [blame] | 32 | #include <linux/bug.h> |
Heiko Carstens | 5c69971 | 2008-01-26 14:11:01 +0100 | [diff] [blame] | 33 | #include <linux/utsname.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <asm/uaccess.h> |
| 35 | #include <asm/io.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 36 | #include <linux/atomic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <asm/mathemu.h> |
| 38 | #include <asm/cpcmd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <asm/lowcore.h> |
| 40 | #include <asm/debug.h> |
Michael Holzheu | 3ab121a | 2012-03-11 11:59:32 -0400 | [diff] [blame] | 41 | #include <asm/ipl.h> |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 42 | #include "entry.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 44 | void (*pgm_check_table[128])(struct pt_regs *regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Heiko Carstens | 02834ee | 2011-12-27 11:27:31 +0100 | [diff] [blame] | 46 | int show_unhandled_signals = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #define stack_pointer ({ void **sp; asm("la %0,0(15)" : "=&d" (sp)); sp; }) |
| 49 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 50 | #ifndef CONFIG_64BIT |
Christian Borntraeger | d7fd5f1 | 2009-03-26 15:23:42 +0100 | [diff] [blame] | 51 | #define LONG "%08lx " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #define FOURLONG "%08lx %08lx %08lx %08lx\n" |
| 53 | static int kstack_depth_to_print = 12; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 54 | #else /* CONFIG_64BIT */ |
Christian Borntraeger | d7fd5f1 | 2009-03-26 15:23:42 +0100 | [diff] [blame] | 55 | #define LONG "%016lx " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #define FOURLONG "%016lx %016lx %016lx %016lx\n" |
| 57 | static int kstack_depth_to_print = 20; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 58 | #endif /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | /* |
| 61 | * For show_trace we have tree different stack to consider: |
| 62 | * - the panic stack which is used if the kernel stack has overflown |
| 63 | * - the asynchronous interrupt stack (cpu related) |
| 64 | * - the synchronous kernel stack (process related) |
| 65 | * The stack trace can start at any of the three stack and can potentially |
| 66 | * touch all of them. The order is: panic stack, async stack, sync stack. |
| 67 | */ |
| 68 | static unsigned long |
| 69 | __show_trace(unsigned long sp, unsigned long low, unsigned long high) |
| 70 | { |
| 71 | struct stack_frame *sf; |
| 72 | struct pt_regs *regs; |
| 73 | |
| 74 | while (1) { |
| 75 | sp = sp & PSW_ADDR_INSN; |
| 76 | if (sp < low || sp > high - sizeof(*sf)) |
| 77 | return sp; |
| 78 | sf = (struct stack_frame *) sp; |
| 79 | printk("([<%016lx>] ", sf->gprs[8] & PSW_ADDR_INSN); |
| 80 | print_symbol("%s)\n", sf->gprs[8] & PSW_ADDR_INSN); |
| 81 | /* Follow the backchain. */ |
| 82 | while (1) { |
| 83 | low = sp; |
| 84 | sp = sf->back_chain & PSW_ADDR_INSN; |
| 85 | if (!sp) |
| 86 | break; |
| 87 | if (sp <= low || sp > high - sizeof(*sf)) |
| 88 | return sp; |
| 89 | sf = (struct stack_frame *) sp; |
| 90 | printk(" [<%016lx>] ", sf->gprs[8] & PSW_ADDR_INSN); |
| 91 | print_symbol("%s\n", sf->gprs[8] & PSW_ADDR_INSN); |
| 92 | } |
| 93 | /* Zero backchain detected, check for interrupt frame. */ |
| 94 | sp = (unsigned long) (sf + 1); |
| 95 | if (sp <= low || sp > high - sizeof(*regs)) |
| 96 | return sp; |
| 97 | regs = (struct pt_regs *) sp; |
| 98 | printk(" [<%016lx>] ", regs->psw.addr & PSW_ADDR_INSN); |
| 99 | print_symbol("%s\n", regs->psw.addr & PSW_ADDR_INSN); |
| 100 | low = sp; |
| 101 | sp = regs->gprs[15]; |
| 102 | } |
| 103 | } |
| 104 | |
Heiko Carstens | 4e83be7 | 2008-04-30 13:38:34 +0200 | [diff] [blame] | 105 | static void show_trace(struct task_struct *task, unsigned long *stack) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { |
| 107 | register unsigned long __r15 asm ("15"); |
| 108 | unsigned long sp; |
| 109 | |
| 110 | sp = (unsigned long) stack; |
| 111 | if (!sp) |
| 112 | sp = task ? task->thread.ksp : __r15; |
| 113 | printk("Call Trace:\n"); |
| 114 | #ifdef CONFIG_CHECK_STACK |
| 115 | sp = __show_trace(sp, S390_lowcore.panic_stack - 4096, |
| 116 | S390_lowcore.panic_stack); |
| 117 | #endif |
| 118 | sp = __show_trace(sp, S390_lowcore.async_stack - ASYNC_SIZE, |
| 119 | S390_lowcore.async_stack); |
| 120 | if (task) |
Al Viro | 30af712 | 2006-01-12 01:05:50 -0800 | [diff] [blame] | 121 | __show_trace(sp, (unsigned long) task_stack_page(task), |
| 122 | (unsigned long) task_stack_page(task) + THREAD_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | else |
| 124 | __show_trace(sp, S390_lowcore.thread_info, |
| 125 | S390_lowcore.thread_info + THREAD_SIZE); |
Heiko Carstens | 236257e | 2006-12-04 15:40:47 +0100 | [diff] [blame] | 126 | if (!task) |
| 127 | task = current; |
| 128 | debug_show_held_locks(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | void show_stack(struct task_struct *task, unsigned long *sp) |
| 132 | { |
| 133 | register unsigned long * __r15 asm ("15"); |
| 134 | unsigned long *stack; |
| 135 | int i; |
| 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | if (!sp) |
Heiko Carstens | 7380534 | 2006-06-29 14:56:23 +0200 | [diff] [blame] | 138 | stack = task ? (unsigned long *) task->thread.ksp : __r15; |
| 139 | else |
| 140 | stack = sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | for (i = 0; i < kstack_depth_to_print; i++) { |
| 143 | if (((addr_t) stack & (THREAD_SIZE-1)) == 0) |
| 144 | break; |
Heiko Carstens | ddadfa8 | 2012-03-11 11:59:35 -0400 | [diff] [blame] | 145 | if ((i * sizeof(long) % 32) == 0) |
| 146 | printk("%s ", i == 0 ? "" : "\n"); |
Christian Borntraeger | d7fd5f1 | 2009-03-26 15:23:42 +0100 | [diff] [blame] | 147 | printk(LONG, *stack++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
| 149 | printk("\n"); |
| 150 | show_trace(task, sp); |
| 151 | } |
| 152 | |
Heiko Carstens | 4e83be7 | 2008-04-30 13:38:34 +0200 | [diff] [blame] | 153 | static void show_last_breaking_event(struct pt_regs *regs) |
Christian Borntraeger | 9e74a6b8 | 2008-04-17 07:46:30 +0200 | [diff] [blame] | 154 | { |
Heiko Carstens | 4e83be7 | 2008-04-30 13:38:34 +0200 | [diff] [blame] | 155 | #ifdef CONFIG_64BIT |
Christian Borntraeger | 9e74a6b8 | 2008-04-17 07:46:30 +0200 | [diff] [blame] | 156 | printk("Last Breaking-Event-Address:\n"); |
| 157 | printk(" [<%016lx>] ", regs->args[0] & PSW_ADDR_INSN); |
| 158 | print_symbol("%s\n", regs->args[0] & PSW_ADDR_INSN); |
Christian Borntraeger | 9e74a6b8 | 2008-04-17 07:46:30 +0200 | [diff] [blame] | 159 | #endif |
Heiko Carstens | 4e83be7 | 2008-04-30 13:38:34 +0200 | [diff] [blame] | 160 | } |
Christian Borntraeger | 9e74a6b8 | 2008-04-17 07:46:30 +0200 | [diff] [blame] | 161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | /* |
| 163 | * The architecture-independent dump_stack generator |
| 164 | */ |
| 165 | void dump_stack(void) |
| 166 | { |
Heiko Carstens | 5c69971 | 2008-01-26 14:11:01 +0100 | [diff] [blame] | 167 | printk("CPU: %d %s %s %.*s\n", |
| 168 | task_thread_info(current)->cpu, print_tainted(), |
| 169 | init_utsname()->release, |
| 170 | (int)strcspn(init_utsname()->version, " "), |
| 171 | init_utsname()->version); |
| 172 | printk("Process %s (pid: %d, task: %p, ksp: %p)\n", |
| 173 | current->comm, current->pid, current, |
| 174 | (void *) current->thread.ksp); |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 175 | show_stack(NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | EXPORT_SYMBOL(dump_stack); |
| 178 | |
Martin Schwidefsky | bb11e3b | 2007-04-27 16:01:41 +0200 | [diff] [blame] | 179 | static inline int mask_bits(struct pt_regs *regs, unsigned long bits) |
| 180 | { |
| 181 | return (regs->psw.mask & bits) / ((~bits + 1) & bits); |
| 182 | } |
| 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | void show_registers(struct pt_regs *regs) |
| 185 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | char *mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
Heiko Carstens | 7d25617 | 2012-07-27 10:31:12 +0200 | [diff] [blame] | 188 | mode = user_mode(regs) ? "User" : "Krnl"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | printk("%s PSW : %p %p", |
| 190 | mode, (void *) regs->psw.mask, |
| 191 | (void *) regs->psw.addr); |
| 192 | print_symbol(" (%s)\n", regs->psw.addr & PSW_ADDR_INSN); |
Martin Schwidefsky | bb11e3b | 2007-04-27 16:01:41 +0200 | [diff] [blame] | 193 | printk(" R:%x T:%x IO:%x EX:%x Key:%x M:%x W:%x " |
| 194 | "P:%x AS:%x CC:%x PM:%x", mask_bits(regs, PSW_MASK_PER), |
| 195 | mask_bits(regs, PSW_MASK_DAT), mask_bits(regs, PSW_MASK_IO), |
| 196 | mask_bits(regs, PSW_MASK_EXT), mask_bits(regs, PSW_MASK_KEY), |
| 197 | mask_bits(regs, PSW_MASK_MCHECK), mask_bits(regs, PSW_MASK_WAIT), |
| 198 | mask_bits(regs, PSW_MASK_PSTATE), mask_bits(regs, PSW_MASK_ASC), |
| 199 | mask_bits(regs, PSW_MASK_CC), mask_bits(regs, PSW_MASK_PM)); |
| 200 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 201 | printk(" EA:%x", mask_bits(regs, PSW_MASK_EA | PSW_MASK_BA)); |
Martin Schwidefsky | bb11e3b | 2007-04-27 16:01:41 +0200 | [diff] [blame] | 202 | #endif |
| 203 | printk("\n%s GPRS: " FOURLONG, mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | regs->gprs[0], regs->gprs[1], regs->gprs[2], regs->gprs[3]); |
| 205 | printk(" " FOURLONG, |
| 206 | regs->gprs[4], regs->gprs[5], regs->gprs[6], regs->gprs[7]); |
| 207 | printk(" " FOURLONG, |
| 208 | regs->gprs[8], regs->gprs[9], regs->gprs[10], regs->gprs[11]); |
| 209 | printk(" " FOURLONG, |
| 210 | regs->gprs[12], regs->gprs[13], regs->gprs[14], regs->gprs[15]); |
| 211 | |
Martin Schwidefsky | bb11e3b | 2007-04-27 16:01:41 +0200 | [diff] [blame] | 212 | show_code(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Heiko Carstens | 4e83be7 | 2008-04-30 13:38:34 +0200 | [diff] [blame] | 215 | void show_regs(struct pt_regs *regs) |
| 216 | { |
| 217 | print_modules(); |
| 218 | printk("CPU: %d %s %s %.*s\n", |
| 219 | task_thread_info(current)->cpu, print_tainted(), |
| 220 | init_utsname()->release, |
| 221 | (int)strcspn(init_utsname()->version, " "), |
| 222 | init_utsname()->version); |
| 223 | printk("Process %s (pid: %d, task: %p, ksp: %p)\n", |
| 224 | current->comm, current->pid, current, |
| 225 | (void *) current->thread.ksp); |
| 226 | show_registers(regs); |
| 227 | /* Show stack backtrace if pt_regs is from kernel mode */ |
Heiko Carstens | 7d25617 | 2012-07-27 10:31:12 +0200 | [diff] [blame] | 228 | if (!user_mode(regs)) |
Heiko Carstens | 4e83be7 | 2008-04-30 13:38:34 +0200 | [diff] [blame] | 229 | show_trace(NULL, (unsigned long *) regs->gprs[15]); |
| 230 | show_last_breaking_event(regs); |
| 231 | } |
| 232 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 233 | static DEFINE_SPINLOCK(die_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 235 | void die(struct pt_regs *regs, const char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { |
| 237 | static int die_counter; |
| 238 | |
Heiko Carstens | bca0fb86 | 2007-06-19 13:10:05 +0200 | [diff] [blame] | 239 | oops_enter(); |
Michael Holzheu | 3ab121a | 2012-03-11 11:59:32 -0400 | [diff] [blame] | 240 | lgr_info_log(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | debug_stop_all(); |
| 242 | console_verbose(); |
| 243 | spin_lock_irq(&die_lock); |
| 244 | bust_spinlocks(1); |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 245 | printk("%s: %04x [#%d] ", str, regs->int_code & 0xffff, ++die_counter); |
Heiko Carstens | 5c69971 | 2008-01-26 14:11:01 +0100 | [diff] [blame] | 246 | #ifdef CONFIG_PREEMPT |
| 247 | printk("PREEMPT "); |
| 248 | #endif |
| 249 | #ifdef CONFIG_SMP |
Heiko Carstens | 2485579 | 2008-02-05 16:50:37 +0100 | [diff] [blame] | 250 | printk("SMP "); |
| 251 | #endif |
| 252 | #ifdef CONFIG_DEBUG_PAGEALLOC |
| 253 | printk("DEBUG_PAGEALLOC"); |
Heiko Carstens | 5c69971 | 2008-01-26 14:11:01 +0100 | [diff] [blame] | 254 | #endif |
| 255 | printk("\n"); |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 256 | notify_die(DIE_OOPS, str, regs, 0, regs->int_code & 0xffff, SIGSEGV); |
Heiko Carstens | bca0fb86 | 2007-06-19 13:10:05 +0200 | [diff] [blame] | 257 | show_regs(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | bust_spinlocks(0); |
Pavel Emelianov | bcdcd8e | 2007-07-17 04:03:42 -0700 | [diff] [blame] | 259 | add_taint(TAINT_DIE); |
Heiko Carstens | bca0fb86 | 2007-06-19 13:10:05 +0200 | [diff] [blame] | 260 | spin_unlock_irq(&die_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | if (in_interrupt()) |
| 262 | panic("Fatal exception in interrupt"); |
| 263 | if (panic_on_oops) |
| 264 | panic("Fatal exception: panic_on_oops"); |
Heiko Carstens | bca0fb86 | 2007-06-19 13:10:05 +0200 | [diff] [blame] | 265 | oops_exit(); |
| 266 | do_exit(SIGSEGV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 269 | static inline void report_user_fault(struct pt_regs *regs, int signr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | { |
Heiko Carstens | ab3c68e | 2010-05-17 10:00:21 +0200 | [diff] [blame] | 271 | if ((task_pid_nr(current) > 1) && !show_unhandled_signals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | return; |
Heiko Carstens | ab3c68e | 2010-05-17 10:00:21 +0200 | [diff] [blame] | 273 | if (!unhandled_signal(current, signr)) |
| 274 | return; |
| 275 | if (!printk_ratelimit()) |
| 276 | return; |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 277 | printk("User process fault: interruption code 0x%X ", regs->int_code); |
Heiko Carstens | ab3c68e | 2010-05-17 10:00:21 +0200 | [diff] [blame] | 278 | print_vma_addr("in ", regs->psw.addr & PSW_ADDR_INSN); |
| 279 | printk("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | show_regs(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Heiko Carstens | c0007f1 | 2007-04-27 16:01:42 +0200 | [diff] [blame] | 283 | int is_valid_bugaddr(unsigned long addr) |
| 284 | { |
| 285 | return 1; |
| 286 | } |
| 287 | |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 288 | static inline void __user *get_psw_address(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | { |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 290 | return (void __user *) |
| 291 | ((regs->psw.addr - (regs->int_code >> 16)) & PSW_ADDR_INSN); |
| 292 | } |
| 293 | |
| 294 | static void __kprobes do_trap(struct pt_regs *regs, |
| 295 | int si_signo, int si_code, char *str) |
| 296 | { |
| 297 | siginfo_t info; |
| 298 | |
| 299 | if (notify_die(DIE_TRAP, str, regs, 0, |
| 300 | regs->int_code, si_signo) == NOTIFY_STOP) |
Michael Grundy | 4ba069b | 2006-09-20 15:58:39 +0200 | [diff] [blame] | 301 | return; |
| 302 | |
Heiko Carstens | 7d25617 | 2012-07-27 10:31:12 +0200 | [diff] [blame] | 303 | if (user_mode(regs)) { |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 304 | info.si_signo = si_signo; |
| 305 | info.si_errno = 0; |
| 306 | info.si_code = si_code; |
| 307 | info.si_addr = get_psw_address(regs); |
| 308 | force_sig_info(si_signo, &info, current); |
| 309 | report_user_fault(regs, si_signo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | } else { |
| 311 | const struct exception_table_entry *fixup; |
| 312 | fixup = search_exception_tables(regs->psw.addr & PSW_ADDR_INSN); |
| 313 | if (fixup) |
| 314 | regs->psw.addr = fixup->fixup | PSW_ADDR_AMODE; |
Heiko Carstens | c0007f1 | 2007-04-27 16:01:42 +0200 | [diff] [blame] | 315 | else { |
| 316 | enum bug_trap_type btt; |
| 317 | |
Heiko Carstens | 608e261 | 2007-07-15 23:41:39 -0700 | [diff] [blame] | 318 | btt = report_bug(regs->psw.addr & PSW_ADDR_INSN, regs); |
Heiko Carstens | c0007f1 | 2007-04-27 16:01:42 +0200 | [diff] [blame] | 319 | if (btt == BUG_TRAP_TYPE_WARN) |
| 320 | return; |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 321 | die(regs, str); |
Heiko Carstens | c0007f1 | 2007-04-27 16:01:42 +0200 | [diff] [blame] | 322 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 326 | void __kprobes do_per_trap(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | { |
Martin Schwidefsky | 73b7d40 | 2011-07-24 10:48:33 +0200 | [diff] [blame] | 328 | siginfo_t info; |
| 329 | |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 330 | if (notify_die(DIE_SSTEP, "sstep", regs, 0, 0, SIGTRAP) == NOTIFY_STOP) |
Michael Grundy | 4ba069b | 2006-09-20 15:58:39 +0200 | [diff] [blame] | 331 | return; |
Martin Schwidefsky | 73b7d40 | 2011-07-24 10:48:33 +0200 | [diff] [blame] | 332 | if (!current->ptrace) |
| 333 | return; |
| 334 | info.si_signo = SIGTRAP; |
| 335 | info.si_errno = 0; |
| 336 | info.si_code = TRAP_HWBKPT; |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 337 | info.si_addr = |
| 338 | (void __force __user *) current->thread.per_event.address; |
Martin Schwidefsky | 73b7d40 | 2011-07-24 10:48:33 +0200 | [diff] [blame] | 339 | force_sig_info(SIGTRAP, &info, current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 342 | static void default_trap_handler(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | { |
Heiko Carstens | 7d25617 | 2012-07-27 10:31:12 +0200 | [diff] [blame] | 344 | if (user_mode(regs)) { |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 345 | report_user_fault(regs, SIGSEGV); |
Heiko Carstens | 6ea5096 | 2010-05-17 10:00:13 +0200 | [diff] [blame] | 346 | do_exit(SIGSEGV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } else |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 348 | die(regs, "Unknown program exception"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Martin Schwidefsky | 1e54622 | 2010-10-25 16:10:37 +0200 | [diff] [blame] | 351 | #define DO_ERROR_INFO(name, signr, sicode, str) \ |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 352 | static void name(struct pt_regs *regs) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | { \ |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 354 | do_trap(regs, signr, sicode, str); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Martin Schwidefsky | 1e54622 | 2010-10-25 16:10:37 +0200 | [diff] [blame] | 357 | DO_ERROR_INFO(addressing_exception, SIGILL, ILL_ILLADR, |
| 358 | "addressing exception") |
| 359 | DO_ERROR_INFO(execute_exception, SIGILL, ILL_ILLOPN, |
| 360 | "execute exception") |
| 361 | DO_ERROR_INFO(divide_exception, SIGFPE, FPE_INTDIV, |
| 362 | "fixpoint divide exception") |
| 363 | DO_ERROR_INFO(overflow_exception, SIGFPE, FPE_INTOVF, |
| 364 | "fixpoint overflow exception") |
| 365 | DO_ERROR_INFO(hfp_overflow_exception, SIGFPE, FPE_FLTOVF, |
| 366 | "HFP overflow exception") |
| 367 | DO_ERROR_INFO(hfp_underflow_exception, SIGFPE, FPE_FLTUND, |
| 368 | "HFP underflow exception") |
| 369 | DO_ERROR_INFO(hfp_significance_exception, SIGFPE, FPE_FLTRES, |
| 370 | "HFP significance exception") |
| 371 | DO_ERROR_INFO(hfp_divide_exception, SIGFPE, FPE_FLTDIV, |
| 372 | "HFP divide exception") |
| 373 | DO_ERROR_INFO(hfp_sqrt_exception, SIGFPE, FPE_FLTINV, |
| 374 | "HFP square root exception") |
| 375 | DO_ERROR_INFO(operand_exception, SIGILL, ILL_ILLOPN, |
| 376 | "operand exception") |
| 377 | DO_ERROR_INFO(privileged_op, SIGILL, ILL_PRVOPC, |
| 378 | "privileged operation") |
| 379 | DO_ERROR_INFO(special_op_exception, SIGILL, ILL_ILLOPN, |
| 380 | "special operation exception") |
| 381 | DO_ERROR_INFO(translation_exception, SIGILL, ILL_ILLOPN, |
| 382 | "translation exception") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 384 | static inline void do_fp_trap(struct pt_regs *regs, int fpc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | { |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 386 | int si_code = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | /* FPC[2] is Data Exception Code */ |
| 388 | if ((fpc & 0x00000300) == 0) { |
| 389 | /* bits 6 and 7 of DXC are 0 iff IEEE exception */ |
| 390 | if (fpc & 0x8000) /* invalid fp operation */ |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 391 | si_code = FPE_FLTINV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | else if (fpc & 0x4000) /* div by 0 */ |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 393 | si_code = FPE_FLTDIV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | else if (fpc & 0x2000) /* overflow */ |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 395 | si_code = FPE_FLTOVF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | else if (fpc & 0x1000) /* underflow */ |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 397 | si_code = FPE_FLTUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | else if (fpc & 0x0800) /* inexact */ |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 399 | si_code = FPE_FLTRES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | } |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 401 | do_trap(regs, SIGFPE, si_code, "floating point exception"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 404 | static void __kprobes illegal_op(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | { |
| 406 | siginfo_t info; |
| 407 | __u8 opcode[6]; |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 408 | __u16 __user *location; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | int signal = 0; |
| 410 | |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 411 | location = get_psw_address(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
Heiko Carstens | 7d25617 | 2012-07-27 10:31:12 +0200 | [diff] [blame] | 413 | if (user_mode(regs)) { |
Heiko Carstens | 12bae23 | 2006-10-27 12:39:22 +0200 | [diff] [blame] | 414 | if (get_user(*((__u16 *) opcode), (__u16 __user *) location)) |
| 415 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | if (*((__u16 *) opcode) == S390_BREAKPOINT_U16) { |
Martin Schwidefsky | 73b7d40 | 2011-07-24 10:48:33 +0200 | [diff] [blame] | 417 | if (current->ptrace) { |
| 418 | info.si_signo = SIGTRAP; |
| 419 | info.si_errno = 0; |
| 420 | info.si_code = TRAP_BRKPT; |
| 421 | info.si_addr = location; |
| 422 | force_sig_info(SIGTRAP, &info, current); |
| 423 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | signal = SIGILL; |
| 425 | #ifdef CONFIG_MATHEMU |
| 426 | } else if (opcode[0] == 0xb3) { |
Heiko Carstens | 12bae23 | 2006-10-27 12:39:22 +0200 | [diff] [blame] | 427 | if (get_user(*((__u16 *) (opcode+2)), location+1)) |
| 428 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | signal = math_emu_b3(opcode, regs); |
| 430 | } else if (opcode[0] == 0xed) { |
Heiko Carstens | 12bae23 | 2006-10-27 12:39:22 +0200 | [diff] [blame] | 431 | if (get_user(*((__u32 *) (opcode+2)), |
| 432 | (__u32 __user *)(location+1))) |
| 433 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | signal = math_emu_ed(opcode, regs); |
| 435 | } else if (*((__u16 *) opcode) == 0xb299) { |
Heiko Carstens | 12bae23 | 2006-10-27 12:39:22 +0200 | [diff] [blame] | 436 | if (get_user(*((__u16 *) (opcode+2)), location+1)) |
| 437 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | signal = math_emu_srnm(opcode, regs); |
| 439 | } else if (*((__u16 *) opcode) == 0xb29c) { |
Heiko Carstens | 12bae23 | 2006-10-27 12:39:22 +0200 | [diff] [blame] | 440 | if (get_user(*((__u16 *) (opcode+2)), location+1)) |
| 441 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | signal = math_emu_stfpc(opcode, regs); |
| 443 | } else if (*((__u16 *) opcode) == 0xb29d) { |
Heiko Carstens | 12bae23 | 2006-10-27 12:39:22 +0200 | [diff] [blame] | 444 | if (get_user(*((__u16 *) (opcode+2)), location+1)) |
| 445 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | signal = math_emu_lfpc(opcode, regs); |
| 447 | #endif |
| 448 | } else |
| 449 | signal = SIGILL; |
Heiko Carstens | 35df8d5 | 2007-02-05 21:17:29 +0100 | [diff] [blame] | 450 | } else { |
| 451 | /* |
| 452 | * If we get an illegal op in kernel mode, send it through the |
| 453 | * kprobes notifier. If kprobes doesn't pick it up, SIGILL |
| 454 | */ |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 455 | if (notify_die(DIE_BPT, "bpt", regs, 0, |
Heiko Carstens | 35df8d5 | 2007-02-05 21:17:29 +0100 | [diff] [blame] | 456 | 3, SIGTRAP) != NOTIFY_STOP) |
| 457 | signal = SIGILL; |
| 458 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
| 460 | #ifdef CONFIG_MATHEMU |
| 461 | if (signal == SIGFPE) |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 462 | do_fp_trap(regs, current->thread.fp_regs.fpc); |
| 463 | else if (signal == SIGSEGV) |
| 464 | do_trap(regs, signal, SEGV_MAPERR, "user address fault"); |
| 465 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | #endif |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 467 | if (signal) |
| 468 | do_trap(regs, signal, ILL_ILLOPC, "illegal operation"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | |
| 472 | #ifdef CONFIG_MATHEMU |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 473 | void specification_exception(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | { |
| 475 | __u8 opcode[6]; |
Al Viro | 5a42b81 | 2006-10-09 20:28:03 +0100 | [diff] [blame] | 476 | __u16 __user *location = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | int signal = 0; |
| 478 | |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 479 | location = (__u16 __user *) get_psw_address(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
Heiko Carstens | 7d25617 | 2012-07-27 10:31:12 +0200 | [diff] [blame] | 481 | if (user_mode(regs)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | get_user(*((__u16 *) opcode), location); |
| 483 | switch (opcode[0]) { |
| 484 | case 0x28: /* LDR Rx,Ry */ |
| 485 | signal = math_emu_ldr(opcode); |
| 486 | break; |
| 487 | case 0x38: /* LER Rx,Ry */ |
| 488 | signal = math_emu_ler(opcode); |
| 489 | break; |
| 490 | case 0x60: /* STD R,D(X,B) */ |
| 491 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 492 | signal = math_emu_std(opcode, regs); |
| 493 | break; |
| 494 | case 0x68: /* LD R,D(X,B) */ |
| 495 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 496 | signal = math_emu_ld(opcode, regs); |
| 497 | break; |
| 498 | case 0x70: /* STE R,D(X,B) */ |
| 499 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 500 | signal = math_emu_ste(opcode, regs); |
| 501 | break; |
| 502 | case 0x78: /* LE R,D(X,B) */ |
| 503 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 504 | signal = math_emu_le(opcode, regs); |
| 505 | break; |
| 506 | default: |
| 507 | signal = SIGILL; |
| 508 | break; |
| 509 | } |
| 510 | } else |
| 511 | signal = SIGILL; |
| 512 | |
| 513 | if (signal == SIGFPE) |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 514 | do_fp_trap(regs, current->thread.fp_regs.fpc); |
| 515 | else if (signal) |
| 516 | do_trap(regs, signal, ILL_ILLOPN, "specification exception"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | } |
| 518 | #else |
Martin Schwidefsky | 1e54622 | 2010-10-25 16:10:37 +0200 | [diff] [blame] | 519 | DO_ERROR_INFO(specification_exception, SIGILL, ILL_ILLOPN, |
| 520 | "specification exception"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | #endif |
| 522 | |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 523 | static void data_exception(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | { |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 525 | __u16 __user *location; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | int signal = 0; |
| 527 | |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 528 | location = get_psw_address(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
| 530 | if (MACHINE_HAS_IEEE) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 531 | asm volatile("stfpc %0" : "=m" (current->thread.fp_regs.fpc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
| 533 | #ifdef CONFIG_MATHEMU |
Heiko Carstens | 7d25617 | 2012-07-27 10:31:12 +0200 | [diff] [blame] | 534 | else if (user_mode(regs)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | __u8 opcode[6]; |
| 536 | get_user(*((__u16 *) opcode), location); |
| 537 | switch (opcode[0]) { |
| 538 | case 0x28: /* LDR Rx,Ry */ |
| 539 | signal = math_emu_ldr(opcode); |
| 540 | break; |
| 541 | case 0x38: /* LER Rx,Ry */ |
| 542 | signal = math_emu_ler(opcode); |
| 543 | break; |
| 544 | case 0x60: /* STD R,D(X,B) */ |
| 545 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 546 | signal = math_emu_std(opcode, regs); |
| 547 | break; |
| 548 | case 0x68: /* LD R,D(X,B) */ |
| 549 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 550 | signal = math_emu_ld(opcode, regs); |
| 551 | break; |
| 552 | case 0x70: /* STE R,D(X,B) */ |
| 553 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 554 | signal = math_emu_ste(opcode, regs); |
| 555 | break; |
| 556 | case 0x78: /* LE R,D(X,B) */ |
| 557 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 558 | signal = math_emu_le(opcode, regs); |
| 559 | break; |
| 560 | case 0xb3: |
| 561 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 562 | signal = math_emu_b3(opcode, regs); |
| 563 | break; |
| 564 | case 0xed: |
| 565 | get_user(*((__u32 *) (opcode+2)), |
Al Viro | 5a42b81 | 2006-10-09 20:28:03 +0100 | [diff] [blame] | 566 | (__u32 __user *)(location+1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | signal = math_emu_ed(opcode, regs); |
| 568 | break; |
| 569 | case 0xb2: |
| 570 | if (opcode[1] == 0x99) { |
| 571 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 572 | signal = math_emu_srnm(opcode, regs); |
| 573 | } else if (opcode[1] == 0x9c) { |
| 574 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 575 | signal = math_emu_stfpc(opcode, regs); |
| 576 | } else if (opcode[1] == 0x9d) { |
| 577 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 578 | signal = math_emu_lfpc(opcode, regs); |
| 579 | } else |
| 580 | signal = SIGILL; |
| 581 | break; |
| 582 | default: |
| 583 | signal = SIGILL; |
| 584 | break; |
| 585 | } |
| 586 | } |
| 587 | #endif |
| 588 | if (current->thread.fp_regs.fpc & FPC_DXC_MASK) |
| 589 | signal = SIGFPE; |
| 590 | else |
| 591 | signal = SIGILL; |
| 592 | if (signal == SIGFPE) |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 593 | do_fp_trap(regs, current->thread.fp_regs.fpc); |
| 594 | else if (signal) |
| 595 | do_trap(regs, signal, ILL_ILLOPN, "data exception"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 598 | static void space_switch_exception(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | /* Set user psw back to home space mode. */ |
Heiko Carstens | 7d25617 | 2012-07-27 10:31:12 +0200 | [diff] [blame] | 601 | if (user_mode(regs)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | regs->psw.mask |= PSW_ASC_HOME; |
| 603 | /* Send SIGILL. */ |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 604 | do_trap(regs, SIGILL, ILL_PRVOPC, "space switch event"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | } |
| 606 | |
Martin Schwidefsky | fdb204d | 2011-07-24 10:48:24 +0200 | [diff] [blame] | 607 | void __kprobes kernel_stack_overflow(struct pt_regs * regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | { |
Heiko Carstens | 77eb65c | 2005-06-21 17:16:28 -0700 | [diff] [blame] | 609 | bust_spinlocks(1); |
| 610 | printk("Kernel stack overflow.\n"); |
| 611 | show_regs(regs); |
| 612 | bust_spinlocks(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | panic("Corrupt kernel stack, can't continue."); |
| 614 | } |
| 615 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | /* init is done in lowcore.S and head.S */ |
| 617 | |
| 618 | void __init trap_init(void) |
| 619 | { |
| 620 | int i; |
| 621 | |
| 622 | for (i = 0; i < 128; i++) |
| 623 | pgm_check_table[i] = &default_trap_handler; |
| 624 | pgm_check_table[1] = &illegal_op; |
| 625 | pgm_check_table[2] = &privileged_op; |
| 626 | pgm_check_table[3] = &execute_exception; |
| 627 | pgm_check_table[4] = &do_protection_exception; |
| 628 | pgm_check_table[5] = &addressing_exception; |
| 629 | pgm_check_table[6] = &specification_exception; |
| 630 | pgm_check_table[7] = &data_exception; |
| 631 | pgm_check_table[8] = &overflow_exception; |
| 632 | pgm_check_table[9] = ÷_exception; |
| 633 | pgm_check_table[0x0A] = &overflow_exception; |
| 634 | pgm_check_table[0x0B] = ÷_exception; |
| 635 | pgm_check_table[0x0C] = &hfp_overflow_exception; |
| 636 | pgm_check_table[0x0D] = &hfp_underflow_exception; |
| 637 | pgm_check_table[0x0E] = &hfp_significance_exception; |
| 638 | pgm_check_table[0x0F] = &hfp_divide_exception; |
| 639 | pgm_check_table[0x10] = &do_dat_exception; |
| 640 | pgm_check_table[0x11] = &do_dat_exception; |
| 641 | pgm_check_table[0x12] = &translation_exception; |
| 642 | pgm_check_table[0x13] = &special_op_exception; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 643 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 644 | pgm_check_table[0x38] = &do_asce_exception; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | pgm_check_table[0x39] = &do_dat_exception; |
| 646 | pgm_check_table[0x3A] = &do_dat_exception; |
| 647 | pgm_check_table[0x3B] = &do_dat_exception; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 648 | #endif /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | pgm_check_table[0x15] = &operand_exception; |
| 650 | pgm_check_table[0x1C] = &space_switch_exception; |
| 651 | pgm_check_table[0x1D] = &hfp_sqrt_exception; |
Heiko Carstens | f3e1a27 | 2011-01-05 12:48:00 +0100 | [diff] [blame] | 652 | /* Enable machine checks early. */ |
| 653 | local_mcck_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | } |