[NTDLL]: Use LOCK instead of lock for SList assembly functions, this is a conditional...
[reactos.git] / reactos / lib / rtl / i386 / interlck.S
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/rtl/i386/interlck.S
5 * PURPOSE: Rtl Interlocked Functions for x86
6 * PROGRAMMERS: Timo Kreuzer
7 */
8
9 .intel_syntax noprefix
10
11 /* FUNCTIONS ****************************************************************/
12
13
14 /* PSLIST_ENTRY
15 * NTAPI
16 * RtlInterlockedPopEntrySList(
17 * IN PSLIST_HEADER ListHead);
18 */
19 .global _ExpInterlockedPopEntrySListResume@0
20 .global _ExpInterlockedPopEntrySListEnd@0
21 .global _ExpInterlockedPopEntrySListFault@0
22 .global _RtlInterlockedPopEntrySList@4
23 _RtlInterlockedPopEntrySList@4:
24
25 /* Save registers */
26 push ebx
27 push ebp
28
29 /* Load ListHead into ebp */
30 mov ebp, [esp + 12]
31 _ExpInterlockedPopEntrySListResume@0:
32 /* Load ListHead->Next into eax */
33 mov eax, [ebp]
34
35 /* Load ListHead->Depth and ListHead->Sequence into edx */
36 mov edx, [ebp + 4]
37
38 1:
39 /* Check if ListHead->Next is NULL */
40 or eax, eax
41 jz 2f
42
43 /* Copy Depth and Sequence number and adjust Depth */
44 lea ecx, [edx - 1]
45
46 _ExpInterlockedPopEntrySListFault@0:
47 /* Get next pointer */
48 mov ebx, [eax]
49 _ExpInterlockedPopEntrySListEnd@0:
50 /* If [ebp] equals edx:eax, exchange it with ecx:ebx */
51 LOCK cmpxchg8b qword ptr [ebp]
52
53 /* If not equal, retry with edx:eax, being the content of [ebp] now */
54 jnz _ExpInterlockedPopEntrySListResume@0
55
56 /* Restore registers and return */
57 2:
58 pop ebp
59 pop ebx
60 ret 4
61
62
63 /* PSLIST_ENTRY
64 * NTAPI
65 * RtlInterlockedPushEntrySList(
66 * IN PSLIST_HEADER ListHead,
67 * IN PSLIST_ENTRY ListEntry);
68 */
69 .global _RtlInterlockedPushEntrySList@8
70 _RtlInterlockedPushEntrySList@8:
71
72 /* Save registers */
73 push ebx
74 push ebp
75
76 /* Load ListHead into ebp */
77 mov ebp, [esp + 12]
78
79 /* Load ListEntry into ebx */
80 mov ebx, [esp + 16]
81
82 /* Load ListHead->Next into eax */
83 mov eax, [ebp]
84
85 /* Load ListHead->Depth and ListHead->Sequence into edx */
86 mov edx, [ebp + 4]
87
88 1:
89 /* Set ListEntry->Next to ListHead->Next */
90 mov [ebx], eax
91
92 /* Copy ListHead->Depth and ListHead->Sequence and adjust them */
93 lea ecx, [edx + 0x10001]
94
95 /* If [ebp] equals edx:eax, exchange it with ecx:ebx */
96 LOCK cmpxchg8b qword ptr [ebp]
97
98 /* If not equal, retry with edx:eax, being the content of [ebp] now */
99 jnz 1b
100
101 /* Restore registers and return */
102 pop ebp
103 pop ebx
104 ret 8
105
106
107 /* PSLIST_ENTRY
108 * NTAPI
109 * RtlInterlockedFlushSList(
110 * IN PSINGLE_LIST_ENTRY ListHead);
111 */
112 .global _RtlInterlockedFlushSList@4
113 _RtlInterlockedFlushSList@4:
114
115 /* Save registers */
116 push ebx
117 push ebp
118
119 /* Clear ebx */
120 xor ebx, ebx
121
122 /* Load ListHead into ebp */
123 mov ebp, [esp + 12]
124
125 /* Load ListHead->Next into eax */
126 mov eax, [ebp]
127
128 /* Load ListHead->Depth and ListHead->Sequence into edx */
129 mov edx, [ebp + 4]
130
131 1:
132 /* Check if ListHead->Next is NULL */
133 or eax, eax
134 jz 2f
135
136 /* Copy Depth and Sequence number to ecx */
137 mov ecx, edx
138
139 /* Clear Depth in cx */
140 xor cx, cx
141
142 /* If [ebp] equals edx:eax, exchange it with ecx:ebx */
143 LOCK cmpxchg8b qword ptr [ebp]
144
145 /* If not equal, retry with edx:eax, being the content of [ebp] now */
146 jnz 1b
147
148 /* Restore registers and return */
149 2:
150 pop ebp
151 pop ebx
152 ret 4