Continue of MSVC-compiling changes....
[reactos.git] / reactos / ntoskrnl / ex / i386 / interlck.c
1 /* $Id: interlck.c,v 1.6 2003/12/30 18:52:03 fireball Exp $
2 *
3 * reactos/ntoskrnl/ex/i386/interlck.c
4 *
5 */
6 #include <ddk/ntddk.h>
7
8
9 #if defined(__GNUC__)
10
11 INTERLOCKED_RESULT FASTCALL
12 Exfi386InterlockedIncrementLong(IN PLONG Addend);
13
14 __asm__("\n\t.global @Exfi386InterlockedIncrementLong@4\n\t"
15 "@Exfi386InterlockedIncrementLong@4:\n\t"
16 "addl $1,(%ecx)\n\t"
17 "lahf\n\t"
18 "andl $0xC000, %eax\n\t"
19 "ret\n\t");
20
21 #elif defined(_MSC_VER)
22
23 __declspec(naked)
24 INTERLOCKED_RESULT FASTCALL
25 Exfi386InterlockedIncrementLong(IN PLONG Addend)
26 {
27 __asm add ecx, 1
28 __asm lahf
29 __asm and eax, 0xC000
30 __asm ret
31 }
32
33 #else
34 #error Unknown compiler for inline assembler
35 #endif
36
37
38 #if defined(__GNUC__)
39
40 INTERLOCKED_RESULT FASTCALL
41 Exfi386InterlockedDecrementLong(IN PLONG Addend);
42
43 __asm__("\n\t.global @Exfi386InterlockedDecrementLong@4\n\t"
44 "@Exfi386InterlockedDecrementLong@4:\n\t"
45 "subl $1,(%ecx)\n\t"
46 "lahf\n\t"
47 "andl $0xC000, %eax\n\t"
48 "ret\n\t");
49
50 #elif defined(_MSC_VER)
51
52 __declspec(naked)
53 INTERLOCKED_RESULT FASTCALL
54 Exfi386InterlockedDecrementLong(IN PLONG Addend)
55 {
56 __asm sub ecx, 1
57 __asm lahf
58 __asm and eax, 0xC000
59 __asm ret
60 }
61
62 #else
63 #error Unknown compiler for inline assembler
64 #endif
65
66
67 #if defined(__GNUC__)
68
69 ULONG FASTCALL
70 Exfi386InterlockedExchangeUlong(IN PULONG Target,
71 IN ULONG Value);
72
73 __asm__("\n\t.global @Exfi386InterlockedExchangeUlong@8\n\t"
74 "@Exfi386InterlockedExchangeUlong@8:\n\t"
75 "xchgl %edx,(%ecx)\n\t"
76 "movl %edx,%eax\n\t"
77 "ret\n\t");
78
79 #elif defined(_MSC_VER)
80
81 __declspec(naked)
82 ULONG FASTCALL
83 Exfi386InterlockedExchangeUlong(IN PULONG Target,
84 IN ULONG Value)
85 {
86 __asm xchg [ecx], edx
87 __asm mov eax, edx
88 __asm ret
89 }
90
91 #else
92 #error Unknown compiler for inline assembler
93 #endif
94
95
96 #if defined(__GNUC__)
97
98 INTERLOCKED_RESULT STDCALL
99 Exi386InterlockedIncrementLong(IN PLONG Addend);
100
101 __asm__("\n\t.global _Exi386InterlockedIncrementLong@4\n\t"
102 "_Exi386InterlockedIncrementLong@4:\n\t"
103 "movl 4(%esp),%eax\n\t"
104 "addl $1,(%eax)\n\t"
105 "lahf\n\t"
106 "andl $0xC000, %eax\n\t"
107 "ret $4\n\t");
108
109 #elif defined(_MSC_VER)
110
111 __declspec(naked)
112 INTERLOCKED_RESULT STDCALL
113 Exi386InterlockedIncrementLong(IN PLONG Addend)
114 {
115 __asm mov eax, Addend
116 __asm add [eax], 1
117 __asm lahf
118 __asm and eax, 0xC000
119 __asm ret 4
120 }
121
122 #else
123 #error Unknown compiler for inline assembler
124 #endif
125
126
127 #if defined(__GNUC__)
128
129 INTERLOCKED_RESULT STDCALL
130 Exi386InterlockedDecrementLong(IN PLONG Addend);
131
132 __asm__("\n\t.global _Exi386InterlockedDecrementLong@4\n\t"
133 "_Exi386InterlockedDecrementLong@4:\n\t"
134 "movl 4(%esp),%eax\n\t"
135 "subl $1,(%eax)\n\t"
136 "lahf\n\t"
137 "andl $0xC000, %eax\n\t"
138 "ret $4\n\t");
139
140 #elif defined(_MSC_VER)
141
142 __declspec(naked)
143 INTERLOCKED_RESULT STDCALL
144 Exi386InterlockedDecrementLong(IN PLONG Addend)
145 {
146 __asm mov eax, Addend
147 __asm sub [eax], 1
148 __asm lahf
149 __asm and eax, 0xC000
150 __asm ret 4
151 }
152
153 #else
154 #error Unknown compiler for inline assembler
155 #endif
156
157
158 #if defined(__GNUC__)
159
160 ULONG STDCALL
161 Exi386InterlockedExchangeUlong(IN PULONG Target,
162 IN ULONG Value);
163
164 __asm__("\n\t.global _Exi386InterlockedExchangeUlong@8\n\t"
165 "_Exi386InterlockedExchangeUlong@8:\n\t"
166 "movl 4(%esp),%edx\n\t"
167 "movl 8(%esp),%eax\n\t"
168 "xchgl %eax,(%edx)\n\t"
169 "ret $8\n\t");
170
171 #elif defined(_MSC_VER)
172
173 __declspec(naked)
174 ULONG STDCALL
175 Exi386InterlockedExchangeUlong(IN PULONG Target,
176 IN ULONG Value)
177 {
178 __asm mov edx, Value
179 __asm mov eax, Target
180 __asm xchg [edx], eax
181 __asm ret 8
182 }
183
184 #else
185 #error Unknown compiler for inline assembler
186 #endif
187
188
189
190 /**********************************************************************
191 * FASTCALL: @InterlockedIncrement@4
192 * STDCALL : _InterlockedIncrement@4
193 */
194 #if defined(__GNUC__)
195 LONG FASTCALL
196 InterlockedIncrement(PLONG Addend);
197 /*
198 * FUNCTION: Increments a caller supplied variable of type LONG as an
199 * atomic operation
200 * ARGUMENTS:
201 * Addend = Points to a variable whose value is to be increment
202 * RETURNS: The incremented value
203 */
204
205 __asm__("\n\t.global @InterlockedIncrement@4\n\t"
206 "@InterlockedIncrement@4:\n\t"
207 "movl $1,%eax\n\t"
208 "xaddl %eax,(%ecx)\n\t"
209 "incl %eax\n\t"
210 "ret\n\t");
211
212 #elif defined(_MSC_VER)
213
214 __declspec(naked)
215 LONG FASTCALL
216 InterlockedIncrement(PLONG Addend)
217 {
218 __asm mov eax, 1
219 __asm xadd [ecx], eax
220 __asm inc eax
221 __asm ret
222 }
223
224 #else
225 #error Unknown compiler for inline assembler
226 #endif
227
228
229 /**********************************************************************
230 * FASTCALL: @InterlockedDecrement@4
231 * STDCALL : _InterlockedDecrement@4
232 */
233 #if defined(__GNUC__)
234 LONG FASTCALL
235 InterlockedDecrement(PLONG Addend);
236
237 __asm__("\n\t.global @InterlockedDecrement@4\n\t"
238 "@InterlockedDecrement@4:\n\t"
239 "movl $-1,%eax\n\t"
240 "xaddl %eax,(%ecx)\n\t"
241 "decl %eax\n\t"
242 "ret\n\t");
243
244 #elif defined(_MSC_VER)
245
246 __declspec(naked)
247 LONG FASTCALL
248 InterlockedDecrement(PLONG Addend)
249 {
250 __asm mov eax, -1
251 __asm xadd [ecx], eax
252 __asm dec eax
253 __asm ret
254 }
255
256 #else
257 #error Unknown compiler for inline assembler
258 #endif
259
260
261 /**********************************************************************
262 * FASTCALL: @InterlockedExchange@8
263 * STDCALL : _InterlockedExchange@8
264 */
265
266 #if defined(__GNUC__)
267 LONG FASTCALL
268 InterlockedExchange(PLONG Target,
269 LONG Value);
270
271 __asm__("\n\t.global @InterlockedExchange@8\n\t"
272 "@InterlockedExchange@8:\n\t"
273 "xchgl %edx,(%ecx)\n\t"
274 "movl %edx,%eax\n\t"
275 "ret\n\t");
276
277 #elif defined(_MSC_VER)
278
279 __declspec(naked)
280 LONG FASTCALL
281 InterlockedExchange(PLONG Target,
282 LONG Value)
283 {
284 __asm xchg [ecx], edx
285 __asm mov eax, edx
286 __asm ret
287 }
288
289 #else
290 #error Unknown compiler for inline assembler
291 #endif
292
293 /**********************************************************************
294 * FASTCALL: @InterlockedExchangeAdd@8
295 * STDCALL: _InterlockedExchangeAdd@8
296 */
297 #if defined(__GNUC__)
298
299 LONG FASTCALL
300 InterlockedExchangeAdd(PLONG Addend,
301 LONG Value);
302
303 __asm__("\n\t.global @InterlockedExchangeAdd@8\n\t"
304 "@InterlockedExchangeAdd@8:\n\t"
305 "xaddl %edx,(%ecx)\n\t"
306 "movl %edx,%eax\n\t"
307 "ret\n\t");
308
309 #elif defined(_MSC_VER)
310
311 __declspec(naked)
312 LONG FASTCALL
313 InterlockedExchangeAdd(PLONG Addend,
314 LONG Value)
315 {
316 __asm xadd [ecx], edx
317 __asm mov eax, edx
318 __asm ret
319 }
320
321 #else
322 #error Unknown compiler for inline assembler
323 #endif
324
325
326 /**********************************************************************
327 * FASTCALL: @InterlockedCompareExchange@12
328 * STDCALL: _InterlockedCompareExchange@12
329 */
330 #if defined(__GNUC__)
331
332 LONG FASTCALL
333 InterlockedCompareExchange(PLONG Destination,
334 LONG Exchange,
335 LONG Comperand);
336
337 __asm__("\n\t.global @InterlockedCompareExchange@12\n\t"
338 "@InterlockedCompareExchange@12:\n\t"
339 "movl 4(%esp),%eax\n\t"
340 "cmpxchg %edx,(%ecx)\n\t"
341 "ret $4\n\t");
342
343 #elif defined(_MSC_VER)
344
345 __declspec(naked)
346 LONG FASTCALL
347 InterlockedCompareExchange(PLONG Destination,
348 LONG Exchange,
349 LONG Comperand)
350 {
351 __asm mov eax, Comperand
352 __asm cmpxchg [ecx], edx
353 __asm ret 4
354 }
355
356 #else
357 #error Unknown compiler for inline assembler
358 #endif
359
360 /* EOF */