4 #include <linux/kernel.h>
5 #include <asm/segment.h>
6 #include <asm/cmpxchg.h>
10 /* entries in ARCH_DLINFO: */
11 #ifdef CONFIG_IA32_EMULATION
12 # define AT_VECTOR_SIZE_ARCH 2
14 # define AT_VECTOR_SIZE_ARCH 1
17 #define __SAVE(reg,offset) "movq %%" #reg ",(14-" #offset ")*8(%%rsp)\n\t"
18 #define __RESTORE(reg,offset) "movq (14-" #offset ")*8(%%rsp),%%" #reg "\n\t"
20 /* frame pointer must be last for get_wchan */
21 #define SAVE_CONTEXT "pushf ; pushq %%rbp ; movq %%rsi,%%rbp\n\t"
22 #define RESTORE_CONTEXT "movq %%rbp,%%rsi ; popq %%rbp ; popf\t"
24 #define __EXTRA_CLOBBER \
25 ,"rcx","rbx","rdx","r8","r9","r10","r11","r12","r13","r14","r15"
27 /* Save restore flags to clear handle leaking NT */
28 #define switch_to(prev,next,last) \
29 asm volatile(SAVE_CONTEXT \
30 "movq %%rsp,%P[threadrsp](%[prev])\n\t" /* save RSP */ \
31 "movq %P[threadrsp](%[next]),%%rsp\n\t" /* restore RSP */ \
32 "call __switch_to\n\t" \
33 ".globl thread_return\n" \
34 "thread_return:\n\t" \
35 "movq %%gs:%P[pda_pcurrent],%%rsi\n\t" \
36 "movq %P[thread_info](%%rsi),%%r8\n\t" \
37 LOCK_PREFIX "btr %[tif_fork],%P[ti_flags](%%r8)\n\t" \
38 "movq %%rax,%%rdi\n\t" \
39 "jc ret_from_fork\n\t" \
42 : [next] "S" (next), [prev] "D" (prev), \
43 [threadrsp] "i" (offsetof(struct task_struct, thread.rsp)), \
44 [ti_flags] "i" (offsetof(struct thread_info, flags)),\
45 [tif_fork] "i" (TIF_FORK), \
46 [thread_info] "i" (offsetof(struct task_struct, stack)), \
47 [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent)) \
48 : "memory", "cc" __EXTRA_CLOBBER)
50 extern void load_gs_index(unsigned);
53 * Load a segment. Fall back on loading the zero
54 * segment if something goes wrong..
56 #define loadsegment(seg,value) \
59 "movl %k0,%%" #seg "\n" \
61 ".section .fixup,\"ax\"\n" \
63 "movl %1,%%" #seg "\n\t" \
66 ".section __ex_table,\"a\"\n\t" \
70 : :"r" (value), "r" (0))
73 * Clear and set 'TS' bit respectively
75 #define clts() __asm__ __volatile__ ("clts")
77 static inline unsigned long read_cr0(void)
80 asm volatile("movq %%cr0,%0" : "=r" (cr0));
84 static inline void write_cr0(unsigned long val)
86 asm volatile("movq %0,%%cr0" :: "r" (val));
89 static inline unsigned long read_cr2(void)
92 asm volatile("movq %%cr2,%0" : "=r" (cr2));
96 static inline void write_cr2(unsigned long val)
98 asm volatile("movq %0,%%cr2" :: "r" (val));
101 static inline unsigned long read_cr3(void)
104 asm volatile("movq %%cr3,%0" : "=r" (cr3));
108 static inline void write_cr3(unsigned long val)
110 asm volatile("movq %0,%%cr3" :: "r" (val) : "memory");
113 static inline unsigned long read_cr4(void)
116 asm volatile("movq %%cr4,%0" : "=r" (cr4));
120 static inline void write_cr4(unsigned long val)
122 asm volatile("movq %0,%%cr4" :: "r" (val) : "memory");
125 static inline unsigned long read_cr8(void)
128 asm volatile("movq %%cr8,%0" : "=r" (cr8));
132 static inline void write_cr8(unsigned long val)
134 asm volatile("movq %0,%%cr8" :: "r" (val) : "memory");
137 #define stts() write_cr0(8 | read_cr0())
140 __asm__ __volatile__ ("wbinvd": : :"memory")
142 #endif /* __KERNEL__ */
144 static inline void clflush(volatile void *__p)
146 asm volatile("clflush %0" : "+m" (*(char __force *)__p));
149 #define nop() __asm__ __volatile__ ("nop")
152 #define smp_mb() mb()
153 #define smp_rmb() barrier()
154 #define smp_wmb() barrier()
155 #define smp_read_barrier_depends() do {} while(0)
157 #define smp_mb() barrier()
158 #define smp_rmb() barrier()
159 #define smp_wmb() barrier()
160 #define smp_read_barrier_depends() do {} while(0)
165 * Force strict CPU ordering.
166 * And yes, this is required on UP too when we're talking
169 #define mb() asm volatile("mfence":::"memory")
170 #define rmb() asm volatile("lfence":::"memory")
171 #define wmb() asm volatile("sfence" ::: "memory")
173 #define read_barrier_depends() do {} while(0)
174 #define set_mb(var, value) do { (void) xchg(&var, value); } while (0)
176 #define warn_if_not_ulong(x) do { unsigned long foo; (void) (&(x) == &foo); } while (0)
178 #include <linux/irqflags.h>
180 void cpu_idle_wait(void);
182 extern unsigned long arch_align_stack(unsigned long sp);
183 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);