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