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_segment_exception;
58 extern pgm_check_handler_t do_region_exception;
59 extern pgm_check_handler_t do_page_exception;
60 extern pgm_check_handler_t do_pseudo_page_fault;
62 extern int pfault_init(void);
63 extern void pfault_fini(void);
64 extern void pfault_interrupt(struct pt_regs *regs, __u16 error_code);
65 static ext_int_info_t ext_int_pfault;
67 #if defined(CONFIG_NO_IDLE_HZ) || defined(CONFIG_VIRT_TIMER)
68 extern pgm_check_handler_t do_monitor_call;
71 #define stack_pointer ({ void **sp; asm("la %0,0(15)" : "=&d" (sp)); sp; })
73 #ifndef CONFIG_ARCH_S390X
75 #define FOURLONG "%08lx %08lx %08lx %08lx\n"
76 static int kstack_depth_to_print = 12;
78 #else /* CONFIG_ARCH_S390X */
80 #define FOURLONG "%016lx %016lx %016lx %016lx\n"
81 static int kstack_depth_to_print = 20;
83 #endif /* CONFIG_ARCH_S390X */
85 void show_trace(struct task_struct *task, unsigned long * stack)
87 unsigned long backchain, low_addr, high_addr, ret_addr;
90 stack = (task == NULL) ? *stack_pointer : &(task->thread.ksp);
92 printk("Call Trace:\n");
93 low_addr = ((unsigned long) stack) & PSW_ADDR_INSN;
94 high_addr = (low_addr & (-THREAD_SIZE)) + THREAD_SIZE;
95 /* Skip the first frame (biased stack) */
96 backchain = *((unsigned long *) low_addr) & PSW_ADDR_INSN;
97 /* Print up to 8 lines */
98 while (backchain > low_addr && backchain <= high_addr) {
99 ret_addr = *((unsigned long *) (backchain+RET_ADDR)) & PSW_ADDR_INSN;
100 printk(" [<%016lx>] ", ret_addr);
101 print_symbol("%s\n", ret_addr);
102 low_addr = backchain;
103 backchain = *((unsigned long *) backchain) & PSW_ADDR_INSN;
108 void show_stack(struct task_struct *task, unsigned long *sp)
110 unsigned long *stack;
113 // debugging aid: "show_stack(NULL);" prints the
114 // back trace for this cpu.
118 sp = (unsigned long *) task->thread.ksp;
124 for (i = 0; i < kstack_depth_to_print; i++) {
125 if (((addr_t) stack & (THREAD_SIZE-1)) == 0)
127 if (i && ((i * sizeof (long) % 32) == 0))
129 printk("%p ", (void *)*stack++);
132 show_trace(task, sp);
136 * The architecture-independent dump_stack generator
138 void dump_stack(void)
143 EXPORT_SYMBOL(dump_stack);
145 void show_registers(struct pt_regs *regs)
151 mode = (regs->psw.mask & PSW_MASK_PSTATE) ? "User" : "Krnl";
152 printk("%s PSW : %p %p",
153 mode, (void *) regs->psw.mask,
154 (void *) regs->psw.addr);
155 print_symbol(" (%s)\n", regs->psw.addr & PSW_ADDR_INSN);
156 printk("%s GPRS: " FOURLONG, mode,
157 regs->gprs[0], regs->gprs[1], regs->gprs[2], regs->gprs[3]);
159 regs->gprs[4], regs->gprs[5], regs->gprs[6], regs->gprs[7]);
161 regs->gprs[8], regs->gprs[9], regs->gprs[10], regs->gprs[11]);
163 regs->gprs[12], regs->gprs[13], regs->gprs[14], regs->gprs[15]);
166 /* FIXME: this isn't needed any more but it changes the ksymoops
167 * input. To remove or not to remove ... */
168 save_access_regs(regs->acrs);
169 printk("%s ACRS: %08x %08x %08x %08x\n", mode,
170 regs->acrs[0], regs->acrs[1], regs->acrs[2], regs->acrs[3]);
171 printk(" %08x %08x %08x %08x\n",
172 regs->acrs[4], regs->acrs[5], regs->acrs[6], regs->acrs[7]);
173 printk(" %08x %08x %08x %08x\n",
174 regs->acrs[8], regs->acrs[9], regs->acrs[10], regs->acrs[11]);
175 printk(" %08x %08x %08x %08x\n",
176 regs->acrs[12], regs->acrs[13], regs->acrs[14], regs->acrs[15]);
180 * Print the first 20 byte of the instruction stream at the
184 if (regs->psw.mask & PSW_MASK_PSTATE)
188 printk("%s Code: ", mode);
189 for (i = 0; i < 20; i++) {
191 if (__get_user(c, (char *)(regs->psw.addr + i))) {
202 /* This is called from fs/proc/array.c */
203 char *task_show_regs(struct task_struct *task, char *buffer)
205 struct pt_regs *regs;
207 regs = __KSTK_PTREGS(task);
208 buffer += sprintf(buffer, "task: %p, ksp: %p\n",
209 task, (void *)task->thread.ksp);
210 buffer += sprintf(buffer, "User PSW : %p %p\n",
211 (void *) regs->psw.mask, (void *)regs->psw.addr);
213 buffer += sprintf(buffer, "User GPRS: " FOURLONG,
214 regs->gprs[0], regs->gprs[1],
215 regs->gprs[2], regs->gprs[3]);
216 buffer += sprintf(buffer, " " FOURLONG,
217 regs->gprs[4], regs->gprs[5],
218 regs->gprs[6], regs->gprs[7]);
219 buffer += sprintf(buffer, " " FOURLONG,
220 regs->gprs[8], regs->gprs[9],
221 regs->gprs[10], regs->gprs[11]);
222 buffer += sprintf(buffer, " " FOURLONG,
223 regs->gprs[12], regs->gprs[13],
224 regs->gprs[14], regs->gprs[15]);
225 buffer += sprintf(buffer, "User ACRS: %08x %08x %08x %08x\n",
226 task->thread.acrs[0], task->thread.acrs[1],
227 task->thread.acrs[2], task->thread.acrs[3]);
228 buffer += sprintf(buffer, " %08x %08x %08x %08x\n",
229 task->thread.acrs[4], task->thread.acrs[5],
230 task->thread.acrs[6], task->thread.acrs[7]);
231 buffer += sprintf(buffer, " %08x %08x %08x %08x\n",
232 task->thread.acrs[8], task->thread.acrs[9],
233 task->thread.acrs[10], task->thread.acrs[11]);
234 buffer += sprintf(buffer, " %08x %08x %08x %08x\n",
235 task->thread.acrs[12], task->thread.acrs[13],
236 task->thread.acrs[14], task->thread.acrs[15]);
240 spinlock_t die_lock = SPIN_LOCK_UNLOCKED;
242 void die(const char * str, struct pt_regs * regs, long err)
244 static int die_counter;
246 spin_lock_irq(&die_lock);
248 printk("%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter);
251 spin_unlock_irq(&die_lock);
253 panic("Fatal exception in interrupt");
255 panic("Fatal exception: panic_on_oops");
259 static void inline do_trap(long interruption_code, int signr, char *str,
260 struct pt_regs *regs, siginfo_t *info)
263 * We got all needed information from the lowcore and can
264 * now safely switch on interrupts.
266 if (regs->psw.mask & PSW_MASK_PSTATE)
269 if (regs->psw.mask & PSW_MASK_PSTATE) {
270 struct task_struct *tsk = current;
272 tsk->thread.trap_no = interruption_code & 0xffff;
274 force_sig_info(signr, info, tsk);
276 force_sig(signr, tsk);
277 #ifndef CONFIG_SYSCTL
278 #ifdef CONFIG_PROCESS_DEBUG
279 printk("User process fault: interruption code 0x%lX\n",
284 if (sysctl_userprocess_debug) {
285 printk("User process fault: interruption code 0x%lX\n",
291 const struct exception_table_entry *fixup;
292 fixup = search_exception_tables(regs->psw.addr & PSW_ADDR_INSN);
294 regs->psw.addr = fixup->fixup | PSW_ADDR_AMODE;
296 die(str, regs, interruption_code);
300 static inline void *get_check_address(struct pt_regs *regs)
302 return (void *)((regs->psw.addr-S390_lowcore.pgm_ilc) & PSW_ADDR_INSN);
305 int do_debugger_trap(struct pt_regs *regs)
307 if ((regs->psw.mask & PSW_MASK_PSTATE) &&
308 (current->ptrace & PT_PTRACED)) {
309 force_sig(SIGTRAP,current);
315 #define DO_ERROR(signr, str, name) \
316 asmlinkage void name(struct pt_regs * regs, long interruption_code) \
318 do_trap(interruption_code, signr, str, regs, NULL); \
321 #define DO_ERROR_INFO(signr, str, name, sicode, siaddr) \
322 asmlinkage void name(struct pt_regs * regs, long interruption_code) \
325 info.si_signo = signr; \
327 info.si_code = sicode; \
328 info.si_addr = (void *)siaddr; \
329 do_trap(interruption_code, signr, str, regs, &info); \
332 DO_ERROR(SIGSEGV, "Unknown program exception", default_trap_handler)
334 DO_ERROR_INFO(SIGBUS, "addressing exception", addressing_exception,
335 BUS_ADRERR, get_check_address(regs))
336 DO_ERROR_INFO(SIGILL, "execute exception", execute_exception,
337 ILL_ILLOPN, get_check_address(regs))
338 DO_ERROR_INFO(SIGFPE, "fixpoint divide exception", divide_exception,
339 FPE_INTDIV, get_check_address(regs))
340 DO_ERROR_INFO(SIGILL, "operand exception", operand_exception,
341 ILL_ILLOPN, get_check_address(regs))
342 DO_ERROR_INFO(SIGILL, "privileged operation", privileged_op,
343 ILL_PRVOPC, get_check_address(regs))
344 DO_ERROR_INFO(SIGILL, "special operation exception", special_op_exception,
345 ILL_ILLOPN, get_check_address(regs))
346 DO_ERROR_INFO(SIGILL, "translation exception", translation_exception,
347 ILL_ILLOPN, get_check_address(regs))
350 do_fp_trap(struct pt_regs *regs, void *location,
351 int fpc, long interruption_code)
355 si.si_signo = SIGFPE;
357 si.si_addr = location;
359 /* FPC[2] is Data Exception Code */
360 if ((fpc & 0x00000300) == 0) {
361 /* bits 6 and 7 of DXC are 0 iff IEEE exception */
362 if (fpc & 0x8000) /* invalid fp operation */
363 si.si_code = FPE_FLTINV;
364 else if (fpc & 0x4000) /* div by 0 */
365 si.si_code = FPE_FLTDIV;
366 else if (fpc & 0x2000) /* overflow */
367 si.si_code = FPE_FLTOVF;
368 else if (fpc & 0x1000) /* underflow */
369 si.si_code = FPE_FLTUND;
370 else if (fpc & 0x0800) /* inexact */
371 si.si_code = FPE_FLTRES;
373 current->thread.ieee_instruction_pointer = (addr_t) location;
374 do_trap(interruption_code, SIGFPE,
375 "floating point exception", regs, &si);
378 asmlinkage void illegal_op(struct pt_regs * regs, long interruption_code)
384 location = (__u16 *) get_check_address(regs);
387 * We got all needed information from the lowcore and can
388 * now safely switch on interrupts.
390 if (regs->psw.mask & PSW_MASK_PSTATE)
393 if (regs->psw.mask & PSW_MASK_PSTATE)
394 get_user(*((__u16 *) opcode), location);
396 *((__u16 *)opcode)=*((__u16 *)location);
397 if (*((__u16 *)opcode)==S390_BREAKPOINT_U16)
399 if(do_debugger_trap(regs))
402 #ifdef CONFIG_MATHEMU
403 else if (regs->psw.mask & PSW_MASK_PSTATE)
405 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);
484 if (signal == SIGFPE)
485 do_fp_trap(regs, location,
486 current->thread.fp_regs.fpc, interruption_code);
489 info.si_signo = signal;
491 info.si_code = ILL_ILLOPN;
492 info.si_addr = location;
493 do_trap(interruption_code, signal,
494 "specification exception", regs, &info);
498 DO_ERROR_INFO(SIGILL, "specification exception", specification_exception,
499 ILL_ILLOPN, get_check_address(regs));
502 asmlinkage void data_exception(struct pt_regs * regs, long interruption_code)
507 location = (__u16 *) get_check_address(regs);
510 * We got all needed information from the lowcore and can
511 * now safely switch on interrupts.
513 if (regs->psw.mask & PSW_MASK_PSTATE)
516 if (MACHINE_HAS_IEEE)
517 __asm__ volatile ("stfpc %0\n\t"
518 : "=m" (current->thread.fp_regs.fpc));
520 #ifdef CONFIG_MATHEMU
521 else if (regs->psw.mask & PSW_MASK_PSTATE) {
523 get_user(*((__u16 *) opcode), location);
525 case 0x28: /* LDR Rx,Ry */
526 signal = math_emu_ldr(opcode);
528 case 0x38: /* LER Rx,Ry */
529 signal = math_emu_ler(opcode);
531 case 0x60: /* STD R,D(X,B) */
532 get_user(*((__u16 *) (opcode+2)), location+1);
533 signal = math_emu_std(opcode, regs);
535 case 0x68: /* LD R,D(X,B) */
536 get_user(*((__u16 *) (opcode+2)), location+1);
537 signal = math_emu_ld(opcode, regs);
539 case 0x70: /* STE R,D(X,B) */
540 get_user(*((__u16 *) (opcode+2)), location+1);
541 signal = math_emu_ste(opcode, regs);
543 case 0x78: /* LE R,D(X,B) */
544 get_user(*((__u16 *) (opcode+2)), location+1);
545 signal = math_emu_le(opcode, regs);
548 get_user(*((__u16 *) (opcode+2)), location+1);
549 signal = math_emu_b3(opcode, regs);
552 get_user(*((__u32 *) (opcode+2)),
553 (__u32 *)(location+1));
554 signal = math_emu_ed(opcode, regs);
557 if (opcode[1] == 0x99) {
558 get_user(*((__u16 *) (opcode+2)), location+1);
559 signal = math_emu_srnm(opcode, regs);
560 } else if (opcode[1] == 0x9c) {
561 get_user(*((__u16 *) (opcode+2)), location+1);
562 signal = math_emu_stfpc(opcode, regs);
563 } else if (opcode[1] == 0x9d) {
564 get_user(*((__u16 *) (opcode+2)), location+1);
565 signal = math_emu_lfpc(opcode, regs);
575 if (current->thread.fp_regs.fpc & FPC_DXC_MASK)
579 if (signal == SIGFPE)
580 do_fp_trap(regs, location,
581 current->thread.fp_regs.fpc, interruption_code);
584 info.si_signo = signal;
586 info.si_code = ILL_ILLOPN;
587 info.si_addr = location;
588 do_trap(interruption_code, signal,
589 "data exception", regs, &info);
595 /* init is done in lowcore.S and head.S */
597 void __init trap_init(void)
601 for (i = 0; i < 128; i++)
602 pgm_check_table[i] = &default_trap_handler;
603 pgm_check_table[1] = &illegal_op;
604 pgm_check_table[2] = &privileged_op;
605 pgm_check_table[3] = &execute_exception;
606 pgm_check_table[4] = &do_protection_exception;
607 pgm_check_table[5] = &addressing_exception;
608 pgm_check_table[6] = &specification_exception;
609 pgm_check_table[7] = &data_exception;
610 pgm_check_table[9] = ÷_exception;
611 pgm_check_table[0x10] = &do_segment_exception;
612 pgm_check_table[0x11] = &do_page_exception;
613 pgm_check_table[0x12] = &translation_exception;
614 pgm_check_table[0x13] = &special_op_exception;
615 #ifndef CONFIG_ARCH_S390X
616 pgm_check_table[0x14] = &do_pseudo_page_fault;
617 #else /* CONFIG_ARCH_S390X */
618 pgm_check_table[0x38] = &addressing_exception;
619 pgm_check_table[0x3B] = &do_region_exception;
620 #endif /* CONFIG_ARCH_S390X */
621 pgm_check_table[0x15] = &operand_exception;
622 pgm_check_table[0x1C] = &privileged_op;
623 #if defined(CONFIG_VIRT_TIMER) || defined(CONFIG_NO_IDLE_HZ)
624 pgm_check_table[0x40] = &do_monitor_call;
628 * First try to get pfault pseudo page faults going.
629 * If this isn't available turn on pagex page faults.
632 /* request the 0x2603 external interrupt */
633 if (register_early_external_interrupt(0x2603, pfault_interrupt,
634 &ext_int_pfault) != 0)
635 panic("Couldn't request external interrupt 0x2603");
637 if (pfault_init() == 0)
640 /* Tough luck, no pfault. */
641 unregister_early_external_interrupt(0x2603, pfault_interrupt,
644 #ifndef CONFIG_ARCH_S390X
645 cpcmd("SET PAGEX ON", NULL, 0);