xref: /reactos/ntoskrnl/ex/i386/fastinterlck_asm.S (revision 0c2cdcae)
1/*
2 * COPYRIGHT:       See COPYING in the top level directory
3 * PROJECT:         ReactOS kernel
4 * FILE:            ntoskrnl/ex/i386/fastinterlck_asm.S
5 * PURPOSE:         FASTCALL Interlocked Functions
6 * PROGRAMMERS:     Alex Ionescu (alex@relsoft.net)
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include <asm.inc>
12#include <ks386.inc>
13#include <internal/i386/asmmacro.S>
14
15/* FUNCTIONS ****************************************************************/
16
17.code32
18
19/*
20 * NOTE: These functions must obey the following rules:
21 *  - Acquire locks only on MP systems.
22 *  - Be safe at HIGH_LEVEL (no paged access).
23 *  - Preserve flags.
24 *  - Disable interrupts.
25 */
26
27/*VOID
28 *FASTCALL
29 *ExInterlockedAddLargeStatistic(IN PLARGE_INTEGER Addend,
30 *                               IN ULONG Increment)
31 */
32PUBLIC @ExInterlockedAddLargeStatistic@8
33@ExInterlockedAddLargeStatistic@8:
34
35#ifdef CONFIG_SMP
36    /* Do the addition */
37    lock add [ecx], edx
38
39    /* Check for carry bit and return */
40    jc .l1
41    ret
42
43.l1:
44    /* Add carry */
45    lock adc dword ptr [ecx+4], 0
46#else
47    /* Do the addition and add the carry */
48    add dword ptr [ecx], edx
49    adc dword ptr [ecx+4], 0
50#endif
51    /* Return */
52    ret
53
54
55
56/*PSINGLE_LIST_ENTRY
57 *FASTCALL
58 *ExInterlockedPopEntrySList(IN PSINGLE_LIST_ENTRY ListHead,
59 *                           IN PKSPIN_LOCK Lock)
60 */
61PUBLIC @ExInterlockedPopEntrySList@8
62PUBLIC @InterlockedPopEntrySList@4
63PUBLIC _ExpInterlockedPopEntrySListResume@0
64PUBLIC _ExpInterlockedPopEntrySListFault@0
65PUBLIC _ExpInterlockedPopEntrySListEnd@0
66@ExInterlockedPopEntrySList@8:
67@InterlockedPopEntrySList@4:
68
69    /* Save registers */
70    push ebx
71    push ebp
72
73    /* Pointer to list */
74    mov ebp, ecx
75
76    /* Get sequence number and link pointer */
77_ExpInterlockedPopEntrySListResume@0:
78    mov edx, [ebp+4]
79    mov eax, [ebp]
80
81    /* Check if the list is empty */
82    or eax, eax
83    jz .l7
84
85    /* Copy depth and adjust it */
86    lea ecx, [edx-1]
87
88    /* Get next pointer and do the exchange */
89_ExpInterlockedPopEntrySListFault@0:
90    mov ebx, [eax]
91_ExpInterlockedPopEntrySListEnd@0:
92    LOCK cmpxchg8b qword ptr [ebp]
93    jnz _ExpInterlockedPopEntrySListResume@0
94
95    /* Restore registers and return */
96.l7:
97    pop ebp
98    pop ebx
99    ret
100
101/*PSINGLE_LIST_ENTRY
102 *FASTCALL
103 *ExInterlockedPushEntrySList(IN PSINGLE_LIST_ENTRY ListHead,
104 *                            IN PSINGLE_LIST_ENTRY ListEntry,
105 *                            IN PKSPIN_LOCK Lock)
106 */
107PUBLIC @ExInterlockedPushEntrySList@12
108@ExInterlockedPushEntrySList@12:
109
110    /* So we can fall through below */
111    pop [esp]
112
113PUBLIC @InterlockedPushEntrySList@8
114@InterlockedPushEntrySList@8:
115
116    /* Save registers */
117    push ebx
118    push ebp
119
120    /* Pointer to list */
121    mov ebp, ecx
122    mov ebx, edx
123
124    /* Get sequence number and link pointer */
125    mov edx, [ebp+4]
126    mov eax, [ebp]
127
128.l8:
129    /* Set link pointer */
130    mov [ebx], eax
131
132    /* Copy sequence number and adjust it */
133    lea ecx, [edx + HEX(10001)]
134
135    /* Do the exchange */
136    LOCK cmpxchg8b qword ptr [ebp]
137    jnz .l8
138
139    /* Restore registers and return */
140    pop ebp
141    pop ebx
142    ret
143
144/*PSINGLE_LIST_ENTRY
145 *FASTCALL
146 *ExInterlockedFlushSList(IN PSINGLE_LIST_ENTRY ListHead)
147 */
148PUBLIC @ExInterlockedFlushSList@4
149@ExInterlockedFlushSList@4:
150
151    /* Save registers */
152    push ebx
153    push ebp
154
155    /* Clear ebx */
156    xor ebx, ebx
157
158    /* Pointer to list */
159    mov ebp, ecx
160
161    /* Get sequence number and link pointer */
162    mov edx, [ebp+4]
163    mov eax, [ebp]
164
165.l9:
166    /* Check if the list is empty */
167    or eax, eax
168    jz .l10
169
170    /* Clear depth and pointer */
171    mov ecx, edx
172    mov cx, bx
173
174    /* Do the exchange */
175    LOCK cmpxchg8b qword ptr [ebp]
176    jnz .l9
177
178    /* Restore registers and return */
179.l10:
180    pop ebp
181    pop ebx
182    ret
183
184END
185/* EOF */
186