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/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>
24 #include <linux/smp.h>
25 #include <linux/init.h>
26 #include <linux/interrupt.h>
27 #include <linux/delay.h>
28 #include <linux/module.h>
29 #include <linux/kdebug.h>
30 #include <linux/kallsyms.h>
31 #include <linux/reboot.h>
32 #include <linux/kprobes.h>
33 #include <linux/bug.h>
34 #include <asm/system.h>
35 #include <asm/uaccess.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>
44 /* Called from entry.S only */
45 extern void handle_per_exception(struct pt_regs *regs);
47 typedef void pgm_check_handler_t(struct pt_regs *, long);
48 pgm_check_handler_t *pgm_check_table[128];
51 #ifdef CONFIG_PROCESS_DEBUG
52 int sysctl_userprocess_debug = 1;
54 int sysctl_userprocess_debug = 0;
58 extern pgm_check_handler_t do_protection_exception;
59 extern pgm_check_handler_t do_dat_exception;
60 extern pgm_check_handler_t do_monitor_call;
62 #define stack_pointer ({ void **sp; asm("la %0,0(15)" : "=&d" (sp)); sp; })
65 #define FOURLONG "%08lx %08lx %08lx %08lx\n"
66 static int kstack_depth_to_print = 12;
67 #else /* CONFIG_64BIT */
68 #define FOURLONG "%016lx %016lx %016lx %016lx\n"
69 static int kstack_depth_to_print = 20;
70 #endif /* CONFIG_64BIT */
73 * For show_trace we have tree different stack to consider:
74 * - the panic stack which is used if the kernel stack has overflown
75 * - the asynchronous interrupt stack (cpu related)
76 * - the synchronous kernel stack (process related)
77 * The stack trace can start at any of the three stack and can potentially
78 * touch all of them. The order is: panic stack, async stack, sync stack.
81 __show_trace(unsigned long sp, unsigned long low, unsigned long high)
83 struct stack_frame *sf;
87 sp = sp & PSW_ADDR_INSN;
88 if (sp < low || sp > high - sizeof(*sf))
90 sf = (struct stack_frame *) sp;
91 printk("([<%016lx>] ", sf->gprs[8] & PSW_ADDR_INSN);
92 print_symbol("%s)\n", sf->gprs[8] & PSW_ADDR_INSN);
93 /* Follow the backchain. */
96 sp = sf->back_chain & PSW_ADDR_INSN;
99 if (sp <= low || sp > high - sizeof(*sf))
101 sf = (struct stack_frame *) sp;
102 printk(" [<%016lx>] ", sf->gprs[8] & PSW_ADDR_INSN);
103 print_symbol("%s\n", sf->gprs[8] & PSW_ADDR_INSN);
105 /* Zero backchain detected, check for interrupt frame. */
106 sp = (unsigned long) (sf + 1);
107 if (sp <= low || sp > high - sizeof(*regs))
109 regs = (struct pt_regs *) sp;
110 printk(" [<%016lx>] ", regs->psw.addr & PSW_ADDR_INSN);
111 print_symbol("%s\n", regs->psw.addr & PSW_ADDR_INSN);
117 void show_trace(struct task_struct *task, unsigned long *stack)
119 register unsigned long __r15 asm ("15");
122 sp = (unsigned long) stack;
124 sp = task ? task->thread.ksp : __r15;
125 printk("Call Trace:\n");
126 #ifdef CONFIG_CHECK_STACK
127 sp = __show_trace(sp, S390_lowcore.panic_stack - 4096,
128 S390_lowcore.panic_stack);
130 sp = __show_trace(sp, S390_lowcore.async_stack - ASYNC_SIZE,
131 S390_lowcore.async_stack);
133 __show_trace(sp, (unsigned long) task_stack_page(task),
134 (unsigned long) task_stack_page(task) + THREAD_SIZE);
136 __show_trace(sp, S390_lowcore.thread_info,
137 S390_lowcore.thread_info + THREAD_SIZE);
141 debug_show_held_locks(task);
144 void show_stack(struct task_struct *task, unsigned long *sp)
146 register unsigned long * __r15 asm ("15");
147 unsigned long *stack;
151 stack = task ? (unsigned long *) task->thread.ksp : __r15;
155 for (i = 0; i < kstack_depth_to_print; i++) {
156 if (((addr_t) stack & (THREAD_SIZE-1)) == 0)
158 if (i && ((i * sizeof (long) % 32) == 0))
160 printk("%p ", (void *)*stack++);
163 show_trace(task, sp);
167 * The architecture-independent dump_stack generator
169 void dump_stack(void)
171 show_stack(NULL, NULL);
174 EXPORT_SYMBOL(dump_stack);
176 static inline int mask_bits(struct pt_regs *regs, unsigned long bits)
178 return (regs->psw.mask & bits) / ((~bits + 1) & bits);
181 void show_registers(struct pt_regs *regs)
185 mode = (regs->psw.mask & PSW_MASK_PSTATE) ? "User" : "Krnl";
186 printk("%s PSW : %p %p",
187 mode, (void *) regs->psw.mask,
188 (void *) regs->psw.addr);
189 print_symbol(" (%s)\n", regs->psw.addr & PSW_ADDR_INSN);
190 printk(" R:%x T:%x IO:%x EX:%x Key:%x M:%x W:%x "
191 "P:%x AS:%x CC:%x PM:%x", mask_bits(regs, PSW_MASK_PER),
192 mask_bits(regs, PSW_MASK_DAT), mask_bits(regs, PSW_MASK_IO),
193 mask_bits(regs, PSW_MASK_EXT), mask_bits(regs, PSW_MASK_KEY),
194 mask_bits(regs, PSW_MASK_MCHECK), mask_bits(regs, PSW_MASK_WAIT),
195 mask_bits(regs, PSW_MASK_PSTATE), mask_bits(regs, PSW_MASK_ASC),
196 mask_bits(regs, PSW_MASK_CC), mask_bits(regs, PSW_MASK_PM));
198 printk(" EA:%x", mask_bits(regs, PSW_BASE_BITS));
200 printk("\n%s GPRS: " FOURLONG, mode,
201 regs->gprs[0], regs->gprs[1], regs->gprs[2], regs->gprs[3]);
203 regs->gprs[4], regs->gprs[5], regs->gprs[6], regs->gprs[7]);
205 regs->gprs[8], regs->gprs[9], regs->gprs[10], regs->gprs[11]);
207 regs->gprs[12], regs->gprs[13], regs->gprs[14], regs->gprs[15]);
212 /* This is called from fs/proc/array.c */
213 char *task_show_regs(struct task_struct *task, char *buffer)
215 struct pt_regs *regs;
217 regs = task_pt_regs(task);
218 buffer += sprintf(buffer, "task: %p, ksp: %p\n",
219 task, (void *)task->thread.ksp);
220 buffer += sprintf(buffer, "User PSW : %p %p\n",
221 (void *) regs->psw.mask, (void *)regs->psw.addr);
223 buffer += sprintf(buffer, "User GPRS: " FOURLONG,
224 regs->gprs[0], regs->gprs[1],
225 regs->gprs[2], regs->gprs[3]);
226 buffer += sprintf(buffer, " " FOURLONG,
227 regs->gprs[4], regs->gprs[5],
228 regs->gprs[6], regs->gprs[7]);
229 buffer += sprintf(buffer, " " FOURLONG,
230 regs->gprs[8], regs->gprs[9],
231 regs->gprs[10], regs->gprs[11]);
232 buffer += sprintf(buffer, " " FOURLONG,
233 regs->gprs[12], regs->gprs[13],
234 regs->gprs[14], regs->gprs[15]);
235 buffer += sprintf(buffer, "User ACRS: %08x %08x %08x %08x\n",
236 task->thread.acrs[0], task->thread.acrs[1],
237 task->thread.acrs[2], task->thread.acrs[3]);
238 buffer += sprintf(buffer, " %08x %08x %08x %08x\n",
239 task->thread.acrs[4], task->thread.acrs[5],
240 task->thread.acrs[6], task->thread.acrs[7]);
241 buffer += sprintf(buffer, " %08x %08x %08x %08x\n",
242 task->thread.acrs[8], task->thread.acrs[9],
243 task->thread.acrs[10], task->thread.acrs[11]);
244 buffer += sprintf(buffer, " %08x %08x %08x %08x\n",
245 task->thread.acrs[12], task->thread.acrs[13],
246 task->thread.acrs[14], task->thread.acrs[15]);
250 static DEFINE_SPINLOCK(die_lock);
252 void die(const char * str, struct pt_regs * regs, long err)
254 static int die_counter;
258 spin_lock_irq(&die_lock);
260 printk("%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter);
263 spin_unlock_irq(&die_lock);
265 panic("Fatal exception in interrupt");
267 panic("Fatal exception: panic_on_oops");
272 report_user_fault(long interruption_code, struct pt_regs *regs)
274 #if defined(CONFIG_SYSCTL)
275 if (!sysctl_userprocess_debug)
278 #if defined(CONFIG_SYSCTL) || defined(CONFIG_PROCESS_DEBUG)
279 printk("User process fault: interruption code 0x%lX\n",
285 int is_valid_bugaddr(unsigned long addr)
290 static void __kprobes inline do_trap(long interruption_code, int signr,
291 char *str, struct pt_regs *regs,
295 * We got all needed information from the lowcore and can
296 * now safely switch on interrupts.
298 if (regs->psw.mask & PSW_MASK_PSTATE)
301 if (notify_die(DIE_TRAP, str, regs, interruption_code,
302 interruption_code, signr) == NOTIFY_STOP)
305 if (regs->psw.mask & PSW_MASK_PSTATE) {
306 struct task_struct *tsk = current;
308 tsk->thread.trap_no = interruption_code & 0xffff;
309 force_sig_info(signr, info, tsk);
310 report_user_fault(interruption_code, regs);
312 const struct exception_table_entry *fixup;
313 fixup = search_exception_tables(regs->psw.addr & PSW_ADDR_INSN);
315 regs->psw.addr = fixup->fixup | PSW_ADDR_AMODE;
317 enum bug_trap_type btt;
319 btt = report_bug(regs->psw.addr & PSW_ADDR_INSN);
320 if (btt == BUG_TRAP_TYPE_WARN)
322 die(str, regs, interruption_code);
327 static inline void __user *get_check_address(struct pt_regs *regs)
329 return (void __user *)((regs->psw.addr-S390_lowcore.pgm_ilc) & PSW_ADDR_INSN);
332 void __kprobes do_single_step(struct pt_regs *regs)
334 if (notify_die(DIE_SSTEP, "sstep", regs, 0, 0,
335 SIGTRAP) == NOTIFY_STOP){
338 if ((current->ptrace & PT_PTRACED) != 0)
339 force_sig(SIGTRAP, current);
342 static void default_trap_handler(struct pt_regs * regs, long interruption_code)
344 if (regs->psw.mask & PSW_MASK_PSTATE) {
347 report_user_fault(interruption_code, regs);
349 die("Unknown program exception", regs, interruption_code);
352 #define DO_ERROR_INFO(signr, str, name, sicode, siaddr) \
353 static void name(struct pt_regs * regs, long interruption_code) \
356 info.si_signo = signr; \
358 info.si_code = sicode; \
359 info.si_addr = siaddr; \
360 do_trap(interruption_code, signr, str, regs, &info); \
363 DO_ERROR_INFO(SIGILL, "addressing exception", addressing_exception,
364 ILL_ILLADR, get_check_address(regs))
365 DO_ERROR_INFO(SIGILL, "execute exception", execute_exception,
366 ILL_ILLOPN, get_check_address(regs))
367 DO_ERROR_INFO(SIGFPE, "fixpoint divide exception", divide_exception,
368 FPE_INTDIV, get_check_address(regs))
369 DO_ERROR_INFO(SIGFPE, "fixpoint overflow exception", overflow_exception,
370 FPE_INTOVF, get_check_address(regs))
371 DO_ERROR_INFO(SIGFPE, "HFP overflow exception", hfp_overflow_exception,
372 FPE_FLTOVF, get_check_address(regs))
373 DO_ERROR_INFO(SIGFPE, "HFP underflow exception", hfp_underflow_exception,
374 FPE_FLTUND, get_check_address(regs))
375 DO_ERROR_INFO(SIGFPE, "HFP significance exception", hfp_significance_exception,
376 FPE_FLTRES, get_check_address(regs))
377 DO_ERROR_INFO(SIGFPE, "HFP divide exception", hfp_divide_exception,
378 FPE_FLTDIV, get_check_address(regs))
379 DO_ERROR_INFO(SIGFPE, "HFP square root exception", hfp_sqrt_exception,
380 FPE_FLTINV, get_check_address(regs))
381 DO_ERROR_INFO(SIGILL, "operand exception", operand_exception,
382 ILL_ILLOPN, get_check_address(regs))
383 DO_ERROR_INFO(SIGILL, "privileged operation", privileged_op,
384 ILL_PRVOPC, get_check_address(regs))
385 DO_ERROR_INFO(SIGILL, "special operation exception", special_op_exception,
386 ILL_ILLOPN, get_check_address(regs))
387 DO_ERROR_INFO(SIGILL, "translation exception", translation_exception,
388 ILL_ILLOPN, get_check_address(regs))
391 do_fp_trap(struct pt_regs *regs, void __user *location,
392 int fpc, long interruption_code)
396 si.si_signo = SIGFPE;
398 si.si_addr = location;
400 /* FPC[2] is Data Exception Code */
401 if ((fpc & 0x00000300) == 0) {
402 /* bits 6 and 7 of DXC are 0 iff IEEE exception */
403 if (fpc & 0x8000) /* invalid fp operation */
404 si.si_code = FPE_FLTINV;
405 else if (fpc & 0x4000) /* div by 0 */
406 si.si_code = FPE_FLTDIV;
407 else if (fpc & 0x2000) /* overflow */
408 si.si_code = FPE_FLTOVF;
409 else if (fpc & 0x1000) /* underflow */
410 si.si_code = FPE_FLTUND;
411 else if (fpc & 0x0800) /* inexact */
412 si.si_code = FPE_FLTRES;
414 current->thread.ieee_instruction_pointer = (addr_t) location;
415 do_trap(interruption_code, SIGFPE,
416 "floating point exception", regs, &si);
419 static void illegal_op(struct pt_regs * regs, long interruption_code)
423 __u16 __user *location;
426 location = get_check_address(regs);
429 * We got all needed information from the lowcore and can
430 * now safely switch on interrupts.
432 if (regs->psw.mask & PSW_MASK_PSTATE)
435 if (regs->psw.mask & PSW_MASK_PSTATE) {
436 if (get_user(*((__u16 *) opcode), (__u16 __user *) location))
438 if (*((__u16 *) opcode) == S390_BREAKPOINT_U16) {
439 if (current->ptrace & PT_PTRACED)
440 force_sig(SIGTRAP, current);
443 #ifdef CONFIG_MATHEMU
444 } else if (opcode[0] == 0xb3) {
445 if (get_user(*((__u16 *) (opcode+2)), location+1))
447 signal = math_emu_b3(opcode, regs);
448 } else if (opcode[0] == 0xed) {
449 if (get_user(*((__u32 *) (opcode+2)),
450 (__u32 __user *)(location+1)))
452 signal = math_emu_ed(opcode, regs);
453 } else if (*((__u16 *) opcode) == 0xb299) {
454 if (get_user(*((__u16 *) (opcode+2)), location+1))
456 signal = math_emu_srnm(opcode, regs);
457 } else if (*((__u16 *) opcode) == 0xb29c) {
458 if (get_user(*((__u16 *) (opcode+2)), location+1))
460 signal = math_emu_stfpc(opcode, regs);
461 } else if (*((__u16 *) opcode) == 0xb29d) {
462 if (get_user(*((__u16 *) (opcode+2)), location+1))
464 signal = math_emu_lfpc(opcode, regs);
470 * If we get an illegal op in kernel mode, send it through the
471 * kprobes notifier. If kprobes doesn't pick it up, SIGILL
473 if (notify_die(DIE_BPT, "bpt", regs, interruption_code,
474 3, SIGTRAP) != NOTIFY_STOP)
478 #ifdef CONFIG_MATHEMU
479 if (signal == SIGFPE)
480 do_fp_trap(regs, location,
481 current->thread.fp_regs.fpc, interruption_code);
482 else if (signal == SIGSEGV) {
483 info.si_signo = signal;
485 info.si_code = SEGV_MAPERR;
486 info.si_addr = (void __user *) location;
487 do_trap(interruption_code, signal,
488 "user address fault", regs, &info);
492 info.si_signo = signal;
494 info.si_code = ILL_ILLOPC;
495 info.si_addr = (void __user *) location;
496 do_trap(interruption_code, signal,
497 "illegal operation", regs, &info);
502 #ifdef CONFIG_MATHEMU
504 specification_exception(struct pt_regs * regs, long interruption_code)
507 __u16 __user *location = NULL;
510 location = (__u16 __user *) get_check_address(regs);
513 * We got all needed information from the lowcore and can
514 * now safely switch on interrupts.
516 if (regs->psw.mask & PSW_MASK_PSTATE)
519 if (regs->psw.mask & PSW_MASK_PSTATE) {
520 get_user(*((__u16 *) opcode), location);
522 case 0x28: /* LDR Rx,Ry */
523 signal = math_emu_ldr(opcode);
525 case 0x38: /* LER Rx,Ry */
526 signal = math_emu_ler(opcode);
528 case 0x60: /* STD R,D(X,B) */
529 get_user(*((__u16 *) (opcode+2)), location+1);
530 signal = math_emu_std(opcode, regs);
532 case 0x68: /* LD R,D(X,B) */
533 get_user(*((__u16 *) (opcode+2)), location+1);
534 signal = math_emu_ld(opcode, regs);
536 case 0x70: /* STE R,D(X,B) */
537 get_user(*((__u16 *) (opcode+2)), location+1);
538 signal = math_emu_ste(opcode, regs);
540 case 0x78: /* LE R,D(X,B) */
541 get_user(*((__u16 *) (opcode+2)), location+1);
542 signal = math_emu_le(opcode, regs);
551 if (signal == SIGFPE)
552 do_fp_trap(regs, location,
553 current->thread.fp_regs.fpc, interruption_code);
556 info.si_signo = signal;
558 info.si_code = ILL_ILLOPN;
559 info.si_addr = location;
560 do_trap(interruption_code, signal,
561 "specification exception", regs, &info);
565 DO_ERROR_INFO(SIGILL, "specification exception", specification_exception,
566 ILL_ILLOPN, get_check_address(regs));
569 static void data_exception(struct pt_regs * regs, long interruption_code)
571 __u16 __user *location;
574 location = get_check_address(regs);
577 * We got all needed information from the lowcore and can
578 * now safely switch on interrupts.
580 if (regs->psw.mask & PSW_MASK_PSTATE)
583 if (MACHINE_HAS_IEEE)
584 asm volatile("stfpc %0" : "=m" (current->thread.fp_regs.fpc));
586 #ifdef CONFIG_MATHEMU
587 else if (regs->psw.mask & PSW_MASK_PSTATE) {
589 get_user(*((__u16 *) opcode), location);
591 case 0x28: /* LDR Rx,Ry */
592 signal = math_emu_ldr(opcode);
594 case 0x38: /* LER Rx,Ry */
595 signal = math_emu_ler(opcode);
597 case 0x60: /* STD R,D(X,B) */
598 get_user(*((__u16 *) (opcode+2)), location+1);
599 signal = math_emu_std(opcode, regs);
601 case 0x68: /* LD R,D(X,B) */
602 get_user(*((__u16 *) (opcode+2)), location+1);
603 signal = math_emu_ld(opcode, regs);
605 case 0x70: /* STE R,D(X,B) */
606 get_user(*((__u16 *) (opcode+2)), location+1);
607 signal = math_emu_ste(opcode, regs);
609 case 0x78: /* LE R,D(X,B) */
610 get_user(*((__u16 *) (opcode+2)), location+1);
611 signal = math_emu_le(opcode, regs);
614 get_user(*((__u16 *) (opcode+2)), location+1);
615 signal = math_emu_b3(opcode, regs);
618 get_user(*((__u32 *) (opcode+2)),
619 (__u32 __user *)(location+1));
620 signal = math_emu_ed(opcode, regs);
623 if (opcode[1] == 0x99) {
624 get_user(*((__u16 *) (opcode+2)), location+1);
625 signal = math_emu_srnm(opcode, regs);
626 } else if (opcode[1] == 0x9c) {
627 get_user(*((__u16 *) (opcode+2)), location+1);
628 signal = math_emu_stfpc(opcode, regs);
629 } else if (opcode[1] == 0x9d) {
630 get_user(*((__u16 *) (opcode+2)), location+1);
631 signal = math_emu_lfpc(opcode, regs);
641 if (current->thread.fp_regs.fpc & FPC_DXC_MASK)
645 if (signal == SIGFPE)
646 do_fp_trap(regs, location,
647 current->thread.fp_regs.fpc, interruption_code);
650 info.si_signo = signal;
652 info.si_code = ILL_ILLOPN;
653 info.si_addr = location;
654 do_trap(interruption_code, signal,
655 "data exception", regs, &info);
659 static void space_switch_exception(struct pt_regs * regs, long int_code)
663 /* Set user psw back to home space mode. */
664 if (regs->psw.mask & PSW_MASK_PSTATE)
665 regs->psw.mask |= PSW_ASC_HOME;
667 info.si_signo = SIGILL;
669 info.si_code = ILL_PRVOPC;
670 info.si_addr = get_check_address(regs);
671 do_trap(int_code, SIGILL, "space switch event", regs, &info);
674 asmlinkage void kernel_stack_overflow(struct pt_regs * regs)
677 printk("Kernel stack overflow.\n");
680 panic("Corrupt kernel stack, can't continue.");
683 /* init is done in lowcore.S and head.S */
685 void __init trap_init(void)
689 for (i = 0; i < 128; i++)
690 pgm_check_table[i] = &default_trap_handler;
691 pgm_check_table[1] = &illegal_op;
692 pgm_check_table[2] = &privileged_op;
693 pgm_check_table[3] = &execute_exception;
694 pgm_check_table[4] = &do_protection_exception;
695 pgm_check_table[5] = &addressing_exception;
696 pgm_check_table[6] = &specification_exception;
697 pgm_check_table[7] = &data_exception;
698 pgm_check_table[8] = &overflow_exception;
699 pgm_check_table[9] = ÷_exception;
700 pgm_check_table[0x0A] = &overflow_exception;
701 pgm_check_table[0x0B] = ÷_exception;
702 pgm_check_table[0x0C] = &hfp_overflow_exception;
703 pgm_check_table[0x0D] = &hfp_underflow_exception;
704 pgm_check_table[0x0E] = &hfp_significance_exception;
705 pgm_check_table[0x0F] = &hfp_divide_exception;
706 pgm_check_table[0x10] = &do_dat_exception;
707 pgm_check_table[0x11] = &do_dat_exception;
708 pgm_check_table[0x12] = &translation_exception;
709 pgm_check_table[0x13] = &special_op_exception;
711 pgm_check_table[0x38] = &do_dat_exception;
712 pgm_check_table[0x39] = &do_dat_exception;
713 pgm_check_table[0x3A] = &do_dat_exception;
714 pgm_check_table[0x3B] = &do_dat_exception;
715 #endif /* CONFIG_64BIT */
716 pgm_check_table[0x15] = &operand_exception;
717 pgm_check_table[0x1C] = &space_switch_exception;
718 pgm_check_table[0x1D] = &hfp_sqrt_exception;
719 pgm_check_table[0x40] = &do_monitor_call;