IOMAllMMIO.cpp revision 6c71f030509adce74519d28877dde8032dd3bfe2
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync * IOM - Input / Output Monitor - Any Context, MMIO & String I/O.
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync * Copyright (C) 2006-2012 Oracle Corporation
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * available from http://www.virtualbox.org. This file is free software;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync/*******************************************************************************
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync* Header Files *
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync*******************************************************************************/
e41f0459369a6d814aa36bf4def225482fc56026vboxsync#if defined(IEM_VERIFICATION_MODE) && defined(IN_RING3)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync/*******************************************************************************
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync* Global Variables *
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync*******************************************************************************/
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Array for fast recode of the operand size (1/2/4/8 bytes) to bit shift value.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic const unsigned g_aSize2Shift[] =
d03c6bcd3d78cef8ac4d76186e7c0e72f63ce80fvboxsync ~0U, /* 0 - invalid */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync 0, /* *1 == 2^0 */
d03c6bcd3d78cef8ac4d76186e7c0e72f63ce80fvboxsync ~0U, /* 3 - invalid */
d03c6bcd3d78cef8ac4d76186e7c0e72f63ce80fvboxsync ~0U, /* 5 - invalid */
d03c6bcd3d78cef8ac4d76186e7c0e72f63ce80fvboxsync ~0U, /* 6 - invalid */
d03c6bcd3d78cef8ac4d76186e7c0e72f63ce80fvboxsync ~0U, /* 7 - invalid */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Macro for fast recode of the operand size (1/2/4/8 bytes) to bit shift value.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * Deals with complicated MMIO writes.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * Complicated means unaligned or non-dword/qword sized accesses depending on
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * the MMIO region's access mode flags.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * @returns Strict VBox status code. Any EM scheduling status code,
648b0a0e189323afe4d836f1848f82c7dded0e58vboxsync * VINF_IOM_R3_MMIO_WRITE, VINF_IOM_R3_MMIO_READ_WRITE or
648b0a0e189323afe4d836f1848f82c7dded0e58vboxsync * VINF_IOM_R3_MMIO_READ may be returned.
4bfa7b58e362a1bca0628643c352c137900bf01avboxsync * @param pVM Pointer to the VM.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * @param pRange The range to write to.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * @param GCPhys The physical address to start writing.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * @param pvValue Where to store the value.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * @param cbValue The size of the value to write.
ad9297dbc9565afa293c95d8a3eb2cc4bbaffe27vboxsyncstatic VBOXSTRICTRC iomMMIODoComplicatedWrite(PVM pVM, PIOMMMIORANGE pRange, RTGCPHYS GCPhys, void const *pvValue, unsigned cbValue)
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync AssertReturn( (pRange->fFlags & IOMMMIO_FLAGS_WRITE_MODE) != IOMMMIO_FLAGS_WRITE_PASSTHRU
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync || (pRange->fFlags & IOMMMIO_FLAGS_WRITE_MODE) <= IOMMMIO_FLAGS_WRITE_DWORD_QWORD_READ_MISSING,
683371bbf37760161d1b8454ce978acf89bbb04fvboxsync AssertReturn(cbValue != 0 && cbValue <= 16, VERR_IOM_MMIO_IPE_2);
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync RTGCPHYS const GCPhysStart = GCPhys; NOREF(GCPhysStart);
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync bool const fReadMissing = (pRange->fFlags & IOMMMIO_FLAGS_WRITE_MODE) == IOMMMIO_FLAGS_WRITE_DWORD_READ_MISSING
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync || (pRange->fFlags & IOMMMIO_FLAGS_WRITE_MODE) == IOMMMIO_FLAGS_WRITE_DWORD_QWORD_READ_MISSING;
ad9297dbc9565afa293c95d8a3eb2cc4bbaffe27vboxsync * Do debug stop if requested.
ad9297dbc9565afa293c95d8a3eb2cc4bbaffe27vboxsync if (pRange->fFlags & IOMMMIO_FLAGS_DBGSTOP_ON_COMPLICATED_WRITE)
ad9297dbc9565afa293c95d8a3eb2cc4bbaffe27vboxsync rc = DBGFR3EventSrc(pVM, DBGFEVENT_DEV_STOP, RT_SRC_POS,
648b0a0e189323afe4d836f1848f82c7dded0e58vboxsync "Complicated write %#x byte at %RGp to %s\n", cbValue, GCPhys, R3STRING(pRange->pszDesc));
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * Check if we should ignore the write.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync if ((pRange->fFlags & IOMMMIO_FLAGS_WRITE_MODE) == IOMMMIO_FLAGS_WRITE_ONLY_DWORD)
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync if ((pRange->fFlags & IOMMMIO_FLAGS_WRITE_MODE) == IOMMMIO_FLAGS_WRITE_ONLY_DWORD_QWORD)
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync Assert((cbValue != 4 && cbValue != 8) || (GCPhys & (cbValue - 1)));
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * Split and conquer.
648b0a0e189323afe4d836f1848f82c7dded0e58vboxsync * Get the missing bits (if any).
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync int rc2 = pRange->CTX_SUFF(pfnReadCallback)(pRange->CTX_SUFF(pDevIns), pRange->CTX_SUFF(pvUser),
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync GCPhys & ~(RTGCPHYS)3, &u32MissingValue, sizeof(u32MissingValue));
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync /** @todo What if we've split a transfer and already read
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * something? Since writes generally have sideeffects we
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * could be kind of screwed here...
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * Fix: Save the current state and resume it in ring-3. Requires EM to not go
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * to REM for MMIO accesses (like may currently do). */
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync LogFlow(("iomMMIODoComplicatedWrite: GCPhys=%RGp GCPhysStart=%RGp cbValue=%u rc=%Rrc [read]\n", GCPhys, GCPhysStart, cbValue, rc2));
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync Log(("iomMMIODoComplicatedWrite: GCPhys=%RGp GCPhysStart=%RGp cbValue=%u rc=%Rrc [read]\n", GCPhys, GCPhysStart, cbValue, rc2));
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync AssertMsgReturn(rc2 >= VINF_EM_FIRST && rc2 <= VINF_EM_LAST, ("%Rrc\n", rc2), VERR_IPE_UNEXPECTED_INFO_STATUS);
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * Merge missing and given bits.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync u32GivenValue = RT_MAKE_U32_FROM_U8(((uint8_t const *)pvValue)[0], ((uint8_t const *)pvValue)[1],
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync uint32_t u32Value = (u32MissingValue & ~u32GivenMask)
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * Do DWORD write to the device.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync int rc2 = pRange->CTX_SUFF(pfnWriteCallback)(pRange->CTX_SUFF(pDevIns), pRange->CTX_SUFF(pvUser),
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync GCPhys & ~(RTGCPHYS)3, &u32Value, sizeof(u32Value));
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync /** @todo What if we've split a transfer and already read
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * something? Since reads can have sideeffects we could be
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * kind of screwed here...
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * Fix: Save the current state and resume it in ring-3. Requires EM to not go
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * to REM for MMIO accesses (like may currently do). */
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync LogFlow(("iomMMIODoComplicatedWrite: GCPhys=%RGp GCPhysStart=%RGp cbValue=%u rc=%Rrc [write]\n", GCPhys, GCPhysStart, cbValue, rc2));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("iomMMIODoComplicatedWrite: GCPhys=%RGp GCPhysStart=%RGp cbValue=%u rc=%Rrc [write]\n", GCPhys, GCPhysStart, cbValue, rc2));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsgReturn(rc2 >= VINF_EM_FIRST && rc2 <= VINF_EM_LAST, ("%Rrc\n", rc2), VERR_IPE_UNEXPECTED_INFO_STATUS);
3242fe628b2306c050fb28c489d50bc63118f0c5vboxsync * Wrapper which does the write and updates range statistics when such are enabled.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * @warning RT_SUCCESS(rc=VINF_IOM_R3_MMIO_WRITE) is TRUE!
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsyncstatic int iomMMIODoWrite(PVM pVM, PIOMMMIORANGE pRange, RTGCPHYS GCPhysFault, const void *pvData, unsigned cb)
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync PIOMMMIOSTATS pStats = iomMmioGetStats(pVM, GCPhysFault, pRange);
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfWrite), a);
4bfa7b58e362a1bca0628643c352c137900bf01avboxsync || (pRange->fFlags & IOMMMIO_FLAGS_WRITE_MODE) == IOMMMIO_FLAGS_WRITE_PASSTHRU
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync || (cb == 8 && !(GCPhysFault & 7) && IOMMMIO_DOES_WRITE_MODE_ALLOW_QWORD(pRange->fFlags)) )
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync rc = pRange->CTX_SUFF(pfnWriteCallback)(pRange->CTX_SUFF(pDevIns), pRange->CTX_SUFF(pvUser),
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync GCPhysFault, (void *)pvData, cb); /** @todo fix const!! */
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync rc = iomMMIODoComplicatedWrite(pVM, pRange, GCPhysFault, pvData, cb);
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfWrite), a);
ad9297dbc9565afa293c95d8a3eb2cc4bbaffe27vboxsync * Deals with complicated MMIO reads.
ad9297dbc9565afa293c95d8a3eb2cc4bbaffe27vboxsync * Complicatd means unaligned or non-dword/qword align accesses depending on
3c3fadf5aeb22d1e9869e5fd72bdd6b1ebd4d4acvboxsync * the MMIO region's access mode flags.
ad9297dbc9565afa293c95d8a3eb2cc4bbaffe27vboxsync * @returns Strict VBox status code. Any EM scheduling status code,
ad9297dbc9565afa293c95d8a3eb2cc4bbaffe27vboxsync * VINF_IOM_R3_MMIO_READ, VINF_IOM_R3_MMIO_READ_WRITE or
ad9297dbc9565afa293c95d8a3eb2cc4bbaffe27vboxsync * VINF_IOM_R3_MMIO_WRITE may be returned.
ad9297dbc9565afa293c95d8a3eb2cc4bbaffe27vboxsync * @param pVM Pointer to the VM.
ad9297dbc9565afa293c95d8a3eb2cc4bbaffe27vboxsync * @param pRange The range to read from.
ad9297dbc9565afa293c95d8a3eb2cc4bbaffe27vboxsync * @param GCPhys The physical address to start reading.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * @param pvValue Where to store the value.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * @param cbValue The size of the value to read.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsyncstatic VBOXSTRICTRC iomMMIODoComplicatedRead(PVM pVM, PIOMMMIORANGE pRange, RTGCPHYS GCPhys, void *pvValue, unsigned cbValue)
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync AssertReturn( (pRange->fFlags & IOMMMIO_FLAGS_READ_MODE) == IOMMMIO_FLAGS_READ_DWORD
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync || (pRange->fFlags & IOMMMIO_FLAGS_READ_MODE) == IOMMMIO_FLAGS_READ_DWORD_QWORD,
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync AssertReturn(cbValue != 0 && cbValue <= 16, VERR_IOM_MMIO_IPE_2);
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync RTGCPHYS const GCPhysStart = GCPhys; NOREF(GCPhysStart);
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * Do debug stop if requested.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync if (pRange->fFlags & IOMMMIO_FLAGS_DBGSTOP_ON_COMPLICATED_READ)
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync rc = DBGFR3EventSrc(pVM, DBGFEVENT_DEV_STOP, RT_SRC_POS,
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync "Complicated read %#x byte at %RGp to %s\n", cbValue, GCPhys, R3STRING(pRange->pszDesc));
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * Split and conquer.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * Do DWORD read from the device.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync int rc2 = pRange->CTX_SUFF(pfnReadCallback)(pRange->CTX_SUFF(pDevIns), pRange->CTX_SUFF(pvUser),
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync GCPhys & ~(RTGCPHYS)3, &u32Value, sizeof(u32Value));
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync /** @todo What if we've split a transfer and already read
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * something? Since reads can have sideeffects we could be
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * kind of screwed here... */
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync LogFlow(("iomMMIODoComplicatedRead: GCPhys=%RGp GCPhysStart=%RGp cbValue=%u rc=%Rrc\n", GCPhys, GCPhysStart, cbValue, rc2));
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync Log(("iomMMIODoComplicatedRead: GCPhys=%RGp GCPhysStart=%RGp cbValue=%u rc=%Rrc\n", GCPhys, GCPhysStart, cbValue, rc2));
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync AssertMsgReturn(rc2 >= VINF_EM_FIRST && rc2 <= VINF_EM_LAST, ("%Rrc\n", rc2), VERR_IPE_UNEXPECTED_INFO_STATUS);
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * Write what we've read.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * Implements VINF_IOM_MMIO_UNUSED_FF.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * @returns VINF_SUCCESS.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * @param pvValue Where to store the zeros.
fa7ed0e340622064310fc195e6ae1ae6e6974a30vboxsync * @param cbValue How many bytes to read.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsyncstatic int iomMMIODoReadFFs(void *pvValue, size_t cbValue)
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync case 1: *(uint8_t *)pvValue = UINT8_C(0xff); break;
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync case 2: *(uint16_t *)pvValue = UINT16_C(0xffff); break;
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync case 4: *(uint32_t *)pvValue = UINT32_C(0xffffffff); break;
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync case 8: *(uint64_t *)pvValue = UINT64_C(0xffffffffffffffff); break;
05406988cc320ac1b0971de976b6cf0c986044a9vboxsync * Implements VINF_IOM_MMIO_UNUSED_00.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VINF_SUCCESS.
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * @param pvValue Where to store the zeros.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * @param cbValue How many bytes to read.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsyncstatic int iomMMIODoRead00s(void *pvValue, size_t cbValue)
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync case 1: *(uint8_t *)pvValue = UINT8_C(0x00); break;
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync case 2: *(uint16_t *)pvValue = UINT16_C(0x0000); break;
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync case 4: *(uint32_t *)pvValue = UINT32_C(0x00000000); break;
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync case 8: *(uint64_t *)pvValue = UINT64_C(0x0000000000000000); break;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Wrapper which does the read and updates range statistics when such are enabled.
3242fe628b2306c050fb28c489d50bc63118f0c5vboxsyncDECLINLINE(int) iomMMIODoRead(PVM pVM, PIOMMMIORANGE pRange, RTGCPHYS GCPhys, void *pvValue, unsigned cbValue)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PIOMMMIOSTATS pStats = iomMmioGetStats(pVM, GCPhys, pRange);
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfRead), a);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync || (pRange->fFlags & IOMMMIO_FLAGS_READ_MODE) == IOMMMIO_FLAGS_READ_PASSTHRU
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync rc = pRange->CTX_SUFF(pfnReadCallback)(pRange->CTX_SUFF(pDevIns), pRange->CTX_SUFF(pvUser), GCPhys, pvValue, cbValue);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = iomMMIODoComplicatedRead(pVM, pRange, GCPhys, pvValue, cbValue);
23de3d76e5d27015e334e6ff763ab08de5969363vboxsync case VINF_IOM_MMIO_UNUSED_FF: rc = iomMMIODoReadFFs(pvValue, cbValue); break;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync case VINF_IOM_MMIO_UNUSED_00: rc = iomMMIODoRead00s(pvValue, cbValue); break;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfRead), a);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Internal - statistics only.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) iomMMIOStatLength(PVM pVM, unsigned cb)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* No way. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * MOV reg, mem (read)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * MOVZX reg, mem (read)
fe95fa9fc2a364e3d678307971cc900b89f5c94avboxsync * MOVSX reg, mem (read)
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The virtual machine.
61e80138f3c5ea5213990bde94a973c8e64d1dadvboxsync * @param pRegFrame Pointer to CPUMCTXCORE guest registers structure.
61e80138f3c5ea5213990bde94a973c8e64d1dadvboxsync * @param pCpu Disassembler CPU state.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRange Pointer MMIO range.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int iomInterpretMOVxXRead(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu, PIOMMMIORANGE pRange, RTGCPHYS GCPhysFault)
61e80138f3c5ea5213990bde94a973c8e64d1dadvboxsync Assert(pRange->CTX_SUFF(pfnReadCallback) || !pRange->pfnReadCallbackR3);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Get the data size from parameter 2,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * and call the handler function to get the data.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync unsigned cb = DISGetParamSize(pCpu, &pCpu->Param2);
2309a5a68c254f4881841fbf8118e899c32d7385vboxsync AssertMsg(cb > 0 && cb <= sizeof(uint64_t), ("cb=%d\n", cb));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &u64Data, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Do sign extension for MOVSX.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo checkup MOVSX implementation! */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* DWORD <- BYTE */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* DWORD <- WORD */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Store the result to register (parameter 1).
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync bool fRc = iomSaveDataToReg(pCpu, &pCpu->Param1, pRegFrame, u64Data);
be9bc9b4ba510c4b4159c193f783d024633ef8e9vboxsync AssertMsg(fRc, ("Failed to store register value!\n")); NOREF(fRc);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * MOV mem, reg|imm (write)
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync * @returns VBox status code.
090f6abdd6282f48527b83162b8b441425f05e36vboxsync * @param pVM The virtual machine.
090f6abdd6282f48527b83162b8b441425f05e36vboxsync * @param pRegFrame Pointer to CPUMCTXCORE guest registers structure.
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync * @param pCpu Disassembler CPU state.
2afbe132eb7931e0125141eabe3a48e08f1ffab5vboxsync * @param pRange Pointer MMIO range.
9371df33e2b99a59304093df9f492440fdbff171vboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
9371df33e2b99a59304093df9f492440fdbff171vboxsyncstatic int iomInterpretMOVxXWrite(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu, PIOMMMIORANGE pRange, RTGCPHYS GCPhysFault)
9371df33e2b99a59304093df9f492440fdbff171vboxsync Assert(pRange->CTX_SUFF(pfnWriteCallback) || !pRange->pfnWriteCallbackR3);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Get data to write from second parameter,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * and call the callback to write it.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync unsigned cb = 0;
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync bool fRc = iomGetRegImmData(pCpu, &pCpu->Param2, pRegFrame, &u64Data, &cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(fRc, ("Failed to get reg/imm port number!\n")); NOREF(fRc);
090f6abdd6282f48527b83162b8b441425f05e36vboxsync int rc = iomMMIODoWrite(pVM, pRange, GCPhysFault, &u64Data, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync/** Wrapper for reading virtual memory. */
090f6abdd6282f48527b83162b8b441425f05e36vboxsyncDECLINLINE(int) iomRamRead(PVMCPU pVCpu, void *pDest, RTGCPTR GCSrc, uint32_t cb)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Note: This will fail in R0 or RC if it hits an access handler. That
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync isn't a problem though since the operation can be restarted in REM. */
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync int rc = MMGCRamReadNoTrapHandler(pDest, (void *)(uintptr_t)GCSrc, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Page may be protected and not directly accessible. */
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync/** Wrapper for writing virtual memory. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(int) iomRamWrite(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, RTGCPTR GCPtrDst, void *pvSrc, uint32_t cb)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo Need to update PGMVerifyAccess to take access handlers into account for Ring-0 and
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * raw mode code. Some thought needs to be spent on theoretical concurrency issues as
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * as well since we're not behind the pgm lock and handler may change between calls.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * PGMPhysInterpretedWriteNoHandlers/PGMPhysWriteGCPtr may mess up
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * the state of some shadowed structures. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return PGMPhysInterpretedWriteNoHandlers(pVCpu, pCtxCore, GCPtrDst, pvSrc, cb, false /*fRaiseTrap*/);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return PGMPhysWriteGCPtr(pVCpu, GCPtrDst, pvSrc, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#if defined(IOM_WITH_MOVS_SUPPORT) && 0 /* locking prevents this from working. has buggy ecx handling. */
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync * [REP] MOVSB
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * [REP] MOVSW
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * [REP] MOVSD
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Restricted implementation.
0ebb1ef53864eb9cc97580f722288c9b29bc5d03vboxsync * @returns VBox status code.
0ebb1ef53864eb9cc97580f722288c9b29bc5d03vboxsync * @param pVM The virtual machine.
0ebb1ef53864eb9cc97580f722288c9b29bc5d03vboxsync * @param uErrorCode CPU Error code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRegFrame Trap register frame.
98502a585f6eda30527b54f7df18dd3de3d3d7c6vboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
a44cdd0b29504e3de7b8aa87f839ad62b6e66f51vboxsync * @param pCpu Disassembler CPU state.
a44cdd0b29504e3de7b8aa87f839ad62b6e66f51vboxsync * @param pRange Pointer MMIO range.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param ppStat Which sub-sample to attribute this call to.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int iomInterpretMOVS(PVM pVM, bool fWriteAccess, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, PIOMMMIORANGE pRange,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * We do not support segment prefixes or REPNE.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (pCpu->fPrefix & (DISPREFIX_SEG | DISPREFIX_REPNE))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return VINF_IOM_R3_MMIO_READ_WRITE; /** @todo -> interpret whatever. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (SELMGetCpuModeFromSelector(pVM, pRegFrame->eflags, pRegFrame->cs, &pRegFrame->csHid) == DISCPUMODE_16BIT)
648b0a0e189323afe4d836f1848f82c7dded0e58vboxsync /* Get the current privilege level. */
dcc035155cdf232a3d79024f475c2d4448981e85vboxsync * Get data size.
a64bf60e92e5cb8a76aa6c8e92193932d88a906fvboxsync unsigned cb = DISGetParamSize(pCpu, &pCpu->Param1);
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync AssertMsg(cb > 0 && cb <= sizeof(uint64_t), ("cb=%d\n", cb));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int offIncrement = pRegFrame->eflags.Bits.u1DF ? -(signed)cb : (signed)cb;
d45f7f7fe0c28b500b45b2dc88d7a04f4c0be6b8vboxsync if (pVM->iom.s.cMovsMaxBytes < (cTransfers << SIZE_2_SHIFT(cb)))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pVM->iom.s.cMovsMaxBytes = cTransfers << SIZE_2_SHIFT(cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync/** @todo re-evaluate on page boundaries. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Write operation: [Mem] -> [MMIO]
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * ds:esi (Virt Src) -> es:edi (Phys Dst)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_STATS({ *ppStat = &pVM->iom.s.StatRZInstMovsToMMIO; });
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Check callback. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Convert source address ds:esi. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = SELMToFlatEx(pVM, DISSELREG_DS, pRegFrame, (RTGCPTR)pRegFrame->rsi,
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync /* Access verification first; we currently can't recover properly from traps inside this instruction */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = PGMVerifyAccess(pVCpu, pu8Virt, cTransfers * cb, (cpl == 3) ? X86_PTE_US : 0);
f3701698f9d61fed78c320c3b35c64a0c63d6db1vboxsync Log(("MOVS will generate a trap -> recompiler, rc=%d\n", rc));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* copy loop. */
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync rc = iomRamRead(pVCpu, &u32Data, (RTGCPTR)pu8Virt, cb);
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync rc = iomMMIODoWrite(pVM, pRange, Phys, &u32Data, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Update ecx. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Read operation: [MMIO] -> [mem] or [MMIO] -> [MMIO]
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * ds:[eSI] (Phys Src) -> es:[eDI] (Virt Dst)
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync STAM_STATS({ *ppStat = &pVM->iom.s.StatRZInstMovsFromMMIO; });
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync /* Check callback. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Convert destination address. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = SELMToFlatEx(pVM, DISSELREG_ES, pRegFrame, (RTGCPTR)pRegFrame->rdi,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Check if destination address is MMIO. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = PGMGstGetPage(pVCpu, (RTGCPTR)pu8Virt, NULL, &PhysDst);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PhysDst |= (RTGCUINTPTR)pu8Virt & PAGE_OFFSET_MASK;
13d75a5db336ccb682d7ab28b397a4f0b8982ea3vboxsync && (pMMIODst = iomMmioGetRangeWithRef(pVM, PhysDst)))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo implement per-device locks for MMIO access. */
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync Assert(!pMMIODst->CTX_SUFF(pDevIns)->CTX_SUFF(pCritSect));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Extra: [MMIO] -> [MMIO]
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_STATS({ *ppStat = &pVM->iom.s.StatRZInstMovsMMIO; });
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (!pMMIODst->CTX_SUFF(pfnWriteCallback) && pMMIODst->pfnWriteCallbackR3)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* copy loop. */
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync rc = iomMMIODoRead(pVM, pRange, Phys, &u32Data, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = iomMMIODoWrite(pVM, pMMIODst, PhysDst, &u32Data, cb);
13d75a5db336ccb682d7ab28b397a4f0b8982ea3vboxsync * Normal: [MMIO] -> [Mem]
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Access verification first; we currently can't recover properly from traps inside this instruction */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = PGMVerifyAccess(pVCpu, pu8Virt, cTransfers * cb, X86_PTE_RW | ((cpl == 3) ? X86_PTE_US : 0));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("MOVS will generate a trap -> recompiler, rc=%d\n", rc));
f3701698f9d61fed78c320c3b35c64a0c63d6db1vboxsync /* copy loop. */
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync rc = iomMMIODoRead(pVM, pRange, Phys, &u32Data, cb);
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync rc = iomRamWrite(pVCpu, pRegFrame, (RTGCPTR)pu8Virt, &u32Data, cb);
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync Log(("iomRamWrite %08X size=%d failed with %d\n", pu8Virt, cb, rc));
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync /* Update ecx on exit. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* work statistics. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#endif /* IOM_WITH_MOVS_SUPPORT */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Gets the address / opcode mask corresponding to the given CPU mode.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns Mask.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param enmCpuMode CPU mode.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsyncstatic uint64_t iomDisModeToMask(DISCPUMODE enmCpuMode)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * [REP] STOSB
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync * [REP] STOSW
559419830ee63b8481ade36d8994f235932aae49vboxsync * [REP] STOSD
0ebb1ef53864eb9cc97580f722288c9b29bc5d03vboxsync * Restricted implementation.
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The virtual machine.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRegFrame Trap register frame.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync * @param pCpu Disassembler CPU state.
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync * @param pRange Pointer MMIO range.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int iomInterpretSTOS(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, PIOMMMIORANGE pRange)
332ccb6ac6feb4b50ec24d63ff029119164182ffvboxsync * We do not support segment prefixes or REPNE..
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (pCpu->fPrefix & (DISPREFIX_SEG | DISPREFIX_REPNE))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return VINF_IOM_R3_MMIO_READ_WRITE; /** @todo -> REM instead of HC */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync uint64_t const fAddrMask = iomDisModeToMask((DISCPUMODE)pCpu->uAddrMode);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync/** @todo r=bird: bounds checks! */
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync * Get data size.
f3701698f9d61fed78c320c3b35c64a0c63d6db1vboxsync unsigned cb = DISGetParamSize(pCpu, &pCpu->Param1);
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync AssertMsg(cb > 0 && cb <= sizeof(uint64_t), ("cb=%d\n", cb));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int offIncrement = pRegFrame->eflags.Bits.u1DF ? -(signed)cb : (signed)cb;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (pVM->iom.s.cStosMaxBytes < (cTransfers << SIZE_2_SHIFT(cb)))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pVM->iom.s.cStosMaxBytes = cTransfers << SIZE_2_SHIFT(cb);
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync * Use the fill callback.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo pfnFillCallback must return number of bytes successfully written!!! */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* addr++ variant. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = pRange->CTX_SUFF(pfnFillCallback)(pRange->CTX_SUFF(pDevIns), pRange->CTX_SUFF(pvUser), Phys,
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync /* Update registers. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pRegFrame->rdi = ((pRegFrame->rdi + (cTransfers << SIZE_2_SHIFT(cb))) & fAddrMask)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* addr-- variant. */
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync rc = pRange->CTX_SUFF(pfnFillCallback)(pRange->CTX_SUFF(pDevIns), pRange->CTX_SUFF(pvUser),
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync /* Update registers. */
f3701698f9d61fed78c320c3b35c64a0c63d6db1vboxsync pRegFrame->rdi = ((pRegFrame->rdi - (cTransfers << SIZE_2_SHIFT(cb))) & fAddrMask)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Use the write callback.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(pRange->CTX_SUFF(pfnWriteCallback) || !pRange->pfnWriteCallbackR3);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* fill loop. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = iomMMIODoWrite(pVM, pRange, Phys, &u64Data, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pRegFrame->rdi = ((pRegFrame->rdi + offIncrement) & fAddrMask)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Update rcx on exit. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Work statistics and return.
1df4b0cdc5ec23d817014f9347ef28222b51e3fbvboxsync * [REP] LODSB
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync * [REP] LODSW
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * [REP] LODSD
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Restricted implementation.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
9d4c9e0a3e2dcc3bd19303d7b4e2d96d12c11814vboxsync * @param pVM The virtual machine.
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync * @param pRegFrame Trap register frame.
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync * @param pCpu Disassembler CPU state.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRange Pointer MMIO range.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int iomInterpretLODS(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, PIOMMMIORANGE pRange)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(pRange->CTX_SUFF(pfnReadCallback) || !pRange->pfnReadCallbackR3);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * We do not support segment prefixes or REP*.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (pCpu->fPrefix & (DISPREFIX_SEG | DISPREFIX_REP | DISPREFIX_REPNE))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return VINF_IOM_R3_MMIO_READ_WRITE; /** @todo -> REM instead of HC */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Get data size.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync unsigned cb = DISGetParamSize(pCpu, &pCpu->Param2);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(cb > 0 && cb <= sizeof(uint64_t), ("cb=%d\n", cb));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int offIncrement = pRegFrame->eflags.Bits.u1DF ? -(signed)cb : (signed)cb;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Perform read.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &pRegFrame->rax, cb);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync uint64_t const fAddrMask = iomDisModeToMask((DISCPUMODE)pCpu->uAddrMode);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pRegFrame->rsi = ((pRegFrame->rsi + offIncrement) & fAddrMask)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Work statistics and return.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * CMP [MMIO], reg|imm
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync * CMP reg|imm, [MMIO]
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Restricted implementation.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The virtual machine.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRegFrame Trap register frame.
0f8b9243304469cd1e58d6986931bbfed5ba359evboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
0f8b9243304469cd1e58d6986931bbfed5ba359evboxsync * @param pCpu Disassembler CPU state.
0f8b9243304469cd1e58d6986931bbfed5ba359evboxsync * @param pRange Pointer MMIO range.
0f8b9243304469cd1e58d6986931bbfed5ba359evboxsyncstatic int iomInterpretCMP(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, PIOMMMIORANGE pRange)
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync Assert(pRange->CTX_SUFF(pfnReadCallback) || !pRange->pfnReadCallbackR3);
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync * Get the operands.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync unsigned cb = 0;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (iomGetRegImmData(pCpu, &pCpu->Param1, pRegFrame, &uData1, &cb))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* cmp reg, [MMIO]. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &uData2, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync else if (iomGetRegImmData(pCpu, &pCpu->Param2, pRegFrame, &uData2, &cb))
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync /* cmp [MMIO], reg|imm. */
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &uData1, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Can't deal with 8 byte operands in our 32-bit emulation code. */
ab0130d1627b2b214952b929de71b89e4ba41eb1vboxsync /* Emulate CMP and update guest flags. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync uint32_t eflags = EMEmulateCmp(uData1, uData2, cb);
9f16100a870e25701da9bc9819e15c0f9fb3870evboxsync pRegFrame->eflags.u32 = (pRegFrame->eflags.u32 & ~(X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF))
9f16100a870e25701da9bc9819e15c0f9fb3870evboxsync | (eflags & (X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF));
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync * AND [MMIO], reg|imm
fe95fa9fc2a364e3d678307971cc900b89f5c94avboxsync * AND reg, [MMIO]
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync * OR [MMIO], reg|imm
fe95fa9fc2a364e3d678307971cc900b89f5c94avboxsync * OR reg, [MMIO]
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync * Restricted implementation.
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The virtual machine.
0f8b9243304469cd1e58d6986931bbfed5ba359evboxsync * @param pRegFrame Trap register frame.
0f8b9243304469cd1e58d6986931bbfed5ba359evboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
0f8b9243304469cd1e58d6986931bbfed5ba359evboxsync * @param pCpu Disassembler CPU state.
648b0a0e189323afe4d836f1848f82c7dded0e58vboxsync * @param pRange Pointer MMIO range.
0f8b9243304469cd1e58d6986931bbfed5ba359evboxsync * @param pfnEmulate Instruction emulation function.
323b78bf4831666c95416edf3b6e54657a769e5dvboxsyncstatic int iomInterpretOrXorAnd(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, PIOMMMIORANGE pRange, PFNEMULATEPARAM3 pfnEmulate)
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync unsigned cb = 0;
648b0a0e189323afe4d836f1848f82c7dded0e58vboxsync const char *pszInstr;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (iomGetRegImmData(pCpu, &pCpu->Param1, pRegFrame, &uData1, &cb))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Can't deal with 8 byte operands in our 32-bit emulation code. */
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync /* and reg, [MMIO]. */
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync Assert(pRange->CTX_SUFF(pfnReadCallback) || !pRange->pfnReadCallbackR3);
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &uData2, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync else if (iomGetRegImmData(pCpu, &pCpu->Param2, pRegFrame, &uData2, &cb))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Can't deal with 8 byte operands in our 32-bit emulation code. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* and [MMIO], reg|imm. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ( (pRange->CTX_SUFF(pfnReadCallback) || !pRange->pfnReadCallbackR3)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync && (pRange->CTX_SUFF(pfnWriteCallback) || !pRange->pfnWriteCallbackR3))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &uData1, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Emulate AND and update guest flags. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync uint32_t eflags = pfnEmulate((uint32_t *)&uData1, uData2, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("iomInterpretOrXorAnd %s result %RX64\n", pszInstr, uData1));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Store result to MMIO. */
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync rc = iomMMIODoWrite(pVM, pRange, GCPhysFault, &uData1, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Store result to register. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync bool fRc = iomSaveDataToReg(pCpu, &pCpu->Param1, pRegFrame, uData1);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(fRc, ("Failed to store register value!\n")); NOREF(fRc);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Update guest's eflags and finish. */
9f16100a870e25701da9bc9819e15c0f9fb3870evboxsync pRegFrame->eflags.u32 = (pRegFrame->eflags.u32 & ~(X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF))
9f16100a870e25701da9bc9819e15c0f9fb3870evboxsync | (eflags & (X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * TEST [MMIO], reg|imm
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * TEST reg, [MMIO]
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Restricted implementation.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The virtual machine.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRegFrame Trap register frame.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pCpu Disassembler CPU state.
0f8b9243304469cd1e58d6986931bbfed5ba359evboxsync * @param pRange Pointer MMIO range.
0f8b9243304469cd1e58d6986931bbfed5ba359evboxsyncstatic int iomInterpretTEST(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, PIOMMMIORANGE pRange)
0f8b9243304469cd1e58d6986931bbfed5ba359evboxsync Assert(pRange->CTX_SUFF(pfnReadCallback) || !pRange->pfnReadCallbackR3);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync unsigned cb = 0;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (iomGetRegImmData(pCpu, &pCpu->Param1, pRegFrame, &uData1, &cb))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* and test, [MMIO]. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &uData2, cb);
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync else if (iomGetRegImmData(pCpu, &pCpu->Param2, pRegFrame, &uData2, &cb))
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync /* test [MMIO], reg|imm. */
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &uData1, cb);
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync /* Can't deal with 8 byte operands in our 32-bit emulation code. */
1f24d758b35a86f1075a86a4760da9bbc1e80229vboxsync /* Emulate TEST (=AND without write back) and update guest EFLAGS. */
1f24d758b35a86f1075a86a4760da9bbc1e80229vboxsync uint32_t eflags = EMEmulateAnd((uint32_t *)&uData1, uData2, cb);
1f24d758b35a86f1075a86a4760da9bbc1e80229vboxsync pRegFrame->eflags.u32 = (pRegFrame->eflags.u32 & ~(X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF))
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync | (eflags & (X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF));
1f24d758b35a86f1075a86a4760da9bbc1e80229vboxsync * BT [MMIO], reg|imm
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync * Restricted implementation.
1f24d758b35a86f1075a86a4760da9bbc1e80229vboxsync * @returns VBox status code.
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync * @param pVM The virtual machine.
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync * @param pRegFrame Trap register frame.
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync * @param pCpu Disassembler CPU state.
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync * @param pRange Pointer MMIO range.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int iomInterpretBT(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, PIOMMMIORANGE pRange)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(pRange->CTX_SUFF(pfnReadCallback) || !pRange->pfnReadCallbackR3);
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync if (!iomGetRegImmData(pCpu, &pCpu->Param2, pRegFrame, &uBit, &cbIgnored))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* The size of the memory operand only matters here. */
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync unsigned cbData = DISGetParamSize(pCpu, &pCpu->Param1);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync /* bt [MMIO], reg|imm. */
96dce0123cc032388e78766d08f9ee5a66b80facvboxsync int rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &uData, cbData);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Find the bit inside the faulting address */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * XCHG [MMIO], reg
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * XCHG reg, [MMIO]
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync * Restricted implementation.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
2309a5a68c254f4881841fbf8118e899c32d7385vboxsync * @param pVM The virtual machine.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRegFrame Trap register frame.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pCpu Disassembler CPU state.
648b0a0e189323afe4d836f1848f82c7dded0e58vboxsync * @param pRange Pointer MMIO range.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int iomInterpretXCHG(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, PIOMMMIORANGE pRange)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Check for read & write handlers since IOMMMIOHandler doesn't cover this. */
2309a5a68c254f4881841fbf8118e899c32d7385vboxsync if ( (!pRange->CTX_SUFF(pfnReadCallback) && pRange->pfnReadCallbackR3)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync || (!pRange->CTX_SUFF(pfnWriteCallback) && pRange->pfnWriteCallbackR3))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync unsigned cb = 0;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (iomGetRegImmData(pCpu, &pCpu->Param1, pRegFrame, &uData1, &cb))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* xchg reg, [MMIO]. */
2309a5a68c254f4881841fbf8118e899c32d7385vboxsync rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &uData2, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Store result to MMIO. */
648b0a0e189323afe4d836f1848f82c7dded0e58vboxsync rc = iomMMIODoWrite(pVM, pRange, GCPhysFault, &uData1, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Store result to register. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync bool fRc = iomSaveDataToReg(pCpu, &pCpu->Param1, pRegFrame, uData2);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(fRc, ("Failed to store register value!\n")); NOREF(fRc);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(rc == VINF_IOM_R3_MMIO_WRITE || rc == VINF_PATM_HC_MMIO_PATCH_WRITE);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(rc == VINF_IOM_R3_MMIO_READ || rc == VINF_PATM_HC_MMIO_PATCH_READ);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync else if (iomGetRegImmData(pCpu, &pCpu->Param2, pRegFrame, &uData2, &cb))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* xchg [MMIO], reg. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &uData1, cb);
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync /* Store result to MMIO. */
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync rc = iomMMIODoWrite(pVM, pRange, GCPhysFault, &uData2, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Store result to register. */
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync bool fRc = iomSaveDataToReg(pCpu, &pCpu->Param2, pRegFrame, uData1);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(fRc, ("Failed to store register value!\n")); NOREF(fRc);
22408fe91738075b3c413b14a421d641aacad508vboxsync AssertMsg(rc == VINF_IOM_R3_MMIO_READ_WRITE || rc == VINF_IOM_R3_MMIO_WRITE || rc == VINF_PATM_HC_MMIO_PATCH_WRITE, ("rc=%Rrc\n", rc));
22408fe91738075b3c413b14a421d641aacad508vboxsync AssertMsg(rc == VINF_IOM_R3_MMIO_READ_WRITE || rc == VINF_IOM_R3_MMIO_READ || rc == VINF_PATM_HC_MMIO_PATCH_READ, ("rc=%Rrc\n", rc));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * \#PF Handler callback for MMIO ranges.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code (appropriate for GC return).
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * @param pVM Pointer to the VM.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * @param uErrorCode CPU Error code. This is UINT32_MAX when we don't have
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * any error code (the EPT misconfig hack).
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * @param pCtxCore Trap register frame.
188ea1a2ae27e2575ff4361c41b368f29128a8c5vboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * @param pvUser Pointer to the MMIO ring-3 range entry.
323b78bf4831666c95416edf3b6e54657a769e5dvboxsyncstatic int iomMMIOHandler(PVM pVM, uint32_t uErrorCode, PCPUMCTXCORE pCtxCore, RTGCPHYS GCPhysFault, void *pvUser)
188ea1a2ae27e2575ff4361c41b368f29128a8c5vboxsync /* Take the IOM lock before performing any MMIO. */
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync STAM_PROFILE_START(&pVM->iom.s.StatRZMMIOHandler, a);
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync Log(("iomMMIOHandler: GCPhys=%RGp uErr=%#x rip=%RGv\n",
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync Assert(pRange == iomMmioGetRange(pVM, GCPhysFault));
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync * Locate the statistics, if > PAGE_SIZE we'll use the first byte for everything.
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync PIOMMMIOSTATS pStats = iomMmioGetStats(pVM, GCPhysFault, pRange);
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync STAM_PROFILE_STOP(&pVM->iom.s.StatRZMMIOHandler, a);
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * Should we defer the request right away? This isn't usually the case, so
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * do the simple test first and the try deal with uErrorCode being N/A.
648b0a0e189323afe4d836f1848f82c7dded0e58vboxsync if (RT_UNLIKELY( ( !pRange->CTX_SUFF(pfnWriteCallback)
188ea1a2ae27e2575ff4361c41b368f29128a8c5vboxsync ? pRange->pfnWriteCallbackR3 || pRange->pfnReadCallbackR3
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync ? !pRange->CTX_SUFF(pfnWriteCallback) && pRange->pfnWriteCallbackR3
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync : !pRange->CTX_SUFF(pfnReadCallback) && pRange->pfnReadCallbackR3
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync STAM_PROFILE_STOP(&pVM->iom.s.StatRZMMIOHandler, a);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#endif /* !IN_RING3 */
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * Retain the range and do locking.
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync rc = PDMCritSectEnter(pDevIns->CTX_SUFF(pCritSectRo), VINF_IOM_R3_MMIO_READ_WRITE);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Disassemble the instruction and interpret it.
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync rc = EMInterpretDisasCurrent(pVM, pVCpu, pDis, &cbOp);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync AssertMsg(uErrorCode == UINT32_MAX || DISUSE_IS_EFFECTIVE_ADDR(pDis->Param1.fUse) == !!(uErrorCode & X86_TRAP_PF_RW), ("flags1=%#llx/%RTbool flags2=%#llx/%RTbool ErrCd=%#x\n", pDis->Param1.fUse, DISUSE_IS_EFFECTIVE_ADDR(pDis->Param1.fUse), pDis->Param2.fUse, DISUSE_IS_EFFECTIVE_ADDR(pDis->Param2.fUse), uErrorCode));
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync if (uErrorCode != UINT32_MAX /* EPT+MMIO optimization */
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync rc = iomInterpretMOVxXWrite(pVM, pCtxCore, pDis, pRange, GCPhysFault);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync rc = iomInterpretMOVxXRead(pVM, pCtxCore, pDis, pRange, GCPhysFault);
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync STAM_PROFILE_ADV_START(&pVM->iom.s.StatRZInstMovs, c);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = iomInterpretMOVS(pVM, !!(uErrorCode & X86_TRAP_PF_RW), pCtxCore, GCPhysFault, pDis, pRange, &pStat);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync STAM_PROFILE_ADV_STOP_EX(&pVM->iom.s.StatRZInstMovs, pStat, c);
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync rc = iomInterpretSTOS(pVM, pCtxCore, GCPhysFault, pDis, pRange);
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync Assert(!(uErrorCode & X86_TRAP_PF_RW) || uErrorCode == UINT32_MAX);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync rc = iomInterpretLODS(pVM, pCtxCore, GCPhysFault, pDis, pRange);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync Assert(!(uErrorCode & X86_TRAP_PF_RW) || uErrorCode == UINT32_MAX);
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync rc = iomInterpretCMP(pVM, pCtxCore, GCPhysFault, pDis, pRange);
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync rc = iomInterpretOrXorAnd(pVM, pCtxCore, GCPhysFault, pDis, pRange, EMEmulateAnd);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = iomInterpretOrXorAnd(pVM, pCtxCore, GCPhysFault, pDis, pRange, EMEmulateOr);
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync rc = iomInterpretOrXorAnd(pVM, pCtxCore, GCPhysFault, pDis, pRange, EMEmulateXor);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(!(uErrorCode & X86_TRAP_PF_RW) || uErrorCode == UINT32_MAX);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = iomInterpretTEST(pVM, pCtxCore, GCPhysFault, pDis, pRange);
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync Assert(!(uErrorCode & X86_TRAP_PF_RW) || uErrorCode == UINT32_MAX);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = iomInterpretBT(pVM, pCtxCore, GCPhysFault, pDis, pRange);
648b0a0e189323afe4d836f1848f82c7dded0e58vboxsync rc = iomInterpretXCHG(pVM, pCtxCore, GCPhysFault, pDis, pRange);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * The instruction isn't supported. Hand it on to ring-3.
8bc010ff67963900f9c39d93ce1a64a4e1c08ba1vboxsync * On success advance EIP.
8bc010ff67963900f9c39d93ce1a64a4e1c08ba1vboxsync#if defined(VBOX_WITH_STATISTICS) && !defined(IN_RING3)
fa8716d08ff627a8e1c14bcac56e8e3867b3f795vboxsync STAM_PROFILE_STOP(&pVM->iom.s.StatRZMMIOHandler, a);
d2c6b2e8826a5ef34170fef0c72c3fc7c5c1b46avboxsync * \#PF Handler callback for MMIO ranges.
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync * @returns VBox status code (appropriate for GC return).
648b0a0e189323afe4d836f1848f82c7dded0e58vboxsync * @param pVM Pointer to the VM.
51afd9e19409617e8f3a204d58e96e22ee618e57vboxsync * @param uErrorCode CPU Error code.
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * @param pCtxCore Trap register frame.
188ea1a2ae27e2575ff4361c41b368f29128a8c5vboxsync * @param pvFault The fault address (cr2).
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
8bc010ff67963900f9c39d93ce1a64a4e1c08ba1vboxsync * @param pvUser Pointer to the MMIO ring-3 range entry.
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsyncVMMDECL(int) IOMMMIOHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pCtxCore, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser)
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync LogFlow(("IOMMMIOHandler: GCPhys=%RGp uErr=%#x pvFault=%RGv rip=%RGv\n",
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync GCPhysFault, (uint32_t)uErrorCode, pvFault, (RTGCPTR)pCtxCore->rip));
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync VBOXSTRICTRC rcStrict = iomMMIOHandler(pVM, (uint32_t)uErrorCode, pCtxCore, GCPhysFault, pvUser);
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync * Physical access handler for MMIO ranges.
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync * @returns VBox status code (appropriate for GC return).
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync * @param pVM Pointer to the VM.
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync * @param uErrorCode CPU Error code.
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync * @param pCtxCore Trap register frame.
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * @param GCPhysFault The GC physical address.
e131925debcc0add6ebecf92e6d09d62150476a4vboxsyncVMMDECL(VBOXSTRICTRC) IOMMMIOPhysHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pCtxCore, RTGCPHYS GCPhysFault)
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync VBOXSTRICTRC rcStrict = iomMMIOHandler(pVM, (uint32_t)uErrorCode, pCtxCore, GCPhysFault, iomMmioGetRange(pVM, GCPhysFault));
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * \#PF Handler callback for MMIO ranges.
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * @returns VINF_SUCCESS if the handler have carried out the operation.
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * @returns VINF_PGM_HANDLER_DO_DEFAULT if the caller should carry out the access operation.
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * @param pVM Pointer to the VM.
188ea1a2ae27e2575ff4361c41b368f29128a8c5vboxsync * @param GCPhys The physical address the guest is writing to.
648b0a0e189323afe4d836f1848f82c7dded0e58vboxsync * @param pvPhys The HC mapping of that address.
188ea1a2ae27e2575ff4361c41b368f29128a8c5vboxsync * @param pvBuf What the guest is reading/writing.
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * @param cbBuf How much it's reading/writing.
188ea1a2ae27e2575ff4361c41b368f29128a8c5vboxsync * @param enmAccessType The access type.
188ea1a2ae27e2575ff4361c41b368f29128a8c5vboxsync * @param pvUser Pointer to the MMIO range entry.
e131925debcc0add6ebecf92e6d09d62150476a4vboxsyncDECLCALLBACK(int) IOMR3MMIOHandler(PVM pVM, RTGCPHYS GCPhysFault, void *pvPhys, void *pvBuf, size_t cbBuf,
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync AssertMsg(cbBuf == 1 || cbBuf == 2 || cbBuf == 4 || cbBuf == 8, ("%zu\n", cbBuf));
188ea1a2ae27e2575ff4361c41b368f29128a8c5vboxsync * Validate the range.
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync Assert(pRange == iomMmioGetRange(pVM, GCPhysFault));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Perform locking.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = PDMCritSectEnter(pDevIns->CTX_SUFF(pCritSectRo), VINF_IOM_R3_MMIO_READ_WRITE);
22408fe91738075b3c413b14a421d641aacad508vboxsync * Perform the access.
22408fe91738075b3c413b14a421d641aacad508vboxsync rc = iomMMIODoRead(pVM, pRange, GCPhysFault, pvBuf, (unsigned)cbBuf);
e41f0459369a6d814aa36bf4def225482fc56026vboxsync rc = iomMMIODoWrite(pVM, pRange, GCPhysFault, pvBuf, (unsigned)cbBuf);
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync#endif /* IN_RING3 */
188ea1a2ae27e2575ff4361c41b368f29128a8c5vboxsync * Reads a MMIO register.
22408fe91738075b3c413b14a421d641aacad508vboxsync * @returns VBox status code.
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * @param pVM Pointer to the VM.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * @param GCPhys The physical address to read.
22408fe91738075b3c413b14a421d641aacad508vboxsync * @param pu32Value Where to store the value read.
188ea1a2ae27e2575ff4361c41b368f29128a8c5vboxsync * @param cbValue The size of the register to read in bytes. 1, 2 or 4 bytes.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsyncVMMDECL(VBOXSTRICTRC) IOMMMIORead(PVM pVM, RTGCPHYS GCPhys, uint32_t *pu32Value, size_t cbValue)
648b0a0e189323afe4d836f1848f82c7dded0e58vboxsync /* Take the IOM lock before performing any MMIO. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#if defined(IEM_VERIFICATION_MODE) && defined(IN_RING3)
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * Lookup the current context range node and statistics.
648b0a0e189323afe4d836f1848f82c7dded0e58vboxsync PIOMMMIORANGE pRange = iomMmioGetRange(pVM, GCPhys);
188ea1a2ae27e2575ff4361c41b368f29128a8c5vboxsync AssertMsgFailed(("Handlers and page tables are out of sync or something! GCPhys=%RGp cbValue=%d\n", GCPhys, cbValue));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PIOMMMIOSTATS pStats = iomMmioGetStats(pVM, GCPhys, pRange);
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync#endif /* VBOX_WITH_STATISTICS */
188ea1a2ae27e2575ff4361c41b368f29128a8c5vboxsync * Perform locking.
3242fe628b2306c050fb28c489d50bc63118f0c5vboxsync rc = PDMCritSectEnter(pDevIns->CTX_SUFF(pCritSectRo), VINF_IOM_R3_MMIO_WRITE);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Perform the read and deal with the result.
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfRead), a);
188ea1a2ae27e2575ff4361c41b368f29128a8c5vboxsync || (pRange->fFlags & IOMMMIO_FLAGS_READ_MODE) == IOMMMIO_FLAGS_READ_PASSTHRU
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = pRange->CTX_SUFF(pfnReadCallback)(pRange->CTX_SUFF(pDevIns), pRange->CTX_SUFF(pvUser), GCPhys,
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync rc = iomMMIODoComplicatedRead(pVM, pRange, GCPhys, pu32Value, (unsigned)cbValue);
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfRead), a);
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync Log4(("IOMMMIORead: GCPhys=%RGp *pu32=%08RX32 cb=%d rc=VINF_SUCCESS\n", GCPhys, *pu32Value, cbValue));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("IOMMMIORead: GCPhys=%RGp *pu32=%08RX32 cb=%d rc=%Rrc\n", GCPhys, *pu32Value, cbValue, VBOXSTRICTRC_VAL(rc)));
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync Log4(("IOMMMIORead: GCPhys=%RGp *pu32=%08RX32 cb=%d rc=%Rrc\n", GCPhys, *pu32Value, cbValue, VBOXSTRICTRC_VAL(rc)));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("IOMMMIORead: GCPhys=%RGp *pu32=%08RX32 cb=%d rc=%Rrc\n", GCPhys, *pu32Value, cbValue, VBOXSTRICTRC_VAL(rc)));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* not reached */
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * Unassigned memory - this is actually not supposed t happen...
e41f0459369a6d814aa36bf4def225482fc56026vboxsync STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfRead), a); /** @todo STAM_PROFILE_ADD_ZERO_PERIOD */
e41f0459369a6d814aa36bf4def225482fc56026vboxsync STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfRead), a);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("IOMMMIORead: GCPhys=%RGp *pu32=%08RX32 cb=%d rc=VINF_SUCCESS\n", GCPhys, *pu32Value, cbValue));
188ea1a2ae27e2575ff4361c41b368f29128a8c5vboxsync * Writes to a MMIO register.
22408fe91738075b3c413b14a421d641aacad508vboxsync * @returns VBox status code.
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * @param pVM Pointer to the VM.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * @param GCPhys The physical address to write to.
22408fe91738075b3c413b14a421d641aacad508vboxsync * @param u32Value The value to write.
188ea1a2ae27e2575ff4361c41b368f29128a8c5vboxsync * @param cbValue The size of the register to read in bytes. 1, 2 or 4 bytes.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsyncVMMDECL(VBOXSTRICTRC) IOMMMIOWrite(PVM pVM, RTGCPHYS GCPhys, uint32_t u32Value, size_t cbValue)
648b0a0e189323afe4d836f1848f82c7dded0e58vboxsync /* Take the IOM lock before performing any MMIO. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#if defined(IEM_VERIFICATION_MODE) && defined(IN_RING3)
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync IEMNotifyMMIOWrite(pVM, GCPhys, u32Value, cbValue);
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * Lookup the current context range node.
648b0a0e189323afe4d836f1848f82c7dded0e58vboxsync PIOMMMIORANGE pRange = iomMmioGetRange(pVM, GCPhys);
188ea1a2ae27e2575ff4361c41b368f29128a8c5vboxsync AssertMsgFailed(("Handlers and page tables are out of sync or something! GCPhys=%RGp cbValue=%d\n", GCPhys, cbValue));
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync PIOMMMIOSTATS pStats = iomMmioGetStats(pVM, GCPhys, pRange);
3242fe628b2306c050fb28c489d50bc63118f0c5vboxsync#endif /* VBOX_WITH_STATISTICS */
cea26cf0a0d390c2cca75cb19cb0e86c580e9d77vboxsync * Perform locking.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = PDMCritSectEnter(pDevIns->CTX_SUFF(pCritSectRo), VINF_IOM_R3_MMIO_READ);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Perform the write.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfWrite), a);
3242fe628b2306c050fb28c489d50bc63118f0c5vboxsync || (pRange->fFlags & IOMMMIO_FLAGS_WRITE_MODE) == IOMMMIO_FLAGS_WRITE_PASSTHRU
b3547e42ce5221377866e3fa041b3086b7cc1562vboxsync rc = pRange->CTX_SUFF(pfnWriteCallback)(pRange->CTX_SUFF(pDevIns), pRange->CTX_SUFF(pvUser),
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = iomMMIODoComplicatedWrite(pVM, pRange, GCPhys, &u32Value, (unsigned)cbValue);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfWrite), a);
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync Log4(("IOMMMIOWrite: GCPhys=%RGp u32=%08RX32 cb=%d rc=%Rrc\n", GCPhys, u32Value, cbValue, VBOXSTRICTRC_VAL(rc)));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * No write handler, nothing to do.
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfWrite), a);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfWrite), a);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("IOMMMIOWrite: GCPhys=%RGp u32=%08RX32 cb=%d rc=%Rrc\n", GCPhys, u32Value, cbValue, VINF_SUCCESS));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * ES:EDI,DX[,ECX]
98502a585f6eda30527b54f7df18dd3de3d3d7c6vboxsync * @remark Assumes caller checked the access privileges (IOMInterpretCheckPortIOAccess)
a82df5167acec0c75d741d08c1d05a4007e3d50evboxsync * @returns Strict VBox status code. Informational status codes other than the one documented
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * here are to be treated as internal failure. Use IOM_SUCCESS() to check for success.
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync * @retval VINF_SUCCESS Success.
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync * @retval VINF_EM_FIRST-VINF_EM_LAST Success with some exceptions (see IOM_SUCCESS()), the
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * status code must be passed on to EM.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_IOM_R3_IOPORT_READ Defer the read to ring-3. (R0/GC only)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_EM_RAW_EMULATE_INSTR Defer the read to the REM.
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync * @retval VINF_EM_RAW_GUEST_TRAP The exception was left pending. (TRPMRaiseXcptErr)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_TRPM_XCPT_DISPATCHED The exception was raised and dispatched for raw-mode execution. (TRPMRaiseXcptErr)
98502a585f6eda30527b54f7df18dd3de3d3d7c6vboxsync * @retval VINF_EM_RESCHEDULE_REM The exception was dispatched and cannot be executed in raw-mode. (TRPMRaiseXcptErr)
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync * @param pVM The virtual machine.
559419830ee63b8481ade36d8994f235932aae49vboxsync * @param pRegFrame Pointer to CPUMCTXCORE guest registers structure.
0ebb1ef53864eb9cc97580f722288c9b29bc5d03vboxsync * @param uPort IO Port
0ebb1ef53864eb9cc97580f722288c9b29bc5d03vboxsync * @param uPrefix IO instruction prefix
0ebb1ef53864eb9cc97580f722288c9b29bc5d03vboxsync * @param enmAddrMode The address mode.
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync * @param cbTransfer Size of transfer unit
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncVMMDECL(VBOXSTRICTRC) IOMInterpretINSEx(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t uPort, uint32_t uPrefix,
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync * We do not support REPNE or decrementing destination
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync * pointer. Segment prefixes are deliberately ignored, as per the instruction specification.
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync * Get bytes/words/dwords count to transfer.
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync uint64_t const fAddrMask = iomDisModeToMask(enmAddrMode);
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync /* Convert destination address es:edi. */
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync int rc2 = SELMToFlatEx(pVCpu, DISSELREG_ES, pRegFrame, pRegFrame->rdi & fAddrMask,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("INS destination address conversion failed -> fallback, rc2=%d\n", rc2));
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync /* Access verification first; we can't recover from traps inside this instruction, as the port read cannot be repeated. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc2 = PGMVerifyAccess(pVCpu, (RTGCUINTPTR)GCPtrDst, cTransfers * cbTransfer,
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync Log(("INS will generate a trap -> fallback, rc2=%d\n", rc2));
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync Log(("IOM: rep ins%d port %#x count %d\n", cbTransfer * 8, uPort, cTransfers));
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync /* If the device supports string transfers, ask it to do as
98502a585f6eda30527b54f7df18dd3de3d3d7c6vboxsync * much as it wants. The rest is done with single-word transfers. */
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync rcStrict = IOMIOPortReadString(pVM, uPort, &GCPtrDst, &cTransfers, cbTransfer);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertRC(VBOXSTRICTRC_VAL(rcStrict)); Assert(cTransfers <= cTransfersOrg);
648b0a0e189323afe4d836f1848f82c7dded0e58vboxsync pRegFrame->rdi = ((pRegFrame->rdi + (cTransfersOrg - cTransfers) * cbTransfer) & fAddrMask)
be2589a6f7086676e45b18d204bb1064889dc586vboxsync rcStrict = IOMIOPortRead(pVM, uPort, &u32Value, cbTransfer);
be2589a6f7086676e45b18d204bb1064889dc586vboxsync rc2 = iomRamWrite(pVCpu, pRegFrame, GCPtrDst, &u32Value, cbTransfer);
a82df5167acec0c75d741d08c1d05a4007e3d50evboxsync GCPtrDst = (RTGCPTR)((RTGCUINTPTR)GCPtrDst + cbTransfer);
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync pRegFrame->rdi = ((pRegFrame->rdi + cbTransfer) & fAddrMask)
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync /* Update rcx on exit. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(rcStrict == VINF_SUCCESS || rcStrict == VINF_IOM_R3_IOPORT_READ || (rcStrict >= VINF_EM_FIRST && rcStrict <= VINF_EM_LAST) || RT_FAILURE(rcStrict), ("%Rrc\n", VBOXSTRICTRC_VAL(rcStrict)));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * ES:EDI,DX[,ECX]
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync * @returns Strict VBox status code. Informational status codes other than the one documented
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * here are to be treated as internal failure. Use IOM_SUCCESS() to check for success.
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync * @retval VINF_SUCCESS Success.
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync * @retval VINF_EM_FIRST-VINF_EM_LAST Success with some exceptions (see IOM_SUCCESS()), the
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * status code must be passed on to EM.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_IOM_R3_IOPORT_READ Defer the read to ring-3. (R0/GC only)
9d4c9e0a3e2dcc3bd19303d7b4e2d96d12c11814vboxsync * @retval VINF_EM_RAW_EMULATE_INSTR Defer the read to the REM.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_EM_RAW_GUEST_TRAP The exception was left pending. (TRPMRaiseXcptErr)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_TRPM_XCPT_DISPATCHED The exception was raised and dispatched for raw-mode execution. (TRPMRaiseXcptErr)
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @retval VINF_EM_RESCHEDULE_REM The exception was dispatched and cannot be executed in raw-mode. (TRPMRaiseXcptErr)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The virtual machine.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRegFrame Pointer to CPUMCTXCORE guest registers structure.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pCpu Disassembler CPU state.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncVMMDECL(VBOXSTRICTRC) IOMInterpretINS(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu)
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * Get port number directly from the register (no need to bother the
a82df5167acec0c75d741d08c1d05a4007e3d50evboxsync * disassembler). And get the I/O register size from the opcode / prefix.
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync unsigned cb = 0;
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync cb = (pCpu->uOpMode == DISCPUMODE_16BIT) ? 2 : 4; /* dword in both 32 & 64 bits mode */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync VBOXSTRICTRC rcStrict = IOMInterpretCheckPortIOAccess(pVM, pRegFrame, Port, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(rcStrict == VINF_EM_RAW_GUEST_TRAP || rcStrict == VINF_TRPM_XCPT_DISPATCHED || rcStrict == VINF_TRPM_XCPT_DISPATCHED || RT_FAILURE(rcStrict), ("%Rrc\n", VBOXSTRICTRC_VAL(rcStrict)));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return IOMInterpretINSEx(pVM, pRegFrame, Port, pCpu->fPrefix, (DISCPUMODE)pCpu->uAddrMode, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * DS:ESI,DX[,ECX]
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @remark Assumes caller checked the access privileges (IOMInterpretCheckPortIOAccess)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns Strict VBox status code. Informational status codes other than the one documented
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync * here are to be treated as internal failure. Use IOM_SUCCESS() to check for success.
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync * @retval VINF_SUCCESS Success.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_EM_FIRST-VINF_EM_LAST Success with some exceptions (see IOM_SUCCESS()), the
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * status code must be passed on to EM.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_IOM_R3_IOPORT_WRITE Defer the write to ring-3. (R0/GC only)
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync * @retval VINF_EM_RAW_GUEST_TRAP The exception was left pending. (TRPMRaiseXcptErr)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_TRPM_XCPT_DISPATCHED The exception was raised and dispatched for raw-mode execution. (TRPMRaiseXcptErr)
98502a585f6eda30527b54f7df18dd3de3d3d7c6vboxsync * @retval VINF_EM_RESCHEDULE_REM The exception was dispatched and cannot be executed in raw-mode. (TRPMRaiseXcptErr)
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync * @param pVM The virtual machine.
559419830ee63b8481ade36d8994f235932aae49vboxsync * @param pRegFrame Pointer to CPUMCTXCORE guest registers structure.
0ebb1ef53864eb9cc97580f722288c9b29bc5d03vboxsync * @param uPort IO Port
0ebb1ef53864eb9cc97580f722288c9b29bc5d03vboxsync * @param uPrefix IO instruction prefix
0ebb1ef53864eb9cc97580f722288c9b29bc5d03vboxsync * @param enmAddrMode The address mode.
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync * @param cbTransfer Size of transfer unit
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncVMMDECL(VBOXSTRICTRC) IOMInterpretOUTSEx(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t uPort, uint32_t uPrefix,
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync * We do not support segment prefixes, REPNE or
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync * decrementing source pointer.
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync * Get bytes/words/dwords count to transfer.
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync uint64_t const fAddrMask = iomDisModeToMask(enmAddrMode);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Convert source address ds:esi. */
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync int rc2 = SELMToFlatEx(pVCpu, DISSELREG_DS, pRegFrame, pRegFrame->rsi & fAddrMask,
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync Log(("OUTS source address conversion failed -> fallback, rc2=%Rrc\n", rc2));
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync /* Access verification first; we currently can't recover properly from traps inside this instruction */
fa14b6834510fceb09a719a6f3c933635f441b20vboxsync rc2 = PGMVerifyAccess(pVCpu, (RTGCUINTPTR)GCPtrSrc, cTransfers * cbTransfer,
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync Log(("OUTS will generate a trap -> fallback, rc2=%Rrc\n", rc2));
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync Log(("IOM: rep outs%d port %#x count %d\n", cbTransfer * 8, uPort, cTransfers));
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync * If the device supports string transfers, ask it to do as
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * much as it wants. The rest is done with single-word transfers.
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync rcStrict = IOMIOPortWriteString(pVM, uPort, &GCPtrSrc, &cTransfers, cbTransfer);
98502a585f6eda30527b54f7df18dd3de3d3d7c6vboxsync AssertRC(VBOXSTRICTRC_VAL(rcStrict)); Assert(cTransfers <= cTransfersOrg);
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync pRegFrame->rsi = ((pRegFrame->rsi + (cTransfersOrg - cTransfers) * cbTransfer) & fAddrMask)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rcStrict = iomRamRead(pVCpu, &u32Value, GCPtrSrc, cbTransfer);
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync rcStrict = IOMIOPortWrite(pVM, uPort, u32Value, cbTransfer);
648b0a0e189323afe4d836f1848f82c7dded0e58vboxsync GCPtrSrc = (RTGCPTR)((RTUINTPTR)GCPtrSrc + cbTransfer);
a82df5167acec0c75d741d08c1d05a4007e3d50evboxsync pRegFrame->rsi = ((pRegFrame->rsi + cbTransfer) & fAddrMask)
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync /* Update rcx on exit. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(rcStrict == VINF_SUCCESS || rcStrict == VINF_IOM_R3_IOPORT_WRITE || (rcStrict >= VINF_EM_FIRST && rcStrict <= VINF_EM_LAST) || RT_FAILURE(rcStrict), ("%Rrc\n", VBOXSTRICTRC_VAL(rcStrict)));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * DS:ESI,DX[,ECX]
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns Strict VBox status code. Informational status codes other than the one documented
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync * here are to be treated as internal failure. Use IOM_SUCCESS() to check for success.
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync * @retval VINF_SUCCESS Success.
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @retval VINF_EM_FIRST-VINF_EM_LAST Success with some exceptions (see IOM_SUCCESS()), the
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync * status code must be passed on to EM.
ed5875886aed64570809cf39f881a0fcb93f44a7vboxsync * @retval VINF_IOM_R3_IOPORT_WRITE Defer the write to ring-3. (R0/GC only)
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @retval VINF_EM_RAW_EMULATE_INSTR Defer the write to the REM.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_EM_RAW_GUEST_TRAP The exception was left pending. (TRPMRaiseXcptErr)
9d4c9e0a3e2dcc3bd19303d7b4e2d96d12c11814vboxsync * @retval VINF_TRPM_XCPT_DISPATCHED The exception was raised and dispatched for raw-mode execution. (TRPMRaiseXcptErr)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_EM_RESCHEDULE_REM The exception was dispatched and cannot be executed in raw-mode. (TRPMRaiseXcptErr)
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync * @param pVM The virtual machine.
b0a3d0ec5780199a2f379da63c59ccf48f1a73b9vboxsync * @param pRegFrame Pointer to CPUMCTXCORE guest registers structure.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @param pCpu Disassembler CPU state.
15cb2a15b8a2bf93c7e5e83d801e6184ed3ab3e2vboxsyncVMMDECL(VBOXSTRICTRC) IOMInterpretOUTS(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu)
f7afd3bd944d339a711ec851bad6a759fd64a7d9vboxsync * Get port number from the first parameter.
f7afd3bd944d339a711ec851bad6a759fd64a7d9vboxsync * And get the I/O register size from the opcode / prefix.
15cb2a15b8a2bf93c7e5e83d801e6184ed3ab3e2vboxsync unsigned cb = 0;
15cb2a15b8a2bf93c7e5e83d801e6184ed3ab3e2vboxsync bool fRc = iomGetRegImmData(pCpu, &pCpu->Param1, pRegFrame, &Port, &cb);
15cb2a15b8a2bf93c7e5e83d801e6184ed3ab3e2vboxsync AssertMsg(fRc, ("Failed to get reg/imm port number!\n")); NOREF(fRc);
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync cb = (pCpu->uOpMode == DISCPUMODE_16BIT) ? 2 : 4; /* dword in both 32 & 64 bits mode */
d7f13a056a2bfd91ca8973baf89c7d87c2d1bf80vboxsync VBOXSTRICTRC rcStrict = IOMInterpretCheckPortIOAccess(pVM, pRegFrame, Port, cb);
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync AssertMsg(rcStrict == VINF_EM_RAW_GUEST_TRAP || rcStrict == VINF_TRPM_XCPT_DISPATCHED || rcStrict == VINF_TRPM_XCPT_DISPATCHED || RT_FAILURE(rcStrict), ("%Rrc\n", VBOXSTRICTRC_VAL(rcStrict)));
be9322776c5e79993df07a0728780a4397be7388vboxsync return IOMInterpretOUTSEx(pVM, pRegFrame, Port, pCpu->fPrefix, (DISCPUMODE)pCpu->uAddrMode, cb);
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * Mapping an MMIO2 page in place of an MMIO page for direct access.
15cb2a15b8a2bf93c7e5e83d801e6184ed3ab3e2vboxsync * (This is a special optimization used by the VGA device.)
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * @returns VBox status code. This API may return VINF_SUCCESS even if no
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * remapping is made,.
51afd9e19409617e8f3a204d58e96e22ee618e57vboxsync * @param pVM The virtual machine.
15cb2a15b8a2bf93c7e5e83d801e6184ed3ab3e2vboxsync * @param GCPhys The address of the MMIO page to be changed.
15cb2a15b8a2bf93c7e5e83d801e6184ed3ab3e2vboxsync * @param GCPhysRemapped The address of the MMIO2 page.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @param fPageFlags Page flags to set. Must be (X86_PTE_RW | X86_PTE_P)
15cb2a15b8a2bf93c7e5e83d801e6184ed3ab3e2vboxsync * for the time being.
15cb2a15b8a2bf93c7e5e83d801e6184ed3ab3e2vboxsyncVMMDECL(int) IOMMMIOMapMMIO2Page(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysRemapped, uint64_t fPageFlags)
15cb2a15b8a2bf93c7e5e83d801e6184ed3ab3e2vboxsync /* Currently only called from the VGA device during MMIO. */
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync Log(("IOMMMIOMapMMIO2Page %RGp -> %RGp flags=%RX64\n", GCPhys, GCPhysRemapped, fPageFlags));
f7afd3bd944d339a711ec851bad6a759fd64a7d9vboxsync AssertReturn(fPageFlags == (X86_PTE_RW | X86_PTE_P), VERR_INVALID_PARAMETER);
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync /* This currently only works in real mode, protected mode without paging or with nested paging. */
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync if ( !HMIsEnabled(pVM) /* useless without VT-x/AMD-V */
0d0687880459ea33aa3e9c5a74d736edcb0937devboxsync return VINF_SUCCESS; /* better luck the next time around */
9243c25e887b8f49e764b130c132bbe1b60bed50vboxsync * Lookup the context range node the page belongs to.
7250d2692ab7cbd235c2feeb78e48f0bdb302f14vboxsync PIOMMMIORANGE pRange = iomMmioGetRange(pVM, GCPhys);
9243c25e887b8f49e764b130c132bbe1b60bed50vboxsync ("Handlers and page tables are out of sync or something! GCPhys=%RGp\n", GCPhys), VERR_IOM_MMIO_RANGE_NOT_FOUND);
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync Assert((pRange->Core.KeyLast & PAGE_OFFSET_MASK) == PAGE_OFFSET_MASK);
b0a3d0ec5780199a2f379da63c59ccf48f1a73b9vboxsync * Do the aliasing; page align the addresses since PGM is picky.
2af2d8756d82236367dfee425f88eb7141a490cbvboxsync rc = PGMHandlerPhysicalPageAlias(pVM, pRange->GCPhys, GCPhys, GCPhysRemapped);
2af2d8756d82236367dfee425f88eb7141a490cbvboxsync * Modify the shadow page table. Since it's an MMIO page it won't be present and we
2af2d8756d82236367dfee425f88eb7141a490cbvboxsync * can simply prefetch it.
2af2d8756d82236367dfee425f88eb7141a490cbvboxsync * Note: This is a NOP in the EPT case; we'll just let it fault again to resync the page.
51afd9e19409617e8f3a204d58e96e22ee618e57vboxsync#if 0 /* The assertion is wrong for the PGM_SYNC_CLEAR_PGM_POOL and VINF_PGM_HANDLER_ALREADY_ALIASED cases. */
2af2d8756d82236367dfee425f88eb7141a490cbvboxsync rc = PGMShwGetPage(pVCpu, (RTGCPTR)GCPhys, &fFlags, &HCPhys);
2af2d8756d82236367dfee425f88eb7141a490cbvboxsync Assert(rc == VERR_PAGE_NOT_PRESENT || rc == VERR_PAGE_TABLE_NOT_PRESENT);
2af2d8756d82236367dfee425f88eb7141a490cbvboxsync Assert(rc == VINF_SUCCESS || rc == VERR_PAGE_NOT_PRESENT || rc == VERR_PAGE_TABLE_NOT_PRESENT);
51afd9e19409617e8f3a204d58e96e22ee618e57vboxsync * Mapping a HC page in place of an MMIO page for direct access.
2af2d8756d82236367dfee425f88eb7141a490cbvboxsync * (This is a special optimization used by the APIC in the VT-x case.)
2af2d8756d82236367dfee425f88eb7141a490cbvboxsync * @returns VBox status code.
2af2d8756d82236367dfee425f88eb7141a490cbvboxsync * @param pVM Pointer to the VM.
2af2d8756d82236367dfee425f88eb7141a490cbvboxsync * @param pVCpu Pointer to the VMCPU.
2af2d8756d82236367dfee425f88eb7141a490cbvboxsync * @param GCPhys The address of the MMIO page to be changed.
2af2d8756d82236367dfee425f88eb7141a490cbvboxsync * @param HCPhys The address of the host physical page.
2af2d8756d82236367dfee425f88eb7141a490cbvboxsync * @param fPageFlags Page flags to set. Must be (X86_PTE_RW | X86_PTE_P)
51afd9e19409617e8f3a204d58e96e22ee618e57vboxsync * for the time being.
2af2d8756d82236367dfee425f88eb7141a490cbvboxsyncVMMDECL(int) IOMMMIOMapMMIOHCPage(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, RTHCPHYS HCPhys, uint64_t fPageFlags)
2af2d8756d82236367dfee425f88eb7141a490cbvboxsync /* Currently only called from VT-x code during a page fault. */
2af2d8756d82236367dfee425f88eb7141a490cbvboxsync Log(("IOMMMIOMapMMIOHCPage %RGp -> %RGp flags=%RX64\n", GCPhys, HCPhys, fPageFlags));
2af2d8756d82236367dfee425f88eb7141a490cbvboxsync AssertReturn(fPageFlags == (X86_PTE_RW | X86_PTE_P), VERR_INVALID_PARAMETER);
2af2d8756d82236367dfee425f88eb7141a490cbvboxsync * Lookup the context range node the page belongs to.
b0a3d0ec5780199a2f379da63c59ccf48f1a73b9vboxsync /* Can't lock IOM here due to potential deadlocks in the VGA device; not safe to access. */
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync PIOMMMIORANGE pRange = iomMMIOGetRangeUnsafe(pVM, GCPhys);
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync ("Handlers and page tables are out of sync or something! GCPhys=%RGp\n", GCPhys), VERR_IOM_MMIO_RANGE_NOT_FOUND);
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync Assert((pRange->Core.KeyLast & PAGE_OFFSET_MASK) == PAGE_OFFSET_MASK);
15cb2a15b8a2bf93c7e5e83d801e6184ed3ab3e2vboxsync * Do the aliasing; page align the addresses since PGM is picky.
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync int rc = PGMHandlerPhysicalPageAliasHC(pVM, GCPhys, GCPhys, HCPhys);
be9322776c5e79993df07a0728780a4397be7388vboxsync * Modify the shadow page table. Since it's an MMIO page it won't be present and we
be9322776c5e79993df07a0728780a4397be7388vboxsync * can simply prefetch it.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * Note: This is a NOP in the EPT case; we'll just let it fault again to resync the page.
51afd9e19409617e8f3a204d58e96e22ee618e57vboxsync Assert(rc == VINF_SUCCESS || rc == VERR_PAGE_NOT_PRESENT || rc == VERR_PAGE_TABLE_NOT_PRESENT);
51afd9e19409617e8f3a204d58e96e22ee618e57vboxsync * Reset a previously modified MMIO region; restore the access flags.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @returns VBox status code.
15cb2a15b8a2bf93c7e5e83d801e6184ed3ab3e2vboxsync * @param pVM The virtual machine.
15cb2a15b8a2bf93c7e5e83d801e6184ed3ab3e2vboxsync * @param GCPhys Physical address that's part of the MMIO region to be reset.
15cb2a15b8a2bf93c7e5e83d801e6184ed3ab3e2vboxsyncVMMDECL(int) IOMMMIOResetRegion(PVM pVM, RTGCPHYS GCPhys)
e0b9d3c357adf9b7d05f55540e86f22943fc4b23vboxsync /* This currently only works in real mode, protected mode without paging or with nested paging. */
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync if ( !HMIsEnabled(pVM) /* useless without VT-x/AMD-V */
15cb2a15b8a2bf93c7e5e83d801e6184ed3ab3e2vboxsync * Lookup the context range node the page belongs to.
15cb2a15b8a2bf93c7e5e83d801e6184ed3ab3e2vboxsync /* Can't lock IOM here due to potential deadlocks in the VGA device; not safe to access. */
15cb2a15b8a2bf93c7e5e83d801e6184ed3ab3e2vboxsync PIOMMMIORANGE pRange = iomMMIOGetRangeUnsafe(pVM, GCPhys);
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync ("Handlers and page tables are out of sync or something! GCPhys=%RGp\n", GCPhys), VERR_IOM_MMIO_RANGE_NOT_FOUND);
15cb2a15b8a2bf93c7e5e83d801e6184ed3ab3e2vboxsync Assert((pRange->Core.KeyLast & PAGE_OFFSET_MASK) == PAGE_OFFSET_MASK);
8f3f7a8bb1cf9f74426deee5af7432ebd63de2b1vboxsync * Call PGM to do the job work.
#ifdef VBOX_STRICT
while (cb)
return rc;