IOMAllMMIO.cpp revision cfb3a8ae5e9668de4506cf5c053b8009bcc89daf
/* $Id$ */
/** @file
* IOM - Input / Output Monitor - Guest Context.
*/
/*
* Copyright (C) 2006-2007 innotek 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 (GPL) 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_IOM
#include "IOMInternal.h"
#include <VBox/disopcode.h>
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static bool iomGetRegImmData(PDISCPUSTATE pCpu, PCOP_PARAMETER pParam, PCPUMCTXCORE pRegFrame, uint32_t *pu32Data, unsigned *pcbSize);
static bool iomSaveDataToReg(PDISCPUSTATE pCpu, PCOP_PARAMETER pParam, PCPUMCTXCORE pRegFrame, uint32_t u32Data);
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/**
* Array for accessing 32-bit general registers in VMMREGFRAME structure
* by register's index from disasm.
*/
static unsigned g_aReg32Index[] =
{
};
/**
* Macro for accessing 32-bit general purpose registers in CPUMCTXCORE structure.
*/
/**
* Array for accessing 16-bit general registers in CPUMCTXCORE structure
* by register's index from disasm.
*/
static unsigned g_aReg16Index[] =
{
};
/**
* Macro for accessing 16-bit general purpose registers in CPUMCTXCORE structure.
*/
/**
* Array for accessing 8-bit general registers in CPUMCTXCORE structure
* by register's index from disasm.
*/
static unsigned g_aReg8Index[] =
{
};
/**
* Macro for accessing 8-bit general purpose registers in CPUMCTXCORE structure.
*/
/**
* Array for accessing segment registers in CPUMCTXCORE structure
* by register's index from disasm.
*/
static unsigned g_aRegSegIndex[] =
{
};
/**
* Macro for accessing segment registers in CPUMCTXCORE structure.
*/
/**
* Array for fast recode of the operand size (1/2/4/8 bytes) to bit shift value.
*/
static const unsigned g_aSize2Shift[] =
{
~0, /* 0 - invalid */
0, /* *1 == 2^0 */
1, /* *2 == 2^1 */
~0, /* 3 - invalid */
2, /* *4 == 2^2 */
~0, /* 5 - invalid */
~0, /* 6 - invalid */
~0, /* 7 - invalid */
3 /* *8 == 2^3 */
};
/**
* Macro for fast recode of the operand size (1/2/4/8 bytes) to bit shift value.
*/
/**
* Wrapper which does the write and updates range statistics when such are enabled.
* @warning VBOX_SUCCESS(rc=VINF_IOM_HC_MMIO_WRITE) is TRUE!
*/
DECLINLINE(int) iomMMIODoWrite(PVM pVM, CTXALLSUFF(PIOMMMIORANGE) pRange, RTGCPHYS GCPhysFault, const void *pvData, unsigned cbSize)
{
#ifdef VBOX_WITH_STATISTICS
{
if (!pStats)
return VINF_IOM_HC_MMIO_WRITE;
int rc = pRange->pfnWriteCallback(pRange->pDevIns, pRange->pvUser, GCPhysFault, (void *)pvData, cbSize); /* @todo fix const!! */
if (rc != VINF_IOM_HC_MMIO_WRITE)
return rc;
}
#endif
return pRange->pfnWriteCallback(pRange->pDevIns, pRange->pvUser, GCPhysFault, (void *)pvData, cbSize);
}
/**
* Wrapper which does the read and updates range statistics when such are enabled.
*/
DECLINLINE(int) iomMMIODoRead(PVM pVM, CTXALLSUFF(PIOMMMIORANGE) pRange, RTGCPHYS GCPhysFault, void *pvData, unsigned cbSize)
{
#ifdef VBOX_WITH_STATISTICS
{
if (!pStats)
return VINF_IOM_HC_MMIO_READ;
if (rc != VINF_IOM_HC_MMIO_READ)
return rc;
}
#endif
}
/**
* Returns the contents of register or immediate data of instruction's parameter.
*
* @returns true on success.
*
* @param pCpu Pointer to current disassembler context.
* @param pParam Pointer to parameter of instruction to proccess.
* @param pRegFrame Pointer to CPUMCTXCORE guest structure.
* @param pu32Data Where to store retrieved data.
* @param pcbSize Where to store the size of data (1, 2, 4).
*/
static bool iomGetRegImmData(PDISCPUSTATE pCpu, PCOP_PARAMETER pParam, PCPUMCTXCORE pRegFrame, uint32_t *pu32Data, unsigned *pcbSize)
{
if (pParam->flags & (USE_BASE | USE_INDEX | USE_SCALE | USE_DISPLACEMENT8 | USE_DISPLACEMENT16 | USE_DISPLACEMENT32))
{
*pcbSize = 0;
*pu32Data = 0;
return false;
}
{
*pcbSize = 4;
return true;
}
{
*pcbSize = 2;
return true;
}
{
*pcbSize = 1;
return true;
}
{
*pcbSize = 4;
return true;
}
{
*pcbSize = 2;
return true;
}
{
*pcbSize = 1;
return true;
}
{
*pcbSize = 2;
return true;
} /* Else - error. */
*pcbSize = 0;
*pu32Data = 0;
return false;
}
/**
* Saves data to 8/16/32 general purpose or segment register defined by
* instruction's parameter.
*
* @returns true on success.
* @param pCpu Pointer to current disassembler context.
* @param pParam Pointer to parameter of instruction to proccess.
* @param pRegFrame Pointer to CPUMCTXCORE guest structure.
* @param u32Data 8/16/32 bit data to store.
*/
static bool iomSaveDataToReg(PDISCPUSTATE pCpu, PCOP_PARAMETER pParam, PCPUMCTXCORE pRegFrame, unsigned u32Data)
{
if (pParam->flags & (USE_BASE | USE_INDEX | USE_SCALE | USE_DISPLACEMENT8 | USE_DISPLACEMENT16 | USE_DISPLACEMENT32 | USE_IMMEDIATE8 | USE_IMMEDIATE16 | USE_IMMEDIATE32 | USE_IMMEDIATE32_SX8 | USE_IMMEDIATE16_SX8))
{
return false;
}
{
return true;
}
{
return true;
}
{
return true;
}
{
return true;
}
/* Else - error. */
return false;
}
/*
* Internal - statistics only.
*/
{
#ifdef VBOX_WITH_STATISTICS
switch (cb)
{
case 1:
break;
case 2:
break;
case 4:
break;
default:
/* No way. */
break;
}
#else
#endif
}
/**
* MOV reg, mem (read)
* MOVZX reg, mem (read)
* MOVSX reg, mem (read)
*
* @returns VBox status code.
*
* @param pVM The virtual machine (GC pointer ofcourse).
* @param pRegFrame Pointer to CPUMCTXCORE guest registers structure.
* @param pCpu Disassembler CPU state.
* @param pRange Pointer MMIO range.
* @param GCPhysFault The GC physical address corresponding to pvFault.
*/
static int iomInterpretMOVxXRead(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu, CTXALLSUFF(PIOMMMIORANGE) pRange, RTGCPHYS GCPhysFault)
{
/*
* If no read handler then go to ring-3 and handle it there.
*/
if (!pRange->pfnReadCallback)
return VINF_IOM_HC_MMIO_READ;
/*
* Get the data size from parameter 2,
* and call the handler function to get the data.
*/
if (rc == VINF_SUCCESS)
{
/*
* Do sign extension for MOVSX.
*/
/** @todo checkup MOVSX implementation! */
{
if (cbSize == 1)
{
/* DWORD <- BYTE */
}
else
{
/* DWORD <- WORD */
}
}
/*
* Store the result to register (parameter 1).
*/
}
if (rc == VINF_SUCCESS)
return rc;
}
/**
* MOV mem, reg|imm (write)
*
* @returns VBox status code.
*
* @param pVM The virtual machine (GC pointer ofcourse).
* @param pRegFrame Pointer to CPUMCTXCORE guest registers structure.
* @param pCpu Disassembler CPU state.
* @param pRange Pointer MMIO range.
* @param GCPhysFault The GC physical address corresponding to pvFault.
*/
static int iomInterpretMOVxXWrite(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu, CTXALLSUFF(PIOMMMIORANGE) pRange, RTGCPHYS GCPhysFault)
{
/*
* If no write handler then go to ring-3 and handle it there.
*/
if (!pRange->pfnWriteCallback)
return VINF_IOM_HC_MMIO_WRITE;
/*
* Get data to write from second parameter,
* and call the callback to write it.
*/
unsigned cbSize = 0;
if (rc == VINF_SUCCESS)
return rc;
}
/** @todo All the string MMIO stuff can do terrible things since physical contiguous mappings are
* assumed all over the place! This must be addressed in a general way, like for example let EM do
* all the interpretation and checking of selectors and addresses.
*
* -> I don't see the problem here. MMIO ranges are by definition linear ranges. The virtual source or destination is read/written properly.
*/
{
#ifdef IN_GC
#else
#endif
}
{
#ifdef IN_GC
#else
#endif
}
/**
* [REP] MOVSB
* [REP] MOVSW
* [REP] MOVSD
*
* Restricted implementation.
*
*
* @returns VBox status code.
*
* @param pVM The virtual machine (GC pointer ofcourse).
* @param uErrorCode CPU Error code.
* @param pRegFrame Trap register frame.
* @param GCPhysFault The GC physical address corresponding to pvFault.
* @param pCpu Disassembler CPU state.
* @param pRange Pointer MMIO range.
*/
#ifdef iom_MOVS_SUPPORT
static int iomInterpretMOVS(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, CTXALLSUFF(PIOMMMIORANGE) pRange)
{
/*
* We do not support segment prefixes or REPNE.
*/
return VINF_IOM_HC_MMIO_READ_WRITE;
/*
*/
{
cTransfers &= 0xffff;
if (!cTransfers)
return VINF_SUCCESS;
}
/* Get the current privilege level. */
/*
* Get data size.
*/
#ifdef VBOX_WITH_STATISTICS
#endif
int rc;
if (uErrorCode & X86_TRAP_PF_RW)
{
/*
* Write operation: [Mem] -> [MMIO]
* ds:esi (Virt Src) -> es:edi (Phys Dst)
*/
/* Check callback. */
if (!pRange->pfnWriteCallback)
{
return VINF_IOM_HC_MMIO_WRITE;
}
/* Convert source address ds:esi. */
rc = SELMToFlatEx(pVM, pRegFrame->eflags, pRegFrame->ds, (RTGCPTR)pRegFrame->esi, &pRegFrame->dsHid,
if (VBOX_SUCCESS(rc))
{
/* Access verification first; we currently can't recover properly from traps inside this instruction */
if (rc != VINF_SUCCESS)
{
return VINF_EM_RAW_EMULATE_INSTR;
}
#ifdef IN_GC
#endif
/* copy loop. */
while (cTransfers)
{
if (rc != VINF_SUCCESS)
break;
if (rc != VINF_SUCCESS)
break;
pu8Virt += offIncrement;
Phys += offIncrement;
cTransfers--;
}
#ifdef IN_GC
#endif
/* Update ecx. */
}
else
}
else
{
/*
* Read operation: [MMIO] -> [mem] or [MMIO] -> [MMIO]
* ds:[eSI] (Phys Src) -> es:[eDI] (Virt Dst)
*/
/* Check callback. */
if (!pRange->pfnReadCallback)
return VINF_IOM_HC_MMIO_READ;
/* Convert destination address. */
rc = SELMToFlatEx(pVM, pRegFrame->eflags, pRegFrame->es, (RTGCPTR)pRegFrame->edi, &pRegFrame->esHid,
if (VBOX_FAILURE(rc))
return VINF_EM_RAW_GUEST_TRAP;
/* Check if destination address is MMIO. */
if ( VBOX_SUCCESS(rc)
{
/*
* Extra: [MMIO] -> [MMIO]
*/
if ( !pMMIODst
|| !pMMIODst->pfnWriteCallback)
{
return VINF_IOM_HC_MMIO_READ_WRITE;
}
/* copy loop. */
while (cTransfers)
{
if (rc != VINF_SUCCESS)
break;
if (rc != VINF_SUCCESS)
break;
Phys += offIncrement;
PhysDst += offIncrement;
cTransfers--;
}
}
else
{
/*
* Normal: [MMIO] -> [Mem]
*/
/* Access verification first; we currently can't recover properly from traps inside this instruction */
rc = PGMVerifyAccess(pVM, pu8Virt, cTransfers * cbSize, X86_PTE_RW | ((cpl == 3) ? X86_PTE_US : 0));
if (rc != VINF_SUCCESS)
{
return VINF_EM_RAW_EMULATE_INSTR;
}
/* copy loop. */
#ifdef IN_GC
#endif
while (cTransfers)
{
if (rc != VINF_SUCCESS)
break;
if (rc != VINF_SUCCESS)
{
break;
}
pu8Virt += offIncrement;
Phys += offIncrement;
cTransfers--;
}
#ifdef IN_GC
#endif
}
/* Update ecx on exit. */
}
/* work statistics. */
if (rc == VINF_SUCCESS)
{
}
return rc;
}
#endif
/**
* [REP] STOSB
* [REP] STOSW
* [REP] STOSD
*
* Restricted implementation.
*
*
* @returns VBox status code.
*
* @param pVM The virtual machine (GC pointer ofcourse).
* @param pRegFrame Trap register frame.
* @param GCPhysFault The GC physical address corresponding to pvFault.
* @param pCpu Disassembler CPU state.
* @param pRange Pointer MMIO range.
*/
static int iomInterpretSTOS(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, CTXALLSUFF(PIOMMMIORANGE) pRange)
{
/*
* We do not support segment prefixes or REPNE..
*/
return VINF_IOM_HC_MMIO_READ_WRITE;
/*
*/
{
cTransfers &= 0xffff;
if (!cTransfers)
return VINF_SUCCESS;
}
/*
* Get data size.
*/
#ifdef VBOX_WITH_STATISTICS
#endif
int rc;
if (pRange->pfnFillCallback)
{
/*
* Use the fill callback.
*/
/** @todo pfnFillCallback must return number of bytes successfully written!!! */
if (offIncrement > 0)
{
/* addr++ variant. */
if (rc == VINF_SUCCESS)
{
/* Update registers. */
}
}
else
{
/* addr-- variant. */
rc = pRange->pfnFillCallback(pRange->pDevIns, pRange->pvUser, (Phys - (cTransfers - 1)) << SIZE_2_SHIFT(cbSize), u32Data, cbSize, cTransfers);
if (rc == VINF_SUCCESS)
{
/* Update registers. */
}
}
}
else
{
/*
* Use the write callback.
*/
/* Check write callback. */
if (!pRange->pfnWriteCallback)
return VINF_IOM_HC_MMIO_WRITE;
/* fill loop. */
do
{
if (rc != VINF_SUCCESS)
break;
Phys += offIncrement;
cTransfers--;
} while (cTransfers);
/* Update ecx on exit. */
}
/*
* Work statistics and return.
*/
if (rc == VINF_SUCCESS)
{
}
return rc;
}
/**
* [REP] LODSB
* [REP] LODSW
* [REP] LODSD
*
* Restricted implementation.
*
*
* @returns VBox status code.
*
* @param pVM The virtual machine (GC pointer ofcourse).
* @param pRegFrame Trap register frame.
* @param GCPhysFault The GC physical address corresponding to pvFault.
* @param pCpu Disassembler CPU state.
* @param pRange Pointer MMIO range.
*/
static int iomInterpretLODS(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, CTXALLSUFF(PIOMMMIORANGE) pRange)
{
/*
* We do not support segment prefixes or REP*.
*/
return VINF_IOM_HC_MMIO_READ_WRITE;
/* Check that we can handle it. */
if (!pRange->pfnReadCallback)
return VINF_IOM_HC_MMIO_READ;
/*
* Get data size.
*/
/*
* Perform read.
*/
if (rc == VINF_SUCCESS)
/*
* Work statistics and return.
*/
if (rc == VINF_SUCCESS)
{
}
return rc;
}
/**
* CMP [MMIO], reg|imm
* CMP reg|imm, [MMIO]
*
* Restricted implementation.
*
*
* @returns VBox status code.
*
* @param pVM The virtual machine (GC pointer ofcourse).
* @param pRegFrame Trap register frame.
* @param GCPhysFault The GC physical address corresponding to pvFault.
* @param pCpu Disassembler CPU state.
* @param pRange Pointer MMIO range.
*/
static int iomInterpretCMP(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, CTXALLSUFF(PIOMMMIORANGE) pRange)
{
/* Check read callback. */
if (!pRange->pfnReadCallback)
return VINF_EM_RAW_GUEST_TRAP;
/*
* Get the operands.
*/
unsigned cbSize = 0;
int rc;
/* cmp reg, [MMIO]. */
/* cmp [MMIO], reg|imm. */
else
{
AssertMsgFailed(("Disassember CMP problem..\n"));
}
if (rc == VINF_SUCCESS)
{
/* Emulate CMP and update guest flags. */
pRegFrame->eflags.u32 = (pRegFrame->eflags.u32 & ~(X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF))
}
return rc;
}
/**
* AND [MMIO], reg|imm
* AND reg, [MMIO]
*
* Restricted implementation.
*
*
* @returns VBox status code.
*
* @param pVM The virtual machine (GC pointer ofcourse).
* @param pRegFrame Trap register frame.
* @param GCPhysFault The GC physical address corresponding to pvFault.
* @param pCpu Disassembler CPU state.
* @param pRange Pointer MMIO range.
*/
static int iomInterpretAND(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, CTXALLSUFF(PIOMMMIORANGE) pRange)
{
/* Check read callback. */
unsigned cbSize = 0;
bool fAndWrite;
int rc;
{
/* and reg, [MMIO]. */
fAndWrite = false;
if (pRange->pfnReadCallback)
else
}
{
/* and [MMIO], reg|imm. */
fAndWrite = true;
else
}
else
{
AssertMsgFailed(("Disassember AND problem..\n"));
}
if (rc == VINF_SUCCESS)
{
/* Emulate AND and update guest flags. */
if (fAndWrite)
/* Store result to MMIO. */
else
{
/* Store result to register. */
}
if (rc == VINF_SUCCESS)
{
/* Update guest's eflags and finish. */
pRegFrame->eflags.u32 = (pRegFrame->eflags.u32 & ~(X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF))
}
}
return rc;
}
/**
* TEST [MMIO], reg|imm
* TEST reg, [MMIO]
*
* Restricted implementation.
*
*
* @returns VBox status code.
*
* @param pVM The virtual machine (GC pointer ofcourse).
* @param pRegFrame Trap register frame.
* @param GCPhysFault The GC physical address corresponding to pvFault.
* @param pCpu Disassembler CPU state.
* @param pRange Pointer MMIO range.
*/
static int iomInterpretTEST(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, CTXALLSUFF(PIOMMMIORANGE) pRange)
{
/* Check read callback. */
unsigned cbSize = 0;
int rc;
{
/* and test, [MMIO]. */
if (pRange->pfnReadCallback)
else
}
{
/* test [MMIO], reg|imm. */
if (pRange->pfnReadCallback)
else
}
else
{
AssertMsgFailed(("Disassember TEST problem..\n"));
}
if (rc == VINF_SUCCESS)
{
/* Emulate TEST (=AND without write back) and update guest EFLAGS. */
pRegFrame->eflags.u32 = (pRegFrame->eflags.u32 & ~(X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF))
}
return rc;
}
/**
* XCHG [MMIO], reg
* XCHG reg, [MMIO]
*
* Restricted implementation.
*
*
* @returns VBox status code.
*
* @param pVM The virtual machine (GC pointer ofcourse).
* @param pRegFrame Trap register frame.
* @param GCPhysFault The GC physical address corresponding to pvFault.
* @param pCpu Disassembler CPU state.
* @param pRange Pointer MMIO range.
*/
static int iomInterpretXCHG(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, PDISCPUSTATE pCpu, CTXALLSUFF(PIOMMMIORANGE) pRange)
{
/* Check read callback. */
unsigned cbSize = 0;
int rc;
{
goto end;
}
{
/* xchg reg, [MMIO]. */
if (rc == VINF_SUCCESS)
{
/* Store result to MMIO. */
if (rc == VINF_SUCCESS)
{
/* Store result to register. */
}
else
}
else
}
else
{
/* xchg [MMIO], reg. */
if (rc == VINF_SUCCESS)
{
/* Store result to MMIO. */
if (rc == VINF_SUCCESS)
{
/* Store result to register. */
}
else
}
else
}
else
{
AssertMsgFailed(("Disassember XCHG problem..\n"));
goto end;
}
end:
return rc;
}
#ifdef IN_RING0
/**
* Read callback for disassembly function; supports reading bytes that cross a page boundary
*
* @returns VBox status code.
* @param pSrc GC source pointer
* @param pDest HC destination pointer
* @param size Number of bytes to read
* @param pvUserdata Callback specific user data (pCpu)
*
*/
{
return rc;
}
{
}
#else
{
}
#endif
/**
* \#PF Handler callback for MMIO ranges.
* Note: we are on ring0 in Hypervisor and interrupts are disabled.
*
* @returns VBox status code (appropriate for GC return).
* @param pVM VM Handle.
* @param uErrorCode CPU Error code.
* @param pRegFrame Trap register frame.
* @param pvFault The fault address (cr2).
* @param GCPhysFault The GC physical address corresponding to pvFault.
* @param pvUser Pointer to the MMIO ring-3 range entry.
*/
IOMDECL(int) IOMMMIOHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, void *pvFault, RTGCPHYS GCPhysFault, void *pvUser)
{
Log3(("IOMMMIOHandler: GCPhys=%RGp uErr=%#x pvFault=%p eip=%RGv\n",
/*
* Find the corresponding MMIO range.
*/
if (!pRange)
{
#ifdef VBOX_WITH_STATISTICS
if (pStats)
{
if (uErrorCode & X86_TRAP_PF_RW)
else
}
#endif
if (pRangeR3)
{
}
/*
* Now, why are we here...
*/
return VERR_IOM_MMIO_HANDLER_BOGUS_CALL;
}
/*
* Convert CS:EIP to linear address and initialize the disassembler.
*/
cpu.mode = SELMIsSelector32Bit(pVM, pRegFrame->eflags, pRegFrame->cs, &pRegFrame->csHid) ? CPUMODE_32BIT : CPUMODE_16BIT;
int rc = SELMValidateAndConvertCSAddr(pVM, pRegFrame->eflags, pRegFrame->ss, pRegFrame->cs, &pRegFrame->csHid, (RTGCPTR)(cpu.mode == CPUMODE_32BIT ? pRegFrame->eip : pRegFrame->eip & 0xffff), &pvCode);
if (VBOX_FAILURE(rc))
{
return VERR_IOM_MMIO_HANDLER_BOGUS_CALL;
}
/*
* Disassemble the instruction and interprete it.
*/
unsigned cbOp;
{
{
case OP_MOV:
case OP_MOVZX:
case OP_MOVSX:
{
if (uErrorCode & X86_TRAP_PF_RW)
else
if (rc == VINF_SUCCESS)
break;
}
#ifdef iom_MOVS_SUPPORT
case OP_MOVSB:
case OP_MOVSWD:
break;
#endif
case OP_STOSB:
case OP_STOSWD:
break;
case OP_LODSB:
case OP_LODSWD:
break;
case OP_CMP:
break;
case OP_AND:
break;
case OP_TEST:
break;
case OP_XCHG:
break;
/*
* The instruction isn't supported. Hand it on to ring-3.
*/
default:
break;
}
}
else
{
AssertMsgFailed(("Disassembler freaked out!\n"));
}
/*
* On success advance EIP.
*/
if (rc == VINF_SUCCESS)
else
{
#ifdef VBOX_WITH_STATISTICS
switch (rc)
{
case VINF_IOM_HC_MMIO_READ:
case VINF_IOM_HC_MMIO_WRITE:
{
if (pStats)
{
if (uErrorCode & X86_TRAP_PF_RW)
else
}
}
break;
}
#endif
}
return rc;
}
/**
* 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;
}
/**
* ES:EDI,DX[,ECX]
*
* @remark Assumes caller checked the access privileges (IOMInterpretCheckPortIOAccess)
*
* @returns Strict VBox status code. Informational status codes other than the one documented
* here are to be treated as internal failure. Use IOM_SUCCESS() to check for success.
* @retval VINF_SUCCESS Success.
* @retval VINF_EM_FIRST-VINF_EM_LAST Success with some exceptions (see IOM_SUCCESS()), the
* status code must be passed on to EM.
* @retval VINF_EM_RAW_EMULATE_INSTR Defer the read to the REM.
* @retval VINF_EM_RAW_GUEST_TRAP The exception was left pending. (TRPMRaiseXcptErr)
* @retval VINF_TRPM_XCPT_DISPATCHED The exception was raised and dispatched for raw-mode execution. (TRPMRaiseXcptErr)
* @retval VINF_EM_RESCHEDULE_REM The exception was dispatched and cannot be executed in raw-mode. (TRPMRaiseXcptErr)
*
* @param pVM The virtual machine (GC pointer ofcourse).
* @param pRegFrame Pointer to CPUMCTXCORE guest registers structure.
* @param uPort IO Port
* @param uPrefix IO instruction prefix
* @param cbTransfer Size of transfer unit
*/
IOMDECL(int) IOMInterpretINSEx(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t uPort, uint32_t uPrefix, uint32_t cbTransfer)
{
#ifdef VBOX_WITH_STATISTICS
#endif
/*
* We do not support REPNE or decrementing destination
* pointer. Segment prefixes are deliberately ignored, as per the instruction specification.
*/
if ( (uPrefix & PREFIX_REPNE)
return VINF_EM_RAW_EMULATE_INSTR;
/*
*/
if (uPrefix & PREFIX_REP)
{
cTransfers &= 0xffff;
if (!cTransfers)
return VINF_SUCCESS;
}
/* Convert destination address es:edi. */
int rc = SELMToFlatEx(pVM, pRegFrame->eflags, pRegFrame->es, (RTGCPTR)pRegFrame->edi, &pRegFrame->esHid,
if (VBOX_FAILURE(rc))
{
return VINF_EM_RAW_EMULATE_INSTR;
}
/* Access verification first; we can't recover from traps inside this instruction, as the port read cannot be repeated. */
if (rc != VINF_SUCCESS)
{
return VINF_EM_RAW_EMULATE_INSTR;
}
if (cTransfers > 1)
{
/* If the device supports string transfers, ask it to do as
* much as it wants. The rest is done with single-word transfers. */
}
#ifdef IN_GC
#endif
{
if (!IOM_SUCCESS(rc))
break;
cTransfers--;
}
#ifdef IN_GC
#endif
/* Update ecx on exit. */
if (uPrefix & PREFIX_REP)
AssertMsg(rc == VINF_SUCCESS || rc == VINF_IOM_HC_IOPORT_READ || (rc >= VINF_EM_FIRST && rc <= VINF_EM_LAST) || VBOX_FAILURE(rc), ("%Vrc\n", rc));
return rc;
}
/**
* ES:EDI,DX[,ECX]
*
* @returns Strict VBox status code. Informational status codes other than the one documented
* here are to be treated as internal failure. Use IOM_SUCCESS() to check for success.
* @retval VINF_SUCCESS Success.
* @retval VINF_EM_FIRST-VINF_EM_LAST Success with some exceptions (see IOM_SUCCESS()), the
* status code must be passed on to EM.
* @retval VINF_EM_RAW_EMULATE_INSTR Defer the read to the REM.
* @retval VINF_EM_RAW_GUEST_TRAP The exception was left pending. (TRPMRaiseXcptErr)
* @retval VINF_TRPM_XCPT_DISPATCHED The exception was raised and dispatched for raw-mode execution. (TRPMRaiseXcptErr)
* @retval VINF_EM_RESCHEDULE_REM The exception was dispatched and cannot be executed in raw-mode. (TRPMRaiseXcptErr)
*
* @param pVM The virtual machine (GC pointer ofcourse).
* @param pRegFrame Pointer to CPUMCTXCORE guest registers structure.
* @param pCpu Disassembler CPU state.
*/
{
/*
* Get port number directly from the register (no need to bother the
* disassembler). And get the I/O register size from the opcode / prefix.
*/
unsigned cbSize = 0;
cbSize = 1;
else
{
AssertMsg(rc == VINF_EM_RAW_GUEST_TRAP || rc == VINF_TRPM_XCPT_DISPATCHED || rc == VINF_TRPM_XCPT_DISPATCHED || VBOX_FAILURE(rc), ("%Vrc\n", rc));
return rc;
}
}
/**
* DS:ESI,DX[,ECX]
*
* @remark Assumes caller checked the access privileges (IOMInterpretCheckPortIOAccess)
*
* @returns Strict VBox status code. Informational status codes other than the one documented
* here are to be treated as internal failure. Use IOM_SUCCESS() to check for success.
* @retval VINF_SUCCESS Success.
* @retval VINF_EM_FIRST-VINF_EM_LAST Success with some exceptions (see IOM_SUCCESS()), the
* status code must be passed on to EM.
* @retval VINF_EM_RAW_GUEST_TRAP The exception was left pending. (TRPMRaiseXcptErr)
* @retval VINF_TRPM_XCPT_DISPATCHED The exception was raised and dispatched for raw-mode execution. (TRPMRaiseXcptErr)
* @retval VINF_EM_RESCHEDULE_REM The exception was dispatched and cannot be executed in raw-mode. (TRPMRaiseXcptErr)
*
* @param pVM The virtual machine (GC pointer ofcourse).
* @param pRegFrame Pointer to CPUMCTXCORE guest registers structure.
* @param uPort IO Port
* @param uPrefix IO instruction prefix
* @param cbTransfer Size of transfer unit
*/
IOMDECL(int) IOMInterpretOUTSEx(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t uPort, uint32_t uPrefix, uint32_t cbTransfer)
{
#ifdef VBOX_WITH_STATISTICS
#endif
/*
* We do not support segment prefixes, REPNE or
* decrementing source pointer.
*/
return VINF_EM_RAW_EMULATE_INSTR;
/*
*/
if (uPrefix & PREFIX_REP)
{
cTransfers &= 0xffff;
if (!cTransfers)
return VINF_SUCCESS;
}
/* Convert source address ds:esi. */
int rc = SELMToFlatEx(pVM, pRegFrame->eflags, pRegFrame->ds, (RTGCPTR)pRegFrame->esi, &pRegFrame->dsHid,
if (VBOX_FAILURE(rc))
{
return VINF_EM_RAW_EMULATE_INSTR;
}
/* Access verification first; we currently can't recover properly from traps inside this instruction */
if (rc != VINF_SUCCESS)
{
return VINF_EM_RAW_EMULATE_INSTR;
}
if (cTransfers > 1)
{
/*
* If the device supports string transfers, ask it to do as
* much as it wants. The rest is done with single-word transfers.
*/
}
#ifdef IN_GC
#endif
{
if (rc != VINF_SUCCESS)
break;
if (!IOM_SUCCESS(rc))
break;
cTransfers--;
}
#ifdef IN_GC
#endif
/* Update ecx on exit. */
if (uPrefix & PREFIX_REP)
AssertMsg(rc == VINF_SUCCESS || rc == VINF_IOM_HC_IOPORT_WRITE || (rc >= VINF_EM_FIRST && rc <= VINF_EM_LAST) || VBOX_FAILURE(rc), ("%Vrc\n", rc));
return rc;
}
/**
* DS:ESI,DX[,ECX]
*
* @returns Strict VBox status code. Informational status codes other than the one documented
* here are to be treated as internal failure. Use IOM_SUCCESS() to check for success.
* @retval VINF_SUCCESS Success.
* @retval VINF_EM_FIRST-VINF_EM_LAST Success with some exceptions (see IOM_SUCCESS()), the
* status code must be passed on to EM.
* @retval VINF_EM_RAW_EMULATE_INSTR Defer the write to the REM.
* @retval VINF_EM_RAW_GUEST_TRAP The exception was left pending. (TRPMRaiseXcptErr)
* @retval VINF_TRPM_XCPT_DISPATCHED The exception was raised and dispatched for raw-mode execution. (TRPMRaiseXcptErr)
* @retval VINF_EM_RESCHEDULE_REM The exception was dispatched and cannot be executed in raw-mode. (TRPMRaiseXcptErr)
*
* @param pVM The virtual machine (GC pointer ofcourse).
* @param pRegFrame Pointer to CPUMCTXCORE guest registers structure.
* @param pCpu Disassembler CPU state.
*/
{
/*
* Get port number from the first parameter.
* And get the I/O register size from the opcode / prefix.
*/
unsigned cbSize = 0;
cbSize = 1;
else
{
AssertMsg(rc == VINF_EM_RAW_GUEST_TRAP || rc == VINF_TRPM_XCPT_DISPATCHED || rc == VINF_TRPM_XCPT_DISPATCHED || VBOX_FAILURE(rc), ("%Vrc\n", rc));
return rc;
}
}