VirtualBox

Changeset 106126 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
Sep 23, 2024 10:45:45 PM (2 months ago)
Author:
vboxsync
Message:

VMM/IEM: Eliminated the #ifndef IEMNATIVE_WITH_RECOMPILER_PROLOGUE_SINGLETON bits to try reduce the #ifdef-spaghetti a little. bugref:10677

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

Legend:

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

    r106125 r106126  
    68676867}
    68686868
    6869 
    6870 #ifndef IEMNATIVE_WITH_RECOMPILER_PROLOGUE_SINGLETON
    6871 /**
    6872  * Emits a standard prolog.
    6873  */
    6874 static uint32_t iemNativeEmitProlog(PIEMRECOMPILERSTATE pReNative, uint32_t off)
    6875 {
    6876 #ifdef RT_ARCH_AMD64
    6877     /*
    6878      * Set up a regular xBP stack frame, pushing all non-volatile GPRs,
    6879      * reserving 64 bytes for stack variables plus 4 non-register argument
    6880      * slots.  Fixed register assignment: xBX = pReNative;
    6881      *
    6882      * Since we always do the same register spilling, we can use the same
    6883      * unwind description for all the code.
    6884      */
    6885     uint8_t *const pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 32);
    6886     pbCodeBuf[off++] = 0x50 + X86_GREG_xBP;     /* push rbp */
    6887     pbCodeBuf[off++] = X86_OP_REX_W;            /* mov rbp, rsp */
    6888     pbCodeBuf[off++] = 0x8b;
    6889     pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, X86_GREG_xBP, X86_GREG_xSP);
    6890     pbCodeBuf[off++] = 0x50 + X86_GREG_xBX;     /* push rbx */
    6891     AssertCompile(IEMNATIVE_REG_FIXED_PVMCPU == X86_GREG_xBX);
    6892 # ifdef RT_OS_WINDOWS
    6893     pbCodeBuf[off++] = X86_OP_REX_W;            /* mov rbx, rcx ; RBX = pVCpu */
    6894     pbCodeBuf[off++] = 0x8b;
    6895     pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, X86_GREG_xBX, X86_GREG_xCX);
    6896     pbCodeBuf[off++] = 0x50 + X86_GREG_xSI;     /* push rsi */
    6897     pbCodeBuf[off++] = 0x50 + X86_GREG_xDI;     /* push rdi */
    6898 # else
    6899     pbCodeBuf[off++] = X86_OP_REX_W;            /* mov rbx, rdi ; RBX = pVCpu */
    6900     pbCodeBuf[off++] = 0x8b;
    6901     pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, X86_GREG_xBX, X86_GREG_xDI);
    6902 # endif
    6903     pbCodeBuf[off++] = X86_OP_REX_B;            /* push r12 */
    6904     pbCodeBuf[off++] = 0x50 + X86_GREG_x12 - 8;
    6905     pbCodeBuf[off++] = X86_OP_REX_B;            /* push r13 */
    6906     pbCodeBuf[off++] = 0x50 + X86_GREG_x13 - 8;
    6907     pbCodeBuf[off++] = X86_OP_REX_B;            /* push r14 */
    6908     pbCodeBuf[off++] = 0x50 + X86_GREG_x14 - 8;
    6909     pbCodeBuf[off++] = X86_OP_REX_B;            /* push r15 */
    6910     pbCodeBuf[off++] = 0x50 + X86_GREG_x15 - 8;
    6911 
    6912 # ifdef VBOX_WITH_IEM_NATIVE_RECOMPILER_LONGJMP
    6913     /* Save the frame pointer. */
    6914     off = iemNativeEmitStoreGprToVCpuU64Ex(pbCodeBuf, off, X86_GREG_xBP, RT_UOFFSETOF(VMCPUCC, iem.s.pvTbFramePointerR3));
    6915 # endif
    6916 
    6917     off = iemNativeEmitSubGprImm(pReNative, off,    /* sub rsp, byte 28h */
    6918                                  X86_GREG_xSP,
    6919                                    IEMNATIVE_FRAME_ALIGN_SIZE
    6920                                  + IEMNATIVE_FRAME_VAR_SIZE
    6921                                  + IEMNATIVE_FRAME_STACK_ARG_COUNT * 8
    6922                                  + IEMNATIVE_FRAME_SHADOW_ARG_COUNT * 8);
    6923     AssertCompile(!(IEMNATIVE_FRAME_VAR_SIZE & 0xf));
    6924     AssertCompile(!(IEMNATIVE_FRAME_STACK_ARG_COUNT & 0x1));
    6925     AssertCompile(!(IEMNATIVE_FRAME_SHADOW_ARG_COUNT & 0x1));
    6926 
    6927 #elif RT_ARCH_ARM64
    6928     /*
    6929      * We set up a stack frame exactly like on x86, only we have to push the
    6930      * return address our selves here.  We save all non-volatile registers.
    6931      */
    6932     uint32_t * const pu32CodeBuf = iemNativeInstrBufEnsure(pReNative, off, 16);
    6933 
    6934 # ifdef RT_OS_DARWIN /** @todo This seems to be requirement by libunwind for JIT FDEs. Investigate further as been unable
    6935                       * to figure out where the BRK following AUTHB*+XPACB* stuff comes from in libunwind.  It's
    6936                       * definitely the dwarf stepping code, but till found it's very tedious to figure out whether it's
    6937                       * in any way conditional, so just emitting this instructions now and hoping for the best... */
    6938     /* pacibsp */
    6939     pu32CodeBuf[off++] = ARMV8_A64_INSTR_PACIBSP;
    6940 # endif
    6941 
    6942     /* stp x19, x20, [sp, #-IEMNATIVE_FRAME_SAVE_REG_SIZE] ; Allocate space for saving registers and place x19+x20 at the bottom. */
    6943     AssertCompile(IEMNATIVE_FRAME_SAVE_REG_SIZE < 64*8);
    6944     pu32CodeBuf[off++] = Armv8A64MkInstrStLdPair(false /*fLoad*/, 2 /*64-bit*/, kArm64InstrStLdPairType_PreIndex,
    6945                                                  ARMV8_A64_REG_X19, ARMV8_A64_REG_X20, ARMV8_A64_REG_SP,
    6946                                                  -IEMNATIVE_FRAME_SAVE_REG_SIZE / 8);
    6947     /* Save x21 thru x28 (SP remains unchanged in the kSigned variant). */
    6948     pu32CodeBuf[off++] = Armv8A64MkInstrStLdPair(false /*fLoad*/, 2 /*64-bit*/, kArm64InstrStLdPairType_Signed,
    6949                                                  ARMV8_A64_REG_X21, ARMV8_A64_REG_X22, ARMV8_A64_REG_SP, 2);
    6950     pu32CodeBuf[off++] = Armv8A64MkInstrStLdPair(false /*fLoad*/, 2 /*64-bit*/, kArm64InstrStLdPairType_Signed,
    6951                                                  ARMV8_A64_REG_X23, ARMV8_A64_REG_X24, ARMV8_A64_REG_SP, 4);
    6952     pu32CodeBuf[off++] = Armv8A64MkInstrStLdPair(false /*fLoad*/, 2 /*64-bit*/, kArm64InstrStLdPairType_Signed,
    6953                                                  ARMV8_A64_REG_X25, ARMV8_A64_REG_X26, ARMV8_A64_REG_SP, 6);
    6954     pu32CodeBuf[off++] = Armv8A64MkInstrStLdPair(false /*fLoad*/, 2 /*64-bit*/, kArm64InstrStLdPairType_Signed,
    6955                                                  ARMV8_A64_REG_X27, ARMV8_A64_REG_X28, ARMV8_A64_REG_SP, 8);
    6956     /* Save the BP and LR (ret address) registers at the top of the frame. */
    6957     pu32CodeBuf[off++] = Armv8A64MkInstrStLdPair(false /*fLoad*/, 2 /*64-bit*/, kArm64InstrStLdPairType_Signed,
    6958                                                  ARMV8_A64_REG_BP,  ARMV8_A64_REG_LR,  ARMV8_A64_REG_SP, 10);
    6959     AssertCompile(IEMNATIVE_FRAME_SAVE_REG_SIZE / 8 == 12);
    6960     /* add bp, sp, IEMNATIVE_FRAME_SAVE_REG_SIZE - 16 ; Set BP to point to the old BP stack address. */
    6961     pu32CodeBuf[off++] = Armv8A64MkInstrAddSubUImm12(false /*fSub*/, ARMV8_A64_REG_BP,
    6962                                                      ARMV8_A64_REG_SP, IEMNATIVE_FRAME_SAVE_REG_SIZE - 16);
    6963 
    6964     /* sub sp, sp, IEMNATIVE_FRAME_VAR_SIZE ;  Allocate the variable area from SP. */
    6965     pu32CodeBuf[off++] = Armv8A64MkInstrAddSubUImm12(true /*fSub*/, ARMV8_A64_REG_SP, ARMV8_A64_REG_SP, IEMNATIVE_FRAME_VAR_SIZE);
    6966 
    6967     /* mov r28, r0  */
    6968     off = iemNativeEmitLoadGprFromGprEx(pu32CodeBuf, off, IEMNATIVE_REG_FIXED_PVMCPU, IEMNATIVE_CALL_ARG0_GREG);
    6969     /* mov r27, r1  */
    6970     off = iemNativeEmitLoadGprFromGprEx(pu32CodeBuf, off, IEMNATIVE_REG_FIXED_PCPUMCTX, IEMNATIVE_CALL_ARG1_GREG);
    6971 
    6972 # ifdef VBOX_WITH_IEM_NATIVE_RECOMPILER_LONGJMP
    6973     /* Save the frame pointer. */
    6974     off = iemNativeEmitStoreGprToVCpuU64Ex(pu32CodeBuf, off, ARMV8_A64_REG_BP, RT_UOFFSETOF(VMCPUCC, iem.s.pvTbFramePointerR3),
    6975                                            ARMV8_A64_REG_X2);
    6976 # endif
    6977 
    6978 #else
    6979 # error "port me"
    6980 #endif
    6981     IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    6982     return off;
    6983 }
    6984 #endif
    69856869
    69866870
     
    99829866    IEMNATIVE_TRY_SETJMP(pReNative, rc)
    99839867    {
    9984 #ifndef IEMNATIVE_WITH_RECOMPILER_PROLOGUE_SINGLETON
    9985         /*
    9986          * Emit prolog code (fixed).
    9987          */
    9988         off = iemNativeEmitProlog(pReNative, off);
    9989 #endif
    9990 
    99919868        /*
    99929869         * Convert the calls to native code.
  • trunk/src/VBox/VMM/VMMAll/IEMAllThrdRecompiler.cpp

    r106061 r106126  
    32153215# endif
    32163216
    3217 # ifndef IEMNATIVE_WITH_RECOMPILER_PROLOGUE_SINGLETON
    3218 #  ifdef RT_ARCH_AMD64
    3219         VBOXSTRICTRC const rcStrict = ((PFNIEMTBNATIVE)pTb->Native.paInstructions)(pVCpu);
    3220 #  else
    3221         VBOXSTRICTRC const rcStrict = ((PFNIEMTBNATIVE)pTb->Native.paInstructions)(pVCpu, &pVCpu->cpum.GstCtx);
    3222 #  endif
     3217# ifdef VBOX_WITH_IEM_NATIVE_RECOMPILER_LONGJMP
     3218        AssertCompileMemberOffset(VMCPUCC, iem.s.pvTbFramePointerR3, 0x7c8); /* This is assumed in iemNativeTbEntry */
     3219# endif
     3220# ifdef RT_ARCH_AMD64
     3221        VBOXSTRICTRC const rcStrict = iemNativeTbEntry(pVCpu, (uintptr_t)pTb->Native.paInstructions);
    32233222# else
    3224 #  ifdef VBOX_WITH_IEM_NATIVE_RECOMPILER_LONGJMP
    3225         AssertCompileMemberOffset(VMCPUCC, iem.s.pvTbFramePointerR3, 0x7c8); /* This is assumed in iemNativeTbEntry */
    3226 #  endif
    3227 #  ifdef RT_ARCH_AMD64
    3228         VBOXSTRICTRC const rcStrict = iemNativeTbEntry(pVCpu, (uintptr_t)pTb->Native.paInstructions);
    3229 #  else
    32303223        VBOXSTRICTRC const rcStrict = iemNativeTbEntry(pVCpu, &pVCpu->cpum.GstCtx, (uintptr_t)pTb->Native.paInstructions);
    3231 #  endif
    32323224# endif
    32333225
  • trunk/src/VBox/VMM/include/IEMN8veRecompiler.h

    r106125 r106126  
    9393/** Always count instructions for now. */
    9494# define IEMNATIVE_WITH_INSTRUCTION_COUNTING
    95 #endif
    96 
    97 /** @def IEMNATIVE_WITH_RECOMPILER_PROLOGUE_SINGLETON
    98  * Enables having only a single prologue for native TBs. */
    99 #if 1 || defined(DOXYGEN_RUNNING)
    100 # define IEMNATIVE_WITH_RECOMPILER_PROLOGUE_SINGLETON
    10195#endif
    10296
     
    28212815
    28222816
    2823 #ifdef IEMNATIVE_WITH_RECOMPILER_PROLOGUE_SINGLETON
    28242817/** @note iemNativeTbEntry returns VBOXSTRICTRC, but we don't declare it as
    28252818 *        it saves us the trouble of a hidden parameter on MSC/amd64. */
    2826 # ifdef RT_ARCH_AMD64
     2819#ifdef RT_ARCH_AMD64
    28272820extern "C" IEM_DECL_NATIVE_HLP_DEF(int, iemNativeTbEntry, (PVMCPUCC pVCpu, uintptr_t pfnTbBody));
    2828 # elif defined(RT_ARCH_ARM64)
     2821#elif defined(RT_ARCH_ARM64)
    28292822extern "C" IEM_DECL_NATIVE_HLP_DEF(int, iemNativeTbEntry, (PVMCPUCC pVCpu, PCPUMCTX pCpumCtx, uintptr_t pfnTbBody));
    2830 # endif
    28312823#endif
    28322824
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