Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / arch / parisc / kernel / traps.c
blobb6c3f936abfbbb80b6613481018bf7c099f9f564
1 /*
2 * linux/arch/parisc/traps.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 * Copyright (C) 1999, 2000 Philipp Rumpf <prumpf@tux.org>
6 */
8 /*
9 * 'Traps.c' handles hardware traps and faults after we have saved some
10 * state in 'asm.s'.
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/spinlock.h>
24 #include <linux/init.h>
25 #include <linux/interrupt.h>
26 #include <linux/console.h>
27 #include <linux/kallsyms.h>
28 #include <linux/bug.h>
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 #include <asm/tlbflush.h>
43 #include <asm/cacheflush.h>
45 #include "../math-emu/math-emu.h" /* for handle_fpe() */
47 #define PRINT_USER_FAULTS /* (turn this on if you want user faults to be */
48 /* dumped to the console via printk) */
50 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
51 DEFINE_SPINLOCK(pa_dbit_lock);
52 #endif
54 <<<<<<< HEAD:arch/parisc/kernel/traps.c
55 =======
56 void parisc_show_stack(struct task_struct *t, unsigned long *sp,
57 struct pt_regs *regs);
59 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/parisc/kernel/traps.c
60 static int printbinary(char *buf, unsigned long x, int nbits)
62 unsigned long mask = 1UL << (nbits - 1);
63 while (mask != 0) {
64 *buf++ = (mask & x ? '1' : '0');
65 mask >>= 1;
67 *buf = '\0';
69 return nbits;
72 #ifdef CONFIG_64BIT
73 #define RFMT "%016lx"
74 #else
75 #define RFMT "%08lx"
76 #endif
77 #define FFMT "%016llx" /* fpregs are 64-bit always */
79 #define PRINTREGS(lvl,r,f,fmt,x) \
80 printk("%s%s%02d-%02d " fmt " " fmt " " fmt " " fmt "\n", \
81 lvl, f, (x), (x+3), (r)[(x)+0], (r)[(x)+1], \
82 (r)[(x)+2], (r)[(x)+3])
84 static void print_gr(char *level, struct pt_regs *regs)
86 int i;
87 char buf[64];
89 printk("%s\n", level);
90 printk("%s YZrvWESTHLNXBCVMcbcbcbcbOGFRQPDI\n", level);
91 printbinary(buf, regs->gr[0], 32);
92 printk("%sPSW: %s %s\n", level, buf, print_tainted());
94 for (i = 0; i < 32; i += 4)
95 PRINTREGS(level, regs->gr, "r", RFMT, i);
98 static void print_fr(char *level, struct pt_regs *regs)
100 int i;
101 char buf[64];
102 struct { u32 sw[2]; } s;
104 /* FR are 64bit everywhere. Need to use asm to get the content
105 * of fpsr/fper1, and we assume that we won't have a FP Identify
106 * in our way, otherwise we're screwed.
107 * The fldd is used to restore the T-bit if there was one, as the
108 * store clears it anyway.
109 * PA2.0 book says "thou shall not use fstw on FPSR/FPERs" - T-Bone */
110 asm volatile ("fstd %%fr0,0(%1) \n\t"
111 "fldd 0(%1),%%fr0 \n\t"
112 : "=m" (s) : "r" (&s) : "r0");
114 printk("%s\n", level);
115 printk("%s VZOUICununcqcqcqcqcqcrmunTDVZOUI\n", level);
116 printbinary(buf, s.sw[0], 32);
117 printk("%sFPSR: %s\n", level, buf);
118 printk("%sFPER1: %08x\n", level, s.sw[1]);
120 /* here we'll print fr0 again, tho it'll be meaningless */
121 for (i = 0; i < 32; i += 4)
122 PRINTREGS(level, regs->fr, "fr", FFMT, i);
125 void show_regs(struct pt_regs *regs)
127 int i;
128 char *level;
129 unsigned long cr30, cr31;
131 level = user_mode(regs) ? KERN_DEBUG : KERN_CRIT;
133 print_gr(level, regs);
135 for (i = 0; i < 8; i += 4)
136 PRINTREGS(level, regs->sr, "sr", RFMT, i);
138 if (user_mode(regs))
139 print_fr(level, regs);
141 cr30 = mfctl(30);
142 cr31 = mfctl(31);
143 printk("%s\n", level);
144 printk("%sIASQ: " RFMT " " RFMT " IAOQ: " RFMT " " RFMT "\n",
145 level, regs->iasq[0], regs->iasq[1], regs->iaoq[0], regs->iaoq[1]);
146 printk("%s IIR: %08lx ISR: " RFMT " IOR: " RFMT "\n",
147 level, regs->iir, regs->isr, regs->ior);
148 printk("%s CPU: %8d CR30: " RFMT " CR31: " RFMT "\n",
149 level, current_thread_info()->cpu, cr30, cr31);
150 printk("%s ORIG_R28: " RFMT "\n", level, regs->orig_r28);
151 printk(level);
152 print_symbol(" IAOQ[0]: %s\n", regs->iaoq[0]);
153 printk(level);
154 print_symbol(" IAOQ[1]: %s\n", regs->iaoq[1]);
155 printk(level);
156 print_symbol(" RP(r2): %s\n", regs->gr[2]);
157 <<<<<<< HEAD:arch/parisc/kernel/traps.c
158 =======
160 parisc_show_stack(current, NULL, regs);
161 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/parisc/kernel/traps.c
165 void dump_stack(void)
167 show_stack(NULL, NULL);
170 EXPORT_SYMBOL(dump_stack);
172 static void do_show_stack(struct unwind_frame_info *info)
174 int i = 1;
176 printk(KERN_CRIT "Backtrace:\n");
177 while (i <= 16) {
178 if (unwind_once(info) < 0 || info->ip == 0)
179 break;
181 if (__kernel_text_address(info->ip)) {
182 printk("%s [<" RFMT ">] ", (i&0x3)==1 ? KERN_CRIT : "", info->ip);
183 #ifdef CONFIG_KALLSYMS
184 print_symbol("%s\n", info->ip);
185 #else
186 if ((i & 0x03) == 0)
187 printk("\n");
188 #endif
189 i++;
192 printk("\n");
195 <<<<<<< HEAD:arch/parisc/kernel/traps.c
196 void show_stack(struct task_struct *task, unsigned long *s)
197 =======
198 void parisc_show_stack(struct task_struct *task, unsigned long *sp,
199 struct pt_regs *regs)
200 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/parisc/kernel/traps.c
202 struct unwind_frame_info info;
203 <<<<<<< HEAD:arch/parisc/kernel/traps.c
204 =======
205 struct task_struct *t;
207 t = task ? task : current;
208 if (regs) {
209 unwind_frame_init(&info, t, regs);
210 goto show_stack;
212 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/parisc/kernel/traps.c
214 <<<<<<< HEAD:arch/parisc/kernel/traps.c
215 if (!task) {
216 =======
217 if (t == current) {
218 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/parisc/kernel/traps.c
219 unsigned long sp;
221 HERE:
222 asm volatile ("copy %%r30, %0" : "=r"(sp));
224 struct pt_regs r;
226 memset(&r, 0, sizeof(struct pt_regs));
227 r.iaoq[0] = (unsigned long)&&HERE;
228 r.gr[2] = (unsigned long)__builtin_return_address(0);
229 r.gr[30] = sp;
231 unwind_frame_init(&info, current, &r);
233 } else {
234 <<<<<<< HEAD:arch/parisc/kernel/traps.c
235 unwind_frame_init_from_blocked_task(&info, task);
236 =======
237 unwind_frame_init_from_blocked_task(&info, t);
238 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/parisc/kernel/traps.c
241 <<<<<<< HEAD:arch/parisc/kernel/traps.c
242 =======
243 show_stack:
244 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/parisc/kernel/traps.c
245 do_show_stack(&info);
248 <<<<<<< HEAD:arch/parisc/kernel/traps.c
249 =======
250 void show_stack(struct task_struct *t, unsigned long *sp)
252 return parisc_show_stack(t, sp, NULL);
255 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/parisc/kernel/traps.c
256 int is_valid_bugaddr(unsigned long iaoq)
258 return 1;
261 void die_if_kernel(char *str, struct pt_regs *regs, long err)
263 if (user_mode(regs)) {
264 if (err == 0)
265 return; /* STFU */
267 printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
268 current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
269 #ifdef PRINT_USER_FAULTS
270 /* XXX for debugging only */
271 show_regs(regs);
272 #endif
273 return;
276 oops_in_progress = 1;
278 /* Amuse the user in a SPARC fashion */
279 if (err) printk(
280 KERN_CRIT " _______________________________ \n"
281 KERN_CRIT " < Your System ate a SPARC! Gah! >\n"
282 KERN_CRIT " ------------------------------- \n"
283 KERN_CRIT " \\ ^__^\n"
284 KERN_CRIT " \\ (xx)\\_______\n"
285 KERN_CRIT " (__)\\ )\\/\\\n"
286 KERN_CRIT " U ||----w |\n"
287 KERN_CRIT " || ||\n");
289 /* unlock the pdc lock if necessary */
290 pdc_emergency_unlock();
292 /* maybe the kernel hasn't booted very far yet and hasn't been able
293 * to initialize the serial or STI console. In that case we should
294 * re-enable the pdc console, so that the user will be able to
295 * identify the problem. */
296 if (!console_drivers)
297 pdc_console_restart();
299 if (err)
300 printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
301 current->comm, task_pid_nr(current), str, err);
303 /* Wot's wrong wif bein' racy? */
304 if (current->thread.flags & PARISC_KERNEL_DEATH) {
305 printk(KERN_CRIT "%s() recursion detected.\n", __FUNCTION__);
306 local_irq_enable();
307 while (1);
309 current->thread.flags |= PARISC_KERNEL_DEATH;
311 show_regs(regs);
312 dump_stack();
313 add_taint(TAINT_DIE);
315 if (in_interrupt())
316 panic("Fatal exception in interrupt");
318 if (panic_on_oops) {
319 printk(KERN_EMERG "Fatal exception: panic in 5 seconds\n");
320 ssleep(5);
321 panic("Fatal exception");
324 do_exit(SIGSEGV);
327 int syscall_ipi(int (*syscall) (struct pt_regs *), struct pt_regs *regs)
329 return syscall(regs);
332 /* gdb uses break 4,8 */
333 #define GDB_BREAK_INSN 0x10004
334 static void handle_gdb_break(struct pt_regs *regs, int wot)
336 struct siginfo si;
338 si.si_signo = SIGTRAP;
339 si.si_errno = 0;
340 si.si_code = wot;
341 si.si_addr = (void __user *) (regs->iaoq[0] & ~3);
342 force_sig_info(SIGTRAP, &si, current);
345 static void handle_break(struct pt_regs *regs)
347 unsigned iir = regs->iir;
349 if (unlikely(iir == PARISC_BUG_BREAK_INSN && !user_mode(regs))) {
350 /* check if a BUG() or WARN() trapped here. */
351 enum bug_trap_type tt;
352 tt = report_bug(regs->iaoq[0] & ~3, regs);
353 if (tt == BUG_TRAP_TYPE_WARN) {
354 regs->iaoq[0] += 4;
355 regs->iaoq[1] += 4;
356 return; /* return to next instruction when WARN_ON(). */
358 die_if_kernel("Unknown kernel breakpoint", regs,
359 (tt == BUG_TRAP_TYPE_NONE) ? 9 : 0);
362 #ifdef PRINT_USER_FAULTS
363 if (unlikely(iir != GDB_BREAK_INSN)) {
364 printk(KERN_DEBUG "break %d,%d: pid=%d command='%s'\n",
365 iir & 31, (iir>>13) & ((1<<13)-1),
366 task_pid_nr(current), current->comm);
367 show_regs(regs);
369 #endif
371 /* send standard GDB signal */
372 handle_gdb_break(regs, TRAP_BRKPT);
375 static void default_trap(int code, struct pt_regs *regs)
377 printk(KERN_ERR "Trap %d on CPU %d\n", code, smp_processor_id());
378 show_regs(regs);
381 void (*cpu_lpmc) (int code, struct pt_regs *regs) __read_mostly = default_trap;
384 void transfer_pim_to_trap_frame(struct pt_regs *regs)
386 register int i;
387 extern unsigned int hpmc_pim_data[];
388 struct pdc_hpmc_pim_11 *pim_narrow;
389 struct pdc_hpmc_pim_20 *pim_wide;
391 if (boot_cpu_data.cpu_type >= pcxu) {
393 pim_wide = (struct pdc_hpmc_pim_20 *)hpmc_pim_data;
396 * Note: The following code will probably generate a
397 * bunch of truncation error warnings from the compiler.
398 * Could be handled with an ifdef, but perhaps there
399 * is a better way.
402 regs->gr[0] = pim_wide->cr[22];
404 for (i = 1; i < 32; i++)
405 regs->gr[i] = pim_wide->gr[i];
407 for (i = 0; i < 32; i++)
408 regs->fr[i] = pim_wide->fr[i];
410 for (i = 0; i < 8; i++)
411 regs->sr[i] = pim_wide->sr[i];
413 regs->iasq[0] = pim_wide->cr[17];
414 regs->iasq[1] = pim_wide->iasq_back;
415 regs->iaoq[0] = pim_wide->cr[18];
416 regs->iaoq[1] = pim_wide->iaoq_back;
418 regs->sar = pim_wide->cr[11];
419 regs->iir = pim_wide->cr[19];
420 regs->isr = pim_wide->cr[20];
421 regs->ior = pim_wide->cr[21];
423 else {
424 pim_narrow = (struct pdc_hpmc_pim_11 *)hpmc_pim_data;
426 regs->gr[0] = pim_narrow->cr[22];
428 for (i = 1; i < 32; i++)
429 regs->gr[i] = pim_narrow->gr[i];
431 for (i = 0; i < 32; i++)
432 regs->fr[i] = pim_narrow->fr[i];
434 for (i = 0; i < 8; i++)
435 regs->sr[i] = pim_narrow->sr[i];
437 regs->iasq[0] = pim_narrow->cr[17];
438 regs->iasq[1] = pim_narrow->iasq_back;
439 regs->iaoq[0] = pim_narrow->cr[18];
440 regs->iaoq[1] = pim_narrow->iaoq_back;
442 regs->sar = pim_narrow->cr[11];
443 regs->iir = pim_narrow->cr[19];
444 regs->isr = pim_narrow->cr[20];
445 regs->ior = pim_narrow->cr[21];
449 * The following fields only have meaning if we came through
450 * another path. So just zero them here.
453 regs->ksp = 0;
454 regs->kpc = 0;
455 regs->orig_r28 = 0;
460 * This routine is called as a last resort when everything else
461 * has gone clearly wrong. We get called for faults in kernel space,
462 * and HPMC's.
464 void parisc_terminate(char *msg, struct pt_regs *regs, int code, unsigned long offset)
466 static DEFINE_SPINLOCK(terminate_lock);
468 oops_in_progress = 1;
470 set_eiem(0);
471 local_irq_disable();
472 spin_lock(&terminate_lock);
474 /* unlock the pdc lock if necessary */
475 pdc_emergency_unlock();
477 /* restart pdc console if necessary */
478 if (!console_drivers)
479 pdc_console_restart();
481 /* Not all paths will gutter the processor... */
482 switch(code){
484 case 1:
485 transfer_pim_to_trap_frame(regs);
486 break;
488 default:
489 /* Fall through */
490 break;
495 /* show_stack(NULL, (unsigned long *)regs->gr[30]); */
496 struct unwind_frame_info info;
497 unwind_frame_init(&info, current, regs);
498 do_show_stack(&info);
501 printk("\n");
502 printk(KERN_CRIT "%s: Code=%d regs=%p (Addr=" RFMT ")\n",
503 msg, code, regs, offset);
504 show_regs(regs);
506 spin_unlock(&terminate_lock);
508 /* put soft power button back under hardware control;
509 * if the user had pressed it once at any time, the
510 * system will shut down immediately right here. */
511 pdc_soft_power_button(0);
513 /* Call kernel panic() so reboot timeouts work properly
514 * FIXME: This function should be on the list of
515 * panic notifiers, and we should call panic
516 * directly from the location that we wish.
517 * e.g. We should not call panic from
518 * parisc_terminate, but rather the oter way around.
519 * This hack works, prints the panic message twice,
520 * and it enables reboot timers!
522 panic(msg);
525 void handle_interruption(int code, struct pt_regs *regs)
527 unsigned long fault_address = 0;
528 unsigned long fault_space = 0;
529 struct siginfo si;
531 if (code == 1)
532 pdc_console_restart(); /* switch back to pdc if HPMC */
533 else
534 local_irq_enable();
536 /* Security check:
537 * If the priority level is still user, and the
538 * faulting space is not equal to the active space
539 * then the user is attempting something in a space
540 * that does not belong to them. Kill the process.
542 * This is normally the situation when the user
543 * attempts to jump into the kernel space at the
544 * wrong offset, be it at the gateway page or a
545 * random location.
547 * We cannot normally signal the process because it
548 * could *be* on the gateway page, and processes
549 * executing on the gateway page can't have signals
550 * delivered.
552 * We merely readjust the address into the users
553 * space, at a destination address of zero, and
554 * allow processing to continue.
556 if (((unsigned long)regs->iaoq[0] & 3) &&
557 ((unsigned long)regs->iasq[0] != (unsigned long)regs->sr[7])) {
558 /* Kill the user process later */
559 regs->iaoq[0] = 0 | 3;
560 regs->iaoq[1] = regs->iaoq[0] + 4;
561 regs->iasq[0] = regs->iasq[0] = regs->sr[7];
562 regs->gr[0] &= ~PSW_B;
563 return;
566 #if 0
567 printk(KERN_CRIT "Interruption # %d\n", code);
568 #endif
570 switch(code) {
572 case 1:
573 /* High-priority machine check (HPMC) */
575 /* set up a new led state on systems shipped with a LED State panel */
576 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_HPMC);
578 parisc_terminate("High Priority Machine Check (HPMC)",
579 regs, code, 0);
580 /* NOT REACHED */
582 case 2:
583 /* Power failure interrupt */
584 printk(KERN_CRIT "Power failure interrupt !\n");
585 return;
587 case 3:
588 /* Recovery counter trap */
589 regs->gr[0] &= ~PSW_R;
590 if (user_space(regs))
591 handle_gdb_break(regs, TRAP_TRACE);
592 /* else this must be the start of a syscall - just let it run */
593 return;
595 case 5:
596 /* Low-priority machine check */
597 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_LPMC);
599 flush_cache_all();
600 flush_tlb_all();
601 cpu_lpmc(5, regs);
602 return;
604 case 6:
605 /* Instruction TLB miss fault/Instruction page fault */
606 fault_address = regs->iaoq[0];
607 fault_space = regs->iasq[0];
608 break;
610 case 8:
611 /* Illegal instruction trap */
612 die_if_kernel("Illegal instruction", regs, code);
613 si.si_code = ILL_ILLOPC;
614 goto give_sigill;
616 case 9:
617 /* Break instruction trap */
618 handle_break(regs);
619 return;
621 case 10:
622 /* Privileged operation trap */
623 die_if_kernel("Privileged operation", regs, code);
624 si.si_code = ILL_PRVOPC;
625 goto give_sigill;
627 case 11:
628 /* Privileged register trap */
629 if ((regs->iir & 0xffdfffe0) == 0x034008a0) {
631 /* This is a MFCTL cr26/cr27 to gr instruction.
632 * PCXS traps on this, so we need to emulate it.
635 if (regs->iir & 0x00200000)
636 regs->gr[regs->iir & 0x1f] = mfctl(27);
637 else
638 regs->gr[regs->iir & 0x1f] = mfctl(26);
640 regs->iaoq[0] = regs->iaoq[1];
641 regs->iaoq[1] += 4;
642 regs->iasq[0] = regs->iasq[1];
643 return;
646 die_if_kernel("Privileged register usage", regs, code);
647 si.si_code = ILL_PRVREG;
648 give_sigill:
649 si.si_signo = SIGILL;
650 si.si_errno = 0;
651 si.si_addr = (void __user *) regs->iaoq[0];
652 force_sig_info(SIGILL, &si, current);
653 return;
655 case 12:
656 /* Overflow Trap, let the userland signal handler do the cleanup */
657 si.si_signo = SIGFPE;
658 si.si_code = FPE_INTOVF;
659 si.si_addr = (void __user *) regs->iaoq[0];
660 force_sig_info(SIGFPE, &si, current);
661 return;
663 case 13:
664 /* Conditional Trap
665 The condition succeeds in an instruction which traps
666 on condition */
667 if(user_mode(regs)){
668 si.si_signo = SIGFPE;
669 /* Set to zero, and let the userspace app figure it out from
670 the insn pointed to by si_addr */
671 si.si_code = 0;
672 si.si_addr = (void __user *) regs->iaoq[0];
673 force_sig_info(SIGFPE, &si, current);
674 return;
676 /* The kernel doesn't want to handle condition codes */
677 break;
679 case 14:
680 /* Assist Exception Trap, i.e. floating point exception. */
681 die_if_kernel("Floating point exception", regs, 0); /* quiet */
682 handle_fpe(regs);
683 return;
685 case 15:
686 /* Data TLB miss fault/Data page fault */
687 /* Fall through */
688 case 16:
689 /* Non-access instruction TLB miss fault */
690 /* The instruction TLB entry needed for the target address of the FIC
691 is absent, and hardware can't find it, so we get to cleanup */
692 /* Fall through */
693 case 17:
694 /* Non-access data TLB miss fault/Non-access data page fault */
695 /* FIXME:
696 Still need to add slow path emulation code here!
697 If the insn used a non-shadow register, then the tlb
698 handlers could not have their side-effect (e.g. probe
699 writing to a target register) emulated since rfir would
700 erase the changes to said register. Instead we have to
701 setup everything, call this function we are in, and emulate
702 by hand. Technically we need to emulate:
703 fdc,fdce,pdc,"fic,4f",prober,probeir,probew, probeiw
705 fault_address = regs->ior;
706 fault_space = regs->isr;
707 break;
709 case 18:
710 /* PCXS only -- later cpu's split this into types 26,27 & 28 */
711 /* Check for unaligned access */
712 if (check_unaligned(regs)) {
713 handle_unaligned(regs);
714 return;
716 /* Fall Through */
717 case 26:
718 /* PCXL: Data memory access rights trap */
719 fault_address = regs->ior;
720 fault_space = regs->isr;
721 break;
723 case 19:
724 /* Data memory break trap */
725 regs->gr[0] |= PSW_X; /* So we can single-step over the trap */
726 /* fall thru */
727 case 21:
728 /* Page reference trap */
729 handle_gdb_break(regs, TRAP_HWBKPT);
730 return;
732 case 25:
733 /* Taken branch trap */
734 regs->gr[0] &= ~PSW_T;
735 if (user_space(regs))
736 handle_gdb_break(regs, TRAP_BRANCH);
737 /* else this must be the start of a syscall - just let it
738 * run.
740 return;
742 case 7:
743 /* Instruction access rights */
744 /* PCXL: Instruction memory protection trap */
747 * This could be caused by either: 1) a process attempting
748 * to execute within a vma that does not have execute
749 * permission, or 2) an access rights violation caused by a
750 * flush only translation set up by ptep_get_and_clear().
751 * So we check the vma permissions to differentiate the two.
752 * If the vma indicates we have execute permission, then
753 * the cause is the latter one. In this case, we need to
754 * call do_page_fault() to fix the problem.
757 if (user_mode(regs)) {
758 struct vm_area_struct *vma;
760 down_read(&current->mm->mmap_sem);
761 vma = find_vma(current->mm,regs->iaoq[0]);
762 if (vma && (regs->iaoq[0] >= vma->vm_start)
763 && (vma->vm_flags & VM_EXEC)) {
765 fault_address = regs->iaoq[0];
766 fault_space = regs->iasq[0];
768 up_read(&current->mm->mmap_sem);
769 break; /* call do_page_fault() */
771 up_read(&current->mm->mmap_sem);
773 /* Fall Through */
774 case 27:
775 /* Data memory protection ID trap */
776 die_if_kernel("Protection id trap", regs, code);
777 si.si_code = SEGV_MAPERR;
778 si.si_signo = SIGSEGV;
779 si.si_errno = 0;
780 if (code == 7)
781 si.si_addr = (void __user *) regs->iaoq[0];
782 else
783 si.si_addr = (void __user *) regs->ior;
784 force_sig_info(SIGSEGV, &si, current);
785 return;
787 case 28:
788 /* Unaligned data reference trap */
789 handle_unaligned(regs);
790 return;
792 default:
793 if (user_mode(regs)) {
794 #ifdef PRINT_USER_FAULTS
795 printk(KERN_DEBUG "\nhandle_interruption() pid=%d command='%s'\n",
796 task_pid_nr(current), current->comm);
797 show_regs(regs);
798 #endif
799 /* SIGBUS, for lack of a better one. */
800 si.si_signo = SIGBUS;
801 si.si_code = BUS_OBJERR;
802 si.si_errno = 0;
803 si.si_addr = (void __user *) regs->ior;
804 force_sig_info(SIGBUS, &si, current);
805 return;
807 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);
809 parisc_terminate("Unexpected interruption", regs, code, 0);
810 /* NOT REACHED */
813 if (user_mode(regs)) {
814 if ((fault_space >> SPACEID_SHIFT) != (regs->sr[7] >> SPACEID_SHIFT)) {
815 #ifdef PRINT_USER_FAULTS
816 if (fault_space == 0)
817 printk(KERN_DEBUG "User Fault on Kernel Space ");
818 else
819 printk(KERN_DEBUG "User Fault (long pointer) (fault %d) ",
820 code);
821 printk("pid=%d command='%s'\n", task_pid_nr(current), current->comm);
822 show_regs(regs);
823 #endif
824 si.si_signo = SIGSEGV;
825 si.si_errno = 0;
826 si.si_code = SEGV_MAPERR;
827 si.si_addr = (void __user *) regs->ior;
828 force_sig_info(SIGSEGV, &si, current);
829 return;
832 else {
835 * The kernel should never fault on its own address space.
838 if (fault_space == 0)
840 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);
841 parisc_terminate("Kernel Fault", regs, code, fault_address);
846 do_page_fault(regs, code, fault_address);
850 int __init check_ivt(void *iva)
852 extern const u32 os_hpmc[];
853 extern const u32 os_hpmc_end[];
855 int i;
856 u32 check = 0;
857 u32 *ivap;
858 u32 *hpmcp;
859 u32 length;
861 if (strcmp((char *)iva, "cows can fly"))
862 return -1;
864 ivap = (u32 *)iva;
866 for (i = 0; i < 8; i++)
867 *ivap++ = 0;
869 /* Compute Checksum for HPMC handler */
871 length = os_hpmc_end - os_hpmc;
872 ivap[7] = length;
874 hpmcp = (u32 *)os_hpmc;
876 for (i=0; i<length/4; i++)
877 check += *hpmcp++;
879 for (i=0; i<8; i++)
880 check += ivap[i];
882 ivap[5] = -check;
884 return 0;
887 #ifndef CONFIG_64BIT
888 extern const void fault_vector_11;
889 #endif
890 extern const void fault_vector_20;
892 void __init trap_init(void)
894 void *iva;
896 if (boot_cpu_data.cpu_type >= pcxu)
897 iva = (void *) &fault_vector_20;
898 else
899 #ifdef CONFIG_64BIT
900 panic("Can't boot 64-bit OS on PA1.1 processor!");
901 #else
902 iva = (void *) &fault_vector_11;
903 #endif
905 if (check_ivt(iva))
906 panic("IVT invalid");