VirtualBox

Changeset 40442 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 13, 2012 11:40:27 AM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
76794
Message:

IEM integration in progress - doing some EM refactoring to ease this process.

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

Legend:

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

    r40357 r40442  
    7575*   Internal Functions                                                         *
    7676*******************************************************************************/
     77#ifndef VBOX_WITH_IEM
    7778DECLINLINE(VBOXSTRICTRC) emInterpretInstructionCPU(PVM pVM, PVMCPU pVCpu, PDISCPUSTATE pDis, PCPUMCTXCORE pRegFrame,
    7879                                                   RTGCPTR pvFault, EMCODETYPE enmCodeType, uint32_t *pcbSize);
     80#endif
    7981
    8082
     
    488490VMMDECL(VBOXSTRICTRC) EMInterpretInstruction(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, uint32_t *pcbSize)
    489491{
     492    LogFlow(("EMInterpretInstruction %RGv fault %RGv\n", (RTGCPTR)pRegFrame->rip, pvFault));
     493#ifdef VBOX_WITH_IEM
     494    int rc = IEMExecOneEx(pVCpu, pRegFrame, IEM_EXEC_ONE_EX_FLAGS_, pcbSize);
     495    if (RT_FAILURE(rc))
     496        switch (rc)
     497        {
     498            case VERR_IEM_ASPECT_NOT_IMPLEMENTED:
     499            case VERR_IEM_INSTR_NOT_IMPLEMENTED:
     500                return VERR_EM_INTERPRETER;
     501        }
     502    return rc;
     503#else
    490504    RTGCPTR pbCode;
    491 
    492     LogFlow(("EMInterpretInstruction %RGv fault %RGv\n", (RTGCPTR)pRegFrame->rip, pvFault));
    493505    VBOXSTRICTRC rc = SELMToFlatEx(pVM, DIS_SELREG_CS, pRegFrame, pRegFrame->rip, 0, &pbCode);
    494506    if (RT_SUCCESS(rc))
     
    509521    }
    510522    return VERR_EM_INTERPRETER;
     523#endif
    511524}
    512525
     
    555568
    556569/**
    557  * Interpret a port I/O instruction.
    558  *
    559  * @returns VBox status code suitable for scheduling.
     570 * Interprets the current instruction using the supplied DISCPUSTATE structure.
     571 *
     572 * IP/EIP/RIP *IS* updated!
     573 *
     574 * @returns VBox strict status code.
     575 * @retval  VINF_*                  Scheduling instructions. When these are returned, it
     576 *                                  starts to get a bit tricky to know whether code was
     577 *                                  executed or not... We'll address this when it becomes a problem.
     578 * @retval  VERR_EM_INTERPRETER     Something we can't cope with.
     579 * @retval  VERR_*                  Fatal errors.
     580 *
    560581 * @param   pVM         The VM handle.
    561582 * @param   pVCpu       The VMCPU handle.
    562  * @param   pCtxCore    The context core. This will be updated on successful return.
    563  * @param   pDis        The instruction to interpret.
    564  * @param   cbOp        The size of the instruction.
    565  * @remark  This may raise exceptions.
    566  */
    567 VMMDECL(VBOXSTRICTRC) EMInterpretPortIO(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, PDISCPUSTATE pDis, uint32_t cbOp)
    568 {
    569     /*
    570      * Hand it on to IOM.
    571      */
    572 #ifdef IN_RC
    573     VBOXSTRICTRC rcStrict = IOMGCIOPortHandler(pVM, pCtxCore, pDis);
    574     if (IOM_SUCCESS(rcStrict))
    575         pCtxCore->rip += cbOp;
    576     NOREF(pVCpu);
    577     return rcStrict;
    578 #else
    579     NOREF(pVM); NOREF(pVCpu); NOREF(pCtxCore); NOREF(pDis); NOREF(cbOp);
    580     AssertReleaseMsgFailed(("not implemented\n"));
    581     return VERR_NOT_IMPLEMENTED;
    582 #endif
    583 }
    584 
     583 * @param   pDis        The disassembler cpu state for the instruction to be
     584 *                      interpreted.
     585 * @param   pRegFrame   The register frame. IP/EIP/RIP *IS* changed!
     586 * @param   pvFault     The fault address (CR2).
     587 * @param   pcbSize     Size of the write (if applicable).
     588 * @param   enmCodeType Code type (user/supervisor)
     589 *
     590 * @remark  Invalid opcode exceptions have a higher priority than GP (see Intel
     591 *          Architecture System Developers Manual, Vol 3, 5.5) so we don't need
     592 *          to worry about e.g. invalid modrm combinations (!)
     593 *
     594 * @todo    At this time we do NOT check if the instruction overwrites vital information.
     595 *          Make sure this can't happen!! (will add some assertions/checks later)
     596 */
     597VMMDECL(VBOXSTRICTRC) EMInterpretInstructionCpuUpdtPC(PVM pVM, PVMCPU pVCpu, PDISCPUSTATE pDis, PCPUMCTXCORE pRegFrame,
     598                                                      RTGCPTR pvFault, EMCODETYPE enmCodeType)
     599{
     600    STAM_PROFILE_START(&pVCpu->em.s.CTX_SUFF(pStats)->CTX_MID_Z(Stat,Emulate), a);
     601    uint32_t cbIgnored;
     602    VBOXSTRICTRC rc = emInterpretInstructionCPU(pVM, pVCpu, pDis, pRegFrame, pvFault, enmCodeType, &cbIgnored);
     603    STAM_PROFILE_STOP(&pVCpu->em.s.CTX_SUFF(pStats)->CTX_MID_Z(Stat,Emulate), a);
     604    if (RT_SUCCESS(rc))
     605    {
     606        pRegFrame->rip += pDis->opsize; /* Move on to the next instruction. */
     607        STAM_COUNTER_INC(&pVCpu->em.s.CTX_SUFF(pStats)->CTX_MID_Z(Stat,InterpretSucceeded));
     608    }
     609    else
     610        STAM_COUNTER_INC(&pVCpu->em.s.CTX_SUFF(pStats)->CTX_MID_Z(Stat,InterpretFailed));
     611    return rc;
     612}
    585613
    586614#ifndef VBOX_WITH_IEM
     615
     616
     617
     618
     619
     620
     621/*
     622 *
     623 * The old interpreter.
     624 * The old interpreter.
     625 * The old interpreter.
     626 * The old interpreter.
     627 * The old interpreter.
     628 *
     629 */
    587630
    588631DECLINLINE(int) emRamRead(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, void *pvDst, RTGCPTR GCPtrSrc, uint32_t cb)
  • trunk/src/VBox/VMM/VMMAll/PGMAllPool.cpp

    r39739 r40442  
    840840     * Must do this in raw mode (!); XP boot will fail otherwise.
    841841     */
    842     uint32_t cbWritten;
    843     VBOXSTRICTRC rc2 = EMInterpretInstructionCPU(pVM, pVCpu, pDis, pRegFrame, pvFault, EMCODETYPE_ALL, &cbWritten);
     842    VBOXSTRICTRC rc2 = EMInterpretInstructionCpuUpdtPC(pVM, pVCpu, pDis, pRegFrame, pvFault, EMCODETYPE_ALL);
    844843    if (RT_SUCCESS(rc2))
    845     {
    846         pRegFrame->rip += pDis->opsize;
    847844        AssertMsg(rc2 == VINF_SUCCESS, ("%Rrc\n", VBOXSTRICTRC_VAL(rc2))); /* ASSUMES no complicated stuff here. */
    848     }
    849845    else if (rc2 == VERR_EM_INTERPRETER)
    850846    {
     
    983979     * Interpret the instruction.
    984980     */
    985     uint32_t cb;
    986     VBOXSTRICTRC rc = EMInterpretInstructionCPU(pVM, pVCpu, pDis, pRegFrame, pvFault, EMCODETYPE_ALL, &cb);
     981    VBOXSTRICTRC rc = EMInterpretInstructionCpuUpdtPC(pVM, pVCpu, pDis, pRegFrame, pvFault, EMCODETYPE_ALL);
    987982    if (RT_SUCCESS(rc))
    988     {
    989         pRegFrame->rip += pDis->opsize;
    990983        AssertMsg(rc == VINF_SUCCESS, ("%Rrc\n", VBOXSTRICTRC_VAL(rc))); /* ASSUMES no complicated stuff here. */
    991     }
    992984    else if (rc == VERR_EM_INTERPRETER)
    993985    {
     
    10281020#endif
    10291021
    1030     LogFlow(("pgmPoolAccessHandlerSimple: returns %Rrc cb=%d\n", VBOXSTRICTRC_VAL(rc), cb));
     1022    LogFlow(("pgmPoolAccessHandlerSimple: returns %Rrc\n", VBOXSTRICTRC_VAL(rc)));
    10311023    return VBOXSTRICTRC_VAL(rc);
    10321024}
  • trunk/src/VBox/VMM/VMMR0/HWVMXR0.cpp

    r40424 r40442  
    31153115            {
    31163116                uint32_t     cbOp;
    3117                 uint32_t     cbSize;
    31183117                PDISCPUSTATE pDis = &pVCpu->hwaccm.s.DisState;
    31193118
     
    33363335
    33373336                    default:
    3338                         rc = EMInterpretInstructionCPU(pVM, pVCpu, pDis, CPUMCTX2CORE(pCtx), 0, EMCODETYPE_SUPERVISOR, &cbSize);
     3337                        rc = EMInterpretInstructionCpuUpdtPC(pVM, pVCpu, pDis, CPUMCTX2CORE(pCtx), 0, EMCODETYPE_SUPERVISOR);
     3338                        fUpdateRIP = false;
    33393339                        break;
    33403340                    }
  • trunk/src/VBox/VMM/VMMR3/EMRaw.cpp

    r40377 r40442  
    605605                AssertRC(rc);
    606606
    607                 uint32_t opsize;
    608                 rc = VBOXSTRICTRC_TODO(EMInterpretInstructionCPU(pVM, pVCpu, &cpu, CPUMCTX2CORE(pCtx), 0, EMCODETYPE_SUPERVISOR, &opsize));
     607                rc = VBOXSTRICTRC_TODO(EMInterpretInstructionCpuUpdtPC(pVM, pVCpu, &cpu, CPUMCTX2CORE(pCtx), 0, EMCODETYPE_SUPERVISOR));
    609608                if (RT_SUCCESS(rc))
    610                 {
    611                     pCtx->rip += cpu.opsize;
    612609                    return rc;
    613                 }
    614610                return emR3ExecuteInstruction(pVM, pVCpu, "Monitor: ");
    615611            }
     
    10471043            &&  SELMGetCpuModeFromSelector(pVM, pCtx->eflags, pCtx->cs, &pCtx->csHid) == CPUMODE_32BIT)
    10481044        {
    1049             uint32_t size;
    1050 
    10511045            STAM_PROFILE_START(&pVCpu->em.s.StatPrivEmu, a);
    10521046            switch (Cpu.pCurInstr->opcode)
     
    11001094#endif
    11011095
    1102                     rc = VBOXSTRICTRC_TODO(EMInterpretInstructionCPU(pVM, pVCpu, &Cpu, CPUMCTX2CORE(pCtx), 0, EMCODETYPE_SUPERVISOR, &size));
     1096                    rc = VBOXSTRICTRC_TODO(EMInterpretInstructionCpuUpdtPC(pVM, pVCpu, &Cpu, CPUMCTX2CORE(pCtx), 0, EMCODETYPE_SUPERVISOR));
    11031097                    if (RT_SUCCESS(rc))
    11041098                    {
    1105                         pCtx->rip += Cpu.opsize;
    11061099                        STAM_PROFILE_STOP(&pVCpu->em.s.StatPrivEmu, a);
    11071100
  • trunk/src/VBox/VMM/VMMR3/IOM.cpp

    r40280 r40442  
    3333 * disassembler (DIS) to figure which instruction caused it (there are a number
    3434 * of instructions in addition to the I/O ones) and if it's an I/O port access
    35  * it will hand it to IOMGCIOPortHandler (via EMInterpretPortIO).
    36  * IOMGCIOPortHandler will lookup the port in the AVL tree of registered
     35 * it will hand it to IOMRCIOPortHandler (via EMInterpretPortIO).
     36 * IOMRCIOPortHandler will lookup the port in the AVL tree of registered
    3737 * handlers. If found, the handler will be called otherwise default action is
    3838 * taken. (Default action is to write into the void and read all set bits.)
  • trunk/src/VBox/VMM/VMMRC/IOMRC.cpp

    r40280 r40442  
    11/* $Id$ */
    22/** @file
    3  * IOM - Input / Output Monitor - Guest Context.
     3 * IOM - Input / Output Monitor - Raw-Mode Context.
    44 */
    55
    66/*
    7  * Copyright (C) 2006-2007 Oracle Corporation
     7 * Copyright (C) 2006-2012 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4646 * Attempts to service an IN/OUT instruction.
    4747 *
    48  * The \#GP trap handler in GC will call this function if the opcode causing the
    49  * trap is a in or out type instruction. (Call it indirectly via EM that is.)
     48 * The \#GP trap handler in RC will call this function if the opcode causing
     49 * the trap is a in or out type instruction. (Call it indirectly via EM that
     50 * is.)
    5051 *
    5152 * @returns Strict VBox status code. Informational status codes other than the one documented
     
    5657 * @retval  VINF_EM_RESCHEDULE_REM      The exception was dispatched and cannot be executed in raw-mode. (TRPMRaiseXcptErr)
    5758 * @retval  VINF_EM_RAW_EMULATE_INSTR   Defer the read to the REM.
    58  * @retval  VINF_IOM_R3_IOPORT_READ     Defer the read to ring-3. (R0/GC only)
     59 * @retval  VINF_IOM_R3_IOPORT_READ     Defer the read to ring-3.
    5960 * @retval  VINF_EM_RAW_GUEST_TRAP      The exception was left pending. (TRPMRaiseXcptErr)
    6061 * @retval  VINF_TRPM_XCPT_DISPATCHED   The exception was raised and dispatched for raw-mode execution. (TRPMRaiseXcptErr)
    6162 *
    62  * @param   pVM         The virtual machine (GC pointer of course).
     63 * @param   pVM         The virtual machine handle.
    6364 * @param   pRegFrame   Pointer to CPUMCTXCORE guest registers structure.
    6465 * @param   pCpu        Disassembler CPU state.
    6566 */
    66 VMMRCDECL(VBOXSTRICTRC) IOMGCIOPortHandler(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu)
     67VMMRCDECL(VBOXSTRICTRC) IOMRCIOPortHandler(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu)
    6768{
    6869    switch (pCpu->pCurInstr->opcode)
  • trunk/src/VBox/VMM/VMMRC/PATMRC.cpp

    r39078 r40442  
    477477        if (pRec->patch.flags & PATMFL_INT3_REPLACEMENT)
    478478        {
    479             uint32_t    size, cbOp;
     479            uint32_t    cbOp;
    480480            DISCPUSTATE cpu;
    481481
     
    523523            }
    524524
    525             rc = EMInterpretInstructionCPU(pVM, VMMGetCpu0(pVM), &cpu, pRegFrame, 0 /* not relevant here */,
    526                                            EMCODETYPE_SUPERVISOR, &size);
     525            rc = EMInterpretInstructionCpuUpdtPC(pVM, VMMGetCpu0(pVM), &cpu, pRegFrame, 0 /* not relevant here */,
     526                                                 EMCODETYPE_SUPERVISOR);
    527527            if (rc != VINF_SUCCESS)
    528528            {
     
    532532                return VINF_EM_RAW_EMULATE_INSTR;
    533533            }
    534 
    535             pRegFrame->eip += cpu.opsize;
    536534            return VINF_SUCCESS;
    537535        }
  • trunk/src/VBox/VMM/VMMRC/TRPMRCHandlers.cpp

    r40280 r40442  
    556556        {
    557557            LogFlow(("TRPMGCTrap06Handler: -> EMInterpretInstructionCPU\n"));
    558             uint32_t cbIgnored;
    559             rc = EMInterpretInstructionCPU(pVM, pVCpu, &Cpu, pRegFrame, PC, EMCODETYPE_SUPERVISOR, &cbIgnored);
    560             if (RT_SUCCESS(rc))
    561                 pRegFrame->eip += Cpu.opsize;
     558            rc = EMInterpretInstructionCpuUpdtPC(pVM, pVCpu, &Cpu, pRegFrame, PC, EMCODETYPE_SUPERVISOR);
    562559        }
    563560        /* Never generate a raw trap here; it might be an instruction, that requires emulation. */
     
    801798        case OP_WRMSR:
    802799        {
    803             uint32_t cbIgnored;
    804             rc = EMInterpretInstructionCPU(pVM, pVCpu, pCpu, pRegFrame, PC, EMCODETYPE_SUPERVISOR, &cbIgnored);
    805             if (RT_SUCCESS(rc))
    806                 pRegFrame->eip += pCpu->opsize;
    807             else if (rc == VERR_EM_INTERPRETER)
     800            rc = EMInterpretInstructionCpuUpdtPC(pVM, pVCpu, pCpu, pRegFrame, PC, EMCODETYPE_SUPERVISOR);
     801            if (rc == VERR_EM_INTERPRETER)
    808802                rc = VINF_EM_RAW_EXCEPTION_PRIVILEGED;
    809803            return trpmGCExitTrap(pVM, pVCpu, rc, pRegFrame);
     
    880874        case OP_RDPMC:
    881875        {
    882             uint32_t cbIgnored;
    883             rc = EMInterpretInstructionCPU(pVM, pVCpu, pCpu, pRegFrame, PC, EMCODETYPE_SUPERVISOR, &cbIgnored);
    884             if (RT_SUCCESS(rc))
    885                 pRegFrame->eip += pCpu->opsize;
    886             else if (rc == VERR_EM_INTERPRETER)
     876            rc = EMInterpretInstructionCpuUpdtPC(pVM, pVCpu, pCpu, pRegFrame, PC, EMCODETYPE_SUPERVISOR);
     877            if (rc == VERR_EM_INTERPRETER)
    887878                rc = VINF_EM_RAW_EXCEPTION_PRIVILEGED;
    888879            return trpmGCExitTrap(pVM, pVCpu, rc, pRegFrame);
     
    1000991        &&  (Cpu.pCurInstr->optype & OPTYPE_PORTIO))
    1001992    {
    1002         VBOXSTRICTRC rcStrict = EMInterpretPortIO(pVM, pVCpu, pRegFrame, &Cpu, cbOp);
    1003         rc = VBOXSTRICTRC_TODO(rcStrict);
     993        VBOXSTRICTRC rcStrict = IOMRCIOPortHandler(pVM, pRegFrame, &Cpu);
     994        if (IOM_SUCCESS(rcStrict))
     995            pRegFrame->rip += cbOp;
    1004996        return trpmGCExitTrap(pVM, pVCpu, rc, pRegFrame);
    1005997    }
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