VirtualBox

Changeset 99982 in vbox for trunk


Ignore:
Timestamp:
May 25, 2023 7:59:54 PM (16 months ago)
Author:
vboxsync
Message:

VMM/IEM: More plotting on the IEM recompiler. bugref:10369

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

Legend:

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

    r99930 r99982  
    278278    pVCpu->iem.s.offCurInstrStart   = 0;
    279279# ifdef VBOX_STRICT
     280    pVCpu->iem.s.GCPhysInstrBuf     = NIL_RTGCPHYS;
    280281    pVCpu->iem.s.cbInstrBuf         = UINT16_MAX;
    281282    pVCpu->iem.s.cbInstrBufTotal    = UINT16_MAX;
     
    384385            pVCpu->iem.s.cbInstrBuf       = 0;
    385386            pVCpu->iem.s.cbInstrBufTotal  = 0;
     387            pVCpu->iem.s.GCPhysInstrBuf   = NIL_RTGCPHYS;
    386388        }
    387389    }
     
    392394        pVCpu->iem.s.cbInstrBuf       = 0;
    393395        pVCpu->iem.s.cbInstrBufTotal  = 0;
     396# ifdef VBOX_STRICT
     397        pVCpu->iem.s.GCPhysInstrBuf   = NIL_RTGCPHYS;
     398# endif
    394399    }
    395400#else
     
    956961                pVCpu->iem.s.offInstrNextByte = offPg + (uint32_t)cbDst;
    957962                pVCpu->iem.s.uInstrBufPc      = GCPtrFirst & ~(RTGCPTR)X86_PAGE_OFFSET_MASK;
     963                pVCpu->iem.s.GCPhysInstrBuf   = pTlbe->GCPhys;
    958964                pVCpu->iem.s.pbInstrBuf       = pTlbe->pbMappingR3;
    959965                memcpy(pvDst, &pTlbe->pbMappingR3[offPg], cbDst);
     
    1033510341        pVCpu->iem.s.offCurInstrStart = 0;
    1033610342        pVCpu->iem.s.offInstrNextByte = 0;
     10343        pVCpu->iem.s.GCPhysInstrBuf   = NIL_RTGCPHYS;
    1033710344#else
    1033810345        pVCpu->iem.s.cbOpcode = (uint8_t)RT_MIN(cbOpcodeBytes, sizeof(pVCpu->iem.s.abOpcode));
     
    1038310390        pVCpu->iem.s.offCurInstrStart = 0;
    1038410391        pVCpu->iem.s.offInstrNextByte = 0;
     10392        pVCpu->iem.s.GCPhysInstrBuf   = NIL_RTGCPHYS;
    1038510393#else
    1038610394        pVCpu->iem.s.cbOpcode = (uint8_t)RT_MIN(cbOpcodeBytes, sizeof(pVCpu->iem.s.abOpcode));
  • trunk/src/VBox/VMM/VMMAll/IEMAllInstructionsThreadedRecompiler.cpp

    r99932 r99982  
    7575
    7676#include "IEMThreadedFunctions.h"
     77
     78
     79/*
     80 * Narrow down configs here to avoid wasting time on unused configs here.
     81 */
     82
     83#ifndef IEM_WITH_CODE_TLB
     84# error The code TLB must be enabled for the recompiler.
     85#endif
     86
     87#ifndef IEM_WITH_DATA_TLB
     88# error The data TLB must be enabled for the recompiler.
     89#endif
     90
     91#ifndef IEM_WITH_SETJMP
     92# error The setjmp approach must be enabled for the recompiler.
     93#endif
    7794
    7895
     
    275292
    276293
    277 static PIEMTB iemThreadedTbLookup(PVMCCV pVM, PVMCPUCC pVCpu)
    278 {
    279     RT_NOREF(pVM, pVCpu);
     294static PIEMTB iemThreadedTbLookup(PVMCCV pVM, PVMCPUCC pVCpu, RTGCPHYS GCPhysPC, uint64_t uPc)
     295{
     296    RT_NOREF(pVM, pVCpu, GCPhysPC, uPc);
    280297    return NULL;
    281298}
     
    286303    RT_NOREF(pVM, pVCpu, pTb);
    287304    return VERR_NOT_IMPLEMENTED;
     305}
     306
     307
     308/**
     309 * This is called when the PC doesn't match the current pbInstrBuf.
     310 */
     311static uint64_t iemGetPcWithPhysAndCodeMissed(PVMCPUCC pVCpu, uint64_t const uPc, PRTGCPHYS pPhys)
     312{
     313    /** @todo see iemOpcodeFetchBytesJmp */
     314    pVCpu->iem.s.pbInstrBuf = NULL;
     315
     316    pVCpu->iem.s.offInstrNextByte = 0;
     317    pVCpu->iem.s.offCurInstrStart = 0;
     318    pVCpu->iem.s.cbInstrBuf       = 0;
     319    pVCpu->iem.s.cbInstrBufTotal  = 0;
     320
     321}
     322
     323/** @todo need private inline decl for throw/nothrow matching IEM_WITH_SETJMP? */
     324DECL_INLINE_THROW(uint64_t) iemGetPcWithPhysAndCode(PVMCPUCC pVCpu, PRTGCPHYS pPhys)
     325{
     326    Assert(pVCpu->cpum.GstCtx.cs.u64Base == 0 || pVCpu->iem.s.enmCpuMode != IEMMODE_64BIT);
     327    uint64_t const uPc = pVCpu->cpum.GstCtx.rip + pVCpu->cpum.GstCtx.cs.u64Base;
     328    if (pVCpu->iem.s.pbInstrBuf)
     329    {
     330        uint64_t off = uPc - pVCpu->iem.s.uInstrBufPc;
     331        if (off < pVCpu->iem.s.cbInstrBufTotal)
     332        {
     333            pVCpu->iem.s.offInstrNextByte = (uint32_t)off;
     334            pVCpu->iem.s.offCurInstrStart = (uint16_t)off;
     335            if ((uint16_t)off + 15 <= pVCpu->iem.s.cbInstrBufTotal)
     336                pVCpu->iem.s.cbInstrBuf = (uint16_t)off + 15;
     337            else
     338                pVCpu->iem.s.cbInstrBuf = pVCpu->iem.s.cbInstrBufTotal;
     339
     340            *pPhys = pVCpu->iem.s.GCPhysInstrBuf + off;
     341            return uPc;
     342        }
     343    }
     344    return iemGetPcWithPhysAndCodeMissed(pVCpu, uPc, pPhys);
    288345}
    289346
     
    307364            for (;;)
    308365            {
    309                 pTb = iemThreadedTbLookup(pVM, pVCpu);
     366                /* Translate PC to physical address, we'll need this for both lookup and compilation. */
     367                RTGCPHYS       GCPhysPC;
     368                uint64_t const uPC = iemGetPcWithPhysAndCode(pVCpu, &GCPhysPC);
     369
     370                pTb = iemThreadedTbLookup(pVM, pVCpu, GCPhysPC, uPc);
    310371                if (pTb)
    311372                    rcStrict = iemThreadedTbExec(pVM, pVCpu, pTb);
    312373                else
    313                     rcStrict = iemThreadedCompile(pVM, pVCpu);
     374                    rcStrict = iemThreadedCompile(pVM, pVCpu, GCPhysPC, uPc);
    314375                if (rcStrict == VINF_SUCCESS)
    315376                { /* likely */ }
  • trunk/src/VBox/VMM/VMMR3/EM.cpp

    r99930 r99982  
    10821082#ifdef VBOX_WITH_IEM_RECOMPILER
    10831083            if (pVM->em.s.fIemRecompiled)
    1084                 rcStrict = IEMExecRecompilerThreaded(pVCpu);
     1084                rcStrict = IEMExecRecompilerThreaded(pVM, pVCpu);
    10851085            else
    10861086#endif
  • trunk/src/VBox/VMM/include/IEMInternal.h

    r99930 r99982  
    600600     * This is set to a non-canonical address when we need to invalidate it. */
    601601    uint64_t                uInstrBufPc;                                                                    /* 0x18 */
     602    /** The guest physical address corresponding to pbInstrBuf. */
     603    RTGCPHYS                GCPhysInstrBuf;                                                                 /* 0x20 */
    602604    /** The number of bytes available at pbInstrBuf in total (for IEMExecLots).
    603605     * This takes the CS segment limit into account. */
    604     uint16_t                cbInstrBufTotal;                                                                /* 0x20 */
     606    uint16_t                cbInstrBufTotal;                                                                /* 0x28 */
    605607    /** Offset into pbInstrBuf of the first byte of the current instruction.
    606608     * Can be negative to efficiently handle cross page instructions. */
    607     int16_t                 offCurInstrStart;                                                               /* 0x22 */
     609    int16_t                 offCurInstrStart;                                                               /* 0x2a */
    608610
    609611    /** The prefix mask (IEM_OP_PRF_XXX). */
    610     uint32_t                fPrefixes;                                                                      /* 0x24 */
     612    uint32_t                fPrefixes;                                                                      /* 0x2c */
    611613    /** The extra REX ModR/M register field bit (REX.R << 3). */
    612     uint8_t                 uRexReg;                                                                        /* 0x28 */
     614    uint8_t                 uRexReg;                                                                        /* 0x30 */
    613615    /** The extra REX ModR/M r/m field, SIB base and opcode reg bit
    614616     * (REX.B << 3). */
    615     uint8_t                 uRexB;                                                                          /* 0x29 */
     617    uint8_t                 uRexB;                                                                          /* 0x31 */
    616618    /** The extra REX SIB index field bit (REX.X << 3). */
    617     uint8_t                 uRexIndex;                                                                      /* 0x2a */
     619    uint8_t                 uRexIndex;                                                                      /* 0x32 */
    618620
    619621    /** The effective segment register (X86_SREG_XXX). */
    620     uint8_t                 iEffSeg;                                                                        /* 0x2b */
     622    uint8_t                 iEffSeg;                                                                        /* 0x33 */
    621623
    622624    /** The offset of the ModR/M byte relative to the start of the instruction. */
    623     uint8_t                 offModRm;                                                                       /* 0x2c */
     625    uint8_t                 offModRm;                                                                       /* 0x34 */
    624626# else  /* !IEM_WITH_CODE_TLB */
    625627    /** The size of what has currently been fetched into abOpcode. */
     
    646648
    647649    /** The effective operand mode. */
    648     IEMMODE                 enmEffOpSize;                                                                   /* 0x2d, 0x13 */
     650    IEMMODE                 enmEffOpSize;                                                                   /* 0x35, 0x13 */
    649651    /** The default addressing mode. */
    650     IEMMODE                 enmDefAddrMode;                                                                 /* 0x2e, 0x14 */
     652    IEMMODE                 enmDefAddrMode;                                                                 /* 0x36, 0x14 */
    651653    /** The effective addressing mode. */
    652     IEMMODE                 enmEffAddrMode;                                                                 /* 0x2f, 0x15 */
     654    IEMMODE                 enmEffAddrMode;                                                                 /* 0x37, 0x15 */
    653655    /** The default operand mode. */
    654     IEMMODE                 enmDefOpSize;                                                                   /* 0x30, 0x16 */
     656    IEMMODE                 enmDefOpSize;                                                                   /* 0x38, 0x16 */
    655657
    656658    /** Prefix index (VEX.pp) for two byte and three byte tables. */
    657     uint8_t                 idxPrefix;                                                                      /* 0x31, 0x17 */
     659    uint8_t                 idxPrefix;                                                                      /* 0x39, 0x17 */
    658660    /** 3rd VEX/EVEX/XOP register.
    659661     * Please use IEM_GET_EFFECTIVE_VVVV to access.  */
    660     uint8_t                 uVex3rdReg;                                                                     /* 0x32, 0x18 */
     662    uint8_t                 uVex3rdReg;                                                                     /* 0x3a, 0x18 */
    661663    /** The VEX/EVEX/XOP length field. */
    662     uint8_t                 uVexLength;                                                                     /* 0x33, 0x19 */
     664    uint8_t                 uVexLength;                                                                     /* 0x3b, 0x19 */
    663665    /** Additional EVEX stuff. */
    664     uint8_t                 fEvexStuff;                                                                     /* 0x34, 0x1a */
     666    uint8_t                 fEvexStuff;                                                                     /* 0x3c, 0x1a */
    665667
    666668    /** Explicit alignment padding. */
    667     uint8_t                 abAlignment2a[1];                                                               /* 0x35, 0x1b */
     669    uint8_t                 abAlignment2a[1];                                                               /* 0x3d, 0x1b */
    668670    /** The FPU opcode (FOP). */
    669     uint16_t                uFpuOpcode;                                                                     /* 0x36, 0x1c */
     671    uint16_t                uFpuOpcode;                                                                     /* 0x3e, 0x1c */
    670672# ifndef IEM_WITH_CODE_TLB
    671673    /** Explicit alignment padding. */
     
    674676
    675677    /** The opcode bytes. */
    676     uint8_t                 abOpcode[15];                                                                   /* 0x48, 0x20 */
     678    uint8_t                 abOpcode[15];                                                                   /* 0x40, 0x20 */
    677679    /** Explicit alignment padding. */
    678680# ifdef IEM_WITH_CODE_TLB
    679     uint8_t                 abAlignment2c[0x48 - 0x47];                                                     /* 0x37 */
     681    //uint8_t                 abAlignment2c[0x4f - 0x4f];                                                     /* 0x4f */
    680682# else
    681     uint8_t                 abAlignment2c[0x48 - 0x2f];                                                     /*       0x2f */
     683    uint8_t                 abAlignment2c[0x4f - 0x2f];                                                     /*       0x2f */
    682684# endif
    683685#else  /* IEM_WITH_OPAQUE_DECODER_STATE */
    684     uint8_t                 abOpaqueDecoder[0x48 - 0x8];
     686    uint8_t                 abOpaqueDecoder[0x4f - 0x8];
    685687#endif /* IEM_WITH_OPAQUE_DECODER_STATE */
    686688    /** @} */
    687689
    688690
    689     /** The flags of the current exception / interrupt. */
    690     uint32_t                fCurXcpt;                                                                       /* 0x48, 0x48 */
    691     /** The current exception / interrupt. */
    692     uint8_t                 uCurXcpt;
    693     /** Exception / interrupt recursion depth. */
    694     int8_t                  cXcptRecursions;
    695 
    696691    /** The number of active guest memory mappings. */
    697     uint8_t                 cActiveMappings;
    698     /** The next unused mapping index. */
    699     uint8_t                 iNextMapping;
     692    uint8_t                 cActiveMappings;                                                                /* 0x4f, 0x4f */
     693
    700694    /** Records for tracking guest memory mappings. */
    701695    struct
    702696    {
    703697        /** The address of the mapped bytes. */
    704         void               *pv;
     698        R3R0PTRTYPE(void *) pv;
    705699        /** The access flags (IEM_ACCESS_XXX).
    706700         * IEM_ACCESS_INVALID if the entry is unused. */
     
    709703        uint32_t            u32Alignment4; /**< Alignment padding. */
    710704#endif
    711     } aMemMappings[3];
     705    } aMemMappings[3];                                                                                      /* 0x50 LB 0x30 */
    712706
    713707    /** Locking records for the mapped memory. */
     
    716710        PGMPAGEMAPLOCK      Lock;
    717711        uint64_t            au64Padding[2];
    718     } aMemMappingLocks[3];
     712    } aMemMappingLocks[3];                                                                                  /* 0x80 LB 0x30 */
    719713
    720714    /** Bounce buffer info.
     
    734728        /** Explicit alignment padding. */
    735729        bool                afAlignment5[3];
    736     } aMemBbMappings[3];
    737 
    738     /* Ensure that aBounceBuffers are aligned at a 32 byte boundrary. */
    739     uint64_t                abAlignment7[1];
     730    } aMemBbMappings[3];                                                                                    /* 0xb0 LB 0x48 */
     731
     732    /** The flags of the current exception / interrupt. */
     733    uint32_t                fCurXcpt;                                                                       /* 0xf8 */
     734    /** The current exception / interrupt. */
     735    uint8_t                 uCurXcpt;                                                                       /* 0xfc */
     736    /** Exception / interrupt recursion depth. */
     737    int8_t                  cXcptRecursions;                                                                /* 0xfb */
     738
     739    /** The next unused mapping index.
     740     * @todo try find room for this up with cActiveMappings. */
     741    uint8_t                 iNextMapping;                                                                   /* 0xfd */
     742    uint8_t                 abAlignment7[1];
    740743
    741744    /** Bounce buffer storage.
     
    744747    {
    745748        uint8_t             ab[512];
    746     } aBounceBuffers[3];
     749    } aBounceBuffers[3];                                                                                    /* 0x100 LB 0x600 */
    747750
    748751
     
    816819    uint8_t                 cLogRelWrMsr;
    817820    /** Alignment padding. */
    818     uint8_t                 abAlignment8[42];
     821    uint8_t                 abAlignment9[46];
    819822
    820823    /** @name Recompilation
     
    846849#endif
    847850} IEMCPU;
    848 AssertCompileMemberOffset(IEMCPU, fCurXcpt, 0x48);
    849 AssertCompileMemberAlignment(IEMCPU, aBounceBuffers, 8);
    850 AssertCompileMemberAlignment(IEMCPU, aBounceBuffers, 16);
    851 AssertCompileMemberAlignment(IEMCPU, aBounceBuffers, 32);
     851AssertCompileMemberOffset(IEMCPU, cActiveMappings, 0x4f);
     852AssertCompileMemberAlignment(IEMCPU, aMemMappings, 16);
     853AssertCompileMemberAlignment(IEMCPU, aMemMappingLocks, 16);
    852854AssertCompileMemberAlignment(IEMCPU, aBounceBuffers, 64);
    853855AssertCompileMemberAlignment(IEMCPU, DataTlb, 64);
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