blob: 92ecffbc8d8233352589b700f5eefa4f165fe832 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/s390/kernel/traps.c
3 *
4 * S390 version
5 * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
7 * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
8 *
9 * Derived from "arch/i386/kernel/traps.c"
10 * Copyright (C) 1991, 1992 Linus Torvalds
11 */
12
13/*
14 * 'Traps.c' handles hardware traps and faults after we have saved some
15 * state in 'asm.s'.
16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/sched.h>
18#include <linux/kernel.h>
19#include <linux/string.h>
20#include <linux/errno.h>
21#include <linux/ptrace.h>
22#include <linux/timer.h>
23#include <linux/mm.h>
24#include <linux/smp.h>
25#include <linux/smp_lock.h>
26#include <linux/init.h>
27#include <linux/interrupt.h>
28#include <linux/delay.h>
29#include <linux/module.h>
30#include <linux/kallsyms.h>
Heiko Carstens5d3f2292005-08-01 21:11:33 -070031#include <linux/reboot.h>
Michael Grundy4ba069b2006-09-20 15:58:39 +020032#include <linux/kprobes.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34#include <asm/system.h>
35#include <asm/uaccess.h>
36#include <asm/io.h>
37#include <asm/atomic.h>
38#include <asm/mathemu.h>
39#include <asm/cpcmd.h>
40#include <asm/s390_ext.h>
41#include <asm/lowcore.h>
42#include <asm/debug.h>
Michael Grundy4ba069b2006-09-20 15:58:39 +020043#include <asm/kdebug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45/* Called from entry.S only */
46extern void handle_per_exception(struct pt_regs *regs);
47
48typedef void pgm_check_handler_t(struct pt_regs *, long);
49pgm_check_handler_t *pgm_check_table[128];
50
51#ifdef CONFIG_SYSCTL
52#ifdef CONFIG_PROCESS_DEBUG
53int sysctl_userprocess_debug = 1;
54#else
55int sysctl_userprocess_debug = 0;
56#endif
57#endif
58
59extern pgm_check_handler_t do_protection_exception;
60extern pgm_check_handler_t do_dat_exception;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#ifdef CONFIG_PFAULT
62extern int pfault_init(void);
63extern void pfault_fini(void);
Heiko Carstens5a489b92006-10-06 16:38:35 +020064extern void pfault_interrupt(__u16 error_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065static ext_int_info_t ext_int_pfault;
66#endif
67extern pgm_check_handler_t do_monitor_call;
68
69#define stack_pointer ({ void **sp; asm("la %0,0(15)" : "=&d" (sp)); sp; })
70
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -080071#ifndef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#define FOURLONG "%08lx %08lx %08lx %08lx\n"
73static int kstack_depth_to_print = 12;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -080074#else /* CONFIG_64BIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -070075#define FOURLONG "%016lx %016lx %016lx %016lx\n"
76static int kstack_depth_to_print = 20;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -080077#endif /* CONFIG_64BIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Michael Grundy4ba069b2006-09-20 15:58:39 +020079ATOMIC_NOTIFIER_HEAD(s390die_chain);
80
81int register_die_notifier(struct notifier_block *nb)
82{
83 return atomic_notifier_chain_register(&s390die_chain, nb);
84}
85EXPORT_SYMBOL(register_die_notifier);
86
87int unregister_die_notifier(struct notifier_block *nb)
88{
89 return atomic_notifier_chain_unregister(&s390die_chain, nb);
90}
91EXPORT_SYMBOL(unregister_die_notifier);
92
Linus Torvalds1da177e2005-04-16 15:20:36 -070093/*
94 * For show_trace we have tree different stack to consider:
95 * - the panic stack which is used if the kernel stack has overflown
96 * - the asynchronous interrupt stack (cpu related)
97 * - the synchronous kernel stack (process related)
98 * The stack trace can start at any of the three stack and can potentially
99 * touch all of them. The order is: panic stack, async stack, sync stack.
100 */
101static unsigned long
102__show_trace(unsigned long sp, unsigned long low, unsigned long high)
103{
104 struct stack_frame *sf;
105 struct pt_regs *regs;
106
107 while (1) {
108 sp = sp & PSW_ADDR_INSN;
109 if (sp < low || sp > high - sizeof(*sf))
110 return sp;
111 sf = (struct stack_frame *) sp;
112 printk("([<%016lx>] ", sf->gprs[8] & PSW_ADDR_INSN);
113 print_symbol("%s)\n", sf->gprs[8] & PSW_ADDR_INSN);
114 /* Follow the backchain. */
115 while (1) {
116 low = sp;
117 sp = sf->back_chain & PSW_ADDR_INSN;
118 if (!sp)
119 break;
120 if (sp <= low || sp > high - sizeof(*sf))
121 return sp;
122 sf = (struct stack_frame *) sp;
123 printk(" [<%016lx>] ", sf->gprs[8] & PSW_ADDR_INSN);
124 print_symbol("%s\n", sf->gprs[8] & PSW_ADDR_INSN);
125 }
126 /* Zero backchain detected, check for interrupt frame. */
127 sp = (unsigned long) (sf + 1);
128 if (sp <= low || sp > high - sizeof(*regs))
129 return sp;
130 regs = (struct pt_regs *) sp;
131 printk(" [<%016lx>] ", regs->psw.addr & PSW_ADDR_INSN);
132 print_symbol("%s\n", regs->psw.addr & PSW_ADDR_INSN);
133 low = sp;
134 sp = regs->gprs[15];
135 }
136}
137
138void show_trace(struct task_struct *task, unsigned long * stack)
139{
140 register unsigned long __r15 asm ("15");
141 unsigned long sp;
142
143 sp = (unsigned long) stack;
144 if (!sp)
145 sp = task ? task->thread.ksp : __r15;
146 printk("Call Trace:\n");
147#ifdef CONFIG_CHECK_STACK
148 sp = __show_trace(sp, S390_lowcore.panic_stack - 4096,
149 S390_lowcore.panic_stack);
150#endif
151 sp = __show_trace(sp, S390_lowcore.async_stack - ASYNC_SIZE,
152 S390_lowcore.async_stack);
153 if (task)
Al Viro30af7122006-01-12 01:05:50 -0800154 __show_trace(sp, (unsigned long) task_stack_page(task),
155 (unsigned long) task_stack_page(task) + THREAD_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 else
157 __show_trace(sp, S390_lowcore.thread_info,
158 S390_lowcore.thread_info + THREAD_SIZE);
159 printk("\n");
160}
161
162void show_stack(struct task_struct *task, unsigned long *sp)
163{
164 register unsigned long * __r15 asm ("15");
165 unsigned long *stack;
166 int i;
167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 if (!sp)
Heiko Carstens73805342006-06-29 14:56:23 +0200169 stack = task ? (unsigned long *) task->thread.ksp : __r15;
170 else
171 stack = sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 for (i = 0; i < kstack_depth_to_print; i++) {
174 if (((addr_t) stack & (THREAD_SIZE-1)) == 0)
175 break;
176 if (i && ((i * sizeof (long) % 32) == 0))
177 printk("\n ");
178 printk("%p ", (void *)*stack++);
179 }
180 printk("\n");
181 show_trace(task, sp);
182}
183
184/*
185 * The architecture-independent dump_stack generator
186 */
187void dump_stack(void)
188{
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200189 show_stack(NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190}
191
192EXPORT_SYMBOL(dump_stack);
193
194void show_registers(struct pt_regs *regs)
195{
196 mm_segment_t old_fs;
197 char *mode;
198 int i;
199
200 mode = (regs->psw.mask & PSW_MASK_PSTATE) ? "User" : "Krnl";
201 printk("%s PSW : %p %p",
202 mode, (void *) regs->psw.mask,
203 (void *) regs->psw.addr);
204 print_symbol(" (%s)\n", regs->psw.addr & PSW_ADDR_INSN);
205 printk("%s GPRS: " FOURLONG, mode,
206 regs->gprs[0], regs->gprs[1], regs->gprs[2], regs->gprs[3]);
207 printk(" " FOURLONG,
208 regs->gprs[4], regs->gprs[5], regs->gprs[6], regs->gprs[7]);
209 printk(" " FOURLONG,
210 regs->gprs[8], regs->gprs[9], regs->gprs[10], regs->gprs[11]);
211 printk(" " FOURLONG,
212 regs->gprs[12], regs->gprs[13], regs->gprs[14], regs->gprs[15]);
213
214#if 0
215 /* FIXME: this isn't needed any more but it changes the ksymoops
216 * input. To remove or not to remove ... */
217 save_access_regs(regs->acrs);
218 printk("%s ACRS: %08x %08x %08x %08x\n", mode,
219 regs->acrs[0], regs->acrs[1], regs->acrs[2], regs->acrs[3]);
220 printk(" %08x %08x %08x %08x\n",
221 regs->acrs[4], regs->acrs[5], regs->acrs[6], regs->acrs[7]);
222 printk(" %08x %08x %08x %08x\n",
223 regs->acrs[8], regs->acrs[9], regs->acrs[10], regs->acrs[11]);
224 printk(" %08x %08x %08x %08x\n",
225 regs->acrs[12], regs->acrs[13], regs->acrs[14], regs->acrs[15]);
226#endif
227
228 /*
229 * Print the first 20 byte of the instruction stream at the
230 * time of the fault.
231 */
232 old_fs = get_fs();
233 if (regs->psw.mask & PSW_MASK_PSTATE)
234 set_fs(USER_DS);
235 else
236 set_fs(KERNEL_DS);
237 printk("%s Code: ", mode);
238 for (i = 0; i < 20; i++) {
239 unsigned char c;
240 if (__get_user(c, (char __user *)(regs->psw.addr + i))) {
241 printk(" Bad PSW.");
242 break;
243 }
244 printk("%02x ", c);
245 }
246 set_fs(old_fs);
247
248 printk("\n");
249}
250
251/* This is called from fs/proc/array.c */
252char *task_show_regs(struct task_struct *task, char *buffer)
253{
254 struct pt_regs *regs;
255
Al Viroc7584fb2006-01-12 01:05:49 -0800256 regs = task_pt_regs(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 buffer += sprintf(buffer, "task: %p, ksp: %p\n",
258 task, (void *)task->thread.ksp);
259 buffer += sprintf(buffer, "User PSW : %p %p\n",
260 (void *) regs->psw.mask, (void *)regs->psw.addr);
261
262 buffer += sprintf(buffer, "User GPRS: " FOURLONG,
263 regs->gprs[0], regs->gprs[1],
264 regs->gprs[2], regs->gprs[3]);
265 buffer += sprintf(buffer, " " FOURLONG,
266 regs->gprs[4], regs->gprs[5],
267 regs->gprs[6], regs->gprs[7]);
268 buffer += sprintf(buffer, " " FOURLONG,
269 regs->gprs[8], regs->gprs[9],
270 regs->gprs[10], regs->gprs[11]);
271 buffer += sprintf(buffer, " " FOURLONG,
272 regs->gprs[12], regs->gprs[13],
273 regs->gprs[14], regs->gprs[15]);
274 buffer += sprintf(buffer, "User ACRS: %08x %08x %08x %08x\n",
275 task->thread.acrs[0], task->thread.acrs[1],
276 task->thread.acrs[2], task->thread.acrs[3]);
277 buffer += sprintf(buffer, " %08x %08x %08x %08x\n",
278 task->thread.acrs[4], task->thread.acrs[5],
279 task->thread.acrs[6], task->thread.acrs[7]);
280 buffer += sprintf(buffer, " %08x %08x %08x %08x\n",
281 task->thread.acrs[8], task->thread.acrs[9],
282 task->thread.acrs[10], task->thread.acrs[11]);
283 buffer += sprintf(buffer, " %08x %08x %08x %08x\n",
284 task->thread.acrs[12], task->thread.acrs[13],
285 task->thread.acrs[14], task->thread.acrs[15]);
286 return buffer;
287}
288
289DEFINE_SPINLOCK(die_lock);
290
291void die(const char * str, struct pt_regs * regs, long err)
292{
293 static int die_counter;
294
295 debug_stop_all();
296 console_verbose();
297 spin_lock_irq(&die_lock);
298 bust_spinlocks(1);
299 printk("%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter);
300 show_regs(regs);
301 bust_spinlocks(0);
302 spin_unlock_irq(&die_lock);
303 if (in_interrupt())
304 panic("Fatal exception in interrupt");
305 if (panic_on_oops)
306 panic("Fatal exception: panic_on_oops");
307 do_exit(SIGSEGV);
308}
309
310static void inline
311report_user_fault(long interruption_code, struct pt_regs *regs)
312{
313#if defined(CONFIG_SYSCTL)
314 if (!sysctl_userprocess_debug)
315 return;
316#endif
317#if defined(CONFIG_SYSCTL) || defined(CONFIG_PROCESS_DEBUG)
318 printk("User process fault: interruption code 0x%lX\n",
319 interruption_code);
320 show_regs(regs);
321#endif
322}
323
Michael Grundy4ba069b2006-09-20 15:58:39 +0200324static void __kprobes inline do_trap(long interruption_code, int signr,
325 char *str, struct pt_regs *regs,
326 siginfo_t *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327{
328 /*
329 * We got all needed information from the lowcore and can
330 * now safely switch on interrupts.
331 */
332 if (regs->psw.mask & PSW_MASK_PSTATE)
333 local_irq_enable();
334
Michael Grundy4ba069b2006-09-20 15:58:39 +0200335 if (notify_die(DIE_TRAP, str, regs, interruption_code,
336 interruption_code, signr) == NOTIFY_STOP)
337 return;
338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 if (regs->psw.mask & PSW_MASK_PSTATE) {
340 struct task_struct *tsk = current;
341
342 tsk->thread.trap_no = interruption_code & 0xffff;
343 force_sig_info(signr, info, tsk);
344 report_user_fault(interruption_code, regs);
345 } else {
346 const struct exception_table_entry *fixup;
347 fixup = search_exception_tables(regs->psw.addr & PSW_ADDR_INSN);
348 if (fixup)
349 regs->psw.addr = fixup->fixup | PSW_ADDR_AMODE;
350 else
351 die(str, regs, interruption_code);
352 }
353}
354
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200355static inline void __user *get_check_address(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200357 return (void __user *)((regs->psw.addr-S390_lowcore.pgm_ilc) & PSW_ADDR_INSN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358}
359
Michael Grundy4ba069b2006-09-20 15:58:39 +0200360void __kprobes do_single_step(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
Michael Grundy4ba069b2006-09-20 15:58:39 +0200362 if (notify_die(DIE_SSTEP, "sstep", regs, 0, 0,
363 SIGTRAP) == NOTIFY_STOP){
364 return;
365 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 if ((current->ptrace & PT_PTRACED) != 0)
367 force_sig(SIGTRAP, current);
368}
369
370asmlinkage void
371default_trap_handler(struct pt_regs * regs, long interruption_code)
372{
373 if (regs->psw.mask & PSW_MASK_PSTATE) {
374 local_irq_enable();
375 do_exit(SIGSEGV);
376 report_user_fault(interruption_code, regs);
377 } else
378 die("Unknown program exception", regs, interruption_code);
379}
380
381#define DO_ERROR_INFO(signr, str, name, sicode, siaddr) \
382asmlinkage void name(struct pt_regs * regs, long interruption_code) \
383{ \
384 siginfo_t info; \
385 info.si_signo = signr; \
386 info.si_errno = 0; \
387 info.si_code = sicode; \
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200388 info.si_addr = siaddr; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 do_trap(interruption_code, signr, str, regs, &info); \
390}
391
392DO_ERROR_INFO(SIGILL, "addressing exception", addressing_exception,
393 ILL_ILLADR, get_check_address(regs))
394DO_ERROR_INFO(SIGILL, "execute exception", execute_exception,
395 ILL_ILLOPN, get_check_address(regs))
396DO_ERROR_INFO(SIGFPE, "fixpoint divide exception", divide_exception,
397 FPE_INTDIV, get_check_address(regs))
398DO_ERROR_INFO(SIGFPE, "fixpoint overflow exception", overflow_exception,
399 FPE_INTOVF, get_check_address(regs))
400DO_ERROR_INFO(SIGFPE, "HFP overflow exception", hfp_overflow_exception,
401 FPE_FLTOVF, get_check_address(regs))
402DO_ERROR_INFO(SIGFPE, "HFP underflow exception", hfp_underflow_exception,
403 FPE_FLTUND, get_check_address(regs))
404DO_ERROR_INFO(SIGFPE, "HFP significance exception", hfp_significance_exception,
405 FPE_FLTRES, get_check_address(regs))
406DO_ERROR_INFO(SIGFPE, "HFP divide exception", hfp_divide_exception,
407 FPE_FLTDIV, get_check_address(regs))
408DO_ERROR_INFO(SIGFPE, "HFP square root exception", hfp_sqrt_exception,
409 FPE_FLTINV, get_check_address(regs))
410DO_ERROR_INFO(SIGILL, "operand exception", operand_exception,
411 ILL_ILLOPN, get_check_address(regs))
412DO_ERROR_INFO(SIGILL, "privileged operation", privileged_op,
413 ILL_PRVOPC, get_check_address(regs))
414DO_ERROR_INFO(SIGILL, "special operation exception", special_op_exception,
415 ILL_ILLOPN, get_check_address(regs))
416DO_ERROR_INFO(SIGILL, "translation exception", translation_exception,
417 ILL_ILLOPN, get_check_address(regs))
418
419static inline void
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200420do_fp_trap(struct pt_regs *regs, void __user *location,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 int fpc, long interruption_code)
422{
423 siginfo_t si;
424
425 si.si_signo = SIGFPE;
426 si.si_errno = 0;
427 si.si_addr = location;
428 si.si_code = 0;
429 /* FPC[2] is Data Exception Code */
430 if ((fpc & 0x00000300) == 0) {
431 /* bits 6 and 7 of DXC are 0 iff IEEE exception */
432 if (fpc & 0x8000) /* invalid fp operation */
433 si.si_code = FPE_FLTINV;
434 else if (fpc & 0x4000) /* div by 0 */
435 si.si_code = FPE_FLTDIV;
436 else if (fpc & 0x2000) /* overflow */
437 si.si_code = FPE_FLTOVF;
438 else if (fpc & 0x1000) /* underflow */
439 si.si_code = FPE_FLTUND;
440 else if (fpc & 0x0800) /* inexact */
441 si.si_code = FPE_FLTRES;
442 }
443 current->thread.ieee_instruction_pointer = (addr_t) location;
444 do_trap(interruption_code, SIGFPE,
445 "floating point exception", regs, &si);
446}
447
448asmlinkage void illegal_op(struct pt_regs * regs, long interruption_code)
449{
450 siginfo_t info;
451 __u8 opcode[6];
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200452 __u16 __user *location;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 int signal = 0;
454
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200455 location = get_check_address(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
457 /*
458 * We got all needed information from the lowcore and can
459 * now safely switch on interrupts.
460 */
461 if (regs->psw.mask & PSW_MASK_PSTATE)
462 local_irq_enable();
463
464 if (regs->psw.mask & PSW_MASK_PSTATE) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200465 if (get_user(*((__u16 *) opcode), (__u16 __user *) location))
466 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 if (*((__u16 *) opcode) == S390_BREAKPOINT_U16) {
468 if (current->ptrace & PT_PTRACED)
469 force_sig(SIGTRAP, current);
470 else
471 signal = SIGILL;
472#ifdef CONFIG_MATHEMU
473 } else if (opcode[0] == 0xb3) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200474 if (get_user(*((__u16 *) (opcode+2)), location+1))
475 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 signal = math_emu_b3(opcode, regs);
477 } else if (opcode[0] == 0xed) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200478 if (get_user(*((__u32 *) (opcode+2)),
479 (__u32 __user *)(location+1)))
480 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 signal = math_emu_ed(opcode, regs);
482 } else if (*((__u16 *) opcode) == 0xb299) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200483 if (get_user(*((__u16 *) (opcode+2)), location+1))
484 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 signal = math_emu_srnm(opcode, regs);
486 } else if (*((__u16 *) opcode) == 0xb29c) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200487 if (get_user(*((__u16 *) (opcode+2)), location+1))
488 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 signal = math_emu_stfpc(opcode, regs);
490 } else if (*((__u16 *) opcode) == 0xb29d) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200491 if (get_user(*((__u16 *) (opcode+2)), location+1))
492 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 signal = math_emu_lfpc(opcode, regs);
494#endif
495 } else
496 signal = SIGILL;
497 } else
498 signal = SIGILL;
499
500#ifdef CONFIG_MATHEMU
501 if (signal == SIGFPE)
502 do_fp_trap(regs, location,
503 current->thread.fp_regs.fpc, interruption_code);
504 else if (signal == SIGSEGV) {
505 info.si_signo = signal;
506 info.si_errno = 0;
507 info.si_code = SEGV_MAPERR;
Al Viro5a42b812006-10-09 20:28:03 +0100508 info.si_addr = (void __user *) location;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 do_trap(interruption_code, signal,
510 "user address fault", regs, &info);
511 } else
512#endif
513 if (signal) {
514 info.si_signo = signal;
515 info.si_errno = 0;
516 info.si_code = ILL_ILLOPC;
Al Viro793af242006-02-01 06:55:59 -0500517 info.si_addr = (void __user *) location;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 do_trap(interruption_code, signal,
519 "illegal operation", regs, &info);
520 }
521}
522
523
524#ifdef CONFIG_MATHEMU
525asmlinkage void
526specification_exception(struct pt_regs * regs, long interruption_code)
527{
528 __u8 opcode[6];
Al Viro5a42b812006-10-09 20:28:03 +0100529 __u16 __user *location = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 int signal = 0;
531
Al Viro5a42b812006-10-09 20:28:03 +0100532 location = (__u16 __user *) get_check_address(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
534 /*
535 * We got all needed information from the lowcore and can
536 * now safely switch on interrupts.
537 */
538 if (regs->psw.mask & PSW_MASK_PSTATE)
539 local_irq_enable();
540
541 if (regs->psw.mask & PSW_MASK_PSTATE) {
542 get_user(*((__u16 *) opcode), location);
543 switch (opcode[0]) {
544 case 0x28: /* LDR Rx,Ry */
545 signal = math_emu_ldr(opcode);
546 break;
547 case 0x38: /* LER Rx,Ry */
548 signal = math_emu_ler(opcode);
549 break;
550 case 0x60: /* STD R,D(X,B) */
551 get_user(*((__u16 *) (opcode+2)), location+1);
552 signal = math_emu_std(opcode, regs);
553 break;
554 case 0x68: /* LD R,D(X,B) */
555 get_user(*((__u16 *) (opcode+2)), location+1);
556 signal = math_emu_ld(opcode, regs);
557 break;
558 case 0x70: /* STE R,D(X,B) */
559 get_user(*((__u16 *) (opcode+2)), location+1);
560 signal = math_emu_ste(opcode, regs);
561 break;
562 case 0x78: /* LE R,D(X,B) */
563 get_user(*((__u16 *) (opcode+2)), location+1);
564 signal = math_emu_le(opcode, regs);
565 break;
566 default:
567 signal = SIGILL;
568 break;
569 }
570 } else
571 signal = SIGILL;
572
573 if (signal == SIGFPE)
574 do_fp_trap(regs, location,
575 current->thread.fp_regs.fpc, interruption_code);
576 else if (signal) {
577 siginfo_t info;
578 info.si_signo = signal;
579 info.si_errno = 0;
580 info.si_code = ILL_ILLOPN;
581 info.si_addr = location;
582 do_trap(interruption_code, signal,
583 "specification exception", regs, &info);
584 }
585}
586#else
587DO_ERROR_INFO(SIGILL, "specification exception", specification_exception,
588 ILL_ILLOPN, get_check_address(regs));
589#endif
590
591asmlinkage void data_exception(struct pt_regs * regs, long interruption_code)
592{
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200593 __u16 __user *location;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 int signal = 0;
595
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200596 location = get_check_address(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
598 /*
599 * We got all needed information from the lowcore and can
600 * now safely switch on interrupts.
601 */
602 if (regs->psw.mask & PSW_MASK_PSTATE)
603 local_irq_enable();
604
605 if (MACHINE_HAS_IEEE)
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200606 asm volatile("stfpc %0" : "=m" (current->thread.fp_regs.fpc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
608#ifdef CONFIG_MATHEMU
609 else if (regs->psw.mask & PSW_MASK_PSTATE) {
610 __u8 opcode[6];
611 get_user(*((__u16 *) opcode), location);
612 switch (opcode[0]) {
613 case 0x28: /* LDR Rx,Ry */
614 signal = math_emu_ldr(opcode);
615 break;
616 case 0x38: /* LER Rx,Ry */
617 signal = math_emu_ler(opcode);
618 break;
619 case 0x60: /* STD R,D(X,B) */
620 get_user(*((__u16 *) (opcode+2)), location+1);
621 signal = math_emu_std(opcode, regs);
622 break;
623 case 0x68: /* LD R,D(X,B) */
624 get_user(*((__u16 *) (opcode+2)), location+1);
625 signal = math_emu_ld(opcode, regs);
626 break;
627 case 0x70: /* STE R,D(X,B) */
628 get_user(*((__u16 *) (opcode+2)), location+1);
629 signal = math_emu_ste(opcode, regs);
630 break;
631 case 0x78: /* LE R,D(X,B) */
632 get_user(*((__u16 *) (opcode+2)), location+1);
633 signal = math_emu_le(opcode, regs);
634 break;
635 case 0xb3:
636 get_user(*((__u16 *) (opcode+2)), location+1);
637 signal = math_emu_b3(opcode, regs);
638 break;
639 case 0xed:
640 get_user(*((__u32 *) (opcode+2)),
Al Viro5a42b812006-10-09 20:28:03 +0100641 (__u32 __user *)(location+1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 signal = math_emu_ed(opcode, regs);
643 break;
644 case 0xb2:
645 if (opcode[1] == 0x99) {
646 get_user(*((__u16 *) (opcode+2)), location+1);
647 signal = math_emu_srnm(opcode, regs);
648 } else if (opcode[1] == 0x9c) {
649 get_user(*((__u16 *) (opcode+2)), location+1);
650 signal = math_emu_stfpc(opcode, regs);
651 } else if (opcode[1] == 0x9d) {
652 get_user(*((__u16 *) (opcode+2)), location+1);
653 signal = math_emu_lfpc(opcode, regs);
654 } else
655 signal = SIGILL;
656 break;
657 default:
658 signal = SIGILL;
659 break;
660 }
661 }
662#endif
663 if (current->thread.fp_regs.fpc & FPC_DXC_MASK)
664 signal = SIGFPE;
665 else
666 signal = SIGILL;
667 if (signal == SIGFPE)
668 do_fp_trap(regs, location,
669 current->thread.fp_regs.fpc, interruption_code);
670 else if (signal) {
671 siginfo_t info;
672 info.si_signo = signal;
673 info.si_errno = 0;
674 info.si_code = ILL_ILLOPN;
675 info.si_addr = location;
676 do_trap(interruption_code, signal,
677 "data exception", regs, &info);
678 }
679}
680
681asmlinkage void space_switch_exception(struct pt_regs * regs, long int_code)
682{
683 siginfo_t info;
684
685 /* Set user psw back to home space mode. */
686 if (regs->psw.mask & PSW_MASK_PSTATE)
687 regs->psw.mask |= PSW_ASC_HOME;
688 /* Send SIGILL. */
689 info.si_signo = SIGILL;
690 info.si_errno = 0;
691 info.si_code = ILL_PRVOPC;
692 info.si_addr = get_check_address(regs);
693 do_trap(int_code, SIGILL, "space switch event", regs, &info);
694}
695
696asmlinkage void kernel_stack_overflow(struct pt_regs * regs)
697{
Heiko Carstens77eb65c2005-06-21 17:16:28 -0700698 bust_spinlocks(1);
699 printk("Kernel stack overflow.\n");
700 show_regs(regs);
701 bust_spinlocks(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 panic("Corrupt kernel stack, can't continue.");
703}
704
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705/* init is done in lowcore.S and head.S */
706
707void __init trap_init(void)
708{
709 int i;
710
711 for (i = 0; i < 128; i++)
712 pgm_check_table[i] = &default_trap_handler;
713 pgm_check_table[1] = &illegal_op;
714 pgm_check_table[2] = &privileged_op;
715 pgm_check_table[3] = &execute_exception;
716 pgm_check_table[4] = &do_protection_exception;
717 pgm_check_table[5] = &addressing_exception;
718 pgm_check_table[6] = &specification_exception;
719 pgm_check_table[7] = &data_exception;
720 pgm_check_table[8] = &overflow_exception;
721 pgm_check_table[9] = &divide_exception;
722 pgm_check_table[0x0A] = &overflow_exception;
723 pgm_check_table[0x0B] = &divide_exception;
724 pgm_check_table[0x0C] = &hfp_overflow_exception;
725 pgm_check_table[0x0D] = &hfp_underflow_exception;
726 pgm_check_table[0x0E] = &hfp_significance_exception;
727 pgm_check_table[0x0F] = &hfp_divide_exception;
728 pgm_check_table[0x10] = &do_dat_exception;
729 pgm_check_table[0x11] = &do_dat_exception;
730 pgm_check_table[0x12] = &translation_exception;
731 pgm_check_table[0x13] = &special_op_exception;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800732#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 pgm_check_table[0x38] = &do_dat_exception;
734 pgm_check_table[0x39] = &do_dat_exception;
735 pgm_check_table[0x3A] = &do_dat_exception;
736 pgm_check_table[0x3B] = &do_dat_exception;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800737#endif /* CONFIG_64BIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 pgm_check_table[0x15] = &operand_exception;
739 pgm_check_table[0x1C] = &space_switch_exception;
740 pgm_check_table[0x1D] = &hfp_sqrt_exception;
741 pgm_check_table[0x40] = &do_monitor_call;
742
743 if (MACHINE_IS_VM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744#ifdef CONFIG_PFAULT
Martin Schwidefskyd4b68992005-11-07 00:59:06 -0800745 /*
746 * Try to get pfault pseudo page faults going.
747 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 if (register_early_external_interrupt(0x2603, pfault_interrupt,
749 &ext_int_pfault) != 0)
750 panic("Couldn't request external interrupt 0x2603");
751
752 if (pfault_init() == 0)
753 return;
754
755 /* Tough luck, no pfault. */
756 unregister_early_external_interrupt(0x2603, pfault_interrupt,
757 &ext_int_pfault);
758#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 }
760}