Changeset 1987 for trunk/src


Ignore:
Timestamp:
Dec 6, 1999, 9:34:59 AM (26 years ago)
Author:
phaller
Message:

Fix: implemented Interlocked APIs according to NT4

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/interlock.asm

    r1977 r1987  
    1 ; $Id: interlock.asm,v 1.2 1999-12-05 13:39:21 sandervl Exp $
     1; $Id: interlock.asm,v 1.3 1999-12-06 08:34:59 phaller Exp $
    22
    33;/*
    44; * Interlocked apis
    55; *
     6; * IMPORTANT NOTE: THIS CODE WILL NOT RUN ON 386 CPUs,
     7; *                 486 IS MINIMUM REQUIREMENT!
     8; *
    69; * Copyright 1999 Sander van Leeuwen
    710; * Copyright 1999 Patrick Haller
    811; *
    9 ; * Based on WINE code: win32\thread.c (990815)
    10 ; *
    11 ; * Copyright 1995 Martin von Loewis
    12 ; * Copyright 1997 Onno Hovers
    13 ; *
    1412; * Project Odin Software License can be found in LICENSE.TXT
    1513; *
    1614; */
    17 .586P
     15.486P
    1816               NAME    interlocked
    1917
    2018CODE32         SEGMENT DWORD PUBLIC USE32 'CODE'
    2119
    22        public  _InterlockedIncrement@4
    23 
     20
     21;************************************************************************
    2422;*           InterlockedIncrement                       [KERNEL32]      *
    2523;*                                                                      *
     
    3028;*                                                                      *
    3129;* The returned number need not be equal to the result!!!!              *
    32 
     30;************************************************************************
     31
     32       public  _InterlockedIncrement@4
    3333_InterlockedIncrement@4 proc near
    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
     34
     35;@@@PH NT4 implementation
     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 from 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
    4369_InterlockedIncrement@4 endp
    4470
    45        public  _InterlockedDecrement@4
    46 
     71
     72;************************************************************************
    4773;*           InterlockedDecrement                       [KERNEL32]      *
    4874;*                                                                      *
     
    5379;*                                                                      *
    5480;* The returned number need not be equal to the result!!!!              *
    55 
     81;************************************************************************
     82
     83       public  _InterlockedDecrement@4
    5684_InterlockedDecrement@4 proc near
    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
     85
     86;@@@PH NT4 implementation
     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 from 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
    66123_InterlockedDecrement@4 endp
    67124
    68125
     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;************************************************************************
     134
    69135       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
    76 
    77136_InterlockedExchange@8 proc near
    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     8
     137
     138;@@@PH NT4 implementation
     139         mov      ecx, [esp+8]
     140         mov      edx, [esp+4]
     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 from 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
    84172_InterlockedExchange@8 endp
    85173
     
    87175
    88176                public _InterlockedCompareExchange@12
    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 ; */
     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;************************************************************************
    98187_InterlockedCompareExchange@12 proc near
    99         push    ebp
    100         mov     ebp, esp
    101         push    edx
    102         push    ebx
    103 
    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
    110 
    111         pop     ebx
    112         pop     edx
    113         pop     ebp
    114         ret     12
     188
     189;@@@PH NT4 implementation
     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
     197
     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
    115216_InterlockedCompareExchange@12 endp
    116217
     218
     219;************************************************************************
     220;*           InterlockedExchangeAdd                     [KERNEL32.880]
     221;*
     222;* Atomically adds Increment to Addend and returns the previous value of
     223;* Addend
     224;*
     225;* RETURNS
     226;*      Prior value of value pointed to by cwAddendTarget
     227;*
     228;************************************************************************
    117229                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 ; */
    126230_InterlockedExchangeAdd@8 proc near
    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
     231
     232;@@@PH NT4 implementation
     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
    133247_InterlockedExchangeAdd@8 endp
    134248
Note: See TracChangeset for help on using the changeset viewer.