Char: rocket, fix signed/unsigned warning
[linux-2.6/mini2440.git] / include / asm-x86 / system_64.h
blob4cb23848d4605c436730c353c17c60728af8f373
1 #ifndef __ASM_SYSTEM_H
2 #define __ASM_SYSTEM_H
4 #include <linux/kernel.h>
5 #include <asm/segment.h>
6 #include <asm/cmpxchg.h>
8 #ifdef __KERNEL__
10 #define __SAVE(reg,offset) "movq %%" #reg ",(14-" #offset ")*8(%%rsp)\n\t"
11 #define __RESTORE(reg,offset) "movq (14-" #offset ")*8(%%rsp),%%" #reg "\n\t"
13 /* frame pointer must be last for get_wchan */
14 #define SAVE_CONTEXT "pushf ; pushq %%rbp ; movq %%rsi,%%rbp\n\t"
15 #define RESTORE_CONTEXT "movq %%rbp,%%rsi ; popq %%rbp ; popf\t"
17 #define __EXTRA_CLOBBER \
18 ,"rcx","rbx","rdx","r8","r9","r10","r11","r12","r13","r14","r15"
20 /* Save restore flags to clear handle leaking NT */
21 #define switch_to(prev,next,last) \
22 asm volatile(SAVE_CONTEXT \
23 "movq %%rsp,%P[threadrsp](%[prev])\n\t" /* save RSP */ \
24 "movq %P[threadrsp](%[next]),%%rsp\n\t" /* restore RSP */ \
25 "call __switch_to\n\t" \
26 ".globl thread_return\n" \
27 "thread_return:\n\t" \
28 "movq %%gs:%P[pda_pcurrent],%%rsi\n\t" \
29 "movq %P[thread_info](%%rsi),%%r8\n\t" \
30 LOCK_PREFIX "btr %[tif_fork],%P[ti_flags](%%r8)\n\t" \
31 "movq %%rax,%%rdi\n\t" \
32 "jc ret_from_fork\n\t" \
33 RESTORE_CONTEXT \
34 : "=a" (last) \
35 : [next] "S" (next), [prev] "D" (prev), \
36 [threadrsp] "i" (offsetof(struct task_struct, thread.rsp)), \
37 [ti_flags] "i" (offsetof(struct thread_info, flags)),\
38 [tif_fork] "i" (TIF_FORK), \
39 [thread_info] "i" (offsetof(struct task_struct, stack)), \
40 [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent)) \
41 : "memory", "cc" __EXTRA_CLOBBER)
43 extern void load_gs_index(unsigned);
46 * Load a segment. Fall back on loading the zero
47 * segment if something goes wrong..
49 #define loadsegment(seg,value) \
50 asm volatile("\n" \
51 "1:\t" \
52 "movl %k0,%%" #seg "\n" \
53 "2:\n" \
54 ".section .fixup,\"ax\"\n" \
55 "3:\t" \
56 "movl %1,%%" #seg "\n\t" \
57 "jmp 2b\n" \
58 ".previous\n" \
59 ".section __ex_table,\"a\"\n\t" \
60 ".align 8\n\t" \
61 ".quad 1b,3b\n" \
62 ".previous" \
63 : :"r" (value), "r" (0))
66 * Clear and set 'TS' bit respectively
68 #define clts() __asm__ __volatile__ ("clts")
70 static inline unsigned long read_cr0(void)
72 unsigned long cr0;
73 asm volatile("movq %%cr0,%0" : "=r" (cr0));
74 return cr0;
77 static inline void write_cr0(unsigned long val)
79 asm volatile("movq %0,%%cr0" :: "r" (val));
82 static inline unsigned long read_cr2(void)
84 unsigned long cr2;
85 asm volatile("movq %%cr2,%0" : "=r" (cr2));
86 return cr2;
89 static inline void write_cr2(unsigned long val)
91 asm volatile("movq %0,%%cr2" :: "r" (val));
94 static inline unsigned long read_cr3(void)
96 unsigned long cr3;
97 asm volatile("movq %%cr3,%0" : "=r" (cr3));
98 return cr3;
101 static inline void write_cr3(unsigned long val)
103 asm volatile("movq %0,%%cr3" :: "r" (val) : "memory");
106 static inline unsigned long read_cr4(void)
108 unsigned long cr4;
109 asm volatile("movq %%cr4,%0" : "=r" (cr4));
110 return cr4;
113 static inline void write_cr4(unsigned long val)
115 asm volatile("movq %0,%%cr4" :: "r" (val) : "memory");
118 static inline unsigned long read_cr8(void)
120 unsigned long cr8;
121 asm volatile("movq %%cr8,%0" : "=r" (cr8));
122 return cr8;
125 static inline void write_cr8(unsigned long val)
127 asm volatile("movq %0,%%cr8" :: "r" (val) : "memory");
130 #define stts() write_cr0(8 | read_cr0())
132 #define wbinvd() \
133 __asm__ __volatile__ ("wbinvd": : :"memory")
135 #endif /* __KERNEL__ */
137 static inline void clflush(volatile void *__p)
139 asm volatile("clflush %0" : "+m" (*(char __force *)__p));
142 #define nop() __asm__ __volatile__ ("nop")
144 #ifdef CONFIG_SMP
145 #define smp_mb() mb()
146 #define smp_rmb() barrier()
147 #define smp_wmb() barrier()
148 #define smp_read_barrier_depends() do {} while(0)
149 #else
150 #define smp_mb() barrier()
151 #define smp_rmb() barrier()
152 #define smp_wmb() barrier()
153 #define smp_read_barrier_depends() do {} while(0)
154 #endif
158 * Force strict CPU ordering.
159 * And yes, this is required on UP too when we're talking
160 * to devices.
162 #define mb() asm volatile("mfence":::"memory")
163 #define rmb() asm volatile("lfence":::"memory")
164 #define wmb() asm volatile("sfence" ::: "memory")
166 #define read_barrier_depends() do {} while(0)
167 #define set_mb(var, value) do { (void) xchg(&var, value); } while (0)
169 #define warn_if_not_ulong(x) do { unsigned long foo; (void) (&(x) == &foo); } while (0)
171 #include <linux/irqflags.h>
173 void cpu_idle_wait(void);
175 extern unsigned long arch_align_stack(unsigned long sp);
176 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
178 #endif