aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-x86/system.h
diff options
context:
space:
mode:
authorGlauber de Oliveira Costa <gcosta@redhat.com>2008-01-30 07:31:08 -0500
committerIngo Molnar <mingo@elte.hu>2008-01-30 07:31:08 -0500
commit0a3b4d151a8e57f50ce5a12c7ea5ec9965cf0b5a (patch)
treed052ba5e4b35484a78d613d3af42e4026b2fc192 /include/asm-x86/system.h
parent833d8469b102365f427f7791e79ec1843ff5f164 (diff)
x86: move switch_to macro to system.h
This patch moves the switch_to() macro to system.h As those macros are fundamentally different between i386 and x86_64, they are enclosed around an ifdef. Signed-off-by: Glauber de Oliveira Costa <gcosta@redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'include/asm-x86/system.h')
-rw-r--r--include/asm-x86/system.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/include/asm-x86/system.h b/include/asm-x86/system.h
index 4c15eb11a917..ba3403f1d020 100644
--- a/include/asm-x86/system.h
+++ b/include/asm-x86/system.h
@@ -6,8 +6,69 @@
6#include <linux/kernel.h> 6#include <linux/kernel.h>
7 7
8#ifdef CONFIG_X86_32 8#ifdef CONFIG_X86_32
9#define AT_VECTOR_SIZE_ARCH 2 /* entries in ARCH_DLINFO */
10
11struct task_struct; /* one of the stranger aspects of C forward declarations */
12extern struct task_struct *FASTCALL(__switch_to(struct task_struct *prev,
13 struct task_struct *next));
14
15/*
16 * Saving eflags is important. It switches not only IOPL between tasks,
17 * it also protects other tasks from NT leaking through sysenter etc.
18 */
19#define switch_to(prev, next, last) do { \
20 unsigned long esi, edi; \
21 asm volatile("pushfl\n\t" /* Save flags */ \
22 "pushl %%ebp\n\t" \
23 "movl %%esp,%0\n\t" /* save ESP */ \
24 "movl %5,%%esp\n\t" /* restore ESP */ \
25 "movl $1f,%1\n\t" /* save EIP */ \
26 "pushl %6\n\t" /* restore EIP */ \
27 "jmp __switch_to\n" \
28 "1:\t" \
29 "popl %%ebp\n\t" \
30 "popfl" \
31 :"=m" (prev->thread.sp), "=m" (prev->thread.ip), \
32 "=a" (last), "=S" (esi), "=D" (edi) \
33 :"m" (next->thread.sp), "m" (next->thread.ip), \
34 "2" (prev), "d" (next)); \
35} while (0)
36
9# include "system_32.h" 37# include "system_32.h"
10#else 38#else
39#define __SAVE(reg, offset) "movq %%" #reg ",(14-" #offset ")*8(%%rsp)\n\t"
40#define __RESTORE(reg, offset) "movq (14-" #offset ")*8(%%rsp),%%" #reg "\n\t"
41
42/* frame pointer must be last for get_wchan */
43#define SAVE_CONTEXT "pushf ; pushq %%rbp ; movq %%rsi,%%rbp\n\t"
44#define RESTORE_CONTEXT "movq %%rbp,%%rsi ; popq %%rbp ; popf\t"
45
46#define __EXTRA_CLOBBER \
47 , "rcx", "rbx", "rdx", "r8", "r9", "r10", "r11", \
48 "r12", "r13", "r14", "r15"
49
50/* Save restore flags to clear handle leaking NT */
51#define switch_to(prev, next, last) \
52 asm volatile(SAVE_CONTEXT \
53 "movq %%rsp,%P[threadrsp](%[prev])\n\t" /* save RSP */ \
54 "movq %P[threadrsp](%[next]),%%rsp\n\t" /* restore RSP */ \
55 "call __switch_to\n\t" \
56 ".globl thread_return\n" \
57 "thread_return:\n\t" \
58 "movq %%gs:%P[pda_pcurrent],%%rsi\n\t" \
59 "movq %P[thread_info](%%rsi),%%r8\n\t" \
60 LOCK_PREFIX "btr %[tif_fork],%P[ti_flags](%%r8)\n\t" \
61 "movq %%rax,%%rdi\n\t" \
62 "jc ret_from_fork\n\t" \
63 RESTORE_CONTEXT \
64 : "=a" (last) \
65 : [next] "S" (next), [prev] "D" (prev), \
66 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
67 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
68 [tif_fork] "i" (TIF_FORK), \
69 [thread_info] "i" (offsetof(struct task_struct, stack)), \
70 [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent)) \
71 : "memory", "cc" __EXTRA_CLOBBER)
11# include "system_64.h" 72# include "system_64.h"
12#endif 73#endif
13 74