diff options
author | Glauber de Oliveira Costa <gcosta@redhat.com> | 2008-01-30 07:31:08 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-01-30 07:31:08 -0500 |
commit | 0a3b4d151a8e57f50ce5a12c7ea5ec9965cf0b5a (patch) | |
tree | d052ba5e4b35484a78d613d3af42e4026b2fc192 | |
parent | 833d8469b102365f427f7791e79ec1843ff5f164 (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>
-rw-r--r-- | include/asm-x86/system.h | 61 | ||||
-rw-r--r-- | include/asm-x86/system_32.h | 31 | ||||
-rw-r--r-- | include/asm-x86/system_64.h | 43 |
3 files changed, 61 insertions, 74 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 | |||
11 | struct task_struct; /* one of the stranger aspects of C forward declarations */ | ||
12 | extern 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 | ||
diff --git a/include/asm-x86/system_32.h b/include/asm-x86/system_32.h index 7da0716fb317..83af46443bd0 100644 --- a/include/asm-x86/system_32.h +++ b/include/asm-x86/system_32.h | |||
@@ -5,37 +5,6 @@ | |||
5 | #include <asm/cpufeature.h> | 5 | #include <asm/cpufeature.h> |
6 | #include <asm/cmpxchg.h> | 6 | #include <asm/cmpxchg.h> |
7 | 7 | ||
8 | #ifdef __KERNEL__ | ||
9 | #define AT_VECTOR_SIZE_ARCH 2 /* entries in ARCH_DLINFO */ | ||
10 | |||
11 | struct task_struct; /* one of the stranger aspects of C forward declarations.. */ | ||
12 | extern struct task_struct * FASTCALL(__switch_to(struct task_struct *prev, struct task_struct *next)); | ||
13 | |||
14 | /* | ||
15 | * Saving eflags is important. It switches not only IOPL between tasks, | ||
16 | * it also protects other tasks from NT leaking through sysenter etc. | ||
17 | */ | ||
18 | #define switch_to(prev,next,last) do { \ | ||
19 | unsigned long esi,edi; \ | ||
20 | asm volatile("pushfl\n\t" /* Save flags */ \ | ||
21 | "pushl %%ebp\n\t" \ | ||
22 | "movl %%esp,%0\n\t" /* save ESP */ \ | ||
23 | "movl %5,%%esp\n\t" /* restore ESP */ \ | ||
24 | "movl $1f,%1\n\t" /* save EIP */ \ | ||
25 | "pushl %6\n\t" /* restore EIP */ \ | ||
26 | "jmp __switch_to\n" \ | ||
27 | "1:\t" \ | ||
28 | "popl %%ebp\n\t" \ | ||
29 | "popfl" \ | ||
30 | :"=m" (prev->thread.sp),"=m" (prev->thread.ip), \ | ||
31 | "=a" (last),"=S" (esi),"=D" (edi) \ | ||
32 | :"m" (next->thread.sp),"m" (next->thread.ip), \ | ||
33 | "2" (prev), "d" (next)); \ | ||
34 | } while (0) | ||
35 | |||
36 | #endif /* __KERNEL__ */ | ||
37 | |||
38 | |||
39 | #include <linux/irqflags.h> | 8 | #include <linux/irqflags.h> |
40 | 9 | ||
41 | /* | 10 | /* |
diff --git a/include/asm-x86/system_64.h b/include/asm-x86/system_64.h index 9def35eb75e3..97fa251ccb2b 100644 --- a/include/asm-x86/system_64.h +++ b/include/asm-x86/system_64.h | |||
@@ -4,49 +4,6 @@ | |||
4 | #include <asm/segment.h> | 4 | #include <asm/segment.h> |
5 | #include <asm/cmpxchg.h> | 5 | #include <asm/cmpxchg.h> |
6 | 6 | ||
7 | #ifdef __KERNEL__ | ||
8 | |||
9 | /* entries in ARCH_DLINFO: */ | ||
10 | #ifdef CONFIG_IA32_EMULATION | ||
11 | # define AT_VECTOR_SIZE_ARCH 2 | ||
12 | #else | ||
13 | # define AT_VECTOR_SIZE_ARCH 1 | ||
14 | #endif | ||
15 | |||
16 | #define __SAVE(reg,offset) "movq %%" #reg ",(14-" #offset ")*8(%%rsp)\n\t" | ||
17 | #define __RESTORE(reg,offset) "movq (14-" #offset ")*8(%%rsp),%%" #reg "\n\t" | ||
18 | |||
19 | /* frame pointer must be last for get_wchan */ | ||
20 | #define SAVE_CONTEXT "pushf ; pushq %%rbp ; movq %%rsi,%%rbp\n\t" | ||
21 | #define RESTORE_CONTEXT "movq %%rbp,%%rsi ; popq %%rbp ; popf\t" | ||
22 | |||
23 | #define __EXTRA_CLOBBER \ | ||
24 | ,"rcx","rbx","rdx","r8","r9","r10","r11","r12","r13","r14","r15" | ||
25 | |||
26 | /* Save restore flags to clear handle leaking NT */ | ||
27 | #define switch_to(prev,next,last) \ | ||
28 | asm volatile(SAVE_CONTEXT \ | ||
29 | "movq %%rsp,%P[threadrsp](%[prev])\n\t" /* save RSP */ \ | ||
30 | "movq %P[threadrsp](%[next]),%%rsp\n\t" /* restore RSP */ \ | ||
31 | "call __switch_to\n\t" \ | ||
32 | ".globl thread_return\n" \ | ||
33 | "thread_return:\n\t" \ | ||
34 | "movq %%gs:%P[pda_pcurrent],%%rsi\n\t" \ | ||
35 | "movq %P[thread_info](%%rsi),%%r8\n\t" \ | ||
36 | LOCK_PREFIX "btr %[tif_fork],%P[ti_flags](%%r8)\n\t" \ | ||
37 | "movq %%rax,%%rdi\n\t" \ | ||
38 | "jc ret_from_fork\n\t" \ | ||
39 | RESTORE_CONTEXT \ | ||
40 | : "=a" (last) \ | ||
41 | : [next] "S" (next), [prev] "D" (prev), \ | ||
42 | [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \ | ||
43 | [ti_flags] "i" (offsetof(struct thread_info, flags)),\ | ||
44 | [tif_fork] "i" (TIF_FORK), \ | ||
45 | [thread_info] "i" (offsetof(struct task_struct, stack)), \ | ||
46 | [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent)) \ | ||
47 | : "memory", "cc" __EXTRA_CLOBBER) | ||
48 | |||
49 | #endif /* __KERNEL__ */ | ||
50 | 7 | ||
51 | static inline unsigned long read_cr8(void) | 8 | static inline unsigned long read_cr8(void) |
52 | { | 9 | { |