VirtualBox

Ignore:
Timestamp:
May 19, 2016 7:12:56 PM (9 years ago)
Author:
vboxsync
Message:

CPUM,++: Split up CPUM_USED_FPU into CPUM_USED_FPU_GUEST & CPUM_USED_FPU_HOST.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR0/CPUMR0A.asm

    r61031 r61058  
    55
    66;
    7 ; Copyright (C) 2006-2015 Oracle Corporation
     7; Copyright (C) 2006-2016 Oracle Corporation
    88;
    99; This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616;
    1717
     18
    1819;*******************************************************************************
    1920;* Header Files                                                                *
    2021;*******************************************************************************
     22%define RT_ASM_WITH_SEH64
     23%include "iprt/asmdefs.mac"
    2124%include "VBox/asmdefs.mac"
    2225%include "VBox/vmm/vm.mac"
     
    2730%include "VBox/vmm/cpum.mac"
    2831
    29 %ifdef IN_RING3
    30  %error "The jump table doesn't link on leopard."
    31 %endif
    3232
    3333;*******************************************************************************
     
    123123; @uses     rax, rdx
    124124; @param    pCpumCpu    Define for the register containing the CPUMCPU pointer.
    125 ; @param    pXState     Define for the regsiter containing the extended state pointer.
     125; @param    pXState     Define for the register containing the extended state pointer.
    126126;
    127127%macro CPUMR0_SAVE_HOST 0
     
    164164; @uses     rax, rdx
    165165; @param    pCpumCpu    Define for the register containing the CPUMCPU pointer.
    166 ; @param    pXState     Define for the regsiter containing the extended state pointer.
     166; @param    pXState     Define for the register containing the extended state pointer.
    167167;
    168168%macro CPUMR0_LOAD_HOST 0
     
    246246; @uses     rax, rdx
    247247; @param    pCpumCpu    Define for the register containing the CPUMCPU pointer.
    248 ; @param    pXState     Define for the regsiter containing the extended state pointer.
     248; @param    pXState     Define for the register containing the extended state pointer.
    249249;
    250250%macro CPUMR0_SAVE_GUEST 0
     
    314314; @uses     rax, rdx
    315315; @param    pCpumCpu    Define for the register containing the CPUMCPU pointer.
    316 ; @param    pXState     Define for the regsiter containing the extended state pointer.
     316; @param    pXState     Define for the register containing the extended state pointer.
    317317;
    318318%macro CPUMR0_LOAD_GUEST 0
     
    352352; Saves the host FPU/SSE/AVX state and restores the guest FPU/SSE/AVX state.
    353353;
    354 ; @returns  0
    355354; @param    pCpumCpu  x86:[ebp+8] gcc:rdi msc:rcx     CPUMCPU pointer
    356355;
    357356align 16
    358357BEGINPROC cpumR0SaveHostRestoreGuestFPUState
     358        push    xBP
     359        SEH64_PUSH_xBP
     360        mov     xBP, xSP
     361        SEH64_SET_FRAME_xBP 0
     362SEH64_END_PROLOGUE
     363
    359364        ;
    360365        ; Prologue - xAX+xDX must be free for XSAVE/XRSTOR input.
     
    369374 %define pXState    r10
    370375%else
    371         push    ebp
    372         mov     ebp, esp
    373376        push    ebx
    374377        push    esi
     
    381384        cli                             ; interrupt occurs while we're doing fxsave/fxrstor/cr0.
    382385
     386%ifdef VBOX_WITH_KERNEL_USING_XMM
     387        movaps  xmm0, xmm0              ; Make 100% sure it's used before we save it or mess with CR0/XCR0.
     388%endif
    383389        SAVE_CR0_CLEAR_FPU_TRAPS xCX, xAX ; xCX is now old CR0 value, don't use!
    384390
     391        ;
     392        ; Save the host state.
     393        ;
     394        test    dword [pCpumCpu + CPUMCPU.fUseFlags], CPUM_USED_FPU_HOST
     395        jnz     .already_saved_host
    385396        CPUMR0_SAVE_HOST
     397%ifdef VBOX_WITH_KERNEL_USING_XMM
     398        jmp     .load_guest
     399%endif
     400.already_saved_host:
     401%ifdef VBOX_WITH_KERNEL_USING_XMM
     402        ; If we didn't save the host state, we must save the non-volatile XMM registers.
     403        mov     pXState, [pCpumCpu + CPUMCPU.Host.pXStateR0]
     404        movdqa  [pXState + XMM_OFF_IN_X86FXSTATE + 060h], xmm6
     405        movdqa  [pXState + XMM_OFF_IN_X86FXSTATE + 070h], xmm7
     406        movdqa  [pXState + XMM_OFF_IN_X86FXSTATE + 080h], xmm8
     407        movdqa  [pXState + XMM_OFF_IN_X86FXSTATE + 090h], xmm9
     408        movdqa  [pXState + XMM_OFF_IN_X86FXSTATE + 0a0h], xmm10
     409        movdqa  [pXState + XMM_OFF_IN_X86FXSTATE + 0b0h], xmm11
     410        movdqa  [pXState + XMM_OFF_IN_X86FXSTATE + 0c0h], xmm12
     411        movdqa  [pXState + XMM_OFF_IN_X86FXSTATE + 0d0h], xmm13
     412        movdqa  [pXState + XMM_OFF_IN_X86FXSTATE + 0e0h], xmm14
     413        movdqa  [pXState + XMM_OFF_IN_X86FXSTATE + 0f0h], xmm15
     414
     415        ;
     416        ; Load the guest state.
     417        ;
     418.load_guest:
     419%endif
    386420        CPUMR0_LOAD_GUEST
    387421
     
    401435%endif
    402436
     437        ;; @todo Save CR0 + XCR0 bits related to FPU, SSE and AVX*, leaving these register sets accessible to IEM.
    403438        RESTORE_CR0 xCX
    404         or      dword [pCpumCpu + CPUMCPU.fUseFlags], (CPUM_USED_FPU | CPUM_USED_FPU_SINCE_REM)
     439        or      dword [pCpumCpu + CPUMCPU.fUseFlags], (CPUM_USED_FPU_GUEST | CPUM_USED_FPU_SINCE_REM | CPUM_USED_FPU_HOST)
    405440        popf
    406441
     
    408443        pop     esi
    409444        pop     ebx
     445%endif
    410446        leave
    411 %endif
    412         xor     eax, eax
    413447        ret
    414448ENDPROC   cpumR0SaveHostRestoreGuestFPUState
    415449
    416450
    417 %ifndef RT_ARCH_AMD64
    418  %ifdef  VBOX_WITH_64_BITS_GUESTS
    419451;;
    420452; Saves the host FPU/SSE/AVX state.
     
    425457align 16
    426458BEGINPROC cpumR0SaveHostFPUState
    427         ;
    428         ; Prologue - xAX+xDX must be free for XSAVE/XRSTOR input.
    429         ;
    430   %ifdef RT_ARCH_AMD64
    431    %ifdef RT_OS_WINDOWS
    432           mov     r11, rcx
    433    %else
    434           mov     r11, rdi
    435    %endif
    436    %define pCpumCpu   r11
    437    %define pXState    r10
    438   %else
    439         push    ebp
    440         mov     ebp, esp
    441         push    ebx
    442         push    esi
    443         mov     ebx, dword [ebp + 8]
    444    %define pCpumCpu ebx
    445    %define pXState  esi
    446   %endif
    447 
    448         pushf                           ; The darwin kernel can get upset or upset things if an
    449         cli                             ; interrupt occurs while we're doing fxsave/fxrstor/cr0.
    450         SAVE_CR0_CLEAR_FPU_TRAPS xCX, xAX ; xCX is now old CR0 value, don't use!
    451 
    452         CPUMR0_SAVE_HOST
    453 
    454         RESTORE_CR0 xCX
    455         or      dword [pCpumCpu + CPUMCPU.fUseFlags], (CPUM_USED_FPU | CPUM_USED_FPU_SINCE_REM)
    456         popf
    457 
    458   %ifdef RT_ARCH_X86
    459         pop     esi
    460         pop     ebx
    461         leave
    462   %endif
    463         xor     eax, eax
    464         ret
    465 %undef pCpumCpu
    466 %undef pXState
    467 ENDPROC   cpumR0SaveHostFPUState
    468  %endif
    469 %endif
    470 
    471 
    472 ;;
    473 ; Saves the guest FPU/SSE/AVX state and restores the host FPU/SSE/AVX state.
    474 ;
    475 ; @returns  VINF_SUCCESS (0) in eax.
    476 ; @param    pCpumCpu  x86:[ebp+8] gcc:rdi msc:rcx     CPUMCPU pointer
    477 ;
    478 align 16
    479 BEGINPROC cpumR0SaveGuestRestoreHostFPUState
     459        push    xBP
     460        SEH64_PUSH_xBP
     461        mov     xBP, xSP
     462        SEH64_SET_FRAME_xBP 0
     463SEH64_END_PROLOGUE
     464
    480465        ;
    481466        ; Prologue - xAX+xDX must be free for XSAVE/XRSTOR input.
     
    490475 %define pXState    r10
    491476%else
    492         push    ebp
    493         mov     ebp, esp
    494477        push    ebx
    495478        push    esi
     
    499482%endif
    500483
    501         ;
    502         ; Only restore FPU if guest has used it.
    503         ;
    504         test    dword [pCpumCpu + CPUMCPU.fUseFlags], CPUM_USED_FPU
    505         jz      .fpu_not_used
    506 
    507484        pushf                           ; The darwin kernel can get upset or upset things if an
    508485        cli                             ; interrupt occurs while we're doing fxsave/fxrstor/cr0.
     486%ifdef VBOX_WITH_KERNEL_USING_XMM
     487        movaps  xmm0, xmm0              ; Make 100% sure it's used before we save it or mess with CR0/XCR0.
     488%endif
    509489        SAVE_CR0_CLEAR_FPU_TRAPS xCX, xAX ; xCX is now old CR0 value, don't use!
    510490
    511         CPUMR0_SAVE_GUEST
    512         CPUMR0_LOAD_HOST
     491        CPUMR0_SAVE_HOST
     492        ;; @todo Save CR0 + XCR0 bits related to FPU, SSE and AVX*, leaving these register sets accessible to IEM.
    513493
    514494        RESTORE_CR0 xCX
    515         and     dword [pCpumCpu + CPUMCPU.fUseFlags], ~CPUM_USED_FPU
     495        or      dword [pCpumCpu + CPUMCPU.fUseFlags], (CPUM_USED_FPU_HOST | CPUM_USED_FPU_SINCE_REM) ; Latter is not necessarily true, but normally yes.
    516496        popf
    517497
    518 .fpu_not_used:
    519498%ifdef RT_ARCH_X86
    520499        pop     esi
    521500        pop     ebx
     501%endif
    522502        leave
    523 %endif
    524         xor     eax, eax
    525503        ret
    526504%undef pCpumCpu
    527505%undef pXState
    528 ENDPROC   cpumR0SaveGuestRestoreHostFPUState
    529 
    530 
    531 ;;
    532 ; Restores the host's FPU/SSE/AVX state from pCpumCpu->Host.
    533 ;
    534 ; @returns  0
     506ENDPROC   cpumR0SaveHostFPUState
     507
     508
     509;;
     510; Saves the guest FPU/SSE/AVX state and restores the host FPU/SSE/AVX state.
     511;
    535512; @param    pCpumCpu  x86:[ebp+8] gcc:rdi msc:rcx     CPUMCPU pointer
    536513;
    537514align 16
    538 BEGINPROC cpumR0RestoreHostFPUState
     515BEGINPROC cpumR0SaveGuestRestoreHostFPUState
     516        push    xBP
     517        SEH64_PUSH_xBP
     518        mov     xBP, xSP
     519        SEH64_SET_FRAME_xBP 0
     520SEH64_END_PROLOGUE
     521
    539522        ;
    540523        ; Prologue - xAX+xDX must be free for XSAVE/XRSTOR input.
     
    549532 %define pXState    r10
    550533%else
     534        push    ebx
     535        push    esi
     536        mov     ebx, dword [ebp + 8]
     537 %define pCpumCpu   ebx
     538 %define pXState    esi
     539%endif
     540        pushf                           ; The darwin kernel can get upset or upset things if an
     541        cli                             ; interrupt occurs while we're doing fxsave/fxrstor/cr0.
     542        SAVE_CR0_CLEAR_FPU_TRAPS xCX, xAX ; xCX is now old CR0 value, don't use!
     543
     544
     545 %ifdef VBOX_WITH_KERNEL_USING_XMM
     546        ;
     547        ; Copy non-volatile XMM registers to the host state so we can use
     548        ; them while saving the guest state (we've gotta do this anyway).
     549        ;
     550        mov     pXState, [pCpumCpu + CPUMCPU.Host.pXStateR0]
     551        movdqa  [pXState + XMM_OFF_IN_X86FXSTATE + 060h], xmm6
     552        movdqa  [pXState + XMM_OFF_IN_X86FXSTATE + 070h], xmm7
     553        movdqa  [pXState + XMM_OFF_IN_X86FXSTATE + 080h], xmm8
     554        movdqa  [pXState + XMM_OFF_IN_X86FXSTATE + 090h], xmm9
     555        movdqa  [pXState + XMM_OFF_IN_X86FXSTATE + 0a0h], xmm10
     556        movdqa  [pXState + XMM_OFF_IN_X86FXSTATE + 0b0h], xmm11
     557        movdqa  [pXState + XMM_OFF_IN_X86FXSTATE + 0c0h], xmm12
     558        movdqa  [pXState + XMM_OFF_IN_X86FXSTATE + 0d0h], xmm13
     559        movdqa  [pXState + XMM_OFF_IN_X86FXSTATE + 0e0h], xmm14
     560        movdqa  [pXState + XMM_OFF_IN_X86FXSTATE + 0f0h], xmm15
     561 %endif
     562
     563        ;
     564        ; Save the guest state if necessary.
     565        ;
     566        test    dword [pCpumCpu + CPUMCPU.fUseFlags], CPUM_USED_FPU_GUEST
     567        jz      .load_only_host
     568
     569 %ifdef VBOX_WITH_KERNEL_USING_XMM
     570        ; Load the guest XMM register values we already saved in HMR0VMXStartVMWrapXMM.
     571        mov     pXState, [pCpumCpu + CPUMCPU.Guest.pXStateR0]
     572        movdqa  xmm0,  [pXState + XMM_OFF_IN_X86FXSTATE + 000h]
     573        movdqa  xmm1,  [pXState + XMM_OFF_IN_X86FXSTATE + 010h]
     574        movdqa  xmm2,  [pXState + XMM_OFF_IN_X86FXSTATE + 020h]
     575        movdqa  xmm3,  [pXState + XMM_OFF_IN_X86FXSTATE + 030h]
     576        movdqa  xmm4,  [pXState + XMM_OFF_IN_X86FXSTATE + 040h]
     577        movdqa  xmm5,  [pXState + XMM_OFF_IN_X86FXSTATE + 050h]
     578        movdqa  xmm6,  [pXState + XMM_OFF_IN_X86FXSTATE + 060h]
     579        movdqa  xmm7,  [pXState + XMM_OFF_IN_X86FXSTATE + 070h]
     580        movdqa  xmm8,  [pXState + XMM_OFF_IN_X86FXSTATE + 080h]
     581        movdqa  xmm9,  [pXState + XMM_OFF_IN_X86FXSTATE + 090h]
     582        movdqa  xmm10, [pXState + XMM_OFF_IN_X86FXSTATE + 0a0h]
     583        movdqa  xmm11, [pXState + XMM_OFF_IN_X86FXSTATE + 0b0h]
     584        movdqa  xmm12, [pXState + XMM_OFF_IN_X86FXSTATE + 0c0h]
     585        movdqa  xmm13, [pXState + XMM_OFF_IN_X86FXSTATE + 0d0h]
     586        movdqa  xmm14, [pXState + XMM_OFF_IN_X86FXSTATE + 0e0h]
     587        movdqa  xmm15, [pXState + XMM_OFF_IN_X86FXSTATE + 0f0h]
     588 %endif
     589        CPUMR0_SAVE_GUEST
     590
     591        ;
     592        ; Load the host state.
     593        ;
     594.load_only_host:
     595        CPUMR0_LOAD_HOST
     596
     597        ;; @todo Restore CR0 + XCR0 bits related to FPU, SSE and AVX* (for IEM).
     598        RESTORE_CR0 xCX
     599        and     dword [pCpumCpu + CPUMCPU.fUseFlags], ~(CPUM_USED_FPU_GUEST | CPUM_USED_FPU_HOST)
     600
     601        popf
     602%ifdef RT_ARCH_X86
     603        pop     esi
     604        pop     ebx
     605%endif
     606        leave
     607        ret
     608%undef pCpumCpu
     609%undef pXState
     610ENDPROC   cpumR0SaveGuestRestoreHostFPUState
     611
     612
     613%if ARCH_BITS == 32
     614 %ifdef VBOX_WITH_64_BITS_GUESTS
     615;;
     616; Restores the host's FPU/SSE/AVX state from pCpumCpu->Host.
     617;
     618; @param    pCpumCpu  x86:[ebp+8] gcc:rdi msc:rcx     CPUMCPU pointer
     619;
     620align 16
     621BEGINPROC cpumR0RestoreHostFPUState
     622        ;
     623        ; Prologue - xAX+xDX must be free for XSAVE/XRSTOR input.
     624        ;
    551625        push    ebp
    552626        mov     ebp, esp
     
    554628        push    esi
    555629        mov     ebx, dword [ebp + 8]
    556  %define pCpumCpu ebx
    557  %define pXState  esi
    558 %endif
    559 
    560         ;
    561         ; Restore FPU if guest has used it.
    562         ;
    563         test    dword [pCpumCpu + CPUMCPU.fUseFlags], CPUM_USED_FPU
    564         jz short .fpu_not_used
    565 
     630  %define pCpumCpu ebx
     631  %define pXState  esi
     632
     633        ;
     634        ; Restore host CPU state.
     635        ;
    566636        pushf                           ; The darwin kernel can get upset or upset things if an
    567637        cli                             ; interrupt occurs while we're doing fxsave/fxrstor/cr0.
     
    571641
    572642        RESTORE_CR0 xCX
    573         and     dword [pCpumCpu + CPUMCPU.fUseFlags], ~CPUM_USED_FPU
     643        and     dword [pCpumCpu + CPUMCPU.fUseFlags], ~CPUM_USED_FPU_HOST
    574644        popf
    575645
    576 .fpu_not_used:
    577 %ifdef RT_ARCH_X86
    578646        pop     esi
    579647        pop     ebx
    580648        leave
    581 %endif
    582         xor     eax, eax
    583649        ret
    584 %undef pCpumCPu
    585 %undef pXState
     650  %undef pCpumCPu
     651  %undef pXState
    586652ENDPROC   cpumR0RestoreHostFPUState
    587 
     653 %endif ; VBOX_WITH_64_BITS_GUESTS
     654%endif  ; ARCH_BITS == 32
     655
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