Author: tkreuzer Date: Thu Nov 26 23:40:07 2009 New Revision: 44289
URL: http://svn.reactos.org/svn/reactos?rev=44289&view=rev Log: - rewrite the completely broken RtlInterlockedPopEntrySList, implement RtlInterlockedPushEntrySList, RtlInterlockedFlushSList - use these for ExpInterlocked* - remove a bunch of Interlocked* functions from amd64 kernel exports
Added: branches/ros-amd64-bringup/reactos/lib/rtl/amd64/slist.S - copied, changed from r44068, branches/ros-amd64-bringup/reactos/lib/rtl/amd64/interlck.S Removed: branches/ros-amd64-bringup/reactos/lib/rtl/amd64/interlck.S Modified: branches/ros-amd64-bringup/reactos/lib/rtl/rtl.rbuild branches/ros-amd64-bringup/reactos/ntoskrnl/ex/amd64/fastinterlck.c branches/ros-amd64-bringup/reactos/ntoskrnl/ntoskrnl.pspec
Removed: branches/ros-amd64-bringup/reactos/lib/rtl/amd64/interlck.S URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/lib/rt... ============================================================================== --- branches/ros-amd64-bringup/reactos/lib/rtl/amd64/interlck.S [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/lib/rtl/amd64/interlck.S (removed) @@ -1,188 +1,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/rtl/amd64/interlck.S - * PURPOSE: Rtl Interlocked Functions for amd64 - * PROGRAMMERS: Timo Kreuzer - */ - -#include <ndk/asm.h> -#include <ndk/amd64/asmmacro.S> -.intel_syntax noprefix - - -#define SLIST8A_DEPTH_MASK 0x000000000000FFFF -#define SLIST8A_DEPTH_INC 0x0000000000000001 -#define SLIST8A_SEQUENCE_MASK 0x0000000001FF0000 -#define SLIST8A_SEQUENCE_INC 0x0000000000010000 -#define SLIST8A_NEXTENTRY_MASK 0xFFFFFFFFFE000000 -#define SLIST8A_NEXTENTRY_SHIFT 21 -#define SLIST8B_HEADERTYPE_MASK 0x0000000000000001 -#define SLIST8B_INIT_MASK 0x0000000000000002 -#define SLIST8B_REGION_MASK 0xE000000000000000 - -#define SLIST16A_DEPTH_MASK 0x000000000000FFFF -#define SLIST16A_DEPTH_INC 0x0000000000000001 -#define SLIST16A_SEQUENCE_MASK 0xFFFFFFFFFFFF0000 -#define SLIST16B_HEADERTYPE_MASK 0x0000000000000001 -#define SLIST16B_INIT_MASK 0x0000000000000002 -#define SLIST16B_NEXTENTY_MASK 0xFFFFFFFFFFFFFFF0 - - -POINTER_MASK: .quad 0x000007FFFFFFFFF0 - -SLIST16_POINTER_MASK: .quad 0xFFFFFFFFFFFFFFF0 - - -/* FUNCTIONS ****************************************************************/ - - -/* PSLIST_ENTRY - * NTAPI - * RtlInterlockedPopEntrySList( - * IN PSLIST_HEADER ListHead); - */ -.proc RtlInterlockedPopEntrySList - - /* Save registers */ - push rbx - push rbp - - /* Load ListHead->Region into rax */ - mov rax, [rcx + 8] - - /* Check what kind of header this is */ - test rax, SLIST8B_HEADERTYPE_MASK - jnz 3f - - /* We have an 8 byte header */ - - /* Load ListHead->Alignment into rax */ - mov rax, [rcx] - - /* Check if ListHead->NextEntry is NULL */ - and rax, SLIST8A_NEXTENTRY_MASK - jz 2f - - /* Copy rcx to rbp, as we need ecx for the exchange */ - mov rbp, rcx - - /* Copy the low 32 bits to eax */ - mov eax, [rbp] - - /* Copy the high 32 bits to edx */ - mov edx, [rbp + 4] - -1: - /* Use rbp as pointer template in rbx*/ - mov rbx, rbp - and rbx, POINTER_MASK - - /* Extract the NextEntry pointer */ - mov rcx, [rbp] - and rcx, SLIST8A_NEXTENTRY_MASK - shr rcx, SLIST8A_NEXTENTRY_SHIFT - - /* Combine to new pointer in rcx */ - or rcx, rbx - - /* Load the next NextEntry pointer to rcx */ - mov rcx, [rcx] - - /* Copy Depth and Sequence number and adjust Depth */ - lea rbx, [rax - SLIST8A_DEPTH_INC] - - /* Shift bits in place */ - shl rcx, SLIST8A_NEXTENTRY_SHIFT - - /* Combine into rbx */ - and rbx, SLIST8A_SEQUENCE_INC | SLIST8A_DEPTH_MASK - or rbx, rcx - - /* Copy higher 32 bits into ecx */ - mov rcx, rbx - shr rcx, 32 - - /* If [rbp] equals edx:eax, exchange it with ecx:ebx */ - lock cmpxchg8b [rbp] - - /* If not equal, retry with edx:eax, being the content of [rbp] now */ - jnz 1b - - /* Move result from edx:eax to rax */ - shl rdx, 32 - or rax, rdx - - /* Use rbp as pointer template */ - and rbp, POINTER_MASK - - and rax, SLIST8A_NEXTENTRY_MASK - shr rax, SLIST8A_NEXTENTRY_SHIFT - or rax, rbp - -2: - /* Restore registers and return */ - pop rbp - pop rbx - ret - -3: /* This is a 16 byte header */ - - /* Copy rcx to rbp, as we need rcx for the exchange */ - mov rbp, rcx - - -4: - /* Check if ListHead->NextEntry is NULL */ - mov rcx, rdx - and rcx, SLIST16_POINTER_MASK - jz 5f - - /* Copy Depth and Sequence number and adjust Depth */ - lea rbx, [rax - SLIST16A_DEPTH_INC] - - /* Get next pointer */ - mov rcx, [rcx] - - /* Set ListHead->HeaderType = 1 */ - or rcx, 1 - - /* If [rbp] equals rdx:rax, exchange it with rcx:rbx */ - lock cmpxchg16b [rbp] - - /* If not equal, retry with rdx:rax, being the content of [rbp] now */ - jnz 4b - -5: - - - /* Restore registers and return */ - pop rbp - pop rbx - ret -.endproc - - -/* PSLIST_ENTRY - * NTAPI - * RtlInterlockedPushEntrySList( - * IN PSLIST_HEADER ListHead, - * IN PSLIST_ENTRY ListEntry); - */ -.proc RtlInterlockedPushEntrySList - - - ret -.endproc - - -/* PSLIST_ENTRY - * NTAPI - * RtlInterlockedFlushSList( - * IN PSINGLE_LIST_ENTRY ListHead); - */ -.proc RtlInterlockedFlushSList - - - ret -.endproc
Copied: branches/ros-amd64-bringup/reactos/lib/rtl/amd64/slist.S (from r44068, branches/ros-amd64-bringup/reactos/lib/rtl/amd64/interlck.S) URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/lib/rt... ============================================================================== --- branches/ros-amd64-bringup/reactos/lib/rtl/amd64/interlck.S [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/lib/rtl/amd64/slist.S [iso-8859-1] Thu Nov 26 23:40:07 2009 @@ -10,32 +10,37 @@ #include <ndk/amd64/asmmacro.S> .intel_syntax noprefix
- -#define SLIST8A_DEPTH_MASK 0x000000000000FFFF -#define SLIST8A_DEPTH_INC 0x0000000000000001 -#define SLIST8A_SEQUENCE_MASK 0x0000000001FF0000 -#define SLIST8A_SEQUENCE_INC 0x0000000000010000 -#define SLIST8A_NEXTENTRY_MASK 0xFFFFFFFFFE000000 -#define SLIST8A_NEXTENTRY_SHIFT 21 -#define SLIST8B_HEADERTYPE_MASK 0x0000000000000001 -#define SLIST8B_INIT_MASK 0x0000000000000002 -#define SLIST8B_REGION_MASK 0xE000000000000000 +#define SLIST8A_DEPTH_MASK 0x000000000000FFFF +#define SLIST8A_DEPTH_INC 0x0000000000000001 +#define SLIST8A_SEQUENCE_MASK 0x0000000001FF0000 +#define SLIST8A_SEQUENCE_INC 0x0000000000010000 +#define SLIST8A_NEXTENTRY_MASK 0xFFFFFFFFFE000000 +#define SLIST8A_NEXTENTRY_SHIFT 21 +#define SLIST8B_HEADERTYPE_MASK 0x0000000000000001 +#define SLIST8B_INIT_MASK 0x0000000000000002 +#define SLIST8B_REGION_MASK 0xE000000000000000 +#define SLIST8_POINTER_MASK 0x000007FFFFFFFFF0
#define SLIST16A_DEPTH_MASK 0x000000000000FFFF #define SLIST16A_DEPTH_INC 0x0000000000000001 #define SLIST16A_SEQUENCE_MASK 0xFFFFFFFFFFFF0000 +#define SLIST16A_SEQUENCE_INC 0x0000000000010000 #define SLIST16B_HEADERTYPE_MASK 0x0000000000000001 #define SLIST16B_INIT_MASK 0x0000000000000002 #define SLIST16B_NEXTENTY_MASK 0xFFFFFFFFFFFFFFF0
-POINTER_MASK: .quad 0x000007FFFFFFFFF0 - -SLIST16_POINTER_MASK: .quad 0xFFFFFFFFFFFFFFF0 - - /* FUNCTIONS ****************************************************************/
+.global _ExpInterlockedPopEntrySList +.global _ExpInterlockedPopEntrySListResume +.global _ExpInterlockedPopEntrySListFault +.global _ExpInterlockedPopEntrySListEnd +.global _ExpInterlockedPopEntrySListResume16 +.global _ExpInterlockedPopEntrySListFault16 +.global _ExpInterlockedPopEntrySListEnd16 +.global _ExpInterlockedPushEntrySList +.global _ExpInterlockedFlushSList
/* PSLIST_ENTRY * NTAPI @@ -43,123 +48,124 @@ * IN PSLIST_HEADER ListHead); */ .proc RtlInterlockedPopEntrySList - - /* Save registers */ - push rbx - push rbp - - /* Load ListHead->Region into rax */ - mov rax, [rcx + 8] - - /* Check what kind of header this is */ - test rax, SLIST8B_HEADERTYPE_MASK - jnz 3f - - /* We have an 8 byte header */ +_ExpInterlockedPopEntrySList: + + /* Load ListHead->Region into rdx */ + mov rdx, [rcx + 8]
/* Load ListHead->Alignment into rax */ mov rax, [rcx]
+ /* Check what kind of header this is */ + test rdx, SLIST8B_HEADERTYPE_MASK + jnz _RtlInterlockedPopEntrySList16 + + /* We have an 8 byte header */ + +_ExpInterlockedPopEntrySListResume: + /* Check if ListHead->NextEntry is NULL */ - and rax, SLIST8A_NEXTENTRY_MASK - jz 2f - - /* Copy rcx to rbp, as we need ecx for the exchange */ - mov rbp, rcx - - /* Copy the low 32 bits to eax */ - mov eax, [rbp] - - /* Copy the high 32 bits to edx */ - mov edx, [rbp + 4] - -1: - /* Use rbp as pointer template in rbx*/ - mov rbx, rbp - and rbx, POINTER_MASK - - /* Extract the NextEntry pointer */ - mov rcx, [rbp] - and rcx, SLIST8A_NEXTENTRY_MASK - shr rcx, SLIST8A_NEXTENTRY_SHIFT - - /* Combine to new pointer in rcx */ - or rcx, rbx - - /* Load the next NextEntry pointer to rcx */ - mov rcx, [rcx] + mov r9, rax + and r9, SLIST8A_NEXTENTRY_MASK + jz _RtlInterlockedPopEntrySListEmpty
/* Copy Depth and Sequence number and adjust Depth */ - lea rbx, [rax - SLIST8A_DEPTH_INC] + lea r8, [rax - SLIST8A_DEPTH_INC] + and r8, SLIST8A_SEQUENCE_MASK | SLIST8A_DEPTH_MASK + + /* Create a pointer template from rcx in rdx */ + mov rdx, ~SLIST8_POINTER_MASK + and rdx, rcx + + /* Shift the NextEntry pointer */ + shr r9, SLIST8A_NEXTENTRY_SHIFT + + /* Combine to new pointer in rdx */ + or rdx, r9 + +_ExpInterlockedPopEntrySListFault: + + /* Load the next NextEntry pointer to r9 */ + mov r9, [rdx]
/* Shift bits in place */ - shl rcx, SLIST8A_NEXTENTRY_SHIFT - - /* Combine into rbx */ - and rbx, SLIST8A_SEQUENCE_INC | SLIST8A_DEPTH_MASK - or rbx, rcx - - /* Copy higher 32 bits into ecx */ - mov rcx, rbx - shr rcx, 32 - - /* If [rbp] equals edx:eax, exchange it with ecx:ebx */ - lock cmpxchg8b [rbp] - - /* If not equal, retry with edx:eax, being the content of [rbp] now */ - jnz 1b - - /* Move result from edx:eax to rax */ - shl rdx, 32 - or rax, rdx - - /* Use rbp as pointer template */ - and rbp, POINTER_MASK - + shl r9, SLIST8A_NEXTENTRY_SHIFT + + /* Combine into r8 */ + or r8, r9 + +_ExpInterlockedPopEntrySListEnd: + + /* If [rcx] equals rax, exchange it with r8 */ + lock cmpxchg [rcx], r8 + + /* If not equal, retry with rax, being the content of [rcx] now */ + jnz _ExpInterlockedPopEntrySListResume + + /* Shift the pointer bits in place */ and rax, SLIST8A_NEXTENTRY_MASK shr rax, SLIST8A_NEXTENTRY_SHIFT - or rax, rbp - -2: - /* Restore registers and return */ - pop rbp - pop rbx - ret - -3: /* This is a 16 byte header */ - - /* Copy rcx to rbp, as we need rcx for the exchange */ - mov rbp, rcx - - -4: + + /* Use rcx as pointer template */ + mov rdx, ~SLIST8_POINTER_MASK + or rdx, rcx + + /* Combine result and return */ + or rax, rdx + ret + +_RtlInterlockedPopEntrySListEmpty: + xor rax, rax + ret + +_RtlInterlockedPopEntrySList16: + /* This is a 16 byte header */ + + /* Save rbx */ + push rbx + + /* Copy rcx to r8, as we need rcx for the exchange */ + mov r8, rcx + +_ExpInterlockedPopEntrySListResume16: + /* Check if ListHead->NextEntry is NULL */ - mov rcx, rdx - and rcx, SLIST16_POINTER_MASK - jz 5f + mov r9, rdx + and r9, SLIST16B_NEXTENTY_MASK + jz _RtlInterlockedPopEntrySListEmpty16 + +_ExpInterlockedPopEntrySListFault16: + + /* Get next pointer */ + mov rcx, [r9] + + /* Set ListHead->HeaderType = 1 and ListHead->Init = 1 */ + or rcx, 0x3
/* Copy Depth and Sequence number and adjust Depth */ lea rbx, [rax - SLIST16A_DEPTH_INC]
- /* Get next pointer */ - mov rcx, [rcx] - - /* Set ListHead->HeaderType = 1 */ - or rcx, 1 - - /* If [rbp] equals rdx:rax, exchange it with rcx:rbx */ - lock cmpxchg16b [rbp] - - /* If not equal, retry with rdx:rax, being the content of [rbp] now */ - jnz 4b - -5: - - - /* Restore registers and return */ - pop rbp +_ExpInterlockedPopEntrySListEnd16: + + /* If [r8] equals rdx:rax, exchange it with rcx:rbx */ + lock cmpxchg16b [r8] + + /* If not equal, retry with rdx:rax, being the content of [r8] now */ + jnz _ExpInterlockedPopEntrySListResume16 + + /* Copy the old NextEntry pointer to rax */ + mov rax, rdx + and rax, SLIST16B_NEXTENTY_MASK + + /* Return */ pop rbx ret + +_RtlInterlockedPopEntrySListEmpty16: + xor rax, rax + pop rbx + ret + .endproc
@@ -170,11 +176,109 @@ * IN PSLIST_ENTRY ListEntry); */ .proc RtlInterlockedPushEntrySList - - - ret +_ExpInterlockedPushEntrySList: + + /* Move 2nd parameter to r9 */ + mov r9, rdx + + /* Load ListHead->Region into rdx */ + mov rdx, [rcx + 8] + + /* Load ListHead->Alignment into rax */ + mov rax, [rcx] + + /* Check what kind of header this is */ + test rdx, SLIST8B_HEADERTYPE_MASK + jnz _RtlInterlockedPushEntrySList16 + + /* We have an 8 byte header */ + +_RtlInterlockedPushEntrySListLoop: + + /* Get ListHead->NextEntry */ + mov r8, rax + and r8, SLIST8A_NEXTENTRY_MASK + + /* Shift the NextEntry pointer */ + shr r8, SLIST8A_NEXTENTRY_SHIFT + + /* Create a pointer template from rcx in rdx */ + mov rdx, ~SLIST8_POINTER_MASK + and rdx, rcx + + /* Combine to new pointer and save as ListEntry->NextEntry */ + or rdx, r8 + mov [r9], rdx + + /* Shift and mask the new ListEntry pointer */ + shl r9, SLIST8A_NEXTENTRY_SHIFT + and r9, SLIST8A_NEXTENTRY_MASK + + /* Copy and adjust depth and sequence number */ + lea r8, [rax + SLIST8A_DEPTH_INC + SLIST8A_SEQUENCE_INC] + and r8, SLIST8A_SEQUENCE_MASK | SLIST8A_DEPTH_MASK + + /* Combine to exchange value in r8 */ + or r8, r9 + + /* If [rcx] equals rax, exchange it with r8 */ + lock cmpxchg [rcx], r8 + + /* If not equal, retry with rax, being the content of [rcx] now */ + jnz _RtlInterlockedPushEntrySListLoop + + /* Shift the pointer bits in place */ + and rax, SLIST8A_NEXTENTRY_MASK + shr rax, SLIST8A_NEXTENTRY_SHIFT + + /* Use rcx as pointer template */ + mov rdx, ~SLIST8_POINTER_MASK + or rdx, rcx + + /* Combine result and return */ + or rax, rdx + ret + +_RtlInterlockedPushEntrySList16: + /* This is a 16 byte header */ + + /* Save rbx */ + push rbx + + /* Copy rcx to r8, as we need rcx for the exchange */ + mov r8, rcx + + /* Set ListHead->HeaderType = 1 and ListHead->Init = 1 */ + mov rcx, r9 + or rcx, 0x3 + +_RtlInterlockedPushEntrySListLoop16: + + /* Move ListHead->NextEntry to rbx */ + mov rbx, rdx + and rbx, SLIST16B_NEXTENTY_MASK + + /* Store next pointer in ListEntry->NextEntry */ + mov [r9], rbx + + /* Copy Depth and Sequence number and adjust Depth */ + lea rbx, [rax + SLIST16A_DEPTH_INC + SLIST16A_SEQUENCE_INC] + + /* If [r8] equals rdx:rax, exchange it with rcx:rbx */ + lock cmpxchg16b [r8] + + /* If not equal, retry with rdx:rax, being the content of [r8] now */ + jnz _RtlInterlockedPushEntrySListLoop16 + + /* Copy the old NextEntry pointer to rax */ + mov rax, rdx + and rax, SLIST16B_NEXTENTY_MASK + + /* Return */ + pop rbx + ret + .endproc -
/* PSLIST_ENTRY * NTAPI @@ -182,7 +286,58 @@ * IN PSINGLE_LIST_ENTRY ListHead); */ .proc RtlInterlockedFlushSList - - - ret +_ExpInterlockedFlushSList: + + /* Load ListHead->Region into rdx */ + mov rax, [rcx + 8] + + /* Check what kind of header this is */ + test rax, SLIST8B_HEADERTYPE_MASK + jnz _RtlInterlockedFlushSList16 + + /* We have an 8 byte header */ + +_RtlInterlockedFlushSListLoop: + + /* Zero ListHead->Alignment */ + xor r8, r8 + + /* If [rcx] equals rax, exchange it with r8 */ + lock cmpxchg [rcx], r8 + + /* If not equal, retry with rax, being the content of [rcx] now */ + jnz _RtlInterlockedFlushSListLoop + + /* Use rcx as pointer template */ + mov rdx, ~SLIST8_POINTER_MASK + or rdx, rcx + + /* Combine result and return */ + or rax, rdx + ret + +_RtlInterlockedFlushSList16: + /* We have a 16 byte header */ + push rbx + + mov rdx, [rcx + 8] + xor rbx, rbx + mov rcx, 0x3 + +_RtlInterlockedFlushSListLoop16: + + /* If [r8] equals rdx:rax, exchange it with rcx:rbx */ + lock cmpxchg16b [r8] + + /* If not equal, retry with rdx:rax, being the content of [r8] now */ + jnz _RtlInterlockedFlushSListLoop16 + + /* Copy the old NextEntry pointer to rax */ + mov rax, rdx + and rax, SLIST16B_NEXTENTY_MASK + + /* Return */ + pop rbx + ret + .endproc
Modified: branches/ros-amd64-bringup/reactos/lib/rtl/rtl.rbuild URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/lib/rt... ============================================================================== --- branches/ros-amd64-bringup/reactos/lib/rtl/rtl.rbuild [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/lib/rtl/rtl.rbuild [iso-8859-1] Thu Nov 26 23:40:07 2009 @@ -39,7 +39,7 @@ <directory name="amd64"> <file>debug_asm.S</file> <file>except_asm.S</file> - <file>interlck.S</file> + <file>slist.S</file> <file>unwind.c</file> <file>stubs.c</file> </directory>
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/ex/amd64/fastinterlck.c URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskr... ============================================================================== --- branches/ros-amd64-bringup/reactos/ntoskrnl/ex/amd64/fastinterlck.c [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/ntoskrnl/ex/amd64/fastinterlck.c [iso-8859-1] Thu Nov 26 23:40:07 2009 @@ -111,27 +111,3 @@ return OldHead; }
-PSLIST_ENTRY -ExpInterlockedFlushSList( - PSLIST_HEADER ListHead) -{ - UNIMPLEMENTED; - return NULL; -} - -PSLIST_ENTRY -ExpInterlockedPopEntrySList( - IN PSLIST_HEADER ListHead) -{ - UNIMPLEMENTED; - return NULL; -} - -PSLIST_ENTRY -ExpInterlockedPushEntrySList( - PSLIST_HEADER ListHead, - PSLIST_ENTRY ListEntry) -{ - UNIMPLEMENTED; - return NULL; -}
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/ntoskrnl.pspec URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskr... ============================================================================== --- branches/ros-amd64-bringup/reactos/ntoskrnl/ntoskrnl.pspec [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/ntoskrnl/ntoskrnl.pspec [iso-8859-1] Thu Nov 26 23:40:07 2009 @@ -339,12 +339,12 @@ @ stdcall InbvSetTextColor(long) @ stdcall InbvSolidColorFill(long long long long long) @ extern InitSafeBootMode +#ifndef __x86_64__ @ FASTCALL InterlockedCompareExchange(ptr long long) @ FASTCALL InterlockedDecrement(ptr) @ FASTCALL InterlockedExchange(ptr long) @ FASTCALL InterlockedExchangeAdd(ptr long) @ FASTCALL InterlockedIncrement(ptr) -#ifndef __x86_64__ @ FASTCALL InterlockedPopEntrySList(ptr) @ FASTCALL InterlockedPushEntrySList(ptr ptr) #endif