2 * Copyright (C) 1991,1992 Linus Torvalds
4 * entry_32.S contains the system-call and low-level fault and trap handling routines.
6 * Stack layout while running C code:
7 * ptrace needs to have all registers on the stack.
8 * If the order here is changed, it needs to be
9 * updated in fork.c:copy_process(), signal.c:do_signal(),
10 * ptrace.c and ptrace.h
22 * 28(%esp) - %gs saved iff !CONFIG_X86_32_LAZY_GS
31 #include <linux/linkage.h>
32 #include <linux/err.h>
33 #include <asm/thread_info.h>
34 #include <asm/irqflags.h>
35 #include <asm/errno.h>
36 #include <asm/segment.h>
38 #include <asm/page_types.h>
39 #include <asm/percpu.h>
40 #include <asm/processor-flags.h>
41 #include <asm/ftrace.h>
42 #include <asm/irq_vectors.h>
43 #include <asm/cpufeatures.h>
44 #include <asm/alternative-asm.h>
48 .section .entry.text, "ax"
51 * We use macros for low-level operations which need to be overridden
52 * for paravirtualization. The following will never clobber any registers:
53 * INTERRUPT_RETURN (aka. "iret")
54 * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
55 * ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
57 * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
58 * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
59 * Allowing a register to be clobbered can shrink the paravirt replacement
60 * enough to patch inline, increasing performance.
64 # define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
66 # define preempt_stop(clobbers)
67 # define resume_kernel restore_all
70 .macro TRACE_IRQS_IRET
71 #ifdef CONFIG_TRACE_IRQFLAGS
72 testl $X86_EFLAGS_IF, PT_EFLAGS(%esp) # interrupts off?
80 * User gs save/restore
82 * %gs is used for userland TLS and kernel only uses it for stack
83 * canary which is required to be at %gs:20 by gcc. Read the comment
84 * at the top of stackprotector.h for more info.
86 * Local labels 98 and 99 are used.
88 #ifdef CONFIG_X86_32_LAZY_GS
90 /* unfortunately push/pop can't be no-op */
95 addl $(4 + \pop), %esp
100 /* all the rest are no-op */
107 .macro REG_TO_PTGS reg
109 .macro SET_KERNEL_GS reg
112 #else /* CONFIG_X86_32_LAZY_GS */
125 .pushsection .fixup, "ax"
129 _ASM_EXTABLE(98b, 99b)
133 98: mov PT_GS(%esp), %gs
136 .pushsection .fixup, "ax"
137 99: movl $0, PT_GS(%esp)
140 _ASM_EXTABLE(98b, 99b)
146 .macro REG_TO_PTGS reg
147 movl \reg, PT_GS(%esp)
149 .macro SET_KERNEL_GS reg
150 movl $(__KERNEL_STACK_CANARY), \reg
154 #endif /* CONFIG_X86_32_LAZY_GS */
156 .macro SAVE_ALL pt_regs_ax=%eax
169 movl $(__USER_DS), %edx
172 movl $(__KERNEL_PERCPU), %edx
177 .macro RESTORE_INT_REGS
187 .macro RESTORE_REGS pop=0
193 .pushsection .fixup, "ax"
210 GET_THREAD_INFO(%ebp)
212 pushl $0x0202 # Reset kernel eflags
215 /* When we fork, we trace the syscall return in the child, too. */
217 call syscall_return_slowpath
221 ENTRY(ret_from_kernel_thread)
224 GET_THREAD_INFO(%ebp)
226 pushl $0x0202 # Reset kernel eflags
228 movl PT_EBP(%esp), %eax
230 movl $0, PT_EAX(%esp)
233 * Kernel threads return to userspace as if returning from a syscall.
234 * We should check whether anything actually uses this path and, if so,
235 * consider switching it over to ret_from_fork.
238 call syscall_return_slowpath
240 ENDPROC(ret_from_kernel_thread)
243 * Return to user mode is not as complex as all this looks,
244 * but we want the default path for a system call return to
245 * go as quickly as possible which is why some of this is
246 * less clear than it otherwise should be.
249 # userspace resumption stub bypassing syscall exit tracing
252 preempt_stop(CLBR_ANY)
254 GET_THREAD_INFO(%ebp)
256 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
257 movb PT_CS(%esp), %al
258 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
261 * We can be coming here from child spawned by kernel_thread().
263 movl PT_CS(%esp), %eax
264 andl $SEGMENT_RPL_MASK, %eax
267 jb resume_kernel # not returning to v8086 or userspace
269 ENTRY(resume_userspace)
270 DISABLE_INTERRUPTS(CLBR_ANY)
273 call prepare_exit_to_usermode
275 END(ret_from_exception)
277 #ifdef CONFIG_PREEMPT
279 DISABLE_INTERRUPTS(CLBR_ANY)
281 cmpl $0, PER_CPU_VAR(__preempt_count)
283 testl $X86_EFLAGS_IF, PT_EFLAGS(%esp) # interrupts off (exception path) ?
285 call preempt_schedule_irq
290 GLOBAL(__begin_SYSENTER_singlestep_region)
292 * All code from here through __end_SYSENTER_singlestep_region is subject
293 * to being single-stepped if a user program sets TF and executes SYSENTER.
294 * There is absolutely nothing that we can do to prevent this from happening
295 * (thanks Intel!). To keep our handling of this situation as simple as
296 * possible, we handle TF just like AC and NT, except that our #DB handler
297 * will ignore all of the single-step traps generated in this range.
302 * Xen doesn't set %esp to be precisely what the normal SYSENTER
303 * entry point expects, so fix it up before using the normal path.
305 ENTRY(xen_sysenter_target)
306 addl $5*4, %esp /* remove xen-provided frame */
307 jmp sysenter_past_esp
311 * 32-bit SYSENTER entry.
313 * 32-bit system calls through the vDSO's __kernel_vsyscall enter here
314 * if X86_FEATURE_SEP is available. This is the preferred system call
315 * entry on 32-bit systems.
317 * The SYSENTER instruction, in principle, should *only* occur in the
318 * vDSO. In practice, a small number of Android devices were shipped
319 * with a copy of Bionic that inlined a SYSENTER instruction. This
320 * never happened in any of Google's Bionic versions -- it only happened
321 * in a narrow range of Intel-provided versions.
323 * SYSENTER loads SS, ESP, CS, and EIP from previously programmed MSRs.
324 * IF and VM in RFLAGS are cleared (IOW: interrupts are off).
325 * SYSENTER does not save anything on the stack,
326 * and does not save old EIP (!!!), ESP, or EFLAGS.
328 * To avoid losing track of EFLAGS.VM (and thus potentially corrupting
329 * user and/or vm86 state), we explicitly disable the SYSENTER
330 * instruction in vm86 mode by reprogramming the MSRs.
333 * eax system call number
342 ENTRY(entry_SYSENTER_32)
343 movl TSS_sysenter_sp0(%esp), %esp
345 pushl $__USER_DS /* pt_regs->ss */
346 pushl %ebp /* pt_regs->sp (stashed in bp) */
347 pushfl /* pt_regs->flags (except IF = 0) */
348 orl $X86_EFLAGS_IF, (%esp) /* Fix IF */
349 pushl $__USER_CS /* pt_regs->cs */
350 pushl $0 /* pt_regs->ip = 0 (placeholder) */
351 pushl %eax /* pt_regs->orig_ax */
352 SAVE_ALL pt_regs_ax=$-ENOSYS /* save rest */
355 * SYSENTER doesn't filter flags, so we need to clear NT, AC
356 * and TF ourselves. To save a few cycles, we can check whether
357 * either was set instead of doing an unconditional popfq.
358 * This needs to happen before enabling interrupts so that
359 * we don't get preempted with NT set.
361 * If TF is set, we will single-step all the way to here -- do_debug
362 * will ignore all the traps. (Yes, this is slow, but so is
363 * single-stepping in general. This allows us to avoid having
364 * a more complicated code to handle the case where a user program
365 * forces us to single-step through the SYSENTER entry code.)
367 * NB.: .Lsysenter_fix_flags is a label with the code under it moved
368 * out-of-line as an optimization: NT is unlikely to be set in the
369 * majority of the cases and instead of polluting the I$ unnecessarily,
370 * we're keeping that code behind a branch which will predict as
371 * not-taken and therefore its instructions won't be fetched.
373 testl $X86_EFLAGS_NT|X86_EFLAGS_AC|X86_EFLAGS_TF, PT_EFLAGS(%esp)
374 jnz .Lsysenter_fix_flags
375 .Lsysenter_flags_fixed:
378 * User mode is traced as though IRQs are on, and SYSENTER
384 call do_fast_syscall_32
385 /* XEN PV guests always use IRET path */
386 ALTERNATIVE "testl %eax, %eax; jz .Lsyscall_32_done", \
387 "jmp .Lsyscall_32_done", X86_FEATURE_XENPV
389 /* Opportunistic SYSEXIT */
390 TRACE_IRQS_ON /* User mode traces as IRQs on. */
391 movl PT_EIP(%esp), %edx /* pt_regs->ip */
392 movl PT_OLDESP(%esp), %ecx /* pt_regs->sp */
393 1: mov PT_FS(%esp), %fs
395 popl %ebx /* pt_regs->bx */
396 addl $2*4, %esp /* skip pt_regs->cx and pt_regs->dx */
397 popl %esi /* pt_regs->si */
398 popl %edi /* pt_regs->di */
399 popl %ebp /* pt_regs->bp */
400 popl %eax /* pt_regs->ax */
403 * Restore all flags except IF. (We restore IF separately because
404 * STI gives a one-instruction window in which we won't be interrupted,
405 * whereas POPF does not.)
407 addl $PT_EFLAGS-PT_DS, %esp /* point esp at pt_regs->flags */
408 btr $X86_EFLAGS_IF_BIT, (%esp)
412 * Return back to the vDSO, which will pop ecx and edx.
413 * Don't bother with DS and ES (they already contain __USER_DS).
418 .pushsection .fixup, "ax"
419 2: movl $0, PT_FS(%esp)
425 .Lsysenter_fix_flags:
426 pushl $X86_EFLAGS_FIXED
428 jmp .Lsysenter_flags_fixed
429 GLOBAL(__end_SYSENTER_singlestep_region)
430 ENDPROC(entry_SYSENTER_32)
433 * 32-bit legacy system call entry.
435 * 32-bit x86 Linux system calls traditionally used the INT $0x80
436 * instruction. INT $0x80 lands here.
438 * This entry point can be used by any 32-bit perform system calls.
439 * Instances of INT $0x80 can be found inline in various programs and
440 * libraries. It is also used by the vDSO's __kernel_vsyscall
441 * fallback for hardware that doesn't support a faster entry method.
442 * Restarted 32-bit system calls also fall back to INT $0x80
443 * regardless of what instruction was originally used to do the system
444 * call. (64-bit programs can use INT $0x80 as well, but they can
445 * only run on 64-bit kernels and therefore land in
446 * entry_INT80_compat.)
448 * This is considered a slow path. It is not used by most libc
449 * implementations on modern hardware except during process startup.
452 * eax system call number
460 ENTRY(entry_INT80_32)
462 pushl %eax /* pt_regs->orig_ax */
463 SAVE_ALL pt_regs_ax=$-ENOSYS /* save rest */
466 * User mode is traced as though IRQs are on, and the interrupt gate
472 call do_int80_syscall_32
478 #ifdef CONFIG_X86_ESPFIX32
479 ALTERNATIVE "jmp restore_nocheck", "", X86_BUG_ESPFIX
481 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
483 * Warning: PT_OLDSS(%esp) contains the wrong/random values if we
484 * are returning to the kernel.
485 * See comments in process.c:copy_thread() for details.
487 movb PT_OLDSS(%esp), %ah
488 movb PT_CS(%esp), %al
489 andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
490 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
491 je ldt_ss # returning to user-space with LDT SS
494 RESTORE_REGS 4 # skip orig_eax/error_code
497 .section .fixup, "ax"
499 pushl $0 # no error code
503 _ASM_EXTABLE(irq_return, iret_exc)
505 #ifdef CONFIG_X86_ESPFIX32
508 * Setup and switch to ESPFIX stack
510 * We're returning to userspace with a 16 bit stack. The CPU will not
511 * restore the high word of ESP for us on executing iret... This is an
512 * "official" bug of all the x86-compatible CPUs, which we can work
513 * around to make dosemu and wine happy. We do this by preloading the
514 * high word of ESP with the high word of the userspace ESP while
515 * compensating for the offset by changing to the ESPFIX segment with
516 * a base address that matches for the difference.
518 #define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
519 mov %esp, %edx /* load kernel esp */
520 mov PT_OLDESP(%esp), %eax /* load userspace esp */
521 mov %dx, %ax /* eax: new kernel esp */
522 sub %eax, %edx /* offset (low word is 0) */
524 mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
525 mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
527 pushl %eax /* new kernel esp */
529 * Disable interrupts, but do not irqtrace this section: we
530 * will soon execute iret and the tracer was already set to
531 * the irqstate after the IRET:
533 DISABLE_INTERRUPTS(CLBR_EAX)
534 lss (%esp), %esp /* switch to espfix segment */
537 ENDPROC(entry_INT80_32)
539 .macro FIXUP_ESPFIX_STACK
541 * Switch back for ESPFIX stack to the normal zerobased stack
543 * We can't call C functions using the ESPFIX stack. This code reads
544 * the high word of the segment base from the GDT and swiches to the
545 * normal stack and adjusts ESP with the matching offset.
547 #ifdef CONFIG_X86_ESPFIX32
548 /* fixup the stack */
549 mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
550 mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
552 addl %esp, %eax /* the adjusted stack pointer */
555 lss (%esp), %esp /* switch to the normal stack segment */
558 .macro UNWIND_ESPFIX_STACK
559 #ifdef CONFIG_X86_ESPFIX32
561 /* see if on espfix stack */
562 cmpw $__ESPFIX_SS, %ax
564 movl $__KERNEL_DS, %eax
567 /* switch to normal stack */
574 * Build the entry stubs with some assembler magic.
575 * We pack 1 stub into every 8-byte block.
578 ENTRY(irq_entries_start)
579 vector=FIRST_EXTERNAL_VECTOR
580 .rept (FIRST_SYSTEM_VECTOR - FIRST_EXTERNAL_VECTOR)
581 pushl $(~vector+0x80) /* Note: always in signed byte range */
586 END(irq_entries_start)
589 * the CPU automatically disables interrupts when executing an IRQ vector,
590 * so IRQ-flags tracing has to follow that:
592 .p2align CONFIG_X86_L1_CACHE_SHIFT
595 addl $-0x80, (%esp) /* Adjust vector into the [-256, -1] range */
601 ENDPROC(common_interrupt)
603 #define BUILD_INTERRUPT3(name, nr, fn) \
615 #ifdef CONFIG_TRACING
616 # define TRACE_BUILD_INTERRUPT(name, nr) BUILD_INTERRUPT3(trace_##name, nr, smp_trace_##name)
618 # define TRACE_BUILD_INTERRUPT(name, nr)
621 #define BUILD_INTERRUPT(name, nr) \
622 BUILD_INTERRUPT3(name, nr, smp_##name); \
623 TRACE_BUILD_INTERRUPT(name, nr)
625 /* The include is where all of the SMP etc. interrupts come from */
626 #include <asm/entry_arch.h>
628 ENTRY(coprocessor_error)
631 pushl $do_coprocessor_error
633 END(coprocessor_error)
635 ENTRY(simd_coprocessor_error)
638 #ifdef CONFIG_X86_INVD_BUG
639 /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
640 ALTERNATIVE "pushl $do_general_protection", \
641 "pushl $do_simd_coprocessor_error", \
644 pushl $do_simd_coprocessor_error
647 END(simd_coprocessor_error)
649 ENTRY(device_not_available)
651 pushl $-1 # mark this as an int
652 pushl $do_device_not_available
654 END(device_not_available)
656 #ifdef CONFIG_PARAVIRT
659 _ASM_EXTABLE(native_iret, iret_exc)
684 ENTRY(coprocessor_segment_overrun)
687 pushl $do_coprocessor_segment_overrun
689 END(coprocessor_segment_overrun)
693 pushl $do_invalid_TSS
697 ENTRY(segment_not_present)
699 pushl $do_segment_not_present
701 END(segment_not_present)
705 pushl $do_stack_segment
709 ENTRY(alignment_check)
711 pushl $do_alignment_check
717 pushl $0 # no error code
718 pushl $do_divide_error
722 #ifdef CONFIG_X86_MCE
726 pushl machine_check_vector
731 ENTRY(spurious_interrupt_bug)
734 pushl $do_spurious_interrupt_bug
736 END(spurious_interrupt_bug)
739 ENTRY(xen_hypervisor_callback)
740 pushl $-1 /* orig_ax = -1 => not a system call */
745 * Check to see if we got the event in the critical
746 * region in xen_iret_direct, after we've reenabled
747 * events and checked for pending events. This simulates
748 * iret instruction's behaviour where it delivers a
749 * pending interrupt when enabling interrupts:
751 movl PT_EIP(%esp), %eax
752 cmpl $xen_iret_start_crit, %eax
754 cmpl $xen_iret_end_crit, %eax
757 jmp xen_iret_crit_fixup
761 call xen_evtchn_do_upcall
762 #ifndef CONFIG_PREEMPT
763 call xen_maybe_preempt_hcall
766 ENDPROC(xen_hypervisor_callback)
769 * Hypervisor uses this for application faults while it executes.
770 * We get here for two reasons:
771 * 1. Fault while reloading DS, ES, FS or GS
772 * 2. Fault while executing IRET
773 * Category 1 we fix up by reattempting the load, and zeroing the segment
774 * register if the load fails.
775 * Category 2 we fix up by jumping to do_iret_error. We cannot use the
776 * normal Linux return path in this case because if we use the IRET hypercall
777 * to pop the stack frame we end up in an infinite loop of failsafe callbacks.
778 * We distinguish between categories by maintaining a status value in EAX.
780 ENTRY(xen_failsafe_callback)
787 /* EAX == 0 => Category 1 (Bad segment)
788 EAX != 0 => Category 2 (Bad IRET) */
794 5: pushl $-1 /* orig_ax = -1 => not a system call */
796 jmp ret_from_exception
798 .section .fixup, "ax"
816 ENDPROC(xen_failsafe_callback)
818 BUILD_INTERRUPT3(xen_hvm_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
819 xen_evtchn_do_upcall)
821 #endif /* CONFIG_XEN */
823 #if IS_ENABLED(CONFIG_HYPERV)
825 BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
826 hyperv_vector_handler)
828 #endif /* CONFIG_HYPERV */
830 #ifdef CONFIG_FUNCTION_TRACER
831 #ifdef CONFIG_DYNAMIC_FTRACE
841 pushl $0 /* Pass NULL as regs pointer */
844 movl function_trace_op, %ecx
845 subl $MCOUNT_INSN_SIZE, %eax
851 addl $4, %esp /* skip NULL pointer */
856 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
857 .globl ftrace_graph_call
867 ENTRY(ftrace_regs_caller)
868 pushf /* push flags before compare (in cs location) */
871 * i386 does not save SS and ESP when coming from kernel.
872 * Instead, to get sp, ®s->sp is used (see ptrace.h).
873 * Unfortunately, that means eflags must be at the same location
874 * as the current return ip is. We move the return ip into the
875 * ip location, and move flags into the return ip location.
877 pushl 4(%esp) /* save return ip into ip slot */
879 pushl $0 /* Load 0 into orig_ax */
892 movl 13*4(%esp), %eax /* Get the saved flags */
893 movl %eax, 14*4(%esp) /* Move saved flags into regs->flags location */
894 /* clobbering return ip */
895 movl $__KERNEL_CS, 13*4(%esp)
897 movl 12*4(%esp), %eax /* Load ip (1st parameter) */
898 subl $MCOUNT_INSN_SIZE, %eax /* Adjust ip */
899 movl 0x4(%ebp), %edx /* Load parent ip (2nd parameter) */
900 movl function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */
901 pushl %esp /* Save pt_regs as 4th parameter */
903 GLOBAL(ftrace_regs_call)
906 addl $4, %esp /* Skip pt_regs */
907 movl 14*4(%esp), %eax /* Move flags back into cs */
908 movl %eax, 13*4(%esp) /* Needed to keep addl from modifying flags */
909 movl 12*4(%esp), %eax /* Get return ip from regs->ip */
910 movl %eax, 14*4(%esp) /* Put return ip back for ret */
923 addl $8, %esp /* Skip orig_ax and ip */
924 popf /* Pop flags at end (no addl to corrupt flags) */
929 #else /* ! CONFIG_DYNAMIC_FTRACE */
932 cmpl $__PAGE_OFFSET, %esp
933 jb ftrace_stub /* Paging not enabled yet? */
935 cmpl $ftrace_stub, ftrace_trace_function
937 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
938 cmpl $ftrace_stub, ftrace_graph_return
939 jnz ftrace_graph_caller
941 cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
942 jnz ftrace_graph_caller
948 /* taken from glibc */
955 subl $MCOUNT_INSN_SIZE, %eax
957 call *ftrace_trace_function
964 #endif /* CONFIG_DYNAMIC_FTRACE */
965 #endif /* CONFIG_FUNCTION_TRACER */
967 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
968 ENTRY(ftrace_graph_caller)
975 subl $MCOUNT_INSN_SIZE, %eax
976 call prepare_ftrace_return
981 END(ftrace_graph_caller)
983 .globl return_to_handler
988 call ftrace_return_to_handler
995 #ifdef CONFIG_TRACING
996 ENTRY(trace_page_fault)
998 pushl $trace_do_page_fault
1000 END(trace_page_fault)
1005 pushl $do_page_fault
1008 /* the function address is in %gs's slot on the stack */
1020 movl $(__KERNEL_PERCPU), %ecx
1024 movl PT_GS(%esp), %edi # get the function address
1025 movl PT_ORIG_EAX(%esp), %edx # get the error code
1026 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
1029 movl $(__USER_DS), %ecx
1033 movl %esp, %eax # pt_regs pointer
1035 jmp ret_from_exception
1040 * #DB can happen at the first instruction of
1041 * entry_SYSENTER_32 or in Xen's SYSENTER prologue. If this
1042 * happens, then we will be running on a very small stack. We
1043 * need to detect this condition and switch to the thread
1044 * stack before calling any C code at all.
1046 * If you edit this code, keep in mind that NMIs can happen in here.
1049 pushl $-1 # mark this as an int
1051 xorl %edx, %edx # error code 0
1052 movl %esp, %eax # pt_regs pointer
1054 /* Are we currently on the SYSENTER stack? */
1055 PER_CPU(cpu_tss + CPU_TSS_SYSENTER_stack + SIZEOF_SYSENTER_stack, %ecx)
1056 subl %eax, %ecx /* ecx = (end of SYSENTER_stack) - esp */
1057 cmpl $SIZEOF_SYSENTER_stack, %ecx
1058 jb .Ldebug_from_sysenter_stack
1062 jmp ret_from_exception
1064 .Ldebug_from_sysenter_stack:
1065 /* We're on the SYSENTER stack. Switch off. */
1067 movl PER_CPU_VAR(cpu_current_top_of_stack), %esp
1071 jmp ret_from_exception
1075 * NMI is doubly nasty. It can happen on the first instruction of
1076 * entry_SYSENTER_32 (just like #DB), but it can also interrupt the beginning
1077 * of the #DB handler even if that #DB in turn hit before entry_SYSENTER_32
1078 * switched stacks. We handle both conditions by simply checking whether we
1079 * interrupted kernel code running on the SYSENTER stack.
1083 #ifdef CONFIG_X86_ESPFIX32
1086 cmpw $__ESPFIX_SS, %ax
1091 pushl %eax # pt_regs->orig_ax
1093 xorl %edx, %edx # zero error code
1094 movl %esp, %eax # pt_regs pointer
1096 /* Are we currently on the SYSENTER stack? */
1097 PER_CPU(cpu_tss + CPU_TSS_SYSENTER_stack + SIZEOF_SYSENTER_stack, %ecx)
1098 subl %eax, %ecx /* ecx = (end of SYSENTER_stack) - esp */
1099 cmpl $SIZEOF_SYSENTER_stack, %ecx
1100 jb .Lnmi_from_sysenter_stack
1102 /* Not on SYSENTER stack. */
1104 jmp restore_all_notrace
1106 .Lnmi_from_sysenter_stack:
1108 * We're on the SYSENTER stack. Switch off. No one (not even debug)
1109 * is using the thread stack right now, so it's safe for us to use it.
1112 movl PER_CPU_VAR(cpu_current_top_of_stack), %esp
1115 jmp restore_all_notrace
1117 #ifdef CONFIG_X86_ESPFIX32
1120 * create the pointer to lss back
1125 /* copy the iret frame of 12 bytes */
1131 FIXUP_ESPFIX_STACK # %eax == %esp
1132 xorl %edx, %edx # zero error code
1135 lss 12+4(%esp), %esp # back to espfix stack
1142 pushl $-1 # mark this as an int
1145 xorl %edx, %edx # zero error code
1146 movl %esp, %eax # pt_regs pointer
1148 jmp ret_from_exception
1151 ENTRY(general_protection)
1152 pushl $do_general_protection
1154 END(general_protection)
1156 #ifdef CONFIG_KVM_GUEST
1157 ENTRY(async_page_fault)
1159 pushl $do_async_page_fault
1161 END(async_page_fault)