- Timestamp:
- Dec 16, 1999, 1:22:47 AM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/interlock.asm
r2009 r2088 1 ; $Id: interlock.asm,v 1. 5 1999-12-07 18:19:07 sandervl Exp $1 ; $Id: interlock.asm,v 1.6 1999-12-16 00:22:47 sandervl Exp $ 2 2 3 3 ;/* 4 4 ; * Interlocked apis 5 5 ; * 6 ; * IMPORTANT NOTE: THIS CODE WILL NOT RUN ON 386 CPUs,7 ; * 486 IS MINIMUM REQUIREMENT!8 ; *9 6 ; * Copyright 1999 Sander van Leeuwen 10 7 ; * Copyright 1999 Patrick Haller 8 ; * 9 ; * Based on WINE code: win32\thread.c (990815) 10 ; * 11 ; * Copyright 1995 Martin von Loewis 12 ; * Copyright 1997 Onno Hovers 11 13 ; * 12 14 ; * Project Odin Software License can be found in LICENSE.TXT 13 15 ; * 14 16 ; */ 15 . 486P17 .586P 16 18 NAME interlocked 17 19 18 20 CODE32 SEGMENT DWORD PUBLIC USE32 'CODE' 19 21 22 public _InterlockedIncrement@4 20 23 21 ;************************************************************************22 24 ;* InterlockedIncrement [KERNEL32] * 23 25 ;* * … … 28 30 ;* * 29 31 ;* The returned number need not be equal to the result!!!! * 30 ;************************************************************************31 32 32 public _InterlockedIncrement@433 33 _InterlockedIncrement@4 proc near 34 35 ;@@@PH similar to NT4 36 mov ecx, [esp+4] 37 mov eax, 1 38 nop 39 lock xadd dword ptr [ecx], eax 40 inc eax 41 retn 4 42 43 ; @@@PH 1999/12/06 old implementation similar to W95 44 ;var_4 = dword ptr -4 45 ;arg_0 = dword ptr 4 46 ; 47 ; sub esp, 4 48 ; mov eax, [esp + 4 + arg_0] 49 ; lock inc dword ptr [eax] 50 ; mov ecx, 0ffffffffh 51 ; js _ic_2 52 ; jz _ic_1 53 ; inc ecx 54 ;_ic_1: inc ecx 55 ;_ic_2: mov [esp + 4 + var_4], ecx 56 ; mov eax, ecx 57 ; retn 4 58 ; 59 ; @@@PH 1999/12/06 old implementation from WINE 60 ; mov eax, dword ptr [esp+4] ; LPLONG lpAddend 61 ; lock inc dword ptr [eax] 62 ; mov eax, 0 63 ; je @end ; not incremented? 64 ; jl @decr 65 ; inc eax ; ? 66 ; jmp @end 67 ;@decr: dec eax ; ? 68 ;@end: ret 4 34 mov eax, dword ptr [esp+4] ; LPLONG lpAddend 35 lock inc dword ptr [eax] 36 mov eax, 0 37 je @end ; not incremented? 38 jl @decr 39 inc eax ; ? 40 jmp @end 41 @decr: dec eax ; ? 42 @end: ret 4 69 43 _InterlockedIncrement@4 endp 70 44 45 public _InterlockedDecrement@4 71 46 72 ;************************************************************************73 47 ;* InterlockedDecrement [KERNEL32] * 74 48 ;* * … … 79 53 ;* * 80 54 ;* The returned number need not be equal to the result!!!! * 81 ;************************************************************************82 55 83 public _InterlockedDecrement@484 56 _InterlockedDecrement@4 proc near 85 86 ;@@@PH similar to NT4 87 mov ecx, [esp+4] 88 mov eax, 0ffffffffh 89 nop 90 lock xadd dword ptr [ecx], eax 91 dec eax 92 retn 4 93 94 95 ; @@@PH 1999/12/06 old implementation similar to W95 96 ;var_4 = dword ptr -4 97 ;arg_0 = dword ptr 4 98 ; 99 ; sub esp, 4 100 ; mov eax, dword ptr[esp+4+arg_0] 101 ; lock dec dword ptr [eax] 102 ; mov ecx, 0ffffffffh 103 ; js _id_2 104 ; jz _id_1 105 ; inc ecx 106 ;_id_1: inc ecx 107 ;_id_2: mov dword ptr [esp+4+var_4], ecx 108 ; mov eax, ecx 109 ; add esp, 4 110 ; retn 4 111 112 ; @@@PH 1999/12/06 old implementation from WINE 113 ; mov eax, dword ptr [esp+4] ; LPLONG lpAddend 114 ; lock dec dword ptr [eax] 115 ; mov eax, 0 116 ; je @end ; not decremented? 117 ; jl @decr 118 ; inc eax ; ? 119 ; jmp @end 120 ;@decr: dec eax ; ? 121 ;@end: ret 4 122 57 mov eax, dword ptr [esp+4] ; LPLONG lpAddend 58 lock dec dword ptr [eax] 59 mov eax, 0 60 je @end ; not decremented? 61 jl @decr 62 inc eax ; ? 63 jmp @end 64 @decr: dec eax ; ? 65 @end: ret 4 123 66 _InterlockedDecrement@4 endp 124 67 125 68 126 ;************************************************************************ 127 ;* InterlockedExchange [KERNEL32.???] * 128 ;* * 129 ;* Atomically exchanges a pair of values. * 130 ;* * 131 ;* RETURNS * 132 ;* Prior value of value pointed to by Target * 133 ;************************************************************************ 69 public _InterlockedExchange@8 70 ; * InterlockedExchange [KERNEL32.???] 71 ; * 72 ; * Atomically exchanges a pair of values. 73 ; * 74 ; * RETURNS 75 ; * Prior value of value pointed to by Target 134 76 135 public _InterlockedExchange@8136 77 _InterlockedExchange@8 proc near 137 138 ;@@@PH similar to NT4 139 mov ecx, [esp+4] ; LPLONG target 140 mov edx, [esp+8] ; LONG value 141 mov eax, dword ptr [ecx] 142 _ie_1: 143 nop 144 lock cmpxchg dword ptr [ecx], edx 145 jnz _ie_1 146 retn 8 147 148 ; @@@PH 1999/12/06 old implementation similar to W95 149 ;var_4 = dword ptr -4 150 ;arg_0 = dword ptr 8 151 ;arg_4 = dword ptr 0Ch 152 ; 153 ; push ebp 154 ; mov ebp, esp 155 ; sub esp, 4 156 ; mov eax, dword ptr [ebp+arg_0] 157 ; mov ecx, dword ptr [ebp+arg_4] 158 ; xchg ecx, dword ptr [eax] 159 ; mov dword ptr [ebp+var_4], ecx 160 ; mov eax, ecx 161 ; mov esp, ebp 162 ; pop ebp 163 ; retn 8 164 165 ; @@@PH 1999/12/06 old implementation from WINE 166 ; push edx 167 ; mov eax, [esp+12] ; LONG value 168 ; mov edx,[esp+8] ; LPLONG target 169 ; lock xchg eax, dword ptr [edx] 170 ; pop edx 171 ; ret 8 78 push edx 79 mov eax, [esp+12] ; LONG value 80 mov edx,[esp+8] ; LPLONG target 81 lock xchg eax, dword ptr [edx] 82 pop edx 83 ret 4 172 84 _InterlockedExchange@8 endp 173 85 … … 175 87 176 88 public _InterlockedCompareExchange@12 177 ;************************************************************************ 178 ;* InterlockedCompareExchange [KERNEL32.879] 179 ;* 180 ;* Atomically compares Destination and Comperand, and if found equal exchanges 181 ;* the value of Destination with Exchange 182 ;* 183 ;* RETURNS 184 ;* Prior value of value pointed to by Destination 185 ;* 186 ;************************************************************************ 89 ;/************************************************************************ 90 ; * InterlockedCompareExchange [KERNEL32.879] 91 ; * 92 ; * Atomically compares Destination and Comperand, and if found equal exchanges 93 ; * the value of Destination with Exchange 94 ; * 95 ; * RETURNS 96 ; * Prior value of value pointed to by Destination 97 ; */ 187 98 _InterlockedCompareExchange@12 proc near 99 push ebp 100 mov ebp, esp 101 push edx 102 push ebx 188 103 189 ;@@@PH similar to NT4 190 mov ecx, dword ptr [esp + 12] 191 mov edx, dword ptr [esp + 8] 192 mov eax, dword ptr [esp + 4] 193 _ice_1: 194 nop 195 lock cmpxchg dword ptr [ecx], edx 196 retn 12 104 mov ebx, dword ptr [ebp+8] ;PVOID *Destination, /* Address of 32-bit value to exchange */ 105 push dword ptr [ebx] ;save old *Destination 106 mov eax, [ebp+16] ;PVOID Comperand /* value to compare, 32 bits */ 107 mov edx, [ebp+12] ;PVOID Exchange, /* change value, 32 bits */ 108 lock cmpxchg dword ptr [ebx],edx 109 pop eax 197 110 198 199 ; @@@PH 1999/12/06 old implementation from WINE 200 ; push ebp 201 ; mov ebp, esp 202 ; push edx 203 ; push ebx 204 ; 205 ; mov ebx, dword ptr [ebp+8] ;PVOID *Destination, /* Address of 32-bit value to exchange */ 206 ; push dword ptr [ebx] ;save old *Destination 207 ; mov eax, [ebp+16] ;PVOID Comperand /* value to compare, 32 bits */ 208 ; mov edx, [ebp+12] ;PVOID Exchange, /* change value, 32 bits */ 209 ; lock cmpxchg dword ptr [ebx],edx 210 ; pop eax 211 ; 212 ; pop ebx 213 ; pop edx 214 ; pop ebp 215 ; ret 12 111 pop ebx 112 pop edx 113 pop ebp 114 ret 12 216 115 _InterlockedCompareExchange@12 endp 217 116 218 219 ;************************************************************************220 ;* InterlockedExchangeAdd [KERNEL32.880]221 ;*222 ;* Atomically adds Increment to Addend and returns the previous value of223 ;* Addend224 ;*225 ;* RETURNS226 ;* Prior value of value pointed to by cwAddendTarget227 ;*228 ;************************************************************************229 117 public _InterlockedExchangeAdd@8 118 ; * InterlockedExchangeAdd [KERNEL32.880] 119 ; * 120 ; * Atomically adds Increment to Addend and returns the previous value of 121 ; * Addend 122 ; * 123 ; * RETURNS 124 ; * Prior value of value pointed to by cwAddendTarget 125 ; */ 230 126 _InterlockedExchangeAdd@8 proc near 231 232 ;@@@PH similar to NT4 233 mov ecx, dword ptr [esp + 4] 234 mov eax, dword ptr [esp + 8] 235 nop 236 lock xadd dword ptr [ecx], eax 237 retn 8 238 239 ; @@@PH 1999/12/06 old implementation from WINE 240 ; 241 ; push edx 242 ; mov eax, dword ptr [esp+12] ;LONG Increment /* Value to add */ 243 ; mov edx, dword ptr [esp+8] ;PLONG Addend, /* Address of 32-bit value to exchange */ 244 ; lock xadd dword ptr [edx], eax 245 ; pop edx 246 ; ret 8 127 push edx 128 mov eax, dword ptr [esp+12] ;LONG Increment /* Value to add */ 129 mov edx, dword ptr [esp+8] ;PLONG Addend, /* Address of 32-bit value to exchange */ 130 lock xadd dword ptr [edx], eax 131 pop edx 132 ret 8 247 133 _InterlockedExchangeAdd@8 endp 248 134
Note:
See TracChangeset
for help on using the changeset viewer.