1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
COMMENT | -*- Mode: asm; tab-width: 8; c-basic-offset: 4 -*-
The contents of this file are subject to the Mozilla Public
License Version 1.1 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of
the License at http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
implied. See the License for the specific language governing
rights and limitations under the License.
The Original Code is the Netscape Portable Runtime (NSPR).
The Initial Developer of the Original Code is IBM Corporation.
Portions created by IBM are Copyright (C) 2001 IBM Corporation.
All Rights Reserved.
Contributor(s):
Alternatively, the contents of this file may be used under the
terms of the GNU General Public License Version 2 or later (the
"GPL"), in which case the provisions of the GPL are applicable
instead of those above. If you wish to allow use of your
version of this file only under the terms of the GPL and not to
allow others to use your version of this file under the MPL,
indicate your decision by deleting the provisions above and
replace them with the notice and other provisions required by
the GPL. If you do not delete the provisions above, a recipient
may use your version of this file under either the MPL or the
GPL.
Windows uses inline assembly for their atomic functions, so we have
created an assembly file for VACPP on OS/2.
This assembly file also contains an implementation of RAM semaphores.
Notes:
The ulTIDPID element of the RAMSEM structure is overloaded in the 386
implementation to hold the TID:PID in the lower 31 bits and the lock
bit in the high bit
|
page ,132
.486P
ASSUME CS:FLAT, DS:FLAT, SS:FLAT, ES:FLAT, FS:FLAT
EXTRN Dos32PostEventSem:PROC
EXTRN Dos32WaitEventSem:PROC
EXTRN Dos32ResetEventSem:PROC
ramsem STRUC
ramsem_ulTIDPID DD ?
ramsem_hevSem DD ?
ramsem_cLocks DD ?
ramsem_cWaiting DW ?
ramsem_cPosts DW ?
ramsem ENDS
ERROR_SEM_TIMEOUT equ 121
ERROR_NOT_OWNER equ 288
SEM_RELEASE_UNOWNED equ 1
SEM_RELEASE_ALL equ 2
TS_LOCKBIT equ 31
DATA SEGMENT DWORD USE32 PUBLIC 'DATA'
EXTRN plisCurrent:DWORD
DATA ENDS
CODE32 SEGMENT USE32 PUBLIC 'CODE'
PUBLIC SemRequest486
PUBLIC SemReleasex86
PUBLIC _PR_MD_ATOMIC_SET
PUBLIC _PR_MD_ATOMIC_ADD
PUBLIC _PR_MD_ATOMIC_INCREMENT
PUBLIC _PR_MD_ATOMIC_DECREMENT
;;;---------------------------------------------------------------------------
;;; APIRET _Optlink SemRequest(PRAMSEM pramsem, ULONG ulTimeout);
;;;
;;; Registers:
;;; EAX - packed TID:PID word
;;; ECX - address of RAMSEM structure
;;; EDX - length of timeout in milli-seconds
;;;---------------------------------------------------------------------------
ALIGN 10H
SemRequest486 PROC
push ebx ; Save ebx (volatile)
mov ecx, eax ; PRAMSEM must be in ecx,
; not eax, for cmpxchg
mov ebx, dword ptr [plisCurrent]
mov eax, dword ptr [ebx+4] ; Place thread id in high
; word, process id in low
mov ax, word ptr [ebx] ; word
mov ebx,eax
req486_test:
xor eax,eax
cmp (ramsem PTR [ecx]).ramsem_ulTIDPID, ebx ; If we own the sem, just
jz short req486_inc_exit ; increment the use count
lock inc (ramsem PTR [ecx]).ramsem_cWaiting ; inc waiting flag
; lock ; Uncomment for SMP
DB 0F0h
; cmpxchg (ramsem PTR [ecx]).ramsem_ulTIDPID, ebx
; (byte 3 is the offset of ulProcessThread into the RAMSEM structure)
DB 00Fh
DB 0B1h
DB 019h
jnz short req486_sleep
req486_inc_exit:
lock inc (ramsem PTR [ecx]).ramsem_cLocks
req486_exit:
pop ebx ; Restore ebx
ret
req486_sleep:
push ecx ; Save ecx (volatile)
push edx ; Save edx (volatile)
push edx ; timeout
push (ramsem PTR [ecx]).ramsem_hevSem
call Dos32WaitEventSem
add esp, 8
pop edx ; restore edx
pop ecx ; restore ecx
or eax, eax
jne req486_exit ; Exit, if error
push ecx ; Save ecx (volatile)
push edx ; Save edx (volatile)
sub esp, 4 ; Use stack space for
push esp ; dummy pulPostCt
push (ramsem PTR [ecx]).ramsem_hevSem
call Dos32ResetEventSem
add esp, 12
pop edx ; restore edx
pop ecx ; restore ecx
jmp req486_test ; Retry the semaphore
SemRequest486 ENDP
;;;---------------------------------------------------------------------
;;; APIRET _Optlink SemReleasex86(PRAMSEM pramsem, ULONG flFlags);
;;;
;;; Registers:
;;; EAX - address of RAMSEM structure
;;; ECX - temporary variable
;;; EDX - flags
;;;---------------------------------------------------------------------
ALIGN 10H
SemReleasex86 PROC
test edx, SEM_RELEASE_UNOWNED ; If set, don't bother
jnz short rel_ownerok ; getting/checking PID/TID
push ebx ; Save ebx (volatile)
mov ebx, dword ptr [plisCurrent]
mov ecx, dword ptr [ebx+4] ; Place thread id in high
; word, process id in low
mov cx, word ptr [ebx] ; word
pop ebx ; Restore ebx
sub ecx, (ramsem PTR [eax]).ramsem_ulTIDPID ; This thread the owner?
shl ecx,1 ; Don't compare top bit
jnz short rel_notowner
rel_ownerok:
test edx, SEM_RELEASE_ALL
jnz short rel_clear
lock dec (ramsem PTR [eax]).ramsem_cLocks
jnz short rel_exit
rel_disown:
mov (ramsem PTR [eax]).ramsem_ulTIDPID, 0
lock inc (ramsem PTR [eax]).ramsem_cPosts
mov cx, (ramsem PTR [eax]).ramsem_cWaiting
cmp (ramsem PTR [eax]).ramsem_cPosts, cx
jne short rel_post
rel_exit:
xor eax, eax
ret
rel_clear:
lock mov (ramsem PTR [eax]).ramsem_cLocks,0
jmp rel_disown
rel_notowner:
mov eax, ERROR_NOT_OWNER
ret
rel_post:
mov (ramsem PTR [eax]).ramsem_cPosts, cx
push (ramsem PTR [eax]).ramsem_hevSem
call Dos32PostEventSem
add esp,4
xor eax,eax
ret
SemReleasex86 ENDP
;;;---------------------------------------------------------------------
;;; PRInt32 _Optlink _PR_MD_ATOMIC_SET(PRInt32* val, PRInt32 newval)
;;;---------------------------------------------------------------------
ALIGN 10H
_PR_MD_ATOMIC_SET proc
lock xchg dword ptr [eax],edx
mov eax, edx;
ret
_PR_MD_ATOMIC_SET endp
;;;---------------------------------------------------------------------
;;; PRInt32 _Optlink _PR_MD_ATOMIC_ADD(PRInt32* ptr, PRInt32 val)
;;;---------------------------------------------------------------------
ALIGN 10H
_PR_MD_ATOMIC_ADD proc
mov ecx, edx
lock xadd dword ptr [eax], edx
mov eax, edx
add eax, ecx
ret
_PR_MD_ATOMIC_ADD endp
;;;---------------------------------------------------------------------
;;; PRInt32 _Optlink _PR_MD_ATOMIC_INCREMENT(PRInt32* val)
;;;---------------------------------------------------------------------
ALIGN 10H
_PR_MD_ATOMIC_INCREMENT proc
mov edx, 1
lock xadd dword ptr [eax], edx
mov eax, edx
inc eax
ret
_PR_MD_ATOMIC_INCREMENT endp
;;;---------------------------------------------------------------------
;;; PRInt32 _Optlink _PR_MD_ATOMIC_DECREMENT(PRInt32* val)
;;;---------------------------------------------------------------------
ALIGN 10H
_PR_MD_ATOMIC_DECREMENT proc
mov edx, 0ffffffffh
lock xadd dword ptr [eax], edx
mov eax, edx
dec eax
ret
_PR_MD_ATOMIC_DECREMENT endp
CODE32 ENDS
END
|