VirtualBox

Changeset 2892 in vbox


Ignore:
Timestamp:
May 28, 2007 12:52:11 PM (18 years ago)
Author:
vboxsync
Message:

Preliminary code for real mode and protected mode without paging.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR0/HWVMXR0.cpp

    r2818 r2892  
    594594    {
    595595        rc =  VMXWriteVMCS(VMX_VMCS_GUEST_FIELD_TR,         pCtx->tr);
     596
     597        /* Real mode emulation using v86 mode with CR4.VME (interrupt redirection using the int bitmap in the TSS) */
     598        /* @todo use fake TSS here */
     599        //if (!(pCtx->cr0 & X86_CR0_PROTECTION_ENABLE))
     600
    596601        rc |= VMXWriteVMCS(VMX_VMCS_GUEST_TR_LIMIT,         pCtx->trHid.u32Limit);
    597602        rc |= VMXWriteVMCS(VMX_VMCS_GUEST_TR_BASE,          pCtx->trHid.u32Base);
     
    599604
    600605        /* The TSS selector must be busy. */
    601         if ((val & 0xF) == X86_SEL_TYPE_SYS_386_TSS_AVAIL)
    602             val = (val & ~0xF) | X86_SEL_TYPE_SYS_386_TSS_BUSY;
    603         else
    604606        if ((val & 0xF) == X86_SEL_TYPE_SYS_286_TSS_AVAIL)
    605607            val = (val & ~0xF) | X86_SEL_TYPE_SYS_286_TSS_BUSY;
     608        else
     609            /* Default even if no TR selector has been set (otherwise vmlaunch will fail!) */
     610            val = (val & ~0xF) | X86_SEL_TYPE_SYS_386_TSS_BUSY;
    606611
    607612        rc |= VMXWriteVMCS(VMX_VMCS_GUEST_TR_ACCESS_RIGHTS, val);
     
    664669            val |= X86_CR0_NE;  /* always turn on the native mechanism to report FPU errors (old style uses interrupts) */
    665670        }
     671        /* Note: protected mode & paging are always enabled; we use them for emulating real and protected mode without paging too. */
     672        val |= X86_CR0_PE | X86_CR0_PG;
     673
    666674        rc |= VMXWriteVMCS(VMX_VMCS_GUEST_CR0,              val);
    667675        Log2(("Guest CR0 %08x\n", val));
     
    669677         * the VM will exit.
    670678         */
    671         val =   X86_CR0_PE
     679        val =   X86_CR0_PE  /* Must monitor this bit (assumptions are made for real mode emulation) */
    672680              | X86_CR0_WP  /** @todo do we care? (we do if we start patching the guest) */
    673               | X86_CR0_PG
     681              | X86_CR0_PG  /* Must monitor this bit (assumptions are made for real mode & protected mode without paging emulation) */
    674682              | X86_CR0_TS
    675683              | X86_CR0_ET
     
    691699        switch(pVM->hwaccm.s.enmShadowMode)
    692700        {
    693         case PGMMODE_REAL:
    694         case PGMMODE_PROTECTED:     /* Protected mode, no paging. */
    695             AssertFailed();
    696             return VERR_PGM_UNSUPPORTED_HOST_PAGING_MODE;
    697 
     701        case PGMMODE_REAL:          /* Real mode                 -> emulated using v86 mode */
     702        case PGMMODE_PROTECTED:     /* Protected mode, no paging -> emulated using identity mapping. */
    698703        case PGMMODE_32_BIT:        /* 32-bit paging. */
    699704            break;
     
    714719            return VERR_PGM_UNSUPPORTED_HOST_PAGING_MODE;
    715720        }
     721        /* Real mode emulation using v86 mode with CR4.VME (interrupt redirection using the int bitmap in the TSS) */
     722        if (!(pCtx->cr0 & X86_CR0_PROTECTION_ENABLE))
     723            val |= X86_CR4_VME;
     724
    716725        rc |= VMXWriteVMCS(VMX_VMCS_GUEST_CR4,              val);
    717726        Log2(("Guest CR4 %08x\n", val));
     
    770779    val &= VMX_EFLAGS_RESERVED_0;
    771780    val |= VMX_EFLAGS_RESERVED_1;
     781
     782    /* Real mode emulation using v86 mode with CR4.VME (interrupt redirection using the int bitmap in the TSS) */
     783    if (!(pCtx->cr0 & X86_CR0_PROTECTION_ENABLE))
     784    {
     785        val |= X86_EFL_VM;
     786        if (pCtx->eflags.Bits.u1IF)
     787            val |= X86_EFL_VIF;
     788        else
     789            val &= ~X86_EFL_VIF;
     790    }
     791
    772792    rc   = VMXWriteVMCS(VMX_VMCS_GUEST_RFLAGS,           val);
    773793    AssertRC(rc);
     
    11851205    pCtx->eflags.u32        = val;
    11861206
     1207    /* Real mode emulation using v86 mode with CR4.VME (interrupt redirection using the int bitmap in the TSS) */
     1208    if (!(pCtx->cr0 & X86_CR0_PROTECTION_ENABLE))
     1209    {
     1210        /* Hide our emulation flags */
     1211        pCtx->eflags.Bits.u1VM  = 0;
     1212        pCtx->eflags.Bits.u1IF  = pCtx->eflags.Bits.u1VIF;
     1213        pCtx->eflags.Bits.u1VIF = 0;
     1214    }
     1215
    11871216    /* Control registers. */
    11881217    VMXReadVMCS(VMX_VMCS_CTRL_CR0_READ_SHADOW,   &valShadow);
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