1
COMMENT | -*- Mode: asm; tab-width: 8; c-basic-offset: 4 -*-
2
***** BEGIN LICENSE BLOCK *****
3
Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
The contents of this file are subject to the Mozilla Public License Version
6
1.1 (the "License"); you may not use this file except in compliance with
7
the License. You may obtain a copy of the License at
8
http://www.mozilla.org/MPL/
10
Software distributed under the License is distributed on an "AS IS" basis,
11
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
for the specific language governing rights and limitations under the
15
The Original Code is mozilla.org Code.
17
The Initial Developer of the Original Code is
18
Netscape Communications Corporation.
19
Portions created by the Initial Developer are Copyright (C) 2001
20
the Initial Developer. All Rights Reserved.
24
Alternatively, the contents of this file may be used under the terms of
25
either the GNU General Public License Version 2 or later (the "GPL"), or
26
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
in which case the provisions of the GPL or the LGPL are applicable instead
28
of those above. If you wish to allow use of your version of this file only
29
under the terms of either the GPL or the LGPL, and not to allow others to
30
use your version of this file under the terms of the MPL, indicate your
31
decision by deleting the provisions above and replace them with the notice
32
and other provisions required by the GPL or the LGPL. If you do not delete
33
the provisions above, a recipient may use your version of this file under
34
the terms of any one of the MPL, the GPL or the LGPL.
36
***** END LICENSE BLOCK *****
37
License Version 1.1 (the "License"); you may not use this file
38
except in compliance with the License. You may obtain a copy of
39
the License at http://www.mozilla.org/MPL/
41
Software distributed under the License is distributed on an "AS
42
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
43
implied. See the License for the specific language governing
44
rights and limitations under the License.
46
The Original Code is the Netscape Portable Runtime (NSPR).
48
The Initial Developer of the Original Code is IBM Corporation.
49
Portions created by IBM are Copyright (C) 2001 IBM Corporation.
54
Alternatively, the contents of this file may be used under the
55
terms of the GNU General Public License Version 2 or later (the
56
"GPL"), in which case the provisions of the GPL are applicable
57
instead of those above. If you wish to allow use of your
58
version of this file only under the terms of the GPL and not to
59
allow others to use your version of this file under the MPL,
60
indicate your decision by deleting the provisions above and
61
replace them with the notice and other provisions required by
62
the GPL. If you do not delete the provisions above, a recipient
63
may use your version of this file under either the MPL or the
66
Windows uses inline assembly for their atomic functions, so we have
67
created an assembly file for VACPP on OS/2.
69
This assembly file also contains an implementation of RAM semaphores.
72
The ulTIDPID element of the RAMSEM structure is overloaded in the 386
73
implementation to hold the TID:PID in the lower 31 bits and the lock
79
ASSUME CS:FLAT, DS:FLAT, SS:FLAT, ES:FLAT, FS:FLAT
81
EXTRN Dos32PostEventSem:PROC
82
EXTRN Dos32WaitEventSem:PROC
83
EXTRN Dos32ResetEventSem:PROC
93
ERROR_SEM_TIMEOUT equ 121
94
ERROR_NOT_OWNER equ 288
95
SEM_RELEASE_UNOWNED equ 1
100
DATA SEGMENT DWORD USE32 PUBLIC 'DATA'
102
EXTRN plisCurrent:DWORD
106
CODE32 SEGMENT USE32 PUBLIC 'CODE'
111
PUBLIC _PR_MD_ATOMIC_SET
112
PUBLIC _PR_MD_ATOMIC_ADD
113
PUBLIC _PR_MD_ATOMIC_INCREMENT
114
PUBLIC _PR_MD_ATOMIC_DECREMENT
116
;;;---------------------------------------------------------------------------
117
;;; APIRET _Optlink SemRequest(PRAMSEM pramsem, ULONG ulTimeout);
120
;;; EAX - packed TID:PID word
121
;;; ECX - address of RAMSEM structure
122
;;; EDX - length of timeout in milli-seconds
123
;;;---------------------------------------------------------------------------
127
push ebx ; Save ebx (volatile)
128
mov ecx, eax ; PRAMSEM must be in ecx,
129
; not eax, for cmpxchg
131
mov ebx, dword ptr [plisCurrent]
132
mov eax, dword ptr [ebx+4] ; Place thread id in high
133
; word, process id in low
134
mov ax, word ptr [ebx] ; word
139
cmp (ramsem PTR [ecx]).ramsem_ulTIDPID, ebx ; If we own the sem, just
140
jz short req486_inc_exit ; increment the use count
142
lock inc (ramsem PTR [ecx]).ramsem_cWaiting ; inc waiting flag
144
; lock ; Uncomment for SMP
146
; cmpxchg (ramsem PTR [ecx]).ramsem_ulTIDPID, ebx
147
; (byte 3 is the offset of ulProcessThread into the RAMSEM structure)
151
jnz short req486_sleep
154
lock inc (ramsem PTR [ecx]).ramsem_cLocks
157
pop ebx ; Restore ebx
161
push ecx ; Save ecx (volatile)
162
push edx ; Save edx (volatile)
164
push (ramsem PTR [ecx]).ramsem_hevSem
165
call Dos32WaitEventSem
167
pop edx ; restore edx
168
pop ecx ; restore ecx
170
jne req486_exit ; Exit, if error
172
push ecx ; Save ecx (volatile)
173
push edx ; Save edx (volatile)
174
sub esp, 4 ; Use stack space for
175
push esp ; dummy pulPostCt
176
push (ramsem PTR [ecx]).ramsem_hevSem
177
call Dos32ResetEventSem
179
pop edx ; restore edx
180
pop ecx ; restore ecx
181
jmp req486_test ; Retry the semaphore
185
;;;---------------------------------------------------------------------
186
;;; APIRET _Optlink SemReleasex86(PRAMSEM pramsem, ULONG flFlags);
189
;;; EAX - address of RAMSEM structure
190
;;; ECX - temporary variable
192
;;;---------------------------------------------------------------------
196
test edx, SEM_RELEASE_UNOWNED ; If set, don't bother
197
jnz short rel_ownerok ; getting/checking PID/TID
199
push ebx ; Save ebx (volatile)
200
mov ebx, dword ptr [plisCurrent]
201
mov ecx, dword ptr [ebx+4] ; Place thread id in high
202
; word, process id in low
203
mov cx, word ptr [ebx] ; word
204
pop ebx ; Restore ebx
206
sub ecx, (ramsem PTR [eax]).ramsem_ulTIDPID ; This thread the owner?
207
shl ecx,1 ; Don't compare top bit
208
jnz short rel_notowner
211
test edx, SEM_RELEASE_ALL
214
lock dec (ramsem PTR [eax]).ramsem_cLocks
218
mov (ramsem PTR [eax]).ramsem_ulTIDPID, 0
220
lock inc (ramsem PTR [eax]).ramsem_cPosts
221
mov cx, (ramsem PTR [eax]).ramsem_cWaiting
222
cmp (ramsem PTR [eax]).ramsem_cPosts, cx
230
lock mov (ramsem PTR [eax]).ramsem_cLocks,0
234
mov eax, ERROR_NOT_OWNER
238
mov (ramsem PTR [eax]).ramsem_cPosts, cx
239
push (ramsem PTR [eax]).ramsem_hevSem
240
call Dos32PostEventSem
246
;;;---------------------------------------------------------------------
247
;;; PRInt32 _Optlink _PR_MD_ATOMIC_SET(PRInt32* val, PRInt32 newval)
248
;;;---------------------------------------------------------------------
250
_PR_MD_ATOMIC_SET proc
251
lock xchg dword ptr [eax],edx
254
_PR_MD_ATOMIC_SET endp
256
;;;---------------------------------------------------------------------
257
;;; PRInt32 _Optlink _PR_MD_ATOMIC_ADD(PRInt32* ptr, PRInt32 val)
258
;;;---------------------------------------------------------------------
260
_PR_MD_ATOMIC_ADD proc
262
lock xadd dword ptr [eax], edx
266
_PR_MD_ATOMIC_ADD endp
268
;;;---------------------------------------------------------------------
269
;;; PRInt32 _Optlink _PR_MD_ATOMIC_INCREMENT(PRInt32* val)
270
;;;---------------------------------------------------------------------
272
_PR_MD_ATOMIC_INCREMENT proc
274
lock xadd dword ptr [eax], edx
278
_PR_MD_ATOMIC_INCREMENT endp
280
;;;---------------------------------------------------------------------
281
;;; PRInt32 _Optlink _PR_MD_ATOMIC_DECREMENT(PRInt32* val)
282
;;;---------------------------------------------------------------------
284
_PR_MD_ATOMIC_DECREMENT proc
286
lock xadd dword ptr [eax], edx
290
_PR_MD_ATOMIC_DECREMENT endp