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>
19 #include <asm/fpswa.h>
21 #include <asm/intrinsics.h>
22 #include <asm/processor.h>
23 #include <asm/uaccess.h>
25 extern spinlock_t timerlist_lock;
27 fpswa_interface_t *fpswa_interface;
28 EXPORT_SYMBOL(fpswa_interface);
33 if (ia64_boot_param->fpswa)
34 /* FPSWA fixup: make the interface pointer a kernel virtual address: */
35 fpswa_interface = __va(ia64_boot_param->fpswa);
39 * Unlock any spinlocks which will prevent us from getting the message out (timerlist_lock
40 * is acquired through the console unblank code)
43 bust_spinlocks (int yes)
45 int loglevel_save = console_loglevel;
57 * OK, the message is on the console. Now we call printk() without
58 * oops_in_progress set so that printk will give klogd a poke. Hold onto
61 console_loglevel = 15; /* NMI oopser may have shut the console up */
63 console_loglevel = loglevel_save;
67 die (const char *str, struct pt_regs *regs, long err)
74 .lock = SPIN_LOCK_UNLOCKED,
78 static int die_counter;
80 if (die.lock_owner != smp_processor_id()) {
82 spin_lock_irq(&die.lock);
83 die.lock_owner = smp_processor_id();
84 die.lock_owner_depth = 0;
88 if (++die.lock_owner_depth < 3) {
89 printk("%s[%d]: %s %ld [%d]\n",
90 current->comm, current->pid, str, err, ++die_counter);
93 printk(KERN_ERR "Recursive die() failure, output suppressed\n");
97 spin_unlock_irq(&die.lock);
102 die_if_kernel (char *str, struct pt_regs *regs, long err)
104 if (!user_mode(regs))
109 ia64_bad_break (unsigned long break_num, struct pt_regs *regs)
114 /* break.b always sets cr.iim to 0, which causes problems for
115 * debuggers. Get the real break number from the original instruction,
116 * but only for kernel code. User space break.b is left alone, to
117 * preserve the existing behaviour. All break codings have the same
118 * format, so there is no need to check the slot type.
120 if (break_num == 0 && !user_mode(regs)) {
121 struct ia64_psr *ipsr = ia64_psr(regs);
122 unsigned long *bundle = (unsigned long *)regs->cr_iip;
125 case 0: slot = (bundle[0] >> 5); break;
126 case 1: slot = (bundle[0] >> 46) | (bundle[1] << 18); break;
127 default: slot = (bundle[1] >> 23); break;
129 break_num = ((slot >> 36 & 1) << 20) | (slot >> 6 & 0xfffff);
132 /* SIGILL, SIGFPE, SIGSEGV, and SIGBUS want these field initialized: */
133 siginfo.si_addr = (void __user *) (regs->cr_iip + ia64_psr(regs)->ri);
134 siginfo.si_imm = break_num;
135 siginfo.si_flags = 0; /* clear __ISR_VALID */
139 case 0: /* unknown error (used by GCC for __builtin_abort()) */
140 die_if_kernel("bugcheck!", regs, break_num);
141 sig = SIGILL; code = ILL_ILLOPC;
144 case 1: /* integer divide by zero */
145 sig = SIGFPE; code = FPE_INTDIV;
148 case 2: /* integer overflow */
149 sig = SIGFPE; code = FPE_INTOVF;
152 case 3: /* range check/bounds check */
153 sig = SIGFPE; code = FPE_FLTSUB;
156 case 4: /* null pointer dereference */
157 sig = SIGSEGV; code = SEGV_MAPERR;
160 case 5: /* misaligned data */
161 sig = SIGSEGV; code = BUS_ADRALN;
164 case 6: /* decimal overflow */
165 sig = SIGFPE; code = __FPE_DECOVF;
168 case 7: /* decimal divide by zero */
169 sig = SIGFPE; code = __FPE_DECDIV;
172 case 8: /* packed decimal error */
173 sig = SIGFPE; code = __FPE_DECERR;
176 case 9: /* invalid ASCII digit */
177 sig = SIGFPE; code = __FPE_INVASC;
180 case 10: /* invalid decimal digit */
181 sig = SIGFPE; code = __FPE_INVDEC;
184 case 11: /* paragraph stack overflow */
185 sig = SIGSEGV; code = __SEGV_PSTKOVF;
188 case 0x3f000 ... 0x3ffff: /* bundle-update in progress */
189 sig = SIGILL; code = __ILL_BNDMOD;
193 if (break_num < 0x40000 || break_num > 0x100000)
194 die_if_kernel("Bad break", regs, break_num);
196 if (break_num < 0x80000) {
197 sig = SIGILL; code = __ILL_BREAK;
199 sig = SIGTRAP; code = TRAP_BRKPT;
202 siginfo.si_signo = sig;
203 siginfo.si_errno = 0;
204 siginfo.si_code = code;
205 force_sig_info(sig, &siginfo, current);
209 * disabled_fph_fault() is called when a user-level process attempts to access f32..f127
210 * and it doesn't own the fp-high register partition. When this happens, we save the
211 * current fph partition in the task_struct of the fpu-owner (if necessary) and then load
212 * the fp-high partition of the current task (if necessary). Note that the kernel has
213 * access to fph by the time we get here, as the IVT's "Disabled FP-Register" handler takes
214 * care of clearing psr.dfh.
217 disabled_fph_fault (struct pt_regs *regs)
219 struct ia64_psr *psr = ia64_psr(regs);
221 /* first, grant user-level access to fph partition: */
225 struct task_struct *fpu_owner
226 = (struct task_struct *)ia64_get_kr(IA64_KR_FPU_OWNER);
228 if (ia64_is_local_fpu_owner(current))
232 ia64_flush_fph(fpu_owner);
234 #endif /* !CONFIG_SMP */
235 ia64_set_local_fpu_owner(current);
236 if ((current->thread.flags & IA64_THREAD_FPH_VALID) != 0) {
237 __ia64_load_fpu(current->thread.fph);
242 * Set mfh because the state in thread.fph does not match the state in
250 fp_emulate (int fp_fault, void *bundle, long *ipsr, long *fpsr, long *isr, long *pr, long *ifs,
251 struct pt_regs *regs)
256 if (!fpswa_interface)
259 memset(&fp_state, 0, sizeof(fp_state_t));
262 * compute fp_state. only FP registers f6 - f11 are used by the
263 * kernel, so set those bits in the mask and set the low volatile
264 * pointer to point to these registers.
266 fp_state.bitmask_low64 = 0xfc0; /* bit6..bit11 */
268 fp_state.fp_state_low_volatile = (fp_state_low_volatile_t *) ®s->f6;
270 * unsigned long (*EFI_FPSWA) (
271 * unsigned long trap_type,
273 * unsigned long *pipsr,
274 * unsigned long *pfsr,
275 * unsigned long *pisr,
276 * unsigned long *ppreds,
277 * unsigned long *pifs,
280 ret = (*fpswa_interface->fpswa)((unsigned long) fp_fault, bundle,
281 (unsigned long *) ipsr, (unsigned long *) fpsr,
282 (unsigned long *) isr, (unsigned long *) pr,
283 (unsigned long *) ifs, &fp_state);
289 * Handle floating-point assist faults and traps.
292 handle_fpu_swa (int fp_fault, struct pt_regs *regs, unsigned long isr)
294 long exception, bundle[2];
295 unsigned long fault_ip;
296 struct siginfo siginfo;
297 static int fpu_swa_count = 0;
298 static unsigned long last_time;
300 fault_ip = regs->cr_iip;
301 if (!fp_fault && (ia64_psr(regs)->ri == 0))
303 if (copy_from_user(bundle, (void __user *) fault_ip, sizeof(bundle)))
306 if (jiffies - last_time > 5*HZ)
308 if ((fpu_swa_count < 4) && !(current->thread.flags & IA64_THREAD_FPEMU_NOPRINT)) {
312 "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
313 current->comm, current->pid, regs->cr_iip + ia64_psr(regs)->ri, isr);
316 exception = fp_emulate(fp_fault, bundle, ®s->cr_ipsr, ®s->ar_fpsr, &isr, ®s->pr,
317 ®s->cr_ifs, regs);
319 if (exception == 0) {
320 /* emulation was successful */
321 ia64_increment_ip(regs);
322 } else if (exception == -1) {
323 printk(KERN_ERR "handle_fpu_swa: fp_emulate() returned -1\n");
326 /* is next instruction a trap? */
328 ia64_increment_ip(regs);
330 siginfo.si_signo = SIGFPE;
331 siginfo.si_errno = 0;
332 siginfo.si_code = __SI_FAULT; /* default code */
333 siginfo.si_addr = (void __user *) (regs->cr_iip + ia64_psr(regs)->ri);
335 siginfo.si_code = FPE_FLTINV;
336 } else if (isr & 0x22) {
337 /* denormal operand gets the same si_code as underflow
338 * see arch/i386/kernel/traps.c:math_error() */
339 siginfo.si_code = FPE_FLTUND;
340 } else if (isr & 0x44) {
341 siginfo.si_code = FPE_FLTDIV;
343 siginfo.si_isr = isr;
344 siginfo.si_flags = __ISR_VALID;
346 force_sig_info(SIGFPE, &siginfo, current);
349 if (exception == -1) {
350 printk(KERN_ERR "handle_fpu_swa: fp_emulate() returned -1\n");
352 } else if (exception != 0) {
353 /* raise exception */
354 siginfo.si_signo = SIGFPE;
355 siginfo.si_errno = 0;
356 siginfo.si_code = __SI_FAULT; /* default code */
357 siginfo.si_addr = (void __user *) (regs->cr_iip + ia64_psr(regs)->ri);
359 siginfo.si_code = FPE_FLTOVF;
360 } else if (isr & 0x1100) {
361 siginfo.si_code = FPE_FLTUND;
362 } else if (isr & 0x2200) {
363 siginfo.si_code = FPE_FLTRES;
365 siginfo.si_isr = isr;
366 siginfo.si_flags = __ISR_VALID;
368 force_sig_info(SIGFPE, &siginfo, current);
374 struct illegal_op_return {
375 unsigned long fkt, arg1, arg2, arg3;
378 struct illegal_op_return
379 ia64_illegal_op_fault (unsigned long ec, long arg1, long arg2, long arg3,
380 long arg4, long arg5, long arg6, long arg7,
383 struct illegal_op_return rv;
387 #ifdef CONFIG_IA64_BRL_EMU
389 extern struct illegal_op_return ia64_emulate_brl (struct pt_regs *, unsigned long);
391 rv = ia64_emulate_brl(®s, ec);
392 if (rv.fkt != (unsigned long) -1)
397 sprintf(buf, "IA-64 Illegal operation fault");
398 die_if_kernel(buf, ®s, 0);
400 memset(&si, 0, sizeof(si));
401 si.si_signo = SIGILL;
402 si.si_code = ILL_ILLOPC;
403 si.si_addr = (void __user *) (regs.cr_iip + ia64_psr(®s)->ri);
404 force_sig_info(SIGILL, &si, current);
410 ia64_fault (unsigned long vector, unsigned long isr, unsigned long ifa,
411 unsigned long iim, unsigned long itir, long arg5, long arg6,
412 long arg7, struct pt_regs regs)
414 unsigned long code, error = isr, iip;
415 struct siginfo siginfo;
418 static const char *reason[] = {
419 "IA-64 Illegal Operation fault",
420 "IA-64 Privileged Operation fault",
421 "IA-64 Privileged Register fault",
422 "IA-64 Reserved Register/Field fault",
423 "Disabled Instruction Set Transition fault",
424 "Unknown fault 5", "Unknown fault 6", "Unknown fault 7", "Illegal Hazard fault",
425 "Unknown fault 9", "Unknown fault 10", "Unknown fault 11", "Unknown fault 12",
426 "Unknown fault 13", "Unknown fault 14", "Unknown fault 15"
429 if ((isr & IA64_ISR_NA) && ((isr & IA64_ISR_CODE_MASK) == IA64_ISR_CODE_LFETCH)) {
431 * This fault was due to lfetch.fault, set "ed" bit in the psr to cancel
434 ia64_psr(®s)->ed = 1;
438 iip = regs.cr_iip + ia64_psr(®s)->ri;
441 case 24: /* General Exception */
442 code = (isr >> 4) & 0xf;
443 sprintf(buf, "General Exception: %s%s", reason[code],
444 (code == 3) ? ((isr & (1UL << 37))
445 ? " (RSE access)" : " (data access)") : "");
447 # ifdef CONFIG_IA64_PRINT_HAZARDS
448 printk("%s[%d]: possible hazard @ ip=%016lx (pr = %016lx)\n",
449 current->comm, current->pid,
450 regs.cr_iip + ia64_psr(®s)->ri, regs.pr);
456 case 25: /* Disabled FP-Register */
458 disabled_fph_fault(®s);
461 sprintf(buf, "Disabled FPL fault---not supposed to happen!");
464 case 26: /* NaT Consumption */
465 if (user_mode(®s)) {
468 if (((isr >> 4) & 0xf) == 2) {
469 /* NaT page consumption */
472 addr = (void __user *) ifa;
474 /* register NaT consumption */
477 addr = (void __user *) (regs.cr_iip
478 + ia64_psr(®s)->ri);
480 siginfo.si_signo = sig;
481 siginfo.si_code = code;
482 siginfo.si_errno = 0;
483 siginfo.si_addr = addr;
484 siginfo.si_imm = vector;
485 siginfo.si_flags = __ISR_VALID;
486 siginfo.si_isr = isr;
487 force_sig_info(sig, &siginfo, current);
489 } else if (ia64_done_with_exception(®s))
491 sprintf(buf, "NaT consumption");
494 case 31: /* Unsupported Data Reference */
495 if (user_mode(®s)) {
496 siginfo.si_signo = SIGILL;
497 siginfo.si_code = ILL_ILLOPN;
498 siginfo.si_errno = 0;
499 siginfo.si_addr = (void __user *) iip;
500 siginfo.si_imm = vector;
501 siginfo.si_flags = __ISR_VALID;
502 siginfo.si_isr = isr;
503 force_sig_info(SIGILL, &siginfo, current);
506 sprintf(buf, "Unsupported data reference");
510 case 35: /* Taken Branch Trap */
511 case 36: /* Single Step Trap */
512 if (fsys_mode(current, ®s)) {
513 extern char __kernel_syscall_via_break[];
515 * Got a trap in fsys-mode: Taken Branch Trap and Single Step trap
516 * need special handling; Debug trap is not supposed to happen.
518 if (unlikely(vector == 29)) {
519 die("Got debug trap in fsys-mode---not supposed to happen!",
523 /* re-do the system call via break 0x100000: */
524 regs.cr_iip = (unsigned long) __kernel_syscall_via_break;
525 ia64_psr(®s)->ri = 0;
526 ia64_psr(®s)->cpl = 3;
531 siginfo.si_code = TRAP_HWBKPT;
532 #ifdef CONFIG_ITANIUM
534 * Erratum 10 (IFA may contain incorrect address) now has
535 * "NoFix" status. There are no plans for fixing this.
537 if (ia64_psr(®s)->is == 0)
541 case 35: siginfo.si_code = TRAP_BRANCH; ifa = 0; break;
542 case 36: siginfo.si_code = TRAP_TRACE; ifa = 0; break;
544 siginfo.si_signo = SIGTRAP;
545 siginfo.si_errno = 0;
546 siginfo.si_addr = (void __user *) ifa;
548 siginfo.si_flags = __ISR_VALID;
549 siginfo.si_isr = isr;
550 force_sig_info(SIGTRAP, &siginfo, current);
553 case 32: /* fp fault */
554 case 33: /* fp trap */
555 result = handle_fpu_swa((vector == 32) ? 1 : 0, ®s, isr);
556 if ((result < 0) || (current->thread.flags & IA64_THREAD_FPEMU_SIGFPE)) {
557 siginfo.si_signo = SIGFPE;
558 siginfo.si_errno = 0;
559 siginfo.si_code = FPE_FLTINV;
560 siginfo.si_addr = (void __user *) iip;
561 siginfo.si_flags = __ISR_VALID;
562 siginfo.si_isr = isr;
564 force_sig_info(SIGFPE, &siginfo, current);
570 /* Lower-Privilege Transfer Trap */
572 * Just clear PSR.lp and then return immediately: all the
573 * interesting work (e.g., signal delivery is done in the kernel
576 ia64_psr(®s)->lp = 0;
579 /* Unimplemented Instr. Address Trap */
580 if (user_mode(®s)) {
581 siginfo.si_signo = SIGILL;
582 siginfo.si_code = ILL_BADIADDR;
583 siginfo.si_errno = 0;
584 siginfo.si_flags = 0;
587 siginfo.si_addr = (void __user *) iip;
588 force_sig_info(SIGILL, &siginfo, current);
591 sprintf(buf, "Unimplemented Instruction Address fault");
596 #ifdef CONFIG_IA32_SUPPORT
597 if (ia32_exception(®s, isr) == 0)
600 printk(KERN_ERR "Unexpected IA-32 exception (Trap 45)\n");
601 printk(KERN_ERR " iip - 0x%lx, ifa - 0x%lx, isr - 0x%lx\n",
603 force_sig(SIGSEGV, current);
607 #ifdef CONFIG_IA32_SUPPORT
608 if (ia32_intercept(®s, isr) == 0)
611 printk(KERN_ERR "Unexpected IA-32 intercept trap (Trap 46)\n");
612 printk(KERN_ERR " iip - 0x%lx, ifa - 0x%lx, isr - 0x%lx, iim - 0x%lx\n",
614 force_sig(SIGSEGV, current);
618 sprintf(buf, "IA-32 Interruption Fault (int 0x%lx)", isr >> 16);
622 sprintf(buf, "Fault %lu", vector);
625 die_if_kernel(buf, ®s, error);
626 force_sig(SIGILL, current);