VirtualBox

Changeset 97231 in vbox for trunk/src


Ignore:
Timestamp:
Oct 19, 2022 9:12:57 AM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
154207
Message:

VMM/CPUM: Define our own X86EFLAGS/X86RFLAGS structures so we can use reserved bits for internal state.

Location:
trunk/src/VBox/VMM
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/CPUMAllRegs.cpp

    r97220 r97231  
    184184{
    185185    return pVCpu->cpum.s.Hyper.dr[7];
     186}
     187
     188
     189/**
     190 * Checks that the special cookie stored in unused reserved RFLAGS bits
     191 *
     192 * @retval  true if cookie is ok.
     193 * @retval  false if cookie is not ok.
     194 * @param   pVM         The cross context VM structure.
     195 * @param   pVCpu       The cross context virtual CPU structure.
     196 */
     197VMM_INT_DECL(bool) CPUMAssertGuestRFlagsCookie(PVM pVM, PVMCPU pVCpu)
     198{
     199    AssertLogRelMsgReturn(      (pVCpu->cpum.s.Guest.rflags.uBoth & ~(uint64_t)(X86_EFL_LIVE_MASK | X86_EFL_RA1_MASK))
     200                             == pVM->cpum.s.fReservedRFlagsCookie
     201                          && (pVCpu->cpum.s.Guest.rflags.uBoth & X86_EFL_RA1_MASK) == X86_EFL_RA1_MASK,
     202                          ("rflags=%#RX64 vs fReservedRFlagsCookie=%#RX64\n",
     203                           pVCpu->cpum.s.Guest.rflags.uBoth, pVM->cpum.s.fReservedRFlagsCookie),
     204                          false);
     205    return true;
    186206}
    187207
  • trunk/src/VBox/VMM/VMMAll/IEMAllCImpl.cpp

    r97208 r97231  
    80248024            || (pVCpu->cpum.GstCtx.ax & 0xf) >= 10)
    80258025        {
    8026             iemAImpl_add_u16(&pVCpu->cpum.GstCtx.ax, 0x106, &pVCpu->cpum.GstCtx.eflags.u32);
     8026            iemAImpl_add_u16(&pVCpu->cpum.GstCtx.ax, 0x106, &pVCpu->cpum.GstCtx.eflags.uBoth);
    80278027            pVCpu->cpum.GstCtx.eflags.Bits.u1AF = 1;
    80288028            pVCpu->cpum.GstCtx.eflags.Bits.u1CF = 1;
     
    80698069            || (pVCpu->cpum.GstCtx.ax & 0xf) >= 10)
    80708070        {
    8071             iemAImpl_sub_u16(&pVCpu->cpum.GstCtx.ax, 0x106, &pVCpu->cpum.GstCtx.eflags.u32);
     8071            iemAImpl_sub_u16(&pVCpu->cpum.GstCtx.ax, 0x106, &pVCpu->cpum.GstCtx.eflags.uBoth);
    80728072            pVCpu->cpum.GstCtx.eflags.Bits.u1AF = 1;
    80738073            pVCpu->cpum.GstCtx.eflags.Bits.u1CF = 1;
  • trunk/src/VBox/VMM/VMMAll/VMXAllTemplate.cpp.h

    r97223 r97231  
    18051805           Use 32-bit VMWRITE. */
    18061806        uint32_t fEFlags = pVCpu->cpum.GstCtx.eflags.u;
    1807         Assert(fEFlags & X86_EFL_RA1_MASK);
    1808         Assert(!(fEFlags & ~(X86_EFL_1 | X86_EFL_LIVE_MASK)));
     1807        Assert((fEFlags & X86_EFL_RA1_MASK) == X86_EFL_RA1_MASK);
     1808        AssertMsg(!(fEFlags & ~(X86_EFL_LIVE_MASK | X86_EFL_RA1_MASK)), ("%#x\n", fEFlags));
    18091809
    18101810#ifndef IN_NEM_DARWIN
  • trunk/src/VBox/VMM/VMMR3/CPUM.cpp

    r97219 r97231  
    145145#include <iprt/mem.h>
    146146#include <iprt/mp.h>
     147#include <iprt/rand.h>
    147148#include <iprt/string.h>
    148149
     
    22052206
    22062207    /*
     2208     * Generate the RFLAGS cookie.
     2209     */
     2210    pVM->cpum.s.fReservedRFlagsCookie = RTRandU64() & ~(CPUMX86EFLAGS_HW_MASK_64 | CPUMX86EFLAGS_INT_MASK_64);
     2211
     2212    /*
    22072213     * Init the VMX/SVM state.
    22082214     *
     
    22202226        Assert(pVM->apCpusR3[0]->cpum.s.Guest.hwvirt.enmHwvirt == CPUMHWVIRT_NONE);
    22212227
     2228    /*
     2229     * Initialize the general guest CPU state.
     2230     */
    22222231    CPUMR3Reset(pVM);
     2232
    22232233    return VINF_SUCCESS;
    22242234}
     
    23032313    pCtx->eip                       = 0x0000fff0;
    23042314    pCtx->edx                       = 0x00000600;   /* P6 processor */
    2305     pCtx->eflags.Bits.u1Reserved0   = 1;
     2315
     2316    Assert((pVM->cpum.s.fReservedRFlagsCookie & (X86_EFL_LIVE_MASK | X86_EFL_RAZ_LO_MASK | X86_EFL_RA1_MASK)) == 0);
     2317    pCtx->rflags.uBoth              = pVM->cpum.s.fReservedRFlagsCookie | X86_EFL_RA1_MASK;
    23062318
    23072319    pCtx->cs.Sel                    = 0xf000;
     
    24952507    for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
    24962508    {
    2497         PVMCPU pVCpu = pVM->apCpusR3[idCpu];
    2498 
     2509        PVMCPU const   pVCpu   = pVM->apCpusR3[idCpu];
     2510        PCPUMCTX const pGstCtx = &pVCpu->cpum.s.Guest;
     2511
     2512        /** @todo ditch this the next time we change the saved state. */
    24992513        SSMR3PutStructEx(pSSM, &DummyHyperCtx,           sizeof(DummyHyperCtx),           0, g_aCpumCtxFields, NULL);
    25002514
    2501         PCPUMCTX pGstCtx = &pVCpu->cpum.s.Guest;
     2515        uint64_t const fSavedRFlags = pGstCtx->rflags.uBoth;
     2516        pGstCtx->rflags.uBoth &= CPUMX86EFLAGS_HW_MASK_64; /* Temporarily clear the non-hardware bits in RFLAGS while saving. */
    25022517        SSMR3PutStructEx(pSSM, pGstCtx,                  sizeof(*pGstCtx),                0, g_aCpumCtxFields, NULL);
     2518        pGstCtx->rflags.uBoth  = fSavedRFlags;
     2519
    25032520        SSMR3PutStructEx(pSSM, &pGstCtx->XState.x87,     sizeof(pGstCtx->XState.x87),     0, g_aCpumX87Fields, NULL);
    25042521        if (pGstCtx->fXStateMask != 0)
     
    29222939            AssertRCReturn(rc, rc);
    29232940
     2941            /* Deal with the reusing of reserved RFLAGS bits. */
     2942            pGstCtx->rflags.uBoth |= pVM->cpum.s.fReservedRFlagsCookie;
     2943
    29242944            /* REM and other may have cleared must-be-one fields in DR6 and
    29252945               DR7, fix these. */
  • trunk/src/VBox/VMM/VMMR3/EM.cpp

    r97178 r97231  
    22102210                fFFDone = false;
    22112211
     2212#ifdef VBOX_STRICT
     2213            CPUMAssertGuestRFlagsCookie(pVM, pVCpu);
     2214#endif
     2215
    22122216            /*
    22132217             * Now what to do?
  • trunk/src/VBox/VMM/include/CPUMInternal.h

    r97213 r97231  
    382382    uint8_t                 abPadding1[1];
    383383
     384    /** Random value we store in the reserved RFLAGS bits we don't use ourselves so
     385     *  we can detect corruption. */
     386    uint64_t                fReservedRFlagsCookie;
     387
    384388    /** Align to 64-byte boundary. */
    385     uint8_t                 abPadding2[20+4];
     389    uint8_t                 abPadding2[16];
    386390
    387391    /** Host CPU feature information.
  • trunk/src/VBox/VMM/include/IEMMc.h

    r97153 r97231  
    334334#define IEM_MC_REF_GREG_I64(a_pi64Dst, a_iGReg)         (a_pi64Dst) = (int64_t *)iemGRegRefU64(pVCpu, (a_iGReg))
    335335#define IEM_MC_REF_GREG_I64_CONST(a_pi64Dst, a_iGReg)   (a_pi64Dst) = (int64_t const *)iemGRegRefU64(pVCpu, (a_iGReg))
    336 /** @note Not for IOPL or IF testing or modification. */
    337 #define IEM_MC_REF_EFLAGS(a_pEFlags)                    (a_pEFlags) = &pVCpu->cpum.GstCtx.eflags.u
     336/** @note Not for IOPL or IF testing or modification.
     337 * @note Must preserve any undefined bits, see CPUMX86EFLAGS! */
     338#define IEM_MC_REF_EFLAGS(a_pEFlags)                    (a_pEFlags) = &pVCpu->cpum.GstCtx.eflags.uBoth
    338339#define IEM_MC_REF_MXCSR(a_pfMxcsr)                     (a_pfMxcsr) = &pVCpu->cpum.GstCtx.XState.x87.MXCSR
    339340
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