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