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 <asm/thread_info.h>
46 #include <asm/irqflags.h>
47 #include <asm/errno.h>
48 #include <asm/segment.h>
50 #include <asm/page_types.h>
51 #include <asm/percpu.h>
52 #include <asm/dwarf2.h>
53 #include <asm/processor-flags.h>
54 #include <asm/ftrace.h>
55 #include <asm/irq_vectors.h>
56 #include <asm/cpufeature.h>
58 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
59 #include <linux/elf-em.h>
60 #define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)
61 #define __AUDIT_ARCH_LE 0x40000000
63 #ifndef CONFIG_AUDITSYSCALL
64 #define sysenter_audit syscall_trace_entry
65 #define sysexit_audit syscall_exit_work
69 * We use macros for low-level operations which need to be overridden
70 * for paravirtualization. The following will never clobber any registers:
71 * INTERRUPT_RETURN (aka. "iret")
72 * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
73 * ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
75 * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
76 * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
77 * Allowing a register to be clobbered can shrink the paravirt replacement
78 * enough to patch inline, increasing performance.
81 #define nr_syscalls ((syscall_table_size)/4)
84 #define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
86 #define preempt_stop(clobbers)
87 #define resume_kernel restore_all
90 .macro TRACE_IRQS_IRET
91 #ifdef CONFIG_TRACE_IRQFLAGS
92 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off?
100 #define resume_userspace_sig check_userspace
102 #define resume_userspace_sig resume_userspace
106 * User gs save/restore
108 * %gs is used for userland TLS and kernel only uses it for stack
109 * canary which is required to be at %gs:20 by gcc. Read the comment
110 * at the top of stackprotector.h for more info.
112 * Local labels 98 and 99 are used.
114 #ifdef CONFIG_X86_32_LAZY_GS
116 /* unfortunately push/pop can't be no-op */
121 addl $(4 + \pop), %esp
122 CFI_ADJUST_CFA_OFFSET -(4 + \pop)
127 /* all the rest are no-op */
134 .macro REG_TO_PTGS reg
136 .macro SET_KERNEL_GS reg
139 #else /* CONFIG_X86_32_LAZY_GS */
143 /*CFI_REL_OFFSET gs, 0*/
151 CFI_ADJUST_CFA_OFFSET -\pop
155 .pushsection .fixup, "ax"
158 .section __ex_table, "a"
165 98: mov PT_GS(%esp), %gs
168 .pushsection .fixup, "ax"
169 99: movl $0, PT_GS(%esp)
171 .section __ex_table, "a"
179 /*CFI_REGISTER gs, \reg*/
181 .macro REG_TO_PTGS reg
182 movl \reg, PT_GS(%esp)
183 /*CFI_REL_OFFSET gs, PT_GS*/
185 .macro SET_KERNEL_GS reg
186 movl $(__KERNEL_STACK_CANARY), \reg
190 #endif /* CONFIG_X86_32_LAZY_GS */
196 /*CFI_REL_OFFSET fs, 0;*/
198 /*CFI_REL_OFFSET es, 0;*/
200 /*CFI_REL_OFFSET ds, 0;*/
202 CFI_REL_OFFSET eax, 0
204 CFI_REL_OFFSET ebp, 0
206 CFI_REL_OFFSET edi, 0
208 CFI_REL_OFFSET esi, 0
210 CFI_REL_OFFSET edx, 0
212 CFI_REL_OFFSET ecx, 0
214 CFI_REL_OFFSET ebx, 0
215 movl $(__USER_DS), %edx
218 movl $(__KERNEL_PERCPU), %edx
223 .macro RESTORE_INT_REGS
240 .macro RESTORE_REGS pop=0
249 .pushsection .fixup, "ax"
256 .section __ex_table, "a"
265 .macro RING0_INT_FRAME
269 /*CFI_OFFSET cs, -2*4;*/
273 .macro RING0_EC_FRAME
277 /*CFI_OFFSET cs, -2*4;*/
281 .macro RING0_PTREGS_FRAME
284 CFI_DEF_CFA esp, PT_OLDESP-PT_EBX
285 /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/
286 CFI_OFFSET eip, PT_EIP-PT_OLDESP
287 /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/
288 /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/
289 CFI_OFFSET eax, PT_EAX-PT_OLDESP
290 CFI_OFFSET ebp, PT_EBP-PT_OLDESP
291 CFI_OFFSET edi, PT_EDI-PT_OLDESP
292 CFI_OFFSET esi, PT_ESI-PT_OLDESP
293 CFI_OFFSET edx, PT_EDX-PT_OLDESP
294 CFI_OFFSET ecx, PT_ECX-PT_OLDESP
295 CFI_OFFSET ebx, PT_EBX-PT_OLDESP
302 GET_THREAD_INFO(%ebp)
304 pushl_cfi $0x0202 # Reset kernel eflags
311 * Interrupt exit functions should be protected against kprobes
313 .pushsection .kprobes.text, "ax"
315 * Return to user mode is not as complex as all this looks,
316 * but we want the default path for a system call return to
317 * go as quickly as possible which is why some of this is
318 * less clear than it otherwise should be.
321 # userspace resumption stub bypassing syscall exit tracing
325 preempt_stop(CLBR_ANY)
327 GET_THREAD_INFO(%ebp)
329 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
330 movb PT_CS(%esp), %al
331 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
333 jb resume_kernel # not returning to v8086 or userspace
335 ENTRY(resume_userspace)
337 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
338 # setting need_resched or sigpending
339 # between sampling and the iret
341 movl TI_flags(%ebp), %ecx
342 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
343 # int/exception return?
346 END(ret_from_exception)
348 #ifdef CONFIG_PREEMPT
350 DISABLE_INTERRUPTS(CLBR_ANY)
351 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
354 movl TI_flags(%ebp), %ecx # need_resched set ?
355 testb $_TIF_NEED_RESCHED, %cl
357 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off (exception path) ?
359 call preempt_schedule_irq
365 * End of kprobes section
369 /* SYSENTER_RETURN points to after the "sysenter" instruction in
370 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
372 # sysenter call handler stub
373 ENTRY(ia32_sysenter_target)
377 CFI_REGISTER esp, ebp
378 movl TSS_sysenter_sp0(%esp),%esp
381 * Interrupts are disabled here, but we can't trace it until
382 * enough kernel state to call TRACE_IRQS_OFF can be called - but
383 * we immediately enable interrupts at that point anyway.
386 /*CFI_REL_OFFSET ss, 0*/
388 CFI_REL_OFFSET esp, 0
390 orl $X86_EFLAGS_IF, (%esp)
392 /*CFI_REL_OFFSET cs, 0*/
394 * Push current_thread_info()->sysenter_return to the stack.
395 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
396 * pushed above; +8 corresponds to copy_thread's esp0 setting.
398 pushl_cfi ((TI_sysenter_return)-THREAD_SIZE_asm+8+4*4)(%esp)
399 CFI_REL_OFFSET eip, 0
403 ENABLE_INTERRUPTS(CLBR_NONE)
406 * Load the potential sixth argument from user stack.
407 * Careful about security.
409 cmpl $__PAGE_OFFSET-3,%ebp
412 movl %ebp,PT_EBP(%esp)
413 .section __ex_table,"a"
415 .long 1b,syscall_fault
418 GET_THREAD_INFO(%ebp)
420 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
423 cmpl $(nr_syscalls), %eax
425 call *sys_call_table(,%eax,4)
426 movl %eax,PT_EAX(%esp)
428 DISABLE_INTERRUPTS(CLBR_ANY)
430 movl TI_flags(%ebp), %ecx
431 testl $_TIF_ALLWORK_MASK, %ecx
434 /* if something modifies registers it must also disable sysexit */
435 movl PT_EIP(%esp), %edx
436 movl PT_OLDESP(%esp), %ecx
439 1: mov PT_FS(%esp), %fs
441 ENABLE_INTERRUPTS_SYSEXIT
443 #ifdef CONFIG_AUDITSYSCALL
445 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
446 jnz syscall_trace_entry
448 CFI_ADJUST_CFA_OFFSET -4
449 /* %esi already in 8(%esp) 6th arg: 4th syscall arg */
450 /* %edx already in 4(%esp) 5th arg: 3rd syscall arg */
451 /* %ecx already in 0(%esp) 4th arg: 2nd syscall arg */
452 movl %ebx,%ecx /* 3rd arg: 1st syscall arg */
453 movl %eax,%edx /* 2nd arg: syscall number */
454 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
455 call audit_syscall_entry
457 movl PT_EAX(%esp),%eax /* reload syscall number */
461 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
462 jne syscall_exit_work
464 ENABLE_INTERRUPTS(CLBR_ANY)
465 movl %eax,%edx /* second arg, syscall return value */
466 cmpl $0,%eax /* is it < 0? */
467 setl %al /* 1 if so, 0 if not */
468 movzbl %al,%eax /* zero-extend that */
469 inc %eax /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
470 call audit_syscall_exit
471 DISABLE_INTERRUPTS(CLBR_ANY)
473 movl TI_flags(%ebp), %ecx
474 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
475 jne syscall_exit_work
476 movl PT_EAX(%esp),%eax /* reload syscall return value */
481 .pushsection .fixup,"ax"
482 2: movl $0,PT_FS(%esp)
484 .section __ex_table,"a"
489 ENDPROC(ia32_sysenter_target)
492 * syscall stub including irq exit should be protected against kprobes
494 .pushsection .kprobes.text, "ax"
495 # system call handler stub
497 RING0_INT_FRAME # can't unwind into user space anyway
498 pushl_cfi %eax # save orig_eax
500 GET_THREAD_INFO(%ebp)
501 # system call tracing in operation / emulation
502 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
503 jnz syscall_trace_entry
504 cmpl $(nr_syscalls), %eax
507 call *sys_call_table(,%eax,4)
508 movl %eax,PT_EAX(%esp) # store the return value
511 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
512 # setting need_resched or sigpending
513 # between sampling and the iret
515 movl TI_flags(%ebp), %ecx
516 testl $_TIF_ALLWORK_MASK, %ecx # current->work
517 jne syscall_exit_work
522 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
523 # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
524 # are returning to the kernel.
525 # See comments in process.c:copy_thread() for details.
526 movb PT_OLDSS(%esp), %ah
527 movb PT_CS(%esp), %al
528 andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
529 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
531 je ldt_ss # returning to user-space with LDT SS
533 RESTORE_REGS 4 # skip orig_eax/error_code
538 pushl $0 # no error code
542 .section __ex_table,"a"
544 .long 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 call do_notify_resume
627 jmp resume_userspace_sig
631 pushl_cfi %ecx # save ti_flags for do_notify_resume
632 call save_v86_state # %eax contains pt_regs pointer
639 call do_notify_resume
640 jmp resume_userspace_sig
643 # perform syscall exit tracing
646 movl $-ENOSYS,PT_EAX(%esp)
648 call syscall_trace_enter
649 /* What it returned is what we'll actually use. */
650 cmpl $(nr_syscalls), %eax
653 END(syscall_trace_entry)
655 # perform syscall exit tracing
658 testl $_TIF_WORK_SYSCALL_EXIT, %ecx
661 ENABLE_INTERRUPTS(CLBR_ANY) # could let syscall_trace_leave() call
664 call syscall_trace_leave
666 END(syscall_exit_work)
669 RING0_INT_FRAME # can't unwind into user space anyway
671 GET_THREAD_INFO(%ebp)
672 movl $-EFAULT,PT_EAX(%esp)
677 movl $-ENOSYS,PT_EAX(%esp)
682 * End of kprobes section
687 * System calls that need a pt_regs pointer.
689 #define PTREGSCALL0(name) \
695 #define PTREGSCALL1(name) \
699 movl (PT_EBX+4)(%esp),%eax; \
702 #define PTREGSCALL2(name) \
706 movl (PT_ECX+4)(%esp),%edx; \
707 movl (PT_EBX+4)(%esp),%eax; \
710 #define PTREGSCALL3(name) \
716 movl PT_EDX(%eax),%ecx; \
717 movl PT_ECX(%eax),%edx; \
718 movl PT_EBX(%eax),%eax; \
721 CFI_ADJUST_CFA_OFFSET -4; \
724 ENDPROC(ptregs_##name)
730 PTREGSCALL2(sigaltstack)
731 PTREGSCALL0(sigreturn)
732 PTREGSCALL0(rt_sigreturn)
736 /* Clone is an oddball. The 4th arg is in %edi */
742 pushl_cfi PT_EDI(%eax)
743 movl PT_EDX(%eax),%ecx
744 movl PT_ECX(%eax),%edx
745 movl PT_EBX(%eax),%eax
748 CFI_ADJUST_CFA_OFFSET -8
751 ENDPROC(ptregs_clone)
753 .macro FIXUP_ESPFIX_STACK
755 * Switch back for ESPFIX stack to the normal zerobased stack
757 * We can't call C functions using the ESPFIX stack. This code reads
758 * the high word of the segment base from the GDT and swiches to the
759 * normal stack and adjusts ESP with the matching offset.
761 /* fixup the stack */
762 mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
763 mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
765 addl %esp, %eax /* the adjusted stack pointer */
766 pushl_cfi $__KERNEL_DS
768 lss (%esp), %esp /* switch to the normal stack segment */
769 CFI_ADJUST_CFA_OFFSET -8
771 .macro UNWIND_ESPFIX_STACK
773 /* see if on espfix stack */
774 cmpw $__ESPFIX_SS, %ax
776 movl $__KERNEL_DS, %eax
779 /* switch to normal stack */
785 * Build the entry stubs and pointer table with some assembler magic.
786 * We pack 7 stubs into a single 32-byte chunk, which will fit in a
787 * single cache line on all modern x86 implementations.
789 .section .init.rodata,"a"
793 .p2align CONFIG_X86_L1_CACHE_SHIFT
794 ENTRY(irq_entries_start)
796 vector=FIRST_EXTERNAL_VECTOR
797 .rept (NR_VECTORS-FIRST_EXTERNAL_VECTOR+6)/7
800 .if vector < NR_VECTORS
801 .if vector <> FIRST_EXTERNAL_VECTOR
802 CFI_ADJUST_CFA_OFFSET -4
804 1: pushl_cfi $(~vector+0x80) /* Note: always in signed byte range */
805 .if ((vector-FIRST_EXTERNAL_VECTOR)%7) <> 6
814 2: jmp common_interrupt
816 END(irq_entries_start)
823 * the CPU automatically disables interrupts when executing an IRQ vector,
824 * so IRQ-flags tracing has to follow that:
826 .p2align CONFIG_X86_L1_CACHE_SHIFT
828 addl $-0x80,(%esp) /* Adjust vector into the [-256,-1] range */
834 ENDPROC(common_interrupt)
838 * Irq entries should be protected against kprobes
840 .pushsection .kprobes.text, "ax"
841 #define BUILD_INTERRUPT3(name, nr, fn) \
853 #define BUILD_INTERRUPT(name, nr) BUILD_INTERRUPT3(name, nr, smp_##name)
855 /* The include is where all of the SMP etc. interrupts come from */
856 #include <asm/entry_arch.h>
858 ENTRY(coprocessor_error)
861 pushl_cfi $do_coprocessor_error
864 END(coprocessor_error)
866 ENTRY(simd_coprocessor_error)
869 #ifdef CONFIG_X86_INVD_BUG
870 /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
871 661: pushl_cfi $do_general_protection
873 .section .altinstructions,"a"
877 .word X86_FEATURE_XMM
881 .section .altinstr_replacement,"ax"
882 663: pushl $do_simd_coprocessor_error
886 pushl_cfi $do_simd_coprocessor_error
890 END(simd_coprocessor_error)
892 ENTRY(device_not_available)
894 pushl_cfi $-1 # mark this as an int
895 pushl_cfi $do_device_not_available
898 END(device_not_available)
900 #ifdef CONFIG_PARAVIRT
903 .section __ex_table,"a"
905 .long native_iret, iret_exc
909 ENTRY(native_irq_enable_sysexit)
912 END(native_irq_enable_sysexit)
918 pushl_cfi $do_overflow
934 pushl_cfi $do_invalid_op
939 ENTRY(coprocessor_segment_overrun)
942 pushl_cfi $do_coprocessor_segment_overrun
945 END(coprocessor_segment_overrun)
949 pushl_cfi $do_invalid_TSS
954 ENTRY(segment_not_present)
956 pushl_cfi $do_segment_not_present
959 END(segment_not_present)
963 pushl_cfi $do_stack_segment
968 ENTRY(alignment_check)
970 pushl_cfi $do_alignment_check
977 pushl_cfi $0 # no error code
978 pushl_cfi $do_divide_error
983 #ifdef CONFIG_X86_MCE
987 pushl_cfi machine_check_vector
993 ENTRY(spurious_interrupt_bug)
996 pushl_cfi $do_spurious_interrupt_bug
999 END(spurious_interrupt_bug)
1001 * End of kprobes section
1005 ENTRY(kernel_thread_helper)
1006 pushl $0 # fake return address for unwinder
1011 ud2 # padding for call trace
1013 ENDPROC(kernel_thread_helper)
1016 /* Xen doesn't set %esp to be precisely what the normal sysenter
1017 entrypoint expects, so fix it up before using the normal path. */
1018 ENTRY(xen_sysenter_target)
1020 addl $5*4, %esp /* remove xen-provided frame */
1021 CFI_ADJUST_CFA_OFFSET -5*4
1022 jmp sysenter_past_esp
1025 ENTRY(xen_hypervisor_callback)
1031 /* Check to see if we got the event in the critical
1032 region in xen_iret_direct, after we've reenabled
1033 events and checked for pending events. This simulates
1034 iret instruction's behaviour where it delivers a
1035 pending interrupt when enabling interrupts. */
1036 movl PT_EIP(%esp),%eax
1037 cmpl $xen_iret_start_crit,%eax
1039 cmpl $xen_iret_end_crit,%eax
1042 jmp xen_iret_crit_fixup
1044 ENTRY(xen_do_upcall)
1046 call xen_evtchn_do_upcall
1049 ENDPROC(xen_hypervisor_callback)
1051 # Hypervisor uses this for application faults while it executes.
1052 # We get here for two reasons:
1053 # 1. Fault while reloading DS, ES, FS or GS
1054 # 2. Fault while executing IRET
1055 # Category 1 we fix up by reattempting the load, and zeroing the segment
1056 # register if the load fails.
1057 # Category 2 we fix up by jumping to do_iret_error. We cannot use the
1058 # normal Linux return path in this case because if we use the IRET hypercall
1059 # to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1060 # We distinguish between categories by maintaining a status value in EAX.
1061 ENTRY(xen_failsafe_callback)
1072 CFI_ADJUST_CFA_OFFSET -16
1075 jmp iret_exc # EAX != 0 => Category 2 (Bad IRET)
1076 5: pushl_cfi $0 # EAX == 0 => Category 1 (Bad segment)
1078 jmp ret_from_exception
1081 .section .fixup,"ax"
1095 .section __ex_table,"a"
1102 ENDPROC(xen_failsafe_callback)
1104 BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
1105 xen_evtchn_do_upcall)
1107 #endif /* CONFIG_XEN */
1109 #ifdef CONFIG_FUNCTION_TRACER
1110 #ifdef CONFIG_DYNAMIC_FTRACE
1116 ENTRY(ftrace_caller)
1117 cmpl $0, function_trace_stop
1123 movl 0xc(%esp), %eax
1124 movl 0x4(%ebp), %edx
1125 subl $MCOUNT_INSN_SIZE, %eax
1134 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1135 .globl ftrace_graph_call
1145 #else /* ! CONFIG_DYNAMIC_FTRACE */
1148 cmpl $0, function_trace_stop
1151 cmpl $ftrace_stub, ftrace_trace_function
1153 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1154 cmpl $ftrace_stub, ftrace_graph_return
1155 jnz ftrace_graph_caller
1157 cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
1158 jnz ftrace_graph_caller
1164 /* taken from glibc */
1169 movl 0xc(%esp), %eax
1170 movl 0x4(%ebp), %edx
1171 subl $MCOUNT_INSN_SIZE, %eax
1173 call *ftrace_trace_function
1180 #endif /* CONFIG_DYNAMIC_FTRACE */
1181 #endif /* CONFIG_FUNCTION_TRACER */
1183 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1184 ENTRY(ftrace_graph_caller)
1185 cmpl $0, function_trace_stop
1191 movl 0xc(%esp), %edx
1194 subl $MCOUNT_INSN_SIZE, %edx
1195 call prepare_ftrace_return
1200 END(ftrace_graph_caller)
1202 .globl return_to_handler
1207 call ftrace_return_to_handler
1214 .section .rodata,"a"
1215 #include "syscall_table_32.S"
1217 syscall_table_size=(.-sys_call_table)
1220 * Some functions should be protected against kprobes
1222 .pushsection .kprobes.text, "ax"
1226 pushl_cfi $do_page_fault
1229 /* the function address is in %gs's slot on the stack */
1231 /*CFI_REL_OFFSET fs, 0*/
1233 /*CFI_REL_OFFSET es, 0*/
1235 /*CFI_REL_OFFSET ds, 0*/
1237 CFI_REL_OFFSET eax, 0
1239 CFI_REL_OFFSET ebp, 0
1241 CFI_REL_OFFSET edi, 0
1243 CFI_REL_OFFSET esi, 0
1245 CFI_REL_OFFSET edx, 0
1247 CFI_REL_OFFSET ecx, 0
1249 CFI_REL_OFFSET ebx, 0
1251 movl $(__KERNEL_PERCPU), %ecx
1255 movl PT_GS(%esp), %edi # get the function address
1256 movl PT_ORIG_EAX(%esp), %edx # get the error code
1257 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
1260 movl $(__USER_DS), %ecx
1264 movl %esp,%eax # pt_regs pointer
1266 jmp ret_from_exception
1271 * Debug traps and NMI can happen at the one SYSENTER instruction
1272 * that sets up the real kernel stack. Check here, since we can't
1273 * allow the wrong stack to be used.
1275 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
1276 * already pushed 3 words if it hits on the sysenter instruction:
1277 * eflags, cs and eip.
1279 * We just load the right stack, and push the three (known) values
1280 * by hand onto the new stack - while updating the return eip past
1281 * the instruction that would have done it for sysenter.
1283 .macro FIX_STACK offset ok label
1284 cmpw $__KERNEL_CS, 4(%esp)
1287 movl TSS_sysenter_sp0 + \offset(%esp), %esp
1291 pushl_cfi $__KERNEL_CS
1292 pushl_cfi $sysenter_past_esp
1293 CFI_REL_OFFSET eip, 0
1298 cmpl $ia32_sysenter_target,(%esp)
1299 jne debug_stack_correct
1300 FIX_STACK 12, debug_stack_correct, debug_esp_fix_insn
1301 debug_stack_correct:
1302 pushl_cfi $-1 # mark this as an int
1305 xorl %edx,%edx # error code 0
1306 movl %esp,%eax # pt_regs pointer
1308 jmp ret_from_exception
1313 * NMI is doubly nasty. It can happen _while_ we're handling
1314 * a debug fault, and the debug fault hasn't yet been able to
1315 * clear up the stack. So we first check whether we got an
1316 * NMI on the sysenter entry path, but after that we need to
1317 * check whether we got an NMI on the debug path where the debug
1318 * fault happened on the sysenter path.
1324 cmpw $__ESPFIX_SS, %ax
1327 cmpl $ia32_sysenter_target,(%esp)
1331 /* Do not access memory above the end of our stack page,
1332 * it might not exist.
1334 andl $(THREAD_SIZE-1),%eax
1335 cmpl $(THREAD_SIZE-20),%eax
1337 jae nmi_stack_correct
1338 cmpl $ia32_sysenter_target,12(%esp)
1339 je nmi_debug_stack_check
1341 /* We have a RING0_INT_FRAME here */
1344 xorl %edx,%edx # zero error code
1345 movl %esp,%eax # pt_regs pointer
1347 jmp restore_all_notrace
1352 FIX_STACK 12, nmi_stack_correct, 1
1353 jmp nmi_stack_correct
1355 nmi_debug_stack_check:
1356 /* We have a RING0_INT_FRAME here */
1357 cmpw $__KERNEL_CS,16(%esp)
1358 jne nmi_stack_correct
1360 jb nmi_stack_correct
1361 cmpl $debug_esp_fix_insn,(%esp)
1362 ja nmi_stack_correct
1363 FIX_STACK 24, nmi_stack_correct, 1
1364 jmp nmi_stack_correct
1367 /* We have a RING0_INT_FRAME here.
1369 * create the pointer to lss back
1374 /* copy the iret frame of 12 bytes */
1380 FIXUP_ESPFIX_STACK # %eax == %esp
1381 xorl %edx,%edx # zero error code
1384 lss 12+4(%esp), %esp # back to espfix stack
1385 CFI_ADJUST_CFA_OFFSET -24
1392 pushl_cfi $-1 # mark this as an int
1395 xorl %edx,%edx # zero error code
1396 movl %esp,%eax # pt_regs pointer
1398 jmp ret_from_exception
1402 ENTRY(general_protection)
1404 pushl_cfi $do_general_protection
1407 END(general_protection)
1409 #ifdef CONFIG_KVM_GUEST
1410 ENTRY(async_page_fault)
1412 pushl $do_async_page_fault
1413 CFI_ADJUST_CFA_OFFSET 4
1420 * End of kprobes section