VirtualBox

Changeset 18770 in vbox for trunk/src


Ignore:
Timestamp:
Apr 6, 2009 3:00:15 PM (16 years ago)
Author:
vboxsync
Message:

Fake rdpmc instead of causing an invalid opcode exception.

Location:
trunk/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/EM.cpp

    r18655 r18770  
    210210    STAM_REG_USED(pVM, &pStats->StatRZRdtsc,                STAMTYPE_COUNTER, "/EM/RZ/Interpret/Success/Rdtsc",     STAMUNIT_OCCURENCES,    "The number of times RDTSC was successfully interpreted.");
    211211    STAM_REG_USED(pVM, &pStats->StatR3Rdtsc,                STAMTYPE_COUNTER, "/EM/R3/Interpret/Success/Rdtsc",     STAMUNIT_OCCURENCES,    "The number of times RDTSC was successfully interpreted.");
     212    STAM_REG_USED(pVM, &pStats->StatRZRdpmc,                STAMTYPE_COUNTER, "/EM/RZ/Interpret/Success/Rdpmc",     STAMUNIT_OCCURENCES,    "The number of times RDPMC was successfully interpreted.");
     213    STAM_REG_USED(pVM, &pStats->StatR3Rdpmc,                STAMTYPE_COUNTER, "/EM/R3/Interpret/Success/Rdpmc",     STAMUNIT_OCCURENCES,    "The number of times RDPMC was successfully interpreted.");
    212214    STAM_REG_USED(pVM, &pStats->StatRZSti,                  STAMTYPE_COUNTER, "/EM/RZ/Interpret/Success/Sti",       STAMUNIT_OCCURENCES,    "The number of times STI was successfully interpreted.");
    213215    STAM_REG_USED(pVM, &pStats->StatR3Sti,                  STAMTYPE_COUNTER, "/EM/R3/Interpret/Success/Sti",       STAMUNIT_OCCURENCES,    "The number of times STI was successfully interpreted.");
     
    288290    STAM_REG_USED(pVM, &pStats->StatRZFailedRdtsc,          STAMTYPE_COUNTER, "/EM/RZ/Interpret/Failed/Rdtsc",      STAMUNIT_OCCURENCES,    "The number of times RDTSC was not interpreted.");
    289291    STAM_REG_USED(pVM, &pStats->StatR3FailedRdtsc,          STAMTYPE_COUNTER, "/EM/R3/Interpret/Failed/Rdtsc",      STAMUNIT_OCCURENCES,    "The number of times RDTSC was not interpreted.");
     292    STAM_REG_USED(pVM, &pStats->StatRZFailedRdpmc,          STAMTYPE_COUNTER, "/EM/RZ/Interpret/Failed/Rdpmc",      STAMUNIT_OCCURENCES,    "The number of times RDPMC was not interpreted.");
     293    STAM_REG_USED(pVM, &pStats->StatR3FailedRdpmc,          STAMTYPE_COUNTER, "/EM/R3/Interpret/Failed/Rdpmc",      STAMUNIT_OCCURENCES,    "The number of times RDPMC was not interpreted.");
    290294    STAM_REG_USED(pVM, &pStats->StatRZFailedRdmsr,          STAMTYPE_COUNTER, "/EM/RZ/Interpret/Failed/Rdmsr",      STAMUNIT_OCCURENCES,    "The number of times RDMSR was not interpreted.");
    291295    STAM_REG_USED(pVM, &pStats->StatR3FailedRdmsr,          STAMTYPE_COUNTER, "/EM/R3/Interpret/Failed/Rdmsr",      STAMUNIT_OCCURENCES,    "The number of times RDMSR was not interpreted.");
  • trunk/src/VBox/VMM/EMInternal.h

    r15633 r18770  
    124124    STAMCOUNTER             StatRZRdtsc;
    125125    STAMCOUNTER             StatR3Rdtsc;
     126    STAMCOUNTER             StatRZRdpmc;
     127    STAMCOUNTER             StatR3Rdpmc;
    126128    STAMCOUNTER             StatRZBtr;
    127129    STAMCOUNTER             StatR3Btr;
     
    233235    STAMCOUNTER             StatRZFailedRdtsc;
    234236    STAMCOUNTER             StatR3FailedRdtsc;
     237    STAMCOUNTER             StatRZFailedRdpmc;
     238    STAMCOUNTER             StatR3FailedRdpmc;
    235239    STAMCOUNTER             StatRZFailedClts;
    236240    STAMCOUNTER             StatR3FailedClts;
  • trunk/src/VBox/VMM/HWACCM.cpp

    r18284 r18770  
    307307        HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitCpuid,              "/HWACCM/CPU%d/Exit/Instr/Cpuid");
    308308        HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitRdtsc,              "/HWACCM/CPU%d/Exit/Instr/Rdtsc");
     309        HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitRdpmc,              "/HWACCM/CPU%d/Exit/Instr/Rdpmc");
    309310        HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitDRxWrite,           "/HWACCM/CPU%d/Exit/Instr/DR/Write");
    310311        HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitDRxRead,            "/HWACCM/CPU%d/Exit/Instr/DR/Read");
  • trunk/src/VBox/VMM/HWACCMInternal.h

    r17909 r18770  
    600600    STAMCOUNTER             StatExitCpuid;
    601601    STAMCOUNTER             StatExitRdtsc;
     602    STAMCOUNTER             StatExitRdpmc;
    602603    STAMCOUNTER             StatExitCli;
    603604    STAMCOUNTER             StatExitSti;
  • trunk/src/VBox/VMM/VMMAll/EMAll.cpp

    r18764 r18770  
    25592559}
    25602560
     2561/**
     2562 * Interpret RDPMC
     2563 *
     2564 * @returns VBox status code.
     2565 * @param   pVM         The VM handle.
     2566 * @param   pRegFrame   The register frame.
     2567 *
     2568 */
     2569VMMDECL(int) EMInterpretRdpmc(PVM pVM, PCPUMCTXCORE pRegFrame)
     2570{
     2571    unsigned uCR4 = CPUMGetGuestCR4(pVM);
     2572
     2573    /* If X86_CR4_PCE is not set, then CPL must be zero. */
     2574    if (    !(uCR4 & X86_CR4_PCE)
     2575        ||  CPUMGetGuestCPL(pVM, pRegFrame) != 0)
     2576    {
     2577        Assert(CPUMGetGuestCR0(pVM) & X86_CR0_PE);
     2578        return VERR_EM_INTERPRETER; /* genuine #GP */
     2579    }
     2580
     2581    /* Just return zero here; rather tricky to properly emulate this, especially as the specs are a mess. */
     2582    pRegFrame->rax = 0;
     2583    pRegFrame->rdx = 0;
     2584    /* @todo We should trigger a #GP here if the cpu doesn't support the index in ecx. */
     2585    return VINF_SUCCESS;
     2586}
     2587
     2588/**
     2589 * RDPMC Emulation
     2590 */
     2591static int emInterpretRdpmc(PVM pVM, PDISCPUSTATE pCpu, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, uint32_t *pcbSize)
     2592{
     2593    return EMInterpretRdpmc(pVM, pRegFrame);
     2594}
    25612595
    25622596/**
     
    31883222        INTERPRET_CASE_EX_PARAM2(OP_BTS,Bts, BitTest, EMEmulateBts);
    31893223        INTERPRET_CASE_EX_PARAM2(OP_BTC,Btc, BitTest, EMEmulateBtc);
     3224        INTERPRET_CASE(OP_RDPMC,Rdpmc);
    31903225        INTERPRET_CASE(OP_RDTSC,Rdtsc);
    31913226        INTERPRET_CASE(OP_CMPXCHG, CmpXchg);
  • trunk/src/VBox/VMM/VMMGC/TRPMGCHandlers.cpp

    r18723 r18770  
    653653        case OP_STI:
    654654        case OP_RDTSC:  /* just in case */
     655        case OP_RDPMC:
    655656        case OP_CLTS:
    656657        case OP_WBINVD: /* nop */
     
    732733
    733734        /*
    734          * Handle virtualized TSC reads, just in case.
     735         * Handle virtualized TSC & PMC reads, just in case.
    735736         */
    736737        case OP_RDTSC:
     738        case OP_RDPMC:
    737739        {
    738740            uint32_t cbIgnored;
  • trunk/src/VBox/VMM/VMMR0/HWSVMR0.cpp

    r18617 r18770  
    16391639    }
    16401640
     1641    case SVM_EXIT_RDPMC:                /* Guest software attempted to execute RDPMC. */
     1642    {
     1643        Log2(("SVM: Rdpmc %x\n", pCtx->ecx));
     1644        STAM_COUNTER_INC(&pVCpu->hwaccm.s.StatExitRdpmc);
     1645        rc = EMInterpretRdpmc(pVM, CPUMCTX2CORE(pCtx));
     1646        if (rc == VINF_SUCCESS)
     1647        {
     1648            /* Update EIP and continue execution. */
     1649            pCtx->rip += 2;             /* Note! hardcoded opcode size! */
     1650            goto ResumeExecution;
     1651        }
     1652        AssertMsgFailed(("EMU: rdpmc failed with %Rrc\n", rc));
     1653        rc = VINF_EM_RAW_EMULATE_INSTR;
     1654        break;
     1655    }
     1656
    16411657    case SVM_EXIT_RDTSCP:                /* Guest software attempted to execute RDTSCP. */
    16421658    {
     
    20482064
    20492065    case SVM_EXIT_MONITOR:
    2050     case SVM_EXIT_RDPMC:
    20512066    case SVM_EXIT_PAUSE:
    20522067    case SVM_EXIT_MWAIT_UNCOND:
  • trunk/src/VBox/VMM/VMMR0/HWVMXR0.cpp

    r18666 r18770  
    29212921    }
    29222922
     2923    case VMX_EXIT_RDPMC:                /* 15 Guest software attempted to execute RDPMC. */
     2924    {
     2925        Log2(("VMX: Rdpmc %x\n", pCtx->ecx));
     2926        STAM_COUNTER_INC(&pVCpu->hwaccm.s.StatExitRdpmc);
     2927        rc = EMInterpretRdpmc(pVM, CPUMCTX2CORE(pCtx));
     2928        if (rc == VINF_SUCCESS)
     2929        {
     2930            /* Update EIP and continue execution. */
     2931            Assert(cbInstr == 2);
     2932            pCtx->rip += cbInstr;
     2933            goto ResumeExecution;
     2934        }
     2935        AssertMsgFailed(("EMU: rdpmc failed with %Rrc\n", rc));
     2936        rc = VINF_EM_RAW_EMULATE_INSTR;
     2937        break;
     2938    }
     2939
    29232940    case VMX_EXIT_RDTSC:                /* 16 Guest software attempted to execute RDTSC. */
    29242941    {
     
    33613378    case VMX_EXIT_DRX_MOVE:             /* 29 Debug-register accesses. */
    33623379    case VMX_EXIT_PORT_IO:              /* 30 I/O instruction. */
     3380    case VMX_EXIT_RDPMC:                /* 15 Guest software attempted to execute RDPMC. */
    33633381        /* already handled above */
    33643382        AssertMsg(   rc == VINF_PGM_CHANGE_MODE
     
    33823400        break;
    33833401
    3384     case VMX_EXIT_RDPMC:                /* 15 Guest software attempted to execute RDPMC. */
    33853402    case VMX_EXIT_MWAIT:                /* 36 Guest software executed MWAIT. */
    33863403    case VMX_EXIT_MONITOR:              /* 39 Guest software attempted to execute MONITOR. */
  • trunk/src/recompiler_new/target-i386/op_helper.c

    r18475 r18770  
    37003700void helper_rdpmc(void)
    37013701{
     3702#ifdef VBOX
     3703    /* If X86_CR4_PCE is *not* set, then CPL must be zero. */
     3704    if (!(env->cr[4] & CR4_PCE_MASK) && ((env->hflags & HF_CPL_MASK) != 0)) {
     3705        raise_exception(EXCP0D_GPF);
     3706    }
     3707    /* Just return zero here; rather tricky to properly emulate this, especially as the specs are a mess. */
     3708    EAX = 0;
     3709    EDX = 0;
     3710#else
    37023711    if ((env->cr[4] & CR4_PCE_MASK) && ((env->hflags & HF_CPL_MASK) != 0)) {
    37033712        raise_exception(EXCP0D_GPF);
     
    37073716    /* currently unimplemented */
    37083717    raise_exception_err(EXCP06_ILLOP, 0);
     3718#endif
    37093719}
    37103720
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