2 * arch/s390/kernel/traps.c
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),
9 * Derived from "arch/i386/kernel/traps.c"
10 * Copyright (C) 1991, 1992 Linus Torvalds
14 * 'Traps.c' handles hardware traps and faults after we have saved some
17 #include <linux/config.h>
18 #include <linux/sched.h>
19 #include <linux/kernel.h>
20 #include <linux/string.h>
21 #include <linux/errno.h>
22 #include <linux/ptrace.h>
23 #include <linux/timer.h>
25 #include <linux/smp.h>
26 #include <linux/smp_lock.h>
27 #include <linux/init.h>
28 #include <linux/interrupt.h>
29 #include <linux/delay.h>
30 #include <linux/module.h>
31 #include <linux/kallsyms.h>
33 #include <asm/system.h>
34 #include <asm/uaccess.h>
36 #include <asm/atomic.h>
37 #include <asm/mathemu.h>
38 #include <asm/cpcmd.h>
39 #include <asm/s390_ext.h>
40 #include <asm/lowcore.h>
42 /* Called from entry.S only */
43 extern void handle_per_exception(struct pt_regs *regs);
45 typedef void pgm_check_handler_t(struct pt_regs *, long);
46 pgm_check_handler_t *pgm_check_table[128];
49 #ifdef CONFIG_PROCESS_DEBUG
50 int sysctl_userprocess_debug = 1;
52 int sysctl_userprocess_debug = 0;
56 extern pgm_check_handler_t do_protection_exception;
57 extern pgm_check_handler_t do_dat_exception;
58 extern pgm_check_handler_t do_pseudo_page_fault;
60 extern int pfault_init(void);
61 extern void pfault_fini(void);
62 extern void pfault_interrupt(struct pt_regs *regs, __u16 error_code);
63 static ext_int_info_t ext_int_pfault;
65 extern pgm_check_handler_t do_monitor_call;
67 #define stack_pointer ({ void **sp; asm("la %0,0(15)" : "=&d" (sp)); sp; })
69 #ifndef CONFIG_ARCH_S390X
71 #define FOURLONG "%08lx %08lx %08lx %08lx\n"
72 static int kstack_depth_to_print = 12;
74 #else /* CONFIG_ARCH_S390X */
76 #define FOURLONG "%016lx %016lx %016lx %016lx\n"
77 static int kstack_depth_to_print = 20;
79 #endif /* CONFIG_ARCH_S390X */
81 void show_trace(struct task_struct *task, unsigned long * stack)
83 unsigned long backchain, low_addr, high_addr, ret_addr;
86 stack = (task == NULL) ? *stack_pointer : &(task->thread.ksp);
88 printk("Call Trace:\n");
89 low_addr = ((unsigned long) stack) & PSW_ADDR_INSN;
90 high_addr = (low_addr & (-THREAD_SIZE)) + THREAD_SIZE;
91 /* Skip the first frame (biased stack) */
92 backchain = *((unsigned long *) low_addr) & PSW_ADDR_INSN;
93 /* Print up to 8 lines */
94 while (backchain > low_addr && backchain <= high_addr) {
95 ret_addr = *((unsigned long *) (backchain+RET_ADDR)) & PSW_ADDR_INSN;
96 printk(" [<%016lx>] ", ret_addr);
97 print_symbol("%s\n", ret_addr);
99 backchain = *((unsigned long *) backchain) & PSW_ADDR_INSN;
104 void show_stack(struct task_struct *task, unsigned long *sp)
106 unsigned long *stack;
109 // debugging aid: "show_stack(NULL);" prints the
110 // back trace for this cpu.
114 sp = (unsigned long *) task->thread.ksp;
120 for (i = 0; i < kstack_depth_to_print; i++) {
121 if (((addr_t) stack & (THREAD_SIZE-1)) == 0)
123 if (i && ((i * sizeof (long) % 32) == 0))
125 printk("%p ", (void *)*stack++);
128 show_trace(task, sp);
132 * The architecture-independent dump_stack generator
134 void dump_stack(void)
139 EXPORT_SYMBOL(dump_stack);
141 void show_registers(struct pt_regs *regs)
147 mode = (regs->psw.mask & PSW_MASK_PSTATE) ? "User" : "Krnl";
148 printk("%s PSW : %p %p",
149 mode, (void *) regs->psw.mask,
150 (void *) regs->psw.addr);
151 print_symbol(" (%s)\n", regs->psw.addr & PSW_ADDR_INSN);
152 printk("%s GPRS: " FOURLONG, mode,
153 regs->gprs[0], regs->gprs[1], regs->gprs[2], regs->gprs[3]);
155 regs->gprs[4], regs->gprs[5], regs->gprs[6], regs->gprs[7]);
157 regs->gprs[8], regs->gprs[9], regs->gprs[10], regs->gprs[11]);
159 regs->gprs[12], regs->gprs[13], regs->gprs[14], regs->gprs[15]);
162 /* FIXME: this isn't needed any more but it changes the ksymoops
163 * input. To remove or not to remove ... */
164 save_access_regs(regs->acrs);
165 printk("%s ACRS: %08x %08x %08x %08x\n", mode,
166 regs->acrs[0], regs->acrs[1], regs->acrs[2], regs->acrs[3]);
167 printk(" %08x %08x %08x %08x\n",
168 regs->acrs[4], regs->acrs[5], regs->acrs[6], regs->acrs[7]);
169 printk(" %08x %08x %08x %08x\n",
170 regs->acrs[8], regs->acrs[9], regs->acrs[10], regs->acrs[11]);
171 printk(" %08x %08x %08x %08x\n",
172 regs->acrs[12], regs->acrs[13], regs->acrs[14], regs->acrs[15]);
176 * Print the first 20 byte of the instruction stream at the
180 if (regs->psw.mask & PSW_MASK_PSTATE)
184 printk("%s Code: ", mode);
185 for (i = 0; i < 20; i++) {
187 if (__get_user(c, (char __user *)(regs->psw.addr + i))) {
198 /* This is called from fs/proc/array.c */
199 char *task_show_regs(struct task_struct *task, char *buffer)
201 struct pt_regs *regs;
203 regs = __KSTK_PTREGS(task);
204 buffer += sprintf(buffer, "task: %p, ksp: %p\n",
205 task, (void *)task->thread.ksp);
206 buffer += sprintf(buffer, "User PSW : %p %p\n",
207 (void *) regs->psw.mask, (void *)regs->psw.addr);
209 buffer += sprintf(buffer, "User GPRS: " FOURLONG,
210 regs->gprs[0], regs->gprs[1],
211 regs->gprs[2], regs->gprs[3]);
212 buffer += sprintf(buffer, " " FOURLONG,
213 regs->gprs[4], regs->gprs[5],
214 regs->gprs[6], regs->gprs[7]);
215 buffer += sprintf(buffer, " " FOURLONG,
216 regs->gprs[8], regs->gprs[9],
217 regs->gprs[10], regs->gprs[11]);
218 buffer += sprintf(buffer, " " FOURLONG,
219 regs->gprs[12], regs->gprs[13],
220 regs->gprs[14], regs->gprs[15]);
221 buffer += sprintf(buffer, "User ACRS: %08x %08x %08x %08x\n",
222 task->thread.acrs[0], task->thread.acrs[1],
223 task->thread.acrs[2], task->thread.acrs[3]);
224 buffer += sprintf(buffer, " %08x %08x %08x %08x\n",
225 task->thread.acrs[4], task->thread.acrs[5],
226 task->thread.acrs[6], task->thread.acrs[7]);
227 buffer += sprintf(buffer, " %08x %08x %08x %08x\n",
228 task->thread.acrs[8], task->thread.acrs[9],
229 task->thread.acrs[10], task->thread.acrs[11]);
230 buffer += sprintf(buffer, " %08x %08x %08x %08x\n",
231 task->thread.acrs[12], task->thread.acrs[13],
232 task->thread.acrs[14], task->thread.acrs[15]);
236 spinlock_t die_lock = SPIN_LOCK_UNLOCKED;
238 void die(const char * str, struct pt_regs * regs, long err)
240 static int die_counter;
242 spin_lock_irq(&die_lock);
244 printk("%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter);
247 spin_unlock_irq(&die_lock);
249 panic("Fatal exception in interrupt");
251 panic("Fatal exception: panic_on_oops");
255 static void inline do_trap(long interruption_code, int signr, char *str,
256 struct pt_regs *regs, siginfo_t *info)
259 * We got all needed information from the lowcore and can
260 * now safely switch on interrupts.
262 if (regs->psw.mask & PSW_MASK_PSTATE)
265 if (regs->psw.mask & PSW_MASK_PSTATE) {
266 struct task_struct *tsk = current;
268 tsk->thread.trap_no = interruption_code & 0xffff;
270 force_sig_info(signr, info, tsk);
272 force_sig(signr, tsk);
273 #ifndef CONFIG_SYSCTL
274 #ifdef CONFIG_PROCESS_DEBUG
275 printk("User process fault: interruption code 0x%lX\n",
280 if (sysctl_userprocess_debug) {
281 printk("User process fault: interruption code 0x%lX\n",
287 const struct exception_table_entry *fixup;
288 fixup = search_exception_tables(regs->psw.addr & PSW_ADDR_INSN);
290 regs->psw.addr = fixup->fixup | PSW_ADDR_AMODE;
292 die(str, regs, interruption_code);
296 static inline void *get_check_address(struct pt_regs *regs)
298 return (void *)((regs->psw.addr-S390_lowcore.pgm_ilc) & PSW_ADDR_INSN);
301 void do_single_step(struct pt_regs *regs)
303 if ((current->ptrace & PT_PTRACED) != 0)
304 force_sig(SIGTRAP, current);
307 #define DO_ERROR(signr, str, name) \
308 asmlinkage void name(struct pt_regs * regs, long interruption_code) \
310 do_trap(interruption_code, signr, str, regs, NULL); \
313 #define DO_ERROR_INFO(signr, str, name, sicode, siaddr) \
314 asmlinkage void name(struct pt_regs * regs, long interruption_code) \
317 info.si_signo = signr; \
319 info.si_code = sicode; \
320 info.si_addr = (void *)siaddr; \
321 do_trap(interruption_code, signr, str, regs, &info); \
324 DO_ERROR(SIGSEGV, "Unknown program exception", default_trap_handler)
326 DO_ERROR_INFO(SIGILL, "addressing exception", addressing_exception,
327 ILL_ILLADR, get_check_address(regs))
328 DO_ERROR_INFO(SIGILL, "execute exception", execute_exception,
329 ILL_ILLOPN, get_check_address(regs))
330 DO_ERROR_INFO(SIGFPE, "fixpoint divide exception", divide_exception,
331 FPE_INTDIV, get_check_address(regs))
332 DO_ERROR_INFO(SIGFPE, "fixpoint overflow exception", overflow_exception,
333 FPE_INTOVF, get_check_address(regs))
334 DO_ERROR_INFO(SIGFPE, "HFP overflow exception", hfp_overflow_exception,
335 FPE_FLTOVF, get_check_address(regs))
336 DO_ERROR_INFO(SIGFPE, "HFP underflow exception", hfp_underflow_exception,
337 FPE_FLTUND, get_check_address(regs))
338 DO_ERROR_INFO(SIGFPE, "HFP significance exception", hfp_significance_exception,
339 FPE_FLTRES, get_check_address(regs))
340 DO_ERROR_INFO(SIGFPE, "HFP divide exception", hfp_divide_exception,
341 FPE_FLTDIV, get_check_address(regs))
342 DO_ERROR_INFO(SIGFPE, "HFP square root exception", hfp_sqrt_exception,
343 FPE_FLTINV, get_check_address(regs))
344 DO_ERROR_INFO(SIGILL, "operand exception", operand_exception,
345 ILL_ILLOPN, get_check_address(regs))
346 DO_ERROR_INFO(SIGILL, "privileged operation", privileged_op,
347 ILL_PRVOPC, get_check_address(regs))
348 DO_ERROR_INFO(SIGILL, "special operation exception", special_op_exception,
349 ILL_ILLOPN, get_check_address(regs))
350 DO_ERROR_INFO(SIGILL, "translation exception", translation_exception,
351 ILL_ILLOPN, get_check_address(regs))
354 do_fp_trap(struct pt_regs *regs, void *location,
355 int fpc, long interruption_code)
359 si.si_signo = SIGFPE;
361 si.si_addr = location;
363 /* FPC[2] is Data Exception Code */
364 if ((fpc & 0x00000300) == 0) {
365 /* bits 6 and 7 of DXC are 0 iff IEEE exception */
366 if (fpc & 0x8000) /* invalid fp operation */
367 si.si_code = FPE_FLTINV;
368 else if (fpc & 0x4000) /* div by 0 */
369 si.si_code = FPE_FLTDIV;
370 else if (fpc & 0x2000) /* overflow */
371 si.si_code = FPE_FLTOVF;
372 else if (fpc & 0x1000) /* underflow */
373 si.si_code = FPE_FLTUND;
374 else if (fpc & 0x0800) /* inexact */
375 si.si_code = FPE_FLTRES;
377 current->thread.ieee_instruction_pointer = (addr_t) location;
378 do_trap(interruption_code, SIGFPE,
379 "floating point exception", regs, &si);
382 asmlinkage void illegal_op(struct pt_regs * regs, long interruption_code)
388 location = (__u16 *) get_check_address(regs);
391 * We got all needed information from the lowcore and can
392 * now safely switch on interrupts.
394 if (regs->psw.mask & PSW_MASK_PSTATE)
397 if (regs->psw.mask & PSW_MASK_PSTATE) {
398 get_user(*((__u16 *) opcode), (__u16 __user *) location);
399 if (*((__u16 *) opcode) == S390_BREAKPOINT_U16) {
400 if (current->ptrace & PT_PTRACED)
401 force_sig(SIGTRAP, current);
404 #ifdef CONFIG_MATHEMU
405 } else if (opcode[0] == 0xb3) {
406 get_user(*((__u16 *) (opcode+2)), location+1);
407 signal = math_emu_b3(opcode, regs);
408 } else if (opcode[0] == 0xed) {
409 get_user(*((__u32 *) (opcode+2)),
410 (__u32 *)(location+1));
411 signal = math_emu_ed(opcode, regs);
412 } else if (*((__u16 *) opcode) == 0xb299) {
413 get_user(*((__u16 *) (opcode+2)), location+1);
414 signal = math_emu_srnm(opcode, regs);
415 } else if (*((__u16 *) opcode) == 0xb29c) {
416 get_user(*((__u16 *) (opcode+2)), location+1);
417 signal = math_emu_stfpc(opcode, regs);
418 } else if (*((__u16 *) opcode) == 0xb29d) {
419 get_user(*((__u16 *) (opcode+2)), location+1);
420 signal = math_emu_lfpc(opcode, regs);
427 if (signal == SIGFPE)
428 do_fp_trap(regs, location,
429 current->thread.fp_regs.fpc, interruption_code);
431 do_trap(interruption_code, signal,
432 "illegal operation", regs, NULL);
436 #ifdef CONFIG_MATHEMU
438 specification_exception(struct pt_regs * regs, long interruption_code)
441 __u16 *location = NULL;
444 location = (__u16 *) get_check_address(regs);
447 * We got all needed information from the lowcore and can
448 * now safely switch on interrupts.
450 if (regs->psw.mask & PSW_MASK_PSTATE)
453 if (regs->psw.mask & PSW_MASK_PSTATE) {
454 get_user(*((__u16 *) opcode), location);
456 case 0x28: /* LDR Rx,Ry */
457 signal = math_emu_ldr(opcode);
459 case 0x38: /* LER Rx,Ry */
460 signal = math_emu_ler(opcode);
462 case 0x60: /* STD R,D(X,B) */
463 get_user(*((__u16 *) (opcode+2)), location+1);
464 signal = math_emu_std(opcode, regs);
466 case 0x68: /* LD R,D(X,B) */
467 get_user(*((__u16 *) (opcode+2)), location+1);
468 signal = math_emu_ld(opcode, regs);
470 case 0x70: /* STE R,D(X,B) */
471 get_user(*((__u16 *) (opcode+2)), location+1);
472 signal = math_emu_ste(opcode, regs);
474 case 0x78: /* LE R,D(X,B) */
475 get_user(*((__u16 *) (opcode+2)), location+1);
476 signal = math_emu_le(opcode, regs);
485 if (signal == SIGFPE)
486 do_fp_trap(regs, location,
487 current->thread.fp_regs.fpc, interruption_code);
490 info.si_signo = signal;
492 info.si_code = ILL_ILLOPN;
493 info.si_addr = location;
494 do_trap(interruption_code, signal,
495 "specification exception", regs, &info);
499 DO_ERROR_INFO(SIGILL, "specification exception", specification_exception,
500 ILL_ILLOPN, get_check_address(regs));
503 asmlinkage void data_exception(struct pt_regs * regs, long interruption_code)
508 location = (__u16 *) get_check_address(regs);
511 * We got all needed information from the lowcore and can
512 * now safely switch on interrupts.
514 if (regs->psw.mask & PSW_MASK_PSTATE)
517 if (MACHINE_HAS_IEEE)
518 __asm__ volatile ("stfpc %0\n\t"
519 : "=m" (current->thread.fp_regs.fpc));
521 #ifdef CONFIG_MATHEMU
522 else if (regs->psw.mask & PSW_MASK_PSTATE) {
524 get_user(*((__u16 *) opcode), location);
526 case 0x28: /* LDR Rx,Ry */
527 signal = math_emu_ldr(opcode);
529 case 0x38: /* LER Rx,Ry */
530 signal = math_emu_ler(opcode);
532 case 0x60: /* STD R,D(X,B) */
533 get_user(*((__u16 *) (opcode+2)), location+1);
534 signal = math_emu_std(opcode, regs);
536 case 0x68: /* LD R,D(X,B) */
537 get_user(*((__u16 *) (opcode+2)), location+1);
538 signal = math_emu_ld(opcode, regs);
540 case 0x70: /* STE R,D(X,B) */
541 get_user(*((__u16 *) (opcode+2)), location+1);
542 signal = math_emu_ste(opcode, regs);
544 case 0x78: /* LE R,D(X,B) */
545 get_user(*((__u16 *) (opcode+2)), location+1);
546 signal = math_emu_le(opcode, regs);
549 get_user(*((__u16 *) (opcode+2)), location+1);
550 signal = math_emu_b3(opcode, regs);
553 get_user(*((__u32 *) (opcode+2)),
554 (__u32 *)(location+1));
555 signal = math_emu_ed(opcode, regs);
558 if (opcode[1] == 0x99) {
559 get_user(*((__u16 *) (opcode+2)), location+1);
560 signal = math_emu_srnm(opcode, regs);
561 } else if (opcode[1] == 0x9c) {
562 get_user(*((__u16 *) (opcode+2)), location+1);
563 signal = math_emu_stfpc(opcode, regs);
564 } else if (opcode[1] == 0x9d) {
565 get_user(*((__u16 *) (opcode+2)), location+1);
566 signal = math_emu_lfpc(opcode, regs);
576 if (current->thread.fp_regs.fpc & FPC_DXC_MASK)
580 if (signal == SIGFPE)
581 do_fp_trap(regs, location,
582 current->thread.fp_regs.fpc, interruption_code);
585 info.si_signo = signal;
587 info.si_code = ILL_ILLOPN;
588 info.si_addr = location;
589 do_trap(interruption_code, signal,
590 "data exception", regs, &info);
596 /* init is done in lowcore.S and head.S */
598 void __init trap_init(void)
602 for (i = 0; i < 128; i++)
603 pgm_check_table[i] = &default_trap_handler;
604 pgm_check_table[1] = &illegal_op;
605 pgm_check_table[2] = &privileged_op;
606 pgm_check_table[3] = &execute_exception;
607 pgm_check_table[4] = &do_protection_exception;
608 pgm_check_table[5] = &addressing_exception;
609 pgm_check_table[6] = &specification_exception;
610 pgm_check_table[7] = &data_exception;
611 pgm_check_table[8] = &overflow_exception;
612 pgm_check_table[9] = ÷_exception;
613 pgm_check_table[0x0A] = &overflow_exception;
614 pgm_check_table[0x0B] = ÷_exception;
615 pgm_check_table[0x0C] = &hfp_overflow_exception;
616 pgm_check_table[0x0D] = &hfp_underflow_exception;
617 pgm_check_table[0x0E] = &hfp_significance_exception;
618 pgm_check_table[0x0F] = &hfp_divide_exception;
619 pgm_check_table[0x10] = &do_dat_exception;
620 pgm_check_table[0x11] = &do_dat_exception;
621 pgm_check_table[0x12] = &translation_exception;
622 pgm_check_table[0x13] = &special_op_exception;
623 #ifndef CONFIG_ARCH_S390X
624 pgm_check_table[0x14] = &do_pseudo_page_fault;
625 #else /* CONFIG_ARCH_S390X */
626 pgm_check_table[0x38] = &do_dat_exception;
627 pgm_check_table[0x39] = &do_dat_exception;
628 pgm_check_table[0x3A] = &do_dat_exception;
629 pgm_check_table[0x3B] = &do_dat_exception;
630 #endif /* CONFIG_ARCH_S390X */
631 pgm_check_table[0x15] = &operand_exception;
632 pgm_check_table[0x1C] = &privileged_op;
633 pgm_check_table[0x1D] = &hfp_sqrt_exception;
634 pgm_check_table[0x40] = &do_monitor_call;
638 * First try to get pfault pseudo page faults going.
639 * If this isn't available turn on pagex page faults.
642 /* request the 0x2603 external interrupt */
643 if (register_early_external_interrupt(0x2603, pfault_interrupt,
644 &ext_int_pfault) != 0)
645 panic("Couldn't request external interrupt 0x2603");
647 if (pfault_init() == 0)
650 /* Tough luck, no pfault. */
651 unregister_early_external_interrupt(0x2603, pfault_interrupt,
654 #ifndef CONFIG_ARCH_S390X
655 cpcmd("SET PAGEX ON", NULL, 0);