- Timestamp:
- Jul 29, 2019 9:36:45 PM (5 years ago)
- Location:
- trunk/src/VBox/VMM
- Files:
-
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMAll/CPUMAllRegs.cpp
r80053 r80055 1569 1569 } 1570 1570 1571 #ifdef VBOX_WITH_RAW_MODE_NOT_R01572 1573 /**1574 *1575 * @returns @c true if we've entered raw-mode and selectors with RPL=1 are1576 * really RPL=0, @c false if we've not (RPL=1 really is RPL=1).1577 * @param pVCpu The cross context virtual CPU structure of the calling EMT.1578 */1579 VMM_INT_DECL(bool) CPUMIsGuestInRawMode(PCVMCPU pVCpu)1580 {1581 return pVCpu->cpum.s.fRawEntered;1582 }1583 1584 /**1585 * Transforms the guest CPU state to raw-ring mode.1586 *1587 * This function will change the any of the cs and ss register with DPL=0 to DPL=1.1588 *1589 * @returns VBox status code. (recompiler failure)1590 * @param pVCpu The cross context virtual CPU structure.1591 * @see @ref pg_raw1592 */1593 VMM_INT_DECL(int) CPUMRawEnter(PVMCPU pVCpu)1594 {1595 PVM pVM = pVCpu->CTX_SUFF(pVM);1596 1597 Assert(!pVCpu->cpum.s.fRawEntered);1598 Assert(!pVCpu->cpum.s.fRemEntered);1599 PCPUMCTX pCtx = &pVCpu->cpum.s.Guest;1600 1601 /*1602 * Are we in Ring-0?1603 */1604 if ( pCtx->ss.Sel1605 && (pCtx->ss.Sel & X86_SEL_RPL) == 01606 && !pCtx->eflags.Bits.u1VM)1607 {1608 /*1609 * Enter execution mode.1610 */1611 PATMRawEnter(pVM, pCtx);1612 1613 /*1614 * Set CPL to Ring-1.1615 */1616 pCtx->ss.Sel |= 1;1617 if ( pCtx->cs.Sel1618 && (pCtx->cs.Sel & X86_SEL_RPL) == 0)1619 pCtx->cs.Sel |= 1;1620 }1621 else1622 {1623 AssertMsg((pCtx->ss.Sel & X86_SEL_RPL) >= 2 || pCtx->eflags.Bits.u1VM,1624 ("ring-1 code not supported\n"));1625 1626 /*1627 * PATM takes care of IOPL and IF flags for Ring-3 and Ring-2 code as well.1628 */1629 PATMRawEnter(pVM, pCtx);1630 }1631 1632 /*1633 * Assert sanity.1634 */1635 AssertMsg((pCtx->eflags.u32 & X86_EFL_IF), ("X86_EFL_IF is clear\n"));1636 AssertReleaseMsg(pCtx->eflags.Bits.u2IOPL == 0,1637 ("X86_EFL_IOPL=%d CPL=%d\n", pCtx->eflags.Bits.u2IOPL, pCtx->ss.Sel & X86_SEL_RPL));1638 Assert((pVCpu->cpum.s.Guest.cr0 & (X86_CR0_PG | X86_CR0_PE)) == (X86_CR0_PG | X86_CR0_PE));1639 1640 pCtx->eflags.u32 |= X86_EFL_IF; /* paranoia */1641 1642 pVCpu->cpum.s.fRawEntered = true;1643 return VINF_SUCCESS;1644 }1645 1646 1647 /**1648 * Transforms the guest CPU state from raw-ring mode to correct values.1649 *1650 * This function will change any selector registers with DPL=1 to DPL=0.1651 *1652 * @returns Adjusted rc.1653 * @param pVCpu The cross context virtual CPU structure.1654 * @param rc Raw mode return code1655 * @see @ref pg_raw1656 */1657 VMM_INT_DECL(int) CPUMRawLeave(PVMCPU pVCpu, int rc)1658 {1659 PVM pVM = pVCpu->CTX_SUFF(pVM);1660 1661 /*1662 * Don't leave if we've already left (in RC).1663 */1664 Assert(!pVCpu->cpum.s.fRemEntered);1665 if (!pVCpu->cpum.s.fRawEntered)1666 return rc;1667 pVCpu->cpum.s.fRawEntered = false;1668 1669 PCPUMCTX pCtx = &pVCpu->cpum.s.Guest;1670 Assert(pCtx->eflags.Bits.u1VM || (pCtx->ss.Sel & X86_SEL_RPL));1671 AssertMsg(pCtx->eflags.Bits.u1VM || pCtx->eflags.Bits.u2IOPL < (unsigned)(pCtx->ss.Sel & X86_SEL_RPL),1672 ("X86_EFL_IOPL=%d CPL=%d\n", pCtx->eflags.Bits.u2IOPL, pCtx->ss.Sel & X86_SEL_RPL));1673 1674 /*1675 * Are we executing in raw ring-1?1676 */1677 if ( (pCtx->ss.Sel & X86_SEL_RPL) == 11678 && !pCtx->eflags.Bits.u1VM)1679 {1680 /*1681 * Leave execution mode.1682 */1683 PATMRawLeave(pVM, pCtx, rc);1684 /* Not quite sure if this is really required, but shouldn't harm (too much anyways). */1685 /** @todo See what happens if we remove this. */1686 if ((pCtx->ds.Sel & X86_SEL_RPL) == 1)1687 pCtx->ds.Sel &= ~X86_SEL_RPL;1688 if ((pCtx->es.Sel & X86_SEL_RPL) == 1)1689 pCtx->es.Sel &= ~X86_SEL_RPL;1690 if ((pCtx->fs.Sel & X86_SEL_RPL) == 1)1691 pCtx->fs.Sel &= ~X86_SEL_RPL;1692 if ((pCtx->gs.Sel & X86_SEL_RPL) == 1)1693 pCtx->gs.Sel &= ~X86_SEL_RPL;1694 1695 /*1696 * Ring-1 selector => Ring-0.1697 */1698 pCtx->ss.Sel &= ~X86_SEL_RPL;1699 if ((pCtx->cs.Sel & X86_SEL_RPL) == 1)1700 pCtx->cs.Sel &= ~X86_SEL_RPL;1701 }1702 else1703 {1704 /*1705 * PATM is taking care of the IOPL and IF flags for us.1706 */1707 PATMRawLeave(pVM, pCtx, rc);1708 if (!pCtx->eflags.Bits.u1VM)1709 {1710 /** @todo See what happens if we remove this. */1711 if ((pCtx->ds.Sel & X86_SEL_RPL) == 1)1712 pCtx->ds.Sel &= ~X86_SEL_RPL;1713 if ((pCtx->es.Sel & X86_SEL_RPL) == 1)1714 pCtx->es.Sel &= ~X86_SEL_RPL;1715 if ((pCtx->fs.Sel & X86_SEL_RPL) == 1)1716 pCtx->fs.Sel &= ~X86_SEL_RPL;1717 if ((pCtx->gs.Sel & X86_SEL_RPL) == 1)1718 pCtx->gs.Sel &= ~X86_SEL_RPL;1719 }1720 }1721 1722 return rc;1723 }1724 1725 #endif /* VBOX_WITH_RAW_MODE_NOT_R0 */1726 1727 /**1728 * Updates the EFLAGS while we're in raw-mode.1729 *1730 * @param pVCpu The cross context virtual CPU structure.1731 * @param fEfl The new EFLAGS value.1732 */1733 VMMDECL(void) CPUMRawSetEFlags(PVMCPU pVCpu, uint32_t fEfl)1734 {1735 #ifdef VBOX_WITH_RAW_MODE_NOT_R01736 if (pVCpu->cpum.s.fRawEntered)1737 PATMRawSetEFlags(pVCpu->CTX_SUFF(pVM), &pVCpu->cpum.s.Guest, fEfl);1738 else1739 #endif1740 pVCpu->cpum.s.Guest.eflags.u32 = fEfl;1741 }1742 1743 1744 /**1745 * Gets the EFLAGS while we're in raw-mode.1746 *1747 * @returns The eflags.1748 * @param pVCpu The cross context virtual CPU structure of the calling EMT.1749 */1750 VMMDECL(uint32_t) CPUMRawGetEFlags(PVMCPU pVCpu)1751 {1752 #ifdef VBOX_WITH_RAW_MODE_NOT_R01753 if (pVCpu->cpum.s.fRawEntered)1754 return PATMRawGetEFlags(pVCpu->CTX_SUFF(pVM), &pVCpu->cpum.s.Guest);1755 #endif1756 return pVCpu->cpum.s.Guest.eflags.u32;1757 }1758 1759 1571 1760 1572 /** … … 2105 1917 if (!CPUMIsGuestInNestedHwvirtMode(&pVCpu->cpum.s.Guest)) 2106 1918 { 2107 #ifdef VBOX_WITH_RAW_MODE_NOT_R02108 uint32_t const fEFlags = !pVCpu->cpum.s.fRawEntered ? pVCpu->cpum.s.Guest.eflags.u : CPUMRawGetEFlags(pVCpu);2109 #else2110 1919 uint32_t const fEFlags = pVCpu->cpum.s.Guest.eflags.u; 2111 #endif2112 1920 return RT_BOOL(fEFlags & X86_EFL_IF); 2113 1921 } -
trunk/src/VBox/VMM/VMMAll/EMAll.cpp
r80016 r80055 1224 1224 } 1225 1225 1226 #ifdef IN_RC1227 1228 DECLINLINE(int) emRCStackRead(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, void *pvDst, RTGCPTR GCPtrSrc, uint32_t cb)1229 {1230 int rc = MMGCRamRead(pVM, pvDst, (void *)(uintptr_t)GCPtrSrc, cb);1231 if (RT_LIKELY(rc != VERR_ACCESS_DENIED))1232 return rc;1233 return PGMPhysInterpretedReadNoHandlers(pVCpu, pCtxCore, pvDst, GCPtrSrc, cb, /*fMayTrap*/ false);1234 }1235 1236 1237 /**1238 * Interpret IRET (currently only to V86 code) - PATM only.1239 *1240 * @returns VBox status code.1241 * @param pVM The cross context VM structure.1242 * @param pVCpu The cross context virtual CPU structure.1243 * @param pRegFrame The register frame.1244 *1245 */1246 VMM_INT_DECL(int) EMInterpretIretV86ForPatm(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame)1247 {1248 RTGCUINTPTR pIretStack = (RTGCUINTPTR)pRegFrame->esp;1249 RTGCUINTPTR eip, cs, esp, ss, eflags, ds, es, fs, gs, uMask;1250 int rc;1251 1252 Assert(pRegFrame == CPUMGetGuestCtxCore(pVCpu));1253 Assert(!CPUMIsGuestIn64BitCode(pVCpu));1254 /** @todo Rainy day: Test what happens when VERR_EM_INTERPRETER is returned by1255 * this function. Fear that it may guru on us, thus not converted to1256 * IEM. */1257 1258 rc = emRCStackRead(pVM, pVCpu, pRegFrame, &eip, (RTGCPTR)pIretStack , 4);1259 rc |= emRCStackRead(pVM, pVCpu, pRegFrame, &cs, (RTGCPTR)(pIretStack + 4), 4);1260 rc |= emRCStackRead(pVM, pVCpu, pRegFrame, &eflags, (RTGCPTR)(pIretStack + 8), 4);1261 AssertRCReturn(rc, VERR_EM_INTERPRETER);1262 AssertReturn(eflags & X86_EFL_VM, VERR_EM_INTERPRETER);1263 1264 rc |= emRCStackRead(pVM, pVCpu, pRegFrame, &esp, (RTGCPTR)(pIretStack + 12), 4);1265 rc |= emRCStackRead(pVM, pVCpu, pRegFrame, &ss, (RTGCPTR)(pIretStack + 16), 4);1266 rc |= emRCStackRead(pVM, pVCpu, pRegFrame, &es, (RTGCPTR)(pIretStack + 20), 4);1267 rc |= emRCStackRead(pVM, pVCpu, pRegFrame, &ds, (RTGCPTR)(pIretStack + 24), 4);1268 rc |= emRCStackRead(pVM, pVCpu, pRegFrame, &fs, (RTGCPTR)(pIretStack + 28), 4);1269 rc |= emRCStackRead(pVM, pVCpu, pRegFrame, &gs, (RTGCPTR)(pIretStack + 32), 4);1270 AssertRCReturn(rc, VERR_EM_INTERPRETER);1271 1272 pRegFrame->eip = eip & 0xffff;1273 pRegFrame->cs.Sel = cs;1274 1275 /* Mask away all reserved bits */1276 uMask = X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_TF | X86_EFL_IF | X86_EFL_DF | X86_EFL_OF | X86_EFL_IOPL | X86_EFL_NT | X86_EFL_RF | X86_EFL_VM | X86_EFL_AC | X86_EFL_VIF | X86_EFL_VIP | X86_EFL_ID;1277 eflags &= uMask;1278 1279 CPUMRawSetEFlags(pVCpu, eflags);1280 Assert((pRegFrame->eflags.u32 & (X86_EFL_IF|X86_EFL_IOPL)) == X86_EFL_IF);1281 1282 pRegFrame->esp = esp;1283 pRegFrame->ss.Sel = ss;1284 pRegFrame->ds.Sel = ds;1285 pRegFrame->es.Sel = es;1286 pRegFrame->fs.Sel = fs;1287 pRegFrame->gs.Sel = gs;1288 1289 return VINF_SUCCESS;1290 }1291 1292 1293 #endif /* IN_RC */1294 1226 1295 1227 -
trunk/src/VBox/VMM/VMMAll/IEMAll.cpp
r80020 r80055 1111 1111 pVCpu->iem.s.rcPassUp = VINF_SUCCESS; 1112 1112 pVCpu->iem.s.fBypassHandlers = fBypassHandlers; 1113 #ifdef VBOX_WITH_RAW_MODE_NOT_R01114 pVCpu->iem.s.fInPatchCode = pVCpu->iem.s.uCpl == 01115 && pVCpu->cpum.GstCtx.cs.u64Base == 01116 && pVCpu->cpum.GstCtx.cs.u32Limit == UINT32_MAX1117 && PATMIsPatchGCAddr(pVCpu->CTX_SUFF(pVM), pVCpu->cpum.GstCtx.eip);1118 if (!pVCpu->iem.s.fInPatchCode)1119 CPUMRawLeave(pVCpu, VINF_SUCCESS);1120 #endif1121 1113 #if 0 1122 1114 #if defined(VBOX_WITH_NESTED_HWVIRT_VMX) && !defined(IN_RC) … … 1269 1261 pVCpu->iem.s.rcPassUp = VINF_SUCCESS; 1270 1262 pVCpu->iem.s.fBypassHandlers = fBypassHandlers; 1271 #ifdef VBOX_WITH_RAW_MODE_NOT_R01272 pVCpu->iem.s.fInPatchCode = pVCpu->iem.s.uCpl == 01273 && pVCpu->cpum.GstCtx.cs.u64Base == 01274 && pVCpu->cpum.GstCtx.cs.u32Limit == UINT32_MAX1275 && PATMIsPatchGCAddr(pVCpu->CTX_SUFF(pVM), pVCpu->cpum.GstCtx.eip);1276 if (!pVCpu->iem.s.fInPatchCode)1277 CPUMRawLeave(pVCpu, VINF_SUCCESS);1278 #endif1279 1263 1280 1264 #ifdef DBGFTRACE_ENABLED … … 1380 1364 Assert(pVCpu->iem.s.rcPassUp == VINF_SUCCESS); 1381 1365 Assert(pVCpu->iem.s.fBypassHandlers == false); 1382 #ifdef VBOX_WITH_RAW_MODE_NOT_R01383 if (!pVCpu->iem.s.fInPatchCode)1384 { /* likely */ }1385 else1386 {1387 pVCpu->iem.s.fInPatchCode = pVCpu->iem.s.uCpl == 01388 && pVCpu->cpum.GstCtx.cs.u64Base == 01389 && pVCpu->cpum.GstCtx.cs.u32Limit == UINT32_MAX1390 && PATMIsPatchGCAddr(pVCpu->CTX_SUFF(pVM), pVCpu->cpum.GstCtx.eip);1391 if (!pVCpu->iem.s.fInPatchCode)1392 CPUMRawLeave(pVCpu, VINF_SUCCESS);1393 }1394 #endif1395 1366 1396 1367 #ifdef DBGFTRACE_ENABLED … … 3575 3546 /** 3576 3547 * Gets the correct EFLAGS regardless of whether PATM stores parts of them or 3577 * not .3548 * not (kind of obsolete now). 3578 3549 * 3579 3550 * @param a_pVCpu The cross context virtual CPU structure of the calling thread. 3580 3551 */ 3581 #ifdef VBOX_WITH_RAW_MODE_NOT_R0 3582 # define IEMMISC_GET_EFL(a_pVCpu) ( CPUMRawGetEFlags(a_pVCpu) ) 3583 #else 3584 # define IEMMISC_GET_EFL(a_pVCpu) ( (a_pVCpu)->cpum.GstCtx.eflags.u ) 3585 #endif 3586 3587 /** 3588 * Updates the EFLAGS in the correct manner wrt. PATM. 3552 #define IEMMISC_GET_EFL(a_pVCpu) ( (a_pVCpu)->cpum.GstCtx.eflags.u ) 3553 3554 /** 3555 * Updates the EFLAGS in the correct manner wrt. PATM (kind of obsolete). 3589 3556 * 3590 3557 * @param a_pVCpu The cross context virtual CPU structure of the calling thread. 3591 3558 * @param a_fEfl The new EFLAGS. 3592 3559 */ 3593 #ifdef VBOX_WITH_RAW_MODE_NOT_R0 3594 # define IEMMISC_SET_EFL(a_pVCpu, a_fEfl) CPUMRawSetEFlags((a_pVCpu), a_fEfl) 3595 #else 3596 # define IEMMISC_SET_EFL(a_pVCpu, a_fEfl) do { (a_pVCpu)->cpum.GstCtx.eflags.u = (a_fEfl); } while (0) 3597 #endif 3598 3599 3600 /** @} */ 3560 #define IEMMISC_SET_EFL(a_pVCpu, a_fEfl) do { (a_pVCpu)->cpum.GstCtx.eflags.u = (a_fEfl); } while (0) 3561 3562 /** @} */ 3563 3601 3564 3602 3565 /** @name Raising Exceptions. … … 14175 14138 14176 14139 14177 #ifdef IN_RC14178 /**14179 * Re-enters raw-mode or ensure we return to ring-3.14180 *14181 * @returns rcStrict, maybe modified.14182 * @param pVCpu The cross context virtual CPU structure of the calling thread.14183 * @param rcStrict The status code returne by the interpreter.14184 */14185 DECLINLINE(VBOXSTRICTRC) iemRCRawMaybeReenter(PVMCPU pVCpu, VBOXSTRICTRC rcStrict)14186 {14187 if ( !pVCpu->iem.s.fInPatchCode14188 && ( rcStrict == VINF_SUCCESS14189 || rcStrict == VERR_IEM_INSTR_NOT_IMPLEMENTED /* pgmPoolAccessPfHandlerFlush */14190 || rcStrict == VERR_IEM_ASPECT_NOT_IMPLEMENTED /* ditto */ ) )14191 {14192 if (pVCpu->cpum.GstCtx.eflags.Bits.u1IF || rcStrict != VINF_SUCCESS)14193 CPUMRawEnter(pVCpu);14194 else14195 {14196 Log(("iemRCRawMaybeReenter: VINF_EM_RESCHEDULE\n"));14197 rcStrict = VINF_EM_RESCHEDULE;14198 }14199 }14200 return rcStrict;14201 }14202 #endif14203 14204 14205 14140 /** 14206 14141 * Execute one instruction. -
trunk/src/VBox/VMM/VMMAll/SELMAll.cpp
r80014 r80055 36 36 #include <iprt/x86.h> 37 37 #include <iprt/string.h> 38 39 #include "SELMInline.h"40 38 41 39 -
trunk/src/VBox/VMM/VMMR3/SELM.cpp
r80014 r80055 82 82 #include <iprt/thread.h> 83 83 #include <iprt/string.h> 84 85 #include "SELMInline.h"86 84 87 85 -
trunk/src/VBox/VMM/include/IEMInternal.h
r76585 r80055 375 375 /** Whether to bypass access handlers or not. */ 376 376 bool fBypassHandlers; /* 0x06 */ 377 /** Indicates that we're interpreting patch code - RC only! */ 378 bool fInPatchCode; /* 0x07 */ 377 bool fUnusedWasInPatchCode; /* 0x07 */ 379 378 380 379 /** @name Decoder state.
Note:
See TracChangeset
for help on using the changeset viewer.