~ubuntu-branches/ubuntu/gutsy/virtualbox-ose/gutsy

« back to all changes in this revision

Viewing changes to src/libs/xpcom18a4/nsprpub/pr/src/md/os2/os2vacpp.asm

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2007-09-08 16:44:58 UTC
  • Revision ID: james.westby@ubuntu.com-20070908164458-wao29470vqtr8ksy
Tags: upstream-1.5.0-dfsg2
ImportĀ upstreamĀ versionĀ 1.5.0-dfsg2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 
 
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/
 
9
 
 
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
 
13
 License.
 
14
 
 
15
 The Original Code is mozilla.org Code.
 
16
 
 
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.
 
21
 
 
22
 Contributor(s):
 
23
 
 
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.
 
35
 
 
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/
 
40
 
 
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.
 
45
 
 
46
        The Original Code is the Netscape Portable Runtime (NSPR).
 
47
 
 
48
        The Initial Developer of the Original Code is IBM Corporation.
 
49
        Portions created by IBM are Copyright (C) 2001 IBM Corporation.
 
50
        All Rights Reserved.
 
51
 
 
52
        Contributor(s):
 
53
 
 
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
 
64
        GPL.
 
65
 
 
66
        Windows uses inline assembly for their atomic functions, so we have
 
67
        created an assembly file for VACPP on OS/2.
 
68
 
 
69
        This assembly file also contains an implementation of RAM semaphores.
 
70
 
 
71
        Notes:
 
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
 
74
          bit in the high bit
 
75
        |
 
76
        page ,132
 
77
 
 
78
        .486P
 
79
        ASSUME  CS:FLAT,  DS:FLAT,  SS:FLAT,  ES:FLAT,  FS:FLAT
 
80
 
 
81
        EXTRN   Dos32PostEventSem:PROC
 
82
        EXTRN   Dos32WaitEventSem:PROC
 
83
        EXTRN   Dos32ResetEventSem:PROC
 
84
 
 
85
ramsem  STRUC
 
86
        ramsem_ulTIDPID         DD      ?
 
87
        ramsem_hevSem           DD      ?
 
88
        ramsem_cLocks           DD      ?
 
89
        ramsem_cWaiting         DW      ?
 
90
        ramsem_cPosts           DW      ?
 
91
ramsem  ENDS
 
92
 
 
93
ERROR_SEM_TIMEOUT               equ     121
 
94
ERROR_NOT_OWNER                 equ     288
 
95
SEM_RELEASE_UNOWNED             equ     1
 
96
SEM_RELEASE_ALL                 equ     2
 
97
TS_LOCKBIT                      equ     31
 
98
 
 
99
 
 
100
DATA    SEGMENT DWORD USE32 PUBLIC 'DATA'
 
101
 
 
102
        EXTRN   plisCurrent:DWORD
 
103
 
 
104
DATA    ENDS
 
105
 
 
106
CODE32  SEGMENT USE32 PUBLIC 'CODE'
 
107
 
 
108
        PUBLIC  SemRequest486
 
109
        PUBLIC  SemReleasex86
 
110
 
 
111
        PUBLIC  _PR_MD_ATOMIC_SET
 
112
        PUBLIC  _PR_MD_ATOMIC_ADD
 
113
        PUBLIC  _PR_MD_ATOMIC_INCREMENT
 
114
        PUBLIC  _PR_MD_ATOMIC_DECREMENT
 
115
 
 
116
;;;---------------------------------------------------------------------------
 
117
;;; APIRET _Optlink SemRequest(PRAMSEM pramsem, ULONG ulTimeout);
 
118
;;;
 
119
;;; Registers:
 
120
;;;   EAX - packed TID:PID word
 
121
;;;   ECX - address of RAMSEM structure
 
122
;;;   EDX - length of timeout in milli-seconds
 
123
;;;---------------------------------------------------------------------------
 
124
 
 
125
        ALIGN   10H
 
126
SemRequest486     PROC
 
127
        push    ebx                                  ; Save ebx (volatile)
 
128
        mov     ecx, eax                             ; PRAMSEM must be in ecx,
 
129
                                                     ; not eax, for cmpxchg
 
130
 
 
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
 
135
        mov     ebx,eax
 
136
 
 
137
req486_test:
 
138
        xor     eax,eax
 
139
        cmp     (ramsem PTR [ecx]).ramsem_ulTIDPID, ebx ; If we own the sem, just
 
140
        jz short req486_inc_exit                      ; increment the use count
 
141
 
 
142
        lock inc     (ramsem PTR [ecx]).ramsem_cWaiting ; inc waiting flag
 
143
 
 
144
;       lock                                         ; Uncomment for SMP
 
145
        DB      0F0h
 
146
;       cmpxchg (ramsem PTR [ecx]).ramsem_ulTIDPID, ebx
 
147
;         (byte 3 is the offset of ulProcessThread into the RAMSEM structure)
 
148
        DB      00Fh
 
149
        DB      0B1h
 
150
        DB      019h
 
151
        jnz short req486_sleep
 
152
 
 
153
req486_inc_exit:
 
154
   lock inc     (ramsem PTR [ecx]).ramsem_cLocks
 
155
 
 
156
req486_exit:
 
157
        pop     ebx                                  ; Restore ebx
 
158
        ret
 
159
 
 
160
req486_sleep:
 
161
        push    ecx                                  ; Save ecx (volatile)
 
162
        push    edx                                  ; Save edx (volatile)
 
163
        push    edx                                  ; timeout
 
164
        push    (ramsem PTR [ecx]).ramsem_hevSem
 
165
        call    Dos32WaitEventSem
 
166
        add     esp, 8
 
167
        pop     edx                                  ; restore edx
 
168
        pop     ecx                                  ; restore ecx
 
169
        or      eax, eax
 
170
        jne     req486_exit                          ; Exit, if error
 
171
 
 
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
 
178
        add     esp, 12
 
179
        pop     edx                                  ; restore edx
 
180
        pop     ecx                                  ; restore ecx
 
181
        jmp     req486_test                          ; Retry the semaphore
 
182
 
 
183
SemRequest486     ENDP
 
184
 
 
185
;;;---------------------------------------------------------------------
 
186
;;; APIRET _Optlink SemReleasex86(PRAMSEM pramsem, ULONG flFlags);
 
187
;;;
 
188
;;; Registers:
 
189
;;;   EAX - address of RAMSEM structure
 
190
;;;   ECX - temporary variable
 
191
;;;   EDX - flags
 
192
;;;---------------------------------------------------------------------
 
193
 
 
194
        ALIGN   10H
 
195
SemReleasex86     PROC
 
196
        test    edx, SEM_RELEASE_UNOWNED             ; If set, don't bother
 
197
        jnz short rel_ownerok                        ; getting/checking PID/TID
 
198
 
 
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
 
205
 
 
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
 
209
 
 
210
rel_ownerok:
 
211
        test    edx, SEM_RELEASE_ALL
 
212
        jnz short rel_clear
 
213
 
 
214
   lock dec     (ramsem PTR [eax]).ramsem_cLocks
 
215
        jnz short rel_exit
 
216
 
 
217
rel_disown:
 
218
        mov     (ramsem PTR [eax]).ramsem_ulTIDPID, 0
 
219
 
 
220
   lock inc     (ramsem PTR [eax]).ramsem_cPosts
 
221
        mov     cx, (ramsem PTR [eax]).ramsem_cWaiting
 
222
        cmp     (ramsem PTR [eax]).ramsem_cPosts, cx
 
223
        jne short rel_post
 
224
 
 
225
rel_exit:
 
226
        xor     eax, eax
 
227
        ret
 
228
 
 
229
rel_clear:
 
230
   lock mov     (ramsem PTR [eax]).ramsem_cLocks,0
 
231
        jmp     rel_disown
 
232
 
 
233
rel_notowner:
 
234
        mov     eax, ERROR_NOT_OWNER
 
235
        ret
 
236
 
 
237
rel_post:
 
238
        mov     (ramsem PTR [eax]).ramsem_cPosts, cx
 
239
        push    (ramsem PTR [eax]).ramsem_hevSem
 
240
        call    Dos32PostEventSem
 
241
        add     esp,4
 
242
        xor     eax,eax
 
243
        ret
 
244
SemReleasex86     ENDP
 
245
 
 
246
;;;---------------------------------------------------------------------
 
247
;;; PRInt32 _Optlink _PR_MD_ATOMIC_SET(PRInt32* val, PRInt32 newval)
 
248
;;;---------------------------------------------------------------------
 
249
        ALIGN   10H
 
250
_PR_MD_ATOMIC_SET     proc
 
251
   lock xchg    dword ptr [eax],edx
 
252
        mov eax, edx;
 
253
        ret
 
254
_PR_MD_ATOMIC_SET     endp
 
255
 
 
256
;;;---------------------------------------------------------------------
 
257
;;; PRInt32 _Optlink _PR_MD_ATOMIC_ADD(PRInt32* ptr, PRInt32 val)
 
258
;;;---------------------------------------------------------------------
 
259
        ALIGN   10H
 
260
_PR_MD_ATOMIC_ADD     proc
 
261
        mov ecx, edx
 
262
        lock xadd dword ptr [eax], edx
 
263
        mov eax, edx
 
264
        add eax, ecx
 
265
        ret
 
266
_PR_MD_ATOMIC_ADD     endp
 
267
 
 
268
;;;---------------------------------------------------------------------
 
269
;;; PRInt32 _Optlink _PR_MD_ATOMIC_INCREMENT(PRInt32* val)
 
270
;;;---------------------------------------------------------------------
 
271
        ALIGN   10H
 
272
_PR_MD_ATOMIC_INCREMENT     proc
 
273
        mov edx, 1
 
274
        lock xadd dword ptr [eax], edx
 
275
        mov eax, edx
 
276
        inc eax
 
277
        ret
 
278
_PR_MD_ATOMIC_INCREMENT     endp
 
279
 
 
280
;;;---------------------------------------------------------------------
 
281
;;; PRInt32 _Optlink _PR_MD_ATOMIC_DECREMENT(PRInt32* val)
 
282
;;;---------------------------------------------------------------------
 
283
        ALIGN   10H
 
284
_PR_MD_ATOMIC_DECREMENT     proc
 
285
        mov edx, 0ffffffffh
 
286
        lock xadd dword ptr [eax], edx
 
287
        mov eax, edx
 
288
        dec eax
 
289
        ret
 
290
_PR_MD_ATOMIC_DECREMENT     endp
 
291
 
 
292
CODE32  ENDS
 
293
END