VirtualBox

Changeset 11508 in vbox for trunk/src/VBox/VMM/VMMAll


Ignore:
Timestamp:
Aug 20, 2008 9:46:31 AM (16 years ago)
Author:
vboxsync
Message:

Added emulation of cmpxchg & lock cmpxchg (not yet used).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/EMAllA.asm

    r9984 r11508  
    5050; EMDECL(uint32_t) EMEmulateCmp(uint32_t u32Param1, uint64_t u64Param2, size_t cb);
    5151;
    52 ; @returns EFLAGS after the operation, only arithmetic flags is valid.
     52; @returns EFLAGS after the operation, only arithmetic flags are valid.
    5353; @param    [esp + 04h]  rdi  rcx       Param 1 - First parameter (Dst).
    5454; @param    [esp + 08h]  rsi  edx       Param 2 - Second parameter (Src).
     
    114114; EMDECL(uint32_t) EMEmulateAnd(void *pvParam1, uint64_t u64Param2, size_t cb);
    115115;
    116 ; @returns EFLAGS after the operation, only arithmetic flags is valid.
     116; @returns EFLAGS after the operation, only arithmetic flags are valid.
    117117; @param    [esp + 04h]    Param 1 - First parameter - pointer to data item.
    118118; @param    [esp + 08h]    Param 2 - Second parameter.
     
    179179; EMDECL(uint32_t) EMEmulateOr(void *pvParam1, uint64_t u64Param2, size_t cb);
    180180;
    181 ; @returns EFLAGS after the operation, only arithmetic flags is valid.
     181; @returns EFLAGS after the operation, only arithmetic flags are valid.
    182182; @param    [esp + 04h]    Param 1 - First parameter - pointer to data item.
    183183; @param    [esp + 08h]    Param 2 - Second parameter.
     
    326326; EMDECL(uint32_t) EMEmulateXor(void *pvParam1, uint64_t u64Param2, size_t cb);
    327327;
    328 ; @returns EFLAGS after the operation, only arithmetic flags is valid.
     328; @returns EFLAGS after the operation, only arithmetic flags are valid.
    329329; @param    [esp + 04h]    Param 1 - First parameter - pointer to data item.
    330330; @param    [esp + 08h]    Param 2 - Second parameter.
     
    515515; EMDECL(uint32_t) EMEmulateAdd(void *pvParam1, uint64_t u64Param2, size_t cb);
    516516;
    517 ; @returns EFLAGS after the operation, only arithmetic flags is valid.
     517; @returns EFLAGS after the operation, only arithmetic flags are valid.
    518518; @param    [esp + 04h]    Param 1 - First parameter - pointer to data item.
    519519; @param    [esp + 08h]    Param 2 - Second parameter.
     
    579579; EMDECL(uint32_t) EMEmulateAdcWithCarrySet(void *pvParam1, uint64_t u64Param2, size_t cb);
    580580;
    581 ; @returns EFLAGS after the operation, only arithmetic flags is valid.
     581; @returns EFLAGS after the operation, only arithmetic flags are valid.
    582582; @param    [esp + 04h]    Param 1 - First parameter - pointer to data item.
    583583; @param    [esp + 08h]    Param 2 - Second parameter.
     
    647647; EMDECL(uint32_t) EMEmulateSub(void *pvParam1, uint64_t u64Param2, size_t cb);
    648648;
    649 ; @returns EFLAGS after the operation, only arithmetic flags is valid.
     649; @returns EFLAGS after the operation, only arithmetic flags are valid.
    650650; @param    [esp + 04h]    Param 1 - First parameter - pointer to data item.
    651651; @param    [esp + 08h]    Param 2 - Second parameter.
     
    712712; EMDECL(uint32_t) EMEmulateBtr(void *pvParam1, uint64_t u64Param2);
    713713;
    714 ; @returns EFLAGS after the operation, only arithmetic flags is valid.
     714; @returns EFLAGS after the operation, only arithmetic flags are valid.
    715715; @param    [esp + 04h]    Param 1 - First parameter - pointer to data item.
    716716; @param    [esp + 08h]    Param 2 - Second parameter.
     
    785785; EMDECL(uint32_t) EMEmulateBtc(void *pvParam1, uint64_t u64Param2);
    786786;
    787 ; @returns EFLAGS after the operation, only arithmetic flags is valid.
     787; @returns EFLAGS after the operation, only arithmetic flags are valid.
    788788; @param    [esp + 04h]    Param 1 - First parameter - pointer to data item.
    789789; @param    [esp + 08h]    Param 2 - Second parameter.
     
    842842
    843843
    844 %if 0
    845 ;; untested code!!
    846 
    847844;;
    848845; Emulate LOCK CMPXCHG instruction, CDECL calling conv.
    849 ; EMDECL(uint32_t) EMEmulateLockCmpXchg32(RTHCPTR pu32Param1, uint32_t *pu32Param2, uint32_t u32Param3, size_t cbSize);
    850 ;
    851 ; @returns EFLAGS after the operation, only arithmetic flags is valid.
     846; EMDECL(uint32_t) EMEmulateLockCmpXchg(void *pvParam1, uint64_t *pu64Param2, uint64_t u64Param3, size_t cbSize);
     847;
     848; @returns EFLAGS after the operation, only arithmetic flags are valid.
    852849; @param    [esp + 04h]  gcc:rdi  msc:rcx   Param 1 - First parameter - pointer to first parameter
    853850; @param    [esp + 08h]  gcc:rsi  msc:rdx   Param 2 - pointer to second parameter (eax)
    854851; @param    [esp + 0ch]  gcc:rdx  msc:r8    Param 3 - third parameter
    855 ; @param    [esp + 10h]  gcc:rcx  msc:r9    Param 4 - Size of parameters, only 1/2/4 is valid
    856 ; @uses     eax, ecx, edx
    857 ;
    858 align 16
    859 BEGINPROC   EMEmulateLockCmpXchg32
    860     push    ebx
     852; @param    [esp + 14h]  gcc:rcx  msc:r9    Param 4 - Size of parameters, only 1/2/4/8 is valid
     853; @uses     eax, ecx, edx
     854;
     855align 16
     856BEGINPROC   EMEmulateLockCmpXchg
     857    push    xBX
     858%ifdef RT_ARCH_AMD64
     859%ifdef RT_OS_WINDOWS
     860    ; rcx contains the first parameter already
     861    mov     rbx, rdx                    ; rdx = 2nd parameter
     862    mov     rdx, r8                     ; r8  = 3rd parameter
     863    mov     rax, r9                     ; r9  = size of parameters
     864%else
     865    mov     rax, rcx                    ; rcx = size of parameters (4th)
     866    mov     rcx, rdi                    ; rdi = 1st parameter
     867    mov     rbx, rsi                    ; rsi = second parameter
     868    ;rdx contains the 3rd parameter already
     869%endif  ; !RT_OS_WINDOWS
     870%else   ; !RT_ARCH_AMD64
    861871    mov     ecx, [esp + 04h + 4]        ; ecx = first parameter
    862872    mov     ebx, [esp + 08h + 4]        ; ebx = 2nd parameter (eax)
    863873    mov     edx, [esp + 0ch + 4]        ; edx = third parameter
    864     mov     eax, [esp + 10h + 4]        ; eax = size of parameters
    865 
     874    mov     eax, [esp + 14h + 4]        ; eax = size of parameters
     875%endif
     876
     877%ifdef RT_ARCH_AMD64
     878    cmp     al, 8
     879    je short .do_qword                  ; 4 bytes variant
     880%endif
    866881    cmp     al, 4
    867882    je short .do_dword                  ; 4 bytes variant
     
    872887    int3
    873888
     889%ifdef RT_ARCH_AMD64
     890.do_qword:
     891    ; load 2nd parameter's value
     892    mov     rax, qword [rbx]
     893
     894    lock cmpxchg qword [rcx], rdx            ; do 8 bytes CMPXCHG
     895    mov     qword [rbx], rax
     896    jmp     short .done
     897%endif
     898
    874899.do_dword:
    875900    ; load 2nd parameter's value
    876     mov     eax, dword [ebx]
    877 
    878     lock cmpxchg dword [ecx], edx            ; do 4 bytes CMPXCHG
    879     mov     dword [ebx], eax
     901    mov     eax, dword [xBX]
     902
     903    lock cmpxchg dword [xCX], edx            ; do 4 bytes CMPXCHG
     904    mov     dword [xBX], eax
    880905    jmp     short .done
    881906
    882907.do_word:
    883908    ; load 2nd parameter's value
    884     mov     eax, dword [ebx]
    885 
    886     lock cmpxchg word [ecx], dx              ; do 2 bytes CMPXCHG
    887     mov     word [ebx], ax
     909    mov     eax, dword [xBX]
     910
     911    lock cmpxchg word [xCX], dx              ; do 2 bytes CMPXCHG
     912    mov     word [xBX], ax
    888913    jmp     short .done
    889914
    890915.do_byte:
    891916    ; load 2nd parameter's value
    892     mov     eax, dword [ebx]
    893 
    894     lock cmpxchg byte [ecx], dl              ; do 1 bytes CMPXCHG
    895     mov     byte [ebx], al
     917    mov     eax, dword [xBX]
     918
     919    lock cmpxchg byte [xCX], dl              ; do 1 byte CMPXCHG
     920    mov     byte [xBX], al
    896921
    897922.done:
    898923    ; collect flags and return.
    899924    pushf
    900     pop     eax
    901 
    902     pop     ebx
    903     retn
    904 
    905 ENDPROC     EMEmulateLockCmpXchg32
     925    pop     MY_RET_REG
     926
     927    pop     xBX
     928    retn
     929ENDPROC     EMEmulateLockCmpXchg
    906930
    907931;;
    908932; Emulate CMPXCHG instruction, CDECL calling conv.
    909 ; EMDECL(uint32_t) EMEmulateCmpXchg32(RTHCPTR pu32Param1, uint32_t *pu32Param2, uint32_t u32Param3, size_t cbSize);
    910 ;
    911 ; @returns EFLAGS after the operation, only arithmetic flags is valid.
     933; EMDECL(uint32_t) EMEmulateCmpXchg(void *pvParam1, uint64_t *pu32Param2, uint64_t u32Param3, size_t cbSize);
     934;
     935; @returns EFLAGS after the operation, only arithmetic flags are valid.
    912936; @param    [esp + 04h]  gcc:rdi  msc:rcx   Param 1 - First parameter - pointer to first parameter
    913937; @param    [esp + 08h]  gcc:rsi  msc:rdx   Param 2 - pointer to second parameter (eax)
    914938; @param    [esp + 0ch]  gcc:rdx  msc:r8    Param 3 - third parameter
    915 ; @param    [esp + 10h]  gcc:rcx  msc:r9    Param 4 - Size of parameters, only 1/2/4 is valid.
    916 ; @uses     eax, ecx, edx
    917 ;
    918 align 16
    919 BEGINPROC   EMEmulateCmpXchg32
    920     push    ebx
     939; @param    [esp + 14h]  gcc:rcx  msc:r9    Param 4 - Size of parameters, only 1/2/4 is valid.
     940; @uses     eax, ecx, edx
     941;
     942align 16
     943BEGINPROC   EMEmulateCmpXchg
     944    push    xBX
     945%ifdef RT_ARCH_AMD64
     946%ifdef RT_OS_WINDOWS
     947    ; rcx contains the first parameter already
     948    mov     rbx, rdx                    ; rdx = 2nd parameter
     949    mov     rdx, r8                     ; r8  = 3rd parameter
     950    mov     rax, r9                     ; r9  = size of parameters
     951%else
     952    mov     rax, rcx                    ; rcx = size of parameters (4th)
     953    mov     rcx, rdi                    ; rdi = 1st parameter
     954    mov     rbx, rsi                    ; rsi = second parameter
     955    ;rdx contains the 3rd parameter already
     956%endif  ; !RT_OS_WINDOWS
     957%else   ; !RT_ARCH_AMD64
    921958    mov     ecx, [esp + 04h + 4]        ; ecx = first parameter
    922959    mov     ebx, [esp + 08h + 4]        ; ebx = 2nd parameter (eax)
    923960    mov     edx, [esp + 0ch + 4]        ; edx = third parameter
    924     mov     eax, [esp + 10h + 4]        ; eax = size of parameters
    925 
     961    mov     eax, [esp + 14h + 4]        ; eax = size of parameters
     962%endif
     963
     964%ifdef RT_ARCH_AMD64
     965    cmp     al, 8
     966    je short .do_qword                  ; 4 bytes variant
     967%endif
    926968    cmp     al, 4
    927969    je short .do_dword                  ; 4 bytes variant
     
    932974    int3
    933975
     976%ifdef RT_ARCH_AMD64
     977.do_qword:
     978    ; load 2nd parameter's value
     979    mov     rax, qword [rbx]
     980
     981    cmpxchg qword [rcx], rdx            ; do 8 bytes CMPXCHG
     982    mov     qword [rbx], rax
     983    jmp     short .done
     984%endif
     985
    934986.do_dword:
    935987    ; load 2nd parameter's value
    936     mov     eax, dword [ebx]
    937 
    938     cmpxchg dword [ecx], edx            ; do 4 bytes CMPXCHG
    939     mov     dword [ebx], eax
     988    mov     eax, dword [xBX]
     989
     990    cmpxchg dword [xCX], edx            ; do 4 bytes CMPXCHG
     991    mov     dword [xBX], eax
    940992    jmp     short .done
    941993
    942994.do_word:
    943995    ; load 2nd parameter's value
    944     mov     eax, dword [ebx]
    945 
    946     cmpxchg word [ecx], dx              ; do 2 bytes CMPXCHG
    947     mov     word [ebx], ax
     996    mov     eax, dword [xBX]
     997
     998    cmpxchg word [xCX], dx              ; do 2 bytes CMPXCHG
     999    mov     word [xBX], ax
    9481000    jmp     short .done
    9491001
    9501002.do_byte:
    9511003    ; load 2nd parameter's value
    952     mov     eax, dword [ebx]
    953 
    954     cmpxchg byte [ecx], dl              ; do 1 bytes CMPXCHG
    955     mov     byte [ebx], al
     1004    mov     eax, dword [xBX]
     1005
     1006    cmpxchg byte [xCX], dl              ; do 1 byte CMPXCHG
     1007    mov     byte [xBX], al
    9561008
    9571009.done:
    9581010    ; collect flags and return.
    9591011    pushf
    960     pop     eax
    961 
    962     pop     ebx
    963     retn
    964 
    965 ENDPROC     EMEmulateCmpXchg32
     1012    pop     MY_RET_REG
     1013
     1014    pop     xBX
     1015    retn
     1016ENDPROC     EMEmulateCmpXchg
     1017
     1018%if 0
     1019;; not tested!!
    9661020
    9671021;;
     
    9691023; EMDECL(uint32_t) EMEmulateLockCmpXchg8b(RTHCPTR pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX);
    9701024;
    971 ; @returns EFLAGS after the operation, only arithmetic flags is valid.
     1025; @returns EFLAGS after the operation, only arithmetic flags are valid.
    9721026; @param    [esp + 04h]    Param 1 - First parameter - pointer to first parameter
    9731027; @param    [esp + 08h]    Param 2 - Address of the eax register
     
    9781032;
    9791033align 16
    980 BEGINPROC   EMEmulateLockCmpXchg8b32
     1034BEGINPROC   EMEmulateLockCmpXchg8b
    9811035    push    ebp
    9821036    push    ebx
     
    10031057    retn
    10041058
    1005 ENDPROC     EMEmulateLockCmpXchg8b32
     1059ENDPROC     EMEmulateLockCmpXchg8b
    10061060
    10071061;;
    10081062; Emulate CMPXCHG8B instruction, CDECL calling conv.
    1009 ; EMDECL(uint32_t) EMEmulateCmpXchg8b32(RTHCPTR pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX);
    1010 ;
    1011 ; @returns EFLAGS after the operation, only arithmetic flags is valid.
     1063; EMDECL(uint32_t) EMEmulateCmpXchg8b(RTHCPTR pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX);
     1064;
     1065; @returns EFLAGS after the operation, only arithmetic flags are valid.
    10121066; @param    [esp + 04h]    Param 1 - First parameter - pointer to first parameter
    10131067; @param    [esp + 08h]    Param 2 - Address of the eax register
     
    10181072;
    10191073align 16
    1020 BEGINPROC   EMEmulateCmpXchg8b32
     1074BEGINPROC   EMEmulateCmpXchg8b
    10211075    push    ebp
    10221076    push    ebx
     
    10421096    pop     ebp
    10431097    retn
    1044 ENDPROC     EMEmulateCmpXchg8b32
    1045 
    1046 %endif
     1098ENDPROC     EMEmulateCmpXchg8b
     1099
     1100%endif
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette