1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_SWITCH_TO_H
3 #define _ASM_X86_SWITCH_TO_H
5 #include <linux/sched/task_stack.h>
7 struct task_struct; /* one of the stranger aspects of C forward declarations */
9 struct task_struct *__switch_to_asm(struct task_struct *prev,
10 struct task_struct *next);
12 __visible struct task_struct *__switch_to(struct task_struct *prev,
13 struct task_struct *next);
15 asmlinkage void ret_from_fork_asm(void);
16 __visible void ret_from_fork(struct task_struct *prev, struct pt_regs *regs,
17 int (*fn)(void *), void *fn_arg);
20 * This is the structure pointed to by thread.sp for an inactive task. The
21 * order of the fields must match the code in __switch_to_asm().
23 struct inactive_task_frame {
37 * These two fields must be together. They form a stack frame header,
38 * needed by get_frame_pointer().
41 unsigned long ret_addr;
45 struct inactive_task_frame frame;
49 #define switch_to(prev, next, last) \
51 ((last) = __switch_to_asm((prev), (next))); \
55 static inline void refresh_sysenter_cs(struct thread_struct *thread)
57 /* Only happens when SEP is enabled, no need to test "SEP"arately: */
58 if (unlikely(this_cpu_read(cpu_tss_rw.x86_tss.ss1) == thread->sysenter_cs))
61 this_cpu_write(cpu_tss_rw.x86_tss.ss1, thread->sysenter_cs);
62 wrmsr(MSR_IA32_SYSENTER_CS, thread->sysenter_cs, 0);
66 /* This is used when switching tasks or entering/exiting vm86 mode. */
67 static inline void update_task_stack(struct task_struct *task)
69 /* sp0 always points to the entry trampoline stack, which is constant: */
71 this_cpu_write(cpu_tss_rw.x86_tss.sp1, task->thread.sp0);
73 /* Xen PV enters the kernel on the thread stack. */
74 if (cpu_feature_enabled(X86_FEATURE_XENPV))
75 load_sp0(task_top_of_stack(task));
79 static inline void kthread_frame_init(struct inactive_task_frame *frame,
80 int (*fun)(void *), void *arg)
82 frame->bx = (unsigned long)fun;
84 frame->di = (unsigned long)arg;
86 frame->r12 = (unsigned long)arg;
90 #endif /* _ASM_X86_SWITCH_TO_H */