2 * linux/arch/x86_64/entry.S
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 * Copyright (C) 2000, 2001, 2002 Andi Kleen SuSE Labs
6 * Copyright (C) 2000 Pavel Machek <pavel@suse.cz>
10 * entry.S contains the system-call and fault low-level handling routines.
12 * NOTE: This code handles signal-recognition, which happens every time
13 * after an interrupt and after each system call.
15 * Normal syscalls and interrupts don't save a full stack frame, this is
16 * only done for syscall tracing, signals or fork/exec et.al.
18 * A note on terminology:
19 * - top of stack: Architecture defined interrupt frame from SS to RIP
20 * at the top of the kernel process stack.
21 * - partial stack frame: partially saved registers upto R11.
22 * - full stack frame: Like partial stack frame, but all register saved.
25 * - CFI macros are used to generate dwarf2 unwind information for better
26 * backtraces. They don't change any code.
27 * - SAVE_ALL/RESTORE_ALL - Save/restore all registers
28 * - SAVE_ARGS/RESTORE_ARGS - Save/restore registers that C functions modify.
29 * There are unfortunately lots of special cases where some registers
30 * not touched. The macro is a big mess that should be cleaned up.
31 * - SAVE_REST/RESTORE_REST - Handle the registers not saved by SAVE_ARGS.
32 * Gives a full stack frame.
33 * - ENTRY/END Define functions in the symbol table.
34 * - FIXUP_TOP_OF_STACK/RESTORE_TOP_OF_STACK - Fix up the hardware stack
35 * frame that is otherwise undefined after a SYSCALL
36 * - TRACE_IRQ_* - Trace hard interrupt state for lock debugging.
37 * - errorentry/paranoidentry/zeroentry - Define exception entry points.
40 #include <linux/linkage.h>
41 #include <asm/segment.h>
42 #include <asm/cache.h>
43 #include <asm/errno.h>
44 #include <asm/dwarf2.h>
45 #include <asm/calling.h>
46 #include <asm/asm-offsets.h>
48 #include <asm/unistd.h>
49 #include <asm/thread_info.h>
50 #include <asm/hw_irq.h>
52 #include <asm/irqflags.h>
53 #include <asm/paravirt.h>
57 #ifndef CONFIG_PREEMPT
58 #define retint_kernel retint_restore_args
61 #ifdef CONFIG_PARAVIRT
62 ENTRY(native_irq_enable_syscall_ret)
63 movq %gs:pda_oldrsp,%rsp
66 #endif /* CONFIG_PARAVIRT */
69 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
70 #ifdef CONFIG_TRACE_IRQFLAGS
71 bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
79 * C code is not supposed to know about undefined top of stack. Every time
80 * a C function with an pt_regs argument is called from the SYSCALL based
81 * fast path FIXUP_TOP_OF_STACK is needed.
82 * RESTORE_TOP_OF_STACK syncs the syscall state after any possible ptregs
86 /* %rsp:at FRAMEEND */
87 .macro FIXUP_TOP_OF_STACK tmp
88 movq %gs:pda_oldrsp,\tmp
90 movq $__USER_DS,SS(%rsp)
91 movq $__USER_CS,CS(%rsp)
93 movq R11(%rsp),\tmp /* get eflags */
94 movq \tmp,EFLAGS(%rsp)
97 .macro RESTORE_TOP_OF_STACK tmp,offset=0
98 movq RSP-\offset(%rsp),\tmp
99 movq \tmp,%gs:pda_oldrsp
100 movq EFLAGS-\offset(%rsp),\tmp
101 movq \tmp,R11-\offset(%rsp)
104 .macro FAKE_STACK_FRAME child_rip
105 /* push in order ss, rsp, eflags, cs, rip */
108 CFI_ADJUST_CFA_OFFSET 8
109 /*CFI_REL_OFFSET ss,0*/
111 CFI_ADJUST_CFA_OFFSET 8
113 pushq $(1<<9) /* eflags - interrupts on */
114 CFI_ADJUST_CFA_OFFSET 8
115 /*CFI_REL_OFFSET rflags,0*/
116 pushq $__KERNEL_CS /* cs */
117 CFI_ADJUST_CFA_OFFSET 8
118 /*CFI_REL_OFFSET cs,0*/
119 pushq \child_rip /* rip */
120 CFI_ADJUST_CFA_OFFSET 8
122 pushq %rax /* orig rax */
123 CFI_ADJUST_CFA_OFFSET 8
126 .macro UNFAKE_STACK_FRAME
128 CFI_ADJUST_CFA_OFFSET -(6*8)
131 .macro CFI_DEFAULT_STACK start=1
137 CFI_DEF_CFA_OFFSET SS+8
139 CFI_REL_OFFSET r15,R15
140 CFI_REL_OFFSET r14,R14
141 CFI_REL_OFFSET r13,R13
142 CFI_REL_OFFSET r12,R12
143 CFI_REL_OFFSET rbp,RBP
144 CFI_REL_OFFSET rbx,RBX
145 CFI_REL_OFFSET r11,R11
146 CFI_REL_OFFSET r10,R10
149 CFI_REL_OFFSET rax,RAX
150 CFI_REL_OFFSET rcx,RCX
151 CFI_REL_OFFSET rdx,RDX
152 CFI_REL_OFFSET rsi,RSI
153 CFI_REL_OFFSET rdi,RDI
154 CFI_REL_OFFSET rip,RIP
155 /*CFI_REL_OFFSET cs,CS*/
156 /*CFI_REL_OFFSET rflags,EFLAGS*/
157 CFI_REL_OFFSET rsp,RSP
158 /*CFI_REL_OFFSET ss,SS*/
161 * A newly forked process directly context switches into this.
166 push kernel_eflags(%rip)
167 CFI_ADJUST_CFA_OFFSET 4
168 popf # reset kernel eflags
169 CFI_ADJUST_CFA_OFFSET -4
171 GET_THREAD_INFO(%rcx)
172 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT),threadinfo_flags(%rcx)
176 testl $3,CS-ARGOFFSET(%rsp) # from kernel_thread?
177 je int_ret_from_sys_call
178 testl $_TIF_IA32,threadinfo_flags(%rcx)
179 jnz int_ret_from_sys_call
180 RESTORE_TOP_OF_STACK %rdi,ARGOFFSET
181 jmp ret_from_sys_call
184 call syscall_trace_leave
185 GET_THREAD_INFO(%rcx)
191 * System call entry. Upto 6 arguments in registers are supported.
193 * SYSCALL does not save anything on the stack and does not change the
199 * rax system call number
201 * rcx return address for syscall/sysret, C arg3
204 * r10 arg3 (--> moved to rcx for C)
207 * r11 eflags for syscall/sysret, temporary for C
208 * r12-r15,rbp,rbx saved by C code, not touched.
210 * Interrupts are off on entry.
211 * Only called from user space.
213 * XXX if we had a free scratch register we could save the RSP into the stack frame
214 * and report it properly in ps. Unfortunately we haven't.
216 * When user can change the frames always force IRET. That is because
217 * it deals with uncanonical addresses better. SYSRET has trouble
218 * with them due to bugs in both AMD and Intel CPUs.
224 CFI_DEF_CFA rsp,PDA_STACKOFFSET
226 /*CFI_REGISTER rflags,r11*/
229 * A hypervisor implementation might want to use a label
230 * after the swapgs, so that it can do the swapgs
231 * for the guest and jump here on syscall.
233 ENTRY(system_call_after_swapgs)
235 movq %rsp,%gs:pda_oldrsp
236 movq %gs:pda_kernelstack,%rsp
238 * No need to follow this irqs off/on section - it's straight
241 ENABLE_INTERRUPTS(CLBR_NONE)
243 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
244 movq %rcx,RIP-ARGOFFSET(%rsp)
245 CFI_REL_OFFSET rip,RIP-ARGOFFSET
246 GET_THREAD_INFO(%rcx)
247 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%rcx)
249 cmpq $__NR_syscall_max,%rax
252 call *sys_call_table(,%rax,8) # XXX: rip relative
253 movq %rax,RAX-ARGOFFSET(%rsp)
255 * Syscall return path ending with SYSRET (fast path)
256 * Has incomplete stack frame and undefined top of stack.
259 movl $_TIF_ALLWORK_MASK,%edi
263 GET_THREAD_INFO(%rcx)
264 DISABLE_INTERRUPTS(CLBR_NONE)
266 movl threadinfo_flags(%rcx),%edx
271 * sysretq will re-enable interrupts:
274 movq RIP-ARGOFFSET(%rsp),%rcx
276 RESTORE_ARGS 0,-ARG_SKIP,1
277 /*CFI_REGISTER rflags,r11*/
278 ENABLE_INTERRUPTS_SYSCALL_RET
281 /* Handle reschedules */
282 /* edx: work, edi: workmask */
284 bt $TIF_NEED_RESCHED,%edx
287 ENABLE_INTERRUPTS(CLBR_NONE)
289 CFI_ADJUST_CFA_OFFSET 8
292 CFI_ADJUST_CFA_OFFSET -8
295 /* Handle a signal */
298 ENABLE_INTERRUPTS(CLBR_NONE)
299 testl $_TIF_DO_NOTIFY_MASK,%edx
302 /* Really a signal */
303 /* edx: work flags (arg3) */
304 leaq do_notify_resume(%rip),%rax
305 leaq -ARGOFFSET(%rsp),%rdi # &pt_regs -> arg1
306 xorl %esi,%esi # oldset -> arg2
307 call ptregscall_common
308 1: movl $_TIF_NEED_RESCHED,%edi
309 /* Use IRET because user could have changed frame. This
310 works because ptregscall_common has called FIXUP_TOP_OF_STACK. */
311 DISABLE_INTERRUPTS(CLBR_NONE)
316 movq $-ENOSYS,RAX-ARGOFFSET(%rsp)
317 jmp ret_from_sys_call
319 /* Do syscall tracing */
322 movq $-ENOSYS,RAX(%rsp)
323 FIXUP_TOP_OF_STACK %rdi
325 call syscall_trace_enter
326 LOAD_ARGS ARGOFFSET /* reload args from stack in case ptrace changed it */
328 cmpq $__NR_syscall_max,%rax
332 movq %r10,%rcx /* fixup for C */
333 call *sys_call_table(,%rax,8)
334 1: movq %rax,RAX-ARGOFFSET(%rsp)
335 /* Use IRET because user could have changed frame */
338 * Syscall return path ending with IRET.
339 * Has correct top of stack, but partial stack frame.
341 .globl int_ret_from_sys_call
342 int_ret_from_sys_call:
343 DISABLE_INTERRUPTS(CLBR_NONE)
345 testl $3,CS-ARGOFFSET(%rsp)
346 je retint_restore_args
347 movl $_TIF_ALLWORK_MASK,%edi
348 /* edi: mask to check */
351 GET_THREAD_INFO(%rcx)
352 movl threadinfo_flags(%rcx),%edx
355 andl $~TS_COMPAT,threadinfo_status(%rcx)
358 /* Either reschedule or signal or syscall exit tracking needed. */
359 /* First do a reschedule test. */
360 /* edx: work, edi: workmask */
362 bt $TIF_NEED_RESCHED,%edx
365 ENABLE_INTERRUPTS(CLBR_NONE)
367 CFI_ADJUST_CFA_OFFSET 8
370 CFI_ADJUST_CFA_OFFSET -8
371 DISABLE_INTERRUPTS(CLBR_NONE)
375 /* handle signals and tracing -- both require a full stack frame */
378 ENABLE_INTERRUPTS(CLBR_NONE)
380 /* Check for syscall exit trace */
381 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP),%edx
384 CFI_ADJUST_CFA_OFFSET 8
385 leaq 8(%rsp),%rdi # &ptregs -> arg1
386 call syscall_trace_leave
388 CFI_ADJUST_CFA_OFFSET -8
389 andl $~(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP),%edi
393 testl $_TIF_DO_NOTIFY_MASK,%edx
395 movq %rsp,%rdi # &ptregs -> arg1
396 xorl %esi,%esi # oldset -> arg2
397 call do_notify_resume
398 1: movl $_TIF_NEED_RESCHED,%edi
401 DISABLE_INTERRUPTS(CLBR_NONE)
408 * Certain special system calls that need to save a complete full stack frame.
411 .macro PTREGSCALL label,func,arg
414 leaq \func(%rip),%rax
415 leaq -ARGOFFSET+8(%rsp),\arg /* 8 for return address */
416 jmp ptregscall_common
422 PTREGSCALL stub_clone, sys_clone, %r8
423 PTREGSCALL stub_fork, sys_fork, %rdi
424 PTREGSCALL stub_vfork, sys_vfork, %rdi
425 PTREGSCALL stub_rt_sigsuspend, sys_rt_sigsuspend, %rdx
426 PTREGSCALL stub_sigaltstack, sys_sigaltstack, %rdx
427 PTREGSCALL stub_iopl, sys_iopl, %rsi
429 ENTRY(ptregscall_common)
431 CFI_ADJUST_CFA_OFFSET -8
432 CFI_REGISTER rip, r11
435 CFI_REGISTER rip, r15
436 FIXUP_TOP_OF_STACK %r11
438 RESTORE_TOP_OF_STACK %r11
440 CFI_REGISTER rip, r11
443 CFI_ADJUST_CFA_OFFSET 8
444 CFI_REL_OFFSET rip, 0
447 END(ptregscall_common)
452 CFI_ADJUST_CFA_OFFSET -8
453 CFI_REGISTER rip, r11
455 FIXUP_TOP_OF_STACK %r11
456 <<<<<<< HEAD:arch/x86/kernel/entry_64.S
459 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/x86/kernel/entry_64.S
461 RESTORE_TOP_OF_STACK %r11
464 jmp int_ret_from_sys_call
469 * sigreturn is special because it needs to restore all registers on return.
470 * This cannot be done with SYSRET, so use the IRET return path instead.
472 ENTRY(stub_rt_sigreturn)
475 CFI_ADJUST_CFA_OFFSET -8
478 FIXUP_TOP_OF_STACK %r11
479 call sys_rt_sigreturn
480 movq %rax,RAX(%rsp) # fixme, this could be done at the higher layer
482 jmp int_ret_from_sys_call
484 END(stub_rt_sigreturn)
487 * initial frame state for interrupts and exceptions
492 CFI_DEF_CFA rsp,SS+8-\ref
493 /*CFI_REL_OFFSET ss,SS-\ref*/
494 CFI_REL_OFFSET rsp,RSP-\ref
495 /*CFI_REL_OFFSET rflags,EFLAGS-\ref*/
496 /*CFI_REL_OFFSET cs,CS-\ref*/
497 CFI_REL_OFFSET rip,RIP-\ref
500 /* initial frame state for interrupts (and exceptions without error code) */
501 #define INTR_FRAME _frame RIP
502 /* initial frame state for exceptions with error code (and interrupts with
503 vector already pushed) */
504 #define XCPT_FRAME _frame ORIG_RAX
507 * Interrupt entry/exit.
509 * Interrupt entry points save only callee clobbered registers in fast path.
511 * Entry runs with interrupts off.
514 /* 0(%rsp): interrupt number */
515 .macro interrupt func
518 leaq -ARGOFFSET(%rsp),%rdi # arg1 for handler
520 CFI_ADJUST_CFA_OFFSET 8
521 CFI_REL_OFFSET rbp, 0
523 CFI_DEF_CFA_REGISTER rbp
527 /* irqcount is used to check if a CPU is already on an interrupt
528 stack or not. While this is essentially redundant with preempt_count
529 it is a little cheaper to use a separate counter in the PDA
530 (short of moving irq_enter into assembly, which would be too
532 1: incl %gs:pda_irqcount
533 cmoveq %gs:pda_irqstackptr,%rsp
534 push %rbp # backlink for old unwinder
536 * We entered an interrupt context - irqs are off:
542 ENTRY(common_interrupt)
545 /* 0(%rsp): oldrsp-ARGOFFSET */
547 DISABLE_INTERRUPTS(CLBR_NONE)
549 decl %gs:pda_irqcount
551 CFI_DEF_CFA_REGISTER rsp
552 CFI_ADJUST_CFA_OFFSET -8
554 GET_THREAD_INFO(%rcx)
555 testl $3,CS-ARGOFFSET(%rsp)
558 /* Interrupt came from user space */
560 * Has a correct top of stack, but a partial stack frame
561 * %rcx: thread info. Interrupts off.
563 retint_with_reschedule:
564 movl $_TIF_WORK_MASK,%edi
567 movl threadinfo_flags(%rcx),%edx
572 retint_swapgs: /* return to user-space */
574 * The iretq could re-enable interrupts:
576 DISABLE_INTERRUPTS(CLBR_ANY)
581 retint_restore_args: /* return to kernel space */
582 DISABLE_INTERRUPTS(CLBR_ANY)
584 * The iretq could re-enable interrupts:
590 <<<<<<< HEAD:arch/x86/kernel/entry_64.S
594 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/x86/kernel/entry_64.S
597 .section __ex_table, "a"
598 .quad irq_return, bad_iret
601 #ifdef CONFIG_PARAVIRT
605 .section __ex_table,"a"
606 .quad native_iret, bad_iret
613 * The iret traps when the %cs or %ss being restored is bogus.
614 * We've lost the original trap vector and error code.
615 * #GPF is the most likely one to get for an invalid selector.
616 * So pretend we completed the iret and took the #GPF in user mode.
618 * We are now running with the kernel GS after exception recovery.
619 * But error_entry expects us to have user GS to match the user %cs,
625 jmp general_protection
629 /* edi: workmask, edx: work */
632 bt $TIF_NEED_RESCHED,%edx
635 ENABLE_INTERRUPTS(CLBR_NONE)
637 CFI_ADJUST_CFA_OFFSET 8
640 CFI_ADJUST_CFA_OFFSET -8
641 GET_THREAD_INFO(%rcx)
642 DISABLE_INTERRUPTS(CLBR_NONE)
647 testl $_TIF_DO_NOTIFY_MASK,%edx
650 ENABLE_INTERRUPTS(CLBR_NONE)
652 movq $-1,ORIG_RAX(%rsp)
653 xorl %esi,%esi # oldset
654 movq %rsp,%rdi # &pt_regs
655 call do_notify_resume
657 DISABLE_INTERRUPTS(CLBR_NONE)
659 movl $_TIF_NEED_RESCHED,%edi
660 GET_THREAD_INFO(%rcx)
663 #ifdef CONFIG_PREEMPT
664 /* Returning to kernel space. Check if we need preemption */
665 /* rcx: threadinfo. interrupts off. */
667 cmpl $0,threadinfo_preempt_count(%rcx)
668 jnz retint_restore_args
669 bt $TIF_NEED_RESCHED,threadinfo_flags(%rcx)
670 jnc retint_restore_args
671 bt $9,EFLAGS-ARGOFFSET(%rsp) /* interrupts off? */
672 jnc retint_restore_args
673 call preempt_schedule_irq
678 END(common_interrupt)
683 .macro apicinterrupt num,func
686 CFI_ADJUST_CFA_OFFSET 8
692 ENTRY(thermal_interrupt)
693 apicinterrupt THERMAL_APIC_VECTOR,smp_thermal_interrupt
694 END(thermal_interrupt)
696 ENTRY(threshold_interrupt)
697 apicinterrupt THRESHOLD_APIC_VECTOR,mce_threshold_interrupt
698 END(threshold_interrupt)
701 ENTRY(reschedule_interrupt)
702 apicinterrupt RESCHEDULE_VECTOR,smp_reschedule_interrupt
703 END(reschedule_interrupt)
705 .macro INVALIDATE_ENTRY num
706 ENTRY(invalidate_interrupt\num)
707 apicinterrupt INVALIDATE_TLB_VECTOR_START+\num,smp_invalidate_interrupt
708 END(invalidate_interrupt\num)
720 ENTRY(call_function_interrupt)
721 apicinterrupt CALL_FUNCTION_VECTOR,smp_call_function_interrupt
722 END(call_function_interrupt)
723 ENTRY(irq_move_cleanup_interrupt)
724 apicinterrupt IRQ_MOVE_CLEANUP_VECTOR,smp_irq_move_cleanup_interrupt
725 END(irq_move_cleanup_interrupt)
728 ENTRY(apic_timer_interrupt)
729 apicinterrupt LOCAL_TIMER_VECTOR,smp_apic_timer_interrupt
730 END(apic_timer_interrupt)
732 ENTRY(error_interrupt)
733 apicinterrupt ERROR_APIC_VECTOR,smp_error_interrupt
736 ENTRY(spurious_interrupt)
737 apicinterrupt SPURIOUS_APIC_VECTOR,smp_spurious_interrupt
738 END(spurious_interrupt)
741 * Exception entry points.
745 pushq $0 /* push error code/oldrax */
746 CFI_ADJUST_CFA_OFFSET 8
747 pushq %rax /* push real oldrax to the rdi slot */
748 CFI_ADJUST_CFA_OFFSET 8
755 .macro errorentry sym
758 CFI_ADJUST_CFA_OFFSET 8
765 /* error code is on the stack already */
766 /* handle NMI like exceptions that can happen everywhere */
767 .macro paranoidentry sym, ist=0, irqtrace=1
771 movl $MSR_GS_BASE,%ecx
779 movq %gs:pda_data_offset, %rbp
782 movq ORIG_RAX(%rsp),%rsi
783 movq $-1,ORIG_RAX(%rsp)
785 subq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
789 addq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
791 DISABLE_INTERRUPTS(CLBR_NONE)
798 * "Paranoid" exit path from exception stack.
799 * Paranoid because this is used by NMIs and cannot take
800 * any kernel state for granted.
801 * We don't do kernel preemption checks here, because only
802 * NMI should be common and it does not enable IRQs and
803 * cannot get reschedule ticks.
805 * "trace" is 0 for the NMI handler only, because irq-tracing
806 * is fundamentally NMI-unsafe. (we cannot change the soft and
807 * hard flags at once, atomically)
809 .macro paranoidexit trace=1
810 /* ebx: no swapgs flag */
812 testl %ebx,%ebx /* swapgs needed? */
813 jnz paranoid_restore\trace
815 jnz paranoid_userspace\trace
816 paranoid_swapgs\trace:
821 paranoid_restore\trace:
824 paranoid_userspace\trace:
825 GET_THREAD_INFO(%rcx)
826 movl threadinfo_flags(%rcx),%ebx
827 andl $_TIF_WORK_MASK,%ebx
828 jz paranoid_swapgs\trace
829 movq %rsp,%rdi /* &pt_regs */
831 movq %rax,%rsp /* switch stack for scheduling */
832 testl $_TIF_NEED_RESCHED,%ebx
833 jnz paranoid_schedule\trace
834 movl %ebx,%edx /* arg3: thread flags */
838 ENABLE_INTERRUPTS(CLBR_NONE)
839 xorl %esi,%esi /* arg2: oldset */
840 movq %rsp,%rdi /* arg1: &pt_regs */
841 call do_notify_resume
842 DISABLE_INTERRUPTS(CLBR_NONE)
846 jmp paranoid_userspace\trace
847 paranoid_schedule\trace:
851 ENABLE_INTERRUPTS(CLBR_ANY)
853 DISABLE_INTERRUPTS(CLBR_ANY)
857 jmp paranoid_userspace\trace
862 * Exception entry point. This expects an error code/orig_rax on the stack
863 * and the exception handler in %rax.
865 KPROBE_ENTRY(error_entry)
868 /* rdi slot contains rax, oldrax contains error code */
871 CFI_ADJUST_CFA_OFFSET (14*8)
873 CFI_REL_OFFSET rsi,RSI
874 movq 14*8(%rsp),%rsi /* load rax from rdi slot */
877 CFI_REL_OFFSET rdx,RDX
879 CFI_REL_OFFSET rcx,RCX
880 movq %rsi,10*8(%rsp) /* store rax */
881 CFI_REL_OFFSET rax,RAX
887 CFI_REL_OFFSET r10,R10
889 CFI_REL_OFFSET r11,R11
891 CFI_REL_OFFSET rbx,RBX
893 CFI_REL_OFFSET rbp,RBP
895 CFI_REL_OFFSET r12,R12
897 CFI_REL_OFFSET r13,R13
899 CFI_REL_OFFSET r14,R14
901 CFI_REL_OFFSET r15,R15
909 CFI_REL_OFFSET rdi,RDI
911 movq ORIG_RAX(%rsp),%rsi /* get error code */
912 movq $-1,ORIG_RAX(%rsp)
914 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
918 DISABLE_INTERRUPTS(CLBR_NONE)
920 GET_THREAD_INFO(%rcx)
924 movl threadinfo_flags(%rcx),%edx
925 movl $_TIF_WORK_MASK,%edi
933 /* There are two places in the kernel that can potentially fault with
934 usergs. Handle them here. The exception handlers after
935 iret run with kernel gs again, so don't set the user space flag.
936 B stepping K8s sometimes report an truncated RIP for IRET
937 exceptions returning to compat mode. Check for these here too. */
938 leaq irq_return(%rip),%rbp
941 movl %ebp,%ebp /* zero extend */
944 cmpq $gs_change,RIP(%rsp)
947 KPROBE_END(error_entry)
949 /* Reload gs selector with exception handling */
950 /* edi: new selector */
954 CFI_ADJUST_CFA_OFFSET 8
955 DISABLE_INTERRUPTS(CLBR_ANY | ~(CLBR_RDI))
959 2: mfence /* workaround */
962 CFI_ADJUST_CFA_OFFSET -8
965 ENDPROC(load_gs_index)
967 .section __ex_table,"a"
969 .quad gs_change,bad_gs
972 /* running with kernelgs */
974 SWAPGS /* switch back to user gs */
981 * Create a kernel thread.
983 * C extern interface:
984 * extern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
986 * asm input arguments:
987 * rdi: fn, rsi: arg, rdx: flags
991 FAKE_STACK_FRAME $child_rip
994 # rdi: flags, rsi: usp, rdx: will be &pt_regs
996 orq kernel_thread_flags(%rip),%rdi
1009 * It isn't worth to check for reschedule here,
1010 * so internally to the x86_64 port you can rely on kernel_thread()
1011 * not to reschedule the child before returning, this avoids the need
1012 * of hacks for example to fork off the per-CPU idle tasks.
1013 * [Hopefully no generic code relies on the reschedule -AK]
1019 ENDPROC(kernel_thread)
1022 pushq $0 # fake return address
1025 * Here we are in the child and the registers are set as they were
1026 * at kernel_thread() invocation in the parent.
1038 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
1040 * C extern interface:
1041 * extern long execve(char *name, char **argv, char **envp)
1043 * asm input arguments:
1044 * rdi: name, rsi: argv, rdx: envp
1046 * We want to fallback into:
1047 <<<<<<< HEAD:arch/x86/kernel/entry_64.S
1048 * extern long sys_execve(char *name, char **argv,char **envp, struct pt_regs regs)
1050 * extern long sys_execve(char *name, char **argv,char **envp, struct pt_regs *regs)
1051 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/x86/kernel/entry_64.S
1053 * do_sys_execve asm fallback arguments:
1054 <<<<<<< HEAD:arch/x86/kernel/entry_64.S
1055 * rdi: name, rsi: argv, rdx: envp, fake frame on the stack
1057 * rdi: name, rsi: argv, rdx: envp, rcx: fake frame on the stack
1058 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/x86/kernel/entry_64.S
1060 ENTRY(kernel_execve)
1064 <<<<<<< HEAD:arch/x86/kernel/entry_64.S
1067 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/x86/kernel/entry_64.S
1069 movq %rax, RAX(%rsp)
1072 je int_ret_from_sys_call
1077 ENDPROC(kernel_execve)
1079 KPROBE_ENTRY(page_fault)
1080 errorentry do_page_fault
1081 KPROBE_END(page_fault)
1083 ENTRY(coprocessor_error)
1084 zeroentry do_coprocessor_error
1085 END(coprocessor_error)
1087 ENTRY(simd_coprocessor_error)
1088 zeroentry do_simd_coprocessor_error
1089 END(simd_coprocessor_error)
1091 ENTRY(device_not_available)
1092 zeroentry math_state_restore
1093 END(device_not_available)
1095 /* runs on exception stack */
1099 CFI_ADJUST_CFA_OFFSET 8
1100 paranoidentry do_debug, DEBUG_STACK
1104 /* runs on exception stack */
1108 CFI_ADJUST_CFA_OFFSET 8
1109 paranoidentry do_nmi, 0, 0
1110 #ifdef CONFIG_TRACE_IRQFLAGS
1121 CFI_ADJUST_CFA_OFFSET 8
1122 paranoidentry do_int3, DEBUG_STACK
1128 zeroentry do_overflow
1136 zeroentry do_invalid_op
1139 ENTRY(coprocessor_segment_overrun)
1140 zeroentry do_coprocessor_segment_overrun
1141 END(coprocessor_segment_overrun)
1144 zeroentry do_reserved
1147 /* runs on exception stack */
1150 paranoidentry do_double_fault
1156 errorentry do_invalid_TSS
1159 ENTRY(segment_not_present)
1160 errorentry do_segment_not_present
1161 END(segment_not_present)
1163 /* runs on exception stack */
1164 ENTRY(stack_segment)
1166 paranoidentry do_stack_segment
1171 KPROBE_ENTRY(general_protection)
1172 errorentry do_general_protection
1173 KPROBE_END(general_protection)
1175 ENTRY(alignment_check)
1176 errorentry do_alignment_check
1177 END(alignment_check)
1180 zeroentry do_divide_error
1183 ENTRY(spurious_interrupt_bug)
1184 zeroentry do_spurious_interrupt_bug
1185 END(spurious_interrupt_bug)
1187 #ifdef CONFIG_X86_MCE
1188 /* runs on exception stack */
1189 ENTRY(machine_check)
1192 CFI_ADJUST_CFA_OFFSET 8
1193 paranoidentry do_machine_check
1199 /* Call softirq on interrupt stack. Interrupts are off. */
1203 CFI_ADJUST_CFA_OFFSET 8
1204 CFI_REL_OFFSET rbp,0
1206 CFI_DEF_CFA_REGISTER rbp
1207 incl %gs:pda_irqcount
1208 cmove %gs:pda_irqstackptr,%rsp
1209 push %rbp # backlink for old unwinder
1212 CFI_DEF_CFA_REGISTER rsp
1213 CFI_ADJUST_CFA_OFFSET -8
1214 decl %gs:pda_irqcount
1217 ENDPROC(call_softirq)
1219 KPROBE_ENTRY(ignore_sysret)
1224 ENDPROC(ignore_sysret)