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>
47 #include <asm/export.h>
49 .section .entry.text, "ax"
52 * We use macros for low-level operations which need to be overridden
53 * for paravirtualization. The following will never clobber any registers:
54 * INTERRUPT_RETURN (aka. "iret")
55 * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
56 * ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
58 * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
59 * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
60 * Allowing a register to be clobbered can shrink the paravirt replacement
61 * enough to patch inline, increasing performance.
65 # define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
67 # define preempt_stop(clobbers)
68 # define resume_kernel restore_all
71 .macro TRACE_IRQS_IRET
72 #ifdef CONFIG_TRACE_IRQFLAGS
73 testl $X86_EFLAGS_IF, PT_EFLAGS(%esp) # interrupts off?
81 * User gs save/restore
83 * %gs is used for userland TLS and kernel only uses it for stack
84 * canary which is required to be at %gs:20 by gcc. Read the comment
85 * at the top of stackprotector.h for more info.
87 * Local labels 98 and 99 are used.
89 #ifdef CONFIG_X86_32_LAZY_GS
91 /* unfortunately push/pop can't be no-op */
96 addl $(4 + \pop), %esp
101 /* all the rest are no-op */
108 .macro REG_TO_PTGS reg
110 .macro SET_KERNEL_GS reg
113 #else /* CONFIG_X86_32_LAZY_GS */
126 .pushsection .fixup, "ax"
130 _ASM_EXTABLE(98b, 99b)
134 98: mov PT_GS(%esp), %gs
137 .pushsection .fixup, "ax"
138 99: movl $0, PT_GS(%esp)
141 _ASM_EXTABLE(98b, 99b)
147 .macro REG_TO_PTGS reg
148 movl \reg, PT_GS(%esp)
150 .macro SET_KERNEL_GS reg
151 movl $(__KERNEL_STACK_CANARY), \reg
155 #endif /* CONFIG_X86_32_LAZY_GS */
157 .macro SAVE_ALL pt_regs_ax=%eax
170 movl $(__USER_DS), %edx
173 movl $(__KERNEL_PERCPU), %edx
178 .macro RESTORE_INT_REGS
188 .macro RESTORE_REGS pop=0
194 .pushsection .fixup, "ax"
212 ENTRY(__switch_to_asm)
214 * Save callee-saved registers
215 * This must match the order in struct inactive_task_frame
223 movl %esp, TASK_threadsp(%eax)
224 movl TASK_threadsp(%edx), %esp
226 #ifdef CONFIG_CC_STACKPROTECTOR
227 movl TASK_stack_canary(%edx), %ebx
228 movl %ebx, PER_CPU_VAR(stack_canary)+stack_canary_offset
231 /* restore callee-saved registers */
241 * A newly forked process directly context switches into this address.
243 * eax: prev task we switched from
244 * ebx: kernel thread func (NULL for user thread)
245 * edi: kernel thread arg
253 jnz 1f /* kernel threads are uncommon */
256 /* When we fork, we trace the syscall return in the child, too. */
258 call syscall_return_slowpath
265 * A kernel thread is allowed to return here after successfully
266 * calling do_execve(). Exit to userspace to complete the execve()
269 movl $0, PT_EAX(%esp)
274 * Return to user mode is not as complex as all this looks,
275 * but we want the default path for a system call return to
276 * go as quickly as possible which is why some of this is
277 * less clear than it otherwise should be.
280 # userspace resumption stub bypassing syscall exit tracing
283 preempt_stop(CLBR_ANY)
286 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
287 movb PT_CS(%esp), %al
288 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
291 * We can be coming here from child spawned by kernel_thread().
293 movl PT_CS(%esp), %eax
294 andl $SEGMENT_RPL_MASK, %eax
297 jb resume_kernel # not returning to v8086 or userspace
299 ENTRY(resume_userspace)
300 DISABLE_INTERRUPTS(CLBR_ANY)
303 call prepare_exit_to_usermode
305 END(ret_from_exception)
307 #ifdef CONFIG_PREEMPT
309 DISABLE_INTERRUPTS(CLBR_ANY)
311 cmpl $0, PER_CPU_VAR(__preempt_count)
313 testl $X86_EFLAGS_IF, PT_EFLAGS(%esp) # interrupts off (exception path) ?
315 call preempt_schedule_irq
320 GLOBAL(__begin_SYSENTER_singlestep_region)
322 * All code from here through __end_SYSENTER_singlestep_region is subject
323 * to being single-stepped if a user program sets TF and executes SYSENTER.
324 * There is absolutely nothing that we can do to prevent this from happening
325 * (thanks Intel!). To keep our handling of this situation as simple as
326 * possible, we handle TF just like AC and NT, except that our #DB handler
327 * will ignore all of the single-step traps generated in this range.
332 * Xen doesn't set %esp to be precisely what the normal SYSENTER
333 * entry point expects, so fix it up before using the normal path.
335 ENTRY(xen_sysenter_target)
336 addl $5*4, %esp /* remove xen-provided frame */
337 jmp sysenter_past_esp
341 * 32-bit SYSENTER entry.
343 * 32-bit system calls through the vDSO's __kernel_vsyscall enter here
344 * if X86_FEATURE_SEP is available. This is the preferred system call
345 * entry on 32-bit systems.
347 * The SYSENTER instruction, in principle, should *only* occur in the
348 * vDSO. In practice, a small number of Android devices were shipped
349 * with a copy of Bionic that inlined a SYSENTER instruction. This
350 * never happened in any of Google's Bionic versions -- it only happened
351 * in a narrow range of Intel-provided versions.
353 * SYSENTER loads SS, ESP, CS, and EIP from previously programmed MSRs.
354 * IF and VM in RFLAGS are cleared (IOW: interrupts are off).
355 * SYSENTER does not save anything on the stack,
356 * and does not save old EIP (!!!), ESP, or EFLAGS.
358 * To avoid losing track of EFLAGS.VM (and thus potentially corrupting
359 * user and/or vm86 state), we explicitly disable the SYSENTER
360 * instruction in vm86 mode by reprogramming the MSRs.
363 * eax system call number
372 ENTRY(entry_SYSENTER_32)
373 movl TSS_sysenter_sp0(%esp), %esp
375 pushl $__USER_DS /* pt_regs->ss */
376 pushl %ebp /* pt_regs->sp (stashed in bp) */
377 pushfl /* pt_regs->flags (except IF = 0) */
378 orl $X86_EFLAGS_IF, (%esp) /* Fix IF */
379 pushl $__USER_CS /* pt_regs->cs */
380 pushl $0 /* pt_regs->ip = 0 (placeholder) */
381 pushl %eax /* pt_regs->orig_ax */
382 SAVE_ALL pt_regs_ax=$-ENOSYS /* save rest */
385 * SYSENTER doesn't filter flags, so we need to clear NT, AC
386 * and TF ourselves. To save a few cycles, we can check whether
387 * either was set instead of doing an unconditional popfq.
388 * This needs to happen before enabling interrupts so that
389 * we don't get preempted with NT set.
391 * If TF is set, we will single-step all the way to here -- do_debug
392 * will ignore all the traps. (Yes, this is slow, but so is
393 * single-stepping in general. This allows us to avoid having
394 * a more complicated code to handle the case where a user program
395 * forces us to single-step through the SYSENTER entry code.)
397 * NB.: .Lsysenter_fix_flags is a label with the code under it moved
398 * out-of-line as an optimization: NT is unlikely to be set in the
399 * majority of the cases and instead of polluting the I$ unnecessarily,
400 * we're keeping that code behind a branch which will predict as
401 * not-taken and therefore its instructions won't be fetched.
403 testl $X86_EFLAGS_NT|X86_EFLAGS_AC|X86_EFLAGS_TF, PT_EFLAGS(%esp)
404 jnz .Lsysenter_fix_flags
405 .Lsysenter_flags_fixed:
408 * User mode is traced as though IRQs are on, and SYSENTER
414 call do_fast_syscall_32
415 /* XEN PV guests always use IRET path */
416 ALTERNATIVE "testl %eax, %eax; jz .Lsyscall_32_done", \
417 "jmp .Lsyscall_32_done", X86_FEATURE_XENPV
419 /* Opportunistic SYSEXIT */
420 TRACE_IRQS_ON /* User mode traces as IRQs on. */
421 movl PT_EIP(%esp), %edx /* pt_regs->ip */
422 movl PT_OLDESP(%esp), %ecx /* pt_regs->sp */
423 1: mov PT_FS(%esp), %fs
425 popl %ebx /* pt_regs->bx */
426 addl $2*4, %esp /* skip pt_regs->cx and pt_regs->dx */
427 popl %esi /* pt_regs->si */
428 popl %edi /* pt_regs->di */
429 popl %ebp /* pt_regs->bp */
430 popl %eax /* pt_regs->ax */
433 * Restore all flags except IF. (We restore IF separately because
434 * STI gives a one-instruction window in which we won't be interrupted,
435 * whereas POPF does not.)
437 addl $PT_EFLAGS-PT_DS, %esp /* point esp at pt_regs->flags */
438 btr $X86_EFLAGS_IF_BIT, (%esp)
442 * Return back to the vDSO, which will pop ecx and edx.
443 * Don't bother with DS and ES (they already contain __USER_DS).
448 .pushsection .fixup, "ax"
449 2: movl $0, PT_FS(%esp)
455 .Lsysenter_fix_flags:
456 pushl $X86_EFLAGS_FIXED
458 jmp .Lsysenter_flags_fixed
459 GLOBAL(__end_SYSENTER_singlestep_region)
460 ENDPROC(entry_SYSENTER_32)
463 * 32-bit legacy system call entry.
465 * 32-bit x86 Linux system calls traditionally used the INT $0x80
466 * instruction. INT $0x80 lands here.
468 * This entry point can be used by any 32-bit perform system calls.
469 * Instances of INT $0x80 can be found inline in various programs and
470 * libraries. It is also used by the vDSO's __kernel_vsyscall
471 * fallback for hardware that doesn't support a faster entry method.
472 * Restarted 32-bit system calls also fall back to INT $0x80
473 * regardless of what instruction was originally used to do the system
474 * call. (64-bit programs can use INT $0x80 as well, but they can
475 * only run on 64-bit kernels and therefore land in
476 * entry_INT80_compat.)
478 * This is considered a slow path. It is not used by most libc
479 * implementations on modern hardware except during process startup.
482 * eax system call number
490 ENTRY(entry_INT80_32)
492 pushl %eax /* pt_regs->orig_ax */
493 SAVE_ALL pt_regs_ax=$-ENOSYS /* save rest */
496 * User mode is traced as though IRQs are on, and the interrupt gate
502 call do_int80_syscall_32
508 #ifdef CONFIG_X86_ESPFIX32
509 ALTERNATIVE "jmp restore_nocheck", "", X86_BUG_ESPFIX
511 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
513 * Warning: PT_OLDSS(%esp) contains the wrong/random values if we
514 * are returning to the kernel.
515 * See comments in process.c:copy_thread() for details.
517 movb PT_OLDSS(%esp), %ah
518 movb PT_CS(%esp), %al
519 andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
520 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
521 je ldt_ss # returning to user-space with LDT SS
524 RESTORE_REGS 4 # skip orig_eax/error_code
527 .section .fixup, "ax"
529 pushl $0 # no error code
533 _ASM_EXTABLE(irq_return, iret_exc)
535 #ifdef CONFIG_X86_ESPFIX32
538 * Setup and switch to ESPFIX stack
540 * We're returning to userspace with a 16 bit stack. The CPU will not
541 * restore the high word of ESP for us on executing iret... This is an
542 * "official" bug of all the x86-compatible CPUs, which we can work
543 * around to make dosemu and wine happy. We do this by preloading the
544 * high word of ESP with the high word of the userspace ESP while
545 * compensating for the offset by changing to the ESPFIX segment with
546 * a base address that matches for the difference.
548 #define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
549 mov %esp, %edx /* load kernel esp */
550 mov PT_OLDESP(%esp), %eax /* load userspace esp */
551 mov %dx, %ax /* eax: new kernel esp */
552 sub %eax, %edx /* offset (low word is 0) */
554 mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
555 mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
557 pushl %eax /* new kernel esp */
559 * Disable interrupts, but do not irqtrace this section: we
560 * will soon execute iret and the tracer was already set to
561 * the irqstate after the IRET:
563 DISABLE_INTERRUPTS(CLBR_EAX)
564 lss (%esp), %esp /* switch to espfix segment */
567 ENDPROC(entry_INT80_32)
569 .macro FIXUP_ESPFIX_STACK
571 * Switch back for ESPFIX stack to the normal zerobased stack
573 * We can't call C functions using the ESPFIX stack. This code reads
574 * the high word of the segment base from the GDT and swiches to the
575 * normal stack and adjusts ESP with the matching offset.
577 #ifdef CONFIG_X86_ESPFIX32
578 /* fixup the stack */
579 mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
580 mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
582 addl %esp, %eax /* the adjusted stack pointer */
585 lss (%esp), %esp /* switch to the normal stack segment */
588 .macro UNWIND_ESPFIX_STACK
589 #ifdef CONFIG_X86_ESPFIX32
591 /* see if on espfix stack */
592 cmpw $__ESPFIX_SS, %ax
594 movl $__KERNEL_DS, %eax
597 /* switch to normal stack */
604 * Build the entry stubs with some assembler magic.
605 * We pack 1 stub into every 8-byte block.
608 ENTRY(irq_entries_start)
609 vector=FIRST_EXTERNAL_VECTOR
610 .rept (FIRST_SYSTEM_VECTOR - FIRST_EXTERNAL_VECTOR)
611 pushl $(~vector+0x80) /* Note: always in signed byte range */
616 END(irq_entries_start)
619 * the CPU automatically disables interrupts when executing an IRQ vector,
620 * so IRQ-flags tracing has to follow that:
622 .p2align CONFIG_X86_L1_CACHE_SHIFT
625 addl $-0x80, (%esp) /* Adjust vector into the [-256, -1] range */
631 ENDPROC(common_interrupt)
633 #define BUILD_INTERRUPT3(name, nr, fn) \
645 #ifdef CONFIG_TRACING
646 # define TRACE_BUILD_INTERRUPT(name, nr) BUILD_INTERRUPT3(trace_##name, nr, smp_trace_##name)
648 # define TRACE_BUILD_INTERRUPT(name, nr)
651 #define BUILD_INTERRUPT(name, nr) \
652 BUILD_INTERRUPT3(name, nr, smp_##name); \
653 TRACE_BUILD_INTERRUPT(name, nr)
655 /* The include is where all of the SMP etc. interrupts come from */
656 #include <asm/entry_arch.h>
658 ENTRY(coprocessor_error)
661 pushl $do_coprocessor_error
663 END(coprocessor_error)
665 ENTRY(simd_coprocessor_error)
668 #ifdef CONFIG_X86_INVD_BUG
669 /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
670 ALTERNATIVE "pushl $do_general_protection", \
671 "pushl $do_simd_coprocessor_error", \
674 pushl $do_simd_coprocessor_error
677 END(simd_coprocessor_error)
679 ENTRY(device_not_available)
681 pushl $-1 # mark this as an int
682 pushl $do_device_not_available
684 END(device_not_available)
686 #ifdef CONFIG_PARAVIRT
689 _ASM_EXTABLE(native_iret, iret_exc)
714 ENTRY(coprocessor_segment_overrun)
717 pushl $do_coprocessor_segment_overrun
719 END(coprocessor_segment_overrun)
723 pushl $do_invalid_TSS
727 ENTRY(segment_not_present)
729 pushl $do_segment_not_present
731 END(segment_not_present)
735 pushl $do_stack_segment
739 ENTRY(alignment_check)
741 pushl $do_alignment_check
747 pushl $0 # no error code
748 pushl $do_divide_error
752 #ifdef CONFIG_X86_MCE
756 pushl machine_check_vector
761 ENTRY(spurious_interrupt_bug)
764 pushl $do_spurious_interrupt_bug
766 END(spurious_interrupt_bug)
769 ENTRY(xen_hypervisor_callback)
770 pushl $-1 /* orig_ax = -1 => not a system call */
775 * Check to see if we got the event in the critical
776 * region in xen_iret_direct, after we've reenabled
777 * events and checked for pending events. This simulates
778 * iret instruction's behaviour where it delivers a
779 * pending interrupt when enabling interrupts:
781 movl PT_EIP(%esp), %eax
782 cmpl $xen_iret_start_crit, %eax
784 cmpl $xen_iret_end_crit, %eax
787 jmp xen_iret_crit_fixup
791 call xen_evtchn_do_upcall
792 #ifndef CONFIG_PREEMPT
793 call xen_maybe_preempt_hcall
796 ENDPROC(xen_hypervisor_callback)
799 * Hypervisor uses this for application faults while it executes.
800 * We get here for two reasons:
801 * 1. Fault while reloading DS, ES, FS or GS
802 * 2. Fault while executing IRET
803 * Category 1 we fix up by reattempting the load, and zeroing the segment
804 * register if the load fails.
805 * Category 2 we fix up by jumping to do_iret_error. We cannot use the
806 * normal Linux return path in this case because if we use the IRET hypercall
807 * to pop the stack frame we end up in an infinite loop of failsafe callbacks.
808 * We distinguish between categories by maintaining a status value in EAX.
810 ENTRY(xen_failsafe_callback)
817 /* EAX == 0 => Category 1 (Bad segment)
818 EAX != 0 => Category 2 (Bad IRET) */
824 5: pushl $-1 /* orig_ax = -1 => not a system call */
826 jmp ret_from_exception
828 .section .fixup, "ax"
846 ENDPROC(xen_failsafe_callback)
848 BUILD_INTERRUPT3(xen_hvm_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
849 xen_evtchn_do_upcall)
851 #endif /* CONFIG_XEN */
853 #if IS_ENABLED(CONFIG_HYPERV)
855 BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
856 hyperv_vector_handler)
858 #endif /* CONFIG_HYPERV */
860 #ifdef CONFIG_FUNCTION_TRACER
861 #ifdef CONFIG_DYNAMIC_FTRACE
871 pushl $0 /* Pass NULL as regs pointer */
874 movl function_trace_op, %ecx
875 subl $MCOUNT_INSN_SIZE, %eax
881 addl $4, %esp /* skip NULL pointer */
886 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
887 .globl ftrace_graph_call
897 ENTRY(ftrace_regs_caller)
898 pushf /* push flags before compare (in cs location) */
901 * i386 does not save SS and ESP when coming from kernel.
902 * Instead, to get sp, ®s->sp is used (see ptrace.h).
903 * Unfortunately, that means eflags must be at the same location
904 * as the current return ip is. We move the return ip into the
905 * ip location, and move flags into the return ip location.
907 pushl 4(%esp) /* save return ip into ip slot */
909 pushl $0 /* Load 0 into orig_ax */
922 movl 13*4(%esp), %eax /* Get the saved flags */
923 movl %eax, 14*4(%esp) /* Move saved flags into regs->flags location */
924 /* clobbering return ip */
925 movl $__KERNEL_CS, 13*4(%esp)
927 movl 12*4(%esp), %eax /* Load ip (1st parameter) */
928 subl $MCOUNT_INSN_SIZE, %eax /* Adjust ip */
929 movl 0x4(%ebp), %edx /* Load parent ip (2nd parameter) */
930 movl function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */
931 pushl %esp /* Save pt_regs as 4th parameter */
933 GLOBAL(ftrace_regs_call)
936 addl $4, %esp /* Skip pt_regs */
937 movl 14*4(%esp), %eax /* Move flags back into cs */
938 movl %eax, 13*4(%esp) /* Needed to keep addl from modifying flags */
939 movl 12*4(%esp), %eax /* Get return ip from regs->ip */
940 movl %eax, 14*4(%esp) /* Put return ip back for ret */
953 addl $8, %esp /* Skip orig_ax and ip */
954 popf /* Pop flags at end (no addl to corrupt flags) */
959 #else /* ! CONFIG_DYNAMIC_FTRACE */
962 cmpl $__PAGE_OFFSET, %esp
963 jb ftrace_stub /* Paging not enabled yet? */
965 cmpl $ftrace_stub, ftrace_trace_function
967 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
968 cmpl $ftrace_stub, ftrace_graph_return
969 jnz ftrace_graph_caller
971 cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
972 jnz ftrace_graph_caller
978 /* taken from glibc */
985 subl $MCOUNT_INSN_SIZE, %eax
987 call *ftrace_trace_function
994 #endif /* CONFIG_DYNAMIC_FTRACE */
995 EXPORT_SYMBOL(mcount)
996 #endif /* CONFIG_FUNCTION_TRACER */
998 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
999 ENTRY(ftrace_graph_caller)
1003 movl 0xc(%esp), %eax
1006 subl $MCOUNT_INSN_SIZE, %eax
1007 call prepare_ftrace_return
1012 END(ftrace_graph_caller)
1014 .globl return_to_handler
1019 call ftrace_return_to_handler
1026 #ifdef CONFIG_TRACING
1027 ENTRY(trace_page_fault)
1029 pushl $trace_do_page_fault
1031 END(trace_page_fault)
1036 pushl $do_page_fault
1039 /* the function address is in %gs's slot on the stack */
1051 movl $(__KERNEL_PERCPU), %ecx
1055 movl PT_GS(%esp), %edi # get the function address
1056 movl PT_ORIG_EAX(%esp), %edx # get the error code
1057 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
1060 movl $(__USER_DS), %ecx
1064 movl %esp, %eax # pt_regs pointer
1066 jmp ret_from_exception
1071 * #DB can happen at the first instruction of
1072 * entry_SYSENTER_32 or in Xen's SYSENTER prologue. If this
1073 * happens, then we will be running on a very small stack. We
1074 * need to detect this condition and switch to the thread
1075 * stack before calling any C code at all.
1077 * If you edit this code, keep in mind that NMIs can happen in here.
1080 pushl $-1 # mark this as an int
1082 xorl %edx, %edx # error code 0
1083 movl %esp, %eax # pt_regs pointer
1085 /* Are we currently on the SYSENTER stack? */
1086 PER_CPU(cpu_tss + CPU_TSS_SYSENTER_stack + SIZEOF_SYSENTER_stack, %ecx)
1087 subl %eax, %ecx /* ecx = (end of SYSENTER_stack) - esp */
1088 cmpl $SIZEOF_SYSENTER_stack, %ecx
1089 jb .Ldebug_from_sysenter_stack
1093 jmp ret_from_exception
1095 .Ldebug_from_sysenter_stack:
1096 /* We're on the SYSENTER stack. Switch off. */
1098 movl PER_CPU_VAR(cpu_current_top_of_stack), %esp
1102 jmp ret_from_exception
1106 * NMI is doubly nasty. It can happen on the first instruction of
1107 * entry_SYSENTER_32 (just like #DB), but it can also interrupt the beginning
1108 * of the #DB handler even if that #DB in turn hit before entry_SYSENTER_32
1109 * switched stacks. We handle both conditions by simply checking whether we
1110 * interrupted kernel code running on the SYSENTER stack.
1114 #ifdef CONFIG_X86_ESPFIX32
1117 cmpw $__ESPFIX_SS, %ax
1122 pushl %eax # pt_regs->orig_ax
1124 xorl %edx, %edx # zero error code
1125 movl %esp, %eax # pt_regs pointer
1127 /* Are we currently on the SYSENTER stack? */
1128 PER_CPU(cpu_tss + CPU_TSS_SYSENTER_stack + SIZEOF_SYSENTER_stack, %ecx)
1129 subl %eax, %ecx /* ecx = (end of SYSENTER_stack) - esp */
1130 cmpl $SIZEOF_SYSENTER_stack, %ecx
1131 jb .Lnmi_from_sysenter_stack
1133 /* Not on SYSENTER stack. */
1135 jmp restore_all_notrace
1137 .Lnmi_from_sysenter_stack:
1139 * We're on the SYSENTER stack. Switch off. No one (not even debug)
1140 * is using the thread stack right now, so it's safe for us to use it.
1143 movl PER_CPU_VAR(cpu_current_top_of_stack), %esp
1146 jmp restore_all_notrace
1148 #ifdef CONFIG_X86_ESPFIX32
1151 * create the pointer to lss back
1156 /* copy the iret frame of 12 bytes */
1162 FIXUP_ESPFIX_STACK # %eax == %esp
1163 xorl %edx, %edx # zero error code
1166 lss 12+4(%esp), %esp # back to espfix stack
1173 pushl $-1 # mark this as an int
1176 xorl %edx, %edx # zero error code
1177 movl %esp, %eax # pt_regs pointer
1179 jmp ret_from_exception
1182 ENTRY(general_protection)
1183 pushl $do_general_protection
1185 END(general_protection)
1187 #ifdef CONFIG_KVM_GUEST
1188 ENTRY(async_page_fault)
1190 pushl $do_async_page_fault
1192 END(async_page_fault)
1195 ENTRY(rewind_stack_do_exit)
1196 /* Prevent any naive code from trying to unwind to our caller. */
1199 movl PER_CPU_VAR(cpu_current_top_of_stack), %esi
1200 leal -TOP_OF_KERNEL_STACK_PADDING-PTREGS_SIZE(%esi), %esp
1204 END(rewind_stack_do_exit)