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 */
18 #include <asm/fpswa.h>
19 #include <asm/hardirq.h>
21 #include <asm/intrinsics.h>
22 #include <asm/processor.h>
23 #include <asm/uaccess.h>
26 * fp_emulate() needs to be able to access and update all floating point registers. Those
27 * saved in pt_regs can be accessed through that structure, but those not saved, will be
28 * accessed directly. To make this work, we need to ensure that the compiler does not end
29 * up using a preserved floating point register on its own. The following achieves this
30 * by declaring preserved registers that are not marked as "fixed" as global register
34 register double f2 asm ("f2"); register double f3 asm ("f3");
35 register double f4 asm ("f4"); register double f5 asm ("f5");
37 register long f16 asm ("f16"); register long f17 asm ("f17");
38 register long f18 asm ("f18"); register long f19 asm ("f19");
39 register long f20 asm ("f20"); register long f21 asm ("f21");
40 register long f22 asm ("f22"); register long f23 asm ("f23");
42 register double f24 asm ("f24"); register double f25 asm ("f25");
43 register double f26 asm ("f26"); register double f27 asm ("f27");
44 register double f28 asm ("f28"); register double f29 asm ("f29");
45 register double f30 asm ("f30"); register double f31 asm ("f31");
48 extern spinlock_t timerlist_lock;
50 fpswa_interface_t *fpswa_interface;
51 EXPORT_SYMBOL(fpswa_interface);
56 if (ia64_boot_param->fpswa)
57 /* FPSWA fixup: make the interface pointer a kernel virtual address: */
58 fpswa_interface = __va(ia64_boot_param->fpswa);
62 * Unlock any spinlocks which will prevent us from getting the message out (timerlist_lock
63 * is acquired through the console unblank code)
66 bust_spinlocks (int yes)
68 int loglevel_save = console_loglevel;
80 * OK, the message is on the console. Now we call printk() without
81 * oops_in_progress set so that printk will give klogd a poke. Hold onto
84 console_loglevel = 15; /* NMI oopser may have shut the console up */
86 console_loglevel = loglevel_save;
90 die (const char *str, struct pt_regs *regs, long err)
97 .lock = SPIN_LOCK_UNLOCKED,
101 static int die_counter;
103 if (die.lock_owner != smp_processor_id()) {
105 spin_lock_irq(&die.lock);
106 die.lock_owner = smp_processor_id();
107 die.lock_owner_depth = 0;
111 if (++die.lock_owner_depth < 3) {
112 printk("%s[%d]: %s %ld [%d]\n",
113 current->comm, current->pid, str, err, ++die_counter);
116 printk(KERN_ERR "Recursive die() failure, output suppressed\n");
120 spin_unlock_irq(&die.lock);
125 die_if_kernel (char *str, struct pt_regs *regs, long err)
127 if (!user_mode(regs))
132 ia64_bad_break (unsigned long break_num, struct pt_regs *regs)
137 /* SIGILL, SIGFPE, SIGSEGV, and SIGBUS want these field initialized: */
138 siginfo.si_addr = (void *) (regs->cr_iip + ia64_psr(regs)->ri);
139 siginfo.si_imm = break_num;
140 siginfo.si_flags = 0; /* clear __ISR_VALID */
144 case 0: /* unknown error (used by GCC for __builtin_abort()) */
145 die_if_kernel("bugcheck!", regs, break_num);
146 sig = SIGILL; code = ILL_ILLOPC;
149 case 1: /* integer divide by zero */
150 sig = SIGFPE; code = FPE_INTDIV;
153 case 2: /* integer overflow */
154 sig = SIGFPE; code = FPE_INTOVF;
157 case 3: /* range check/bounds check */
158 sig = SIGFPE; code = FPE_FLTSUB;
161 case 4: /* null pointer dereference */
162 sig = SIGSEGV; code = SEGV_MAPERR;
165 case 5: /* misaligned data */
166 sig = SIGSEGV; code = BUS_ADRALN;
169 case 6: /* decimal overflow */
170 sig = SIGFPE; code = __FPE_DECOVF;
173 case 7: /* decimal divide by zero */
174 sig = SIGFPE; code = __FPE_DECDIV;
177 case 8: /* packed decimal error */
178 sig = SIGFPE; code = __FPE_DECERR;
181 case 9: /* invalid ASCII digit */
182 sig = SIGFPE; code = __FPE_INVASC;
185 case 10: /* invalid decimal digit */
186 sig = SIGFPE; code = __FPE_INVDEC;
189 case 11: /* paragraph stack overflow */
190 sig = SIGSEGV; code = __SEGV_PSTKOVF;
193 case 0x3f000 ... 0x3ffff: /* bundle-update in progress */
194 sig = SIGILL; code = __ILL_BNDMOD;
198 if (break_num < 0x40000 || break_num > 0x100000)
199 die_if_kernel("Bad break", regs, break_num);
201 if (break_num < 0x80000) {
202 sig = SIGILL; code = __ILL_BREAK;
204 sig = SIGTRAP; code = TRAP_BRKPT;
207 siginfo.si_signo = sig;
208 siginfo.si_errno = 0;
209 siginfo.si_code = code;
210 force_sig_info(sig, &siginfo, current);
214 * disabled_fph_fault() is called when a user-level process attempts to access f32..f127
215 * and it doesn't own the fp-high register partition. When this happens, we save the
216 * current fph partition in the task_struct of the fpu-owner (if necessary) and then load
217 * the fp-high partition of the current task (if necessary). Note that the kernel has
218 * access to fph by the time we get here, as the IVT's "Disabled FP-Register" handler takes
219 * care of clearing psr.dfh.
222 disabled_fph_fault (struct pt_regs *regs)
224 struct ia64_psr *psr = ia64_psr(regs);
226 /* first, grant user-level access to fph partition: */
230 struct task_struct *fpu_owner
231 = (struct task_struct *)ia64_get_kr(IA64_KR_FPU_OWNER);
233 if (ia64_is_local_fpu_owner(current))
237 ia64_flush_fph(fpu_owner);
239 #endif /* !CONFIG_SMP */
240 ia64_set_local_fpu_owner(current);
241 if ((current->thread.flags & IA64_THREAD_FPH_VALID) != 0) {
242 __ia64_load_fpu(current->thread.fph);
247 * Set mfh because the state in thread.fph does not match the state in
255 fp_emulate (int fp_fault, void *bundle, long *ipsr, long *fpsr, long *isr, long *pr, long *ifs,
256 struct pt_regs *regs)
261 if (!fpswa_interface)
264 memset(&fp_state, 0, sizeof(fp_state_t));
267 * compute fp_state. only FP registers f6 - f11 are used by the
268 * kernel, so set those bits in the mask and set the low volatile
269 * pointer to point to these registers.
271 fp_state.bitmask_low64 = 0xfc0; /* bit6..bit11 */
273 fp_state.fp_state_low_volatile = (fp_state_low_volatile_t *) ®s->f6;
275 * unsigned long (*EFI_FPSWA) (
276 * unsigned long trap_type,
278 * unsigned long *pipsr,
279 * unsigned long *pfsr,
280 * unsigned long *pisr,
281 * unsigned long *ppreds,
282 * unsigned long *pifs,
285 ret = (*fpswa_interface->fpswa)((unsigned long) fp_fault, bundle,
286 (unsigned long *) ipsr, (unsigned long *) fpsr,
287 (unsigned long *) isr, (unsigned long *) pr,
288 (unsigned long *) ifs, &fp_state);
294 * Handle floating-point assist faults and traps.
297 handle_fpu_swa (int fp_fault, struct pt_regs *regs, unsigned long isr)
299 long exception, bundle[2];
300 unsigned long fault_ip;
301 struct siginfo siginfo;
302 static int fpu_swa_count = 0;
303 static unsigned long last_time;
305 fault_ip = regs->cr_iip;
306 if (!fp_fault && (ia64_psr(regs)->ri == 0))
308 if (copy_from_user(bundle, (void *) fault_ip, sizeof(bundle)))
311 if (jiffies - last_time > 5*HZ)
313 if ((fpu_swa_count < 4) && !(current->thread.flags & IA64_THREAD_FPEMU_NOPRINT)) {
317 "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
318 current->comm, current->pid, regs->cr_iip + ia64_psr(regs)->ri, isr);
321 exception = fp_emulate(fp_fault, bundle, ®s->cr_ipsr, ®s->ar_fpsr, &isr, ®s->pr,
322 ®s->cr_ifs, regs);
324 if (exception == 0) {
325 /* emulation was successful */
326 ia64_increment_ip(regs);
327 } else if (exception == -1) {
328 printk(KERN_ERR "handle_fpu_swa: fp_emulate() returned -1\n");
331 /* is next instruction a trap? */
333 ia64_increment_ip(regs);
335 siginfo.si_signo = SIGFPE;
336 siginfo.si_errno = 0;
337 siginfo.si_code = __SI_FAULT; /* default code */
338 siginfo.si_addr = (void *) (regs->cr_iip + ia64_psr(regs)->ri);
340 siginfo.si_code = FPE_FLTINV;
341 } else if (isr & 0x22) {
342 /* denormal operand gets the same si_code as underflow
343 * see arch/i386/kernel/traps.c:math_error() */
344 siginfo.si_code = FPE_FLTUND;
345 } else if (isr & 0x44) {
346 siginfo.si_code = FPE_FLTDIV;
348 siginfo.si_isr = isr;
349 siginfo.si_flags = __ISR_VALID;
351 force_sig_info(SIGFPE, &siginfo, current);
354 if (exception == -1) {
355 printk(KERN_ERR "handle_fpu_swa: fp_emulate() returned -1\n");
357 } else if (exception != 0) {
358 /* raise exception */
359 siginfo.si_signo = SIGFPE;
360 siginfo.si_errno = 0;
361 siginfo.si_code = __SI_FAULT; /* default code */
362 siginfo.si_addr = (void *) (regs->cr_iip + ia64_psr(regs)->ri);
364 siginfo.si_code = FPE_FLTOVF;
365 } else if (isr & 0x1100) {
366 siginfo.si_code = FPE_FLTUND;
367 } else if (isr & 0x2200) {
368 siginfo.si_code = FPE_FLTRES;
370 siginfo.si_isr = isr;
371 siginfo.si_flags = __ISR_VALID;
373 force_sig_info(SIGFPE, &siginfo, current);
379 struct illegal_op_return {
380 unsigned long fkt, arg1, arg2, arg3;
383 struct illegal_op_return
384 ia64_illegal_op_fault (unsigned long ec, unsigned long arg1, unsigned long arg2,
385 unsigned long arg3, unsigned long arg4, unsigned long arg5,
386 unsigned long arg6, unsigned long arg7, unsigned long stack)
388 struct pt_regs *regs = (struct pt_regs *) &stack;
389 struct illegal_op_return rv;
393 #ifdef CONFIG_IA64_BRL_EMU
395 extern struct illegal_op_return ia64_emulate_brl (struct pt_regs *, unsigned long);
397 rv = ia64_emulate_brl(regs, ec);
398 if (rv.fkt != (unsigned long) -1)
403 sprintf(buf, "IA-64 Illegal operation fault");
404 die_if_kernel(buf, regs, 0);
406 memset(&si, 0, sizeof(si));
407 si.si_signo = SIGILL;
408 si.si_code = ILL_ILLOPC;
409 si.si_addr = (void *) (regs->cr_iip + ia64_psr(regs)->ri);
410 force_sig_info(SIGILL, &si, current);
416 ia64_fault (unsigned long vector, unsigned long isr, unsigned long ifa,
417 unsigned long iim, unsigned long itir, unsigned long arg5,
418 unsigned long arg6, unsigned long arg7, unsigned long stack)
420 struct pt_regs *regs = (struct pt_regs *) &stack;
421 unsigned long code, error = isr;
422 struct siginfo siginfo;
425 static const char *reason[] = {
426 "IA-64 Illegal Operation fault",
427 "IA-64 Privileged Operation fault",
428 "IA-64 Privileged Register fault",
429 "IA-64 Reserved Register/Field fault",
430 "Disabled Instruction Set Transition fault",
431 "Unknown fault 5", "Unknown fault 6", "Unknown fault 7", "Illegal Hazard fault",
432 "Unknown fault 9", "Unknown fault 10", "Unknown fault 11", "Unknown fault 12",
433 "Unknown fault 13", "Unknown fault 14", "Unknown fault 15"
436 if ((isr & IA64_ISR_NA) && ((isr & IA64_ISR_CODE_MASK) == IA64_ISR_CODE_LFETCH)) {
438 * This fault was due to lfetch.fault, set "ed" bit in the psr to cancel
441 ia64_psr(regs)->ed = 1;
446 case 24: /* General Exception */
447 code = (isr >> 4) & 0xf;
448 sprintf(buf, "General Exception: %s%s", reason[code],
449 (code == 3) ? ((isr & (1UL << 37))
450 ? " (RSE access)" : " (data access)") : "");
452 # ifdef CONFIG_IA64_PRINT_HAZARDS
453 printk("%s[%d]: possible hazard @ ip=%016lx (pr = %016lx)\n",
454 current->comm, current->pid, regs->cr_iip + ia64_psr(regs)->ri,
461 case 25: /* Disabled FP-Register */
463 disabled_fph_fault(regs);
466 sprintf(buf, "Disabled FPL fault---not supposed to happen!");
469 case 26: /* NaT Consumption */
470 if (user_mode(regs)) {
473 if (((isr >> 4) & 0xf) == 2) {
474 /* NaT page consumption */
479 /* register NaT consumption */
482 addr = (void *) (regs->cr_iip + ia64_psr(regs)->ri);
484 siginfo.si_signo = sig;
485 siginfo.si_code = code;
486 siginfo.si_errno = 0;
487 siginfo.si_addr = addr;
488 siginfo.si_imm = vector;
489 siginfo.si_flags = __ISR_VALID;
490 siginfo.si_isr = isr;
491 force_sig_info(sig, &siginfo, current);
493 } else if (ia64_done_with_exception(regs))
495 sprintf(buf, "NaT consumption");
498 case 31: /* Unsupported Data Reference */
499 if (user_mode(regs)) {
500 siginfo.si_signo = SIGILL;
501 siginfo.si_code = ILL_ILLOPN;
502 siginfo.si_errno = 0;
503 siginfo.si_addr = (void *) (regs->cr_iip + ia64_psr(regs)->ri);
504 siginfo.si_imm = vector;
505 siginfo.si_flags = __ISR_VALID;
506 siginfo.si_isr = isr;
507 force_sig_info(SIGILL, &siginfo, current);
510 sprintf(buf, "Unsupported data reference");
514 case 35: /* Taken Branch Trap */
515 case 36: /* Single Step Trap */
516 if (fsys_mode(current, regs)) {
517 extern char __kernel_syscall_via_break[];
519 * Got a trap in fsys-mode: Taken Branch Trap and Single Step trap
520 * need special handling; Debug trap is not supposed to happen.
522 if (unlikely(vector == 29)) {
523 die("Got debug trap in fsys-mode---not supposed to happen!",
527 /* re-do the system call via break 0x100000: */
528 regs->cr_iip = (unsigned long) __kernel_syscall_via_break;
529 ia64_psr(regs)->ri = 0;
530 ia64_psr(regs)->cpl = 3;
535 siginfo.si_code = TRAP_HWBKPT;
536 #ifdef CONFIG_ITANIUM
538 * Erratum 10 (IFA may contain incorrect address) now has
539 * "NoFix" status. There are no plans for fixing this.
541 if (ia64_psr(regs)->is == 0)
545 case 35: siginfo.si_code = TRAP_BRANCH; ifa = 0; break;
546 case 36: siginfo.si_code = TRAP_TRACE; ifa = 0; break;
548 siginfo.si_signo = SIGTRAP;
549 siginfo.si_errno = 0;
550 siginfo.si_addr = (void *) ifa;
552 siginfo.si_flags = __ISR_VALID;
553 siginfo.si_isr = isr;
554 force_sig_info(SIGTRAP, &siginfo, current);
557 case 32: /* fp fault */
558 case 33: /* fp trap */
559 result = handle_fpu_swa((vector == 32) ? 1 : 0, regs, isr);
560 if ((result < 0) || (current->thread.flags & IA64_THREAD_FPEMU_SIGFPE)) {
561 siginfo.si_signo = SIGFPE;
562 siginfo.si_errno = 0;
563 siginfo.si_code = FPE_FLTINV;
564 siginfo.si_addr = (void *) (regs->cr_iip + ia64_psr(regs)->ri);
565 siginfo.si_flags = __ISR_VALID;
566 siginfo.si_isr = isr;
568 force_sig_info(SIGFPE, &siginfo, current);
574 /* Lower-Privilege Transfer Trap */
576 * Just clear PSR.lp and then return immediately: all the
577 * interesting work (e.g., signal delivery is done in the kernel
580 ia64_psr(regs)->lp = 0;
583 /* Unimplemented Instr. Address Trap */
584 if (user_mode(regs)) {
585 siginfo.si_signo = SIGILL;
586 siginfo.si_code = ILL_BADIADDR;
587 siginfo.si_errno = 0;
588 siginfo.si_flags = 0;
591 siginfo.si_addr = (void *) (regs->cr_iip + ia64_psr(regs)->ri);
592 force_sig_info(SIGILL, &siginfo, current);
595 sprintf(buf, "Unimplemented Instruction Address fault");
600 #ifdef CONFIG_IA32_SUPPORT
601 if (ia32_exception(regs, isr) == 0)
604 printk(KERN_ERR "Unexpected IA-32 exception (Trap 45)\n");
605 printk(KERN_ERR " iip - 0x%lx, ifa - 0x%lx, isr - 0x%lx\n",
606 regs->cr_iip, ifa, isr);
607 force_sig(SIGSEGV, current);
611 #ifdef CONFIG_IA32_SUPPORT
612 if (ia32_intercept(regs, isr) == 0)
615 printk(KERN_ERR "Unexpected IA-32 intercept trap (Trap 46)\n");
616 printk(KERN_ERR " iip - 0x%lx, ifa - 0x%lx, isr - 0x%lx, iim - 0x%lx\n",
617 regs->cr_iip, ifa, isr, iim);
618 force_sig(SIGSEGV, current);
622 sprintf(buf, "IA-32 Interruption Fault (int 0x%lx)", isr >> 16);
626 sprintf(buf, "Fault %lu", vector);
629 die_if_kernel(buf, regs, error);
630 force_sig(SIGILL, current);