3 * Copyright (C) 1991, 1992 Linus Torvalds
7 * entry.S contains the system-call and fault low-level handling routines.
8 * This also contains the timer-interrupt handler, as well as all interrupts
9 * and faults that can result in a task-switch.
11 * NOTE: This code handles signal-recognition, which happens every time
12 * after a timer-interrupt and after each system call.
14 * I changed all the .align's to 4 (16 byte alignment), as that's faster
17 * Stack layout in 'syscall_exit':
18 * ptrace needs to have all regs on the stack.
19 * if the order here is changed, it needs to be
20 * updated in fork.c:copy_process, signal.c:do_signal,
21 * ptrace.c and ptrace.h
33 * 28(%esp) - %gs saved iff !CONFIG_X86_32_LAZY_GS
41 * "current" is in register %ebx during any slow entries.
44 #include <linux/linkage.h>
45 #include <linux/err.h>
46 #include <asm/thread_info.h>
47 #include <asm/irqflags.h>
48 #include <asm/errno.h>
49 #include <asm/segment.h>
51 #include <asm/page_types.h>
52 #include <asm/percpu.h>
53 #include <asm/dwarf2.h>
54 #include <asm/processor-flags.h>
55 #include <asm/ftrace.h>
56 #include <asm/irq_vectors.h>
57 #include <asm/cpufeature.h>
58 #include <asm/alternative-asm.h>
62 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
63 #include <linux/elf-em.h>
64 #define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)
65 #define __AUDIT_ARCH_LE 0x40000000
67 #ifndef CONFIG_AUDITSYSCALL
68 #define sysenter_audit syscall_trace_entry
69 #define sysexit_audit syscall_exit_work
72 .section .entry.text, "ax"
75 * We use macros for low-level operations which need to be overridden
76 * for paravirtualization. The following will never clobber any registers:
77 * INTERRUPT_RETURN (aka. "iret")
78 * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
79 * ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
81 * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
82 * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
83 * Allowing a register to be clobbered can shrink the paravirt replacement
84 * enough to patch inline, increasing performance.
88 #define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
90 #define preempt_stop(clobbers)
91 #define resume_kernel restore_all
94 .macro TRACE_IRQS_IRET
95 #ifdef CONFIG_TRACE_IRQFLAGS
96 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off?
104 * User gs save/restore
106 * %gs is used for userland TLS and kernel only uses it for stack
107 * canary which is required to be at %gs:20 by gcc. Read the comment
108 * at the top of stackprotector.h for more info.
110 * Local labels 98 and 99 are used.
112 #ifdef CONFIG_X86_32_LAZY_GS
114 /* unfortunately push/pop can't be no-op */
119 addl $(4 + \pop), %esp
120 CFI_ADJUST_CFA_OFFSET -(4 + \pop)
125 /* all the rest are no-op */
132 .macro REG_TO_PTGS reg
134 .macro SET_KERNEL_GS reg
137 #else /* CONFIG_X86_32_LAZY_GS */
141 /*CFI_REL_OFFSET gs, 0*/
149 CFI_ADJUST_CFA_OFFSET -\pop
153 .pushsection .fixup, "ax"
157 _ASM_EXTABLE(98b,99b)
161 98: mov PT_GS(%esp), %gs
164 .pushsection .fixup, "ax"
165 99: movl $0, PT_GS(%esp)
168 _ASM_EXTABLE(98b,99b)
173 /*CFI_REGISTER gs, \reg*/
175 .macro REG_TO_PTGS reg
176 movl \reg, PT_GS(%esp)
177 /*CFI_REL_OFFSET gs, PT_GS*/
179 .macro SET_KERNEL_GS reg
181 #ifdef CONFIG_CC_STACKPROTECTOR
182 movl $(__KERNEL_STACK_CANARY), \reg
183 #elif defined(CONFIG_PAX_MEMORY_UDEREF)
184 movl $(__USER_DS), \reg
192 #endif /* CONFIG_X86_32_LAZY_GS */
194 .macro pax_enter_kernel
195 #ifdef CONFIG_PAX_KERNEXEC
196 call pax_enter_kernel
200 .macro pax_exit_kernel
201 #ifdef CONFIG_PAX_KERNEXEC
206 #ifdef CONFIG_PAX_KERNEXEC
207 ENTRY(pax_enter_kernel)
208 #ifdef CONFIG_PARAVIRT
211 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
219 cmp $__KERNEL_CS, %esi
221 ljmp $__KERNEL_CS, $3f
222 1: ljmp $__KERNEXEC_KERNEL_CS, $2f
224 #ifdef CONFIG_PARAVIRT
226 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
231 #ifdef CONFIG_PARAVIRT
236 ENDPROC(pax_enter_kernel)
238 ENTRY(pax_exit_kernel)
239 #ifdef CONFIG_PARAVIRT
244 cmp $__KERNEXEC_KERNEL_CS, %esi
246 #ifdef CONFIG_PARAVIRT
247 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
253 ljmp $__KERNEL_CS, $1f
255 #ifdef CONFIG_PARAVIRT
257 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
262 #ifdef CONFIG_PARAVIRT
267 ENDPROC(pax_exit_kernel)
270 .macro pax_erase_kstack
271 #ifdef CONFIG_PAX_MEMORY_STACKLEAK
272 call pax_erase_kstack
276 #ifdef CONFIG_PAX_MEMORY_STACKLEAK
280 ENTRY(pax_erase_kstack)
285 mov TI_lowest_stack(%ebp), %edi
290 and $THREAD_SIZE_asm - 1, %ecx
307 cmp $THREAD_SIZE_asm, %ecx
315 mov TI_task_thread_sp0(%ebp), %edi
317 mov %edi, TI_lowest_stack(%ebp)
323 ENDPROC(pax_erase_kstack)
326 .macro __SAVE_ALL _DS
330 /*CFI_REL_OFFSET fs, 0;*/
332 /*CFI_REL_OFFSET es, 0;*/
334 /*CFI_REL_OFFSET ds, 0;*/
336 CFI_REL_OFFSET eax, 0
338 CFI_REL_OFFSET ebp, 0
340 CFI_REL_OFFSET edi, 0
342 CFI_REL_OFFSET esi, 0
344 CFI_REL_OFFSET edx, 0
346 CFI_REL_OFFSET ecx, 0
348 CFI_REL_OFFSET ebx, 0
352 movl $(__KERNEL_PERCPU), %edx
358 #if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
359 __SAVE_ALL __KERNEL_DS
366 .macro RESTORE_INT_REGS
383 .macro RESTORE_REGS pop=0
392 .pushsection .fixup, "ax"
406 .macro RING0_INT_FRAME
410 /*CFI_OFFSET cs, -2*4;*/
414 .macro RING0_EC_FRAME
418 /*CFI_OFFSET cs, -2*4;*/
422 .macro RING0_PTREGS_FRAME
425 CFI_DEF_CFA esp, PT_OLDESP-PT_EBX
426 /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/
427 CFI_OFFSET eip, PT_EIP-PT_OLDESP
428 /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/
429 /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/
430 CFI_OFFSET eax, PT_EAX-PT_OLDESP
431 CFI_OFFSET ebp, PT_EBP-PT_OLDESP
432 CFI_OFFSET edi, PT_EDI-PT_OLDESP
433 CFI_OFFSET esi, PT_ESI-PT_OLDESP
434 CFI_OFFSET edx, PT_EDX-PT_OLDESP
435 CFI_OFFSET ecx, PT_ECX-PT_OLDESP
436 CFI_OFFSET ebx, PT_EBX-PT_OLDESP
443 GET_THREAD_INFO(%ebp)
445 pushl_cfi $0x0202 # Reset kernel eflags
449 ENDPROC(ret_from_fork)
451 ENTRY(ret_from_kernel_thread)
455 GET_THREAD_INFO(%ebp)
457 pushl_cfi $0x0202 # Reset kernel eflags
459 movl PT_EBP(%esp),%eax
464 ENDPROC(ret_from_kernel_thread)
467 * Interrupt exit functions should be protected against kprobes
469 .pushsection .kprobes.text, "ax"
471 * Return to user mode is not as complex as all this looks,
472 * but we want the default path for a system call return to
473 * go as quickly as possible which is why some of this is
474 * less clear than it otherwise should be.
477 # userspace resumption stub bypassing syscall exit tracing
481 preempt_stop(CLBR_ANY)
483 GET_THREAD_INFO(%ebp)
485 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
486 movb PT_CS(%esp), %al
487 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
490 * We can be coming here from child spawned by kernel_thread().
492 movl PT_CS(%esp), %eax
493 andl $SEGMENT_RPL_MASK, %eax
497 #ifdef CONFIG_PAX_KERNEXEC
503 jb resume_kernel # not returning to v8086 or userspace
506 ENTRY(resume_userspace)
508 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
509 # setting need_resched or sigpending
510 # between sampling and the iret
512 movl TI_flags(%ebp), %ecx
513 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
514 # int/exception return?
517 ENDPROC(ret_from_exception)
519 #ifdef CONFIG_PREEMPT
521 DISABLE_INTERRUPTS(CLBR_ANY)
522 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
525 movl TI_flags(%ebp), %ecx # need_resched set ?
526 testb $_TIF_NEED_RESCHED, %cl
528 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off (exception path) ?
530 call preempt_schedule_irq
532 ENDPROC(resume_kernel)
536 * End of kprobes section
540 /* SYSENTER_RETURN points to after the "sysenter" instruction in
541 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
543 # sysenter call handler stub
544 ENTRY(ia32_sysenter_target)
548 CFI_REGISTER esp, ebp
549 movl TSS_sysenter_sp0(%esp),%esp
552 * Interrupts are disabled here, but we can't trace it until
553 * enough kernel state to call TRACE_IRQS_OFF can be called - but
554 * we immediately enable interrupts at that point anyway.
557 /*CFI_REL_OFFSET ss, 0*/
559 CFI_REL_OFFSET esp, 0
561 orl $X86_EFLAGS_IF, (%esp)
563 /*CFI_REL_OFFSET cs, 0*/
565 * Push current_thread_info()->sysenter_return to the stack.
568 CFI_REL_OFFSET eip, 0
572 GET_THREAD_INFO(%ebp)
573 movl TI_sysenter_return(%ebp),%ebp
574 movl %ebp,PT_EIP(%esp)
575 ENABLE_INTERRUPTS(CLBR_NONE)
578 * Load the potential sixth argument from user stack.
579 * Careful about security.
581 movl PT_OLDESP(%esp),%ebp
583 #ifdef CONFIG_PAX_MEMORY_UDEREF
584 mov PT_OLDSS(%esp),%ds
585 1: movl %ds:(%ebp),%ebp
589 cmpl $__PAGE_OFFSET-3,%ebp
596 movl %ebp,PT_EBP(%esp)
597 _ASM_EXTABLE(1b,syscall_fault)
599 GET_THREAD_INFO(%ebp)
601 #ifdef CONFIG_PAX_RANDKSTACK
605 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
608 cmpl $(NR_syscalls), %eax
610 call *sys_call_table(,%eax,4)
611 movl %eax,PT_EAX(%esp)
614 DISABLE_INTERRUPTS(CLBR_ANY)
616 movl TI_flags(%ebp), %ecx
617 testl $_TIF_ALLWORK_MASK, %ecx
621 #ifdef CONFIG_PAX_RANDKSTACK
624 call pax_randomize_kstack
630 /* if something modifies registers it must also disable sysexit */
631 movl PT_EIP(%esp), %edx
632 movl PT_OLDESP(%esp), %ecx
635 1: mov PT_FS(%esp), %fs
636 2: mov PT_DS(%esp), %ds
637 3: mov PT_ES(%esp), %es
639 ENABLE_INTERRUPTS_SYSEXIT
641 #ifdef CONFIG_AUDITSYSCALL
643 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
644 jnz syscall_trace_entry
646 CFI_ADJUST_CFA_OFFSET -4
647 /* %esi already in 8(%esp) 6th arg: 4th syscall arg */
648 /* %edx already in 4(%esp) 5th arg: 3rd syscall arg */
649 /* %ecx already in 0(%esp) 4th arg: 2nd syscall arg */
650 movl %ebx,%ecx /* 3rd arg: 1st syscall arg */
651 movl %eax,%edx /* 2nd arg: syscall number */
652 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
653 call __audit_syscall_entry
658 movl PT_EAX(%esp),%eax /* reload syscall number */
662 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
663 jne syscall_exit_work
665 ENABLE_INTERRUPTS(CLBR_ANY)
666 movl %eax,%edx /* second arg, syscall return value */
667 cmpl $-MAX_ERRNO,%eax /* is it an error ? */
668 setbe %al /* 1 if so, 0 if not */
669 movzbl %al,%eax /* zero-extend that */
670 call __audit_syscall_exit
671 DISABLE_INTERRUPTS(CLBR_ANY)
673 movl TI_flags(%ebp), %ecx
674 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
675 jne syscall_exit_work
676 movl PT_EAX(%esp),%eax /* reload syscall return value */
681 .pushsection .fixup,"ax"
682 4: movl $0,PT_FS(%esp)
684 5: movl $0,PT_DS(%esp)
686 6: movl $0,PT_ES(%esp)
693 ENDPROC(ia32_sysenter_target)
696 * syscall stub including irq exit should be protected against kprobes
698 .pushsection .kprobes.text, "ax"
699 # system call handler stub
701 RING0_INT_FRAME # can't unwind into user space anyway
703 pushl_cfi %eax # save orig_eax
705 GET_THREAD_INFO(%ebp)
707 #ifdef CONFIG_PAX_RANDKSTACK
711 # system call tracing in operation / emulation
712 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
713 jnz syscall_trace_entry
714 cmpl $(NR_syscalls), %eax
717 call *sys_call_table(,%eax,4)
718 movl %eax,PT_EAX(%esp) # store the return value
721 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
722 # setting need_resched or sigpending
723 # between sampling and the iret
725 movl TI_flags(%ebp), %ecx
726 testl $_TIF_ALLWORK_MASK, %ecx # current->work
727 jne syscall_exit_work
731 #ifdef CONFIG_PAX_RANDKSTACK
733 call pax_randomize_kstack
741 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
742 # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
743 # are returning to the kernel.
744 # See comments in process.c:copy_thread() for details.
745 movb PT_OLDSS(%esp), %ah
746 movb PT_CS(%esp), %al
747 andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
748 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
750 je ldt_ss # returning to user-space with LDT SS
752 RESTORE_REGS 4 # skip orig_eax/error_code
757 pushl $0 # no error code
761 _ASM_EXTABLE(irq_return,iret_exc)
765 #ifdef CONFIG_PARAVIRT
767 * The kernel can't run on a non-flat stack if paravirt mode
768 * is active. Rather than try to fixup the high bits of
769 * ESP, bypass this code entirely. This may break DOSemu
770 * and/or Wine support in a paravirt VM, although the option
771 * is still available to implement the setting of the high
772 * 16-bits in the INTERRUPT_RETURN paravirt-op.
774 cmpl $0, pv_info+PARAVIRT_enabled
779 * Setup and switch to ESPFIX stack
781 * We're returning to userspace with a 16 bit stack. The CPU will not
782 * restore the high word of ESP for us on executing iret... This is an
783 * "official" bug of all the x86-compatible CPUs, which we can work
784 * around to make dosemu and wine happy. We do this by preloading the
785 * high word of ESP with the high word of the userspace ESP while
786 * compensating for the offset by changing to the ESPFIX segment with
787 * a base address that matches for the difference.
789 #define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
790 mov %esp, %edx /* load kernel esp */
791 mov PT_OLDESP(%esp), %eax /* load userspace esp */
792 mov %dx, %ax /* eax: new kernel esp */
793 sub %eax, %edx /* offset (low word is 0) */
795 movl PER_CPU_VAR(cpu_number), %ebx
796 shll $PAGE_SHIFT_asm, %ebx
797 addl $cpu_gdt_table, %ebx
799 movl $cpu_gdt_table, %ebx
803 #ifdef CONFIG_PAX_KERNEXEC
809 mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
810 mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
812 #ifdef CONFIG_PAX_KERNEXEC
817 pushl_cfi $__ESPFIX_SS
818 pushl_cfi %eax /* new kernel esp */
819 /* Disable interrupts, but do not irqtrace this section: we
820 * will soon execute iret and the tracer was already set to
821 * the irqstate after the iret */
822 DISABLE_INTERRUPTS(CLBR_EAX)
823 lss (%esp), %esp /* switch to espfix segment */
824 CFI_ADJUST_CFA_OFFSET -8
829 # perform work that needs to be done immediately before resumption
831 RING0_PTREGS_FRAME # can't unwind into user space anyway
833 testb $_TIF_NEED_RESCHED, %cl
838 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
839 # setting need_resched or sigpending
840 # between sampling and the iret
842 movl TI_flags(%ebp), %ecx
843 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
844 # than syscall tracing?
846 testb $_TIF_NEED_RESCHED, %cl
849 work_notifysig: # deal with pending signals and
850 # notify-resume requests
853 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
854 jne work_notifysig_v86 # returning to kernel-space or
859 ENABLE_INTERRUPTS(CLBR_NONE)
860 movb PT_CS(%esp), %bl
861 andb $SEGMENT_RPL_MASK, %bl
865 call do_notify_resume
871 pushl_cfi %ecx # save ti_flags for do_notify_resume
872 call save_v86_state # %eax contains pt_regs pointer
877 ENDPROC(work_pending)
879 # perform syscall exit tracing
882 movl $-ENOSYS,PT_EAX(%esp)
884 call syscall_trace_enter
888 /* What it returned is what we'll actually use. */
889 cmpl $(NR_syscalls), %eax
892 ENDPROC(syscall_trace_entry)
894 # perform syscall exit tracing
897 testl $_TIF_WORK_SYSCALL_EXIT, %ecx
900 ENABLE_INTERRUPTS(CLBR_ANY) # could let syscall_trace_leave() call
903 call syscall_trace_leave
905 ENDPROC(syscall_exit_work)
908 RING0_INT_FRAME # can't unwind into user space anyway
910 #ifdef CONFIG_PAX_MEMORY_UDEREF
915 GET_THREAD_INFO(%ebp)
916 movl $-EFAULT,PT_EAX(%esp)
918 ENDPROC(syscall_fault)
921 movl $-ENOSYS,PT_EAX(%esp)
923 ENDPROC(syscall_badsys)
926 movl $-ENOSYS,PT_EAX(%esp)
927 jmp sysenter_after_call
928 ENDPROC(syscall_badsys)
931 * End of kprobes section
935 .macro FIXUP_ESPFIX_STACK
937 * Switch back for ESPFIX stack to the normal zerobased stack
939 * We can't call C functions using the ESPFIX stack. This code reads
940 * the high word of the segment base from the GDT and swiches to the
941 * normal stack and adjusts ESP with the matching offset.
943 /* fixup the stack */
945 movl PER_CPU_VAR(cpu_number), %ebx
946 shll $PAGE_SHIFT_asm, %ebx
947 addl $cpu_gdt_table, %ebx
949 movl $cpu_gdt_table, %ebx
951 mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
952 mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
954 addl %esp, %eax /* the adjusted stack pointer */
955 pushl_cfi $__KERNEL_DS
957 lss (%esp), %esp /* switch to the normal stack segment */
958 CFI_ADJUST_CFA_OFFSET -8
960 .macro UNWIND_ESPFIX_STACK
962 /* see if on espfix stack */
963 cmpw $__ESPFIX_SS, %ax
965 movl $__KERNEL_DS, %eax
968 /* switch to normal stack */
974 * Build the entry stubs and pointer table with some assembler magic.
975 * We pack 7 stubs into a single 32-byte chunk, which will fit in a
976 * single cache line on all modern x86 implementations.
978 .section .init.rodata,"a"
980 .section .entry.text, "ax"
982 .p2align CONFIG_X86_L1_CACHE_SHIFT
983 ENTRY(irq_entries_start)
985 vector=FIRST_EXTERNAL_VECTOR
986 .rept (NR_VECTORS-FIRST_EXTERNAL_VECTOR+6)/7
989 .if vector < NR_VECTORS
990 .if vector <> FIRST_EXTERNAL_VECTOR
991 CFI_ADJUST_CFA_OFFSET -4
993 1: pushl_cfi $(~vector+0x80) /* Note: always in signed byte range */
994 .if ((vector-FIRST_EXTERNAL_VECTOR)%7) <> 6
999 .section .entry.text, "ax"
1003 2: jmp common_interrupt
1005 ENDPROC(irq_entries_start)
1012 * the CPU automatically disables interrupts when executing an IRQ vector,
1013 * so IRQ-flags tracing has to follow that:
1015 .p2align CONFIG_X86_L1_CACHE_SHIFT
1018 addl $-0x80,(%esp) /* Adjust vector into the [-256,-1] range */
1024 ENDPROC(common_interrupt)
1028 * Irq entries should be protected against kprobes
1030 .pushsection .kprobes.text, "ax"
1031 #define BUILD_INTERRUPT3(name, nr, fn) \
1040 jmp ret_from_intr; \
1044 #define BUILD_INTERRUPT(name, nr) BUILD_INTERRUPT3(name, nr, smp_##name)
1046 /* The include is where all of the SMP etc. interrupts come from */
1047 #include <asm/entry_arch.h>
1049 ENTRY(coprocessor_error)
1053 pushl_cfi $do_coprocessor_error
1056 ENDPROC(coprocessor_error)
1058 ENTRY(simd_coprocessor_error)
1062 #ifdef CONFIG_X86_INVD_BUG
1063 /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
1064 661: pushl_cfi $do_general_protection
1066 .section .altinstructions,"a"
1067 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
1069 .section .altinstr_replacement,"a"
1070 663: pushl $do_simd_coprocessor_error
1074 pushl_cfi $do_simd_coprocessor_error
1078 ENDPROC(simd_coprocessor_error)
1080 ENTRY(device_not_available)
1083 pushl_cfi $-1 # mark this as an int
1084 pushl_cfi $do_device_not_available
1087 ENDPROC(device_not_available)
1089 #ifdef CONFIG_PARAVIRT
1092 _ASM_EXTABLE(native_iret, iret_exc)
1093 ENDPROC(native_iret)
1095 ENTRY(native_irq_enable_sysexit)
1098 ENDPROC(native_irq_enable_sysexit)
1105 pushl_cfi $do_overflow
1114 pushl_cfi $do_bounds
1123 pushl_cfi $do_invalid_op
1128 ENTRY(coprocessor_segment_overrun)
1132 pushl_cfi $do_coprocessor_segment_overrun
1135 ENDPROC(coprocessor_segment_overrun)
1140 pushl_cfi $do_invalid_TSS
1143 ENDPROC(invalid_TSS)
1145 ENTRY(segment_not_present)
1148 pushl_cfi $do_segment_not_present
1151 ENDPROC(segment_not_present)
1153 ENTRY(stack_segment)
1156 pushl_cfi $do_stack_segment
1159 ENDPROC(stack_segment)
1161 ENTRY(alignment_check)
1164 pushl_cfi $do_alignment_check
1167 ENDPROC(alignment_check)
1172 pushl_cfi $0 # no error code
1173 pushl_cfi $do_divide_error
1176 ENDPROC(divide_error)
1178 #ifdef CONFIG_X86_MCE
1179 ENTRY(machine_check)
1183 pushl_cfi machine_check_vector
1186 ENDPROC(machine_check)
1189 ENTRY(spurious_interrupt_bug)
1193 pushl_cfi $do_spurious_interrupt_bug
1196 ENDPROC(spurious_interrupt_bug)
1198 * End of kprobes section
1203 /* Xen doesn't set %esp to be precisely what the normal sysenter
1204 entrypoint expects, so fix it up before using the normal path. */
1205 ENTRY(xen_sysenter_target)
1207 addl $5*4, %esp /* remove xen-provided frame */
1208 CFI_ADJUST_CFA_OFFSET -5*4
1209 jmp sysenter_past_esp
1212 ENTRY(xen_hypervisor_callback)
1214 pushl_cfi $-1 /* orig_ax = -1 => not a system call */
1218 /* Check to see if we got the event in the critical
1219 region in xen_iret_direct, after we've reenabled
1220 events and checked for pending events. This simulates
1221 iret instruction's behaviour where it delivers a
1222 pending interrupt when enabling interrupts. */
1223 movl PT_EIP(%esp),%eax
1224 cmpl $xen_iret_start_crit,%eax
1226 cmpl $xen_iret_end_crit,%eax
1229 jmp xen_iret_crit_fixup
1231 ENTRY(xen_do_upcall)
1233 call xen_evtchn_do_upcall
1236 ENDPROC(xen_hypervisor_callback)
1238 # Hypervisor uses this for application faults while it executes.
1239 # We get here for two reasons:
1240 # 1. Fault while reloading DS, ES, FS or GS
1241 # 2. Fault while executing IRET
1242 # Category 1 we fix up by reattempting the load, and zeroing the segment
1243 # register if the load fails.
1244 # Category 2 we fix up by jumping to do_iret_error. We cannot use the
1245 # normal Linux return path in this case because if we use the IRET hypercall
1246 # to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1247 # We distinguish between categories by maintaining a status value in EAX.
1248 ENTRY(xen_failsafe_callback)
1256 /* EAX == 0 => Category 1 (Bad segment)
1257 EAX != 0 => Category 2 (Bad IRET) */
1261 CFI_ADJUST_CFA_OFFSET -16
1264 5: pushl_cfi $-1 /* orig_ax = -1 => not a system call */
1266 jmp ret_from_exception
1269 .section .fixup,"ax"
1287 ENDPROC(xen_failsafe_callback)
1289 BUILD_INTERRUPT3(xen_hvm_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
1290 xen_evtchn_do_upcall)
1292 #endif /* CONFIG_XEN */
1294 #if IS_ENABLED(CONFIG_HYPERV)
1296 BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
1297 hyperv_vector_handler)
1299 #endif /* CONFIG_HYPERV */
1301 #ifdef CONFIG_FUNCTION_TRACER
1302 #ifdef CONFIG_DYNAMIC_FTRACE
1308 ENTRY(ftrace_caller)
1309 cmpl $0, function_trace_stop
1315 pushl $0 /* Pass NULL as regs pointer */
1316 movl 4*4(%esp), %eax
1317 movl 0x4(%ebp), %edx
1318 movl function_trace_op, %ecx
1319 subl $MCOUNT_INSN_SIZE, %eax
1325 addl $4,%esp /* skip NULL pointer */
1330 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1331 .globl ftrace_graph_call
1339 ENDPROC(ftrace_caller)
1341 ENTRY(ftrace_regs_caller)
1342 pushf /* push flags before compare (in cs location) */
1343 cmpl $0, function_trace_stop
1344 jne ftrace_restore_flags
1347 * i386 does not save SS and ESP when coming from kernel.
1348 * Instead, to get sp, ®s->sp is used (see ptrace.h).
1349 * Unfortunately, that means eflags must be at the same location
1350 * as the current return ip is. We move the return ip into the
1351 * ip location, and move flags into the return ip location.
1353 pushl 4(%esp) /* save return ip into ip slot */
1355 pushl $0 /* Load 0 into orig_ax */
1368 movl 13*4(%esp), %eax /* Get the saved flags */
1369 movl %eax, 14*4(%esp) /* Move saved flags into regs->flags location */
1370 /* clobbering return ip */
1371 movl $__KERNEL_CS,13*4(%esp)
1373 movl 12*4(%esp), %eax /* Load ip (1st parameter) */
1374 subl $MCOUNT_INSN_SIZE, %eax /* Adjust ip */
1375 movl 0x4(%ebp), %edx /* Load parent ip (2nd parameter) */
1376 movl function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */
1377 pushl %esp /* Save pt_regs as 4th parameter */
1379 GLOBAL(ftrace_regs_call)
1382 addl $4, %esp /* Skip pt_regs */
1383 movl 14*4(%esp), %eax /* Move flags back into cs */
1384 movl %eax, 13*4(%esp) /* Needed to keep addl from modifying flags */
1385 movl 12*4(%esp), %eax /* Get return ip from regs->ip */
1386 movl %eax, 14*4(%esp) /* Put return ip back for ret */
1399 addl $8, %esp /* Skip orig_ax and ip */
1400 popf /* Pop flags at end (no addl to corrupt flags) */
1403 ftrace_restore_flags:
1406 #else /* ! CONFIG_DYNAMIC_FTRACE */
1409 cmpl $0, function_trace_stop
1412 cmpl $ftrace_stub, ftrace_trace_function
1414 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1415 cmpl $ftrace_stub, ftrace_graph_return
1416 jnz ftrace_graph_caller
1418 cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
1419 jnz ftrace_graph_caller
1425 /* taken from glibc */
1430 movl 0xc(%esp), %eax
1431 movl 0x4(%ebp), %edx
1432 subl $MCOUNT_INSN_SIZE, %eax
1434 call *ftrace_trace_function
1441 #endif /* CONFIG_DYNAMIC_FTRACE */
1442 #endif /* CONFIG_FUNCTION_TRACER */
1444 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1445 ENTRY(ftrace_graph_caller)
1449 movl 0xc(%esp), %edx
1452 subl $MCOUNT_INSN_SIZE, %edx
1453 call prepare_ftrace_return
1458 ENDPROC(ftrace_graph_caller)
1460 .globl return_to_handler
1465 call ftrace_return_to_handler
1473 * Some functions should be protected against kprobes
1475 .pushsection .kprobes.text, "ax"
1480 pushl_cfi $do_page_fault
1483 /* the function address is in %gs's slot on the stack */
1485 /*CFI_REL_OFFSET fs, 0*/
1487 /*CFI_REL_OFFSET es, 0*/
1489 /*CFI_REL_OFFSET ds, 0*/
1491 CFI_REL_OFFSET eax, 0
1493 CFI_REL_OFFSET ebp, 0
1495 CFI_REL_OFFSET edi, 0
1497 CFI_REL_OFFSET esi, 0
1499 CFI_REL_OFFSET edx, 0
1501 CFI_REL_OFFSET ecx, 0
1503 CFI_REL_OFFSET ebx, 0
1505 movl $(__KERNEL_PERCPU), %ecx
1509 movl PT_GS(%esp), %edi # get the function address
1510 movl PT_ORIG_EAX(%esp), %edx # get the error code
1511 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
1514 movl $(__KERNEL_DS), %ecx
1521 movl %esp,%eax # pt_regs pointer
1523 jmp ret_from_exception
1528 * Debug traps and NMI can happen at the one SYSENTER instruction
1529 * that sets up the real kernel stack. Check here, since we can't
1530 * allow the wrong stack to be used.
1532 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
1533 * already pushed 3 words if it hits on the sysenter instruction:
1534 * eflags, cs and eip.
1536 * We just load the right stack, and push the three (known) values
1537 * by hand onto the new stack - while updating the return eip past
1538 * the instruction that would have done it for sysenter.
1540 .macro FIX_STACK offset ok label
1541 cmpw $__KERNEL_CS, 4(%esp)
1544 movl TSS_sysenter_sp0 + \offset(%esp), %esp
1548 pushl_cfi $__KERNEL_CS
1549 pushl_cfi $sysenter_past_esp
1550 CFI_REL_OFFSET eip, 0
1556 cmpl $ia32_sysenter_target,(%esp)
1557 jne debug_stack_correct
1558 FIX_STACK 12, debug_stack_correct, debug_esp_fix_insn
1559 debug_stack_correct:
1560 pushl_cfi $-1 # mark this as an int
1563 xorl %edx,%edx # error code 0
1564 movl %esp,%eax # pt_regs pointer
1566 jmp ret_from_exception
1571 * NMI is doubly nasty. It can happen _while_ we're handling
1572 * a debug fault, and the debug fault hasn't yet been able to
1573 * clear up the stack. So we first check whether we got an
1574 * NMI on the sysenter entry path, but after that we need to
1575 * check whether we got an NMI on the debug path where the debug
1576 * fault happened on the sysenter path.
1583 cmpw $__ESPFIX_SS, %ax
1586 cmpl $ia32_sysenter_target,(%esp)
1590 /* Do not access memory above the end of our stack page,
1591 * it might not exist.
1593 andl $(THREAD_SIZE-1),%eax
1594 cmpl $(THREAD_SIZE-20),%eax
1596 jae nmi_stack_correct
1597 cmpl $ia32_sysenter_target,12(%esp)
1598 je nmi_debug_stack_check
1600 /* We have a RING0_INT_FRAME here */
1603 xorl %edx,%edx # zero error code
1604 movl %esp,%eax # pt_regs pointer
1609 jmp restore_all_notrace
1614 FIX_STACK 12, nmi_stack_correct, 1
1615 jmp nmi_stack_correct
1617 nmi_debug_stack_check:
1618 /* We have a RING0_INT_FRAME here */
1619 cmpw $__KERNEL_CS,16(%esp)
1620 jne nmi_stack_correct
1622 jb nmi_stack_correct
1623 cmpl $debug_esp_fix_insn,(%esp)
1624 ja nmi_stack_correct
1625 FIX_STACK 24, nmi_stack_correct, 1
1626 jmp nmi_stack_correct
1629 /* We have a RING0_INT_FRAME here.
1631 * create the pointer to lss back
1636 /* copy the iret frame of 12 bytes */
1642 FIXUP_ESPFIX_STACK # %eax == %esp
1643 xorl %edx,%edx # zero error code
1649 lss 12+4(%esp), %esp # back to espfix stack
1650 CFI_ADJUST_CFA_OFFSET -24
1658 pushl_cfi $-1 # mark this as an int
1661 xorl %edx,%edx # zero error code
1662 movl %esp,%eax # pt_regs pointer
1664 jmp ret_from_exception
1668 ENTRY(general_protection)
1670 pushl_cfi $do_general_protection
1673 ENDPROC(general_protection)
1675 #ifdef CONFIG_KVM_GUEST
1676 ENTRY(async_page_fault)
1679 pushl_cfi $do_async_page_fault
1682 ENDPROC(async_page_fault)
1686 * End of kprobes section