vserver 1.9.5.x5
[linux-2.6.git] / arch / parisc / kernel / traps.c
1 /*
2  *  linux/arch/parisc/traps.c
3  *
4  *  Copyright (C) 1991, 1992  Linus Torvalds
5  *  Copyright (C) 1999, 2000  Philipp Rumpf <prumpf@tux.org>
6  */
7
8 /*
9  * 'Traps.c' handles hardware traps and faults after we have saved some
10  * state in 'asm.s'.
11  */
12
13 #include <linux/config.h>
14 #include <linux/sched.h>
15 #include <linux/kernel.h>
16 #include <linux/string.h>
17 #include <linux/errno.h>
18 #include <linux/ptrace.h>
19 #include <linux/timer.h>
20 #include <linux/mm.h>
21 #include <linux/module.h>
22 #include <linux/smp.h>
23 #include <linux/smp_lock.h>
24 #include <linux/spinlock.h>
25 #include <linux/init.h>
26 #include <linux/interrupt.h>
27 #include <linux/console.h>
28 #include <linux/kallsyms.h>
29
30 #include <asm/assembly.h>
31 #include <asm/system.h>
32 #include <asm/uaccess.h>
33 #include <asm/io.h>
34 #include <asm/irq.h>
35 #include <asm/traps.h>
36 #include <asm/unaligned.h>
37 #include <asm/atomic.h>
38 #include <asm/smp.h>
39 #include <asm/pdc.h>
40 #include <asm/pdc_chassis.h>
41 #include <asm/unwind.h>
42
43 #include "../math-emu/math-emu.h"       /* for handle_fpe() */
44
45 #define PRINT_USER_FAULTS /* (turn this on if you want user faults to be */
46                           /*  dumped to the console via printk)          */
47
48 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
49 DEFINE_SPINLOCK(pa_dbit_lock);
50 #endif
51
52 int printbinary(char *buf, unsigned long x, int nbits)
53 {
54         unsigned long mask = 1UL << (nbits - 1);
55         while (mask != 0) {
56                 *buf++ = (mask & x ? '1' : '0');
57                 mask >>= 1;
58         }
59         *buf = '\0';
60
61         return nbits;
62 }
63
64 #ifdef __LP64__
65 #define RFMT "%016lx"
66 #else
67 #define RFMT "%08lx"
68 #endif
69
70 void show_regs(struct pt_regs *regs)
71 {
72         int i;
73         char buf[128], *p;
74         char *level;
75         unsigned long cr30;
76         unsigned long cr31;
77
78         level = user_mode(regs) ? KERN_DEBUG : KERN_CRIT;
79
80         printk("%s\n", level); /* don't want to have that pretty register dump messed up */
81
82         printk("%s     YZrvWESTHLNXBCVMcbcbcbcbOGFRQPDI\n", level);
83         printbinary(buf, regs->gr[0], 32);
84         printk("%sPSW: %s %s\n", level, buf, print_tainted());
85
86         for (i = 0; i < 32; i += 4) {
87                 int j;
88                 p = buf;
89                 p += sprintf(p, "%sr%02d-%02d ", level, i, i + 3);
90                 for (j = 0; j < 4; j++) {
91                         p += sprintf(p, " " RFMT, (i+j) == 0 ? 0 : regs->gr[i + j]);
92                 }
93                 printk("%s\n", buf);
94         }
95
96         for (i = 0; i < 8; i += 4) {
97                 int j;
98                 p = buf;
99                 p += sprintf(p, "%ssr%d-%d  ", level, i, i + 3);
100                 for (j = 0; j < 4; j++) {
101                         p += sprintf(p, " " RFMT, regs->sr[i + j]);
102                 }
103                 printk("%s\n", buf);
104         }
105
106 #if RIDICULOUSLY_VERBOSE
107         for (i = 0; i < 32; i += 2)
108                 printk("%sFR%02d : %016lx  FR%2d : %016lx", level, i,
109                                 regs->fr[i], i+1, regs->fr[i+1]);
110 #endif
111
112         cr30 = mfctl(30);
113         cr31 = mfctl(31);
114         printk("%s\n", level);
115         printk("%sIASQ: " RFMT " " RFMT " IAOQ: " RFMT " " RFMT "\n",
116                level, regs->iasq[0], regs->iasq[1], regs->iaoq[0], regs->iaoq[1]);
117         printk("%s IIR: %08lx    ISR: " RFMT "  IOR: " RFMT "\n",
118                level, regs->iir, regs->isr, regs->ior);
119         printk("%s CPU: %8d   CR30: " RFMT " CR31: " RFMT "\n",
120                level, current_thread_info()->cpu, cr30, cr31);
121         printk("%s ORIG_R28: " RFMT "\n", level, regs->orig_r28);
122         printk(level);
123         print_symbol(" IAOQ[0]: %s\n", regs->iaoq[0]);
124         printk(level);
125         print_symbol(" IAOQ[1]: %s\n", regs->iaoq[1]);
126         printk(level);
127         print_symbol(" RP(r2): %s\n", regs->gr[2]);
128 }
129
130
131 void dump_stack(void)
132 {
133         show_stack(NULL, NULL);
134 }
135
136 EXPORT_SYMBOL(dump_stack);
137
138 static void do_show_stack(struct unwind_frame_info *info)
139 {
140         int i = 1;
141
142         printk("Backtrace:\n");
143         while (i <= 16) {
144                 if (unwind_once(info) < 0 || info->ip == 0)
145                         break;
146
147                 if (__kernel_text_address(info->ip)) {
148                         printk(" [<" RFMT ">] ", info->ip);
149 #ifdef CONFIG_KALLSYMS
150                         print_symbol("%s\n", info->ip);
151 #else
152                         if ((i & 0x03) == 0)
153                                 printk("\n");
154 #endif
155                         i++;
156                 }
157         }
158         printk("\n");
159 }
160
161 void show_stack(struct task_struct *task, unsigned long *s)
162 {
163         struct unwind_frame_info info;
164
165         if (!task) {
166                 unsigned long sp, ip, rp;
167
168 HERE:
169                 asm volatile ("copy %%r30, %0" : "=r"(sp));
170                 ip = (unsigned long)&&HERE;
171                 rp = (unsigned long)__builtin_return_address(0);
172                 unwind_frame_init(&info, current, sp, ip, rp);
173         } else {
174                 unwind_frame_init_from_blocked_task(&info, task);
175         }
176
177         do_show_stack(&info);
178 }
179
180 void die_if_kernel(char *str, struct pt_regs *regs, long err)
181 {
182         if (user_mode(regs)) {
183                 if (err == 0)
184                         return; /* STFU */
185
186                 printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
187                         current->comm, current->pid, str, err, regs->iaoq[0]);
188 #ifdef PRINT_USER_FAULTS
189                 /* XXX for debugging only */
190                 show_regs(regs);
191 #endif
192                 return;
193         }
194
195         oops_in_progress = 1;
196
197         /* Amuse the user in a SPARC fashion */
198         printk(
199 "      _______________________________ \n"
200 "     < Your System ate a SPARC! Gah! >\n"
201 "      ------------------------------- \n"
202 "             \\   ^__^\n"
203 "              \\  (xx)\\_______\n"
204 "                 (__)\\       )\\/\\\n"
205 "                  U  ||----w |\n"
206 "                     ||     ||\n");
207         
208         /* unlock the pdc lock if necessary */
209         pdc_emergency_unlock();
210
211         /* maybe the kernel hasn't booted very far yet and hasn't been able 
212          * to initialize the serial or STI console. In that case we should 
213          * re-enable the pdc console, so that the user will be able to 
214          * identify the problem. */
215         if (!console_drivers)
216                 pdc_console_restart();
217         
218         printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
219                 current->comm, current->pid, str, err);
220         show_regs(regs);
221
222         /* Wot's wrong wif bein' racy? */
223         if (current->thread.flags & PARISC_KERNEL_DEATH) {
224                 printk(KERN_CRIT "%s() recursion detected.\n", __FUNCTION__);
225                 local_irq_enable();
226                 while (1);
227         }
228
229         current->thread.flags |= PARISC_KERNEL_DEATH;
230         do_exit(SIGSEGV);
231 }
232
233 int syscall_ipi(int (*syscall) (struct pt_regs *), struct pt_regs *regs)
234 {
235         return syscall(regs);
236 }
237
238 /* gdb uses break 4,8 */
239 #define GDB_BREAK_INSN 0x10004
240 void handle_gdb_break(struct pt_regs *regs, int wot)
241 {
242         struct siginfo si;
243
244         si.si_code = wot;
245         si.si_addr = (void *) (regs->iaoq[0] & ~3);
246         si.si_signo = SIGTRAP;
247         si.si_errno = 0;
248         force_sig_info(SIGTRAP, &si, current);
249 }
250
251 void handle_break(unsigned iir, struct pt_regs *regs)
252 {
253         struct siginfo si;
254
255         switch(iir) {
256         case 0x00:
257 #ifdef PRINT_USER_FAULTS
258                 printk(KERN_DEBUG "break 0,0: pid=%d command='%s'\n",
259                        current->pid, current->comm);
260 #endif
261                 die_if_kernel("Breakpoint", regs, 0);
262 #ifdef PRINT_USER_FAULTS
263                 show_regs(regs);
264 #endif
265                 si.si_code = TRAP_BRKPT;
266                 si.si_addr = (void *) (regs->iaoq[0] & ~3);
267                 si.si_signo = SIGTRAP;
268                 force_sig_info(SIGTRAP, &si, current);
269                 break;
270
271         case GDB_BREAK_INSN:
272                 die_if_kernel("Breakpoint", regs, 0);
273                 handle_gdb_break(regs, TRAP_BRKPT);
274                 break;
275
276         default:
277 #ifdef PRINT_USER_FAULTS
278                 printk(KERN_DEBUG "break %#08x: pid=%d command='%s'\n",
279                        iir, current->pid, current->comm);
280                 show_regs(regs);
281 #endif
282                 si.si_signo = SIGTRAP;
283                 si.si_code = TRAP_BRKPT;
284                 si.si_addr = (void *) (regs->iaoq[0] & ~3);
285                 force_sig_info(SIGTRAP, &si, current);
286                 return;
287         }
288 }
289
290
291 int handle_toc(void)
292 {
293         printk(KERN_CRIT "TOC call.\n");
294         return 0;
295 }
296
297 static void default_trap(int code, struct pt_regs *regs)
298 {
299         printk(KERN_ERR "Trap %d on CPU %d\n", code, smp_processor_id());
300         show_regs(regs);
301 }
302
303 void (*cpu_lpmc) (int code, struct pt_regs *regs) = default_trap;
304
305
306 void transfer_pim_to_trap_frame(struct pt_regs *regs)
307 {
308     register int i;
309     extern unsigned int hpmc_pim_data[];
310     struct pdc_hpmc_pim_11 *pim_narrow;
311     struct pdc_hpmc_pim_20 *pim_wide;
312
313     if (boot_cpu_data.cpu_type >= pcxu) {
314
315         pim_wide = (struct pdc_hpmc_pim_20 *)hpmc_pim_data;
316
317         /*
318          * Note: The following code will probably generate a
319          * bunch of truncation error warnings from the compiler.
320          * Could be handled with an ifdef, but perhaps there
321          * is a better way.
322          */
323
324         regs->gr[0] = pim_wide->cr[22];
325
326         for (i = 1; i < 32; i++)
327             regs->gr[i] = pim_wide->gr[i];
328
329         for (i = 0; i < 32; i++)
330             regs->fr[i] = pim_wide->fr[i];
331
332         for (i = 0; i < 8; i++)
333             regs->sr[i] = pim_wide->sr[i];
334
335         regs->iasq[0] = pim_wide->cr[17];
336         regs->iasq[1] = pim_wide->iasq_back;
337         regs->iaoq[0] = pim_wide->cr[18];
338         regs->iaoq[1] = pim_wide->iaoq_back;
339
340         regs->sar  = pim_wide->cr[11];
341         regs->iir  = pim_wide->cr[19];
342         regs->isr  = pim_wide->cr[20];
343         regs->ior  = pim_wide->cr[21];
344     }
345     else {
346         pim_narrow = (struct pdc_hpmc_pim_11 *)hpmc_pim_data;
347
348         regs->gr[0] = pim_narrow->cr[22];
349
350         for (i = 1; i < 32; i++)
351             regs->gr[i] = pim_narrow->gr[i];
352
353         for (i = 0; i < 32; i++)
354             regs->fr[i] = pim_narrow->fr[i];
355
356         for (i = 0; i < 8; i++)
357             regs->sr[i] = pim_narrow->sr[i];
358
359         regs->iasq[0] = pim_narrow->cr[17];
360         regs->iasq[1] = pim_narrow->iasq_back;
361         regs->iaoq[0] = pim_narrow->cr[18];
362         regs->iaoq[1] = pim_narrow->iaoq_back;
363
364         regs->sar  = pim_narrow->cr[11];
365         regs->iir  = pim_narrow->cr[19];
366         regs->isr  = pim_narrow->cr[20];
367         regs->ior  = pim_narrow->cr[21];
368     }
369
370     /*
371      * The following fields only have meaning if we came through
372      * another path. So just zero them here.
373      */
374
375     regs->ksp = 0;
376     regs->kpc = 0;
377     regs->orig_r28 = 0;
378 }
379
380
381 /*
382  * This routine is called as a last resort when everything else
383  * has gone clearly wrong. We get called for faults in kernel space,
384  * and HPMC's.
385  */
386 void parisc_terminate(char *msg, struct pt_regs *regs, int code, unsigned long offset)
387 {
388         static DEFINE_SPINLOCK(terminate_lock);
389
390         oops_in_progress = 1;
391
392         set_eiem(0);
393         local_irq_disable();
394         spin_lock(&terminate_lock);
395
396         /* unlock the pdc lock if necessary */
397         pdc_emergency_unlock();
398
399         /* restart pdc console if necessary */
400         if (!console_drivers)
401                 pdc_console_restart();
402
403         /* Not all paths will gutter the processor... */
404         switch(code){
405
406         case 1:
407                 transfer_pim_to_trap_frame(regs);
408                 break;
409
410         default:
411                 /* Fall through */
412                 break;
413
414         }
415             
416         {
417                 /* show_stack(NULL, (unsigned long *)regs->gr[30]); */
418                 struct unwind_frame_info info;
419                 unwind_frame_init(&info, current, regs->gr[30], regs->iaoq[0], regs->gr[2]);
420                 do_show_stack(&info);
421         }
422
423         printk("\n");
424         printk(KERN_CRIT "%s: Code=%d regs=%p (Addr=" RFMT ")\n",
425                         msg, code, regs, offset);
426         show_regs(regs);
427
428         spin_unlock(&terminate_lock);
429
430         /* put soft power button back under hardware control;
431          * if the user had pressed it once at any time, the 
432          * system will shut down immediately right here. */
433         pdc_soft_power_button(0);
434         
435         /* Call kernel panic() so reboot timeouts work properly 
436          * FIXME: This function should be on the list of
437          * panic notifiers, and we should call panic
438          * directly from the location that we wish. 
439          * e.g. We should not call panic from
440          * parisc_terminate, but rather the oter way around.
441          * This hack works, prints the panic message twice,
442          * and it enables reboot timers!
443          */
444         panic(msg);
445 }
446
447 void handle_interruption(int code, struct pt_regs *regs)
448 {
449         unsigned long fault_address = 0;
450         unsigned long fault_space = 0;
451         struct siginfo si;
452
453         if (code == 1)
454             pdc_console_restart();  /* switch back to pdc if HPMC */
455         else
456             local_irq_enable();
457
458         /* Security check:
459          * If the priority level is still user, and the
460          * faulting space is not equal to the active space
461          * then the user is attempting something in a space
462          * that does not belong to them. Kill the process.
463          *
464          * This is normally the situation when the user
465          * attempts to jump into the kernel space at the
466          * wrong offset, be it at the gateway page or a
467          * random location.
468          *
469          * We cannot normally signal the process because it
470          * could *be* on the gateway page, and processes
471          * executing on the gateway page can't have signals
472          * delivered.
473          * 
474          * We merely readjust the address into the users
475          * space, at a destination address of zero, and
476          * allow processing to continue.
477          */
478         if (((unsigned long)regs->iaoq[0] & 3) &&
479             ((unsigned long)regs->iasq[0] != (unsigned long)regs->sr[7])) { 
480                 /* Kill the user process later */
481                 regs->iaoq[0] = 0 | 3;
482                 regs->iaoq[1] = regs->iaoq[0] + 4;
483                 regs->iasq[0] = regs->iasq[0] = regs->sr[7];
484                 regs->gr[0] &= ~PSW_B;
485                 return;
486         }
487         
488 #if 0
489         printk(KERN_CRIT "Interruption # %d\n", code);
490 #endif
491
492         switch(code) {
493
494         case  1:
495                 /* High-priority machine check (HPMC) */
496                 
497                 /* set up a new led state on systems shipped with a LED State panel */
498                 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_HPMC);
499                     
500                 parisc_terminate("High Priority Machine Check (HPMC)",
501                                 regs, code, 0);
502                 /* NOT REACHED */
503                 
504         case  2:
505                 /* Power failure interrupt */
506                 printk(KERN_CRIT "Power failure interrupt !\n");
507                 return;
508
509         case  3:
510                 /* Recovery counter trap */
511                 regs->gr[0] &= ~PSW_R;
512                 if (user_space(regs))
513                         handle_gdb_break(regs, TRAP_TRACE);
514                 /* else this must be the start of a syscall - just let it run */
515                 return;
516
517         case  5:
518                 /* Low-priority machine check */
519                 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_LPMC);
520                 
521                 flush_all_caches();
522                 cpu_lpmc(5, regs);
523                 return;
524
525         case  6:
526                 /* Instruction TLB miss fault/Instruction page fault */
527                 fault_address = regs->iaoq[0];
528                 fault_space   = regs->iasq[0];
529                 break;
530
531         case  8:
532                 /* Illegal instruction trap */
533                 die_if_kernel("Illegal instruction", regs, code);
534                 si.si_code = ILL_ILLOPC;
535                 goto give_sigill;
536
537         case  9:
538                 /* Break instruction trap */
539                 handle_break(regs->iir,regs);
540                 return;
541         
542         case 10:
543                 /* Privileged operation trap */
544                 die_if_kernel("Privileged operation", regs, code);
545                 si.si_code = ILL_PRVOPC;
546                 goto give_sigill;
547         
548         case 11:
549                 /* Privileged register trap */
550                 if ((regs->iir & 0xffdfffe0) == 0x034008a0) {
551
552                         /* This is a MFCTL cr26/cr27 to gr instruction.
553                          * PCXS traps on this, so we need to emulate it.
554                          */
555
556                         if (regs->iir & 0x00200000)
557                                 regs->gr[regs->iir & 0x1f] = mfctl(27);
558                         else
559                                 regs->gr[regs->iir & 0x1f] = mfctl(26);
560
561                         regs->iaoq[0] = regs->iaoq[1];
562                         regs->iaoq[1] += 4;
563                         regs->iasq[0] = regs->iasq[1];
564                         return;
565                 }
566
567                 die_if_kernel("Privileged register usage", regs, code);
568                 si.si_code = ILL_PRVREG;
569         give_sigill:
570                 si.si_signo = SIGILL;
571                 si.si_errno = 0;
572                 si.si_addr = (void *) regs->iaoq[0];
573                 force_sig_info(SIGILL, &si, current);
574                 return;
575
576         case 12:
577                 /* Overflow Trap, let the userland signal handler do the cleanup */
578                 si.si_signo = SIGFPE;
579                 si.si_code = FPE_INTOVF;
580                 si.si_addr = (void *) regs->iaoq[0];
581                 force_sig_info(SIGFPE, &si, current);
582                 return;
583                 
584         case 13:
585                 /* Conditional Trap
586                    The condition succees in an instruction which traps 
587                    on condition  */
588                 if(user_mode(regs)){
589                         si.si_signo = SIGFPE;
590                         /* Set to zero, and let the userspace app figure it out from
591                            the insn pointed to by si_addr */
592                         si.si_code = 0;
593                         si.si_addr = (void __user *) regs->iaoq[0];
594                         force_sig_info(SIGFPE, &si, current);
595                         return;
596                 } 
597                 /* The kernel doesn't want to handle condition codes */
598                 break;
599                 
600         case 14:
601                 /* Assist Exception Trap, i.e. floating point exception. */
602                 die_if_kernel("Floating point exception", regs, 0); /* quiet */
603                 handle_fpe(regs);
604                 return;
605                 
606         case 15:
607                 /* Data TLB miss fault/Data page fault */
608                 /* Fall through */
609         case 16:
610                 /* Non-access instruction TLB miss fault */
611                 /* The instruction TLB entry needed for the target address of the FIC
612                    is absent, and hardware can't find it, so we get to cleanup */
613                 /* Fall through */
614         case 17:
615                 /* Non-access data TLB miss fault/Non-access data page fault */
616                 /* FIXME: 
617                          Still need to add slow path emulation code here!
618                          If the insn used a non-shadow register, then the tlb
619                          handlers could not have their side-effect (e.g. probe
620                          writing to a target register) emulated since rfir would
621                          erase the changes to said register. Instead we have to
622                          setup everything, call this function we are in, and emulate
623                          by hand. Technically we need to emulate:
624                          fdc,fdce,pdc,"fic,4f",prober,probeir,probew, probeiw
625                 */                        
626                 fault_address = regs->ior;
627                 fault_space = regs->isr;
628                 break;
629
630         case 18:
631                 /* PCXS only -- later cpu's split this into types 26,27 & 28 */
632                 /* Check for unaligned access */
633                 if (check_unaligned(regs)) {
634                         handle_unaligned(regs);
635                         return;
636                 }
637                 /* Fall Through */
638         case 26: 
639                 /* PCXL: Data memory access rights trap */
640                 fault_address = regs->ior;
641                 fault_space   = regs->isr;
642                 break;
643
644         case 19:
645                 /* Data memory break trap */
646                 regs->gr[0] |= PSW_X; /* So we can single-step over the trap */
647                 /* fall thru */
648         case 21:
649                 /* Page reference trap */
650                 handle_gdb_break(regs, TRAP_HWBKPT);
651                 return;
652
653         case 25:
654                 /* Taken branch trap */
655                 regs->gr[0] &= ~PSW_T;
656                 if (user_space(regs))
657                         handle_gdb_break(regs, TRAP_BRANCH);
658                 /* else this must be the start of a syscall - just let it
659                  * run.
660                  */
661                 return;
662
663         case  7:  
664                 /* Instruction access rights */
665                 /* PCXL: Instruction memory protection trap */
666
667                 /*
668                  * This could be caused by either: 1) a process attempting
669                  * to execute within a vma that does not have execute
670                  * permission, or 2) an access rights violation caused by a
671                  * flush only translation set up by ptep_get_and_clear().
672                  * So we check the vma permissions to differentiate the two.
673                  * If the vma indicates we have execute permission, then
674                  * the cause is the latter one. In this case, we need to
675                  * call do_page_fault() to fix the problem.
676                  */
677
678                 if (user_mode(regs)) {
679                         struct vm_area_struct *vma;
680
681                         down_read(&current->mm->mmap_sem);
682                         vma = find_vma(current->mm,regs->iaoq[0]);
683                         if (vma && (regs->iaoq[0] >= vma->vm_start)
684                                 && (vma->vm_flags & VM_EXEC)) {
685
686                                 fault_address = regs->iaoq[0];
687                                 fault_space = regs->iasq[0];
688
689                                 up_read(&current->mm->mmap_sem);
690                                 break; /* call do_page_fault() */
691                         }
692                         up_read(&current->mm->mmap_sem);
693                 }
694                 /* Fall Through */
695         case 27: 
696                 /* Data memory protection ID trap */
697                 die_if_kernel("Protection id trap", regs, code);
698                 si.si_code = SEGV_MAPERR;
699                 si.si_signo = SIGSEGV;
700                 si.si_errno = 0;
701                 if (code == 7)
702                     si.si_addr = (void *) regs->iaoq[0];
703                 else
704                     si.si_addr = (void *) regs->ior;
705                 force_sig_info(SIGSEGV, &si, current);
706                 return;
707
708         case 28: 
709                 /* Unaligned data reference trap */
710                 handle_unaligned(regs);
711                 return;
712
713         default:
714                 if (user_mode(regs)) {
715 #ifdef PRINT_USER_FAULTS
716                         printk(KERN_DEBUG "\nhandle_interruption() pid=%d command='%s'\n",
717                             current->pid, current->comm);
718                         show_regs(regs);
719 #endif
720                         /* SIGBUS, for lack of a better one. */
721                         si.si_signo = SIGBUS;
722                         si.si_code = BUS_OBJERR;
723                         si.si_errno = 0;
724                         si.si_addr = (void *) regs->ior;
725                         force_sig_info(SIGBUS, &si, current);
726                         return;
727                 }
728                 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);
729                 
730                 parisc_terminate("Unexpected interruption", regs, code, 0);
731                 /* NOT REACHED */
732         }
733
734         if (user_mode(regs)) {
735             if ((fault_space>>SPACEID_SHIFT) != (regs->sr[7] >> SPACEID_SHIFT)) {
736 #ifdef PRINT_USER_FAULTS
737                 if (fault_space == 0)
738                         printk(KERN_DEBUG "User Fault on Kernel Space ");
739                 else
740                         printk(KERN_DEBUG "User Fault (long pointer) (fault %d) ",
741                                code);
742                 printk("pid=%d command='%s'\n", current->pid, current->comm);
743                 show_regs(regs);
744 #endif
745                 si.si_signo = SIGSEGV;
746                 si.si_errno = 0;
747                 si.si_code = SEGV_MAPERR;
748                 si.si_addr = (void *) regs->ior;
749                 force_sig_info(SIGSEGV, &si, current);
750                 return;
751             }
752         }
753         else {
754
755             /*
756              * The kernel should never fault on its own address space.
757              */
758
759             if (fault_space == 0) 
760             {
761                 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);
762                 parisc_terminate("Kernel Fault", regs, code, fault_address);
763         
764             }
765         }
766
767         do_page_fault(regs, code, fault_address);
768 }
769
770
771 int __init check_ivt(void *iva)
772 {
773         int i;
774         u32 check = 0;
775         u32 *ivap;
776         u32 *hpmcp;
777         u32 length;
778         extern void os_hpmc(void);
779         extern void os_hpmc_end(void);
780
781         if (strcmp((char *)iva, "cows can fly"))
782                 return -1;
783
784         ivap = (u32 *)iva;
785
786         for (i = 0; i < 8; i++)
787             *ivap++ = 0;
788
789         /* Compute Checksum for HPMC handler */
790
791         length = (u32)((unsigned long)os_hpmc_end - (unsigned long)os_hpmc);
792         ivap[7] = length;
793
794         hpmcp = (u32 *)os_hpmc;
795
796         for (i=0; i<length/4; i++)
797             check += *hpmcp++;
798
799         for (i=0; i<8; i++)
800             check += ivap[i];
801
802         ivap[5] = -check;
803
804         return 0;
805 }
806         
807 #ifndef __LP64__
808 extern const void fault_vector_11;
809 #endif
810 extern const void fault_vector_20;
811
812 void __init trap_init(void)
813 {
814         void *iva;
815
816         if (boot_cpu_data.cpu_type >= pcxu)
817                 iva = (void *) &fault_vector_20;
818         else
819 #ifdef __LP64__
820                 panic("Can't boot 64-bit OS on PA1.1 processor!");
821 #else
822                 iva = (void *) &fault_vector_11;
823 #endif
824
825         if (check_ivt(iva))
826                 panic("IVT invalid");
827 }