1 /* 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 */ 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> 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> 31 #include <linux/reboot.h> 32 33 #include <asm/system.h> 34 #include <asm/uaccess.h> 35 #include <asm/io.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> 41 #include <asm/debug.h> 42 43 /* Called from entry.S only */ 44 extern void handle_per_exception(struct pt_regs *regs); 45 46 typedef void pgm_check_handler_t(struct pt_regs *, long); 47 pgm_check_handler_t *pgm_check_table[128]; 48 49 #ifdef CONFIG_SYSCTL 50 #ifdef CONFIG_PROCESS_DEBUG 51 int sysctl_userprocess_debug = 1; 52 #else 53 int sysctl_userprocess_debug = 0; 54 #endif 55 #endif 56 57 extern pgm_check_handler_t do_protection_exception; 58 extern pgm_check_handler_t do_dat_exception; 59 #ifdef CONFIG_PFAULT 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; 64 #endif 65 extern pgm_check_handler_t do_monitor_call; 66 67 #define stack_pointer ({ void **sp; asm("la %0,0(15)" : "=&d" (sp)); sp; }) 68 69 #ifndef CONFIG_64BIT 70 #define FOURLONG "%08lx %08lx %08lx %08lx\n" 71 static int kstack_depth_to_print = 12; 72 #else /* CONFIG_64BIT */ 73 #define FOURLONG "%016lx %016lx %016lx %016lx\n" 74 static int kstack_depth_to_print = 20; 75 #endif /* CONFIG_64BIT */ 76 77 /* 78 * For show_trace we have tree different stack to consider: 79 * - the panic stack which is used if the kernel stack has overflown 80 * - the asynchronous interrupt stack (cpu related) 81 * - the synchronous kernel stack (process related) 82 * The stack trace can start at any of the three stack and can potentially 83 * touch all of them. The order is: panic stack, async stack, sync stack. 84 */ 85 static unsigned long 86 __show_trace(unsigned long sp, unsigned long low, unsigned long high) 87 { 88 struct stack_frame *sf; 89 struct pt_regs *regs; 90 91 while (1) { 92 sp = sp & PSW_ADDR_INSN; 93 if (sp < low || sp > high - sizeof(*sf)) 94 return sp; 95 sf = (struct stack_frame *) sp; 96 printk("([<%016lx>] ", sf->gprs[8] & PSW_ADDR_INSN); 97 print_symbol("%s)\n", sf->gprs[8] & PSW_ADDR_INSN); 98 /* Follow the backchain. */ 99 while (1) { 100 low = sp; 101 sp = sf->back_chain & PSW_ADDR_INSN; 102 if (!sp) 103 break; 104 if (sp <= low || sp > high - sizeof(*sf)) 105 return sp; 106 sf = (struct stack_frame *) sp; 107 printk(" [<%016lx>] ", sf->gprs[8] & PSW_ADDR_INSN); 108 print_symbol("%s\n", sf->gprs[8] & PSW_ADDR_INSN); 109 } 110 /* Zero backchain detected, check for interrupt frame. */ 111 sp = (unsigned long) (sf + 1); 112 if (sp <= low || sp > high - sizeof(*regs)) 113 return sp; 114 regs = (struct pt_regs *) sp; 115 printk(" [<%016lx>] ", regs->psw.addr & PSW_ADDR_INSN); 116 print_symbol("%s\n", regs->psw.addr & PSW_ADDR_INSN); 117 low = sp; 118 sp = regs->gprs[15]; 119 } 120 } 121 122 void show_trace(struct task_struct *task, unsigned long * stack) 123 { 124 register unsigned long __r15 asm ("15"); 125 unsigned long sp; 126 127 sp = (unsigned long) stack; 128 if (!sp) 129 sp = task ? task->thread.ksp : __r15; 130 printk("Call Trace:\n"); 131 #ifdef CONFIG_CHECK_STACK 132 sp = __show_trace(sp, S390_lowcore.panic_stack - 4096, 133 S390_lowcore.panic_stack); 134 #endif 135 sp = __show_trace(sp, S390_lowcore.async_stack - ASYNC_SIZE, 136 S390_lowcore.async_stack); 137 if (task) 138 __show_trace(sp, (unsigned long) task_stack_page(task), 139 (unsigned long) task_stack_page(task) + THREAD_SIZE); 140 else 141 __show_trace(sp, S390_lowcore.thread_info, 142 S390_lowcore.thread_info + THREAD_SIZE); 143 printk("\n"); 144 } 145 146 void show_stack(struct task_struct *task, unsigned long *sp) 147 { 148 register unsigned long * __r15 asm ("15"); 149 unsigned long *stack; 150 int i; 151 152 if (!sp) 153 stack = task ? (unsigned long *) task->thread.ksp : __r15; 154 else 155 stack = sp; 156 157 for (i = 0; i < kstack_depth_to_print; i++) { 158 if (((addr_t) stack & (THREAD_SIZE-1)) == 0) 159 break; 160 if (i && ((i * sizeof (long) % 32) == 0)) 161 printk("\n "); 162 printk("%p ", (void *)*stack++); 163 } 164 printk("\n"); 165 show_trace(task, sp); 166 } 167 168 /* 169 * The architecture-independent dump_stack generator 170 */ 171 void dump_stack(void) 172 { 173 show_stack(0, 0); 174 } 175 176 EXPORT_SYMBOL(dump_stack); 177 178 void show_registers(struct pt_regs *regs) 179 { 180 mm_segment_t old_fs; 181 char *mode; 182 int i; 183 184 mode = (regs->psw.mask & PSW_MASK_PSTATE) ? "User" : "Krnl"; 185 printk("%s PSW : %p %p", 186 mode, (void *) regs->psw.mask, 187 (void *) regs->psw.addr); 188 print_symbol(" (%s)\n", regs->psw.addr & PSW_ADDR_INSN); 189 printk("%s GPRS: " FOURLONG, mode, 190 regs->gprs[0], regs->gprs[1], regs->gprs[2], regs->gprs[3]); 191 printk(" " FOURLONG, 192 regs->gprs[4], regs->gprs[5], regs->gprs[6], regs->gprs[7]); 193 printk(" " FOURLONG, 194 regs->gprs[8], regs->gprs[9], regs->gprs[10], regs->gprs[11]); 195 printk(" " FOURLONG, 196 regs->gprs[12], regs->gprs[13], regs->gprs[14], regs->gprs[15]); 197 198 #if 0 199 /* FIXME: this isn't needed any more but it changes the ksymoops 200 * input. To remove or not to remove ... */ 201 save_access_regs(regs->acrs); 202 printk("%s ACRS: %08x %08x %08x %08x\n", mode, 203 regs->acrs[0], regs->acrs[1], regs->acrs[2], regs->acrs[3]); 204 printk(" %08x %08x %08x %08x\n", 205 regs->acrs[4], regs->acrs[5], regs->acrs[6], regs->acrs[7]); 206 printk(" %08x %08x %08x %08x\n", 207 regs->acrs[8], regs->acrs[9], regs->acrs[10], regs->acrs[11]); 208 printk(" %08x %08x %08x %08x\n", 209 regs->acrs[12], regs->acrs[13], regs->acrs[14], regs->acrs[15]); 210 #endif 211 212 /* 213 * Print the first 20 byte of the instruction stream at the 214 * time of the fault. 215 */ 216 old_fs = get_fs(); 217 if (regs->psw.mask & PSW_MASK_PSTATE) 218 set_fs(USER_DS); 219 else 220 set_fs(KERNEL_DS); 221 printk("%s Code: ", mode); 222 for (i = 0; i < 20; i++) { 223 unsigned char c; 224 if (__get_user(c, (char __user *)(regs->psw.addr + i))) { 225 printk(" Bad PSW."); 226 break; 227 } 228 printk("%02x ", c); 229 } 230 set_fs(old_fs); 231 232 printk("\n"); 233 } 234 235 /* This is called from fs/proc/array.c */ 236 char *task_show_regs(struct task_struct *task, char *buffer) 237 { 238 struct pt_regs *regs; 239 240 regs = task_pt_regs(task); 241 buffer += sprintf(buffer, "task: %p, ksp: %p\n", 242 task, (void *)task->thread.ksp); 243 buffer += sprintf(buffer, "User PSW : %p %p\n", 244 (void *) regs->psw.mask, (void *)regs->psw.addr); 245 246 buffer += sprintf(buffer, "User GPRS: " FOURLONG, 247 regs->gprs[0], regs->gprs[1], 248 regs->gprs[2], regs->gprs[3]); 249 buffer += sprintf(buffer, " " FOURLONG, 250 regs->gprs[4], regs->gprs[5], 251 regs->gprs[6], regs->gprs[7]); 252 buffer += sprintf(buffer, " " FOURLONG, 253 regs->gprs[8], regs->gprs[9], 254 regs->gprs[10], regs->gprs[11]); 255 buffer += sprintf(buffer, " " FOURLONG, 256 regs->gprs[12], regs->gprs[13], 257 regs->gprs[14], regs->gprs[15]); 258 buffer += sprintf(buffer, "User ACRS: %08x %08x %08x %08x\n", 259 task->thread.acrs[0], task->thread.acrs[1], 260 task->thread.acrs[2], task->thread.acrs[3]); 261 buffer += sprintf(buffer, " %08x %08x %08x %08x\n", 262 task->thread.acrs[4], task->thread.acrs[5], 263 task->thread.acrs[6], task->thread.acrs[7]); 264 buffer += sprintf(buffer, " %08x %08x %08x %08x\n", 265 task->thread.acrs[8], task->thread.acrs[9], 266 task->thread.acrs[10], task->thread.acrs[11]); 267 buffer += sprintf(buffer, " %08x %08x %08x %08x\n", 268 task->thread.acrs[12], task->thread.acrs[13], 269 task->thread.acrs[14], task->thread.acrs[15]); 270 return buffer; 271 } 272 273 DEFINE_SPINLOCK(die_lock); 274 275 void die(const char * str, struct pt_regs * regs, long err) 276 { 277 static int die_counter; 278 279 debug_stop_all(); 280 console_verbose(); 281 spin_lock_irq(&die_lock); 282 bust_spinlocks(1); 283 printk("%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter); 284 show_regs(regs); 285 bust_spinlocks(0); 286 spin_unlock_irq(&die_lock); 287 if (in_interrupt()) 288 panic("Fatal exception in interrupt"); 289 if (panic_on_oops) 290 panic("Fatal exception: panic_on_oops"); 291 do_exit(SIGSEGV); 292 } 293 294 static void inline 295 report_user_fault(long interruption_code, struct pt_regs *regs) 296 { 297 #if defined(CONFIG_SYSCTL) 298 if (!sysctl_userprocess_debug) 299 return; 300 #endif 301 #if defined(CONFIG_SYSCTL) || defined(CONFIG_PROCESS_DEBUG) 302 printk("User process fault: interruption code 0x%lX\n", 303 interruption_code); 304 show_regs(regs); 305 #endif 306 } 307 308 static void inline do_trap(long interruption_code, int signr, char *str, 309 struct pt_regs *regs, siginfo_t *info) 310 { 311 /* 312 * We got all needed information from the lowcore and can 313 * now safely switch on interrupts. 314 */ 315 if (regs->psw.mask & PSW_MASK_PSTATE) 316 local_irq_enable(); 317 318 if (regs->psw.mask & PSW_MASK_PSTATE) { 319 struct task_struct *tsk = current; 320 321 tsk->thread.trap_no = interruption_code & 0xffff; 322 force_sig_info(signr, info, tsk); 323 report_user_fault(interruption_code, regs); 324 } else { 325 const struct exception_table_entry *fixup; 326 fixup = search_exception_tables(regs->psw.addr & PSW_ADDR_INSN); 327 if (fixup) 328 regs->psw.addr = fixup->fixup | PSW_ADDR_AMODE; 329 else 330 die(str, regs, interruption_code); 331 } 332 } 333 334 static inline void *get_check_address(struct pt_regs *regs) 335 { 336 return (void *)((regs->psw.addr-S390_lowcore.pgm_ilc) & PSW_ADDR_INSN); 337 } 338 339 void do_single_step(struct pt_regs *regs) 340 { 341 if ((current->ptrace & PT_PTRACED) != 0) 342 force_sig(SIGTRAP, current); 343 } 344 345 asmlinkage void 346 default_trap_handler(struct pt_regs * regs, long interruption_code) 347 { 348 if (regs->psw.mask & PSW_MASK_PSTATE) { 349 local_irq_enable(); 350 do_exit(SIGSEGV); 351 report_user_fault(interruption_code, regs); 352 } else 353 die("Unknown program exception", regs, interruption_code); 354 } 355 356 #define DO_ERROR_INFO(signr, str, name, sicode, siaddr) \ 357 asmlinkage void name(struct pt_regs * regs, long interruption_code) \ 358 { \ 359 siginfo_t info; \ 360 info.si_signo = signr; \ 361 info.si_errno = 0; \ 362 info.si_code = sicode; \ 363 info.si_addr = (void *)siaddr; \ 364 do_trap(interruption_code, signr, str, regs, &info); \ 365 } 366 367 DO_ERROR_INFO(SIGILL, "addressing exception", addressing_exception, 368 ILL_ILLADR, get_check_address(regs)) 369 DO_ERROR_INFO(SIGILL, "execute exception", execute_exception, 370 ILL_ILLOPN, get_check_address(regs)) 371 DO_ERROR_INFO(SIGFPE, "fixpoint divide exception", divide_exception, 372 FPE_INTDIV, get_check_address(regs)) 373 DO_ERROR_INFO(SIGFPE, "fixpoint overflow exception", overflow_exception, 374 FPE_INTOVF, get_check_address(regs)) 375 DO_ERROR_INFO(SIGFPE, "HFP overflow exception", hfp_overflow_exception, 376 FPE_FLTOVF, get_check_address(regs)) 377 DO_ERROR_INFO(SIGFPE, "HFP underflow exception", hfp_underflow_exception, 378 FPE_FLTUND, get_check_address(regs)) 379 DO_ERROR_INFO(SIGFPE, "HFP significance exception", hfp_significance_exception, 380 FPE_FLTRES, get_check_address(regs)) 381 DO_ERROR_INFO(SIGFPE, "HFP divide exception", hfp_divide_exception, 382 FPE_FLTDIV, get_check_address(regs)) 383 DO_ERROR_INFO(SIGFPE, "HFP square root exception", hfp_sqrt_exception, 384 FPE_FLTINV, get_check_address(regs)) 385 DO_ERROR_INFO(SIGILL, "operand exception", operand_exception, 386 ILL_ILLOPN, get_check_address(regs)) 387 DO_ERROR_INFO(SIGILL, "privileged operation", privileged_op, 388 ILL_PRVOPC, get_check_address(regs)) 389 DO_ERROR_INFO(SIGILL, "special operation exception", special_op_exception, 390 ILL_ILLOPN, get_check_address(regs)) 391 DO_ERROR_INFO(SIGILL, "translation exception", translation_exception, 392 ILL_ILLOPN, get_check_address(regs)) 393 394 static inline void 395 do_fp_trap(struct pt_regs *regs, void *location, 396 int fpc, long interruption_code) 397 { 398 siginfo_t si; 399 400 si.si_signo = SIGFPE; 401 si.si_errno = 0; 402 si.si_addr = location; 403 si.si_code = 0; 404 /* FPC[2] is Data Exception Code */ 405 if ((fpc & 0x00000300) == 0) { 406 /* bits 6 and 7 of DXC are 0 iff IEEE exception */ 407 if (fpc & 0x8000) /* invalid fp operation */ 408 si.si_code = FPE_FLTINV; 409 else if (fpc & 0x4000) /* div by 0 */ 410 si.si_code = FPE_FLTDIV; 411 else if (fpc & 0x2000) /* overflow */ 412 si.si_code = FPE_FLTOVF; 413 else if (fpc & 0x1000) /* underflow */ 414 si.si_code = FPE_FLTUND; 415 else if (fpc & 0x0800) /* inexact */ 416 si.si_code = FPE_FLTRES; 417 } 418 current->thread.ieee_instruction_pointer = (addr_t) location; 419 do_trap(interruption_code, SIGFPE, 420 "floating point exception", regs, &si); 421 } 422 423 asmlinkage void illegal_op(struct pt_regs * regs, long interruption_code) 424 { 425 siginfo_t info; 426 __u8 opcode[6]; 427 __u16 *location; 428 int signal = 0; 429 430 location = (__u16 *) get_check_address(regs); 431 432 /* 433 * We got all needed information from the lowcore and can 434 * now safely switch on interrupts. 435 */ 436 if (regs->psw.mask & PSW_MASK_PSTATE) 437 local_irq_enable(); 438 439 if (regs->psw.mask & PSW_MASK_PSTATE) { 440 get_user(*((__u16 *) opcode), (__u16 __user *) location); 441 if (*((__u16 *) opcode) == S390_BREAKPOINT_U16) { 442 if (current->ptrace & PT_PTRACED) 443 force_sig(SIGTRAP, current); 444 else 445 signal = SIGILL; 446 #ifdef CONFIG_MATHEMU 447 } else if (opcode[0] == 0xb3) { 448 get_user(*((__u16 *) (opcode+2)), location+1); 449 signal = math_emu_b3(opcode, regs); 450 } else if (opcode[0] == 0xed) { 451 get_user(*((__u32 *) (opcode+2)), 452 (__u32 *)(location+1)); 453 signal = math_emu_ed(opcode, regs); 454 } else if (*((__u16 *) opcode) == 0xb299) { 455 get_user(*((__u16 *) (opcode+2)), location+1); 456 signal = math_emu_srnm(opcode, regs); 457 } else if (*((__u16 *) opcode) == 0xb29c) { 458 get_user(*((__u16 *) (opcode+2)), location+1); 459 signal = math_emu_stfpc(opcode, regs); 460 } else if (*((__u16 *) opcode) == 0xb29d) { 461 get_user(*((__u16 *) (opcode+2)), location+1); 462 signal = math_emu_lfpc(opcode, regs); 463 #endif 464 } else 465 signal = SIGILL; 466 } else 467 signal = SIGILL; 468 469 #ifdef CONFIG_MATHEMU 470 if (signal == SIGFPE) 471 do_fp_trap(regs, location, 472 current->thread.fp_regs.fpc, interruption_code); 473 else if (signal == SIGSEGV) { 474 info.si_signo = signal; 475 info.si_errno = 0; 476 info.si_code = SEGV_MAPERR; 477 info.si_addr = (void *) location; 478 do_trap(interruption_code, signal, 479 "user address fault", regs, &info); 480 } else 481 #endif 482 if (signal) { 483 info.si_signo = signal; 484 info.si_errno = 0; 485 info.si_code = ILL_ILLOPC; 486 info.si_addr = (void __user *) location; 487 do_trap(interruption_code, signal, 488 "illegal operation", regs, &info); 489 } 490 } 491 492 493 #ifdef CONFIG_MATHEMU 494 asmlinkage void 495 specification_exception(struct pt_regs * regs, long interruption_code) 496 { 497 __u8 opcode[6]; 498 __u16 *location = NULL; 499 int signal = 0; 500 501 location = (__u16 *) get_check_address(regs); 502 503 /* 504 * We got all needed information from the lowcore and can 505 * now safely switch on interrupts. 506 */ 507 if (regs->psw.mask & PSW_MASK_PSTATE) 508 local_irq_enable(); 509 510 if (regs->psw.mask & PSW_MASK_PSTATE) { 511 get_user(*((__u16 *) opcode), location); 512 switch (opcode[0]) { 513 case 0x28: /* LDR Rx,Ry */ 514 signal = math_emu_ldr(opcode); 515 break; 516 case 0x38: /* LER Rx,Ry */ 517 signal = math_emu_ler(opcode); 518 break; 519 case 0x60: /* STD R,D(X,B) */ 520 get_user(*((__u16 *) (opcode+2)), location+1); 521 signal = math_emu_std(opcode, regs); 522 break; 523 case 0x68: /* LD R,D(X,B) */ 524 get_user(*((__u16 *) (opcode+2)), location+1); 525 signal = math_emu_ld(opcode, regs); 526 break; 527 case 0x70: /* STE R,D(X,B) */ 528 get_user(*((__u16 *) (opcode+2)), location+1); 529 signal = math_emu_ste(opcode, regs); 530 break; 531 case 0x78: /* LE R,D(X,B) */ 532 get_user(*((__u16 *) (opcode+2)), location+1); 533 signal = math_emu_le(opcode, regs); 534 break; 535 default: 536 signal = SIGILL; 537 break; 538 } 539 } else 540 signal = SIGILL; 541 542 if (signal == SIGFPE) 543 do_fp_trap(regs, location, 544 current->thread.fp_regs.fpc, interruption_code); 545 else if (signal) { 546 siginfo_t info; 547 info.si_signo = signal; 548 info.si_errno = 0; 549 info.si_code = ILL_ILLOPN; 550 info.si_addr = location; 551 do_trap(interruption_code, signal, 552 "specification exception", regs, &info); 553 } 554 } 555 #else 556 DO_ERROR_INFO(SIGILL, "specification exception", specification_exception, 557 ILL_ILLOPN, get_check_address(regs)); 558 #endif 559 560 asmlinkage void data_exception(struct pt_regs * regs, long interruption_code) 561 { 562 __u16 *location; 563 int signal = 0; 564 565 location = (__u16 *) get_check_address(regs); 566 567 /* 568 * We got all needed information from the lowcore and can 569 * now safely switch on interrupts. 570 */ 571 if (regs->psw.mask & PSW_MASK_PSTATE) 572 local_irq_enable(); 573 574 if (MACHINE_HAS_IEEE) 575 __asm__ volatile ("stfpc %0\n\t" 576 : "=m" (current->thread.fp_regs.fpc)); 577 578 #ifdef CONFIG_MATHEMU 579 else if (regs->psw.mask & PSW_MASK_PSTATE) { 580 __u8 opcode[6]; 581 get_user(*((__u16 *) opcode), location); 582 switch (opcode[0]) { 583 case 0x28: /* LDR Rx,Ry */ 584 signal = math_emu_ldr(opcode); 585 break; 586 case 0x38: /* LER Rx,Ry */ 587 signal = math_emu_ler(opcode); 588 break; 589 case 0x60: /* STD R,D(X,B) */ 590 get_user(*((__u16 *) (opcode+2)), location+1); 591 signal = math_emu_std(opcode, regs); 592 break; 593 case 0x68: /* LD R,D(X,B) */ 594 get_user(*((__u16 *) (opcode+2)), location+1); 595 signal = math_emu_ld(opcode, regs); 596 break; 597 case 0x70: /* STE R,D(X,B) */ 598 get_user(*((__u16 *) (opcode+2)), location+1); 599 signal = math_emu_ste(opcode, regs); 600 break; 601 case 0x78: /* LE R,D(X,B) */ 602 get_user(*((__u16 *) (opcode+2)), location+1); 603 signal = math_emu_le(opcode, regs); 604 break; 605 case 0xb3: 606 get_user(*((__u16 *) (opcode+2)), location+1); 607 signal = math_emu_b3(opcode, regs); 608 break; 609 case 0xed: 610 get_user(*((__u32 *) (opcode+2)), 611 (__u32 *)(location+1)); 612 signal = math_emu_ed(opcode, regs); 613 break; 614 case 0xb2: 615 if (opcode[1] == 0x99) { 616 get_user(*((__u16 *) (opcode+2)), location+1); 617 signal = math_emu_srnm(opcode, regs); 618 } else if (opcode[1] == 0x9c) { 619 get_user(*((__u16 *) (opcode+2)), location+1); 620 signal = math_emu_stfpc(opcode, regs); 621 } else if (opcode[1] == 0x9d) { 622 get_user(*((__u16 *) (opcode+2)), location+1); 623 signal = math_emu_lfpc(opcode, regs); 624 } else 625 signal = SIGILL; 626 break; 627 default: 628 signal = SIGILL; 629 break; 630 } 631 } 632 #endif 633 if (current->thread.fp_regs.fpc & FPC_DXC_MASK) 634 signal = SIGFPE; 635 else 636 signal = SIGILL; 637 if (signal == SIGFPE) 638 do_fp_trap(regs, location, 639 current->thread.fp_regs.fpc, interruption_code); 640 else if (signal) { 641 siginfo_t info; 642 info.si_signo = signal; 643 info.si_errno = 0; 644 info.si_code = ILL_ILLOPN; 645 info.si_addr = location; 646 do_trap(interruption_code, signal, 647 "data exception", regs, &info); 648 } 649 } 650 651 asmlinkage void space_switch_exception(struct pt_regs * regs, long int_code) 652 { 653 siginfo_t info; 654 655 /* Set user psw back to home space mode. */ 656 if (regs->psw.mask & PSW_MASK_PSTATE) 657 regs->psw.mask |= PSW_ASC_HOME; 658 /* Send SIGILL. */ 659 info.si_signo = SIGILL; 660 info.si_errno = 0; 661 info.si_code = ILL_PRVOPC; 662 info.si_addr = get_check_address(regs); 663 do_trap(int_code, SIGILL, "space switch event", regs, &info); 664 } 665 666 asmlinkage void kernel_stack_overflow(struct pt_regs * regs) 667 { 668 bust_spinlocks(1); 669 printk("Kernel stack overflow.\n"); 670 show_regs(regs); 671 bust_spinlocks(0); 672 panic("Corrupt kernel stack, can't continue."); 673 } 674 675 /* init is done in lowcore.S and head.S */ 676 677 void __init trap_init(void) 678 { 679 int i; 680 681 for (i = 0; i < 128; i++) 682 pgm_check_table[i] = &default_trap_handler; 683 pgm_check_table[1] = &illegal_op; 684 pgm_check_table[2] = &privileged_op; 685 pgm_check_table[3] = &execute_exception; 686 pgm_check_table[4] = &do_protection_exception; 687 pgm_check_table[5] = &addressing_exception; 688 pgm_check_table[6] = &specification_exception; 689 pgm_check_table[7] = &data_exception; 690 pgm_check_table[8] = &overflow_exception; 691 pgm_check_table[9] = ÷_exception; 692 pgm_check_table[0x0A] = &overflow_exception; 693 pgm_check_table[0x0B] = ÷_exception; 694 pgm_check_table[0x0C] = &hfp_overflow_exception; 695 pgm_check_table[0x0D] = &hfp_underflow_exception; 696 pgm_check_table[0x0E] = &hfp_significance_exception; 697 pgm_check_table[0x0F] = &hfp_divide_exception; 698 pgm_check_table[0x10] = &do_dat_exception; 699 pgm_check_table[0x11] = &do_dat_exception; 700 pgm_check_table[0x12] = &translation_exception; 701 pgm_check_table[0x13] = &special_op_exception; 702 #ifdef CONFIG_64BIT 703 pgm_check_table[0x38] = &do_dat_exception; 704 pgm_check_table[0x39] = &do_dat_exception; 705 pgm_check_table[0x3A] = &do_dat_exception; 706 pgm_check_table[0x3B] = &do_dat_exception; 707 #endif /* CONFIG_64BIT */ 708 pgm_check_table[0x15] = &operand_exception; 709 pgm_check_table[0x1C] = &space_switch_exception; 710 pgm_check_table[0x1D] = &hfp_sqrt_exception; 711 pgm_check_table[0x40] = &do_monitor_call; 712 713 if (MACHINE_IS_VM) { 714 #ifdef CONFIG_PFAULT 715 /* 716 * Try to get pfault pseudo page faults going. 717 */ 718 if (register_early_external_interrupt(0x2603, pfault_interrupt, 719 &ext_int_pfault) != 0) 720 panic("Couldn't request external interrupt 0x2603"); 721 722 if (pfault_init() == 0) 723 return; 724 725 /* Tough luck, no pfault. */ 726 unregister_early_external_interrupt(0x2603, pfault_interrupt, 727 &ext_int_pfault); 728 #endif 729 } 730 } 731