VirtualBox

Ignore:
Timestamp:
Sep 22, 2008 6:29:06 PM (16 years ago)
Author:
vboxsync
Message:

#1865: CPUM. Also added missing aliasing for DR4&5 to the guest DRx setter and getter.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR0/CPUMR0.cpp

    r12600 r12657  
    3636
    3737
    38 
    3938/**
    4039 * Does Ring-0 CPUM initialization.
     
    5352     * Check CR0 & CR4 flags.
    5453     */
    55     uint32_t    u32CR0 = ASMGetCR0();
     54    uint32_t u32CR0 = ASMGetCR0();
    5655    if ((u32CR0 & (X86_CR0_PE | X86_CR0_PG)) != (X86_CR0_PE | X86_CR0_PG)) /* a bit paranoid perhaps.. */
    5756    {
     
    9998     * This ASSUMES that DR7.GD is not set, or that it's handled transparently!
    10099     */
    101     uint32_t    u32DR7 = ASMGetDR7();
     100    uint32_t u32DR7 = ASMGetDR7();
    102101    if (u32DR7 & X86_DR7_ENABLED_MASK)
    103102    {
     
    155154     */
    156155
    157     switch(pCtx->cr0 & (X86_CR0_MP | X86_CR0_EM | X86_CR0_TS))
    158     {
    159     case X86_CR0_MP | X86_CR0_TS:
    160     case X86_CR0_MP | X86_CR0_EM | X86_CR0_TS:
    161         return VINF_EM_RAW_GUEST_TRAP;
    162 
    163     default:
    164         break;
     156    switch (pCtx->cr0 & (X86_CR0_MP | X86_CR0_EM | X86_CR0_TS))
     157    {
     158        case X86_CR0_MP | X86_CR0_TS:
     159        case X86_CR0_MP | X86_CR0_EM | X86_CR0_TS:
     160            return VINF_EM_RAW_GUEST_TRAP;
     161        default:
     162            break;
    165163    }
    166164
     
    172170    if (pVM->cpum.s.CPUFeaturesExt.edx & X86_CPUID_AMD_FEATURE_EDX_FFXSR)
    173171    {
    174         /* @todo Do we really need to read this every time?? The host could change this on the fly though. */
     172        /** @todo Do we really need to read this every time?? The host could change this on the fly though.
     173         *  bird: what about starting by skipping the ASMWrMsr below if we didn't
     174         *        change anything? Ditto for the stuff in CPUMR0SaveGuestFPU. */
    175175        oldMsrEFERHost = ASMRdMsr(MSR_K6_EFER);
    176 
    177176        if (oldMsrEFERHost & MSR_K6_EFER_FFXSR)
    178177        {
     
    193192        /* CPUMHandleLazyFPU could have changed CR0; restore it. */
    194193    ASMSetCR0(oldCR0);
    195 #else
    196     /* Save the FPU control word and MXCSR, so we can restore the state properly afterwards.
     194
     195#else  /* CPUM_CAN_HANDLE_NM_TRAPS_IN_KERNEL_MODE */
     196
     197    /*
     198     * Save the FPU control word and MXCSR, so we can restore the state properly afterwards.
    197199     * We don't want the guest to be able to trigger floating point/SSE exceptions on the host.
    198200     */
     
    203205    CPUMLoadFPUAsm(pCtx);
    204206
    205     /* The MSR_K6_EFER_FFXSR feature is AMD only so far, but check the cpuid just in case Intel adds it in the future.
     207    /*
     208     * The MSR_K6_EFER_FFXSR feature is AMD only so far, but check the cpuid just in case Intel adds it in the future.
    206209     *
    207210     * MSR_K6_EFER_FFXSR changes the behaviour of fxsave and fxrstore: the XMM state isn't saved/restored
     
    209212    if (pVM->cpum.s.CPUFeaturesExt.edx & X86_CPUID_AMD_FEATURE_EDX_FFXSR)
    210213    {
    211         /* @todo Do we really need to read this every time?? The host could change this on the fly though. */
     214        /** @todo Do we really need to read this every time?? The host could change this on the fly though. */
    212215        uint64_t msrEFERHost = ASMRdMsr(MSR_K6_EFER);
    213216
     
    219222        }
    220223    }
    221 #endif
     224#endif /* CPUM_CAN_HANDLE_NM_TRAPS_IN_KERNEL_MODE */
    222225
    223226    pVM->cpum.s.fUseFlags |= CPUM_USED_FPU;
     
    254257        ASMWrMsr(MSR_K6_EFER, oldMsrEFERHost | MSR_K6_EFER_FFXSR);
    255258
    256 #else
     259#else  /* CPUM_CAN_HANDLE_NM_TRAPS_IN_KERNEL_MODE */
    257260    CPUMSaveFPUAsm(pCtx);
    258261    if (pVM->cpum.s.fUseFlags & CPUM_MANUAL_XMM_RESTORE)
     
    261264        CPUMSaveXMMAsm(pCtx);
    262265    }
    263     /* Restore the original FPU control word and MXCSR.
     266
     267    /*
     268     * Restore the original FPU control word and MXCSR.
    264269     * We don't want the guest to be able to trigger floating point/SSE exceptions on the host.
    265270     */
     
    267272    if (pVM->cpum.s.CPUFeatures.edx.u1SSE)
    268273        CPUMSetMXCSR(pVM->cpum.s.Host.fpu.MXCSR);
    269 #endif
    270 
    271     pVM->cpum.s.fUseFlags &= ~(CPUM_USED_FPU|CPUM_MANUAL_XMM_RESTORE);
     274#endif /* CPUM_CAN_HANDLE_NM_TRAPS_IN_KERNEL_MODE */
     275
     276    pVM->cpum.s.fUseFlags &= ~(CPUM_USED_FPU | CPUM_MANUAL_XMM_RESTORE);
    272277    return VINF_SUCCESS;
    273278}
     
    294299        pCtx->dr[6] = ASMGetDR6();
    295300
    296     /* Restore the host's debug state. DR0-3, DR6 and only then DR7!
     301    /*
     302     * Restore the host's debug state. DR0-3, DR6 and only then DR7!
    297303     * DR7 contains 0x400 right now.
    298304     */
     
    325331    pVM->cpum.s.Host.dr3 = ASMGetDR3();
    326332    pVM->cpum.s.Host.dr6 = ASMGetDR6();
    327     /* @todo dr7 might already have been changed to 0x400; don't care right now as it's harmless. */
     333    /** @todo dr7 might already have been changed to 0x400; don't care right now as it's harmless. */
    328334    pVM->cpum.s.Host.dr7 = ASMGetDR7();
    329335    /* Make sure DR7 is harmless or else we could trigger breakpoints when restoring dr0-3 (!) */
     
    341347    return VINF_SUCCESS;
    342348}
     349
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