Mega compiler intrinsics patch:
[reactos.git] / reactos / ntoskrnl / include / internal / i386 / intrin_i.h
1 #ifndef _INTRIN_INTERNAL_
2 #define _INTRIN_INTERNAL_
3
4 #ifdef CONFIG_SMP
5 #define LOCK "lock ; "
6 #else
7 #define LOCK ""
8 #endif
9
10 #if defined(__GNUC__)
11
12 #define Ke386SetGlobalDescriptorTable(X) \
13 __asm__("lgdt %0\n\t" \
14 : /* no outputs */ \
15 : "m" (*X));
16
17 #define Ke386GetGlobalDescriptorTable(X) \
18 __asm__("sgdt %0\n\t" \
19 : "=m" (*X) \
20 : /* no input */ \
21 : "memory");
22
23 #define Ke386GetLocalDescriptorTable(X) \
24 __asm__("sldt %0\n\t" \
25 : "=m" (*X) \
26 : /* no input */ \
27 : "memory");
28
29 #define Ke386SetLocalDescriptorTable(X) \
30 __asm__("lldt %w0\n\t" \
31 : /* no outputs */ \
32 : "q" (X));
33
34 #define Ke386SetTr(X) __asm__ __volatile__("ltr %%ax" : :"a" (X));
35
36 #define Ke386GetTr(X) \
37 __asm__("str %0\n\t" \
38 : "=m" (*X));
39
40 #define _Ke386GetSeg(N) ({ \
41 unsigned int __d; \
42 __asm__("movl %%" #N ",%0\n\t" :"=r" (__d)); \
43 __d; \
44 })
45
46 #define _Ke386SetSeg(N,X) __asm__ __volatile__("movl %0,%%" #N : :"r" (X));
47
48 #define Ke386HaltProcessor() __asm__("hlt\n\t");
49
50 #define Ke386FnInit() __asm__("fninit\n\t");
51
52
53 //
54 // CR Macros
55 //
56 #define Ke386SetCr2(X) __asm__ __volatile__("movl %0,%%cr2" : :"r" (X));
57
58 //
59 // Segment Macros
60 //
61 #define Ke386GetSs() _Ke386GetSeg(ss)
62 #define Ke386GetFs() _Ke386GetSeg(fs)
63 #define Ke386SetFs(X) _Ke386SetSeg(fs, X)
64 #define Ke386SetDs(X) _Ke386SetSeg(ds, X)
65 #define Ke386SetEs(X) _Ke386SetSeg(es, X)
66 #define Ke386SetSs(X) _Ke386SetSeg(ss, X)
67 #define Ke386SetGs(X) _Ke386SetSeg(gs, X)
68
69 #elif defined(_MSC_VER)
70
71 FORCEINLINE
72 VOID
73 Ke386FnInit(VOID)
74 {
75 __asm fninit;
76 }
77
78 FORCEINLINE
79 VOID
80 Ke386HaltProcessor(VOID)
81 {
82 __asm hlt;
83 }
84
85 FORCEINLINE
86 VOID
87 Ke386GetGlobalDescriptorTable(OUT PVOID Descriptor)
88 {
89 __asm sgdt [Descriptor];
90 }
91
92 FORCEINLINE
93 VOID
94 Ke386SetGlobalDescriptorTable(IN PVOID Descriptor)
95 {
96 __asm lgdt [Descriptor];
97 }
98
99 FORCEINLINE
100 VOID
101 Ke386GetLocalDescriptorTable(OUT PUSHORT Descriptor)
102 {
103 USHORT _Descriptor;
104 __asm sldt _Descriptor;
105 *Descriptor = _Descriptor;
106 }
107
108 FORCEINLINE
109 VOID
110 Ke386SetLocalDescriptorTable(IN USHORT Descriptor)
111 {
112 __asm lldt Descriptor;
113 }
114
115 FORCEINLINE
116 VOID
117 Ke386SetTr(IN USHORT Tr)
118 {
119 __asm ltr Tr;
120 }
121
122 FORCEINLINE
123 USHORT
124 Ke386GetTr(OUT PUSHORT Tr)
125 {
126 USHORT _Tr;
127 __asm str _Tr;
128 *Tr = _Tr;
129 }
130
131 //
132 // CR Macros
133 //
134 FORCEINLINE
135 VOID
136 Ke386SetCr2(IN ULONG Value)
137 {
138 __asm mov eax, Value;
139 __asm mov cr2, eax;
140 }
141
142 //
143 // Segment Macros
144 //
145 FORCEINLINE
146 USHORT
147 Ke386GetSs(VOID)
148 {
149 __asm mov ax, ss;
150 }
151
152 FORCEINLINE
153 USHORT
154 Ke386GetFs(VOID)
155 {
156 __asm mov ax, fs;
157 }
158
159 FORCEINLINE
160 USHORT
161 Ke386GetDs(VOID)
162 {
163 __asm mov ax, ds;
164 }
165
166 FORCEINLINE
167 USHORT
168 Ke386GetEs(VOID)
169 {
170 __asm mov ax, es;
171 }
172
173 FORCEINLINE
174 VOID
175 Ke386SetSs(IN USHORT Value)
176 {
177 __asm mov ax, Value;
178 __asm mov ss, ax;
179 }
180
181 FORCEINLINE
182 VOID
183 Ke386SetFs(IN USHORT Value)
184 {
185 __asm mov ax, Value;
186 __asm mov fs, ax;
187 }
188
189 FORCEINLINE
190 VOID
191 Ke386SetDs(IN USHORT Value)
192 {
193 __asm mov ax, Value;
194 __asm mov ds, ax;
195 }
196
197 FORCEINLINE
198 VOID
199 Ke386SetEs(IN USHORT Value)
200 {
201 __asm mov ax, Value;
202 __asm mov es, ax;
203 }
204
205 FORCEINLINE
206 VOID
207 Ke386SetGs(IN USHORT Value)
208 {
209 __asm mov ax, Value;
210 __asm mov gs, ax;
211 }
212
213 #else
214 #error Unknown compiler for inline assembler
215 #endif
216
217 #endif
218
219 /* EOF */