VirtualBox

Changeset 99983 in vbox


Ignore:
Timestamp:
May 26, 2023 12:10:23 AM (17 months ago)
Author:
vboxsync
Message:

VMM/IEM: Removed (finally) the need to call CPUMGetGuestCPL and iemCalcCpuMode for every instruction when executing lots of them. bugref:10369

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

Legend:

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

    r99982 r99983  
    338338    Assert(CPUMSELREG_ARE_HIDDEN_PARTS_VALID(pVCpu, &pVCpu->cpum.GstCtx.tr));
    339339
    340     pVCpu->iem.s.uCpl               = CPUMGetGuestCPL(pVCpu);   /** @todo this should be updated during execution! */
    341     IEMMODE enmMode = iemCalcCpuMode(pVCpu);
    342     pVCpu->iem.s.enmCpuMode         = enmMode;                  /** @todo this should be updated during execution! */
     340    Assert(pVCpu->iem.s.uCpl == CPUMGetGuestCPL(pVCpu)); /* ASSUMES: Anyone changing CPL will adjust iem.s.uCpl. */
     341    IEMMODE const enmMode = pVCpu->iem.s.enmCpuMode;
     342    Assert(enmMode == iemCalcCpuMode(pVCpu));            /* ASSUMES: Anyone changing the CPU mode will adjust iem.s.enmCpuMode. */
    343343    pVCpu->iem.s.enmDefAddrMode     = enmMode;  /** @todo check if this is correct... */
    344344    pVCpu->iem.s.enmEffAddrMode     = enmMode;
     
    20572057        iemRaiseXcptAdjustState(pVCpu, u8Vector);
    20582058
     2059    /* pVCpu->iem.s.enmCpuMode and pVCpu->iem.s.uCpl doesn't really change here,
     2060       so best leave them alone in case we're in a weird kind of real mode... */
     2061
    20592062    return fFlags & IEM_XCPT_FLAGS_T_CPU_XCPT ? VINF_IEM_RAISED_XCPT : VINF_SUCCESS;
    20602063}
     
    29052908    }
    29062909
     2910    /* Make sure the CPU mode is correct. */
     2911    IEMMODE const enmNewCpuMode = iemCalcCpuMode(pVCpu);
     2912    if (enmNewCpuMode != pVCpu->iem.s.enmCpuMode)
     2913        Log(("iemTaskSwitch: cpu mode %d -> %d\n", pVCpu->iem.s.enmCpuMode, enmNewCpuMode));
     2914    pVCpu->iem.s.enmCpuMode = enmNewCpuMode;
     2915
    29072916    /** @todo Debug trap. */
    29082917    if (fIsNewTSS386 && fNewDebugTrap)
     
    29172926        && (   !(fFlags & IEM_XCPT_FLAGS_T_SOFT_INT)
    29182927            ||  (fFlags & IEM_XCPT_FLAGS_ICEBP_INSTR)))
    2919     {
    29202928        uExt = 1;
    2921     }
    29222929    else
    29232930        uExt = 0;
     
    34473454        iemRaiseXcptAdjustState(pVCpu, u8Vector);
    34483455
     3456    /* Make sure the CPU mode is correct. */
     3457    IEMMODE const enmNewCpuMode = iemCalcCpuMode(pVCpu);
     3458    if (enmNewCpuMode != pVCpu->iem.s.enmCpuMode)
     3459        Log(("iemRaiseXcptOrIntInProtMode: cpu mode %d -> %d\n", pVCpu->iem.s.enmCpuMode, enmNewCpuMode));
     3460    pVCpu->iem.s.enmCpuMode = enmNewCpuMode;
     3461
    34493462    return fFlags & IEM_XCPT_FLAGS_T_CPU_XCPT ? VINF_IEM_RAISED_XCPT : VINF_SUCCESS;
    34503463}
     
    36903703    pVCpu->cpum.GstCtx.cs.Attr.u     = X86DESC_GET_HID_ATTR(&DescCS.Legacy);
    36913704    pVCpu->cpum.GstCtx.rip           = uNewRip;
     3705    pVCpu->iem.s.enmCpuMode          = IEMMODE_64BIT;
    36923706
    36933707    fEfl &= ~fEflToClear;
     
    40694083{
    40704084    return iemRaiseXcptOrInt(pVCpu, 0, X86_XCPT_TS, IEM_XCPT_FLAGS_T_CPU_XCPT | IEM_XCPT_FLAGS_ERR,
    4071                              pVCpu->cpum.GstCtx.tr.Sel, 0);
     4085                              pVCpu->cpum.GstCtx.tr.Sel, 0);
    40724086}
    40734087
  • trunk/src/VBox/VMM/VMMAll/IEMAllCImpl.cpp

    r99651 r99983  
    31923192    pVCpu->cpum.GstCtx.rip      = (uint16_t)uNewEip;
    31933193    pVCpu->cpum.GstCtx.rsp      = uNewEsp; /** @todo check this out! */
    3194     pVCpu->iem.s.uCpl  = 3;
     3194    pVCpu->iem.s.enmCpuMode = IEMMODE_16BIT;
     3195    pVCpu->iem.s.uCpl       = 3;
    31953196
    31963197    /* Flush the prefetch buffer. */
     
    41434144     */
    41444145    pVCpu->iem.s.uCpl = pVCpu->cpum.GstCtx.cs.Attr.n.u2Dpl;
     4146    Assert(pVCpu->iem.s.enmCpuMode == IEMMODE_16BIT);
    41454147
    41464148    CPUMSetChangedFlags(pVCpu, CPUM_CHANGED_HIDDEN_SEL_REGS | CPUM_CHANGED_IDTR | CPUM_CHANGED_GDTR | CPUM_CHANGED_TR | CPUM_CHANGED_LDTR);
     
    44654467    pVCpu->cpum.GstCtx.rflags.Bits.u1RF = 0;
    44664468
    4467     pVCpu->iem.s.uCpl                   = 0;
     4469    pVCpu->iem.s.uCpl       = 0;
     4470    pVCpu->iem.s.enmCpuMode = iemCalcCpuMode(pVCpu);
    44684471
    44694472    /* Flush the prefetch buffer. */
     
    45604563    pVCpu->cpum.GstCtx.rflags.Bits.u1RF = 0;
    45614564
    4562     pVCpu->iem.s.uCpl                   = 3;
     4565    pVCpu->iem.s.uCpl       = 3;
     4566    pVCpu->iem.s.enmCpuMode = iemCalcCpuMode(pVCpu);
    45634567/** @todo single stepping   */
    45644568
     
    60226026            Assert(pVCpu->cpum.GstCtx.cr0 == uNewCrX);
    60236027
     6028            /* Update the CPU mode if we're in 64-bit mode here, just in case
     6029               we've exited long mode while in 64-bit code... */
     6030            /** @todo testcase: what happens if we disable paging while in 64-bit code? */
     6031            if (pVCpu->iem.s.enmCpuMode == IEMMODE_64BIT)
     6032                pVCpu->iem.s.enmCpuMode = iemCalcCpuMode(pVCpu);
     6033
    60246034            rcStrict = PGMChangeMode(pVCpu, pVCpu->cpum.GstCtx.cr0, pVCpu->cpum.GstCtx.cr4, pVCpu->cpum.GstCtx.msrEFER,
    60256035                                     false /* fForce */);
  • trunk/src/VBox/VMM/include/IEMInline.h

    r99933 r99983  
    273273    pVCpu->iem.s.uCpl             = uCpl;
    274274    pVCpu->iem.s.enmCpuMode       = enmMode;
     275/** @todo r=bird: The rest of this function should not be necessary!
     276 * All these fields below will be re-initialized before we decode more code - as
     277 * they are _not_ relevant to 'Exec' (xcpt rcPassUp), only to 'Decoding'.
     278 *
     279 * Only exception might be rcPassUp, though, I don't know why anyone other than
     280 * the execution loops should need to mess around with it!
     281 *
     282 * I don't think we really need or want this function, better to just set uCpl
     283 * and enmCpuMode explicitly in the relevant code.  We do this in a number of
     284 * other scenarios.  Or, rename it to iemReCalcCpuModeAndCpl.
     285 */
    275286    pVCpu->iem.s.enmDefAddrMode   = enmMode;  /** @todo check if this is correct... */
    276287    pVCpu->iem.s.enmEffAddrMode   = enmMode;
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