VirtualBox

Changeset 97115 in vbox


Ignore:
Timestamp:
Oct 12, 2022 2:24:37 PM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
154076
Message:

ValKit: Test how 32-bit CMPXCHG clears or doesn't clear high dwords of 64-bit registers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/bootsectors/bootsector2-cpu-instr-1-template.mac

    r97108 r97115  
    268268
    269269;;
     270; Test what  CMPXCHG with 32-bit operand size does to 64-bit registers,
     271; as this is not particularly well documented by either Intel or AMD.
     272;
     273; @uses No registers, but BS2_SEL_SPARE0 is trashed.
     274;
     275BEGINPROC TMPL_NM(TestCmpxchg32)
     276        push    xBP
     277        mov     xBP, xSP
     278        push    sAX
     279        push    xBX
     280        push    xCX
     281        push    xDX
     282        push    xDI
     283        push    xSI
     284        sub     xSP, 80h                ; iret stack frame space.
     285        mov     xSI, xSP                ; Save the stack register.
     286
     287        mov     xAX, .s_szSubTestName
     288        call    TMPL_NM_CMN(TestSub)
     289
     290%ifdef TMPL_64BIT
     291
     292        ;
     293        ; CMPXCHG reg, reg - values not equal, eax written
     294        ;
     295        mov     rax, -1            ; Load registers with 64-bit values
     296        mov     rbx, -2
     297        mov     rcx, -3
     298        cmpxchg ebx, ecx           ; Not equal, writes eax
     299        mov     edx, -2            ; Clears high dword
     300        TEST_ASSERT_SIMPLE rax, rdx, jz, "CMPXCHG reg, unequal, rax set"
     301        mov     rdx, -2            ; All ones still in high dword
     302        TEST_ASSERT_SIMPLE rbx, rdx, jz, "CMPXCHG reg, unequal, rbx not set"
     303
     304        ;
     305        ; CMPXCHG reg, reg - values equal, first operand written
     306        ;
     307        mov     rax, -4            ; Load registers with 64-bit values
     308        mov     rbx, -4
     309        mov     rcx, -5
     310        cmpxchg ebx, ecx           ; Equal, writes ecx to ebx
     311        mov     edx, -5            ; Clears high dword
     312        TEST_ASSERT_SIMPLE rbx, rdx, jz, "CMPXCHG reg, equal, rbx set"
     313        mov     rdx, -4            ; All ones still in high dword
     314        TEST_ASSERT_SIMPLE rax, rdx, jz, "CMPXCHG reg, equal, rax not set"
     315
     316        ;
     317        ; CMPXCHG mem, reg - values not equal, eax written
     318        ;
     319        mov     rax, -1            ; Load registers with 64-bit values
     320        mov     rbx, -2
     321        push    rbx
     322        mov     rcx, -3
     323        cmpxchg [rsp], ecx         ; Not equal, writes eax
     324        mov     edx, -2            ; Clears high dword
     325        TEST_ASSERT_SIMPLE rax, rdx, jz, "CMPXCHG mem, unequal, rax set"
     326        pop     rbx
     327
     328        ;
     329        ; CMPXCHG mem, reg - values equal, first operand written
     330        ;
     331        mov     rax, -4            ; Load registers with 64-bit values
     332        mov     rbx, -4
     333        push    rbx
     334        mov     rcx, -5
     335        cmpxchg [rsp], ecx         ; Not equal, writes eax
     336        mov     rdx, -4            ; All ones in high dword
     337        TEST_ASSERT_SIMPLE rax, rdx, jz, "CMPXCHG mem, equal, rax not set"
     338        pop     rbx
     339
     340%endif
     341
     342        ;
     343        ; Done.
     344        ;
     345        call    TMPL_NM_CMN(TestSubDone)
     346.done:
     347        mov     xSP, xSI
     348        add     xSP, 80h
     349        pop     xSI
     350        pop     xDI
     351        pop     xDX
     352        pop     xCX
     353        pop     xBX
     354        pop     sAX
     355        leave
     356        ret
     357
     358.s_szSubTestName:
     359        db      TMPL_MODE_STR, ', 32-bit CMPXCHG in 64-bit mode', 0
     360ENDPROC   TMPL_NM(TestCmpxchg32)
     361
     362
     363;;
    270364; Proving intel manual wrong about using REX.X for BSWAP R8-R15 on 64-bit.
    271365; Checking the 'undefined' 16-bit bswap behavior.
     
    418512        ; Specifically tests 64-bit behavior.
    419513        call    TMPL_NM(TestCvtSize)
     514        call    TMPL_NM(TestCmpxchg32)
    420515%endif
    421516
Note: See TracChangeset for help on using the changeset viewer.

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