VirtualBox

Changeset 1359 in vbox for trunk


Ignore:
Timestamp:
Mar 9, 2007 10:40:44 AM (18 years ago)
Author:
vboxsync
Message:

SELM function changes for v86 mode code.
CPL check fixes for V86 mode code.

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

Legend:

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

    r1336 r1359  
    16451645            if (pCtx->SysEnter.cs != 0)
    16461646            {
    1647                 rc = PATMR3InstallPatch(pVM, SELMToFlat(pVM, pCtx->cs, &pCtx->csHid, pCtx->eip),
    1648                                         SELMIsSelector32Bit(pVM, pCtx->cs, &pCtx->csHid) ? PATMFL_CODE32 : 0);
     1647                rc = PATMR3InstallPatch(pVM, SELMToFlat(pVM, pCtx->eflags, pCtx->cs, &pCtx->csHid, pCtx->eip),
     1648                                        SELMIsSelector32Bit(pVM, pCtx->eflags, pCtx->cs, &pCtx->csHid) ? PATMFL_CODE32 : 0);
    16491649                if (VBOX_SUCCESS(rc))
    16501650                {
     
    18521852            && !PATMIsPatchGCAddr(pVM, pCtx->eip))
    18531853        {
    1854             int rc = PATMR3InstallPatch(pVM, SELMToFlat(pVM, pCtx->cs, &pCtx->csHid, pCtx->eip),
    1855                                         SELMIsSelector32Bit(pVM, pCtx->cs, &pCtx->csHid) ? PATMFL_CODE32 : 0);
     1854            int rc = PATMR3InstallPatch(pVM, SELMToFlat(pVM, pCtx->eflags, pCtx->cs, &pCtx->csHid, pCtx->eip),
     1855                                        SELMIsSelector32Bit(pVM, pCtx->eflags, pCtx->cs, &pCtx->csHid) ? PATMFL_CODE32 : 0);
    18561856            if (VBOX_SUCCESS(rc))
    18571857            {
     
    19601960        if (    (pCtx->ss & X86_SEL_RPL) == 0
    19611961            &&  !pCtx->eflags.Bits.u1VM
    1962             &&  SELMIsSelector32Bit(pVM, pCtx->cs, &pCtx->csHid))
     1962            &&  SELMIsSelector32Bit(pVM, pCtx->eflags, pCtx->cs, &pCtx->csHid))
    19631963        {
    19641964            uint32_t size;
     
    21822182         */
    21832183        case VINF_PATM_HC_MMIO_PATCH_READ:
    2184             rc = PATMR3InstallPatch(pVM, SELMToFlat(pVM, pCtx->cs, &pCtx->csHid, pCtx->eip),
    2185                                     PATMFL_MMIO_ACCESS | (SELMIsSelector32Bit(pVM, pCtx->cs, &pCtx->csHid) ? PATMFL_CODE32 : 0));
     2184            rc = PATMR3InstallPatch(pVM, SELMToFlat(pVM, pCtx->eflags, pCtx->cs, &pCtx->csHid, pCtx->eip),
     2185                                    PATMFL_MMIO_ACCESS | (SELMIsSelector32Bit(pVM, pCtx->eflags, pCtx->cs, &pCtx->csHid) ? PATMFL_CODE32 : 0));
    21862186            if (VBOX_FAILURE(rc))
    21872187                rc = emR3RawExecuteInstruction(pVM, "MMIO");
     
    24332433        /* Prefetch pages for EIP and ESP */
    24342434        /** @todo This is rather expensive. Should investigate if it really helps at all. */
    2435         rc = PGMPrefetchPage(pVM, SELMToFlat(pVM, pCtx->cs, &pCtx->csHid, pCtx->eip));
     2435        rc = PGMPrefetchPage(pVM, SELMToFlat(pVM, pCtx->eflags, pCtx->cs, &pCtx->csHid, pCtx->eip));
    24362436        if (rc == VINF_SUCCESS)
    2437             rc = PGMPrefetchPage(pVM, SELMToFlat(pVM, pCtx->ss, &pCtx->ssHid, pCtx->esp));
     2437            rc = PGMPrefetchPage(pVM, SELMToFlat(pVM, pCtx->eflags, pCtx->ss, &pCtx->ssHid, pCtx->esp));
    24382438        if (rc != VINF_SUCCESS)
    24392439        {
     
    27352735
    27362736            /* Prefetch pages for EIP and ESP */
    2737             rc = PGMPrefetchPage(pVM, SELMToFlat(pVM, pCtx->cs, &pCtx->csHid, pCtx->eip));
     2737            rc = PGMPrefetchPage(pVM, SELMToFlat(pVM, pCtx->eflags, pCtx->cs, &pCtx->csHid, pCtx->eip));
    27382738            if (rc == VINF_SUCCESS)
    2739                 rc = PGMPrefetchPage(pVM, SELMToFlat(pVM, pCtx->ss, &pCtx->ssHid, pCtx->esp));
     2739                rc = PGMPrefetchPage(pVM, SELMToFlat(pVM, pCtx->eflags, pCtx->ss, &pCtx->ssHid, pCtx->esp));
    27402740            if (rc != VINF_SUCCESS)
    27412741            {
  • trunk/src/VBox/VMM/PATM/CSAM.cpp

    r1086 r1359  
    20482048    if (CSAMIsEnabled(pVM))
    20492049    {
    2050         bool fCode32 = SELMIsSelector32Bit(pVM, Sel, pHiddenSel);
     2050        X86EFLAGS fakeflags;
     2051
     2052        /* we're not in v86 mode here */
     2053        fakeflags.u32 = 0;
     2054
     2055        bool fCode32 = SELMIsSelector32Bit(pVM, fakeflags, Sel, pHiddenSel);
    20512056
    20522057        //assuming 32 bits code for now
    20532058        Assert(fCode32);
    20542059
    2055         pInstrGC = SELMToFlat(pVM, Sel, pHiddenSel, pInstrGC);
     2060        pInstrGC = SELMToFlat(pVM, fakeflags, Sel, pHiddenSel, pInstrGC);
    20562061
    20572062        return CSAMR3CheckCode(pVM, pInstrGC);
     
    22392244            CSAMP2GLOOKUPREC cacheRec = {0};            /* Cache record for PATMGCVirtToHCVirt. */
    22402245            PCSAMPAGE pPage = NULL;
     2246            X86EFLAGS fakeflags;
     2247
     2248            /* we're not in v86 mode here */
     2249            fakeflags.u32 = 0;
    22412250
    22422251            pHandler = (pGuestIdte->Gen.u16OffsetHigh << 16) | pGuestIdte->Gen.u16OffsetLow;
    2243             pHandler = SELMToFlat(pVM, pGuestIdte->Gen.u16SegSel, 0, pHandler);
     2252            pHandler = SELMToFlat(pVM, fakeflags, pGuestIdte->Gen.u16SegSel, 0, pHandler);
    22442253
    22452254            if (pGuestIdte->Gen.u5Type2 == VBOX_IDTE_TYPE2_TRAP_32)
  • trunk/src/VBox/VMM/PATM/PATM.cpp

    r1125 r1359  
    33383338
    33393339    pBranchTarget = pCtx->edx;
    3340     pBranchTarget = SELMToFlat(pVM, pCtx->cs, &pCtx->csHid, pBranchTarget);
     3340    pBranchTarget = SELMToFlat(pVM, pCtx->eflags, pCtx->cs, &pCtx->csHid, pBranchTarget);
    33413341
    33423342    /* First we check if the duplicate function target lies in some existing function patch already. Will save some space. */
     
    39553955        &&  (pCtx->ss & X86_SEL_RPL) == 0)
    39563956    {
    3957         RTGCPTR pInstrGCFlat = SELMToFlat(pVM, pCtx->cs, &pCtx->csHid, pInstrGC);
     3957        RTGCPTR pInstrGCFlat = SELMToFlat(pVM, pCtx->eflags, pCtx->cs, &pCtx->csHid, pInstrGC);
    39583958        Assert(pInstrGCFlat == pInstrGC);
    39593959    }
     
    59075907
    59085908    /* Return original address, correct by subtracting the CS base address. */
    5909     *ppNewEip = pNewEip - SELMToFlat(pVM, pCtx->cs, &pCtx->csHid, 0);
     5909    *ppNewEip = pNewEip - SELMToFlat(pVM, pCtx->eflags, pCtx->cs, &pCtx->csHid, 0);
    59105910
    59115911    /* Reset the PATM stack. */
  • trunk/src/VBox/VMM/PATM/VMMGC/PATMGC.cpp

    r1163 r1359  
    469469            }
    470470
    471             cpu.mode = SELMIsSelector32Bit(pVM, pRegFrame->cs, 0) ? CPUMODE_32BIT : CPUMODE_16BIT;
     471            cpu.mode = SELMIsSelector32Bit(pVM, pRegFrame->eflags, pRegFrame->cs, 0) ? CPUMODE_32BIT : CPUMODE_16BIT;
    472472            if(cpu.mode != CPUMODE_32BIT)
    473473            {
  • trunk/src/VBox/VMM/VMMAll/EMAll.cpp

    r1322 r1359  
    131131{
    132132    RTGCPTR GCPtrInstr;
    133     int rc = SELMValidateAndConvertCSAddr(pVM, pCtxCore->ss, pCtxCore->cs, (PCPUMSELREGHID)&pCtxCore->csHid, (RTGCPTR)pCtxCore->eip, &GCPtrInstr);
     133    int rc = SELMValidateAndConvertCSAddr(pVM, pCtxCore->eflags, pCtxCore->ss, pCtxCore->cs, (PCPUMSELREGHID)&pCtxCore->csHid, (RTGCPTR)pCtxCore->eip, &GCPtrInstr);
    134134    if (VBOX_FAILURE(rc))
    135135    {
     
    155155EMDECL(int) EMInterpretDisasOneEx(PVM pVM, RTGCUINTPTR GCPtrInstr, PCCPUMCTXCORE pCtxCore, PDISCPUSTATE pCpu, unsigned *pcbInstr)
    156156{
    157     int rc = DISCoreOneEx(GCPtrInstr, SELMIsSelector32Bit(pVM, pCtxCore->cs, (PCPUMSELREGHID)&pCtxCore->csHid) ? CPUMODE_32BIT : CPUMODE_16BIT,
     157    int rc = DISCoreOneEx(GCPtrInstr, SELMIsSelector32Bit(pVM, pCtxCore->eflags, pCtxCore->cs, (PCPUMSELREGHID)&pCtxCore->csHid) ? CPUMODE_32BIT : CPUMODE_16BIT,
    158158#ifdef IN_GC
    159159                          NULL, NULL,
     
    192192     * Only allow 32-bit code.
    193193     */
    194     if (SELMIsSelector32Bit(pVM, pRegFrame->cs, &pRegFrame->csHid))
     194    if (SELMIsSelector32Bit(pVM, pRegFrame->eflags, pRegFrame->cs, &pRegFrame->csHid))
    195195    {
    196196        RTGCPTR pbCode;
    197         int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)pRegFrame->eip, &pbCode);
     197        int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->eflags, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)pRegFrame->eip, &pbCode);
    198198        if (VBOX_SUCCESS(rc))
    199199        {
     
    542542
    543543            /* Read stack value first */
    544             if (SELMIsSelector32Bit(pVM, pRegFrame->ss, &pRegFrame->ssHid) == false)
     544            if (SELMIsSelector32Bit(pVM, pRegFrame->eflags, pRegFrame->ss, &pRegFrame->ssHid) == false)
    545545                return VERR_EM_INTERPRETER; /* No legacy 16 bits stuff here, please. */
    546546
    547547            /* Convert address; don't bother checking limits etc, as we only read here */
    548             pStackVal = SELMToFlat(pVM, pRegFrame->ss, &pRegFrame->ssHid, (RTGCPTR)pRegFrame->esp);
     548            pStackVal = SELMToFlat(pVM, pRegFrame->eflags, pRegFrame->ss, &pRegFrame->ssHid, (RTGCPTR)pRegFrame->esp);
    549549            if (pStackVal == 0)
    550550                return VERR_EM_INTERPRETER;
     
    17491749
    17501750    Assert(pRegFrame->eflags.u32 & X86_EFL_IF);
    1751     Assert(pvFault == SELMToFlat(pVM, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)pRegFrame->eip));
     1751    Assert(pvFault == SELMToFlat(pVM, pRegFrame->eflags, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)pRegFrame->eip));
    17521752
    17531753    pVM->em.s.GCPtrInhibitInterrupts = pRegFrame->eip + pCpu->opsize;
     
    18531853    /* In HWACCM mode we can execute 16 bits code. Our emulation above can't cope with that yet. */
    18541854    /** @note if not in HWACCM mode, then we will never execute 16 bits code, so don't bother checking. */
    1855     if (HWACCMIsEnabled(pVM) && !SELMIsSelector32Bit(pVM, pRegFrame->cs, &pRegFrame->csHid))
     1855    if (HWACCMIsEnabled(pVM) && !SELMIsSelector32Bit(pVM, pRegFrame->eflags, pRegFrame->cs, &pRegFrame->csHid))
    18561856        return VERR_EM_INTERPRETER;
    18571857
  • trunk/src/VBox/VMM/VMMAll/IOMAll.cpp

    r708 r1359  
    11991199     */
    12001200    uint32_t efl = CPUMRawGetEFlags(pVM, pCtxCore);
    1201     if (    (     (unsigned)(pCtxCore->ss & X86_SEL_RPL) > 1
    1202               &&  X86_EFL_GET_IOPL(efl) < (unsigned)(pCtxCore->ss & X86_SEL_RPL)
    1203             )
    1204          || (efl & X86_EFL_VM)
     1201    uint32_t cpl;
     1202
     1203    if (pCtxCore->eflags.Bits.u1VM)
     1204        cpl = 3;
     1205    else
     1206        cpl = (pCtxCore->ss & X86_SEL_RPL);
     1207
     1208    if (    cpl > 1
     1209        &&  X86_EFL_GET_IOPL(efl) < cpl
    12051210       )
    12061211    {
  • trunk/src/VBox/VMM/VMMAll/IOMAllMMIO.cpp

    r1332 r1359  
    216216
    217217
    218 #if 0
    219 /**
    220  * Calculates effective address (offset from current segment register) for
    221  * instruction parameter, i.e. [eax + esi*4 + 1234h] -> virtual address.
    222  *
    223  * @returns true on success.
    224  * @param   pCpu                Pointer to current disassembler context.
    225  * @param   pParam              Pointer to parameter of instruction to calc EA.
    226  * @param   pRegFrame           Pointer to CPUMCTXCORE guest structure.
    227  * @param   ppAddr              Where to store result address.
    228  */
    229 static bool iomGCCalcParamEA(PDISCPUSTATE pCpu, POP_PARAMETER pParam, PCPUMCTXCORE pRegFrame, void **ppAddr)
    230 {
    231     uint8_t *pAddr = 0;
    232 
    233     if (pCpu->addrmode == CPUMODE_32BIT)
    234     {
    235         /* 32-bit addressing. */
    236         if (pParam->flags & USE_BASE)
    237             pAddr += ACCESS_REG32(pRegFrame, pParam->base.reg_gen32);
    238         if (pParam->flags & USE_INDEX)
    239         {
    240             unsigned i = ACCESS_REG32(pRegFrame, pParam->index.reg_gen);
    241             if (pParam->flags & USE_SCALE)
    242                 i *= pParam->scale;
    243             pAddr += i;
    244         }
    245         if (pParam->flags & USE_DISPLACEMENT8)
    246             pAddr += pParam->disp8;
    247         else
    248             if (pParam->flags & USE_DISPLACEMENT16)
    249             pAddr += pParam->disp16;
    250         else
    251             if (pParam->flags & USE_DISPLACEMENT32)
    252             pAddr += pParam->disp32;
    253 
    254         if (pParam->flags & (USE_BASE | USE_INDEX | USE_DISPLACEMENT8 | USE_DISPLACEMENT16 | USE_DISPLACEMENT32))
    255         {
    256             /* EA present in parameter. */
    257             *ppAddr = pAddr;
    258             return true;
    259         }
    260     }
    261     else
    262     {
    263         /* 16-bit addressing. */
    264         if (pParam->flags & USE_BASE)
    265             pAddr += ACCESS_REG16(pRegFrame, pParam->base.reg_gen16);
    266         if (pParam->flags & USE_INDEX)
    267             pAddr += ACCESS_REG16(pRegFrame, pParam->index.reg_gen);
    268         if (pParam->flags & USE_DISPLACEMENT8)
    269             pAddr += pParam->disp8;
    270         else
    271             if (pParam->flags & USE_DISPLACEMENT16)
    272             pAddr += pParam->disp16;
    273 
    274         if (pParam->flags & (USE_BASE | USE_INDEX | USE_DISPLACEMENT8 | USE_DISPLACEMENT16))
    275         {
    276             /* EA present in parameter. */
    277             *ppAddr = pAddr;
    278             return true;
    279         }
    280     }
    281 
    282     /* Error exit. */
    283     return false;
    284 }
    285 
    286 /**
    287  * Calculates the size of register parameter.
    288  *
    289  * @returns 1, 2, 4 on success.
    290  * @returns 0 if non-register parameter.
    291  * @param   pCpu                Pointer to current disassembler context.
    292  * @param   pParam              Pointer to parameter of instruction to proccess.
    293  */
    294 static unsigned iomGCGetRegSize(PDISCPUSTATE pCpu, PCOP_PARAMETER pParam)
    295 {
    296     if (pParam->flags & (USE_BASE | USE_INDEX | USE_SCALE | USE_DISPLACEMENT8 | USE_DISPLACEMENT16 | USE_DISPLACEMENT32 | USE_IMMEDIATE8 | USE_IMMEDIATE16 | USE_IMMEDIATE32 | USE_IMMEDIATE16_SX8 | USE_IMMEDIATE32_SX8))
    297         return 0;
    298 
    299     if (pParam->flags & USE_REG_GEN32)
    300         return 4;
    301 
    302     if (pParam->flags & USE_REG_GEN16)
    303         return 2;
    304 
    305     if (pParam->flags & USE_REG_GEN8)
    306         return 1;
    307 
    308     if (pParam->flags & USE_REG_SEG)
    309         return 2;
    310     return 0;
    311 }
    312 #endif
    313 
    314218/**
    315219 * Returns the contents of register or immediate data of instruction's parameter.
     
    608512    }
    609513
     514    uint32_t cpl;
     515    if (pRegFrame->eflags.Bits.u1VM)
     516        cpl = 3;
     517    else
     518        cpl = (pRegFrame->ss & X86_SEL_RPL);
     519
    610520    /*
    611521     * Get data size.
     
    639549        /* Convert source address ds:esi. */
    640550        uint8_t *pu8Virt;
    641         rc = SELMToFlatEx(pVM, pRegFrame->ds, (RTGCPTR)pRegFrame->esi,
     551        rc = SELMToFlatEx(pVM, pRegFrame->eflags, pRegFrame->ds, (RTGCPTR)pRegFrame->esi,
    642552                                SELMTOFLAT_FLAGS_HYPER | SELMTOFLAT_FLAGS_NO_PL,
    643553                                (PRTGCPTR)&pu8Virt, NULL);
     
    646556
    647557            /* Access verification first; we currently can't recover properly from traps inside this instruction */
    648             rc = PGMVerifyAccess(pVM, (RTGCUINTPTR)pu8Virt, cTransfers * cbSize, ((pRegFrame->ss & X86_SEL_RPL) == 3) ? X86_PTE_US : 0);
     558            rc = PGMVerifyAccess(pVM, (RTGCUINTPTR)pu8Virt, cTransfers * cbSize, (cpl == 3) ? X86_PTE_US : 0);
    649559            if (rc != VINF_SUCCESS)
    650560            {
     
    695605        /* Convert destination address. */
    696606        uint8_t *pu8Virt;
    697         rc = SELMToFlatEx(pVM, pRegFrame->es, (RTGCPTR)pRegFrame->edi,
     607        rc = SELMToFlatEx(pVM, pRegFrame->eflags, pRegFrame->es, (RTGCPTR)pRegFrame->edi,
    698608                                SELMTOFLAT_FLAGS_HYPER | SELMTOFLAT_FLAGS_NO_PL,
    699609                                (PRTGCPTR)&pu8Virt, NULL);
     
    751661
    752662            /* Access verification first; we currently can't recover properly from traps inside this instruction */
    753             rc = PGMVerifyAccess(pVM, (RTGCUINTPTR)pu8Virt, cTransfers * cbSize, X86_PTE_RW | (((pRegFrame->ss & X86_SEL_RPL) == 3) ? X86_PTE_US : 0));
     663            rc = PGMVerifyAccess(pVM, (RTGCUINTPTR)pu8Virt, cTransfers * cbSize, X86_PTE_RW | ((cpl == 3) ? X86_PTE_US : 0));
    754664            if (rc != VINF_SUCCESS)
    755665            {
     
    13171227          GCPhysFault, uErrorCode, pvFault, pRegFrame->eip));
    13181228
    1319     /** @todo V86 mode; SELM functions don't handle this */
    1320     if (pRegFrame->eflags.Bits.u1VM)
    1321         return (uErrorCode & X86_TRAP_PF_RW) ? VINF_IOM_HC_MMIO_WRITE : VINF_IOM_HC_MMIO_READ;
    1322 
    13231229    /*
    13241230     * Find the corresponding MMIO range.
     
    13561262     */
    13571263    DISCPUSTATE cpu;
    1358     cpu.mode = SELMIsSelector32Bit(pVM, pRegFrame->cs, &pRegFrame->csHid) ? CPUMODE_32BIT : CPUMODE_16BIT;
     1264    cpu.mode = SELMIsSelector32Bit(pVM, pRegFrame->eflags, pRegFrame->cs, &pRegFrame->csHid) ? CPUMODE_32BIT : CPUMODE_16BIT;
    13591265
    13601266    RTGCPTR pvCode;
    1361     int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)(cpu.mode == CPUMODE_32BIT ? pRegFrame->eip : pRegFrame->eip & 0xffff), &pvCode);
     1267    int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->eflags, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)(cpu.mode == CPUMODE_32BIT ? pRegFrame->eip : pRegFrame->eip & 0xffff), &pvCode);
    13621268    if (VBOX_FAILURE(rc))
    13631269    {
  • trunk/src/VBox/VMM/VMMAll/PGMAllBth.h

    r1158 r1359  
    201201                 * Check if the EIP is in a virtual page access handler range.
    202202                 */
    203                 if ((pRegFrame->ss & X86_SEL_RPL) == 1)
     203                if (    (pRegFrame->ss & X86_SEL_RPL) == 1
     204                    &&  !pRegFrame->eflags.Bits.u1VM)
    204205                {
    205206                    RTGCPTR pvEIP;
    206                     rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)pRegFrame->eip, &pvEIP);
     207                    rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->eflags, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)pRegFrame->eip, &pvEIP);
    207208                    if (VBOX_SUCCESS(rc))
    208209                    {
     
    700701    /** @todo this stuff is completely broken by the out-of-sync stuff. since we don't use this stuff, that's not really a problem yet. */
    701702    STAM_PROFILE_START(&pVM->pgm.s.StatEIPHandlers, d);
    702     if ((pRegFrame->ss & X86_SEL_RPL) == 1)
     703    if (    (pRegFrame->ss & X86_SEL_RPL) == 1
     704        &&  !pRegFrame->eflags.Bits.u1VM)
    703705    {
    704706        RTGCPTR pvEIP;
    705         rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)pRegFrame->eip, &pvEIP);
     707        rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->eflags, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)pRegFrame->eip, &pvEIP);
    706708        if (    VBOX_SUCCESS(rc)
    707709            &&  pvEIP == (RTGCPTR)pRegFrame->eip)
  • trunk/src/VBox/VMM/VMMAll/PGMAllHandler.cpp

    r138 r1359  
    10581058{
    10591059    DISCPUSTATE Cpu;
    1060     Cpu.mode = SELMIsSelector32Bit(pVM, pRegFrame->cs, &pRegFrame->csHid) ? CPUMODE_32BIT : CPUMODE_16BIT;
     1060    Cpu.mode = SELMIsSelector32Bit(pVM, pRegFrame->eflags, pRegFrame->cs, &pRegFrame->csHid) ? CPUMODE_32BIT : CPUMODE_16BIT;
    10611061    if (Cpu.mode == CPUMODE_32BIT)
    10621062    {
    10631063        RTGCPTR GCPtrCode;
    1064         int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)pRegFrame->eip, &GCPtrCode);
     1064        int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->eflags, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)pRegFrame->eip, &GCPtrCode);
    10651065        if (VBOX_SUCCESS(rc))
    10661066        {
  • trunk/src/VBox/VMM/VMMAll/SELMAll.cpp

    r105 r1359  
    8484 * @returns Flat address.
    8585 * @param   pVM     VM Handle.
     86 * @param   eflags  Current eflags
    8687 * @param   Sel     Selector part.
    8788 * @param   Addr    Address part.
    8889 */
    89 SELMDECL(RTGCPTR) SELMToFlat(PVM pVM, RTSEL Sel, CPUMSELREGHID *pHiddenSel, RTGCPTR Addr)
    90 {
     90SELMDECL(RTGCPTR) SELMToFlat(PVM pVM, X86EFLAGS eflags, RTSEL Sel, CPUMSELREGHID *pHiddenSel, RTGCPTR Addr)
     91{
     92    /*
     93     * Deal with real mode first.
     94     */
     95    if (    CPUMIsGuestInRealMode(pVM)
     96        ||  eflags.Bits.u1VM)
     97    {
     98        RTGCUINTPTR uFlat = ((RTGCUINTPTR)Addr & 0xffff) + (Sel << 4);
     99        return (RTGCPTR)uFlat;
     100    }
     101
    91102    if (!CPUMAreHiddenSelRegsValid(pVM))
    92103        return selmToFlat(pVM, Sel, Addr);
     
    103114 * @returns VBox status
    104115 * @param   pVM     VM Handle.
     116 * @param   eflags  Current eflags
    105117 * @param   Sel     Selector part.
    106118 * @param   Addr    Address part.
     
    111123 *                  the selector. NULL is allowed.
    112124 */
    113 SELMDECL(int) SELMToFlatEx(PVM pVM, RTSEL Sel, RTGCPTR Addr, unsigned fFlags, PRTGCPTR ppvGC, uint32_t *pcb)
     125SELMDECL(int) SELMToFlatEx(PVM pVM, X86EFLAGS eflags, RTSEL Sel, RTGCPTR Addr, unsigned fFlags, PRTGCPTR ppvGC, uint32_t *pcb)
    114126{
    115127    /*
    116128     * Deal with real mode first.
    117129     */
    118     if (CPUMIsGuestInRealMode(pVM)
    119         /** @todo  || (fFlags & SELMTOFLAT_FLAGS_V86)*/)
     130    if (    CPUMIsGuestInRealMode(pVM)
     131        ||  eflags.Bits.u1VM)
    120132    {
    121133        if (pcb)
     
    353365 * @returns Flat address.
    354366 * @param   pVM          VM Handle.
     367 * @param   eflags       Current eflags
    355368 * @param   SelCPL       Current privilege level. Get this from SS - CS might be conforming!
    356369 *                       A full selector can be passed, we'll only use the RPL part.
     
    360373 * @param   ppvFlat      Where to store the flat address.
    361374 */
    362 SELMDECL(int) SELMValidateAndConvertCSAddr(PVM pVM, RTSEL SelCPL, RTSEL SelCS, CPUMSELREGHID *pHiddenCSSel, RTGCPTR Addr, PRTGCPTR ppvFlat)
    363 {
     375SELMDECL(int) SELMValidateAndConvertCSAddr(PVM pVM, X86EFLAGS eflags, RTSEL SelCPL, RTSEL SelCS, CPUMSELREGHID *pHiddenCSSel, RTGCPTR Addr, PRTGCPTR ppvFlat)
     376{
     377    /* Special handling for V86 mode */
     378    if (eflags.Bits.u1VM)
     379    {
     380        if (ppvFlat)
     381        {
     382            RTGCUINTPTR uFlat = ((RTGCUINTPTR)Addr & 0xffff) + (SelCS << 4);
     383            *ppvFlat = (RTGCPTR)uFlat;
     384        }
     385        return VINF_SUCCESS;
     386    }
     387
    364388    if (!CPUMAreHiddenSelRegsValid(pVM))
    365389        return selmValidateAndConvertCSAddr(pVM, SelCPL, SelCS, Addr, ppvFlat);
     
    441465 * @returns False if it is 16-bit.
    442466 * @param   pVM        VM Handle.
     467 * @param   eflags     Current eflags register
    443468 * @param   Sel        The selector.
    444469 * @param   pHiddenSel The hidden selector register.
    445470 */
    446 SELMDECL(bool) SELMIsSelector32Bit(PVM pVM, RTSEL Sel, CPUMSELREGHID *pHiddenSel)
    447 {
     471SELMDECL(bool) SELMIsSelector32Bit(PVM pVM, X86EFLAGS eflags, RTSEL Sel, CPUMSELREGHID *pHiddenSel)
     472{
     473    if (eflags.Bits.u1VM)
     474        return false;
     475
    448476    if (!CPUMAreHiddenSelRegsValid(pVM))
    449477        return selmIsSelector32Bit(pVM, Sel);
  • trunk/src/VBox/VMM/VMMAll/TRPMAll.cpp

    r1328 r1359  
    492492            /* Note: SELMValidateAndConvertCSAddr checks for code type, memory type, selector validity. */
    493493            /** @todo dpl <= cpl else GPF */
    494             rc = SELMValidateAndConvertCSAddr(pVM, 0, GuestIdte.Gen.u16SegSel, NULL, pHandler, &dummy);
     494
     495            /** @note don't use current eflags as we might be in V86 mode and the IDT always contains protected mode selectors */
     496            X86EFLAGS fakeflags;
     497            fakeflags.u32 = 0;   
     498
     499            rc = SELMValidateAndConvertCSAddr(pVM, fakeflags, 0, GuestIdte.Gen.u16SegSel, NULL, pHandler, &dummy);
    495500            if (rc == VINF_SUCCESS)
    496501            {
     
    558563                        || !ss_r0
    559564                        || (ss_r0 & X86_SEL_RPL) != ((dpl == 0) ? 1 : dpl)
    560                         || SELMToFlatEx(pVM, ss_r0, (RTGCPTR)esp_r0, SELMTOFLAT_FLAGS_CPL1, (PRTGCPTR)&pTrapStackGC, NULL) != VINF_SUCCESS
     565                        || SELMToFlatEx(pVM, fakeflags, ss_r0, (RTGCPTR)esp_r0, SELMTOFLAT_FLAGS_CPL1, (PRTGCPTR)&pTrapStackGC, NULL) != VINF_SUCCESS
    561566                       )
    562567                    {
     
    572577
    573578                    if (    eflags.Bits.u1VM    /* illegal */
    574                         ||  SELMToFlatEx(pVM, ss_r0, (RTGCPTR)esp_r0, SELMTOFLAT_FLAGS_CPL1, (PRTGCPTR)&pTrapStackGC, NULL) != VINF_SUCCESS)
     579                        ||  SELMToFlatEx(pVM, fakeflags, ss_r0, (RTGCPTR)esp_r0, SELMTOFLAT_FLAGS_CPL1, (PRTGCPTR)&pTrapStackGC, NULL) != VINF_SUCCESS)
    575580                    {
    576581                        AssertMsgFailed(("Invalid stack %04X:%VGv??? (VM=%d)\n", ss_r0, esp_r0, eflags.Bits.u1VM));
  • trunk/src/VBox/VMM/VMMGC/DBGFGC.cpp

    r1161 r1359  
    112112    {
    113113        RTGCPTR pPc;
    114         int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid,
    115                                               (RTGCPTR)((RTGCUINTPTR)pRegFrame->eip - 1),
     114        int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->eflags, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid,
     115                                              (RTGCPTR)((RTGCUINTPTR)pRegFrame->eip - 1),                                             
    116116                                              &pPc);
    117117        AssertRCReturn(rc, rc);
  • trunk/src/VBox/VMM/VMMGC/IOMGC.cpp

    r1160 r1359  
    554554        /* Convert destination address es:edi. */
    555555        RTGCPTR GCPtrDst;
    556         rc = SELMToFlatEx(pVM, pRegFrame->es, (RTGCPTR)pRegFrame->edi,
     556        rc = SELMToFlatEx(pVM, pRegFrame->eflags, pRegFrame->es, (RTGCPTR)pRegFrame->edi,
    557557                          SELMTOFLAT_FLAGS_HYPER | SELMTOFLAT_FLAGS_NO_PL,
    558558                          &GCPtrDst, NULL);
     
    659659        /* Convert source address ds:esi. */
    660660        RTGCPTR GCPtrSrc;
    661         rc = SELMToFlatEx(pVM, pRegFrame->ds, (RTGCPTR)pRegFrame->esi,
     661        rc = SELMToFlatEx(pVM, pRegFrame->eflags, pRegFrame->ds, (RTGCPTR)pRegFrame->esi,
    662662                          SELMTOFLAT_FLAGS_HYPER | SELMTOFLAT_FLAGS_NO_PL,
    663663                          &GCPtrSrc, NULL);
  • trunk/src/VBox/VMM/VMMGC/TRPMGCHandlers.cpp

    r1321 r1359  
    349349         */
    350350        RTGCPTR PC;
    351         int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)pRegFrame->eip, &PC);
     351        int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->eflags, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)pRegFrame->eip, &PC);
    352352        if (VBOX_FAILURE(rc))
    353353        {
     
    423423     */
    424424    uint8_t *pu8Code;
    425     if (SELMValidateAndConvertCSAddr(pVM, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)pRegFrame->eip, (PRTGCPTR)&pu8Code) == VINF_SUCCESS)
     425    if (SELMValidateAndConvertCSAddr(pVM, pRegFrame->eflags, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)pRegFrame->eip, (PRTGCPTR)&pu8Code) == VINF_SUCCESS)
    426426    {
    427427        /*
     
    711711        X86EFLAGS eflags;
    712712        eflags.u32 = CPUMRawGetEFlags(pVM, pRegFrame);
    713         if (eflags.Bits.u2IOPL == 0)
    714         {
     713        if (eflags.Bits.u2IOPL != 3)
     714        {
     715            Assert(eflags.Bits.u2IOPL == 0);
     716
    715717            int rc = TRPMForwardTrap(pVM, pRegFrame, 0xD, 0, TRPM_TRAP_HAS_ERRORCODE, TRPM_TRAP);
    716718            Assert(rc == VINF_EM_RAW_GUEST_TRAP);
    717719            return trpmGCExitTrap(pVM, rc, pRegFrame);
    718720        }
    719 
    720         return trpmGCExitTrap(pVM, VINF_EM_RAW_EMULATE_INSTR, pRegFrame);
     721        /* iopl=3 means we can safely interpret e.g. io instructions. */
    721722    }
    722723
     
    726727     */
    727728    RTGCPTR PC;
    728     int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)pRegFrame->eip, &PC);
     729    int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->eflags, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)pRegFrame->eip, &PC);
    729730    if (VBOX_FAILURE(rc))
    730731    {
     
    763764
    764765    /*
    765      * Deal with Ring-3 GPs.
     766     * Deal with Ring-3 GPs. (we currently ignore V86 code)
    766767     */
    767768    if (!pRegFrame->eflags.Bits.u1VM)
    768769        return trpmGCTrap0dHandlerRing3(pVM, pRegFrame, &Cpu);
    769770
    770     /** @todo what about V86 mode? */
    771771    return trpmGCExitTrap(pVM, VINF_EM_RAW_GUEST_TRAP, pRegFrame);
    772772}
  • trunk/src/VBox/VMM/VMMR0/HWSVMR0.cpp

    r1296 r1359  
    14781478     * Only allow 32-bit code.
    14791479     */
    1480     if (SELMIsSelector32Bit(pVM, pRegFrame->cs, &pRegFrame->csHid))
     1480    if (SELMIsSelector32Bit(pVM, pRegFrame->eflags, pRegFrame->cs, &pRegFrame->csHid))
    14811481    {
    14821482        RTGCPTR pbCode;
    1483         int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)pRegFrame->eip, &pbCode);
     1483        int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->eflags, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)pRegFrame->eip, &pbCode);
    14841484        if (VBOX_SUCCESS(rc))
    14851485        {
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