blob: b12d59a318b7cc46d581e347713e1964a4503ba7 [file] [log] [blame]
Jeremy Fitzhardinge9ca36102006-12-07 02:14:02 +01001/*
2 Per-processor Data Areas
3 Jeremy Fitzhardinge <jeremy@goop.org> 2006
4 Based on asm-x86_64/pda.h by Andi Kleen.
5 */
6#ifndef _I386_PDA_H
7#define _I386_PDA_H
8
9#include <linux/stddef.h>
Jeremy Fitzhardingeec7fcaa2006-12-07 02:14:03 +010010#include <linux/types.h>
Jeremy Fitzhardinge9ca36102006-12-07 02:14:02 +010011
12struct i386_pda
13{
14 struct i386_pda *_pda; /* pointer to self */
Jeremy Fitzhardingeb2938f82006-12-07 02:14:03 +010015
16 int cpu_number;
Jeremy Fitzhardingeec7fcaa2006-12-07 02:14:03 +010017 struct task_struct *pcurrent; /* current process */
Jeremy Fitzhardinge70463da2006-12-07 02:14:03 +010018 struct pt_regs *irq_regs;
Jeremy Fitzhardinge9ca36102006-12-07 02:14:02 +010019};
20
21extern struct i386_pda *_cpu_pda[];
22
23#define cpu_pda(i) (_cpu_pda[i])
24
25#define pda_offset(field) offsetof(struct i386_pda, field)
26
27extern void __bad_pda_field(void);
28
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. */
34extern struct i386_pda _proxy_pda;
35
36#define pda_to_op(op,field,val) \
37 do { \
38 typedef typeof(_proxy_pda.field) T__; \
39 if (0) { T__ tmp__; tmp__ = (val); } \
40 switch (sizeof(_proxy_pda.field)) { \
41 case 1: \
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +010042 asm(op "b %1,%%fs:%c2" \
Jeremy Fitzhardinge9ca36102006-12-07 02:14:02 +010043 : "+m" (_proxy_pda.field) \
44 :"ri" ((T__)val), \
45 "i"(pda_offset(field))); \
46 break; \
47 case 2: \
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +010048 asm(op "w %1,%%fs:%c2" \
Jeremy Fitzhardinge9ca36102006-12-07 02:14:02 +010049 : "+m" (_proxy_pda.field) \
50 :"ri" ((T__)val), \
51 "i"(pda_offset(field))); \
52 break; \
53 case 4: \
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +010054 asm(op "l %1,%%fs:%c2" \
Jeremy Fitzhardinge9ca36102006-12-07 02:14:02 +010055 : "+m" (_proxy_pda.field) \
56 :"ri" ((T__)val), \
57 "i"(pda_offset(field))); \
58 break; \
59 default: __bad_pda_field(); \
60 } \
61 } while (0)
62
63#define pda_from_op(op,field) \
64 ({ \
65 typeof(_proxy_pda.field) ret__; \
66 switch (sizeof(_proxy_pda.field)) { \
67 case 1: \
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +010068 asm(op "b %%fs:%c1,%0" \
Jeremy Fitzhardinge9ca36102006-12-07 02:14:02 +010069 : "=r" (ret__) \
70 : "i" (pda_offset(field)), \
71 "m" (_proxy_pda.field)); \
72 break; \
73 case 2: \
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +010074 asm(op "w %%fs:%c1,%0" \
Jeremy Fitzhardinge9ca36102006-12-07 02:14:02 +010075 : "=r" (ret__) \
76 : "i" (pda_offset(field)), \
77 "m" (_proxy_pda.field)); \
78 break; \
79 case 4: \
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +010080 asm(op "l %%fs:%c1,%0" \
Jeremy Fitzhardinge9ca36102006-12-07 02:14:02 +010081 : "=r" (ret__) \
82 : "i" (pda_offset(field)), \
83 "m" (_proxy_pda.field)); \
84 break; \
85 default: __bad_pda_field(); \
86 } \
87 ret__; })
88
89/* Return a pointer to a pda field */
90#define pda_addr(field) \
91 ((typeof(_proxy_pda.field) *)((unsigned char *)read_pda(_pda) + \
92 pda_offset(field)))
93
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)
99
100#endif /* _I386_PDA_H */