3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/ex/i386/interlck.c
6 * PURPOSE: No purpose listed.
8 * PROGRAMMERS: No programmer listed.
20 #define LOCK "lock ; "
25 #elif defined(_MSC_VER)
40 INTERLOCKED_RESULT FASTCALL
41 Exfi386InterlockedIncrementLong(IN PLONG Addend
);
43 __asm__("\n\t.global @Exfi386InterlockedIncrementLong@4\n\t"
44 "@Exfi386InterlockedIncrementLong@4:\n\t"
48 "andl $0xC000, %eax\n\t"
51 #elif defined(_MSC_VER)
57 INTERLOCKED_RESULT FASTCALL
58 Exfi386InterlockedIncrementLong(IN PLONG Addend
)
60 __asm LOCK add dword ptr
[ecx
], 1
67 #error Unknown compiler for inline assembler
76 INTERLOCKED_RESULT FASTCALL
77 Exfi386InterlockedDecrementLong(IN PLONG Addend
);
79 __asm__("\n\t.global @Exfi386InterlockedDecrementLong@4\n\t"
80 "@Exfi386InterlockedDecrementLong@4:\n\t"
84 "andl $0xC000, %eax\n\t"
87 #elif defined(_MSC_VER)
93 INTERLOCKED_RESULT FASTCALL
94 Exfi386InterlockedDecrementLong(IN PLONG Addend
)
96 __asm LOCK sub dword ptr
[ecx
], 1
103 #error Unknown compiler for inline assembler
107 #if defined(__GNUC__)
113 Exfi386InterlockedExchangeUlong(IN PULONG Target
,
116 __asm__("\n\t.global @Exfi386InterlockedExchangeUlong@8\n\t"
117 "@Exfi386InterlockedExchangeUlong@8:\n\t"
119 "xchgl %edx,(%ecx)\n\t"
123 #elif defined(_MSC_VER)
130 Exfi386InterlockedExchangeUlong(IN PULONG Target
,
133 __asm LOCK xchg
[ecx
], edx
139 #error Unknown compiler for inline assembler
143 #if defined(__GNUC__)
145 INTERLOCKED_RESULT STDCALL
146 Exi386InterlockedIncrementLong(IN PLONG Addend
);
148 __asm__("\n\t.global _Exi386InterlockedIncrementLong@4\n\t"
149 "_Exi386InterlockedIncrementLong@4:\n\t"
150 "movl 4(%esp),%eax\n\t"
154 "andl $0xC000, %eax\n\t"
157 #elif defined(_MSC_VER)
160 INTERLOCKED_RESULT STDCALL
161 Exi386InterlockedIncrementLong(IN PLONG Addend
)
163 __asm mov eax
, Addend
164 __asm LOCK add dword ptr
[eax
], 1
166 __asm
and eax
, 0xC000
171 #error Unknown compiler for inline assembler
175 #if defined(__GNUC__)
177 INTERLOCKED_RESULT STDCALL
178 Exi386InterlockedDecrementLong(IN PLONG Addend
);
180 __asm__("\n\t.global _Exi386InterlockedDecrementLong@4\n\t"
181 "_Exi386InterlockedDecrementLong@4:\n\t"
182 "movl 4(%esp),%eax\n\t"
186 "andl $0xC000, %eax\n\t"
189 #elif defined(_MSC_VER)
192 INTERLOCKED_RESULT STDCALL
193 Exi386InterlockedDecrementLong(IN PLONG Addend
)
195 __asm mov eax
, Addend
196 __asm LOCK sub dword ptr
[eax
], 1
198 __asm
and eax
, 0xC000
203 #error Unknown compiler for inline assembler
207 #if defined(__GNUC__)
210 Exi386InterlockedExchangeUlong(IN PULONG Target
,
213 __asm__("\n\t.global _Exi386InterlockedExchangeUlong@8\n\t"
214 "_Exi386InterlockedExchangeUlong@8:\n\t"
215 "movl 4(%esp),%edx\n\t"
216 "movl 8(%esp),%eax\n\t"
218 "xchgl %eax,(%edx)\n\t"
221 #elif defined(_MSC_VER)
225 Exi386InterlockedExchangeUlong(IN PULONG Target
,
229 __asm mov eax
, Target
230 __asm LOCK xchg
[edx
], eax
235 #error Unknown compiler for inline assembler
240 /**********************************************************************
241 * FASTCALL: @InterlockedIncrement@4
242 * STDCALL : _InterlockedIncrement@4
244 #if defined(__GNUC__)
249 InterlockedIncrement(PLONG Addend
);
251 * FUNCTION: Increments a caller supplied variable of type LONG as an
254 * Addend = Points to a variable whose value is to be increment
255 * RETURNS: The incremented value
258 __asm__("\n\t.global @InterlockedIncrement@4\n\t"
259 "@InterlockedIncrement@4:\n\t"
262 "xaddl %eax,(%ecx)\n\t"
266 #elif defined(_MSC_VER)
272 InterlockedIncrement(PLONG Addend
)
275 __asm LOCK xadd
[ecx
], eax
281 #error Unknown compiler for inline assembler
285 /**********************************************************************
286 * FASTCALL: @InterlockedDecrement@4
287 * STDCALL : _InterlockedDecrement@4
289 #if defined(__GNUC__)
294 InterlockedDecrement(PLONG Addend
);
296 __asm__("\n\t.global @InterlockedDecrement@4\n\t"
297 "@InterlockedDecrement@4:\n\t"
300 "xaddl %eax,(%ecx)\n\t"
304 #elif defined(_MSC_VER)
311 InterlockedDecrement(PLONG Addend
)
314 __asm LOCK xadd
[ecx
], eax
320 #error Unknown compiler for inline assembler
324 /**********************************************************************
325 * FASTCALL: @InterlockedExchange@8
326 * STDCALL : _InterlockedExchange@8
329 #if defined(__GNUC__)
334 InterlockedExchange(PLONG Target
,
337 __asm__("\n\t.global @InterlockedExchange@8\n\t"
338 "@InterlockedExchange@8:\n\t"
340 "xchgl %edx,(%ecx)\n\t"
344 #elif defined(_MSC_VER)
350 InterlockedExchange(PLONG Target
,
353 __asm LOCK xchg
[ecx
], edx
359 #error Unknown compiler for inline assembler
362 /**********************************************************************
363 * FASTCALL: @InterlockedExchangeAdd@8
364 * STDCALL: _InterlockedExchangeAdd@8
366 #if defined(__GNUC__)
371 InterlockedExchangeAdd(PLONG Addend
,
374 __asm__("\n\t.global @InterlockedExchangeAdd@8\n\t"
375 "@InterlockedExchangeAdd@8:\n\t"
377 "xaddl %edx,(%ecx)\n\t"
381 #elif defined(_MSC_VER)
387 InterlockedExchangeAdd(PLONG Addend
,
390 __asm LOCK xadd
[ecx
], edx
396 #error Unknown compiler for inline assembler
399 /**********************************************************************
400 * FASTCALL: @InterlockedClearBit@8
401 * STDCALL: _InterlockedClearBit@8
403 #if defined(__GNUC__)
409 InterlockedClearBit(PLONG Destination
,
412 __asm__("\n\t.global @InterlockedClearBit@8\n\t"
413 "@InterlockedClearBit@8:\n\t"
415 "btr %edx,(%ecx)\n\t"
419 #elif defined(_MSC_VER)
426 InterlockedClearBit(PUCHAR Destination
,
429 __asm LOCK btr
[ecx
], edx
435 #error Unknown compiler for inline assembler
438 /**********************************************************************
439 * FASTCALL: @InterlockedCompareExchange@12
440 * STDCALL: _InterlockedCompareExchange@12
442 #if defined(__GNUC__)
445 InterlockedCompareExchange(PLONG Destination
,
449 __asm__("\n\t.global @InterlockedCompareExchange@12\n\t"
450 "@InterlockedCompareExchange@12:\n\t"
451 "movl 4(%esp),%eax\n\t"
453 "cmpxchg %edx,(%ecx)\n\t"
456 #elif defined(_MSC_VER)
460 InterlockedCompareExchange(PLONG Destination
,
464 __asm mov eax
, Comperand
465 __asm LOCK cmpxchg
[ecx
], edx
470 #error Unknown compiler for inline assembler
473 /**********************************************************************
474 * FASTCALL: @InterlockedCompareExchange64@8
476 #if defined(__GNUC__)
478 ExfpInterlockedExchange64(LONGLONG
volatile * Destination
,
481 __asm__("\n\t.global @ExfpInterlockedExchange64@8\n\t"
482 "@ExfpInterlockedExchange64@8:\n\t"
486 "movl (%edx),%ebx\n\t"
487 "movl 4(%edx),%ecx\n\t"
489 "movl (%esi),%eax\n\t"
490 "movl 4(%esi),%edx\n\t"
492 "cmpxchg8b (%esi)\n\t"
499 #error Unknown compiler for inline assembler
502 /**********************************************************************
503 * FASTCALL: @ExfInterlockedCompareExchange@12
505 #if defined(__GNUC__)
507 ExfInterlockedCompareExchange64(LONGLONG
volatile * Destination
,
509 PLONGLONG Comperand
);
511 __asm__("\n\t.global @ExfInterlockedCompareExchange64@12\n\t"
512 "@ExfInterlockedCompareExchange64@12:\n\t"
516 "movl (%edx),%ebx\n\t"
517 "movl 4(%edx),%ecx\n\t"
518 "movl 12(%esp),%edx\n\t"
519 "movl (%edx),%eax\n\t"
520 "movl 4(%edx),%edx\n\t"
522 "cmpxchg8b (%esi)\n\t"
528 #error Unknown compiler for inline assembler