2009-10-12 03:35:35 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
|
|
|
* FILE: ntoskrnl/ex/i386/fastinterlck_asm.S
|
|
|
|
* PURPOSE: FASTCALL Interlocked Functions
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
|
|
|
|
*/
|
2011-06-07 19:50:01 +00:00
|
|
|
|
2009-10-12 03:35:35 +00:00
|
|
|
/* INCLUDES ******************************************************************/
|
2010-02-10 23:24:59 +00:00
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
#include <asm.inc>
|
|
|
|
#include <ks386.inc>
|
2009-10-12 03:35:35 +00:00
|
|
|
#include <internal/i386/asmmacro.S>
|
|
|
|
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
2010-02-10 23:24:59 +00:00
|
|
|
.code32
|
|
|
|
|
2009-10-12 03:35:35 +00:00
|
|
|
/*
|
|
|
|
* NOTE: These functions must obey the following rules:
|
|
|
|
* - Acquire locks only on MP systems.
|
|
|
|
* - Be safe at HIGH_LEVEL (no paged access).
|
|
|
|
* - Preserve flags.
|
|
|
|
* - Disable interrups.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*VOID
|
|
|
|
*FASTCALL
|
|
|
|
*ExInterlockedAddLargeStatistic(IN PLARGE_INTEGER Addend,
|
|
|
|
* IN ULONG Increment)
|
|
|
|
*/
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC @ExInterlockedAddLargeStatistic@8
|
2009-10-12 03:35:35 +00:00
|
|
|
@ExInterlockedAddLargeStatistic@8:
|
|
|
|
|
2011-06-07 19:50:01 +00:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Do the addition */
|
|
|
|
lock add [ecx], edx
|
2011-05-14 19:29:42 +00:00
|
|
|
|
2011-06-07 19:50:01 +00:00
|
|
|
/* Check for carry bit and return */
|
|
|
|
jb .l1
|
2009-10-12 03:35:35 +00:00
|
|
|
ret
|
|
|
|
|
2011-06-07 19:50:01 +00:00
|
|
|
.l1:
|
|
|
|
/* Add carry */
|
|
|
|
lock adc dword ptr [ecx+4], 0
|
|
|
|
#else
|
|
|
|
/* Do the addition and add the carry */
|
|
|
|
add dword ptr [ecx], edx
|
|
|
|
adc dword ptr [ecx+4], 0
|
|
|
|
#endif
|
|
|
|
/* Return */
|
2009-10-12 03:35:35 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
/*ULONG
|
|
|
|
*FASTCALL
|
|
|
|
*ExfInterlockedAddUlong(IN PULONG Addend,
|
|
|
|
* IN ULONG Increment,
|
|
|
|
* IN PKSPIN_LOCK Lock)
|
|
|
|
*/
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC @ExfInterlockedAddUlong@12
|
2009-10-12 03:35:35 +00:00
|
|
|
@ExfInterlockedAddUlong@12:
|
|
|
|
|
|
|
|
/* Save flags */
|
|
|
|
pushfd
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Get lock address */
|
|
|
|
mov eax, [esp+8]
|
|
|
|
.start1:
|
|
|
|
#endif
|
|
|
|
/* Disable interrupts */
|
|
|
|
cli
|
|
|
|
|
|
|
|
/* Acquire lock */
|
|
|
|
ACQUIRE_SPINLOCK(eax, .spin1)
|
|
|
|
|
|
|
|
/* Do the add */
|
|
|
|
mov eax, [ecx]
|
|
|
|
add [ecx], edx
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Get spinlock address and release it */
|
|
|
|
mov edx, [esp+8]
|
|
|
|
RELEASE_SPINLOCK(edx)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Restore flags and return */
|
|
|
|
popfd
|
|
|
|
ret 4
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
.spin1:
|
|
|
|
/* Restore flags and spin */
|
|
|
|
popfd
|
|
|
|
pushfd
|
|
|
|
SPIN_ON_LOCK(eax, .start1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*PLIST_ENTRY
|
|
|
|
*FASTCALL
|
|
|
|
*ExfInterlockedInsertHeadList(IN PLIST_ENTRY ListHead,
|
|
|
|
* IN PLIST_ENTRY ListEntry,
|
|
|
|
* IN PKSPIN_LOCK Lock)
|
|
|
|
*/
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC @ExfInterlockedInsertHeadList@12
|
2009-10-12 03:35:35 +00:00
|
|
|
@ExfInterlockedInsertHeadList@12:
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Save lock address */
|
|
|
|
push esi
|
|
|
|
mov esi, [esp+8]
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Save flags and disable interrupts */
|
|
|
|
pushfd
|
|
|
|
.start2:
|
|
|
|
cli
|
|
|
|
|
|
|
|
/* Acquire lock */
|
|
|
|
ACQUIRE_SPINLOCK(esi, .spin2)
|
|
|
|
|
|
|
|
/* Get list pointer */
|
|
|
|
mov eax, [ecx]
|
|
|
|
|
|
|
|
/* Do the insert */
|
|
|
|
mov [edx], eax
|
|
|
|
mov [edx+4], ecx
|
|
|
|
mov [ecx], edx
|
|
|
|
mov [eax+4], edx
|
|
|
|
|
|
|
|
/* Release lock and restore flags */
|
|
|
|
RELEASE_SPINLOCK(esi)
|
|
|
|
popfd
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
pop esi
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Check if list was empty */
|
|
|
|
xor eax, ecx
|
2010-11-27 22:12:15 +00:00
|
|
|
jz .l2
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Return list pointer */
|
|
|
|
xor eax, ecx
|
2010-11-27 22:12:15 +00:00
|
|
|
.l2:
|
2009-10-12 03:35:35 +00:00
|
|
|
ret 4
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
.spin2:
|
|
|
|
popfd
|
|
|
|
pushfd
|
|
|
|
SPIN_ON_LOCK(esi, .start2)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*PLIST_ENTRY
|
|
|
|
*FASTCALL
|
|
|
|
*ExfInterlockedInsertTailList(IN PLIST_ENTRY ListHead,
|
2011-07-20 13:48:06 +00:00
|
|
|
* IN PLIST_ENTRY ListEntry,
|
|
|
|
* IN PKSPIN_LOCK Lock)
|
2009-10-12 03:35:35 +00:00
|
|
|
*/
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC @ExfInterlockedInsertTailList@12
|
2009-10-12 03:35:35 +00:00
|
|
|
@ExfInterlockedInsertTailList@12:
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Save lock address */
|
|
|
|
push esi
|
|
|
|
mov esi, [esp+8]
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Save flags and disable interrupts */
|
|
|
|
pushfd
|
|
|
|
.start3:
|
|
|
|
cli
|
|
|
|
|
|
|
|
/* Acquire lock */
|
|
|
|
ACQUIRE_SPINLOCK(esi, .spin3)
|
|
|
|
|
|
|
|
/* Get list pointer */
|
|
|
|
mov eax, [ecx+4]
|
|
|
|
|
|
|
|
/* Do the insert */
|
|
|
|
mov [edx], ecx
|
|
|
|
mov [edx+4], eax
|
|
|
|
mov [ecx+4], edx
|
|
|
|
mov [eax], edx
|
|
|
|
|
|
|
|
/* Release lock and restore flags */
|
|
|
|
RELEASE_SPINLOCK(esi)
|
|
|
|
popfd
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
pop esi
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Check if list was empty */
|
|
|
|
xor eax, ecx
|
2010-11-27 22:12:15 +00:00
|
|
|
jz .l3
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Return list pointer */
|
|
|
|
xor eax, ecx
|
2010-11-27 22:12:15 +00:00
|
|
|
.l3:
|
2009-10-12 03:35:35 +00:00
|
|
|
ret 4
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
.spin3:
|
|
|
|
popfd
|
|
|
|
pushfd
|
|
|
|
SPIN_ON_LOCK(esi, .start3)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*PLIST_ENTRY
|
|
|
|
*FASTCALL
|
|
|
|
*ExfInterlockedRemoveHeadList(IN PLIST_ENTRY ListHead,
|
|
|
|
* IN PKSPIN_LOCK Lock)
|
|
|
|
*/
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC @ExfInterlockedRemoveHeadList@8
|
2009-10-12 03:35:35 +00:00
|
|
|
@ExfInterlockedRemoveHeadList@8:
|
|
|
|
|
|
|
|
/* Save flags and disable interrupts */
|
|
|
|
.start4:
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
ACQUIRE_SPINLOCK(edx, .spin4)
|
|
|
|
|
|
|
|
/* Get list pointer */
|
|
|
|
mov eax, [ecx]
|
|
|
|
|
|
|
|
/* Check if it's empty */
|
|
|
|
cmp eax, ecx
|
2010-11-27 22:12:15 +00:00
|
|
|
je .l4
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Get the next entry and do the deletion */
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
push ebx
|
|
|
|
mov ebx, [eax]
|
|
|
|
mov [ecx], ebx
|
|
|
|
mov [ebx+4], ecx
|
|
|
|
#else
|
|
|
|
mov edx, [eax]
|
|
|
|
mov [ecx], edx
|
|
|
|
mov [edx+4], ecx
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Release lock */
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
RELEASE_SPINLOCK(edx)
|
|
|
|
pop ebx
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Restore flags */
|
|
|
|
popfd
|
|
|
|
|
|
|
|
/* Return */
|
|
|
|
ret
|
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
.l4:
|
2009-10-12 03:35:35 +00:00
|
|
|
/* Release lock */
|
|
|
|
RELEASE_SPINLOCK(edx)
|
|
|
|
|
|
|
|
/* Restore flags */
|
|
|
|
popfd
|
|
|
|
|
|
|
|
/* Return empty list */
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
.spin4:
|
|
|
|
popfd
|
|
|
|
SPIN_ON_LOCK(edx, .start4)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*PSINGLE_LIST_ENTRY
|
|
|
|
*FASTCALL
|
|
|
|
*ExfInterlockedPopEntryList(IN PSINGLE_LIST_ENTRY ListHead,
|
|
|
|
* IN PKSPIN_LOCK Lock)
|
|
|
|
*/
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC @ExfInterlockedPopEntryList@8
|
2009-10-12 03:35:35 +00:00
|
|
|
@ExfInterlockedPopEntryList@8:
|
|
|
|
|
|
|
|
/* Save flags and disable interrupts */
|
|
|
|
.start5:
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
ACQUIRE_SPINLOCK(edx, .spin5)
|
|
|
|
|
|
|
|
/* Get list pointer */
|
|
|
|
mov eax, [ecx]
|
|
|
|
|
|
|
|
/* Check if it's empty */
|
|
|
|
or eax, eax
|
2010-11-27 22:12:15 +00:00
|
|
|
je .l6
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Get next entry and do deletion */
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
push edx
|
|
|
|
#endif
|
|
|
|
mov edx, [eax]
|
|
|
|
mov [ecx], edx
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
pop edx
|
|
|
|
#endif
|
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
.l5:
|
2009-10-12 03:35:35 +00:00
|
|
|
/* Release lock */
|
|
|
|
RELEASE_SPINLOCK(edx)
|
|
|
|
|
|
|
|
/* Restore flags */
|
|
|
|
popfd
|
|
|
|
|
|
|
|
/* Return */
|
|
|
|
ret
|
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
.l6:
|
2009-10-12 03:35:35 +00:00
|
|
|
/* Return empty list */
|
|
|
|
xor eax, eax
|
2010-11-27 22:12:15 +00:00
|
|
|
jmp .l5
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
.spin5:
|
|
|
|
popfd
|
|
|
|
SPIN_ON_LOCK(edx, .start5)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*PSINGLE_LIST_ENTRY
|
|
|
|
*FASTCALL
|
|
|
|
*ExfInterlockedPushEntryList(IN PSINGLE_LIST_ENTRY ListHead,
|
|
|
|
* IN PSINGLE_LIST_ENTRY ListEntry,
|
|
|
|
* IN PKSPIN_LOCK Lock)
|
|
|
|
*/
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC @ExfInterlockedPushEntryList@12
|
2009-10-12 03:35:35 +00:00
|
|
|
@ExfInterlockedPushEntryList@12:
|
|
|
|
|
|
|
|
/* Save flags */
|
|
|
|
pushfd
|
|
|
|
|
|
|
|
/* Save lock pointer */
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
push edx
|
|
|
|
mov edx, [esp+12]
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Disable interrupts */
|
|
|
|
.start6:
|
|
|
|
cli
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
ACQUIRE_SPINLOCK(edx, .spin6)
|
|
|
|
pop edx
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Get list pointer */
|
|
|
|
mov eax, [ecx]
|
|
|
|
|
|
|
|
/* Do push */
|
|
|
|
mov [edx], eax
|
|
|
|
mov [ecx], edx
|
|
|
|
|
|
|
|
/* Release lock */
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
mov edx, [esp+8]
|
|
|
|
RELEASE_SPINLOCK(edx)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Restore flags */
|
|
|
|
popfd
|
|
|
|
|
|
|
|
/* Return */
|
|
|
|
ret 4
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
.spin6:
|
|
|
|
pop edx
|
|
|
|
popfd
|
|
|
|
pushfd
|
|
|
|
push edx
|
|
|
|
mov edx, [esp+12]
|
|
|
|
SPIN_ON_LOCK(edx, .start6)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*PSINGLE_LIST_ENTRY
|
|
|
|
*FASTCALL
|
|
|
|
*ExInterlockedPopEntrySList(IN PSINGLE_LIST_ENTRY ListHead,
|
|
|
|
* IN PKSPIN_LOCK Lock)
|
|
|
|
*/
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC @ExInterlockedPopEntrySList@8
|
|
|
|
PUBLIC @InterlockedPopEntrySList@4
|
|
|
|
PUBLIC _ExpInterlockedPopEntrySListResume@0
|
|
|
|
PUBLIC _ExpInterlockedPopEntrySListFault@0
|
|
|
|
PUBLIC _ExpInterlockedPopEntrySListEnd@0
|
2009-10-12 03:35:35 +00:00
|
|
|
@ExInterlockedPopEntrySList@8:
|
|
|
|
@InterlockedPopEntrySList@4:
|
|
|
|
|
|
|
|
/* Save registers */
|
|
|
|
push ebx
|
|
|
|
push ebp
|
|
|
|
|
|
|
|
/* Pointer to list */
|
|
|
|
mov ebp, ecx
|
|
|
|
|
|
|
|
/* Get sequence number and link pointer */
|
|
|
|
_ExpInterlockedPopEntrySListResume@0:
|
|
|
|
mov edx, [ebp+4]
|
|
|
|
mov eax, [ebp]
|
|
|
|
|
|
|
|
/* Check if the list is empty */
|
|
|
|
or eax, eax
|
2010-11-27 22:12:15 +00:00
|
|
|
jz .l7
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Copy sequence number and adjust it */
|
|
|
|
lea ecx, [edx-1]
|
|
|
|
|
|
|
|
/* Get next pointer and do the exchange */
|
|
|
|
_ExpInterlockedPopEntrySListFault@0:
|
|
|
|
mov ebx, [eax]
|
|
|
|
_ExpInterlockedPopEntrySListEnd@0:
|
2009-11-02 18:40:24 +00:00
|
|
|
LOCK cmpxchg8b qword ptr [ebp]
|
2009-10-12 03:35:35 +00:00
|
|
|
jnz _ExpInterlockedPopEntrySListResume@0
|
|
|
|
|
|
|
|
/* Restore registers and return */
|
2010-11-27 22:12:15 +00:00
|
|
|
.l7:
|
2009-10-12 03:35:35 +00:00
|
|
|
pop ebp
|
|
|
|
pop ebx
|
|
|
|
ret
|
|
|
|
|
|
|
|
/*PSINGLE_LIST_ENTRY
|
|
|
|
*FASTCALL
|
|
|
|
*ExInterlockedPushEntrySList(IN PSINGLE_LIST_ENTRY ListHead,
|
|
|
|
* IN PSINGLE_LIST_ENTRY ListEntry,
|
|
|
|
* IN PKSPIN_LOCK Lock)
|
|
|
|
*/
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC @ExInterlockedPushEntrySList@12
|
2009-10-12 03:35:35 +00:00
|
|
|
@ExInterlockedPushEntrySList@12:
|
|
|
|
|
|
|
|
/* So we can fall through below */
|
|
|
|
pop [esp]
|
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC @InterlockedPushEntrySList@8
|
2009-10-12 03:35:35 +00:00
|
|
|
@InterlockedPushEntrySList@8:
|
|
|
|
|
|
|
|
/* Save registers */
|
|
|
|
push ebx
|
|
|
|
push ebp
|
|
|
|
|
|
|
|
/* Pointer to list */
|
|
|
|
mov ebp, ecx
|
|
|
|
mov ebx, edx
|
|
|
|
|
|
|
|
/* Get sequence number and link pointer */
|
|
|
|
mov edx, [ebp+4]
|
|
|
|
mov eax, [ebp]
|
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
.l8:
|
2009-10-12 03:35:35 +00:00
|
|
|
/* Set link pointer */
|
|
|
|
mov [ebx], eax
|
|
|
|
|
|
|
|
/* Copy sequence number and adjust it */
|
2010-11-27 22:12:15 +00:00
|
|
|
lea ecx, [edx + HEX(10001)]
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Do the exchange */
|
2009-11-02 18:40:24 +00:00
|
|
|
LOCK cmpxchg8b qword ptr [ebp]
|
2010-11-27 22:12:15 +00:00
|
|
|
jnz .l8
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Restore registers and return */
|
|
|
|
pop ebp
|
|
|
|
pop ebx
|
|
|
|
ret
|
|
|
|
|
|
|
|
/*PSINGLE_LIST_ENTRY
|
|
|
|
*FASTCALL
|
|
|
|
*ExInterlockedFlushSList(IN PSINGLE_LIST_ENTRY ListHead)
|
|
|
|
*/
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC @ExInterlockedFlushSList@4
|
2009-10-12 03:35:35 +00:00
|
|
|
@ExInterlockedFlushSList@4:
|
|
|
|
|
|
|
|
/* Save registers */
|
|
|
|
push ebx
|
|
|
|
push ebp
|
|
|
|
|
|
|
|
/* Clear ebx */
|
|
|
|
xor ebx, ebx
|
|
|
|
|
|
|
|
/* Pointer to list */
|
|
|
|
mov ebp, ecx
|
|
|
|
|
|
|
|
/* Get sequence number and link pointer */
|
|
|
|
mov edx, [ebp+4]
|
|
|
|
mov eax, [ebp]
|
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
.l9:
|
2009-10-12 03:35:35 +00:00
|
|
|
/* Check if the list is empty */
|
|
|
|
or eax, eax
|
2010-11-27 22:12:15 +00:00
|
|
|
jz .l10
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Clear sequence and pointer */
|
|
|
|
mov ecx, edx
|
|
|
|
mov cx, bx
|
|
|
|
|
|
|
|
/* Do the exchange */
|
2009-11-02 18:40:24 +00:00
|
|
|
LOCK cmpxchg8b qword ptr [ebp]
|
2010-11-27 22:12:15 +00:00
|
|
|
jnz .l9
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Restore registers and return */
|
2010-11-27 22:12:15 +00:00
|
|
|
.l10:
|
2009-10-12 03:35:35 +00:00
|
|
|
pop ebp
|
|
|
|
pop ebx
|
|
|
|
ret
|
|
|
|
|
|
|
|
/*INTERLOCKED_RESULT
|
|
|
|
*FASTCALL
|
|
|
|
*Exfi386InterlockedIncrementLong(IN PLONG Addend)
|
|
|
|
*/
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC @Exfi386InterlockedIncrementLong@4
|
2009-10-12 03:35:35 +00:00
|
|
|
@Exfi386InterlockedIncrementLong@4:
|
|
|
|
|
|
|
|
/* Do the op */
|
|
|
|
LOCK add dword ptr [ecx], 1
|
|
|
|
|
|
|
|
/* Return */
|
|
|
|
lahf
|
|
|
|
and eax, EFLAG_SELECT
|
|
|
|
ret
|
|
|
|
|
|
|
|
/*INTERLOCKED_RESULT
|
|
|
|
*FASTCALL
|
|
|
|
*Exfi386InterlockedDecrementLong(IN PLONG Addend)
|
|
|
|
*/
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC @Exfi386InterlockedDecrementLong@4
|
2009-10-12 03:35:35 +00:00
|
|
|
@Exfi386InterlockedDecrementLong@4:
|
|
|
|
|
|
|
|
/* Do the op */
|
|
|
|
LOCK sub dword ptr [ecx], 1
|
|
|
|
|
|
|
|
/* Return */
|
|
|
|
lahf
|
|
|
|
and eax, EFLAG_SELECT
|
|
|
|
ret
|
|
|
|
|
|
|
|
/*ULONG
|
|
|
|
*FASTCALL
|
2011-07-20 13:48:06 +00:00
|
|
|
*Exfi386InterlockedExchangeUlong(IN PULONG Target,
|
2009-10-12 03:35:35 +00:00
|
|
|
* IN ULONG Value)
|
|
|
|
*/
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC @Exfi386InterlockedExchangeUlong@8
|
2009-10-12 03:35:35 +00:00
|
|
|
@Exfi386InterlockedExchangeUlong@8:
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* On MP, do the exchange */
|
|
|
|
xchg [ecx], edx
|
|
|
|
mov eax, edx
|
|
|
|
#else
|
|
|
|
/* On UP, use cmpxchg */
|
|
|
|
mov eax, [ecx]
|
2010-11-27 22:12:15 +00:00
|
|
|
.l11:
|
2009-10-12 03:35:35 +00:00
|
|
|
cmpxchg [ecx], edx
|
2010-11-27 22:12:15 +00:00
|
|
|
jnz .l11
|
2009-10-12 03:35:35 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Return */
|
|
|
|
ret
|
|
|
|
|
|
|
|
/*PVOID
|
|
|
|
*FASTCALL
|
|
|
|
*ExfInterlockedCompareExchange64(IN PLONGLONG Destination,
|
|
|
|
* IN PLONGLONG Exchange,
|
|
|
|
* IN PLONGLONG Comperand)
|
|
|
|
*/
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC @ExfInterlockedCompareExchange64@12
|
2009-10-12 03:35:35 +00:00
|
|
|
@ExfInterlockedCompareExchange64@12:
|
|
|
|
|
|
|
|
/* Save registers */
|
|
|
|
push ebx
|
|
|
|
push ebp
|
|
|
|
|
|
|
|
/* Get destination pointer, exchange value and comperand value/address */
|
|
|
|
mov ebp, ecx
|
|
|
|
mov ebx, [edx]
|
|
|
|
mov ecx, [edx+4]
|
|
|
|
mov edx, [esp+12]
|
|
|
|
mov eax, [edx]
|
|
|
|
mov edx, [edx+4]
|
|
|
|
|
|
|
|
/* Do the op */
|
2009-11-02 18:40:24 +00:00
|
|
|
LOCK cmpxchg8b qword ptr [ebp]
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Restore volatiles */
|
|
|
|
pop ebp
|
|
|
|
pop ebx
|
|
|
|
|
|
|
|
/* Return */
|
|
|
|
ret 4
|
|
|
|
|
|
|
|
/*PVOID
|
|
|
|
*FASTCALL
|
2011-07-20 13:48:06 +00:00
|
|
|
*ExInterlockedCompareExchange64(IN PLONGLONG Destination,
|
|
|
|
* IN PLONGLONG Exchange,
|
|
|
|
* IN PLONGLONG Comperand,
|
|
|
|
* IN PKSPIN_LOCK Lock)
|
2009-10-12 03:35:35 +00:00
|
|
|
*/
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC @ExInterlockedCompareExchange64@16
|
2009-10-12 03:35:35 +00:00
|
|
|
@ExInterlockedCompareExchange64@16:
|
|
|
|
|
|
|
|
/* Save registers */
|
2011-07-20 13:48:06 +00:00
|
|
|
push ebx
|
2009-10-12 03:35:35 +00:00
|
|
|
push ebp
|
|
|
|
|
|
|
|
/* Get destination pointer, exchange value and comperand value/address */
|
|
|
|
mov ebp, ecx
|
|
|
|
mov ebx, [edx]
|
|
|
|
mov ecx, [edx+4]
|
|
|
|
mov edx, [esp+12]
|
|
|
|
mov eax, [edx]
|
|
|
|
mov edx, [edx+4]
|
|
|
|
|
|
|
|
/* Do the op */
|
2009-11-02 18:40:24 +00:00
|
|
|
LOCK cmpxchg8b qword ptr [ebp]
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Restore volatiles */
|
|
|
|
pop ebp
|
|
|
|
pop ebx
|
|
|
|
|
|
|
|
/* Return */
|
|
|
|
ret 8
|
|
|
|
|
|
|
|
/*** Non-586 functions ***/
|
|
|
|
|
|
|
|
/*PSINGLE_LIST_ENTRY
|
|
|
|
*FASTCALL
|
|
|
|
*ExfInterlockedPopEntrySList(IN PSINGLE_LIST_ENTRY ListHead,
|
|
|
|
* IN PKSPIN_LOCK Lock)
|
|
|
|
*/
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC @ExfInterlockedPopEntrySList@8
|
2009-10-12 03:35:35 +00:00
|
|
|
@ExfInterlockedPopEntrySList@8:
|
|
|
|
|
|
|
|
/* Save flags */
|
|
|
|
.starta:
|
|
|
|
pushfd
|
|
|
|
|
|
|
|
/* Disable interrupts */
|
|
|
|
cli
|
|
|
|
|
|
|
|
/* Acquire lock */
|
|
|
|
ACQUIRE_SPINLOCK(edx, .spina)
|
|
|
|
|
|
|
|
/* Get the next link and check if it's empty */
|
|
|
|
mov eax, [ecx]
|
|
|
|
or eax, eax
|
2010-11-27 22:12:15 +00:00
|
|
|
jz .l12
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Get address of the next link and store it */
|
|
|
|
push [eax]
|
|
|
|
pop [ecx]
|
|
|
|
|
|
|
|
/* Decrement list depth */
|
|
|
|
dec dword ptr [ecx+4]
|
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
.l12:
|
2009-10-12 03:35:35 +00:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Release spinlock */
|
|
|
|
RELEASE_SPINLOCK(edx)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Restore flags and return */
|
|
|
|
popfd
|
|
|
|
ret 0
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
.spina:
|
|
|
|
/* Restore flags and spin */
|
|
|
|
popfd
|
|
|
|
SPIN_ON_LOCK(edx, .starta)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*PSINGLE_LIST_ENTRY
|
|
|
|
*FASTCALL
|
|
|
|
*ExfInterlockedPushEntrySList(IN PSINGLE_LIST_ENTRY ListHead,
|
|
|
|
* IN PSINGLE_LIST_ENTRY ListEntry,
|
|
|
|
* IN PKSPIN_LOCK Lock)
|
|
|
|
*/
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC @ExfInterlockedPushEntrySList@12
|
2009-10-12 03:35:35 +00:00
|
|
|
@ExfInterlockedPushEntrySList@12:
|
|
|
|
|
|
|
|
/* Save flags */
|
|
|
|
.startb:
|
|
|
|
pushfd
|
|
|
|
|
|
|
|
/* Disable interrupts */
|
|
|
|
cli
|
|
|
|
|
|
|
|
/* Acquire lock */
|
|
|
|
#ifndef CONFIG_SMP
|
|
|
|
mov eax, [esp+8]
|
|
|
|
ACQUIRE_SPINLOCK(eax, .spinb)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Get the next link and check if it's empty */
|
|
|
|
push [ecx]
|
|
|
|
|
|
|
|
/* Get address of the next link and store it */
|
|
|
|
pop [edx]
|
|
|
|
mov [ecx], edx
|
|
|
|
|
|
|
|
/* Increment list depth */
|
|
|
|
inc dword ptr [ecx+4]
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Release spinlock */
|
|
|
|
RELEASE_SPINLOCK(eax)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Restore flags and return */
|
|
|
|
popfd
|
|
|
|
ret 4
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
.spinb:
|
|
|
|
/* Restore flags and spin */
|
|
|
|
popfd
|
|
|
|
SPIN_ON_LOCK(eax, .startb)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*PVOID
|
|
|
|
*FASTCALL
|
|
|
|
*ExpInterlockedCompareExchange64(IN PLONGLONG Destination,
|
|
|
|
* IN PLONGLONG Exchange,
|
|
|
|
* IN PLONGLONG Comperand,
|
|
|
|
* IN PKSPIN_LOCK Lock)
|
|
|
|
*/
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC @ExpInterlockedCompareExchange64@16
|
2009-10-12 03:35:35 +00:00
|
|
|
@ExpInterlockedCompareExchange64@16:
|
|
|
|
|
|
|
|
/* Save registers */
|
|
|
|
push ebp
|
|
|
|
push ebp
|
|
|
|
|
|
|
|
/* Get destination pointer, exchange value and comperand value/address */
|
|
|
|
mov ebp, ecx
|
|
|
|
mov ebx, [edx]
|
|
|
|
mov ecx, [edx+4]
|
|
|
|
mov edx, [esp+12]
|
|
|
|
mov eax, [edx]
|
|
|
|
mov edx, [edx+4]
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Save ESI so we can store KSPINLOCK in it */
|
|
|
|
push esi
|
|
|
|
|
|
|
|
/* Save flags and lock, and disable interrupts */
|
|
|
|
pushfd
|
|
|
|
mov esi, [esp+24]
|
|
|
|
.startc:
|
|
|
|
cli
|
|
|
|
|
|
|
|
/* Acquire the spinlock */
|
|
|
|
ACQUIRE_SPINLOCK(esi, .spinc)
|
|
|
|
#else
|
|
|
|
/* Save flags and disable interrupts */
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Compare bottom */
|
|
|
|
cmp eax, [ebp]
|
|
|
|
jne NoMatch
|
|
|
|
|
|
|
|
/* Compare top */
|
|
|
|
cmp edx, [ebp+4]
|
|
|
|
jne NoMatch
|
|
|
|
|
|
|
|
/* Save new value */
|
|
|
|
mov [ebp], ebx
|
|
|
|
mov [ebp+4], ecx
|
|
|
|
|
|
|
|
AfterSave:
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Release lock, restore volatiles and flags */
|
|
|
|
RELEASE_SPINLOCK(esi)
|
|
|
|
popfd
|
|
|
|
pop esi
|
|
|
|
#else
|
|
|
|
popfd
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Restore the other volatiles and return */
|
|
|
|
pop ebp
|
|
|
|
pop ebx
|
|
|
|
|
|
|
|
/* Return */
|
|
|
|
ret 8
|
|
|
|
|
|
|
|
NoMatch:
|
|
|
|
/* Return the current value */
|
|
|
|
mov eax, [ebp]
|
|
|
|
mov edx, [ebp+4]
|
|
|
|
jmp AfterSave
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
.spinc:
|
|
|
|
/* Restore flags and spin */
|
|
|
|
popfd
|
|
|
|
pushfd
|
|
|
|
SPIN_ON_LOCK(esi, .startc)
|
|
|
|
#endif
|
2010-11-27 22:12:15 +00:00
|
|
|
|
|
|
|
END
|
2009-10-12 03:35:35 +00:00
|
|
|
/* EOF */
|