VirtualBox

Changeset 55062 in vbox


Ignore:
Timestamp:
Apr 1, 2015 12:45:12 AM (9 years ago)
Author:
vboxsync
Message:

Remove CPUFeatures and CPUFeaturesExt from CPUM, use HostFeatures instead. Extended HostFeatures.

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/cpum.h

    r55000 r55062  
    12191219VMMR3DECL(uint32_t)     CPUMR3RemEnter(PVMCPU pVCpu, uint32_t *puCpl);
    12201220VMMR3DECL(void)         CPUMR3RemLeave(PVMCPU pVCpu, bool fNoOutOfSyncSels);
    1221 VMMDECL(bool)           CPUMSupportsFXSR(PVM pVM);
     1221VMMDECL(bool)           CPUMSupportsXSave(PVM pVM);
    12221222VMMDECL(bool)           CPUMIsHostUsingSysEnter(PVM pVM);
    12231223VMMDECL(bool)           CPUMIsHostUsingSysCall(PVM pVM);
  • trunk/src/VBox/VMM/VMMAll/CPUMAllRegs.cpp

    r55000 r55062  
    746746        pVCpu->cpum.s.fChanged |= CPUM_CHANGED_GLOBAL_TLB_FLUSH;
    747747    pVCpu->cpum.s.fChanged |= CPUM_CHANGED_CR4;
    748     if (!CPUMSupportsFXSR(pVCpu->CTX_SUFF(pVM)))
    749         cr4 &= ~X86_CR4_OSFXSR;
    750748    pVCpu->cpum.s.Guest.cr4 = cr4;
    751749    return VINF_SUCCESS;
     
    24802478
    24812479/**
    2482  * Checks if the CPU supports the FXSAVE and FXRSTOR instruction.
     2480 * Checks if the CPU supports the XSAVE and XRSTOR instruction.
     2481 *
    24832482 * @returns true if supported.
    24842483 * @returns false if not supported.
    24852484 * @param   pVM     Pointer to the VM.
    24862485 */
    2487 VMMDECL(bool) CPUMSupportsFXSR(PVM pVM)
    2488 {
    2489     return pVM->cpum.s.CPUFeatures.edx.u1FXSR != 0;
     2486VMMDECL(bool) CPUMSupportsXSave(PVM pVM)
     2487{
     2488    return pVM->cpum.s.HostFeatures.fXSaveRstor != 0;
    24902489}
    24912490
  • trunk/src/VBox/VMM/VMMR0/CPUMR0.cpp

    r55048 r55062  
    339339VMMR0_INT_DECL(int) CPUMR0Trap07Handler(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx)
    340340{
    341     Assert(pVM->cpum.s.CPUFeatures.edx.u1FXSR);
     341    Assert(pVM->cpum.s.HostFeatures.fFxSaveRstor);
    342342    Assert(ASMGetCR4() & X86_CR4_OSFXSR);
    343343
     
    399399VMMR0_INT_DECL(int) CPUMR0LoadGuestFPU(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx)
    400400{
    401 
    402401    Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));
    403402#if HC_ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
     
    423422        uint64_t uHostEfer    = 0;
    424423        bool     fRestoreEfer = false;
    425         if (pVM->cpum.s.CPUFeaturesExt.edx & X86_CPUID_AMD_FEATURE_EDX_FFXSR)
     424        if (pVM->cpum.s.HostFeatures.fLeakyFxSR)
    426425        {
    427426            /** @todo r=ramshankar: Can't we used a cached value here
     
    460459VMMR0_INT_DECL(int) CPUMR0SaveGuestFPU(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx)
    461460{
    462     Assert(pVM->cpum.s.CPUFeatures.edx.u1FXSR);
     461    Assert(pVM->cpum.s.HostFeatures.fFxSaveRstor);
    463462    Assert(ASMGetCR4() & X86_CR4_OSFXSR);
    464463    AssertReturn((pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU), VINF_SUCCESS);
  • trunk/src/VBox/VMM/VMMR3/CPUM.cpp

    r55054 r55062  
    640640        return VMSetError(pVM, VERR_UNSUPPORTED_CPU, RT_SRC_POS, "Host CPU does not support RDTSC.");
    641641
    642     /* Bogus on AMD? */
    643     if (!pVM->cpum.s.CPUFeatures.edx.u1SEP)
    644         Log(("The CPU doesn't support SYSENTER/SYSEXIT!\n"));
    645 
    646     /*
    647      * Setup the CR4 AND and OR masks used in the switcher
     642    /*
     643     * Setup the CR4 AND and OR masks used in the raw-mode switcher.
    648644     */
    649645    pVM->cpum.s.CR4.AndMask = X86_CR4_OSXMMEEXCPT | X86_CR4_PVI | X86_CR4_VME;
     
    653649     * Allocate memory for the extended CPU state.
    654650     */
    655     uint32_t cbMaxXState = sizeof(X86FXSTATE);
     651    uint32_t cbMaxXState = pVM->cpum.s.HostFeatures.cbMaxExtendedState;
    656652    cbMaxXState = RT_ALIGN(cbMaxXState, 128);
     653    AssertLogRelReturn(cbMaxXState >= sizeof(X86FXSTATE) && cbMaxXState <= _8K, VERR_CPUM_IPE_2);
     654
    657655    uint8_t *pbXStates;
    658656    rc = MMR3HyperAllocOnceNoRelEx(pVM, cbMaxXState * 3 * pVM->cCpus, PAGE_SIZE, MM_TAG_CPUM_CTX,
  • trunk/src/VBox/VMM/VMMR3/CPUMDbg.cpp

    r55048 r55062  
    239239
    240240/**
    241  * Is the FPU state in FXSAVE format or not.
    242  *
    243  * @returns true if it is, false if it's in FNSAVE.
    244  * @param   pVCpu               Pointer to the VMCPU.
    245  */
    246 DECLINLINE(bool) cpumR3RegIsFxSaveFormat(PVMCPU pVCpu)
    247 {
    248 #ifdef RT_ARCH_AMD64
    249     NOREF(pVCpu);
    250     return true;
    251 #else
    252     return pVCpu->pVMR3->cpum.s.CPUFeatures.edx.u1FXSR;
    253 #endif
    254 }
    255 
    256 
    257 /**
    258241 * Determins the tag register value for a CPU register when the FPU state
    259242 * format is FXSAVE.
     
    300283    Assert(pDesc->enmType == DBGFREGVALTYPE_U16);
    301284
    302     if (cpumR3RegIsFxSaveFormat(pVCpu))
    303         pValue->u16 =  cpumR3RegCalcFpuTagFromFxSave(pFpu, 0)
    304                     | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 1) <<  2)
    305                     | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 2) <<  4)
    306                     | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 3) <<  6)
    307                     | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 4) <<  8)
    308                     | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 5) << 10)
    309                     | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 6) << 12)
    310                     | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 7) << 14);
    311     else
    312     {
    313         PCX86FPUSTATE pOldFpu = (PCX86FPUSTATE)pFpu;
    314         pValue->u16 = pOldFpu->FTW;
    315     }
     285    pValue->u16 =  cpumR3RegCalcFpuTagFromFxSave(pFpu, 0)
     286                | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 1) <<  2)
     287                | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 2) <<  4)
     288                | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 3) <<  6)
     289                | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 4) <<  8)
     290                | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 5) << 10)
     291                | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 6) << 12)
     292                | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 7) << 14);
    316293    return VINF_SUCCESS;
    317294}
     
    620597
    621598    PX86FXSTATE pFpuCtx = &pVCpu->cpum.s.Guest.CTX_SUFF(pXState)->x87;
    622     if (cpumR3RegIsFxSaveFormat(pVCpu))
    623     {
    624         unsigned iReg = (pFpuCtx->FSW >> 11) & 7;
    625         iReg += pDesc->offRegister;
    626         iReg &= 7;
    627         pValue->r80Ex = pFpuCtx->aRegs[iReg].r80Ex;
    628     }
    629     else
    630     {
    631         PCX86FPUSTATE pOldFpuCtx = (PCX86FPUSTATE)pFpuCtx;
    632 
    633         unsigned iReg = (pOldFpuCtx->FSW >> 11) & 7;
    634         iReg += pDesc->offRegister;
    635         iReg &= 7;
    636         pValue->r80Ex = pOldFpuCtx->regs[iReg].r80Ex;
    637     }
     599    unsigned iReg = (pFpuCtx->FSW >> 11) & 7;
     600    iReg += pDesc->offRegister;
     601    iReg &= 7;
     602    pValue->r80Ex = pFpuCtx->aRegs[iReg].r80Ex;
    638603
    639604    return VINF_SUCCESS;
  • trunk/src/VBox/VMM/VMMR3/CPUMR3CpuId.cpp

    r55060 r55062  
    15011501
    15021502
     1503static PCCPUMCPUIDLEAF cpumR3CpuIdFindLeafEx(PCCPUMCPUIDLEAF paLeaves, uint32_t cLeaves, uint32_t uLeaf, uint32_t uSubLeaf)
     1504{
     1505    PCCPUMCPUIDLEAF pLeaf = cpumR3CpuIdFindLeaf(paLeaves, cLeaves, uLeaf);
     1506    if (   !pLeaf
     1507        || pLeaf->uSubLeaf != (uSubLeaf & pLeaf->fSubLeafMask))
     1508        return pLeaf;
     1509
     1510    /* Linear sub-leaf search. Lazy as usual. */
     1511    cLeaves = pLeaf - paLeaves;
     1512    while (   cLeaves-- > 0
     1513           && pLeaf->uLeaf == uLeaf)
     1514    {
     1515        if (pLeaf->uSubLeaf == (uSubLeaf & pLeaf->fSubLeafMask))
     1516            return pLeaf;
     1517        pLeaf++;
     1518    }
     1519
     1520    return NULL;
     1521}
     1522
     1523
    15031524int cpumR3CpuIdExplodeFeatures(PCCPUMCPUIDLEAF paLeaves, uint32_t cLeaves, PCPUMFEATURES pFeatures)
    15041525{
     
    15381559        pFeatures->fPat                 = RT_BOOL(paLeaves[1].uEdx & X86_CPUID_FEATURE_EDX_PAT);
    15391560        pFeatures->fFxSaveRstor         = RT_BOOL(paLeaves[1].uEdx & X86_CPUID_FEATURE_EDX_FXSR);
     1561        pFeatures->fXSaveRstor          = RT_BOOL(paLeaves[1].uEcx & X86_CPUID_FEATURE_ECX_XSAVE);
    15401562        pFeatures->fMmx                 = RT_BOOL(paLeaves[1].uEdx & X86_CPUID_FEATURE_EDX_MMX);
     1563        pFeatures->fSse                 = RT_BOOL(paLeaves[1].uEdx & X86_CPUID_FEATURE_EDX_SSE);
     1564        pFeatures->fSse2                = RT_BOOL(paLeaves[1].uEdx & X86_CPUID_FEATURE_EDX_SSE2);
     1565        pFeatures->fSse3                = RT_BOOL(paLeaves[1].uEcx & X86_CPUID_FEATURE_ECX_SSE3);
     1566        pFeatures->fSsse3               = RT_BOOL(paLeaves[1].uEcx & X86_CPUID_FEATURE_ECX_SSSE3);
     1567        pFeatures->fSse41               = RT_BOOL(paLeaves[1].uEcx & X86_CPUID_FEATURE_ECX_SSE4_1);
     1568        pFeatures->fSse42               = RT_BOOL(paLeaves[1].uEcx & X86_CPUID_FEATURE_ECX_SSE4_2);
     1569        pFeatures->fAvx                 = RT_BOOL(paLeaves[1].uEcx & X86_CPUID_FEATURE_ECX_AVX);
    15411570        pFeatures->fTsc                 = RT_BOOL(paLeaves[1].uEdx & X86_CPUID_FEATURE_EDX_TSC);
    15421571        pFeatures->fSysEnter            = RT_BOOL(paLeaves[1].uEdx & X86_CPUID_FEATURE_EDX_SEP);
    15431572        pFeatures->fHypervisorPresent   = RT_BOOL(paLeaves[1].uEcx & X86_CPUID_FEATURE_ECX_HVP);
    15441573        pFeatures->fMonitorMWait        = RT_BOOL(paLeaves[1].uEcx & X86_CPUID_FEATURE_ECX_MONITOR);
     1574
     1575        /* Structured extended features. */
     1576        PCCPUMCPUIDLEAF const pSxfLeaf0 = cpumR3CpuIdFindLeafEx(paLeaves, cLeaves, 7, 0);
     1577        if (pSxfLeaf0)
     1578        {
     1579            pFeatures->fAvx2                = RT_BOOL(pSxfLeaf0->uEcx & X86_CPUID_STEXT_FEATURE_EBX_AVX2);
     1580            pFeatures->fAvx512Foundation    = RT_BOOL(pSxfLeaf0->uEcx & X86_CPUID_STEXT_FEATURE_EBX_AVX512F);
     1581        }
    15451582
    15461583        /* MWAIT/MONITOR leaf. */
     
    15851622                             && pFeatures->enmCpuVendor == CPUMCPUVENDOR_AMD
    15861623                             && pFeatures->uFamily >= 6 /* K7 and up */;
     1624
     1625        /*
     1626         * Max extended (/FPU) state.
     1627         */
     1628        pFeatures->cbMaxExtendedState = pFeatures->fFxSaveRstor ? sizeof(X86FXSTATE) : sizeof(X86FPUSTATE);
     1629        if (pFeatures->fXSaveRstor)
     1630        {
     1631            PCCPUMCPUIDLEAF const pXStateLeaf0 = cpumR3CpuIdFindLeafEx(paLeaves, cLeaves, 13, 0);
     1632            if (pXStateLeaf0)
     1633            {
     1634                if (   pXStateLeaf0->uEcx >= sizeof(X86FXSTATE)
     1635                    && pXStateLeaf0->uEcx <= _8K
     1636                    && RT_ALIGN_32(pXStateLeaf0->uEcx, 8) == pXStateLeaf0->uEcx
     1637                    && pXStateLeaf0->uEbx >= sizeof(X86FXSTATE)
     1638                    && pXStateLeaf0->uEbx <= pXStateLeaf0->uEcx
     1639                    && RT_ALIGN_32(pXStateLeaf0->uEbx, 8) == pXStateLeaf0->uEbx)
     1640                {
     1641                    pFeatures->cbMaxExtendedState = pXStateLeaf0->uEcx;
     1642                }
     1643                else
     1644                    AssertLogRelMsgFailedStmt(("Unexpected max/cur XSAVE area sizes: %#x/%#x\n", pXStateLeaf0->uEcx, pXStateLeaf0->uEbx),
     1645                                              pFeatures->fXSaveRstor = 0);
     1646            }
     1647            else
     1648                AssertLogRelMsgFailedStmt(("Expected leaf eax=0xd/ecx=0 with the XSAVE/XRSTOR feature!\n"),
     1649                                          pFeatures->fXSaveRstor = 0);
     1650        }
    15871651    }
    15881652    else
  • trunk/src/VBox/VMM/VMMR3/VMMSwitcher.cpp

    r55054 r55062  
    698698                uint32_t offTrg = *u.pu32++;
    699699                Assert(offTrg < pSwitcher->cbCode);
    700                 if (!CPUMSupportsFXSR(pVM))
     700                if (!CPUMSupportsXSave(pVM))
    701701                {
    702702                    *uSrc.pu8++ = 0xe9; /* jmp rel32 */
  • trunk/src/VBox/VMM/include/CPUMInternal.h

    r55054 r55062  
    172172    uint8_t         cMaxPhysAddrWidth;
    173173    /** Alignment padding. */
    174     uint8_t         abPadding[3];
     174    uint8_t         abPadding[1];
     175    /** Max size of the extended state (or FPU state if no XSAVE). */
     176    uint16_t        cbMaxExtendedState;
    175177
    176178    /** Supports MSRs. */
     
    187189    /** Supports the FXSAVE and FXRSTOR instructions. */
    188190    uint32_t        fFxSaveRstor : 1;
     191    /** Supports the XSAVE and XRSTOR instructions. */
     192    uint32_t        fXSaveRstor : 1;
    189193    /** Supports MMX. */
    190194    uint32_t        fMmx : 1;
     195    /** Supports SSE. */
     196    uint32_t        fSse : 1;
     197    /** Supports SSE2. */
     198    uint32_t        fSse2 : 1;
     199    /** Supports SSE3. */
     200    uint32_t        fSse3 : 1;
     201    /** Supports SSSE3. */
     202    uint32_t        fSsse3 : 1;
     203    /** Supports SSE4.1. */
     204    uint32_t        fSse41 : 1;
     205    /** Supports SSE4.2. */
     206    uint32_t        fSse42 : 1;
     207    /** Supports AVX. */
     208    uint32_t        fAvx : 1;
     209    /** Supports AVX2. */
     210    uint32_t        fAvx2 : 1;
     211    /** Supports AVX512 foundation. */
     212    uint32_t        fAvx512Foundation : 1;
    191213    /** Supports RDTSC. */
    192214    uint32_t        fTsc : 1;
     
    220242    uint32_t        fLeakyFxSR : 1;
    221243
    222     /** Alignment padding. */
    223     uint32_t        fPadding : 12;
    224 
     244    /** Alignment padding / reserved for future use. */
     245    uint32_t        fPadding : 2;
    225246    uint64_t        auPadding[2];
    226247} CPUMFEATURES;
     
    469490    uint32_t                fHostUseFlags;
    470491
    471     /** Host CPU Features - ECX */
    472     struct
    473     {
    474         /** edx part */
    475         X86CPUIDFEATEDX     edx;
    476         /** ecx part */
    477         X86CPUIDFEATECX     ecx;
    478     } CPUFeatures;
    479     /** Host extended CPU features. */
    480     struct
    481     {
    482         /** edx part */
    483         uint32_t            edx;
    484         /** ecx part */
    485         uint32_t            ecx;
    486     } CPUFeaturesExt;
    487 
    488492    /** CR4 mask */
    489493    struct
  • trunk/src/VBox/VMM/include/CPUMInternal.mac

    r55049 r55062  
    7878    .offCPUMCPU0          resd    1
    7979    .fHostUseFlags        resd    1
    80 
    81     ; CPUID eax=1
    82     .CPUFeatures.edx      resd    1
    83     .CPUFeatures.ecx      resd    1
    84 
    85     ; CPUID eax=0x80000001
    86     .CPUFeaturesExt.edx   resd    1
    87     .CPUFeaturesExt.ecx   resd    1
    8880
    8981    ; CR4 masks
  • trunk/src/VBox/VMM/testcase/tstVMStruct.h

    r55048 r55062  
    2929    GEN_CHECK_OFF(CPUM, offCPUMCPU0);
    3030    GEN_CHECK_OFF(CPUM, fHostUseFlags);
    31     GEN_CHECK_OFF(CPUM, CPUFeatures);
    32     GEN_CHECK_OFF(CPUM, CPUFeaturesExt);
    33     GEN_CHECK_OFF(CPUM, CPUFeaturesExt);
    3431    GEN_CHECK_OFF(CPUM, CR4);
    3532#ifndef VBOX_FOR_DTRACE_LIB
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