IOMAll.cpp revision 1c531d81a4aed214aace5672d8c3436023949bea
/* $Id$ */
/** @file
* IOM - Input / Output Monitor - Any Context.
*/
/*
* Copyright (C) 2006 InnoTek Systemberatung GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License as published by the Free Software Foundation,
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
* distribution. VirtualBox OSE is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY of any kind.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_IOM
#include "IOMInternal.h"
/**
* Registers a Port IO GC handler.
*
* This API is called by PDM on behalf of a device. Devices must first register ring-3 ranges
* using IOMIOPortRegisterR3() before calling this function.
*
*
* @returns VBox status code.
*
* @param pVM VM handle.
* @param pDevIns PDM device instance owning the port range.
* @param PortStart First port number in the range.
* @param cPorts Number of ports to register.
* @param pvUser User argument for the callbacks.
* @param pfnOutCallback Pointer to function which is gonna handle OUT operations in GC.
* @param pfnInCallback Pointer to function which is gonna handle IN operations in GC.
* @param pfnOutStrCallback Pointer to function which is gonna handle string OUT operations in GC.
* @param pfnInStrCallback Pointer to function which is gonna handle string IN operations in GC.
* @param pszDesc Pointer to description string. This must not be freed.
*/
IOMDECL(int) IOMIOPortRegisterGC(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts, RTGCPTR pvUser,
GCPTRTYPE(PFNIOMIOPORTOUTSTRING) pfnOutStrCallback, GCPTRTYPE(PFNIOMIOPORTINSTRING) pfnInStrCallback, const char *pszDesc)
{
LogFlow(("IOMIOPortRegisterGC: pDevIns=%p PortStart=%#x cPorts=%#x pvUser=%VGv pfnOutCallback=%VGv pfnInCallback=%VGv pfnOutStrCallback=%VGv pfnInStrCallback=%VGv pszDesc=%s\n",
pDevIns, PortStart, cPorts, pvUser, pfnOutCallback, pfnInCallback, pfnOutStrCallback, pfnInStrCallback, pszDesc));
/*
* Validate input.
*/
{
AssertMsgFailed(("Invalid port range %#x-%#x! (%s)\n", PortStart, (RTUINT)PortStart + (cPorts - 1), pszDesc));
return VERR_IOM_INVALID_IOPORT_RANGE;
}
if (!pfnOutCallback && !pfnInCallback)
{
AssertMsgFailed(("Invalid port range %#x-%#x! No callbacks! (%s)\n", PortStart, PortLast, pszDesc));
return VERR_INVALID_PARAMETER;
}
/*
* Validate that there are ring-3 ranges for the ports.
*/
{
PIOMIOPORTRANGER3 pRange = (PIOMIOPORTRANGER3)RTAvlroIOPortRangeGet(&pVM->iom.s.CTXSUFF(pTrees)->IOPortTreeR3, Port);
if (!pRange)
{
AssertMsgFailed(("No R3! Port=#x %#x-%#x! (%s)\n", Port, PortStart, (unsigned)PortStart + cPorts - 1, pszDesc));
return VERR_IOM_NO_HC_IOPORT_RANGE;
}
#ifndef IOM_NO_PDMINS_CHECKS
#ifndef IN_GC
#else
#endif
{
AssertMsgFailed(("Not owner! Port=%#x %#x-%#x! (%s)\n", Port, PortStart, (unsigned)PortStart + cPorts - 1, pszDesc));
return VERR_IOM_NOT_IOPORT_RANGE_OWNER;
}
#endif
}
/* Flush the IO port lookup cache */
/*
* Allocate new range record and initialize it.
*/
if (VBOX_SUCCESS(rc))
{
#ifdef IN_GC
#else
#endif
/*
* Insert it.
*/
return VINF_SUCCESS;
/* conflict. */
AssertMsgFailed(("Port range %#x-%#x (%s) conflicts with existing range(s)!\n", PortStart, (unsigned)PortStart + cPorts - 1, pszDesc));
}
return rc;
}
/**
* Registers a Memory Mapped I/O GC handler range.
*
* This API is called by PDM on behalf of a device. Devices must first register ring-3 ranges
* using IOMMMIORegisterR3() before calling this function.
*
*
* @returns VBox status code.
*
* @param pVM VM handle.
* @param pDevIns PDM device instance owning the MMIO range.
* @param GCPhysStart First physical address in the range.
* @param cbRange The size of the range (in bytes).
* @param pvUser User argument for the callbacks.
* @param pfnWriteCallback Pointer to function which is gonna handle Write operations.
* @param pfnReadCallback Pointer to function which is gonna handle Read operations.
* @param pszDesc Pointer to description string. This must not be freed.
*/
IOMDECL(int) IOMMMIORegisterGC(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTGCPTR pvUser,
{
LogFlow(("IOMMMIORegisterGC: pDevIns=%p GCPhysStart=%#x cbRange=%#x pvUser=%VGv pfnWriteCallback=%#x pfnReadCallback=%#x pfnFillCallback=%#x pszDesc=%s\n",
pDevIns, GCPhysStart, cbRange, pvUser, pfnWriteCallback, pfnReadCallback, pfnFillCallback, pszDesc));
/*
* Validate input.
*/
if (!pfnWriteCallback && !pfnReadCallback)
{
return VERR_INVALID_PARAMETER;
}
if (GCPhysLast < GCPhysStart)
{
return VERR_IOM_INVALID_MMIO_RANGE;
}
/*
* Check that a ring-3 MMIO range exists.
*/
{
PIOMMMIORANGER3 pRange = (PIOMMMIORANGER3)RTAvlroGCPhysRangeGet(&pVM->iom.s.CTXSUFF(pTrees)->MMIOTreeR3, GCPhys);
if (!pRange)
{
return VERR_IOM_NO_HC_MMIO_RANGE;
}
#ifndef IOM_NO_PDMINS_CHECKS
#ifndef IN_GC
#else
#endif
{
AssertMsgFailed(("Not owner! GCPhys=%#x %#x LB%#x %s / %#x-%#x %s\n", GCPhys, GCPhysStart, cbRange, pszDesc,
return VERR_IOM_NOT_MMIO_RANGE_OWNER;
}
#endif /* !IOM_NO_PDMINS_CHECKS */
/* next */
}
/*
* Allocate new range record and initialize it.
*/
if (VBOX_SUCCESS(rc))
{
#ifdef IN_GC
#else
#endif
/*
* Try insert it.
*/
return VINF_SUCCESS;
}
return rc;
}
/**
* Registers a Port IO R0 handler.
*
* This API is called by PDM on behalf of a device. Devices must first register ring-3 ranges
* using IOMR3IOPortRegisterR3() before calling this function.
*
*
* @returns VBox status code.
*
* @param pVM VM handle.
* @param pDevIns PDM device instance owning the port range.
* @param PortStart First port number in the range.
* @param cPorts Number of ports to register.
* @param pvUser User argument for the callbacks.
* @param pfnOutCallback Pointer to function which is gonna handle OUT operations in GC.
* @param pfnInCallback Pointer to function which is gonna handle IN operations in GC.
* @param pfnOutStrCallback Pointer to function which is gonna handle OUT operations in GC.
* @param pfnInStrCallback Pointer to function which is gonna handle IN operations in GC.
* @param pszDesc Pointer to description string. This must not be freed.
*/
IOMDECL(int) IOMIOPortRegisterR0(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts, RTHCPTR pvUser,
HCPTRTYPE(PFNIOMIOPORTOUTSTRING) pfnOutStrCallback, HCPTRTYPE(PFNIOMIOPORTINSTRING) pfnInStrCallback,
const char *pszDesc)
{
LogFlow(("IOMIOPortRegisterR0: pDevIns=%p PortStart=%#x cPorts=%#x pvUser=%VHv pfnOutCallback=%VGv pfnInCallback=%VGv pfnOutStrCallback=%VGv pfnInStrCallback=%VGv pszDesc=%s\n",
pDevIns, PortStart, cPorts, pvUser, pfnOutCallback, pfnInCallback, pfnOutStrCallback, pfnInStrCallback, pszDesc));
/*
* Validate input.
*/
{
AssertMsgFailed(("Invalid port range %#x-%#x! (%s)\n", PortStart, (RTUINT)PortStart + (cPorts - 1), pszDesc));
return VERR_IOM_INVALID_IOPORT_RANGE;
}
if (!pfnOutCallback && !pfnInCallback)
{
AssertMsgFailed(("Invalid port range %#x-%#x! No callbacks! (%s)\n", PortStart, PortLast, pszDesc));
return VERR_INVALID_PARAMETER;
}
/*
* Validate that there are ring-3 ranges for the ports.
*/
{
PIOMIOPORTRANGER3 pRange = (PIOMIOPORTRANGER3)RTAvlroIOPortRangeGet(&pVM->iom.s.CTXSUFF(pTrees)->IOPortTreeR3, Port);
if (!pRange)
{
AssertMsgFailed(("No R3! Port=#x %#x-%#x! (%s)\n", Port, PortStart, (unsigned)PortStart + cPorts - 1, pszDesc));
return VERR_IOM_NO_HC_IOPORT_RANGE;
}
#ifndef IOM_NO_PDMINS_CHECKS
# ifndef IN_GC
# else
# endif
{
AssertMsgFailed(("Not owner! Port=%#x %#x-%#x! (%s)\n", Port, PortStart, (unsigned)PortStart + cPorts - 1, pszDesc));
return VERR_IOM_NOT_IOPORT_RANGE_OWNER;
}
#endif
}
/* Flush the IO port lookup cache */
/*
* Allocate new range record and initialize it.
*/
if (VBOX_SUCCESS(rc))
{
#ifdef IN_GC
#else
#endif
/*
* Insert it.
*/
return VINF_SUCCESS;
/* conflict. */
AssertMsgFailed(("Port range %#x-%#x (%s) conflicts with existing range(s)!\n", PortStart, (unsigned)PortStart + cPorts - 1, pszDesc));
}
return rc;
}
/**
* Registers a Memory Mapped I/O R0 handler range.
*
* This API is called by PDM on behalf of a device. Devices must first register ring-3 ranges
* using IOMMR3MIORegisterHC() before calling this function.
*
*
* @returns VBox status code.
*
* @param pVM VM handle.
* @param pDevIns PDM device instance owning the MMIO range.
* @param GCPhysStart First physical address in the range.
* @param cbRange The size of the range (in bytes).
* @param pvUser User argument for the callbacks.
* @param pfnWriteCallback Pointer to function which is gonna handle Write operations.
* @param pfnReadCallback Pointer to function which is gonna handle Read operations.
* @param pszDesc Pointer to description string. This must not be freed.
*/
IOMDECL(int) IOMMMIORegisterR0(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTHCPTR pvUser,
{
LogFlow(("IOMMMIORegisterR0: pDevIns=%p GCPhysStart=%#x cbRange=%#x pvUser=%VHv pfnWriteCallback=%#x pfnReadCallback=%#x pfnFillCallback=%#x pszDesc=%s\n",
pDevIns, GCPhysStart, cbRange, pvUser, pfnWriteCallback, pfnReadCallback, pfnFillCallback, pszDesc));
/*
* Validate input.
*/
if (!pfnWriteCallback && !pfnReadCallback)
{
return VERR_INVALID_PARAMETER;
}
if (GCPhysLast < GCPhysStart)
{
return VERR_IOM_INVALID_MMIO_RANGE;
}
/*
* Check that a ring-3 MMIO range exists.
*/
{
PIOMMMIORANGER3 pRange = (PIOMMMIORANGER3)RTAvlroGCPhysRangeGet(&pVM->iom.s.CTXSUFF(pTrees)->MMIOTreeR3, GCPhys);
if (!pRange)
{
return VERR_IOM_NO_HC_MMIO_RANGE;
}
#ifndef IOM_NO_PDMINS_CHECKS
# ifndef IN_GC
# else
# endif
{
AssertMsgFailed(("Not owner! GCPhys=%#x %#x LB%#x %s / %#x-%#x %s\n", GCPhys, GCPhysStart, cbRange, pszDesc,
return VERR_IOM_NOT_MMIO_RANGE_OWNER;
}
#endif /* !IOM_NO_PDMINS_CHECKS */
/* next */
}
/*
* Allocate new range record and initialize it.
*/
if (VBOX_SUCCESS(rc))
{
#ifdef IN_GC
#else
#endif
/*
* Try insert it.
*/
return VINF_SUCCESS;
}
return rc;
}
/**
* Flushes the IOM port & statistics lookup cache
*
* @param pVM The VM.
*/
{
/*
*/
}
//#undef LOG_GROUP
//#define LOG_GROUP LOG_GROUP_IOM_IOPORT
/**
* Reads an I/O port register.
*
* @returns VBox status code.
*
* @param pVM VM handle.
* @param Port The port to read.
* @param pu32Value Where to store the value read.
* @param cbValue The size of the register to read in bytes. 1, 2 or 4 bytes.
*/
{
#ifdef VBOX_WITH_STATISTICS
/*
* Get the statistics record.
*/
{
if (pStats)
}
#endif
/*
* Get handler for current context.
*/
if ( !pRange
{
if (pRange)
}
#ifdef IN_GC
Assert(!pRange || MMHyperIsInsideArea(pVM, pRange)); /** @todo r=bird: there is a macro for this which skips the #if'ing. */
#endif
if (pRange)
{
/*
* Found a range.
*/
#ifndef IN_RING3
if (!pRange->pfnInCallback)
{
# ifdef VBOX_WITH_STATISTICS
if (pStats)
# endif
return VINF_IOM_HC_IOPORT_READ;
}
#endif
/* call the device. */
#ifdef VBOX_WITH_STATISTICS
if (pStats)
#endif
#ifdef VBOX_WITH_STATISTICS
if (pStats)
# ifndef IN_RING3
# endif
#endif
if (rc == VERR_IOM_IOPORT_UNUSED)
{
/* make return value */
rc = VINF_SUCCESS;
switch (cbValue)
{
default:
return VERR_IOM_INVALID_IOPORT_SIZE;
}
}
return rc;
}
#ifndef IN_RING3
/*
* Handler in ring-3?
*/
if (pRangeR3)
{
# ifdef VBOX_WITH_STATISTICS
if (pStats)
# endif
return VINF_IOM_HC_IOPORT_READ;
}
#endif
/*
* Ok, no handler for this port.
*/
#ifdef VBOX_WITH_STATISTICS
if (pStats)
else
{
# ifndef IN_RING3
/* Ring-3 will have to create the statistics record. */
return VINF_IOM_HC_IOPORT_READ;
# else
if (pStats)
# endif
}
#endif
/* make return value */
switch (cbValue)
{
default:
return VERR_IOM_INVALID_IOPORT_SIZE;
}
Log3(("IOMIOPortRead: Port=%RTiop *pu32=%08RX32 cb=%d rc=VINF_SUCCESS\n", Port, *pu32Value, cbValue));
return VINF_SUCCESS;
}
/**
* Reads the string buffer of an I/O port register.
*
* @returns VBox status code.
*
* @param pVM VM handle.
* @param Port The port to read.
* @param pGCPtrDst Pointer to the destination buffer (GC, incremented appropriately).
* @param pcTransfers Pointer to the number of transfer units to read, on return remaining transfer units.
* @param cb Size of the transfer unit (1, 2 or 4 bytes).
* */
IOMDECL(int) IOMIOPortReadString(PVM pVM, RTIOPORT Port, PRTGCPTR pGCPtrDst, PRTGCUINTREG pcTransfers, unsigned cb)
{
#ifdef LOG_ENABLED
#endif
#ifdef VBOX_WITH_STATISTICS
/*
* Get the statistics record.
*/
{
if (pStats)
}
#endif
/*
* Get handler for current context.
*/
if ( !pRange
{
if (pRange)
}
#ifdef IN_GC
Assert(!pRange || MMHyperIsInsideArea(pVM, pRange)); /** @todo r=bird: there is a macro for this which skips the #if'ing. */
#endif
if (pRange)
{
/*
* Found a range.
*/
#ifndef IN_RING3
if (!pRange->pfnInStrCallback)
{
# ifdef VBOX_WITH_STATISTICS
if (pStats)
# endif
return VINF_IOM_HC_IOPORT_READ;
}
#endif
/* call the device. */
#ifdef VBOX_WITH_STATISTICS
if (pStats)
#endif
int rc = pRange->pfnInStrCallback(pRange->pDevIns, pRange->pvUser, Port, pGCPtrDst, pcTransfers, cb);
#ifdef VBOX_WITH_STATISTICS
if (pStats)
# ifndef IN_RING3
# endif
#endif
Log3(("IOMIOPortReadStr: Port=%RTiop pGCPtrDst=%p pcTransfer=%p:{%#x->%#x} cb=%d rc=%Vrc\n",
return rc;
}
#ifndef IN_RING3
/*
* Handler in ring-3?
*/
if (pRangeR3)
{
# ifdef VBOX_WITH_STATISTICS
if (pStats)
# endif
return VINF_IOM_HC_IOPORT_READ;
}
#endif
/*
* Ok, no handler for this port.
*/
#ifdef VBOX_WITH_STATISTICS
if (pStats)
else
{
# ifndef IN_RING3
/* Ring-3 will have to create the statistics record. */
return VINF_IOM_HC_IOPORT_READ;
# else
if (pStats)
# endif
}
#endif
Log3(("IOMIOPortReadStr: Port=%RTiop pGCPtrDst=%p pcTransfer=%p:{%#x->%#x} cb=%d rc=VINF_SUCCESS\n",
return VINF_SUCCESS;
}
/**
* Writes to an I/O port register.
*
* @returns VBox status code.
*
* @param pVM VM handle.
* @param Port The port to write to.
* @param u32Value The value to write.
* @param cbValue The size of the register to read in bytes. 1, 2 or 4 bytes.
*/
{
/** @todo bird: When I get time, I'll remove the GC tree and link the GC entries to the ring-3 node. */
#ifdef VBOX_WITH_STATISTICS
/*
* Find the statistics record.
*/
{
if (pStats)
}
#endif
/*
* Get handler for current context.
*/
if ( !pRange
{
if (pRange)
}
#ifdef IN_GC
#endif
if (pRange)
{
/*
* Found a range.
*/
#ifndef IN_RING3
if (!pRange->pfnOutCallback)
{
# ifdef VBOX_WITH_STATISTICS
if (pStats)
# endif
return VINF_IOM_HC_IOPORT_WRITE;
}
#endif
/* call the device. */
#ifdef VBOX_WITH_STATISTICS
if (pStats)
#endif
#ifdef VBOX_WITH_STATISTICS
if (pStats)
# ifndef IN_RING3
# endif
#endif
return rc;
}
#ifndef IN_RING3
/*
* Handler in ring-3?
*/
if (pRangeR3)
{
# ifdef VBOX_WITH_STATISTICS
if (pStats)
# endif
return VINF_IOM_HC_IOPORT_WRITE;
}
#endif
/*
* Ok, no handler for that port.
*/
#ifdef VBOX_WITH_STATISTICS
/* statistics. */
if (pStats)
else
{
# ifndef IN_RING3
/* R3 will have to create the statistics record. */
return VINF_IOM_HC_IOPORT_WRITE;
# else
if (pStats)
# endif
}
#endif
return VINF_SUCCESS;
}
/**
* Writes the string buffer of an I/O port register.
*
* @returns VBox status code.
*
* @param pVM VM handle.
* @param Port The port to write.
* @param pGCPtrSrc Pointer to the source buffer (GC, incremented appropriately).
* @param pcTransfers Pointer to the number of transfer units to write, on return remaining transfer units.
* @param cb Size of the transfer unit (1, 2 or 4 bytes).
* */
IOMDECL(int) IOMIOPortWriteString(PVM pVM, RTIOPORT Port, PRTGCPTR pGCPtrSrc, PRTGCUINTREG pcTransfers, unsigned cb)
{
#ifdef LOG_ENABLED
#endif
#ifdef VBOX_WITH_STATISTICS
/*
* Get the statistics record.
*/
{
if (pStats)
}
#endif
/*
* Get handler for current context.
*/
if ( !pRange
{
if (pRange)
}
#ifdef IN_GC
Assert(!pRange || MMHyperIsInsideArea(pVM, pRange)); /** @todo r=bird: there is a macro for this which skips the #if'ing. */
#endif
if (pRange)
{
/*
* Found a range.
*/
#ifndef IN_RING3
if (!pRange->pfnOutStrCallback)
{
# ifdef VBOX_WITH_STATISTICS
if (pStats)
# endif
return VINF_IOM_HC_IOPORT_WRITE;
}
#endif
/* call the device. */
#ifdef VBOX_WITH_STATISTICS
if (pStats)
#endif
int rc = pRange->pfnOutStrCallback(pRange->pDevIns, pRange->pvUser, Port, pGCPtrSrc, pcTransfers, cb);
#ifdef VBOX_WITH_STATISTICS
if (pStats)
# ifndef IN_RING3
# endif
#endif
Log3(("IOMIOPortWriteStr: Port=%RTiop pGCPtrSrc=%p pcTransfer=%p:{%#x->%#x} cb=%d rc=%Vrc\n",
return rc;
}
#ifndef IN_RING3
/*
* Handler in ring-3?
*/
if (pRangeR3)
{
# ifdef VBOX_WITH_STATISTICS
if (pStats)
# endif
return VINF_IOM_HC_IOPORT_WRITE;
}
#endif
/*
* Ok, no handler for this port.
*/
#ifdef VBOX_WITH_STATISTICS
if (pStats)
else
{
# ifndef IN_RING3
/* Ring-3 will have to create the statistics record. */
return VINF_IOM_HC_IOPORT_WRITE;
# else
if (pStats)
# endif
}
#endif
Log3(("IOMIOPortWriteStr: Port=%RTiop pGCPtrSrc=%p pcTransfer=%p:{%#x->%#x} cb=%d rc=VINF_SUCCESS\n",
return VINF_SUCCESS;
}
//#undef LOG_GROUP
//#define LOG_GROUP LOG_GROUP_IOM_MMIO
/**
* Reads a MMIO register.
*
* @returns VBox status code.
*
* @param pVM VM handle.
* @param GCPhys The physical address to read.
* @param pu32Value Where to store the value read.
* @param cbValue The size of the register to read in bytes. 1, 2 or 4 bytes.
*/
{
/** @todo add return to ring-3 statistics when this function is used in GC! */
/*
* Lookup the current context range node and statistics.
*/
#ifdef VBOX_WITH_STATISTICS
# ifdef IN_RING3
# else
return VINF_IOM_HC_MMIO_READ;
# endif
#endif /* VBOX_WITH_STATISTICS */
#ifdef IN_RING3
if (pRange)
#else /* !IN_RING3 */
#endif /* !IN_RING3 */
{
/*
* Perform the read and deal with the result.
*/
#ifdef VBOX_WITH_STATISTICS
if (pStats)
#endif
#ifdef VBOX_WITH_STATISTICS
if (pStats)
#endif
switch (rc)
{
case VINF_SUCCESS:
default:
return rc;
case VINF_IOM_MMIO_UNUSED_00:
switch (cbValue)
{
}
return VINF_SUCCESS;
case VINF_IOM_MMIO_UNUSED_FF:
switch (cbValue)
{
}
return VINF_SUCCESS;
}
}
#ifndef IN_RING3
/*
* Lookup the ring-3 range.
*/
if (pRangeR3)
{
if (pRangeR3->pfnReadCallback)
return VINF_IOM_HC_MMIO_READ;
# ifdef VBOX_WITH_STATISTICS
if (pStats)
# endif
*pu32Value = 0;
Log4(("IOMMMIORead: GCPhys=%RGp *pu32=%08RX32 cb=%d rc=VINF_SUCCESS\n", GCPhys, *pu32Value, cbValue));
return VINF_SUCCESS;
}
#endif
AssertMsgFailed(("Handlers and page tables are out of sync or something! GCPhys=%VGp cbValue=%d\n", GCPhys, cbValue));
return VERR_INTERNAL_ERROR;
}
/**
* Writes to a MMIO register.
*
* @returns VBox status code.
*
* @param pVM VM handle.
* @param GCPhys The physical address to write to.
* @param u32Value The value to write.
* @param cbValue The size of the register to read in bytes. 1, 2 or 4 bytes.
*/
{
/** @todo add return to ring-3 statistics when this function is used in GC! */
/*
* Lookup the current context range node.
*/
#ifdef VBOX_WITH_STATISTICS
# ifdef IN_RING3
# else
return VINF_IOM_HC_MMIO_WRITE;
# endif
#endif /* VBOX_WITH_STATISTICS */
/*
* Perform the write if we found a range.
*/
#ifdef IN_RING3
if (pRange)
#else /* !IN_RING3 */
#endif /* !IN_RING3 */
{
#ifdef VBOX_WITH_STATISTICS
if (pStats)
#endif
#ifdef VBOX_WITH_STATISTICS
if (pStats)
#endif
return rc;
}
#ifndef IN_RING3
/*
* Lookup the ring-3 range.
*/
if (pRangeR3)
{
if (pRangeR3->pfnWriteCallback)
return VINF_IOM_HC_MMIO_WRITE;
# ifdef VBOX_WITH_STATISTICS
if (pStats)
# endif
return VINF_SUCCESS;
}
#endif
AssertMsgFailed(("Handlers and page tables are out of sync or something! GCPhys=%VGp cbValue=%d\n", GCPhys, cbValue));
return VERR_INTERNAL_ERROR;
}
/**
* Checks that the operation is allowed according to the IOPL
* level and I/O bitmap.
*
* @returns VBox status code.
* If not VINF_SUCCESS a \#GP(0) was raised or an error occured.
*
* @param pVM VM handle.
* @param pCtxCore Pointer to register frame.
* @param Port The I/O port number.
* @param cb The access size.
*/
IOMDECL(int) IOMInterpretCheckPortIOAccess(PVM pVM, PCPUMCTXCORE pCtxCore, RTIOPORT Port, unsigned cb)
{
/*
* If this isn't ring-0, we have to check for I/O privileges.
*/
if ( ( cpl > 1
)
{
/*
* Get TSS location and check if there can be a I/O bitmap.
*/
bool fCanHaveIOBitmap;
if (VBOX_FAILURE(rc))
{
}
if ( !fCanHaveIOBitmap
{
Log(("iomInterpretCheckPortIOAccess: Port=%RTiop cb=%d cbTss=%#x fCanHaveIOBitmap=%RTbool -> #GP(0)\n",
}
/*
* Fetch the I/O bitmap offset.
*/
rc = PGMPhysInterpretedRead(pVM, pCtxCore, &offIOPB, GCPtrTss + RT_OFFSETOF(VBOXTSS, offIoBitmap), sizeof(offIOPB));
if (rc != VINF_SUCCESS)
{
Log(("iomInterpretCheckPortIOAccess: Port=%RTiop cb=%d GCPtrTss=%VGv %Vrc\n",
return rc;
}
/*
* Check the limit and read the two bitmap bytes.
*/
{
Log(("iomInterpretCheckPortIOAccess: Port=%RTiop cb=%d offTss=%#x cbTss=%#x -> #GP(0)\n",
}
if (rc != VINF_SUCCESS)
{
Log(("iomInterpretCheckPortIOAccess: Port=%RTiop cb=%d GCPtrTss=%VGv offTss=%#x -> %Vrc\n",
return rc;
}
/*
* All the bits must be clear.
*/
{
Log(("iomInterpretCheckPortIOAccess: Port=%RTiop cb=%d u16=%#x -> #GP(0)\n",
}
LogFlow(("iomInterpretCheckPortIOAccess: Port=%RTiop cb=%d offTss=%#x cbTss=%#x u16=%#x -> OK\n",
}
return VINF_SUCCESS;
}