IOMAllMMIO.cpp revision 352f5cf617a287b8a3ca2fbe1f23afe258874ce9
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync * IOM - Input / Output Monitor - Any Context, MMIO & String I/O.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * additional information or have any questions.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync/*******************************************************************************
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync* Header Files *
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync*******************************************************************************/
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[] =
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync ~0, /* 0 - invalid */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync 0, /* *1 == 2^0 */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync ~0, /* 3 - invalid */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync ~0, /* 5 - invalid */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync ~0, /* 6 - invalid */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync ~0, /* 7 - invalid */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Macro for fast recode of the operand size (1/2/4/8 bytes) to bit shift value.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Wrapper which does the write and updates range statistics when such are enabled.
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync * @warning RT_SUCCESS(rc=VINF_IOM_HC_MMIO_WRITE) is TRUE!
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsyncDECLINLINE(int) iomMMIODoWrite(PVM pVM, PIOMMMIORANGE pRange, RTGCPHYS GCPhysFault, const void *pvData, unsigned cb)
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync PIOMMMIOSTATS pStats = iomMMIOGetStats(&pVM->iom.s, GCPhysFault, pRange);
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync rc = pRange->CTX_SUFF(pfnWriteCallback)(pRange->CTX_SUFF(pDevIns), pRange->CTX_SUFF(pvUser), GCPhysFault, (void *)pvData, cb); /* @todo fix const!! */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Wrapper which does the read and updates range statistics when such are enabled.
05406988cc320ac1b0971de976b6cf0c986044a9vboxsyncDECLINLINE(int) iomMMIODoRead(PVM pVM, PIOMMMIORANGE pRange, RTGCPHYS GCPhys, void *pvValue, unsigned cbValue)
05406988cc320ac1b0971de976b6cf0c986044a9vboxsync PIOMMMIOSTATS pStats = iomMMIOGetStats(&pVM->iom.s, GCPhys, pRange);
05406988cc320ac1b0971de976b6cf0c986044a9vboxsync rc = pRange->CTX_SUFF(pfnReadCallback)(pRange->CTX_SUFF(pDevIns), pRange->CTX_SUFF(pvUser), GCPhys, pvValue, cbValue);
05406988cc320ac1b0971de976b6cf0c986044a9vboxsync case 1: *(uint8_t *)pvValue = UINT8_C(0xff); break;
05406988cc320ac1b0971de976b6cf0c986044a9vboxsync case 2: *(uint16_t *)pvValue = UINT16_C(0xffff); break;
05406988cc320ac1b0971de976b6cf0c986044a9vboxsync case 4: *(uint32_t *)pvValue = UINT32_C(0xffffffff); break;
05406988cc320ac1b0971de976b6cf0c986044a9vboxsync case 8: *(uint64_t *)pvValue = UINT64_C(0xffffffffffffffff); break;
1db6afc370c2fa84144478dffa9c1ed3c28c7158vboxsync default: AssertReleaseMsgFailed(("cbValue=%d GCPhys=%RGp\n", cbValue, GCPhys)); break;
05406988cc320ac1b0971de976b6cf0c986044a9vboxsync case 1: *(uint8_t *)pvValue = UINT8_C(0x00); break;
05406988cc320ac1b0971de976b6cf0c986044a9vboxsync case 2: *(uint16_t *)pvValue = UINT16_C(0x0000); break;
05406988cc320ac1b0971de976b6cf0c986044a9vboxsync case 4: *(uint32_t *)pvValue = UINT32_C(0x00000000); break;
05406988cc320ac1b0971de976b6cf0c986044a9vboxsync case 8: *(uint64_t *)pvValue = UINT64_C(0x0000000000000000); break;
1db6afc370c2fa84144478dffa9c1ed3c28c7158vboxsync default: AssertReleaseMsgFailed(("cbValue=%d GCPhys=%RGp\n", cbValue, GCPhys)); break;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Internal - statistics only.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsyncDECLINLINE(void) iomMMIOStatLength(PVM pVM, unsigned cb)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* No way. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * MOV reg, mem (read)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * MOVZX reg, mem (read)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * MOVSX reg, mem (read)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @param pVM The virtual machine.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRegFrame Pointer to CPUMCTXCORE guest registers structure.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pCpu Disassembler CPU state.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRange Pointer MMIO range.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsyncstatic int iomInterpretMOVxXRead(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu, PIOMMMIORANGE pRange, RTGCPHYS GCPhysFault)
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync 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.
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync unsigned cb = DISGetParamSize(pCpu, &pCpu->param2);
61e80138f3c5ea5213990bde94a973c8e64d1dadvboxsync AssertMsg(cb > 0 && cb <= sizeof(uint64_t), ("cb=%d\n", cb));
61e80138f3c5ea5213990bde94a973c8e64d1dadvboxsync 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).
61e80138f3c5ea5213990bde94a973c8e64d1dadvboxsync bool fRc = iomSaveDataToReg(pCpu, &pCpu->param1, pRegFrame, u64Data);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(fRc, ("Failed to store register value!\n")); NOREF(fRc);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * MOV mem, reg|imm (write)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @param pVM The virtual machine.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRegFrame Pointer to CPUMCTXCORE guest registers structure.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pCpu Disassembler CPU state.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRange Pointer MMIO range.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsyncstatic int iomInterpretMOVxXWrite(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu, PIOMMMIORANGE pRange, RTGCPHYS GCPhysFault)
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync Assert(pRange->CTX_SUFF(pfnWriteCallback) || !pRange->pfnWriteCallbackR3);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Get data to write from second parameter,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * and call the callback to write it.
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync unsigned cb = 0;
be9bc9b4ba510c4b4159c193f783d024633ef8e9vboxsync bool fRc = iomGetRegImmData(pCpu, &pCpu->param2, pRegFrame, &u64Data, &cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(fRc, ("Failed to get reg/imm port number!\n")); NOREF(fRc);
be9bc9b4ba510c4b4159c193f783d024633ef8e9vboxsync int rc = iomMMIODoWrite(pVM, pRange, GCPhysFault, &u64Data, cb);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync/** Wrapper for reading virtual memory. */
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsyncDECLINLINE(int) iomRamRead(PVM pVM, void *pDest, RTGCPTR GCSrc, uint32_t cb)
78a205e3fc6719d59e8c561b3d287d3a4f879852vboxsync return MMGCRamReadNoTrapHandler(pDest, (void *)GCSrc, cb);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync/** Wrapper for writing virtual memory. */
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsyncDECLINLINE(int) iomRamWrite(PVM pVM, RTGCPTR GCDest, void *pSrc, uint32_t cb)
78a205e3fc6719d59e8c561b3d287d3a4f879852vboxsync return MMGCRamWriteNoTrapHandler((void *)GCDest, pSrc, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * [REP] MOVSB
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * [REP] MOVSW
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * [REP] MOVSD
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Restricted implementation.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @param pVM The virtual machine.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param uErrorCode CPU Error code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRegFrame Trap register frame.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pCpu Disassembler CPU state.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRange Pointer MMIO range.
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync * @param ppStat Which sub-sample to attribute this call to.
323b78bf4831666c95416edf3b6e54657a769e5dvboxsyncstatic int iomInterpretMOVS(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, PIOMMMIORANGE pRange, PSTAMPROFILE *ppStat)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * We do not support segment prefixes or REPNE.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync return VINF_IOM_HC_MMIO_READ_WRITE; /** @todo -> interpret whatever. */
f5395a2af3050ddd694b0ad505975f7b717ab4f1vboxsync if (SELMGetCpuModeFromSelector(pVM, pRegFrame->eflags, pRegFrame->cs, &pRegFrame->csHid) == CPUMODE_16BIT)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Get the current privilege level. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Get data size.
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync unsigned cb = DISGetParamSize(pCpu, &pCpu->param1);
61e80138f3c5ea5213990bde94a973c8e64d1dadvboxsync AssertMsg(cb > 0 && cb <= sizeof(uint32_t), ("cb=%d\n", cb));
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync int offIncrement = pRegFrame->eflags.Bits.u1DF ? -(signed)cb : (signed)cb;
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync if (pVM->iom.s.cMovsMaxBytes < (cTransfers << SIZE_2_SHIFT(cb)))
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync pVM->iom.s.cMovsMaxBytes = cTransfers << SIZE_2_SHIFT(cb);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync/** @todo re-evaluate on page boundraries. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Write operation: [Mem] -> [MMIO]
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * ds:esi (Virt Src) -> es:edi (Phys Dst)
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync STAM_STATS({ *ppStat = &pVM->iom.s.StatRZInstMovsToMMIO; });
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Check callback. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Convert source address ds:esi. */
13d75a5db336ccb682d7ab28b397a4f0b8982ea3vboxsync rc = SELMToFlatEx(pVM, DIS_SELREG_DS, pRegFrame, (RTGCPTR)pRegFrame->rsi,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Access verification first; we currently can't recover properly from traps inside this instruction */
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync rc = PGMVerifyAccess(pVM, pu8Virt, cTransfers * cb, (cpl == 3) ? X86_PTE_US : 0);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("MOVS will generate a trap -> recompiler, rc=%d\n", rc));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* copy loop. */
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync rc = iomRamRead(pVM, &u32Data, (RTGCPTR)pu8Virt, cb);
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync 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; });
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Check callback. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Convert destination address. */
13d75a5db336ccb682d7ab28b397a4f0b8982ea3vboxsync rc = SELMToFlatEx(pVM, DIS_SELREG_ES, pRegFrame, (RTGCPTR)pRegFrame->rdi,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Check if destination address is MMIO. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = PGMGstGetPage(pVM, (RTGCPTR)pu8Virt, NULL, &PhysDst);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync PhysDst |= (RTGCUINTPTR)pu8Virt & PAGE_OFFSET_MASK;
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync && (pMMIODst = iomMMIOGetRange(&pVM->iom.s, PhysDst)))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Extra: [MMIO] -> [MMIO]
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync STAM_STATS({ *ppStat = &pVM->iom.s.StatRZInstMovsMMIO; });
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync if (!pMMIODst->CTX_SUFF(pfnWriteCallback) && pMMIODst->pfnWriteCallbackR3)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* copy loop. */
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync rc = iomMMIODoRead(pVM, pRange, Phys, &u32Data, cb);
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync rc = iomMMIODoWrite(pVM, pMMIODst, PhysDst, &u32Data, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Normal: [MMIO] -> [Mem]
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Access verification first; we currently can't recover properly from traps inside this instruction */
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync rc = PGMVerifyAccess(pVM, pu8Virt, cTransfers * cb, X86_PTE_RW | ((cpl == 3) ? X86_PTE_US : 0));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("MOVS will generate a trap -> recompiler, rc=%d\n", rc));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* copy loop. */
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync rc = iomMMIODoRead(pVM, pRange, Phys, &u32Data, cb);
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync rc = iomRamWrite(pVM, (RTGCPTR)pu8Virt, &u32Data, cb);
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync Log(("iomRamWrite %08X size=%d failed with %d\n", pu8Virt, cb, rc));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Update ecx on exit. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* work statistics. */
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync#endif /* IOM_WITH_MOVS_SUPPORT */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * [REP] STOSB
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * [REP] STOSW
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * [REP] STOSD
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Restricted implementation.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
ebe05ec36d1fcd24d62e7066dedcb4eb2e691358vboxsync * @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.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRange Pointer MMIO range.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsyncstatic int iomInterpretSTOS(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, PIOMMMIORANGE pRange)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * We do not support segment prefixes or REPNE..
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync return VINF_IOM_HC_MMIO_READ_WRITE; /** @todo -> REM instead of HC */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Get bytes/words/dwords count to copy.
f5395a2af3050ddd694b0ad505975f7b717ab4f1vboxsync if (SELMGetCpuModeFromSelector(pVM, pRegFrame->eflags, pRegFrame->cs, &pRegFrame->csHid) == CPUMODE_16BIT)
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync/** @todo r=bird: bounds checks! */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Get data size.
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync unsigned cb = DISGetParamSize(pCpu, &pCpu->param1);
61e80138f3c5ea5213990bde94a973c8e64d1dadvboxsync AssertMsg(cb > 0 && cb <= sizeof(uint32_t), ("cb=%d\n", cb));
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync int offIncrement = pRegFrame->eflags.Bits.u1DF ? -(signed)cb : (signed)cb;
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync if (pVM->iom.s.cStosMaxBytes < (cTransfers << SIZE_2_SHIFT(cb)))
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync pVM->iom.s.cStosMaxBytes = cTransfers << SIZE_2_SHIFT(cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Use the fill callback.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo pfnFillCallback must return number of bytes successfully written!!! */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* addr++ variant. */
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync rc = pRange->CTX_SUFF(pfnFillCallback)(pRange->CTX_SUFF(pDevIns), pRange->CTX_SUFF(pvUser), Phys, u32Data, cb, cTransfers);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Update registers. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* addr-- variant. */
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync rc = pRange->CTX_SUFF(pfnFillCallback)(pRange->CTX_SUFF(pDevIns), pRange->CTX_SUFF(pvUser), (Phys - (cTransfers - 1)) << SIZE_2_SHIFT(cb), u32Data, cb, cTransfers);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Update registers. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Use the write callback.
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync Assert(pRange->CTX_SUFF(pfnWriteCallback) || !pRange->pfnWriteCallbackR3);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* fill loop. */
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync rc = iomMMIODoWrite(pVM, pRange, Phys, &u32Data, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Update ecx on exit. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Work statistics and return.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * [REP] LODSB
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * [REP] LODSW
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * [REP] LODSD
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Restricted implementation.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @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.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRange Pointer MMIO range.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsyncstatic int iomInterpretLODS(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, PIOMMMIORANGE pRange)
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync Assert(pRange->CTX_SUFF(pfnReadCallback) || !pRange->pfnReadCallbackR3);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * We do not support segment prefixes or REP*.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (pCpu->prefix & (PREFIX_SEG | PREFIX_REP | PREFIX_REPNE))
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync return VINF_IOM_HC_MMIO_READ_WRITE; /** @todo -> REM instead of HC */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Get data size.
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync unsigned cb = DISGetParamSize(pCpu, &pCpu->param2);
1df4b0cdc5ec23d817014f9347ef28222b51e3fbvboxsync AssertMsg(cb > 0 && cb <= sizeof(uint64_t), ("cb=%d\n", cb));
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync int offIncrement = pRegFrame->eflags.Bits.u1DF ? -(signed)cb : (signed)cb;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Perform read.
1df4b0cdc5ec23d817014f9347ef28222b51e3fbvboxsync int rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &pRegFrame->rax, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Work statistics and return.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * CMP [MMIO], reg|imm
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * CMP reg|imm, [MMIO]
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Restricted implementation.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @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.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRange Pointer MMIO range.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsyncstatic int iomInterpretCMP(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, PIOMMMIORANGE pRange)
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync Assert(pRange->CTX_SUFF(pfnReadCallback) || !pRange->pfnReadCallbackR3);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Get the operands.
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync unsigned cb = 0;
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync if (iomGetRegImmData(pCpu, &pCpu->param1, pRegFrame, &uData1, &cb))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* cmp reg, [MMIO]. */
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &uData2, cb);
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync else if (iomGetRegImmData(pCpu, &pCpu->param2, pRegFrame, &uData2, &cb))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* cmp [MMIO], reg|imm. */
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &uData1, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Emulate CMP and update guest flags. */
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync uint32_t eflags = EMEmulateCmp(uData1, uData2, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pRegFrame->eflags.u32 = (pRegFrame->eflags.u32 & ~(X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync | (eflags & (X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * AND [MMIO], reg|imm
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * AND reg, [MMIO]
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync * OR [MMIO], reg|imm
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync * OR reg, [MMIO]
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Restricted implementation.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @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.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRange Pointer MMIO range.
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync * @param pfnEmulate Instruction emulation function.
ab0130d1627b2b214952b929de71b89e4ba41eb1vboxsyncstatic int iomInterpretOrXorAnd(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, PIOMMMIORANGE pRange, PFNEMULATEPARAM3 pfnEmulate)
9f16100a870e25701da9bc9819e15c0f9fb3870evboxsync unsigned cb = 0;
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync const char *pszInstr;
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync if (iomGetRegImmData(pCpu, &pCpu->param1, pRegFrame, &uData1, &cb))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* and reg, [MMIO]. */
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync Assert(pRange->CTX_SUFF(pfnReadCallback) || !pRange->pfnReadCallbackR3);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &uData2, cb);
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync else if (iomGetRegImmData(pCpu, &pCpu->param2, pRegFrame, &uData2, &cb))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* and [MMIO], reg|imm. */
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync if ( (pRange->CTX_SUFF(pfnReadCallback) || !pRange->pfnReadCallbackR3)
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync && (pRange->CTX_SUFF(pfnWriteCallback) || !pRange->pfnWriteCallbackR3))
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &uData1, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Emulate AND and update guest flags. */
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync uint32_t eflags = pfnEmulate((uint32_t *)&uData1, uData2, cb);
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync LogFlow(("iomInterpretOrXorAnd %s result %RX64\n", pszInstr, uData1));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Store result to MMIO. */
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync rc = iomMMIODoWrite(pVM, pRange, GCPhysFault, &uData1, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Store result to register. */
61283d6341bac43f73cf33c9ec754a59f674fa19vboxsync 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. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pRegFrame->eflags.u32 = (pRegFrame->eflags.u32 & ~(X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync | (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.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @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.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRange Pointer MMIO range.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsyncstatic int iomInterpretTEST(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, PIOMMMIORANGE pRange)
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync Assert(pRange->CTX_SUFF(pfnReadCallback) || !pRange->pfnReadCallbackR3);
9f16100a870e25701da9bc9819e15c0f9fb3870evboxsync unsigned cb = 0;
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync if (iomGetRegImmData(pCpu, &pCpu->param1, pRegFrame, &uData1, &cb))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* and test, [MMIO]. */
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &uData2, cb);
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync else if (iomGetRegImmData(pCpu, &pCpu->param2, pRegFrame, &uData2, &cb))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* test [MMIO], reg|imm. */
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &uData1, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Emulate TEST (=AND without write back) and update guest EFLAGS. */
be9bc9b4ba510c4b4159c193f783d024633ef8e9vboxsync uint32_t eflags = EMEmulateAnd((uint32_t *)&uData1, uData2, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pRegFrame->eflags.u32 = (pRegFrame->eflags.u32 & ~(X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync | (eflags & (X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF));
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync * BT [MMIO], reg|imm
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync * Restricted implementation.
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync * @returns VBox status code.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @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.
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsyncstatic int iomInterpretBT(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, PIOMMMIORANGE pRange)
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync Assert(pRange->CTX_SUFF(pfnReadCallback) || !pRange->pfnReadCallbackR3);
9f16100a870e25701da9bc9819e15c0f9fb3870evboxsync unsigned cb = 0;
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync if (iomGetRegImmData(pCpu, &pCpu->param2, pRegFrame, &uBit, &cb))
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync /* bt [MMIO], reg|imm. */
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &uData1, cb);
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync /* The size of the memory operand only matters here. */
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync /* Find the bit inside the faulting address */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * XCHG [MMIO], reg
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * XCHG reg, [MMIO]
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Restricted implementation.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @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.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRange Pointer MMIO range.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsyncstatic int iomInterpretXCHG(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, PIOMMMIORANGE pRange)
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync /* Check for read & write handlers since IOMMMIOHandler doesn't cover this. */
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync if ( (!pRange->CTX_SUFF(pfnReadCallback) && pRange->pfnReadCallbackR3)
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync || (!pRange->CTX_SUFF(pfnWriteCallback) && pRange->pfnWriteCallbackR3))
9f16100a870e25701da9bc9819e15c0f9fb3870evboxsync unsigned cb = 0;
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync if (iomGetRegImmData(pCpu, &pCpu->param1, pRegFrame, &uData1, &cb))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* xchg reg, [MMIO]. */
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &uData2, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Store result to MMIO. */
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync rc = iomMMIODoWrite(pVM, pRange, GCPhysFault, &uData1, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Store result to register. */
61283d6341bac43f73cf33c9ec754a59f674fa19vboxsync bool fRc = iomSaveDataToReg(pCpu, &pCpu->param1, pRegFrame, uData2);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(fRc, ("Failed to store register value!\n")); NOREF(fRc);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(rc == VINF_IOM_HC_MMIO_WRITE || rc == VINF_PATM_HC_MMIO_PATCH_WRITE);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(rc == VINF_IOM_HC_MMIO_READ || rc == VINF_PATM_HC_MMIO_PATCH_READ);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync else if (iomGetRegImmData(pCpu, &pCpu->param2, pRegFrame, &uData2, &cb))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* xchg [MMIO], reg. */
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync rc = iomMMIODoRead(pVM, pRange, GCPhysFault, &uData1, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Store result to MMIO. */
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync rc = iomMMIODoWrite(pVM, pRange, GCPhysFault, &uData2, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Store result to register. */
61283d6341bac43f73cf33c9ec754a59f674fa19vboxsync bool fRc = iomSaveDataToReg(pCpu, &pCpu->param2, pRegFrame, uData1);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(fRc, ("Failed to store register value!\n")); NOREF(fRc);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(rc == VINF_IOM_HC_MMIO_WRITE || rc == VINF_PATM_HC_MMIO_PATCH_WRITE);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(rc == VINF_IOM_HC_MMIO_READ || rc == VINF_PATM_HC_MMIO_PATCH_READ);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * \#PF Handler callback for MMIO ranges.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code (appropriate for GC return).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM VM Handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param uErrorCode CPU Error code.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * @param pCtxCore Trap register frame.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pvFault The fault address (cr2).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pvUser Pointer to the MMIO ring-3 range entry.
9ad5e3912962c3dbccc1afc4e7d62890fe906814vboxsyncVMMDECL(int) IOMMMIOHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pCtxCore, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser)
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync STAM_PROFILE_START(&pVM->iom.s.StatRZMMIOHandler, a);
08bc90fc2848c80bf8270bedc883745b8398e186vboxsync Log(("IOMMMIOHandler: GCPhys=%RGp uErr=%#x pvFault=%RGv rip=%RGv\n",
79b07d7ae28b916539c6397e010a5cc05e300551vboxsync GCPhysFault, (uint32_t)uErrorCode, pvFault, (RTGCPTR)pCtxCore->rip));
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync Assert(pRange == iomMMIOGetRange(&pVM->iom.s, GCPhysFault));
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * Locate the statistics, if > PAGE_SIZE we'll use the first byte for everything.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync PIOMMMIOSTATS pStats = iomMMIOGetStats(&pVM->iom.s, GCPhysFault, pRange);
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync STAM_PROFILE_STOP(&pVM->iom.s.StatRZMMIOHandler, a);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync return uErrorCode & X86_TRAP_PF_RW ? VINF_IOM_HC_MMIO_WRITE : VINF_IOM_HC_MMIO_READ;
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * Should we defer the request right away?
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync ? !pRange->CTX_SUFF(pfnWriteCallback) && pRange->pfnWriteCallbackR3
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync : !pRange->CTX_SUFF(pfnReadCallback) && pRange->pfnReadCallbackR3)
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync STAM_PROFILE_STOP(&pVM->iom.s.StatRZMMIOHandler, a);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync return uErrorCode & X86_TRAP_PF_RW ? VINF_IOM_HC_MMIO_WRITE : VINF_IOM_HC_MMIO_READ;
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync#endif /* !IN_RING3 */
352f5cf617a287b8a3ca2fbe1f23afe258874ce9vboxsync * Disassemble the instruction and interpret it.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync int rc = EMInterpretDisasOne(pVM, pCtxCore, &Cpu, &cbOp);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync rc = iomInterpretMOVxXWrite(pVM, pCtxCore, &Cpu, pRange, GCPhysFault);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync rc = iomInterpretMOVxXRead(pVM, pCtxCore, &Cpu, pRange, GCPhysFault);
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync STAM_PROFILE_ADV_START(&pVM->iom.s.StatRZInstMovs, c);
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync rc = iomInterpretMOVS(pVM, uErrorCode, pCtxCore, GCPhysFault, &Cpu, pRange, &pStat);
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync STAM_PROFILE_ADV_STOP_EX(&pVM->iom.s.StatRZInstMovs, pStat, c);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync rc = iomInterpretSTOS(pVM, pCtxCore, GCPhysFault, &Cpu, pRange);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync rc = iomInterpretLODS(pVM, pCtxCore, GCPhysFault, &Cpu, pRange);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync rc = iomInterpretCMP(pVM, pCtxCore, GCPhysFault, &Cpu, pRange);
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync rc = iomInterpretOrXorAnd(pVM, pCtxCore, GCPhysFault, &Cpu, pRange, EMEmulateAnd);
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync rc = iomInterpretOrXorAnd(pVM, pCtxCore, GCPhysFault, &Cpu, pRange, EMEmulateOr);
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync rc = iomInterpretOrXorAnd(pVM, pCtxCore, GCPhysFault, &Cpu, pRange, EMEmulateXor);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync rc = iomInterpretTEST(pVM, pCtxCore, GCPhysFault, &Cpu, pRange);
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync rc = iomInterpretBT(pVM, pCtxCore, GCPhysFault, &Cpu, pRange);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync rc = iomInterpretXCHG(pVM, pCtxCore, GCPhysFault, &Cpu, pRange);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * The instruction isn't supported. Hand it on to ring-3.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync rc = (uErrorCode & X86_TRAP_PF_RW) ? VINF_IOM_HC_MMIO_WRITE : VINF_IOM_HC_MMIO_READ;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * On success advance EIP.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync#if defined(VBOX_WITH_STATISTICS) && !defined(IN_RING3)
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync STAM_PROFILE_STOP(&pVM->iom.s.StatRZMMIOHandler, a);
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync * \#PF Handler callback for MMIO ranges.
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync * @returns VINF_SUCCESS if the handler have carried out the operation.
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync * @returns VINF_PGM_HANDLER_DO_DEFAULT if the caller should carry out the access operation.
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync * @param pVM VM Handle.
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync * @param GCPhys The physical address the guest is writing to.
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync * @param pvPhys The HC mapping of that address.
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync * @param pvBuf What the guest is reading/writing.
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync * @param cbBuf How much it's reading/writing.
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync * @param enmAccessType The access type.
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync * @param pvUser Pointer to the MMIO range entry.
e131925debcc0add6ebecf92e6d09d62150476a4vboxsyncDECLCALLBACK(int) IOMR3MMIOHandler(PVM pVM, RTGCPHYS GCPhysFault, void *pvPhys, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, void *pvUser)
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync AssertMsg(cbBuf == 1 || cbBuf == 2 || cbBuf == 4 || cbBuf == 8, ("%zu\n", cbBuf));
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync Assert(pRange == iomMMIOGetRange(&pVM->iom.s, GCPhysFault));
5ae72b1f28e1d602e74d89e79e43778c9fc18203vboxsync rc = iomMMIODoRead(pVM, pRange, GCPhysFault, pvBuf, (unsigned)cbBuf);
5ae72b1f28e1d602e74d89e79e43778c9fc18203vboxsync rc = iomMMIODoWrite(pVM, pRange, GCPhysFault, pvBuf, (unsigned)cbBuf);
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync#endif /* IN_RING3 */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Reads a MMIO register.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhys The physical address to read.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pu32Value Where to store the value read.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param cbValue The size of the register to read in bytes. 1, 2 or 4 bytes.
9ad5e3912962c3dbccc1afc4e7d62890fe906814vboxsyncVMMDECL(int) IOMMMIORead(PVM pVM, RTGCPHYS GCPhys, uint32_t *pu32Value, size_t cbValue)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Lookup the current context range node and statistics.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync PIOMMMIORANGE pRange = iomMMIOGetRange(&pVM->iom.s, GCPhys);
b1c3cdef473df2fbc621d5da81acc82dbfb8a11avboxsync ("Handlers and page tables are out of sync or something! GCPhys=%RGp cbValue=%d\n", GCPhys, cbValue),
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync PIOMMMIOSTATS pStats = iomMMIOGetStats(&pVM->iom.s, GCPhys, pRange);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#endif /* VBOX_WITH_STATISTICS */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Perform the read and deal with the result.
be2a61911f40a64584c3c7188104f45e0c4311ddvboxsync STAM_PROFILE_ADV_START(&pStats->CTX_SUFF_Z(ProfRead), a);
5ae72b1f28e1d602e74d89e79e43778c9fc18203vboxsync int rc = pRange->CTX_SUFF(pfnReadCallback)(pRange->CTX_SUFF(pDevIns), pRange->CTX_SUFF(pvUser), GCPhys, pu32Value, (unsigned)cbValue);
be2a61911f40a64584c3c7188104f45e0c4311ddvboxsync STAM_PROFILE_ADV_STOP(&pStats->CTX_SUFF_Z(ProfRead), a);
b3547e42ce5221377866e3fa041b3086b7cc1562vboxsync Log4(("IOMMMIORead: GCPhys=%RGp *pu32=%08RX32 cb=%d rc=%Rrc\n", GCPhys, *pu32Value, cbValue, rc));
212d777d7378ef2a3ecc028df71ca7b82b9cb1dcvboxsync case 1: *(uint8_t *)pu32Value = UINT8_C(0x00); break;
212d777d7378ef2a3ecc028df71ca7b82b9cb1dcvboxsync case 2: *(uint16_t *)pu32Value = UINT16_C(0x0000); break;
212d777d7378ef2a3ecc028df71ca7b82b9cb1dcvboxsync case 4: *(uint32_t *)pu32Value = UINT32_C(0x00000000); break;
212d777d7378ef2a3ecc028df71ca7b82b9cb1dcvboxsync case 8: *(uint64_t *)pu32Value = UINT64_C(0x0000000000000000); break;
b1c3cdef473df2fbc621d5da81acc82dbfb8a11avboxsync default: AssertReleaseMsgFailed(("cbValue=%d GCPhys=%RGp\n", cbValue, GCPhys)); break;
b3547e42ce5221377866e3fa041b3086b7cc1562vboxsync Log4(("IOMMMIORead: GCPhys=%RGp *pu32=%08RX32 cb=%d rc=%Rrc\n", GCPhys, *pu32Value, cbValue, rc));
212d777d7378ef2a3ecc028df71ca7b82b9cb1dcvboxsync case 1: *(uint8_t *)pu32Value = UINT8_C(0xff); break;
212d777d7378ef2a3ecc028df71ca7b82b9cb1dcvboxsync case 2: *(uint16_t *)pu32Value = UINT16_C(0xffff); break;
212d777d7378ef2a3ecc028df71ca7b82b9cb1dcvboxsync case 4: *(uint32_t *)pu32Value = UINT32_C(0xffffffff); break;
212d777d7378ef2a3ecc028df71ca7b82b9cb1dcvboxsync case 8: *(uint64_t *)pu32Value = UINT64_C(0xffffffffffffffff); break;
b1c3cdef473df2fbc621d5da81acc82dbfb8a11avboxsync default: AssertReleaseMsgFailed(("cbValue=%d GCPhys=%RGp\n", cbValue, GCPhys)); break;
b3547e42ce5221377866e3fa041b3086b7cc1562vboxsync Log4(("IOMMMIORead: GCPhys=%RGp *pu32=%08RX32 cb=%d rc=%Rrc\n", GCPhys, *pu32Value, cbValue, rc));
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * Lookup the ring-3 range.
afc45562e8673a50bc8cb53333049d67fef30bcbvboxsync /* Unassigned memory; this is actually not supposed to happen. */
e718c14033c9205b4264213b6583a936692861d2vboxsync case 1: *(uint8_t *)pu32Value = UINT8_C(0xff); break;
e718c14033c9205b4264213b6583a936692861d2vboxsync case 2: *(uint16_t *)pu32Value = UINT16_C(0xffff); break;
e718c14033c9205b4264213b6583a936692861d2vboxsync case 4: *(uint32_t *)pu32Value = UINT32_C(0xffffffff); break;
e718c14033c9205b4264213b6583a936692861d2vboxsync case 8: *(uint64_t *)pu32Value = UINT64_C(0xffffffffffffffff); break;
b1c3cdef473df2fbc621d5da81acc82dbfb8a11avboxsync default: AssertReleaseMsgFailed(("cbValue=%d GCPhys=%RGp\n", cbValue, GCPhys)); break;
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync Log4(("IOMMMIORead: GCPhys=%RGp *pu32=%08RX32 cb=%d rc=VINF_SUCCESS\n", GCPhys, *pu32Value, cbValue));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Writes to a MMIO register.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhys The physical address to write to.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param u32Value The value to write.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param cbValue The size of the register to read in bytes. 1, 2 or 4 bytes.
9ad5e3912962c3dbccc1afc4e7d62890fe906814vboxsyncVMMDECL(int) IOMMMIOWrite(PVM pVM, RTGCPHYS GCPhys, uint32_t u32Value, size_t cbValue)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Lookup the current context range node.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync PIOMMMIORANGE pRange = iomMMIOGetRange(&pVM->iom.s, GCPhys);
b1c3cdef473df2fbc621d5da81acc82dbfb8a11avboxsync ("Handlers and page tables are out of sync or something! GCPhys=%RGp cbValue=%d\n", GCPhys, cbValue),
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync PIOMMMIOSTATS pStats = iomMMIOGetStats(&pVM->iom.s, GCPhys, pRange);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#endif /* VBOX_WITH_STATISTICS */
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * Perform the write if there's a write handler. R0/GC may have
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * to defer it to ring-3.
be2a61911f40a64584c3c7188104f45e0c4311ddvboxsync STAM_PROFILE_ADV_START(&pStats->CTX_SUFF_Z(ProfWrite), a);
5ae72b1f28e1d602e74d89e79e43778c9fc18203vboxsync int rc = pRange->CTX_SUFF(pfnWriteCallback)(pRange->CTX_SUFF(pDevIns), pRange->CTX_SUFF(pvUser), GCPhys, &u32Value, (unsigned)cbValue);
be2a61911f40a64584c3c7188104f45e0c4311ddvboxsync STAM_PROFILE_ADV_STOP(&pStats->CTX_SUFF_Z(ProfWrite), a);
b3547e42ce5221377866e3fa041b3086b7cc1562vboxsync Log4(("IOMMMIOWrite: GCPhys=%RGp u32=%08RX32 cb=%d rc=%Rrc\n", GCPhys, u32Value, cbValue, rc));
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * No write handler, nothing to do.
b3547e42ce5221377866e3fa041b3086b7cc1562vboxsync Log4(("IOMMMIOWrite: GCPhys=%RGp u32=%08RX32 cb=%d rc=%Rrc\n", GCPhys, u32Value, cbValue, VINF_SUCCESS));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * ES:EDI,DX[,ECX]
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @remark Assumes caller checked the access privileges (IOMInterpretCheckPortIOAccess)
a82df5167acec0c75d741d08c1d05a4007e3d50evboxsync * @returns Strict VBox status code. Informational status codes other than the one documented
be2589a6f7086676e45b18d204bb1064889dc586vboxsync * here are to be treated as internal failure. Use IOM_SUCCESS() to check for success.
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @retval VINF_SUCCESS Success.
a82df5167acec0c75d741d08c1d05a4007e3d50evboxsync * @retval VINF_EM_FIRST-VINF_EM_LAST Success with some exceptions (see IOM_SUCCESS()), the
be2589a6f7086676e45b18d204bb1064889dc586vboxsync * status code must be passed on to EM.
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @retval VINF_IOM_HC_IOPORT_READ Defer the read to ring-3. (R0/GC only)
a82df5167acec0c75d741d08c1d05a4007e3d50evboxsync * @retval VINF_EM_RAW_EMULATE_INSTR Defer the read to the REM.
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @retval VINF_EM_RAW_GUEST_TRAP The exception was left pending. (TRPMRaiseXcptErr)
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @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)
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @param pVM The virtual machine.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRegFrame Pointer to CPUMCTXCORE guest registers structure.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param uPort IO Port
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param uPrefix IO instruction prefix
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param cbTransfer Size of transfer unit
9ad5e3912962c3dbccc1afc4e7d62890fe906814vboxsyncVMMDECL(int) IOMInterpretINSEx(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t uPort, uint32_t uPrefix, uint32_t cbTransfer)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * We do not support REPNE or decrementing destination
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * pointer. Segment prefixes are deliberately ignored, as per the instruction specification.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Get bytes/words/dwords count to transfer.
f5395a2af3050ddd694b0ad505975f7b717ab4f1vboxsync if (SELMGetCpuModeFromSelector(pVM, pRegFrame->eflags, pRegFrame->cs, &pRegFrame->csHid) == CPUMODE_16BIT)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Convert destination address es:edi. */
13d75a5db336ccb682d7ab28b397a4f0b8982ea3vboxsync int rc = SELMToFlatEx(pVM, DIS_SELREG_ES, pRegFrame, (RTGCPTR)pRegFrame->rdi,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("INS destination address conversion failed -> fallback, rc=%d\n", rc));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Access verification first; we can't recover from traps inside this instruction, as the port read cannot be repeated. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = PGMVerifyAccess(pVM, (RTGCUINTPTR)GCPtrDst, cTransfers * cbTransfer,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("INS will generate a trap -> fallback, rc=%d\n", rc));
65047a71308d9524254c8f60dc1371cf5679d53avboxsync Log(("IOM: rep ins%d port %#x count %d\n", cbTransfer * 8, uPort, cTransfers));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* If the device supports string transfers, ask it to do as
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * much as it wants. The rest is done with single-word transfers. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = IOMIOPortReadString(pVM, uPort, &GCPtrDst, &cTransfers, cbTransfer);
13d75a5db336ccb682d7ab28b397a4f0b8982ea3vboxsync pRegFrame->rdi += (cTransfersOrg - cTransfers) * cbTransfer;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = IOMIOPortRead(pVM, uPort, &u32Value, cbTransfer);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc2 = iomRamWrite(pVM, GCPtrDst, &u32Value, cbTransfer);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync GCPtrDst = (RTGCPTR)((RTGCUINTPTR)GCPtrDst + cbTransfer);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Update ecx on exit. */
b3547e42ce5221377866e3fa041b3086b7cc1562vboxsync AssertMsg(rc == VINF_SUCCESS || rc == VINF_IOM_HC_IOPORT_READ || (rc >= VINF_EM_FIRST && rc <= VINF_EM_LAST) || RT_FAILURE(rc), ("%Rrc\n", rc));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * ES:EDI,DX[,ECX]
a82df5167acec0c75d741d08c1d05a4007e3d50evboxsync * @returns Strict VBox status code. Informational status codes other than the one documented
be2589a6f7086676e45b18d204bb1064889dc586vboxsync * here are to be treated as internal failure. Use IOM_SUCCESS() to check for success.
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @retval VINF_SUCCESS Success.
a82df5167acec0c75d741d08c1d05a4007e3d50evboxsync * @retval VINF_EM_FIRST-VINF_EM_LAST Success with some exceptions (see IOM_SUCCESS()), the
be2589a6f7086676e45b18d204bb1064889dc586vboxsync * status code must be passed on to EM.
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @retval VINF_IOM_HC_IOPORT_READ Defer the read to ring-3. (R0/GC only)
a82df5167acec0c75d741d08c1d05a4007e3d50evboxsync * @retval VINF_EM_RAW_EMULATE_INSTR Defer the read to the REM.
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @retval VINF_EM_RAW_GUEST_TRAP The exception was left pending. (TRPMRaiseXcptErr)
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @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)
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @param pVM The virtual machine.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRegFrame Pointer to CPUMCTXCORE guest registers structure.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pCpu Disassembler CPU state.
9ad5e3912962c3dbccc1afc4e7d62890fe906814vboxsyncVMMDECL(int) IOMInterpretINS(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Get port number directly from the register (no need to bother the
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * disassembler). And get the I/O register size from the opcode / prefix.
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync unsigned cb = 0;
fe376b8f218c234c1ba918513340aff917aa7925vboxsync cb = (pCpu->opmode == CPUMODE_16BIT) ? 2 : 4; /* dword in both 32 & 64 bits mode */
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync int rc = IOMInterpretCheckPortIOAccess(pVM, pRegFrame, Port, cb);
b3547e42ce5221377866e3fa041b3086b7cc1562vboxsync AssertMsg(rc == VINF_EM_RAW_GUEST_TRAP || rc == VINF_TRPM_XCPT_DISPATCHED || rc == VINF_TRPM_XCPT_DISPATCHED || RT_FAILURE(rc), ("%Rrc\n", rc));
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync return IOMInterpretINSEx(pVM, pRegFrame, Port, pCpu->prefix, cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * DS:ESI,DX[,ECX]
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @remark Assumes caller checked the access privileges (IOMInterpretCheckPortIOAccess)
a82df5167acec0c75d741d08c1d05a4007e3d50evboxsync * @returns Strict VBox status code. Informational status codes other than the one documented
be2589a6f7086676e45b18d204bb1064889dc586vboxsync * here are to be treated as internal failure. Use IOM_SUCCESS() to check for success.
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @retval VINF_SUCCESS Success.
a82df5167acec0c75d741d08c1d05a4007e3d50evboxsync * @retval VINF_EM_FIRST-VINF_EM_LAST Success with some exceptions (see IOM_SUCCESS()), the
be2589a6f7086676e45b18d204bb1064889dc586vboxsync * status code must be passed on to EM.
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @retval VINF_IOM_HC_IOPORT_WRITE Defer the write to ring-3. (R0/GC only)
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @retval VINF_EM_RAW_GUEST_TRAP The exception was left pending. (TRPMRaiseXcptErr)
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @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)
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @param pVM The virtual machine.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRegFrame Pointer to CPUMCTXCORE guest registers structure.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param uPort IO Port
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param uPrefix IO instruction prefix
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param cbTransfer Size of transfer unit
9ad5e3912962c3dbccc1afc4e7d62890fe906814vboxsyncVMMDECL(int) IOMInterpretOUTSEx(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t uPort, uint32_t uPrefix, uint32_t cbTransfer)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * We do not support segment prefixes, REPNE or
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * decrementing source pointer.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Get bytes/words/dwords count to transfer.
f5395a2af3050ddd694b0ad505975f7b717ab4f1vboxsync if (SELMGetCpuModeFromSelector(pVM, pRegFrame->eflags, pRegFrame->cs, &pRegFrame->csHid) == CPUMODE_16BIT)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Convert source address ds:esi. */
13d75a5db336ccb682d7ab28b397a4f0b8982ea3vboxsync int rc = SELMToFlatEx(pVM, DIS_SELREG_DS, pRegFrame, (RTGCPTR)pRegFrame->rsi,
b3547e42ce5221377866e3fa041b3086b7cc1562vboxsync Log(("OUTS source address conversion failed -> fallback, rc=%Rrc\n", rc));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Access verification first; we currently can't recover properly from traps inside this instruction */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = PGMVerifyAccess(pVM, (RTGCUINTPTR)GCPtrSrc, cTransfers * cbTransfer,
b3547e42ce5221377866e3fa041b3086b7cc1562vboxsync Log(("OUTS will generate a trap -> fallback, rc=%Rrc\n", rc));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("IOM: rep outs%d port %#x count %d\n", cbTransfer * 8, uPort, cTransfers));
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * If the device supports string transfers, ask it to do as
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * much as it wants. The rest is done with single-word transfers.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = IOMIOPortWriteString(pVM, uPort, &GCPtrSrc, &cTransfers, cbTransfer);
13d75a5db336ccb682d7ab28b397a4f0b8982ea3vboxsync pRegFrame->rsi += (cTransfersOrg - cTransfers) * cbTransfer;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = iomRamRead(pVM, &u32Value, GCPtrSrc, cbTransfer);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = IOMIOPortWrite(pVM, uPort, u32Value, cbTransfer);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync GCPtrSrc = (RTGCPTR)((RTUINTPTR)GCPtrSrc + cbTransfer);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Update ecx on exit. */
b3547e42ce5221377866e3fa041b3086b7cc1562vboxsync AssertMsg(rc == VINF_SUCCESS || rc == VINF_IOM_HC_IOPORT_WRITE || (rc >= VINF_EM_FIRST && rc <= VINF_EM_LAST) || RT_FAILURE(rc), ("%Rrc\n", rc));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * DS:ESI,DX[,ECX]
a82df5167acec0c75d741d08c1d05a4007e3d50evboxsync * @returns Strict VBox status code. Informational status codes other than the one documented
be2589a6f7086676e45b18d204bb1064889dc586vboxsync * here are to be treated as internal failure. Use IOM_SUCCESS() to check for success.
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @retval VINF_SUCCESS Success.
a82df5167acec0c75d741d08c1d05a4007e3d50evboxsync * @retval VINF_EM_FIRST-VINF_EM_LAST Success with some exceptions (see IOM_SUCCESS()), the
be2589a6f7086676e45b18d204bb1064889dc586vboxsync * status code must be passed on to EM.
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @retval VINF_IOM_HC_IOPORT_WRITE Defer the write to ring-3. (R0/GC only)
a82df5167acec0c75d741d08c1d05a4007e3d50evboxsync * @retval VINF_EM_RAW_EMULATE_INSTR Defer the write to the REM.
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @retval VINF_EM_RAW_GUEST_TRAP The exception was left pending. (TRPMRaiseXcptErr)
d8df004f4caf4f71e78f0be1cc2e2a918358ae9fvboxsync * @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)
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @param pVM The virtual machine.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRegFrame Pointer to CPUMCTXCORE guest registers structure.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pCpu Disassembler CPU state.
9ad5e3912962c3dbccc1afc4e7d62890fe906814vboxsyncVMMDECL(int) IOMInterpretOUTS(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Get port number from the first parameter.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * And get the I/O register size from the opcode / prefix.
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync unsigned cb = 0;
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync bool fRc = iomGetRegImmData(pCpu, &pCpu->param1, pRegFrame, &Port, &cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(fRc, ("Failed to get reg/imm port number!\n")); NOREF(fRc);
fe376b8f218c234c1ba918513340aff917aa7925vboxsync cb = (pCpu->opmode == CPUMODE_16BIT) ? 2 : 4; /* dword in both 32 & 64 bits mode */
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync int rc = IOMInterpretCheckPortIOAccess(pVM, pRegFrame, Port, cb);
b3547e42ce5221377866e3fa041b3086b7cc1562vboxsync AssertMsg(rc == VINF_EM_RAW_GUEST_TRAP || rc == VINF_TRPM_XCPT_DISPATCHED || rc == VINF_TRPM_XCPT_DISPATCHED || RT_FAILURE(rc), ("%Rrc\n", rc));
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync return IOMInterpretOUTSEx(pVM, pRegFrame, Port, pCpu->prefix, cb);
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * Modify an existing MMIO region page; map to another guest physical region and change the access flags
ebe05ec36d1fcd24d62e7066dedcb4eb2e691358vboxsync * @returns VBox status code.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @param pVM The virtual machine.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @param GCPhys Physical address that's part of the MMIO region to be changed.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @param GCPhysRemapped Remapped address.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @param fPageFlags Page flags to set (typically X86_PTE_RW).
ebe05ec36d1fcd24d62e7066dedcb4eb2e691358vboxsyncVMMDECL(int) IOMMMIOModifyPage(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysRemapped, uint64_t fPageFlags)
b1c3cdef473df2fbc621d5da81acc82dbfb8a11avboxsync Log(("IOMMMIOModifyPage %RGp -> %RGp flags=%RX64\n", GCPhys, GCPhysRemapped, fPageFlags));
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * Lookup the current context range node and statistics.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync PIOMMMIORANGE pRange = iomMMIOGetRange(&pVM->iom.s, GCPhys);
b1c3cdef473df2fbc621d5da81acc82dbfb8a11avboxsync ("Handlers and page tables are out of sync or something! GCPhys=%RGp\n", GCPhys),
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync /* This currently only works in real mode, protected mode without paging or with nested paging. */
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync int rc = PGMHandlerPhysicalPageAlias(pVM, pRange->GCPhys, GCPhys, GCPhysRemapped);
9243c25e887b8f49e764b130c132bbe1b60bed50vboxsync rc = PGMShwGetPage(pVM, (RTGCPTR)GCPhys, &fFlags, &HCPhys);
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync /* Mark it as writable and present so reads and writes no longer fault. */
ae9ec50c70638edbb5128ccc1577e568f3fa3982vboxsync rc = PGMShwModifyPage(pVM, (RTGCPTR)GCPhys, 1, fPageFlags, ~fPageFlags);
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * Reset a previously modified MMIO region; restore the access flags.
ebe05ec36d1fcd24d62e7066dedcb4eb2e691358vboxsync * @returns VBox status code.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @param pVM The virtual machine.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * @param GCPhys Physical address that's part of the MMIO region to be reset.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsyncVMMDECL(int) IOMMMIOResetRegion(PVM pVM, RTGCPHYS GCPhys)
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync * Lookup the current context range node and statistics.
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync PIOMMMIORANGE pRange = iomMMIOGetRange(&pVM->iom.s, GCPhys);
b1c3cdef473df2fbc621d5da81acc82dbfb8a11avboxsync ("Handlers and page tables are out of sync or something! GCPhys=%RGp\n", GCPhys),
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync /* This currently only works in real mode, protected mode without paging or with nested paging. */
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync int rc = PGMHandlerPhysicalPageReset(pVM, pRange->GCPhys, GCPhys);
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync /* Mark it as not present again to intercept all read and write access. */
ae9ec50c70638edbb5128ccc1577e568f3fa3982vboxsync rc = PGMShwModifyPage(pVM, (RTGCPTR)GCPhys, 1, 0, ~(uint64_t)(X86_PTE_RW|X86_PTE_P));
996e3c380ffc191ee846a2384f2ec876d2b194a6vboxsync rc = PGMShwGetPage(pVM, (RTGCPTR)GCPhys, &fFlags, &HCPhys);
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync#endif /* !IN_RC */