VirtualBox

Changeset 13343

Show
Ignore:
Timestamp:
10/16/08 17:01:44 (3 months ago)
Author:
vboxsync
Message:

VT-x real mode emulation: got rid of all the ugly hacks and just fall back to the recompiler if VT-x can't handle the current CPU state

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/VBox/hwaccm.h

    r13221 r13343  
    110110VMMR3DECL(bool) HWACCMR3IsNestedPagingActive(PVM pVM); 
    111111VMMR3DECL(bool) HWACCMR3IsAllowed(PVM pVM); 
    112 VMMR3DECL(void) HWACCMR3PagingModeChanged(PVM pVM, PGMMODE enmShadowMode); 
     112VMMR3DECL(void) HWACCMR3PagingModeChanged(PVM pVM, PGMMODE enmShadowMode, PGMMODE enmGuestMode); 
    113113VMMR3DECL(bool) HWACCMR3IsVPIDActive(PVM pVM); 
    114114 
  • trunk/src/VBox/VMM/EM.cpp

    r13265 r13343  
    779779        Log(("EMV86: %04X:%08X IF=%d\n", pCtx->cs, pCtx->eip, pCtx->eflags.Bits.u1IF)); 
    780780    else 
    781         Log(("EMR%d: %08X ESP=%08X IF=%d CR0=%x\n", cpl, pCtx->eip, pCtx->esp, pCtx->eflags.Bits.u1IF, (uint32_t)pCtx->cr0)); 
     781        Log(("EMR%d: %04X:%08X ESP=%08X IF=%d CR0=%x\n", cpl, pCtx->cs, pCtx->eip, pCtx->esp, pCtx->eflags.Bits.u1IF, (uint32_t)pCtx->cr0)); 
    782782#endif 
    783783    STAM_REL_PROFILE_ADV_START(&pVM->em.s.StatREMTotal, a); 
  • trunk/src/VBox/VMM/HWACCM.cpp

    r13276 r13343  
    783783 * 
    784784 * @param   pVM            The VM to operate on. 
    785  * @param   enmShadowMode  New paging mode. 
    786  */ 
    787 VMMR3DECL(void) HWACCMR3PagingModeChanged(PVM pVM, PGMMODE enmShadowMode) 
     785 * @param   enmShadowMode  New shadow paging mode. 
     786 * @param   enmGuestMode   New guest paging mode. 
     787 */ 
     788VMMR3DECL(void) HWACCMR3PagingModeChanged(PVM pVM, PGMMODE enmShadowMode, PGMMODE enmGuestMode) 
    788789{ 
    789790    pVM->hwaccm.s.enmShadowMode = enmShadowMode; 
     791    if (   pVM->hwaccm.s.vmx.fEnabled 
     792        && pVM->fHWACCMEnabled) 
     793    { 
     794        if (    pVM->hwaccm.s.vmx.enmCurrGuestMode == PGMMODE_REAL 
     795            &&  enmGuestMode >= PGMMODE_PROTECTED) 
     796        { 
     797            PCPUMCTX pCtx; 
     798 
     799            CPUMQueryGuestCtxPtr(pVM, &pCtx); 
     800 
     801            /* After a real mode switch to protected mode we must force 
     802             * CPL to 0. Our real mode emulation had to set it to 3. 
     803             */ 
     804            pCtx->ssHid.Attr.n.u2Dpl  = 0; 
     805        } 
     806    } 
    790807} 
    791808 
     
    874891            ||  pCtx->gsHid.u64Base > 0xfffff) 
    875892            return false; 
     893 
     894        if (   (   pCtx->cs != (pCtx->csHid.u64Base >> 4) 
     895                && pCtx->csHid.u64Base != 0xffff0000 /* we can deal with the BIOS code as it's also mapped into the lower region. */) 
     896            || pCtx->ds != (pCtx->dsHid.u64Base >> 4) 
     897            || pCtx->es != (pCtx->esHid.u64Base >> 4) 
     898            || pCtx->fs != (pCtx->fsHid.u64Base >> 4) 
     899            || pCtx->gs != (pCtx->gsHid.u64Base >> 4) 
     900            || pCtx->ss != (pCtx->ssHid.u64Base >> 4)) 
     901            return false; 
     902    } 
     903    else 
     904    { 
     905        PGMMODE enmGuestMode = PGMGetGuestMode(pVM); 
     906        /* Correct weird requirements for switching to protected mode. */ 
     907        if (    pVM->hwaccm.s.vmx.enmCurrGuestMode == PGMMODE_REAL 
     908            &&  enmGuestMode >= PGMMODE_PROTECTED) 
     909        { 
     910            if (   (pCtx->cs & X86_SEL_RPL) 
     911                || (pCtx->ds & X86_SEL_RPL) 
     912                || (pCtx->es & X86_SEL_RPL) 
     913                || (pCtx->fs & X86_SEL_RPL) 
     914                || (pCtx->gs & X86_SEL_RPL) 
     915                || (pCtx->ss & X86_SEL_RPL)) 
     916                return false; 
     917        } 
    876918    } 
    877919#else 
  • trunk/src/VBox/VMM/HWACCMInternal.h

    r13276 r13343  
    340340        struct 
    341341        { 
    342             CPUMSELREGHID               dsHid; 
    343             CPUMSELREGHID               esHid; 
    344             CPUMSELREGHID               fsHid; 
    345             CPUMSELREGHID               gsHid; 
    346             CPUMSELREGHID               ssHid; 
    347             RTSEL                       ds; 
    348             RTSEL                       es; 
    349             RTSEL                       fs; 
    350             RTSEL                       gs; 
    351             RTSEL                       ss; 
    352             RTSEL                       padding5[1]; 
    353342            X86EFLAGS                   eflags; 
    354343            uint32_t                    fValid; 
  • trunk/src/VBox/VMM/PGM.cpp

    r13235 r13343  
    34503450 
    34513451    /* Notify HWACCM as well. */ 
    3452     HWACCMR3PagingModeChanged(pVM, pVM->pgm.s.enmShadowMode); 
     3452    HWACCMR3PagingModeChanged(pVM, pVM->pgm.s.enmShadowMode, pVM->pgm.s.enmGuestMode); 
    34533453    return rc; 
    34543454} 
  • trunk/src/VBox/VMM/VMMR0/HWVMXR0.cpp

    r13289 r13343  
    954954        if (pVM->hwaccm.s.vmx.enmCurrGuestMode != enmGuestMode) 
    955955        { 
    956 # define VTX_CORRECT_PROT_SEL(reg) \ 
    957             {                                                                                               \ 
    958                 if (    pCtx->reg##Hid.u64Base == (pVM->hwaccm.s.vmx.RealMode.reg##Hid.u64Base & 0xfffff)   \ 
    959                     &&  pCtx->reg == ((pVM->hwaccm.s.vmx.RealMode.reg##Hid.u64Base >> 4) & ~X86_SEL_RPL))   \ 
    960                 {                                                                                           \ 
    961                     pCtx->reg##Hid = pVM->hwaccm.s.vmx.RealMode.reg##Hid;                                   \ 
    962                     pCtx->reg      = pVM->hwaccm.s.vmx.RealMode.reg;                                        \ 
    963                 }                                                                                           \ 
    964             } 
    965  
    966956            /* Correct weird requirements for switching to protected mode. */ 
    967957            if (    pVM->hwaccm.s.vmx.enmCurrGuestMode == PGMMODE_REAL 
     
    977967                pCtx->gsHid.Attr.n.u2Dpl  = 0; 
    978968                pCtx->ssHid.Attr.n.u2Dpl  = 0; 
    979  
    980                 /* RPL of all selectors must match the current CPL (0). */ 
    981                 pCtx->cs &= ~X86_SEL_RPL; 
    982                 pCtx->ds &= ~X86_SEL_RPL; 
    983                 pCtx->es &= ~X86_SEL_RPL; 
    984                 pCtx->fs &= ~X86_SEL_RPL; 
    985                 pCtx->gs &= ~X86_SEL_RPL; 
    986                 pCtx->ss &= ~X86_SEL_RPL; 
    987  
    988                 if (pVM->hwaccm.s.vmx.RealMode.fValid) 
    989                 { 
    990                     VTX_CORRECT_PROT_SEL(ds); 
    991                     VTX_CORRECT_PROT_SEL(es); 
    992                     VTX_CORRECT_PROT_SEL(fs); 
    993                     VTX_CORRECT_PROT_SEL(gs); 
    994                     pVM->hwaccm.s.vmx.RealMode.fValid = false; 
    995                 } 
    996969            } 
    997970            else 
     
    1000973                &&  enmGuestMode == PGMMODE_REAL) 
    1001974            { 
    1002                 /* Save the original hidden selectors in case we need to restore them later on. */ 
    1003                 pVM->hwaccm.s.vmx.RealMode.ds     = pCtx->ds; 
    1004                 pVM->hwaccm.s.vmx.RealMode.dsHid  = pCtx->dsHid; 
    1005                 pVM->hwaccm.s.vmx.RealMode.es     = pCtx->es; 
    1006                 pVM->hwaccm.s.vmx.RealMode.esHid  = pCtx->esHid; 
    1007                 pVM->hwaccm.s.vmx.RealMode.fs     = pCtx->fs; 
    1008                 pVM->hwaccm.s.vmx.RealMode.fsHid  = pCtx->fsHid; 
    1009                 pVM->hwaccm.s.vmx.RealMode.gs     = pCtx->gs; 
    1010                 pVM->hwaccm.s.vmx.RealMode.gsHid  = pCtx->gsHid; 
    1011                 pVM->hwaccm.s.vmx.RealMode.ss     = pCtx->ss; 
    1012                 pVM->hwaccm.s.vmx.RealMode.ssHid  = pCtx->ssHid; 
    1013                 pVM->hwaccm.s.vmx.RealMode.fValid = true; 
    1014  
    1015                 /* The selector value & base must be adjusted or else... */ 
    1016                 pCtx->cs = pCtx->csHid.u64Base >> 4; 
    1017                 pCtx->ds = pCtx->dsHid.u64Base >> 4; 
    1018                 pCtx->es = pCtx->esHid.u64Base >> 4; 
    1019                 pCtx->fs = pCtx->fsHid.u64Base >> 4; 
    1020                 pCtx->gs = pCtx->gsHid.u64Base >> 4; 
    1021                 pCtx->ss = pCtx->ssHid.u64Base >> 4; 
    1022  
    1023975                /* The limit must also be adjusted. */ 
    1024976                pCtx->csHid.u32Limit &= 0xffff; 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy