2 Per-processor Data Areas
3 Jeremy Fitzhardinge <jeremy@goop.org> 2006
4 Based on asm-x86_64/pda.h by Andi Kleen.
9 #include <linux/stddef.h>
10 #include <linux/types.h>
14 struct i386_pda *_pda; /* pointer to self */
17 struct task_struct *pcurrent; /* current process */
18 struct pt_regs *irq_regs;
21 extern struct i386_pda *_cpu_pda[];
23 #define cpu_pda(i) (_cpu_pda[i])
25 #define pda_offset(field) offsetof(struct i386_pda, field)
27 extern void __bad_pda_field(void);
29 /* This variable is never instantiated. It is only used as a stand-in
30 for the real per-cpu PDA memory, so that gcc can understand what
31 memory operations the inline asms() below are performing. This
32 eliminates the need to make the asms volatile or have memory
33 clobbers, so gcc can readily analyse them. */
34 extern struct i386_pda _proxy_pda;
36 #define pda_to_op(op,field,val) \
38 typedef typeof(_proxy_pda.field) T__; \
39 if (0) { T__ tmp__; tmp__ = (val); } \
40 switch (sizeof(_proxy_pda.field)) { \
42 asm(op "b %1,%%gs:%c2" \
43 : "+m" (_proxy_pda.field) \
45 "i"(pda_offset(field))); \
48 asm(op "w %1,%%gs:%c2" \
49 : "+m" (_proxy_pda.field) \
51 "i"(pda_offset(field))); \
54 asm(op "l %1,%%gs:%c2" \
55 : "+m" (_proxy_pda.field) \
57 "i"(pda_offset(field))); \
59 default: __bad_pda_field(); \
63 #define pda_from_op(op,field) \
65 typeof(_proxy_pda.field) ret__; \
66 switch (sizeof(_proxy_pda.field)) { \
68 asm(op "b %%gs:%c1,%0" \
70 : "i" (pda_offset(field)), \
71 "m" (_proxy_pda.field)); \
74 asm(op "w %%gs:%c1,%0" \
76 : "i" (pda_offset(field)), \
77 "m" (_proxy_pda.field)); \
80 asm(op "l %%gs:%c1,%0" \
82 : "i" (pda_offset(field)), \
83 "m" (_proxy_pda.field)); \
85 default: __bad_pda_field(); \
89 /* Return a pointer to a pda field */
90 #define pda_addr(field) \
91 ((typeof(_proxy_pda.field) *)((unsigned char *)read_pda(_pda) + \
94 #define read_pda(field) pda_from_op("mov",field)
95 #define write_pda(field,val) pda_to_op("mov",field,val)
96 #define add_pda(field,val) pda_to_op("add",field,val)
97 #define sub_pda(field,val) pda_to_op("sub",field,val)
98 #define or_pda(field,val) pda_to_op("or",field,val)
100 #endif /* _I386_PDA_H */