VirtualBox

Ignore:
Timestamp:
Nov 9, 2023 2:09:51 AM (13 months ago)
Author:
vboxsync
Message:

VMM/IEM: If we use structure variables in MC blocks, we need special fetch and store MCs for them or it won't be possible to recompile the code (as variables references are translated to uint8_t indexes by name, no subfield access possible). So, added some variable checking to tstIEMCheckMc and addressed the issues found. (There is more to do here, but tomorrow.) bugref:10371

File:
1 edited

Legend:

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

    r102011 r102012  
    57565756iemNativeEmitStoreGregU8Const(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t iGRegEx, uint8_t u8Value)
    57575757{
     5758    Assert(iGRegEx < 20);
    57585759    uint8_t const idxGstTmpReg = iemNativeRegAllocTmpForGuestReg(pReNative, &off,
    57595760                                                                 (IEMNATIVEGSTREG)(kIemNativeGstReg_GprFirst + (iGRegEx & 15)),
    5760                                                                   kIemNativeGstRegUse_ForUpdate);
     5761                                                                 kIemNativeGstRegUse_ForUpdate);
    57615762#ifdef RT_ARCH_AMD64
    57625763    uint8_t * const pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 12);
     
    58255826
    58265827
    5827 /*
    5828  * General purpose register manipulation (add, sub).
    5829  */
     5828#if 0
     5829#define IEM_MC_STORE_GREG_U16(a_iGReg, a_u16Value) \
     5830    off = iemNativeEmitStoreGregU16Const(pReNative, off, a_iGReg, a_u16Value)
     5831
     5832/** Emits code for IEM_MC_STORE_GREG_U16. */
     5833DECL_INLINE_THROW(uint32_t)
     5834iemNativeEmitStoreGregU16(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t iGReg, uint8_t idxValueVar)
     5835{
     5836    Assert(iGReg < 16)
     5837    uint8_t const idxGstTmpReg = iemNativeRegAllocTmpForGuestReg(pReNative, &off,
     5838                                                                 (IEMNATIVEGSTREG)(kIemNativeGstReg_GprFirst + iGReg),
     5839                                                                 kIemNativeGstRegUse_ForUpdate);
     5840
     5841
     5842#ifdef RT_ARCH_AMD64
     5843    uint8_t * const pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 12);
     5844
     5845    /* To the lowest byte of the register: mov r8, imm8 */
     5846    if (iGRegEx < 16)
     5847    {
     5848        if (idxGstTmpReg >= 8)
     5849            pbCodeBuf[off++] = X86_OP_REX_B;
     5850        else if (idxGstTmpReg >= 4)
     5851            pbCodeBuf[off++] = X86_OP_REX;
     5852        pbCodeBuf[off++] = 0xb0 + (idxGstTmpReg & 7);
     5853        pbCodeBuf[off++] = u8Value;
     5854    }
     5855    /* Otherwise it's to ah, ch, dh or bh: use mov r8, imm8 if we can, otherwise, we rotate. */
     5856    else if (idxGstTmpReg < 4)
     5857    {
     5858        pbCodeBuf[off++] = 0xb4 + idxGstTmpReg;
     5859        pbCodeBuf[off++] = u8Value;
     5860    }
     5861    else
     5862    {
     5863        /* ror reg64, 8 */
     5864        pbCodeBuf[off++] = X86_OP_REX_W | (idxGstTmpReg < 8 ? 0 : X86_OP_REX_B);
     5865        pbCodeBuf[off++] = 0xc1;
     5866        pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, 1, idxGstTmpReg & 7);
     5867        pbCodeBuf[off++] = 8;
     5868
     5869        /* mov reg8, imm8  */
     5870        if (idxGstTmpReg >= 8)
     5871            pbCodeBuf[off++] = X86_OP_REX_B;
     5872        else if (idxGstTmpReg >= 4)
     5873            pbCodeBuf[off++] = X86_OP_REX;
     5874        pbCodeBuf[off++] = 0xb0 + (idxGstTmpReg & 7);
     5875        pbCodeBuf[off++] = u8Value;
     5876
     5877        /* rol reg64, 8 */
     5878        pbCodeBuf[off++] = X86_OP_REX_W | (idxGstTmpReg < 8 ? 0 : X86_OP_REX_B);
     5879        pbCodeBuf[off++] = 0xc1;
     5880        pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, 0, idxGstTmpReg & 7);
     5881        pbCodeBuf[off++] = 8;
     5882    }
     5883
     5884#elif defined(RT_ARCH_ARM64)
     5885    uint8_t const    idxImmReg   = iemNativeRegAllocTmpImm(pReNative, &off, u8Value);
     5886    uint32_t * const pu32CodeBuf = iemNativeInstrBufEnsure(pReNative, off, 2);
     5887    if (iGRegEx < 16)
     5888        /* bfi w1, w2, 0, 8 - moves bits 7:0 from idxImmReg to idxGstTmpReg bits 7:0. */
     5889        pu32CodeBuf[off++] = Armv8A64MkInstrBfi(idxGstTmpReg, idxImmReg, 0, 8);
     5890    else
     5891        /* bfi w1, w2, 8, 8 - moves bits 7:0 from idxImmReg to idxGstTmpReg bits 15:8. */
     5892        pu32CodeBuf[off++] = Armv8A64MkInstrBfi(idxGstTmpReg, idxImmReg, 8, 8);
     5893    iemNativeRegFreeTmp(pReNative, idxImmReg);
     5894
     5895#else
     5896# error "Port me!"
     5897#endif
     5898
     5899    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
     5900
     5901    off = iemNativeEmitStoreGprToVCpuU64(pReNative, off, idxGstTmpReg, RT_UOFFSETOF_DYN(VMCPU, cpum.GstCtx.aGRegs[iGRegEx & 15]));
     5902
     5903    iemNativeRegFreeTmp(pReNative, idxGstTmpReg);
     5904    return off;
     5905}
     5906#endif
     5907
     5908
     5909
     5910/*********************************************************************************************************************************
     5911*   General purpose register manipulation (add, sub).                                                                            *
     5912*********************************************************************************************************************************/
    58305913
    58315914#define IEM_MC_SUB_GREG_U16(a_iGReg, a_u8SubtrahendConst) \
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