2 * linux/arch/x86-64/traps.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
7 * Pentium III FXSR, SSE support
8 * Gareth Hughes <gareth@valinux.com>, May 2000
10 * $Id: traps.c,v 1.36 2002/03/24 11:09:10 ak Exp $
14 * 'Traps.c' handles hardware traps and faults after we have saved some
17 #include <linux/config.h>
18 #include <linux/sched.h>
19 #include <linux/kernel.h>
20 #include <linux/string.h>
21 #include <linux/errno.h>
22 #include <linux/ptrace.h>
23 #include <linux/timer.h>
25 #include <linux/init.h>
26 #include <linux/delay.h>
27 #include <linux/spinlock.h>
28 #include <linux/interrupt.h>
29 #include <linux/module.h>
30 #include <linux/moduleparam.h>
31 #include <linux/nmi.h>
32 #include <linux/kprobes.h>
33 #include <linux/kexec.h>
35 #include <asm/system.h>
36 #include <asm/uaccess.h>
38 #include <asm/atomic.h>
39 #include <asm/debugreg.h>
42 #include <asm/kdebug.h>
43 #include <asm/processor.h>
46 #include <asm/pgalloc.h>
48 #include <asm/proto.h>
51 asmlinkage void divide_error(void);
52 asmlinkage void debug(void);
53 asmlinkage void nmi(void);
54 asmlinkage void int3(void);
55 asmlinkage void overflow(void);
56 asmlinkage void bounds(void);
57 asmlinkage void invalid_op(void);
58 asmlinkage void device_not_available(void);
59 asmlinkage void double_fault(void);
60 asmlinkage void coprocessor_segment_overrun(void);
61 asmlinkage void invalid_TSS(void);
62 asmlinkage void segment_not_present(void);
63 asmlinkage void stack_segment(void);
64 asmlinkage void general_protection(void);
65 asmlinkage void page_fault(void);
66 asmlinkage void coprocessor_error(void);
67 asmlinkage void simd_coprocessor_error(void);
68 asmlinkage void reserved(void);
69 asmlinkage void alignment_check(void);
70 asmlinkage void machine_check(void);
71 asmlinkage void spurious_interrupt_bug(void);
73 ATOMIC_NOTIFIER_HEAD(die_chain);
75 int register_die_notifier(struct notifier_block *nb)
78 return atomic_notifier_chain_register(&die_chain, nb);
80 EXPORT_SYMBOL(register_die_notifier);
82 int unregister_die_notifier(struct notifier_block *nb)
84 return atomic_notifier_chain_unregister(&die_chain, nb);
86 EXPORT_SYMBOL(unregister_die_notifier);
88 static inline void conditional_sti(struct pt_regs *regs)
90 if (regs->eflags & X86_EFLAGS_IF)
94 static inline void preempt_conditional_sti(struct pt_regs *regs)
97 if (regs->eflags & X86_EFLAGS_IF)
101 static inline void preempt_conditional_cli(struct pt_regs *regs)
103 if (regs->eflags & X86_EFLAGS_IF)
105 preempt_enable_no_resched();
108 static int kstack_depth_to_print = 10;
110 #ifdef CONFIG_KALLSYMS
111 #include <linux/kallsyms.h>
112 int printk_address(unsigned long address)
114 unsigned long offset = 0, symsize;
120 symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
122 return printk("[<%016lx>]", address);
124 modname = delim = "";
125 return printk("<%016lx>{%s%s%s%s%+ld}",
126 address, delim, modname, delim, symname, offset);
129 int printk_address(unsigned long address)
131 return printk("[<%016lx>]", address);
135 static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack,
136 unsigned *usedp, const char **idp)
138 #ifndef CONFIG_X86_NO_TSS
139 static char ids[][8] = {
140 [DEBUG_STACK - 1] = "#DB",
141 [NMI_STACK - 1] = "NMI",
142 [DOUBLEFAULT_STACK - 1] = "#DF",
143 [STACKFAULT_STACK - 1] = "#SS",
144 [MCE_STACK - 1] = "#MC",
145 #if DEBUG_STKSZ > EXCEPTION_STKSZ
146 [N_EXCEPTION_STACKS ... N_EXCEPTION_STACKS + DEBUG_STKSZ / EXCEPTION_STKSZ - 2] = "#DB[?]"
151 for (k = 0; k < N_EXCEPTION_STACKS; k++) {
155 #if DEBUG_STKSZ > EXCEPTION_STKSZ
157 end = cpu_pda(cpu)->debugstack + DEBUG_STKSZ;
161 end = per_cpu(init_tss, cpu).ist[k];
166 if (stack >= end - EXCEPTION_STKSZ) {
167 if (*usedp & (1U << k))
171 return (unsigned long *)end;
173 #if DEBUG_STKSZ > EXCEPTION_STKSZ
174 if (k == DEBUG_STACK - 1 && stack >= end - DEBUG_STKSZ) {
175 unsigned j = N_EXCEPTION_STACKS - 1;
179 end -= EXCEPTION_STKSZ;
180 ids[j][4] = '1' + (j - N_EXCEPTION_STACKS);
181 } while (stack < end - EXCEPTION_STKSZ);
182 if (*usedp & (1U << j))
186 return (unsigned long *)end;
195 * x86-64 can have upto three kernel stacks:
198 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
201 void show_trace(unsigned long *stack)
203 const unsigned cpu = safe_smp_processor_id();
204 unsigned long *irqstack_end = (unsigned long *)cpu_pda(cpu)->irqstackptr;
208 printk("\nCall Trace:");
210 #define HANDLE_STACK(cond) \
212 unsigned long addr = *stack++; \
213 if (kernel_text_address(addr)) { \
221 * If the address is either in the text segment of the \
222 * kernel, or in the region which contains vmalloc'ed \
223 * memory, it *may* be the address of a calling \
224 * routine; if so, print it so that someone tracing \
225 * down the cause of the crash will be able to figure \
226 * out the call path that was taken. \
228 i += printk_address(addr); \
234 unsigned long *estack_end;
235 estack_end = in_exception_stack(cpu, (unsigned long)stack,
239 i += printk(" <%s>", id);
240 HANDLE_STACK (stack < estack_end);
241 i += printk(" <EOE>");
242 stack = (unsigned long *) estack_end[-2];
246 unsigned long *irqstack;
247 irqstack = irqstack_end -
248 (IRQSTACKSIZE - 64) / sizeof(*irqstack);
250 if (stack >= irqstack && stack < irqstack_end) {
251 i += printk(" <IRQ>");
252 HANDLE_STACK (stack < irqstack_end);
253 stack = (unsigned long *) (irqstack_end[-1]);
255 i += printk(" <EOI>");
262 HANDLE_STACK (((long) stack & (THREAD_SIZE-1)) != 0);
267 void show_stack(struct task_struct *tsk, unsigned long * rsp)
269 unsigned long *stack;
271 const int cpu = safe_smp_processor_id();
272 unsigned long *irqstack_end = (unsigned long *) (cpu_pda(cpu)->irqstackptr);
273 unsigned long *irqstack = (unsigned long *) (cpu_pda(cpu)->irqstackptr - IRQSTACKSIZE);
275 // debugging aid: "show_stack(NULL, NULL);" prints the
276 // back trace for this cpu.
280 rsp = (unsigned long *)tsk->thread.rsp;
282 rsp = (unsigned long *)&rsp;
286 for(i=0; i < kstack_depth_to_print; i++) {
287 if (stack >= irqstack && stack <= irqstack_end) {
288 if (stack == irqstack_end) {
289 stack = (unsigned long *) (irqstack_end[-1]);
293 if (((long) stack & (THREAD_SIZE-1)) == 0)
296 if (i && ((i % 4) == 0))
298 printk("%016lx ", *stack++);
299 touch_nmi_watchdog();
301 show_trace((unsigned long *)rsp);
305 * The architecture-independent dump_stack generator
307 void dump_stack(void)
313 EXPORT_SYMBOL(dump_stack);
315 void show_registers(struct pt_regs *regs)
318 int in_kernel = !user_mode(regs);
320 const int cpu = safe_smp_processor_id();
321 struct task_struct *cur = cpu_pda(cpu)->pcurrent;
325 printk("CPU %d ", cpu);
327 printk("Process %s (pid: %d, threadinfo %p, task %p)\n",
328 cur->comm, cur->pid, task_thread_info(cur), cur);
331 * When in-kernel, we also print out the stack and code at the
332 * time of the fault..
337 show_stack(NULL, (unsigned long*)rsp);
340 if (regs->rip < PAGE_OFFSET)
343 for (i=0; i<20; i++) {
345 if (__get_user(c, &((unsigned char*)regs->rip)[i])) {
347 printk(" Bad RIP value.");
356 void handle_BUG(struct pt_regs *regs)
360 const char *prefix = "";
364 if (__copy_from_user(&f, (const void __user *) regs->rip,
365 sizeof(struct bug_frame)))
367 if (f.filename >= 0 ||
368 f.ud2[0] != 0x0f || f.ud2[1] != 0x0b)
370 len = __strnlen_user((char *)(long)f.filename, PATH_MAX) - 1;
371 if (len < 0 || len >= PATH_MAX)
372 f.filename = (int)(long)"unmapped filename";
374 f.filename += len - 50;
377 printk("----------- [cut here ] --------- [please bite here ] ---------\n");
378 printk(KERN_ALERT "Kernel BUG at %s%.50s:%d\n", prefix, (char *)(long)f.filename, f.line);
382 void out_of_line_bug(void)
388 static DEFINE_SPINLOCK(die_lock);
389 static int die_owner = -1;
390 static unsigned int die_nest_count;
392 unsigned __kprobes long oops_begin(void)
394 int cpu = safe_smp_processor_id();
397 /* racy, but better than risking deadlock. */
398 local_irq_save(flags);
399 if (!spin_trylock(&die_lock)) {
400 if (cpu == die_owner)
401 /* nested oops. should stop eventually */;
403 spin_lock(&die_lock);
412 void __kprobes oops_end(unsigned long flags)
418 /* We still own the lock */
419 local_irq_restore(flags);
421 /* Nest count reaches zero, release the lock. */
422 spin_unlock_irqrestore(&die_lock, flags);
427 void __kprobes __die(const char * str, struct pt_regs * regs, long err)
429 static int die_counter;
430 printk(KERN_EMERG "%s: %04lx [%u] ", str, err & 0xffff,++die_counter);
431 #ifdef CONFIG_PREEMPT
437 #ifdef CONFIG_DEBUG_PAGEALLOC
438 printk("DEBUG_PAGEALLOC");
441 notify_die(DIE_OOPS, str, regs, err, current->thread.trap_no, SIGSEGV);
442 show_registers(regs);
443 /* Executive summary in case the oops scrolled away */
444 printk(KERN_ALERT "RIP ");
445 printk_address(regs->rip);
446 printk(" RSP <%016lx>\n", regs->rsp);
447 if (kexec_should_crash(current))
451 void die(const char * str, struct pt_regs * regs, long err)
453 unsigned long flags = oops_begin();
456 __die(str, regs, err);
461 #ifdef CONFIG_X86_LOCAL_APIC
462 void __kprobes die_nmi(char *str, struct pt_regs *regs)
464 unsigned long flags = oops_begin();
467 * We are in trouble anyway, lets at least try
468 * to get a message out.
470 printk(str, safe_smp_processor_id());
471 show_registers(regs);
472 if (kexec_should_crash(current))
474 if (panic_on_timeout || panic_on_oops)
475 panic("nmi watchdog");
476 printk("console shuts up ...\n");
484 static void __kprobes do_trap(int trapnr, int signr, char *str,
485 struct pt_regs * regs, long error_code,
488 struct task_struct *tsk = current;
490 conditional_sti(regs);
492 tsk->thread.error_code = error_code;
493 tsk->thread.trap_no = trapnr;
495 if (user_mode(regs)) {
496 if (exception_trace && unhandled_signal(tsk, signr))
498 "%s[%d] trap %s rip:%lx rsp:%lx error:%lx\n",
499 tsk->comm, tsk->pid, str,
500 regs->rip, regs->rsp, error_code);
503 force_sig_info(signr, info, tsk);
505 force_sig(signr, tsk);
512 const struct exception_table_entry *fixup;
513 fixup = search_exception_tables(regs->rip);
515 regs->rip = fixup->fixup;
517 die(str, regs, error_code);
522 #define DO_ERROR(trapnr, signr, str, name) \
523 asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
525 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
528 do_trap(trapnr, signr, str, regs, error_code, NULL); \
531 #define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
532 asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
535 info.si_signo = signr; \
537 info.si_code = sicode; \
538 info.si_addr = (void __user *)siaddr; \
539 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
542 do_trap(trapnr, signr, str, regs, error_code, &info); \
545 DO_ERROR_INFO( 0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->rip)
546 DO_ERROR( 4, SIGSEGV, "overflow", overflow)
547 DO_ERROR( 5, SIGSEGV, "bounds", bounds)
548 DO_ERROR_INFO( 6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->rip)
549 DO_ERROR( 7, SIGSEGV, "device not available", device_not_available)
550 DO_ERROR( 9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
551 DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
552 DO_ERROR(11, SIGBUS, "segment not present", segment_not_present)
553 DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0)
554 DO_ERROR(18, SIGSEGV, "reserved", reserved)
555 DO_ERROR(12, SIGBUS, "stack segment", stack_segment)
557 asmlinkage void do_double_fault(struct pt_regs * regs, long error_code)
559 static const char str[] = "double fault";
560 struct task_struct *tsk = current;
562 /* Return not checked because double check cannot be ignored */
563 notify_die(DIE_TRAP, str, regs, error_code, 8, SIGSEGV);
565 tsk->thread.error_code = error_code;
566 tsk->thread.trap_no = 8;
568 /* This is always a kernel trap and never fixable (and thus must
571 die(str, regs, error_code);
574 asmlinkage void __kprobes do_general_protection(struct pt_regs * regs,
577 struct task_struct *tsk = current;
579 conditional_sti(regs);
581 tsk->thread.error_code = error_code;
582 tsk->thread.trap_no = 13;
584 if (user_mode(regs)) {
585 if (exception_trace && unhandled_signal(tsk, SIGSEGV))
587 "%s[%d] general protection rip:%lx rsp:%lx error:%lx\n",
589 regs->rip, regs->rsp, error_code);
591 force_sig(SIGSEGV, tsk);
597 const struct exception_table_entry *fixup;
598 fixup = search_exception_tables(regs->rip);
600 regs->rip = fixup->fixup;
603 if (notify_die(DIE_GPF, "general protection fault", regs,
604 error_code, 13, SIGSEGV) == NOTIFY_STOP)
606 die("general protection fault", regs, error_code);
610 static __kprobes void
611 mem_parity_error(unsigned char reason, struct pt_regs * regs)
613 printk("Uhhuh. NMI received. Dazed and confused, but trying to continue\n");
614 printk("You probably have a hardware problem with your RAM chips\n");
617 /* Clear and disable the memory parity error line. */
618 reason = (reason & 0xf) | 4;
623 static __kprobes void
624 io_check_error(unsigned char reason, struct pt_regs * regs)
626 printk("NMI: IOCK error (debug interrupt?)\n");
627 show_registers(regs);
630 /* Re-enable the IOCK line, wait for a few seconds */
631 reason = (reason & 0xf) | 8;
639 static __kprobes void
640 unknown_nmi_error(unsigned char reason, struct pt_regs * regs)
641 { printk("Uhhuh. NMI received for unknown reason %02x.\n", reason);
642 printk("Dazed and confused, but trying to continue\n");
643 printk("Do you have a strange power saving mode enabled?\n");
646 /* Runs on IST stack. This code must keep interrupts off all the time.
647 Nested NMIs are prevented by the CPU. */
648 asmlinkage __kprobes void default_do_nmi(struct pt_regs *regs)
650 unsigned char reason = 0;
653 cpu = smp_processor_id();
655 /* Only the BSP gets external NMIs from the system. */
657 reason = get_nmi_reason();
659 if (!(reason & 0xc0)) {
660 if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT)
663 #ifdef CONFIG_X86_LOCAL_APIC
665 * Ok, so this is none of the documented NMI sources,
666 * so it must be the NMI watchdog.
668 if (nmi_watchdog > 0) {
669 nmi_watchdog_tick(regs,reason);
673 unknown_nmi_error(reason, regs);
676 if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP)
679 /* AK: following checks seem to be broken on modern chipsets. FIXME */
682 mem_parity_error(reason, regs);
684 io_check_error(reason, regs);
687 /* runs on IST stack. */
688 asmlinkage void __kprobes do_int3(struct pt_regs * regs, long error_code)
690 if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP) == NOTIFY_STOP) {
693 do_trap(3, SIGTRAP, "int3", regs, error_code, NULL);
697 /* Help handler running on IST stack to switch back to user stack
698 for scheduling or signal handling. The actual stack switch is done in
700 asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs)
702 struct pt_regs *regs = eregs;
703 /* Did already sync */
704 if (eregs == (struct pt_regs *)eregs->rsp)
706 /* Exception from user space */
707 else if (user_mode(eregs))
708 regs = task_pt_regs(current);
709 /* Exception from kernel and interrupts are enabled. Move to
710 kernel process stack. */
711 else if (eregs->eflags & X86_EFLAGS_IF)
712 regs = (struct pt_regs *)(eregs->rsp -= sizeof(struct pt_regs));
718 /* runs on IST stack. */
719 asmlinkage void __kprobes do_debug(struct pt_regs * regs,
720 unsigned long error_code)
722 unsigned long condition;
723 struct task_struct *tsk = current;
726 get_debugreg(condition, 6);
728 if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code,
729 SIGTRAP) == NOTIFY_STOP)
732 preempt_conditional_sti(regs);
734 /* Mask out spurious debug traps due to lazy DR7 setting */
735 if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) {
736 if (!tsk->thread.debugreg7) {
741 tsk->thread.debugreg6 = condition;
743 /* Mask out spurious TF errors due to lazy TF clearing */
744 if (condition & DR_STEP) {
746 * The TF error should be masked out only if the current
747 * process is not traced and if the TRAP flag has been set
748 * previously by a tracing process (condition detected by
749 * the PT_DTRACE flag); remember that the i386 TRAP flag
750 * can be modified by the process itself in user mode,
751 * allowing programs to debug themselves without the ptrace()
754 if (!user_mode(regs))
755 goto clear_TF_reenable;
757 * Was the TF flag set by a debugger? If so, clear it now,
758 * so that register information is correct.
760 if (tsk->ptrace & PT_DTRACE) {
761 regs->eflags &= ~TF_MASK;
762 tsk->ptrace &= ~PT_DTRACE;
766 /* Ok, finally something we can handle */
767 tsk->thread.trap_no = 1;
768 tsk->thread.error_code = error_code;
769 info.si_signo = SIGTRAP;
771 info.si_code = TRAP_BRKPT;
772 info.si_addr = user_mode(regs) ? (void __user *)regs->rip : NULL;
773 force_sig_info(SIGTRAP, &info, tsk);
776 set_debugreg(0UL, 7);
777 preempt_conditional_cli(regs);
781 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
782 regs->eflags &= ~TF_MASK;
783 preempt_conditional_cli(regs);
786 static int kernel_math_error(struct pt_regs *regs, const char *str, int trapnr)
788 const struct exception_table_entry *fixup;
789 fixup = search_exception_tables(regs->rip);
791 regs->rip = fixup->fixup;
794 notify_die(DIE_GPF, str, regs, 0, trapnr, SIGFPE);
795 /* Illegal floating point operation in the kernel */
796 current->thread.trap_no = trapnr;
802 * Note that we play around with the 'TS' bit in an attempt to get
803 * the correct behaviour even in the presence of the asynchronous
806 asmlinkage void do_coprocessor_error(struct pt_regs *regs)
808 void __user *rip = (void __user *)(regs->rip);
809 struct task_struct * task;
811 unsigned short cwd, swd;
813 conditional_sti(regs);
814 if (!user_mode(regs) &&
815 kernel_math_error(regs, "kernel x87 math error", 16))
819 * Save the info for the exception handler and clear the error.
823 task->thread.trap_no = 16;
824 task->thread.error_code = 0;
825 info.si_signo = SIGFPE;
827 info.si_code = __SI_FAULT;
830 * (~cwd & swd) will mask out exceptions that are not set to unmasked
831 * status. 0x3f is the exception bits in these regs, 0x200 is the
832 * C1 reg you need in case of a stack fault, 0x040 is the stack
833 * fault bit. We should only be taking one exception at a time,
834 * so if this combination doesn't produce any single exception,
835 * then we have a bad program that isn't synchronizing its FPU usage
836 * and it will suffer the consequences since we won't be able to
837 * fully reproduce the context of the exception
839 cwd = get_fpu_cwd(task);
840 swd = get_fpu_swd(task);
841 switch (swd & ~cwd & 0x3f) {
845 case 0x001: /* Invalid Op */
847 * swd & 0x240 == 0x040: Stack Underflow
848 * swd & 0x240 == 0x240: Stack Overflow
849 * User must clear the SF bit (0x40) if set
851 info.si_code = FPE_FLTINV;
853 case 0x002: /* Denormalize */
854 case 0x010: /* Underflow */
855 info.si_code = FPE_FLTUND;
857 case 0x004: /* Zero Divide */
858 info.si_code = FPE_FLTDIV;
860 case 0x008: /* Overflow */
861 info.si_code = FPE_FLTOVF;
863 case 0x020: /* Precision */
864 info.si_code = FPE_FLTRES;
867 force_sig_info(SIGFPE, &info, task);
870 asmlinkage void bad_intr(void)
872 printk("bad interrupt");
875 asmlinkage void do_simd_coprocessor_error(struct pt_regs *regs)
877 void __user *rip = (void __user *)(regs->rip);
878 struct task_struct * task;
880 unsigned short mxcsr;
882 conditional_sti(regs);
883 if (!user_mode(regs) &&
884 kernel_math_error(regs, "kernel simd math error", 19))
888 * Save the info for the exception handler and clear the error.
892 task->thread.trap_no = 19;
893 task->thread.error_code = 0;
894 info.si_signo = SIGFPE;
896 info.si_code = __SI_FAULT;
899 * The SIMD FPU exceptions are handled a little differently, as there
900 * is only a single status/control register. Thus, to determine which
901 * unmasked exception was caught we must mask the exception mask bits
902 * at 0x1f80, and then use these to mask the exception bits at 0x3f.
904 mxcsr = get_fpu_mxcsr(task);
905 switch (~((mxcsr & 0x1f80) >> 7) & (mxcsr & 0x3f)) {
909 case 0x001: /* Invalid Op */
910 info.si_code = FPE_FLTINV;
912 case 0x002: /* Denormalize */
913 case 0x010: /* Underflow */
914 info.si_code = FPE_FLTUND;
916 case 0x004: /* Zero Divide */
917 info.si_code = FPE_FLTDIV;
919 case 0x008: /* Overflow */
920 info.si_code = FPE_FLTOVF;
922 case 0x020: /* Precision */
923 info.si_code = FPE_FLTRES;
926 force_sig_info(SIGFPE, &info, task);
929 asmlinkage void do_spurious_interrupt_bug(struct pt_regs * regs)
934 asmlinkage void __attribute__((weak)) smp_thermal_interrupt(void)
939 asmlinkage void __attribute__((weak)) mce_threshold_interrupt(void)
944 * 'math_state_restore()' saves the current math information in the
945 * old math state array, and gets the new ones from the current task
947 * Careful.. There are problems with IBM-designed IRQ13 behaviour.
948 * Don't touch unless you *really* know how it works.
950 asmlinkage void math_state_restore(void)
952 struct task_struct *me = current;
953 /* clts(); */ /* 'clts' is done for us by Xen during virtual trap. */
957 restore_fpu_checking(&me->thread.i387.fxsave);
958 task_thread_info(me)->status |= TS_USEDFPU;
963 * NB. All these are "interrupt gates" (i.e. events_mask is set) because we
964 * specify <dpl>|4 in the second field.
966 static trap_info_t trap_table[] = {
967 { 0, 0|4, __KERNEL_CS, (unsigned long)divide_error },
968 { 1, 0|4, __KERNEL_CS, (unsigned long)debug },
969 { 3, 3|4, __KERNEL_CS, (unsigned long)int3 },
970 { 4, 3|4, __KERNEL_CS, (unsigned long)overflow },
971 { 5, 0|4, __KERNEL_CS, (unsigned long)bounds },
972 { 6, 0|4, __KERNEL_CS, (unsigned long)invalid_op },
973 { 7, 0|4, __KERNEL_CS, (unsigned long)device_not_available },
974 { 9, 0|4, __KERNEL_CS, (unsigned long)coprocessor_segment_overrun},
975 { 10, 0|4, __KERNEL_CS, (unsigned long)invalid_TSS },
976 { 11, 0|4, __KERNEL_CS, (unsigned long)segment_not_present },
977 { 12, 0|4, __KERNEL_CS, (unsigned long)stack_segment },
978 { 13, 0|4, __KERNEL_CS, (unsigned long)general_protection },
979 { 14, 0|4, __KERNEL_CS, (unsigned long)page_fault },
980 { 15, 0|4, __KERNEL_CS, (unsigned long)spurious_interrupt_bug },
981 { 16, 0|4, __KERNEL_CS, (unsigned long)coprocessor_error },
982 { 17, 0|4, __KERNEL_CS, (unsigned long)alignment_check },
983 #ifdef CONFIG_X86_MCE
984 { 18, 0|4, __KERNEL_CS, (unsigned long)machine_check },
986 { 19, 0|4, __KERNEL_CS, (unsigned long)simd_coprocessor_error },
987 #ifdef CONFIG_IA32_EMULATION
988 { IA32_SYSCALL_VECTOR, 3|4, __KERNEL_CS, (unsigned long)ia32_syscall},
993 void __init trap_init(void)
997 ret = HYPERVISOR_set_trap_table(trap_table);
1000 printk("HYPERVISOR_set_trap_table faild: error %d\n",
1004 * Should be a barrier for any external CPU state.
1009 void smp_trap_init(trap_info_t *trap_ctxt)
1011 trap_info_t *t = trap_table;
1013 for (t = trap_table; t->address; t++) {
1014 trap_ctxt[t->vector].flags = t->flags;
1015 trap_ctxt[t->vector].cs = t->cs;
1016 trap_ctxt[t->vector].address = t->address;
1021 /* Actual parsing is done early in setup.c. */
1022 static int __init oops_dummy(char *s)
1027 __setup("oops=", oops_dummy);
1029 static int __init kstack_setup(char *s)
1031 kstack_depth_to_print = simple_strtoul(s,NULL,0);
1034 __setup("kstack=", kstack_setup);