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);
249 spin_unlock_irq(&die_lock);
251 panic("Fatal exception in interrupt");
255 panic("Fatal exception: panic_on_oops");
260 static void inline do_trap(long interruption_code, int signr, char *str,
261 struct pt_regs *regs, siginfo_t *info)
264 * We got all needed information from the lowcore and can
265 * now safely switch on interrupts.
267 if (regs->psw.mask & PSW_MASK_PSTATE)
270 if (regs->psw.mask & PSW_MASK_PSTATE) {
271 struct task_struct *tsk = current;
273 tsk->thread.trap_no = interruption_code & 0xffff;
275 force_sig_info(signr, info, tsk);
277 force_sig(signr, tsk);
278 #ifndef CONFIG_SYSCTL
279 #ifdef CONFIG_PROCESS_DEBUG
280 printk("User process fault: interruption code 0x%lX\n",
285 if (sysctl_userprocess_debug) {
286 printk("User process fault: interruption code 0x%lX\n",
292 const struct exception_table_entry *fixup;
293 fixup = search_exception_tables(regs->psw.addr & PSW_ADDR_INSN);
295 regs->psw.addr = fixup->fixup | PSW_ADDR_AMODE;
297 die(str, regs, interruption_code);
301 static inline void *get_check_address(struct pt_regs *regs)
303 return (void *)((regs->psw.addr-S390_lowcore.pgm_ilc) & PSW_ADDR_INSN);
306 void do_single_step(struct pt_regs *regs)
308 if ((current->ptrace & PT_PTRACED) != 0)
309 force_sig(SIGTRAP, current);
312 #define DO_ERROR(signr, str, name) \
313 asmlinkage void name(struct pt_regs * regs, long interruption_code) \
315 do_trap(interruption_code, signr, str, regs, NULL); \
318 #define DO_ERROR_INFO(signr, str, name, sicode, siaddr) \
319 asmlinkage void name(struct pt_regs * regs, long interruption_code) \
322 info.si_signo = signr; \
324 info.si_code = sicode; \
325 info.si_addr = (void *)siaddr; \
326 do_trap(interruption_code, signr, str, regs, &info); \
329 DO_ERROR(SIGSEGV, "Unknown program exception", default_trap_handler)
331 DO_ERROR_INFO(SIGILL, "addressing exception", addressing_exception,
332 ILL_ILLADR, get_check_address(regs))
333 DO_ERROR_INFO(SIGILL, "execute exception", execute_exception,
334 ILL_ILLOPN, get_check_address(regs))
335 DO_ERROR_INFO(SIGFPE, "fixpoint divide exception", divide_exception,
336 FPE_INTDIV, get_check_address(regs))
337 DO_ERROR_INFO(SIGFPE, "fixpoint overflow exception", overflow_exception,
338 FPE_INTOVF, get_check_address(regs))
339 DO_ERROR_INFO(SIGFPE, "HFP overflow exception", hfp_overflow_exception,
340 FPE_FLTOVF, get_check_address(regs))
341 DO_ERROR_INFO(SIGFPE, "HFP underflow exception", hfp_underflow_exception,
342 FPE_FLTUND, get_check_address(regs))
343 DO_ERROR_INFO(SIGFPE, "HFP significance exception", hfp_significance_exception,
344 FPE_FLTRES, get_check_address(regs))
345 DO_ERROR_INFO(SIGFPE, "HFP divide exception", hfp_divide_exception,
346 FPE_FLTDIV, get_check_address(regs))
347 DO_ERROR_INFO(SIGFPE, "HFP square root exception", hfp_sqrt_exception,
348 FPE_FLTINV, get_check_address(regs))
349 DO_ERROR_INFO(SIGILL, "operand exception", operand_exception,
350 ILL_ILLOPN, get_check_address(regs))
351 DO_ERROR_INFO(SIGILL, "privileged operation", privileged_op,
352 ILL_PRVOPC, get_check_address(regs))
353 DO_ERROR_INFO(SIGILL, "special operation exception", special_op_exception,
354 ILL_ILLOPN, get_check_address(regs))
355 DO_ERROR_INFO(SIGILL, "translation exception", translation_exception,
356 ILL_ILLOPN, get_check_address(regs))
359 do_fp_trap(struct pt_regs *regs, void *location,
360 int fpc, long interruption_code)
364 si.si_signo = SIGFPE;
366 si.si_addr = location;
368 /* FPC[2] is Data Exception Code */
369 if ((fpc & 0x00000300) == 0) {
370 /* bits 6 and 7 of DXC are 0 iff IEEE exception */
371 if (fpc & 0x8000) /* invalid fp operation */
372 si.si_code = FPE_FLTINV;
373 else if (fpc & 0x4000) /* div by 0 */
374 si.si_code = FPE_FLTDIV;
375 else if (fpc & 0x2000) /* overflow */
376 si.si_code = FPE_FLTOVF;
377 else if (fpc & 0x1000) /* underflow */
378 si.si_code = FPE_FLTUND;
379 else if (fpc & 0x0800) /* inexact */
380 si.si_code = FPE_FLTRES;
382 current->thread.ieee_instruction_pointer = (addr_t) location;
383 do_trap(interruption_code, SIGFPE,
384 "floating point exception", regs, &si);
387 asmlinkage void illegal_op(struct pt_regs * regs, long interruption_code)
393 location = (__u16 *) get_check_address(regs);
396 * We got all needed information from the lowcore and can
397 * now safely switch on interrupts.
399 if (regs->psw.mask & PSW_MASK_PSTATE)
402 if (regs->psw.mask & PSW_MASK_PSTATE) {
403 get_user(*((__u16 *) opcode), (__u16 __user *) location);
404 if (*((__u16 *) opcode) == S390_BREAKPOINT_U16) {
405 if (current->ptrace & PT_PTRACED)
406 force_sig(SIGTRAP, current);
409 #ifdef CONFIG_MATHEMU
410 } else if (opcode[0] == 0xb3) {
411 get_user(*((__u16 *) (opcode+2)), location+1);
412 signal = math_emu_b3(opcode, regs);
413 } else if (opcode[0] == 0xed) {
414 get_user(*((__u32 *) (opcode+2)),
415 (__u32 *)(location+1));
416 signal = math_emu_ed(opcode, regs);
417 } else if (*((__u16 *) opcode) == 0xb299) {
418 get_user(*((__u16 *) (opcode+2)), location+1);
419 signal = math_emu_srnm(opcode, regs);
420 } else if (*((__u16 *) opcode) == 0xb29c) {
421 get_user(*((__u16 *) (opcode+2)), location+1);
422 signal = math_emu_stfpc(opcode, regs);
423 } else if (*((__u16 *) opcode) == 0xb29d) {
424 get_user(*((__u16 *) (opcode+2)), location+1);
425 signal = math_emu_lfpc(opcode, regs);
432 if (signal == SIGFPE)
433 do_fp_trap(regs, location,
434 current->thread.fp_regs.fpc, interruption_code);
436 do_trap(interruption_code, signal,
437 "illegal operation", regs, NULL);
441 #ifdef CONFIG_MATHEMU
443 specification_exception(struct pt_regs * regs, long interruption_code)
446 __u16 *location = NULL;
449 location = (__u16 *) get_check_address(regs);
452 * We got all needed information from the lowcore and can
453 * now safely switch on interrupts.
455 if (regs->psw.mask & PSW_MASK_PSTATE)
458 if (regs->psw.mask & PSW_MASK_PSTATE) {
459 get_user(*((__u16 *) opcode), location);
461 case 0x28: /* LDR Rx,Ry */
462 signal = math_emu_ldr(opcode);
464 case 0x38: /* LER Rx,Ry */
465 signal = math_emu_ler(opcode);
467 case 0x60: /* STD R,D(X,B) */
468 get_user(*((__u16 *) (opcode+2)), location+1);
469 signal = math_emu_std(opcode, regs);
471 case 0x68: /* LD R,D(X,B) */
472 get_user(*((__u16 *) (opcode+2)), location+1);
473 signal = math_emu_ld(opcode, regs);
475 case 0x70: /* STE R,D(X,B) */
476 get_user(*((__u16 *) (opcode+2)), location+1);
477 signal = math_emu_ste(opcode, regs);
479 case 0x78: /* LE R,D(X,B) */
480 get_user(*((__u16 *) (opcode+2)), location+1);
481 signal = math_emu_le(opcode, regs);
490 if (signal == SIGFPE)
491 do_fp_trap(regs, location,
492 current->thread.fp_regs.fpc, interruption_code);
495 info.si_signo = signal;
497 info.si_code = ILL_ILLOPN;
498 info.si_addr = location;
499 do_trap(interruption_code, signal,
500 "specification exception", regs, &info);
504 DO_ERROR_INFO(SIGILL, "specification exception", specification_exception,
505 ILL_ILLOPN, get_check_address(regs));
508 asmlinkage void data_exception(struct pt_regs * regs, long interruption_code)
513 location = (__u16 *) get_check_address(regs);
516 * We got all needed information from the lowcore and can
517 * now safely switch on interrupts.
519 if (regs->psw.mask & PSW_MASK_PSTATE)
522 if (MACHINE_HAS_IEEE)
523 __asm__ volatile ("stfpc %0\n\t"
524 : "=m" (current->thread.fp_regs.fpc));
526 #ifdef CONFIG_MATHEMU
527 else if (regs->psw.mask & PSW_MASK_PSTATE) {
529 get_user(*((__u16 *) opcode), location);
531 case 0x28: /* LDR Rx,Ry */
532 signal = math_emu_ldr(opcode);
534 case 0x38: /* LER Rx,Ry */
535 signal = math_emu_ler(opcode);
537 case 0x60: /* STD R,D(X,B) */
538 get_user(*((__u16 *) (opcode+2)), location+1);
539 signal = math_emu_std(opcode, regs);
541 case 0x68: /* LD R,D(X,B) */
542 get_user(*((__u16 *) (opcode+2)), location+1);
543 signal = math_emu_ld(opcode, regs);
545 case 0x70: /* STE R,D(X,B) */
546 get_user(*((__u16 *) (opcode+2)), location+1);
547 signal = math_emu_ste(opcode, regs);
549 case 0x78: /* LE R,D(X,B) */
550 get_user(*((__u16 *) (opcode+2)), location+1);
551 signal = math_emu_le(opcode, regs);
554 get_user(*((__u16 *) (opcode+2)), location+1);
555 signal = math_emu_b3(opcode, regs);
558 get_user(*((__u32 *) (opcode+2)),
559 (__u32 *)(location+1));
560 signal = math_emu_ed(opcode, regs);
563 if (opcode[1] == 0x99) {
564 get_user(*((__u16 *) (opcode+2)), location+1);
565 signal = math_emu_srnm(opcode, regs);
566 } else if (opcode[1] == 0x9c) {
567 get_user(*((__u16 *) (opcode+2)), location+1);
568 signal = math_emu_stfpc(opcode, regs);
569 } else if (opcode[1] == 0x9d) {
570 get_user(*((__u16 *) (opcode+2)), location+1);
571 signal = math_emu_lfpc(opcode, regs);
581 if (current->thread.fp_regs.fpc & FPC_DXC_MASK)
585 if (signal == SIGFPE)
586 do_fp_trap(regs, location,
587 current->thread.fp_regs.fpc, interruption_code);
590 info.si_signo = signal;
592 info.si_code = ILL_ILLOPN;
593 info.si_addr = location;
594 do_trap(interruption_code, signal,
595 "data exception", regs, &info);
601 /* init is done in lowcore.S and head.S */
603 void __init trap_init(void)
607 for (i = 0; i < 128; i++)
608 pgm_check_table[i] = &default_trap_handler;
609 pgm_check_table[1] = &illegal_op;
610 pgm_check_table[2] = &privileged_op;
611 pgm_check_table[3] = &execute_exception;
612 pgm_check_table[4] = &do_protection_exception;
613 pgm_check_table[5] = &addressing_exception;
614 pgm_check_table[6] = &specification_exception;
615 pgm_check_table[7] = &data_exception;
616 pgm_check_table[8] = &overflow_exception;
617 pgm_check_table[9] = ÷_exception;
618 pgm_check_table[0x0A] = &overflow_exception;
619 pgm_check_table[0x0B] = ÷_exception;
620 pgm_check_table[0x0C] = &hfp_overflow_exception;
621 pgm_check_table[0x0D] = &hfp_underflow_exception;
622 pgm_check_table[0x0E] = &hfp_significance_exception;
623 pgm_check_table[0x0F] = &hfp_divide_exception;
624 pgm_check_table[0x10] = &do_dat_exception;
625 pgm_check_table[0x11] = &do_dat_exception;
626 pgm_check_table[0x12] = &translation_exception;
627 pgm_check_table[0x13] = &special_op_exception;
628 #ifndef CONFIG_ARCH_S390X
629 pgm_check_table[0x14] = &do_pseudo_page_fault;
630 #else /* CONFIG_ARCH_S390X */
631 pgm_check_table[0x38] = &do_dat_exception;
632 pgm_check_table[0x39] = &do_dat_exception;
633 pgm_check_table[0x3A] = &do_dat_exception;
634 pgm_check_table[0x3B] = &do_dat_exception;
635 #endif /* CONFIG_ARCH_S390X */
636 pgm_check_table[0x15] = &operand_exception;
637 pgm_check_table[0x1C] = &privileged_op;
638 pgm_check_table[0x1D] = &hfp_sqrt_exception;
639 pgm_check_table[0x40] = &do_monitor_call;
643 * First try to get pfault pseudo page faults going.
644 * If this isn't available turn on pagex page faults.
647 /* request the 0x2603 external interrupt */
648 if (register_early_external_interrupt(0x2603, pfault_interrupt,
649 &ext_int_pfault) != 0)
650 panic("Couldn't request external interrupt 0x2603");
652 if (pfault_init() == 0)
655 /* Tough luck, no pfault. */
656 unregister_early_external_interrupt(0x2603, pfault_interrupt,
659 #ifndef CONFIG_ARCH_S390X
660 cpcmd("SET PAGEX ON", NULL, 0);