2 * Architecture-specific trap handling.
4 * Copyright (C) 1998-2003 Hewlett-Packard Co
5 * David Mosberger-Tang <davidm@hpl.hp.com>
7 * 05/12/00 grao <goutham.rao@intel.com> : added isr in siginfo for SIGFPE
10 #include <linux/config.h>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/sched.h>
14 #include <linux/tty.h>
15 #include <linux/vt_kern.h> /* For unblank_screen() */
16 #include <linux/module.h> /* for EXPORT_SYMBOL */
17 #include <linux/hardirq.h>
18 #include <linux/kprobes.h>
19 #include <linux/delay.h> /* for ssleep() */
21 #include <asm/fpswa.h>
23 #include <asm/intrinsics.h>
24 #include <asm/processor.h>
25 #include <asm/uaccess.h>
26 #include <asm/kdebug.h>
28 extern spinlock_t timerlist_lock;
30 fpswa_interface_t *fpswa_interface;
31 EXPORT_SYMBOL(fpswa_interface);
33 ATOMIC_NOTIFIER_HEAD(ia64die_chain);
36 register_die_notifier(struct notifier_block *nb)
38 return atomic_notifier_chain_register(&ia64die_chain, nb);
40 EXPORT_SYMBOL_GPL(register_die_notifier);
43 unregister_die_notifier(struct notifier_block *nb)
45 return atomic_notifier_chain_unregister(&ia64die_chain, nb);
47 EXPORT_SYMBOL_GPL(unregister_die_notifier);
52 if (ia64_boot_param->fpswa)
53 /* FPSWA fixup: make the interface pointer a kernel virtual address: */
54 fpswa_interface = __va(ia64_boot_param->fpswa);
58 * Unlock any spinlocks which will prevent us from getting the message out (timerlist_lock
59 * is acquired through the console unblank code)
62 bust_spinlocks (int yes)
64 int loglevel_save = console_loglevel;
76 * OK, the message is on the console. Now we call printk() without
77 * oops_in_progress set so that printk will give klogd a poke. Hold onto
80 console_loglevel = 15; /* NMI oopser may have shut the console up */
82 console_loglevel = loglevel_save;
86 die (const char *str, struct pt_regs *regs, long err)
93 .lock = SPIN_LOCK_UNLOCKED,
97 static int die_counter;
100 if (die.lock_owner != cpu) {
102 spin_lock_irq(&die.lock);
103 die.lock_owner = cpu;
104 die.lock_owner_depth = 0;
109 if (++die.lock_owner_depth < 3) {
110 printk("%s[%d]: %s %ld [%d]\n",
111 current->comm, current->pid, str, err, ++die_counter);
112 (void) notify_die(DIE_OOPS, (char *)str, regs, err, 255, SIGSEGV);
115 printk(KERN_ERR "Recursive die() failure, output suppressed\n");
119 spin_unlock_irq(&die.lock);
122 printk(KERN_EMERG "Fatal exception: panic in 5 seconds\n");
124 panic("Fatal exception");
131 die_if_kernel (char *str, struct pt_regs *regs, long err)
133 if (!user_mode(regs))
138 __kprobes ia64_bad_break (unsigned long break_num, struct pt_regs *regs)
143 /* SIGILL, SIGFPE, SIGSEGV, and SIGBUS want these field initialized: */
144 siginfo.si_addr = (void __user *) (regs->cr_iip + ia64_psr(regs)->ri);
145 siginfo.si_imm = break_num;
146 siginfo.si_flags = 0; /* clear __ISR_VALID */
150 case 0: /* unknown error (used by GCC for __builtin_abort()) */
151 if (notify_die(DIE_BREAK, "break 0", regs, break_num, TRAP_BRKPT, SIGTRAP)
154 die_if_kernel("bugcheck!", regs, break_num);
155 sig = SIGILL; code = ILL_ILLOPC;
158 case 1: /* integer divide by zero */
159 sig = SIGFPE; code = FPE_INTDIV;
162 case 2: /* integer overflow */
163 sig = SIGFPE; code = FPE_INTOVF;
166 case 3: /* range check/bounds check */
167 sig = SIGFPE; code = FPE_FLTSUB;
170 case 4: /* null pointer dereference */
171 sig = SIGSEGV; code = SEGV_MAPERR;
174 case 5: /* misaligned data */
175 sig = SIGSEGV; code = BUS_ADRALN;
178 case 6: /* decimal overflow */
179 sig = SIGFPE; code = __FPE_DECOVF;
182 case 7: /* decimal divide by zero */
183 sig = SIGFPE; code = __FPE_DECDIV;
186 case 8: /* packed decimal error */
187 sig = SIGFPE; code = __FPE_DECERR;
190 case 9: /* invalid ASCII digit */
191 sig = SIGFPE; code = __FPE_INVASC;
194 case 10: /* invalid decimal digit */
195 sig = SIGFPE; code = __FPE_INVDEC;
198 case 11: /* paragraph stack overflow */
199 sig = SIGSEGV; code = __SEGV_PSTKOVF;
202 case 0x3f000 ... 0x3ffff: /* bundle-update in progress */
203 sig = SIGILL; code = __ILL_BNDMOD;
207 if (break_num < 0x40000 || break_num > 0x100000)
208 die_if_kernel("Bad break", regs, break_num);
210 if (break_num < 0x80000) {
211 sig = SIGILL; code = __ILL_BREAK;
213 if (notify_die(DIE_BREAK, "bad break", regs, break_num, TRAP_BRKPT, SIGTRAP)
216 sig = SIGTRAP; code = TRAP_BRKPT;
219 siginfo.si_signo = sig;
220 siginfo.si_errno = 0;
221 siginfo.si_code = code;
222 force_sig_info(sig, &siginfo, current);
226 * disabled_fph_fault() is called when a user-level process attempts to access f32..f127
227 * and it doesn't own the fp-high register partition. When this happens, we save the
228 * current fph partition in the task_struct of the fpu-owner (if necessary) and then load
229 * the fp-high partition of the current task (if necessary). Note that the kernel has
230 * access to fph by the time we get here, as the IVT's "Disabled FP-Register" handler takes
231 * care of clearing psr.dfh.
234 disabled_fph_fault (struct pt_regs *regs)
236 struct ia64_psr *psr = ia64_psr(regs);
238 /* first, grant user-level access to fph partition: */
242 * Make sure that no other task gets in on this processor
243 * while we're claiming the FPU
248 struct task_struct *fpu_owner
249 = (struct task_struct *)ia64_get_kr(IA64_KR_FPU_OWNER);
251 if (ia64_is_local_fpu_owner(current)) {
252 preempt_enable_no_resched();
257 ia64_flush_fph(fpu_owner);
259 #endif /* !CONFIG_SMP */
260 ia64_set_local_fpu_owner(current);
261 if ((current->thread.flags & IA64_THREAD_FPH_VALID) != 0) {
262 __ia64_load_fpu(current->thread.fph);
267 * Set mfh because the state in thread.fph does not match the state in
272 preempt_enable_no_resched();
276 fp_emulate (int fp_fault, void *bundle, long *ipsr, long *fpsr, long *isr, long *pr, long *ifs,
277 struct pt_regs *regs)
282 if (!fpswa_interface)
285 memset(&fp_state, 0, sizeof(fp_state_t));
288 * compute fp_state. only FP registers f6 - f11 are used by the
289 * kernel, so set those bits in the mask and set the low volatile
290 * pointer to point to these registers.
292 fp_state.bitmask_low64 = 0xfc0; /* bit6..bit11 */
294 fp_state.fp_state_low_volatile = (fp_state_low_volatile_t *) ®s->f6;
296 * unsigned long (*EFI_FPSWA) (
297 * unsigned long trap_type,
299 * unsigned long *pipsr,
300 * unsigned long *pfsr,
301 * unsigned long *pisr,
302 * unsigned long *ppreds,
303 * unsigned long *pifs,
306 ret = (*fpswa_interface->fpswa)((unsigned long) fp_fault, bundle,
307 (unsigned long *) ipsr, (unsigned long *) fpsr,
308 (unsigned long *) isr, (unsigned long *) pr,
309 (unsigned long *) ifs, &fp_state);
315 * Handle floating-point assist faults and traps.
318 handle_fpu_swa (int fp_fault, struct pt_regs *regs, unsigned long isr)
320 long exception, bundle[2];
321 unsigned long fault_ip;
322 struct siginfo siginfo;
323 static int fpu_swa_count = 0;
324 static unsigned long last_time;
326 fault_ip = regs->cr_iip;
327 if (!fp_fault && (ia64_psr(regs)->ri == 0))
329 if (copy_from_user(bundle, (void __user *) fault_ip, sizeof(bundle)))
332 if (jiffies - last_time > 5*HZ)
334 if ((fpu_swa_count < 4) && !(current->thread.flags & IA64_THREAD_FPEMU_NOPRINT)) {
338 "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
339 current->comm, current->pid, regs->cr_iip + ia64_psr(regs)->ri, isr);
342 exception = fp_emulate(fp_fault, bundle, ®s->cr_ipsr, ®s->ar_fpsr, &isr, ®s->pr,
343 ®s->cr_ifs, regs);
345 if (exception == 0) {
346 /* emulation was successful */
347 ia64_increment_ip(regs);
348 } else if (exception == -1) {
349 printk(KERN_ERR "handle_fpu_swa: fp_emulate() returned -1\n");
352 /* is next instruction a trap? */
354 ia64_increment_ip(regs);
356 siginfo.si_signo = SIGFPE;
357 siginfo.si_errno = 0;
358 siginfo.si_code = __SI_FAULT; /* default code */
359 siginfo.si_addr = (void __user *) (regs->cr_iip + ia64_psr(regs)->ri);
361 siginfo.si_code = FPE_FLTINV;
362 } else if (isr & 0x22) {
363 /* denormal operand gets the same si_code as underflow
364 * see arch/i386/kernel/traps.c:math_error() */
365 siginfo.si_code = FPE_FLTUND;
366 } else if (isr & 0x44) {
367 siginfo.si_code = FPE_FLTDIV;
369 siginfo.si_isr = isr;
370 siginfo.si_flags = __ISR_VALID;
372 force_sig_info(SIGFPE, &siginfo, current);
375 if (exception == -1) {
376 printk(KERN_ERR "handle_fpu_swa: fp_emulate() returned -1\n");
378 } else if (exception != 0) {
379 /* raise exception */
380 siginfo.si_signo = SIGFPE;
381 siginfo.si_errno = 0;
382 siginfo.si_code = __SI_FAULT; /* default code */
383 siginfo.si_addr = (void __user *) (regs->cr_iip + ia64_psr(regs)->ri);
385 siginfo.si_code = FPE_FLTOVF;
386 } else if (isr & 0x1100) {
387 siginfo.si_code = FPE_FLTUND;
388 } else if (isr & 0x2200) {
389 siginfo.si_code = FPE_FLTRES;
391 siginfo.si_isr = isr;
392 siginfo.si_flags = __ISR_VALID;
394 force_sig_info(SIGFPE, &siginfo, current);
400 struct illegal_op_return {
401 unsigned long fkt, arg1, arg2, arg3;
404 struct illegal_op_return
405 ia64_illegal_op_fault (unsigned long ec, long arg1, long arg2, long arg3,
406 long arg4, long arg5, long arg6, long arg7,
409 struct illegal_op_return rv;
413 #ifdef CONFIG_IA64_BRL_EMU
415 extern struct illegal_op_return ia64_emulate_brl (struct pt_regs *, unsigned long);
417 rv = ia64_emulate_brl(®s, ec);
418 if (rv.fkt != (unsigned long) -1)
423 sprintf(buf, "IA-64 Illegal operation fault");
424 die_if_kernel(buf, ®s, 0);
426 memset(&si, 0, sizeof(si));
427 si.si_signo = SIGILL;
428 si.si_code = ILL_ILLOPC;
429 si.si_addr = (void __user *) (regs.cr_iip + ia64_psr(®s)->ri);
430 force_sig_info(SIGILL, &si, current);
436 ia64_fault (unsigned long vector, unsigned long isr, unsigned long ifa,
437 unsigned long iim, unsigned long itir, long arg5, long arg6,
438 long arg7, struct pt_regs regs)
440 unsigned long code, error = isr, iip;
441 struct siginfo siginfo;
444 static const char *reason[] = {
445 "IA-64 Illegal Operation fault",
446 "IA-64 Privileged Operation fault",
447 "IA-64 Privileged Register fault",
448 "IA-64 Reserved Register/Field fault",
449 "Disabled Instruction Set Transition fault",
450 "Unknown fault 5", "Unknown fault 6", "Unknown fault 7", "Illegal Hazard fault",
451 "Unknown fault 9", "Unknown fault 10", "Unknown fault 11", "Unknown fault 12",
452 "Unknown fault 13", "Unknown fault 14", "Unknown fault 15"
455 if ((isr & IA64_ISR_NA) && ((isr & IA64_ISR_CODE_MASK) == IA64_ISR_CODE_LFETCH)) {
457 * This fault was due to lfetch.fault, set "ed" bit in the psr to cancel
460 ia64_psr(®s)->ed = 1;
464 iip = regs.cr_iip + ia64_psr(®s)->ri;
467 case 24: /* General Exception */
468 code = (isr >> 4) & 0xf;
469 sprintf(buf, "General Exception: %s%s", reason[code],
470 (code == 3) ? ((isr & (1UL << 37))
471 ? " (RSE access)" : " (data access)") : "");
473 # ifdef CONFIG_IA64_PRINT_HAZARDS
474 printk("%s[%d]: possible hazard @ ip=%016lx (pr = %016lx)\n",
475 current->comm, current->pid,
476 regs.cr_iip + ia64_psr(®s)->ri, regs.pr);
482 case 25: /* Disabled FP-Register */
484 disabled_fph_fault(®s);
487 sprintf(buf, "Disabled FPL fault---not supposed to happen!");
490 case 26: /* NaT Consumption */
491 if (user_mode(®s)) {
494 if (((isr >> 4) & 0xf) == 2) {
495 /* NaT page consumption */
498 addr = (void __user *) ifa;
500 /* register NaT consumption */
503 addr = (void __user *) (regs.cr_iip
504 + ia64_psr(®s)->ri);
506 siginfo.si_signo = sig;
507 siginfo.si_code = code;
508 siginfo.si_errno = 0;
509 siginfo.si_addr = addr;
510 siginfo.si_imm = vector;
511 siginfo.si_flags = __ISR_VALID;
512 siginfo.si_isr = isr;
513 force_sig_info(sig, &siginfo, current);
515 } else if (ia64_done_with_exception(®s))
517 sprintf(buf, "NaT consumption");
520 case 31: /* Unsupported Data Reference */
521 if (user_mode(®s)) {
522 siginfo.si_signo = SIGILL;
523 siginfo.si_code = ILL_ILLOPN;
524 siginfo.si_errno = 0;
525 siginfo.si_addr = (void __user *) iip;
526 siginfo.si_imm = vector;
527 siginfo.si_flags = __ISR_VALID;
528 siginfo.si_isr = isr;
529 force_sig_info(SIGILL, &siginfo, current);
532 sprintf(buf, "Unsupported data reference");
536 case 35: /* Taken Branch Trap */
537 case 36: /* Single Step Trap */
538 if (fsys_mode(current, ®s)) {
539 extern char __kernel_syscall_via_break[];
541 * Got a trap in fsys-mode: Taken Branch Trap
542 * and Single Step trap need special handling;
543 * Debug trap is ignored (we disable it here
544 * and re-enable it in the lower-privilege trap).
546 if (unlikely(vector == 29)) {
547 set_thread_flag(TIF_DB_DISABLED);
548 ia64_psr(®s)->db = 0;
549 ia64_psr(®s)->lp = 1;
552 /* re-do the system call via break 0x100000: */
553 regs.cr_iip = (unsigned long) __kernel_syscall_via_break;
554 ia64_psr(®s)->ri = 0;
555 ia64_psr(®s)->cpl = 3;
560 siginfo.si_code = TRAP_HWBKPT;
561 #ifdef CONFIG_ITANIUM
563 * Erratum 10 (IFA may contain incorrect address) now has
564 * "NoFix" status. There are no plans for fixing this.
566 if (ia64_psr(®s)->is == 0)
570 case 35: siginfo.si_code = TRAP_BRANCH; ifa = 0; break;
571 case 36: siginfo.si_code = TRAP_TRACE; ifa = 0; break;
573 if (notify_die(DIE_FAULT, "ia64_fault", ®s, vector, siginfo.si_code, SIGTRAP)
576 siginfo.si_signo = SIGTRAP;
577 siginfo.si_errno = 0;
578 siginfo.si_addr = (void __user *) ifa;
580 siginfo.si_flags = __ISR_VALID;
581 siginfo.si_isr = isr;
582 force_sig_info(SIGTRAP, &siginfo, current);
585 case 32: /* fp fault */
586 case 33: /* fp trap */
587 result = handle_fpu_swa((vector == 32) ? 1 : 0, ®s, isr);
588 if ((result < 0) || (current->thread.flags & IA64_THREAD_FPEMU_SIGFPE)) {
589 siginfo.si_signo = SIGFPE;
590 siginfo.si_errno = 0;
591 siginfo.si_code = FPE_FLTINV;
592 siginfo.si_addr = (void __user *) iip;
593 siginfo.si_flags = __ISR_VALID;
594 siginfo.si_isr = isr;
596 force_sig_info(SIGFPE, &siginfo, current);
602 /* Lower-Privilege Transfer Trap */
604 /* If we disabled debug traps during an fsyscall,
605 * re-enable them here.
607 if (test_thread_flag(TIF_DB_DISABLED)) {
608 clear_thread_flag(TIF_DB_DISABLED);
609 ia64_psr(®s)->db = 1;
613 * Just clear PSR.lp and then return immediately:
614 * all the interesting work (e.g., signal delivery)
615 * is done in the kernel exit path.
617 ia64_psr(®s)->lp = 0;
620 /* Unimplemented Instr. Address Trap */
621 if (user_mode(®s)) {
622 siginfo.si_signo = SIGILL;
623 siginfo.si_code = ILL_BADIADDR;
624 siginfo.si_errno = 0;
625 siginfo.si_flags = 0;
628 siginfo.si_addr = (void __user *) iip;
629 force_sig_info(SIGILL, &siginfo, current);
632 sprintf(buf, "Unimplemented Instruction Address fault");
637 #ifdef CONFIG_IA32_SUPPORT
638 if (ia32_exception(®s, isr) == 0)
641 printk(KERN_ERR "Unexpected IA-32 exception (Trap 45)\n");
642 printk(KERN_ERR " iip - 0x%lx, ifa - 0x%lx, isr - 0x%lx\n",
644 force_sig(SIGSEGV, current);
648 #ifdef CONFIG_IA32_SUPPORT
649 if (ia32_intercept(®s, isr) == 0)
652 printk(KERN_ERR "Unexpected IA-32 intercept trap (Trap 46)\n");
653 printk(KERN_ERR " iip - 0x%lx, ifa - 0x%lx, isr - 0x%lx, iim - 0x%lx\n",
655 force_sig(SIGSEGV, current);
659 sprintf(buf, "IA-32 Interruption Fault (int 0x%lx)", isr >> 16);
663 sprintf(buf, "Fault %lu", vector);
666 die_if_kernel(buf, ®s, error);
667 force_sig(SIGILL, current);