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