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
180 movl $(__KERNEL_STACK_CANARY), \reg
184 #endif /* CONFIG_X86_32_LAZY_GS */
190 /*CFI_REL_OFFSET fs, 0;*/
192 /*CFI_REL_OFFSET es, 0;*/
194 /*CFI_REL_OFFSET ds, 0;*/
196 CFI_REL_OFFSET eax, 0
198 CFI_REL_OFFSET ebp, 0
200 CFI_REL_OFFSET edi, 0
202 CFI_REL_OFFSET esi, 0
204 CFI_REL_OFFSET edx, 0
206 CFI_REL_OFFSET ecx, 0
208 CFI_REL_OFFSET ebx, 0
209 movl $(__USER_DS), %edx
212 movl $(__KERNEL_PERCPU), %edx
217 .macro RESTORE_INT_REGS
234 .macro RESTORE_REGS pop=0
243 .pushsection .fixup, "ax"
257 .macro RING0_INT_FRAME
261 /*CFI_OFFSET cs, -2*4;*/
265 .macro RING0_EC_FRAME
269 /*CFI_OFFSET cs, -2*4;*/
273 .macro RING0_PTREGS_FRAME
276 CFI_DEF_CFA esp, PT_OLDESP-PT_EBX
277 /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/
278 CFI_OFFSET eip, PT_EIP-PT_OLDESP
279 /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/
280 /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/
281 CFI_OFFSET eax, PT_EAX-PT_OLDESP
282 CFI_OFFSET ebp, PT_EBP-PT_OLDESP
283 CFI_OFFSET edi, PT_EDI-PT_OLDESP
284 CFI_OFFSET esi, PT_ESI-PT_OLDESP
285 CFI_OFFSET edx, PT_EDX-PT_OLDESP
286 CFI_OFFSET ecx, PT_ECX-PT_OLDESP
287 CFI_OFFSET ebx, PT_EBX-PT_OLDESP
294 GET_THREAD_INFO(%ebp)
296 pushl_cfi $0x0202 # Reset kernel eflags
302 ENTRY(ret_from_kernel_execve)
305 GET_THREAD_INFO(%ebp)
307 END(ret_from_kernel_execve)
310 * Interrupt exit functions should be protected against kprobes
312 .pushsection .kprobes.text, "ax"
314 * Return to user mode is not as complex as all this looks,
315 * but we want the default path for a system call return to
316 * go as quickly as possible which is why some of this is
317 * less clear than it otherwise should be.
320 # userspace resumption stub bypassing syscall exit tracing
324 preempt_stop(CLBR_ANY)
326 GET_THREAD_INFO(%ebp)
328 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
329 movb PT_CS(%esp), %al
330 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
333 * We can be coming here from child spawned by kernel_thread().
335 movl PT_CS(%esp), %eax
336 andl $SEGMENT_RPL_MASK, %eax
339 jb resume_kernel # not returning to v8086 or userspace
341 ENTRY(resume_userspace)
343 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
344 # setting need_resched or sigpending
345 # between sampling and the iret
347 movl TI_flags(%ebp), %ecx
348 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
349 # int/exception return?
352 END(ret_from_exception)
354 #ifdef CONFIG_PREEMPT
356 DISABLE_INTERRUPTS(CLBR_ANY)
357 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
360 movl TI_flags(%ebp), %ecx # need_resched set ?
361 testb $_TIF_NEED_RESCHED, %cl
363 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off (exception path) ?
365 call preempt_schedule_irq
371 * End of kprobes section
375 /* SYSENTER_RETURN points to after the "sysenter" instruction in
376 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
378 # sysenter call handler stub
379 ENTRY(ia32_sysenter_target)
383 CFI_REGISTER esp, ebp
384 movl TSS_sysenter_sp0(%esp),%esp
387 * Interrupts are disabled here, but we can't trace it until
388 * enough kernel state to call TRACE_IRQS_OFF can be called - but
389 * we immediately enable interrupts at that point anyway.
392 /*CFI_REL_OFFSET ss, 0*/
394 CFI_REL_OFFSET esp, 0
396 orl $X86_EFLAGS_IF, (%esp)
398 /*CFI_REL_OFFSET cs, 0*/
400 * Push current_thread_info()->sysenter_return to the stack.
401 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
402 * pushed above; +8 corresponds to copy_thread's esp0 setting.
404 pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
405 CFI_REL_OFFSET eip, 0
409 ENABLE_INTERRUPTS(CLBR_NONE)
412 * Load the potential sixth argument from user stack.
413 * Careful about security.
415 cmpl $__PAGE_OFFSET-3,%ebp
420 movl %ebp,PT_EBP(%esp)
421 _ASM_EXTABLE(1b,syscall_fault)
423 GET_THREAD_INFO(%ebp)
425 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
428 cmpl $(NR_syscalls), %eax
430 call *sys_call_table(,%eax,4)
431 movl %eax,PT_EAX(%esp)
433 DISABLE_INTERRUPTS(CLBR_ANY)
435 movl TI_flags(%ebp), %ecx
436 testl $_TIF_ALLWORK_MASK, %ecx
439 /* if something modifies registers it must also disable sysexit */
440 movl PT_EIP(%esp), %edx
441 movl PT_OLDESP(%esp), %ecx
444 1: mov PT_FS(%esp), %fs
446 ENABLE_INTERRUPTS_SYSEXIT
448 #ifdef CONFIG_AUDITSYSCALL
450 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
451 jnz syscall_trace_entry
453 CFI_ADJUST_CFA_OFFSET -4
454 /* %esi already in 8(%esp) 6th arg: 4th syscall arg */
455 /* %edx already in 4(%esp) 5th arg: 3rd syscall arg */
456 /* %ecx already in 0(%esp) 4th arg: 2nd syscall arg */
457 movl %ebx,%ecx /* 3rd arg: 1st syscall arg */
458 movl %eax,%edx /* 2nd arg: syscall number */
459 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
460 call __audit_syscall_entry
462 movl PT_EAX(%esp),%eax /* reload syscall number */
466 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
467 jne syscall_exit_work
469 ENABLE_INTERRUPTS(CLBR_ANY)
470 movl %eax,%edx /* second arg, syscall return value */
471 cmpl $-MAX_ERRNO,%eax /* is it an error ? */
472 setbe %al /* 1 if so, 0 if not */
473 movzbl %al,%eax /* zero-extend that */
474 call __audit_syscall_exit
475 DISABLE_INTERRUPTS(CLBR_ANY)
477 movl TI_flags(%ebp), %ecx
478 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
479 jne syscall_exit_work
480 movl PT_EAX(%esp),%eax /* reload syscall return value */
485 .pushsection .fixup,"ax"
486 2: movl $0,PT_FS(%esp)
491 ENDPROC(ia32_sysenter_target)
494 * syscall stub including irq exit should be protected against kprobes
496 .pushsection .kprobes.text, "ax"
497 # system call handler stub
499 RING0_INT_FRAME # can't unwind into user space anyway
501 pushl_cfi %eax # save orig_eax
503 GET_THREAD_INFO(%ebp)
504 # system call tracing in operation / emulation
505 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
506 jnz syscall_trace_entry
507 cmpl $(NR_syscalls), %eax
510 call *sys_call_table(,%eax,4)
511 movl %eax,PT_EAX(%esp) # store the return value
514 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
515 # setting need_resched or sigpending
516 # between sampling and the iret
518 movl TI_flags(%ebp), %ecx
519 testl $_TIF_ALLWORK_MASK, %ecx # current->work
520 jne syscall_exit_work
525 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
526 # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
527 # are returning to the kernel.
528 # See comments in process.c:copy_thread() for details.
529 movb PT_OLDSS(%esp), %ah
530 movb PT_CS(%esp), %al
531 andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
532 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
534 je ldt_ss # returning to user-space with LDT SS
536 RESTORE_REGS 4 # skip orig_eax/error_code
541 pushl $0 # no error code
545 _ASM_EXTABLE(irq_return,iret_exc)
549 larl PT_OLDSS(%esp), %eax
551 testl $0x00400000, %eax # returning to 32bit stack?
552 jnz restore_nocheck # allright, normal return
554 #ifdef CONFIG_PARAVIRT
556 * The kernel can't run on a non-flat stack if paravirt mode
557 * is active. Rather than try to fixup the high bits of
558 * ESP, bypass this code entirely. This may break DOSemu
559 * and/or Wine support in a paravirt VM, although the option
560 * is still available to implement the setting of the high
561 * 16-bits in the INTERRUPT_RETURN paravirt-op.
563 cmpl $0, pv_info+PARAVIRT_enabled
568 * Setup and switch to ESPFIX stack
570 * We're returning to userspace with a 16 bit stack. The CPU will not
571 * restore the high word of ESP for us on executing iret... This is an
572 * "official" bug of all the x86-compatible CPUs, which we can work
573 * around to make dosemu and wine happy. We do this by preloading the
574 * high word of ESP with the high word of the userspace ESP while
575 * compensating for the offset by changing to the ESPFIX segment with
576 * a base address that matches for the difference.
578 #define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
579 mov %esp, %edx /* load kernel esp */
580 mov PT_OLDESP(%esp), %eax /* load userspace esp */
581 mov %dx, %ax /* eax: new kernel esp */
582 sub %eax, %edx /* offset (low word is 0) */
584 mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
585 mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
586 pushl_cfi $__ESPFIX_SS
587 pushl_cfi %eax /* new kernel esp */
588 /* Disable interrupts, but do not irqtrace this section: we
589 * will soon execute iret and the tracer was already set to
590 * the irqstate after the iret */
591 DISABLE_INTERRUPTS(CLBR_EAX)
592 lss (%esp), %esp /* switch to espfix segment */
593 CFI_ADJUST_CFA_OFFSET -8
598 # perform work that needs to be done immediately before resumption
600 RING0_PTREGS_FRAME # can't unwind into user space anyway
602 testb $_TIF_NEED_RESCHED, %cl
607 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
608 # setting need_resched or sigpending
609 # between sampling and the iret
611 movl TI_flags(%ebp), %ecx
612 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
613 # than syscall tracing?
615 testb $_TIF_NEED_RESCHED, %cl
618 work_notifysig: # deal with pending signals and
619 # notify-resume requests
621 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
623 jne work_notifysig_v86 # returning to kernel-space or
626 ENABLE_INTERRUPTS(CLBR_NONE)
627 movb PT_CS(%esp), %bl
628 andb $SEGMENT_RPL_MASK, %bl
632 call do_notify_resume
637 pushl_cfi %ecx # save ti_flags for do_notify_resume
638 call save_v86_state # %eax contains pt_regs pointer
645 ENABLE_INTERRUPTS(CLBR_NONE)
646 movb PT_CS(%esp), %bl
647 andb $SEGMENT_RPL_MASK, %bl
651 call do_notify_resume
655 # perform syscall exit tracing
658 movl $-ENOSYS,PT_EAX(%esp)
660 call syscall_trace_enter
661 /* What it returned is what we'll actually use. */
662 cmpl $(NR_syscalls), %eax
665 END(syscall_trace_entry)
667 # perform syscall exit tracing
670 testl $_TIF_WORK_SYSCALL_EXIT, %ecx
673 ENABLE_INTERRUPTS(CLBR_ANY) # could let syscall_trace_leave() call
676 call syscall_trace_leave
678 END(syscall_exit_work)
681 RING0_INT_FRAME # can't unwind into user space anyway
684 GET_THREAD_INFO(%ebp)
685 movl $-EFAULT,PT_EAX(%esp)
690 movl $-ENOSYS,PT_EAX(%esp)
695 * End of kprobes section
700 * System calls that need a pt_regs pointer.
702 #define PTREGSCALL0(name) \
703 ENTRY(ptregs_##name) ; \
706 ENDPROC(ptregs_##name)
708 #define PTREGSCALL1(name) \
709 ENTRY(ptregs_##name) ; \
711 movl (PT_EBX+4)(%esp),%eax; \
713 ENDPROC(ptregs_##name)
715 #define PTREGSCALL2(name) \
716 ENTRY(ptregs_##name) ; \
718 movl (PT_ECX+4)(%esp),%edx; \
719 movl (PT_EBX+4)(%esp),%eax; \
721 ENDPROC(ptregs_##name)
723 #define PTREGSCALL3(name) \
724 ENTRY(ptregs_##name) ; \
728 movl PT_EDX(%eax),%ecx; \
729 movl PT_ECX(%eax),%edx; \
730 movl PT_EBX(%eax),%eax; \
733 CFI_ADJUST_CFA_OFFSET -4; \
736 ENDPROC(ptregs_##name)
741 PTREGSCALL2(sigaltstack)
742 PTREGSCALL0(sigreturn)
743 PTREGSCALL0(rt_sigreturn)
747 /* Clone is an oddball. The 4th arg is in %edi */
752 pushl_cfi PT_EDI(%eax)
753 movl PT_EDX(%eax),%ecx
754 movl PT_ECX(%eax),%edx
755 movl PT_EBX(%eax),%eax
758 CFI_ADJUST_CFA_OFFSET -8
761 ENDPROC(ptregs_clone)
763 .macro FIXUP_ESPFIX_STACK
765 * Switch back for ESPFIX stack to the normal zerobased stack
767 * We can't call C functions using the ESPFIX stack. This code reads
768 * the high word of the segment base from the GDT and swiches to the
769 * normal stack and adjusts ESP with the matching offset.
771 /* fixup the stack */
772 mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
773 mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
775 addl %esp, %eax /* the adjusted stack pointer */
776 pushl_cfi $__KERNEL_DS
778 lss (%esp), %esp /* switch to the normal stack segment */
779 CFI_ADJUST_CFA_OFFSET -8
781 .macro UNWIND_ESPFIX_STACK
783 /* see if on espfix stack */
784 cmpw $__ESPFIX_SS, %ax
786 movl $__KERNEL_DS, %eax
789 /* switch to normal stack */
795 * Build the entry stubs and pointer table with some assembler magic.
796 * We pack 7 stubs into a single 32-byte chunk, which will fit in a
797 * single cache line on all modern x86 implementations.
799 .section .init.rodata,"a"
801 .section .entry.text, "ax"
803 .p2align CONFIG_X86_L1_CACHE_SHIFT
804 ENTRY(irq_entries_start)
806 vector=FIRST_EXTERNAL_VECTOR
807 .rept (NR_VECTORS-FIRST_EXTERNAL_VECTOR+6)/7
810 .if vector < NR_VECTORS
811 .if vector <> FIRST_EXTERNAL_VECTOR
812 CFI_ADJUST_CFA_OFFSET -4
814 1: pushl_cfi $(~vector+0x80) /* Note: always in signed byte range */
815 .if ((vector-FIRST_EXTERNAL_VECTOR)%7) <> 6
820 .section .entry.text, "ax"
824 2: jmp common_interrupt
826 END(irq_entries_start)
833 * the CPU automatically disables interrupts when executing an IRQ vector,
834 * so IRQ-flags tracing has to follow that:
836 .p2align CONFIG_X86_L1_CACHE_SHIFT
839 addl $-0x80,(%esp) /* Adjust vector into the [-256,-1] range */
845 ENDPROC(common_interrupt)
849 * Irq entries should be protected against kprobes
851 .pushsection .kprobes.text, "ax"
852 #define BUILD_INTERRUPT3(name, nr, fn) \
865 #define BUILD_INTERRUPT(name, nr) BUILD_INTERRUPT3(name, nr, smp_##name)
867 /* The include is where all of the SMP etc. interrupts come from */
868 #include <asm/entry_arch.h>
870 ENTRY(coprocessor_error)
874 pushl_cfi $do_coprocessor_error
877 END(coprocessor_error)
879 ENTRY(simd_coprocessor_error)
883 #ifdef CONFIG_X86_INVD_BUG
884 /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
885 661: pushl_cfi $do_general_protection
887 .section .altinstructions,"a"
888 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
890 .section .altinstr_replacement,"ax"
891 663: pushl $do_simd_coprocessor_error
895 pushl_cfi $do_simd_coprocessor_error
899 END(simd_coprocessor_error)
901 ENTRY(device_not_available)
904 pushl_cfi $-1 # mark this as an int
905 pushl_cfi $do_device_not_available
908 END(device_not_available)
910 #ifdef CONFIG_PARAVIRT
913 _ASM_EXTABLE(native_iret, iret_exc)
916 ENTRY(native_irq_enable_sysexit)
919 END(native_irq_enable_sysexit)
926 pushl_cfi $do_overflow
944 pushl_cfi $do_invalid_op
949 ENTRY(coprocessor_segment_overrun)
953 pushl_cfi $do_coprocessor_segment_overrun
956 END(coprocessor_segment_overrun)
961 pushl_cfi $do_invalid_TSS
966 ENTRY(segment_not_present)
969 pushl_cfi $do_segment_not_present
972 END(segment_not_present)
977 pushl_cfi $do_stack_segment
982 ENTRY(alignment_check)
985 pushl_cfi $do_alignment_check
993 pushl_cfi $0 # no error code
994 pushl_cfi $do_divide_error
999 #ifdef CONFIG_X86_MCE
1000 ENTRY(machine_check)
1004 pushl_cfi machine_check_vector
1010 ENTRY(spurious_interrupt_bug)
1014 pushl_cfi $do_spurious_interrupt_bug
1017 END(spurious_interrupt_bug)
1019 * End of kprobes section
1023 ENTRY(ret_from_kernel_thread)
1027 GET_THREAD_INFO(%ebp)
1029 pushl_cfi $0x0202 # Reset kernel eflags
1031 movl PT_EBP(%esp),%eax
1034 ud2 # padding for call trace
1036 ENDPROC(ret_from_kernel_thread)
1039 /* Xen doesn't set %esp to be precisely what the normal sysenter
1040 entrypoint expects, so fix it up before using the normal path. */
1041 ENTRY(xen_sysenter_target)
1043 addl $5*4, %esp /* remove xen-provided frame */
1044 CFI_ADJUST_CFA_OFFSET -5*4
1045 jmp sysenter_past_esp
1048 ENTRY(xen_hypervisor_callback)
1054 /* Check to see if we got the event in the critical
1055 region in xen_iret_direct, after we've reenabled
1056 events and checked for pending events. This simulates
1057 iret instruction's behaviour where it delivers a
1058 pending interrupt when enabling interrupts. */
1059 movl PT_EIP(%esp),%eax
1060 cmpl $xen_iret_start_crit,%eax
1062 cmpl $xen_iret_end_crit,%eax
1065 jmp xen_iret_crit_fixup
1067 ENTRY(xen_do_upcall)
1069 call xen_evtchn_do_upcall
1072 ENDPROC(xen_hypervisor_callback)
1074 # Hypervisor uses this for application faults while it executes.
1075 # We get here for two reasons:
1076 # 1. Fault while reloading DS, ES, FS or GS
1077 # 2. Fault while executing IRET
1078 # Category 1 we fix up by reattempting the load, and zeroing the segment
1079 # register if the load fails.
1080 # Category 2 we fix up by jumping to do_iret_error. We cannot use the
1081 # normal Linux return path in this case because if we use the IRET hypercall
1082 # to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1083 # We distinguish between categories by maintaining a status value in EAX.
1084 ENTRY(xen_failsafe_callback)
1095 CFI_ADJUST_CFA_OFFSET -16
1098 jmp iret_exc # EAX != 0 => Category 2 (Bad IRET)
1099 5: pushl_cfi $0 # EAX == 0 => Category 1 (Bad segment)
1101 jmp ret_from_exception
1104 .section .fixup,"ax"
1122 ENDPROC(xen_failsafe_callback)
1124 BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
1125 xen_evtchn_do_upcall)
1127 #endif /* CONFIG_XEN */
1129 #ifdef CONFIG_FUNCTION_TRACER
1130 #ifdef CONFIG_DYNAMIC_FTRACE
1136 ENTRY(ftrace_caller)
1137 cmpl $0, function_trace_stop
1143 pushl $0 /* Pass NULL as regs pointer */
1144 movl 4*4(%esp), %eax
1145 movl 0x4(%ebp), %edx
1146 leal function_trace_op, %ecx
1147 subl $MCOUNT_INSN_SIZE, %eax
1153 addl $4,%esp /* skip NULL pointer */
1158 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1159 .globl ftrace_graph_call
1169 ENTRY(ftrace_regs_caller)
1170 pushf /* push flags before compare (in cs location) */
1171 cmpl $0, function_trace_stop
1172 jne ftrace_restore_flags
1175 * i386 does not save SS and ESP when coming from kernel.
1176 * Instead, to get sp, ®s->sp is used (see ptrace.h).
1177 * Unfortunately, that means eflags must be at the same location
1178 * as the current return ip is. We move the return ip into the
1179 * ip location, and move flags into the return ip location.
1181 pushl 4(%esp) /* save return ip into ip slot */
1183 pushl $0 /* Load 0 into orig_ax */
1196 movl 13*4(%esp), %eax /* Get the saved flags */
1197 movl %eax, 14*4(%esp) /* Move saved flags into regs->flags location */
1198 /* clobbering return ip */
1199 movl $__KERNEL_CS,13*4(%esp)
1201 movl 12*4(%esp), %eax /* Load ip (1st parameter) */
1202 subl $MCOUNT_INSN_SIZE, %eax /* Adjust ip */
1203 movl 0x4(%ebp), %edx /* Load parent ip (2nd parameter) */
1204 leal function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */
1205 pushl %esp /* Save pt_regs as 4th parameter */
1207 GLOBAL(ftrace_regs_call)
1210 addl $4, %esp /* Skip pt_regs */
1211 movl 14*4(%esp), %eax /* Move flags back into cs */
1212 movl %eax, 13*4(%esp) /* Needed to keep addl from modifying flags */
1213 movl 12*4(%esp), %eax /* Get return ip from regs->ip */
1214 movl %eax, 14*4(%esp) /* Put return ip back for ret */
1227 addl $8, %esp /* Skip orig_ax and ip */
1228 popf /* Pop flags at end (no addl to corrupt flags) */
1231 ftrace_restore_flags:
1234 #else /* ! CONFIG_DYNAMIC_FTRACE */
1237 cmpl $0, function_trace_stop
1240 cmpl $ftrace_stub, ftrace_trace_function
1242 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1243 cmpl $ftrace_stub, ftrace_graph_return
1244 jnz ftrace_graph_caller
1246 cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
1247 jnz ftrace_graph_caller
1253 /* taken from glibc */
1258 movl 0xc(%esp), %eax
1259 movl 0x4(%ebp), %edx
1260 subl $MCOUNT_INSN_SIZE, %eax
1262 call *ftrace_trace_function
1269 #endif /* CONFIG_DYNAMIC_FTRACE */
1270 #endif /* CONFIG_FUNCTION_TRACER */
1272 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1273 ENTRY(ftrace_graph_caller)
1277 movl 0xc(%esp), %edx
1280 subl $MCOUNT_INSN_SIZE, %edx
1281 call prepare_ftrace_return
1286 END(ftrace_graph_caller)
1288 .globl return_to_handler
1293 call ftrace_return_to_handler
1301 * Some functions should be protected against kprobes
1303 .pushsection .kprobes.text, "ax"
1308 pushl_cfi $do_page_fault
1311 /* the function address is in %gs's slot on the stack */
1313 /*CFI_REL_OFFSET fs, 0*/
1315 /*CFI_REL_OFFSET es, 0*/
1317 /*CFI_REL_OFFSET ds, 0*/
1319 CFI_REL_OFFSET eax, 0
1321 CFI_REL_OFFSET ebp, 0
1323 CFI_REL_OFFSET edi, 0
1325 CFI_REL_OFFSET esi, 0
1327 CFI_REL_OFFSET edx, 0
1329 CFI_REL_OFFSET ecx, 0
1331 CFI_REL_OFFSET ebx, 0
1333 movl $(__KERNEL_PERCPU), %ecx
1337 movl PT_GS(%esp), %edi # get the function address
1338 movl PT_ORIG_EAX(%esp), %edx # get the error code
1339 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
1342 movl $(__USER_DS), %ecx
1346 movl %esp,%eax # pt_regs pointer
1348 jmp ret_from_exception
1353 * Debug traps and NMI can happen at the one SYSENTER instruction
1354 * that sets up the real kernel stack. Check here, since we can't
1355 * allow the wrong stack to be used.
1357 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
1358 * already pushed 3 words if it hits on the sysenter instruction:
1359 * eflags, cs and eip.
1361 * We just load the right stack, and push the three (known) values
1362 * by hand onto the new stack - while updating the return eip past
1363 * the instruction that would have done it for sysenter.
1365 .macro FIX_STACK offset ok label
1366 cmpw $__KERNEL_CS, 4(%esp)
1369 movl TSS_sysenter_sp0 + \offset(%esp), %esp
1373 pushl_cfi $__KERNEL_CS
1374 pushl_cfi $sysenter_past_esp
1375 CFI_REL_OFFSET eip, 0
1381 cmpl $ia32_sysenter_target,(%esp)
1382 jne debug_stack_correct
1383 FIX_STACK 12, debug_stack_correct, debug_esp_fix_insn
1384 debug_stack_correct:
1385 pushl_cfi $-1 # mark this as an int
1388 xorl %edx,%edx # error code 0
1389 movl %esp,%eax # pt_regs pointer
1391 jmp ret_from_exception
1396 * NMI is doubly nasty. It can happen _while_ we're handling
1397 * a debug fault, and the debug fault hasn't yet been able to
1398 * clear up the stack. So we first check whether we got an
1399 * NMI on the sysenter entry path, but after that we need to
1400 * check whether we got an NMI on the debug path where the debug
1401 * fault happened on the sysenter path.
1408 cmpw $__ESPFIX_SS, %ax
1411 cmpl $ia32_sysenter_target,(%esp)
1415 /* Do not access memory above the end of our stack page,
1416 * it might not exist.
1418 andl $(THREAD_SIZE-1),%eax
1419 cmpl $(THREAD_SIZE-20),%eax
1421 jae nmi_stack_correct
1422 cmpl $ia32_sysenter_target,12(%esp)
1423 je nmi_debug_stack_check
1425 /* We have a RING0_INT_FRAME here */
1428 xorl %edx,%edx # zero error code
1429 movl %esp,%eax # pt_regs pointer
1431 jmp restore_all_notrace
1436 FIX_STACK 12, nmi_stack_correct, 1
1437 jmp nmi_stack_correct
1439 nmi_debug_stack_check:
1440 /* We have a RING0_INT_FRAME here */
1441 cmpw $__KERNEL_CS,16(%esp)
1442 jne nmi_stack_correct
1444 jb nmi_stack_correct
1445 cmpl $debug_esp_fix_insn,(%esp)
1446 ja nmi_stack_correct
1447 FIX_STACK 24, nmi_stack_correct, 1
1448 jmp nmi_stack_correct
1451 /* We have a RING0_INT_FRAME here.
1453 * create the pointer to lss back
1458 /* copy the iret frame of 12 bytes */
1464 FIXUP_ESPFIX_STACK # %eax == %esp
1465 xorl %edx,%edx # zero error code
1468 lss 12+4(%esp), %esp # back to espfix stack
1469 CFI_ADJUST_CFA_OFFSET -24
1477 pushl_cfi $-1 # mark this as an int
1480 xorl %edx,%edx # zero error code
1481 movl %esp,%eax # pt_regs pointer
1483 jmp ret_from_exception
1487 ENTRY(general_protection)
1489 pushl_cfi $do_general_protection
1492 END(general_protection)
1494 #ifdef CONFIG_KVM_GUEST
1495 ENTRY(async_page_fault)
1498 pushl_cfi $do_async_page_fault
1501 END(async_page_fault)
1505 * End of kprobes section