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