DisasmReg.cpp revision b4aee06a140a74517eedd6e55625cb88bd7b3d87
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * VBox disassembler:
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Core components
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * available from http://www.virtualbox.org. This file is free software;
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * you can redistribute it and/or modify it under the terms of the GNU
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * General Public License (GPL) as published by the Free Software
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * additional information or have any questions.
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync/*******************************************************************************
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync* Header Files *
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync*******************************************************************************/
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync/*******************************************************************************
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync* Global Variables *
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync*******************************************************************************/
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Array for accessing 64-bit general registers in VMMREGFRAME structure
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * by register's index from disasm.
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncstatic const unsigned g_aReg64Index[] =
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Macro for accessing 64-bit general purpose registers in CPUMCTXCORE structure.
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync#define DIS_READ_REG64(p, idx) (*(uint64_t *)((char *)(p) + g_aReg64Index[idx]))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync#define DIS_WRITE_REG64(p, idx, val) (*(uint64_t *)((char *)(p) + g_aReg64Index[idx]) = val)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync#define DIS_PTR_REG64(p, idx) ( (uint64_t *)((char *)(p) + g_aReg64Index[idx]))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Array for accessing 32-bit general registers in VMMREGFRAME structure
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * by register's index from disasm.
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncstatic const unsigned g_aReg32Index[] =
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Macro for accessing 32-bit general purpose registers in CPUMCTXCORE structure.
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync#define DIS_READ_REG32(p, idx) (*(uint32_t *)((char *)(p) + g_aReg32Index[idx]))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync/* From http://www.cs.cmu.edu/~fp/courses/15213-s06/misc/asm64-handout.pdf:
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * ``Perhaps unexpectedly, instructions that move or generate 32-bit register
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * values also set the upper 32 bits of the register to zero. Consequently
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * there is no need for an instruction movzlq.''
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync#define DIS_WRITE_REG32(p, idx, val) (*(uint64_t *)((char *)(p) + g_aReg32Index[idx]) = (uint32_t)val)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync#define DIS_PTR_REG32(p, idx) ( (uint32_t *)((char *)(p) + g_aReg32Index[idx]))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Array for accessing 16-bit general registers in CPUMCTXCORE structure
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * by register's index from disasm.
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncstatic const unsigned g_aReg16Index[] =
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Macro for accessing 16-bit general purpose registers in CPUMCTXCORE structure.
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync#define DIS_READ_REG16(p, idx) (*(uint16_t *)((char *)(p) + g_aReg16Index[idx]))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync#define DIS_WRITE_REG16(p, idx, val) (*(uint16_t *)((char *)(p) + g_aReg16Index[idx]) = val)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync#define DIS_PTR_REG16(p, idx) ( (uint16_t *)((char *)(p) + g_aReg16Index[idx]))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Array for accessing 8-bit general registers in CPUMCTXCORE structure
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * by register's index from disasm.
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncstatic const unsigned g_aReg8Index[] =
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync RT_OFFSETOF(CPUMCTXCORE, eax) + 1, /* USE_REG_AH */
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync RT_OFFSETOF(CPUMCTXCORE, ecx) + 1, /* USE_REG_CH */
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync RT_OFFSETOF(CPUMCTXCORE, edx) + 1, /* USE_REG_DH */
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync RT_OFFSETOF(CPUMCTXCORE, ebx) + 1, /* USE_REG_BH */
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync RT_OFFSETOF(CPUMCTXCORE, esp), /* USE_REG_SPL; with REX prefix only */
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync RT_OFFSETOF(CPUMCTXCORE, ebp), /* USE_REG_BPL; with REX prefix only */
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync RT_OFFSETOF(CPUMCTXCORE, esi), /* USE_REG_SIL; with REX prefix only */
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync RT_OFFSETOF(CPUMCTXCORE, edi) /* USE_REG_DIL; with REX prefix only */
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Macro for accessing 8-bit general purpose registers in CPUMCTXCORE structure.
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync#define DIS_READ_REG8(p, idx) (*(uint8_t *)((char *)(p) + g_aReg8Index[idx]))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync#define DIS_WRITE_REG8(p, idx, val) (*(uint8_t *)((char *)(p) + g_aReg8Index[idx]) = val)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync#define DIS_PTR_REG8(p, idx) ( (uint8_t *)((char *)(p) + g_aReg8Index[idx]))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Array for accessing segment registers in CPUMCTXCORE structure
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * by register's index from disasm.
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncstatic const unsigned g_aRegSegIndex[] =
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncstatic const unsigned g_aRegHidSegIndex[] =
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync RT_OFFSETOF(CPUMCTXCORE, esHid), /* DIS_SELREG_ES */
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync RT_OFFSETOF(CPUMCTXCORE, csHid), /* DIS_SELREG_CS */
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync RT_OFFSETOF(CPUMCTXCORE, ssHid), /* DIS_SELREG_SS */
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync RT_OFFSETOF(CPUMCTXCORE, dsHid), /* DIS_SELREG_DS */
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync RT_OFFSETOF(CPUMCTXCORE, fsHid), /* DIS_SELREG_FS */
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync RT_OFFSETOF(CPUMCTXCORE, gsHid) /* DIS_SELREG_GS */
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Macro for accessing segment registers in CPUMCTXCORE structure.
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync#define DIS_READ_REGSEG(p, idx) (*((uint16_t *)((char *)(p) + g_aRegSegIndex[idx])))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync#define DIS_WRITE_REGSEG(p, idx, val) (*((uint16_t *)((char *)(p) + g_aRegSegIndex[idx])) = val)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync//*****************************************************************************
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync//*****************************************************************************
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(int) DISGetParamSize(PDISCPUSTATE pCpu, POP_PARAMETER pParam)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync /* make gcc happy */
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync else //@todo dangerous!!!
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync//*****************************************************************************
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync//*****************************************************************************
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(DIS_SELREG) DISDetectSegReg(PDISCPUSTATE pCpu, POP_PARAMETER pParam)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync /* Use specified SEG: prefix. */
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync /* Guess segment register by parameter type. */
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (pParam->flags & (USE_REG_GEN32|USE_REG_GEN64|USE_REG_GEN16))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (pParam->base.reg_gen == USE_REG_ESP || pParam->base.reg_gen == USE_REG_EBP)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync /* Default is use DS: for data access. */
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync//*****************************************************************************
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync//*****************************************************************************
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(uint8_t) DISQuerySegPrefixByte(PDISCPUSTATE pCpu)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync return 0x26;
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync return 0x2E;
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync return 0x36;
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync return 0x3E;
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync return 0x64;
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync return 0x65;
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Returns the value of the specified 8 bits general purpose register
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(int) DISFetchReg8(PCCPUMCTXCORE pCtx, unsigned reg8, uint8_t *pVal)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync AssertReturn(reg8 < ELEMENTS(g_aReg8Index), VERR_INVALID_PARAMETER);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Returns the value of the specified 16 bits general purpose register
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(int) DISFetchReg16(PCCPUMCTXCORE pCtx, unsigned reg16, uint16_t *pVal)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync AssertReturn(reg16 < ELEMENTS(g_aReg16Index), VERR_INVALID_PARAMETER);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Returns the value of the specified 32 bits general purpose register
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(int) DISFetchReg32(PCCPUMCTXCORE pCtx, unsigned reg32, uint32_t *pVal)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync AssertReturn(reg32 < ELEMENTS(g_aReg32Index), VERR_INVALID_PARAMETER);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Returns the value of the specified 64 bits general purpose register
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(int) DISFetchReg64(PCCPUMCTXCORE pCtx, unsigned reg64, uint64_t *pVal)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync AssertReturn(reg64 < ELEMENTS(g_aReg64Index), VERR_INVALID_PARAMETER);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Returns the pointer to the specified 8 bits general purpose register
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(int) DISPtrReg8(PCPUMCTXCORE pCtx, unsigned reg8, uint8_t **ppReg)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync AssertReturn(reg8 < ELEMENTS(g_aReg8Index), VERR_INVALID_PARAMETER);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Returns the pointer to the specified 16 bits general purpose register
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(int) DISPtrReg16(PCPUMCTXCORE pCtx, unsigned reg16, uint16_t **ppReg)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync AssertReturn(reg16 < ELEMENTS(g_aReg16Index), VERR_INVALID_PARAMETER);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Returns the pointer to the specified 32 bits general purpose register
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(int) DISPtrReg32(PCPUMCTXCORE pCtx, unsigned reg32, uint32_t **ppReg)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync AssertReturn(reg32 < ELEMENTS(g_aReg32Index), VERR_INVALID_PARAMETER);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Returns the pointer to the specified 64 bits general purpose register
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(int) DISPtrReg64(PCPUMCTXCORE pCtx, unsigned reg64, uint64_t **ppReg)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync AssertReturn(reg64 < ELEMENTS(g_aReg64Index), VERR_INVALID_PARAMETER);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Returns the value of the specified segment register
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(int) DISFetchRegSeg(PCCPUMCTXCORE pCtx, DIS_SELREG sel, RTSEL *pVal)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync AssertReturn((unsigned)sel < ELEMENTS(g_aRegSegIndex), VERR_INVALID_PARAMETER);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Returns the value of the specified segment register including a pointer to the hidden register in the supplied cpu context
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(int) DISFetchRegSegEx(PCCPUMCTXCORE pCtx, DIS_SELREG sel, RTSEL *pVal, CPUMSELREGHID **ppSelHidReg)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync AssertReturn((unsigned)sel < ELEMENTS(g_aRegSegIndex), VERR_INVALID_PARAMETER);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync *ppSelHidReg = (CPUMSELREGHID *)((char *)pCtx + g_aRegHidSegIndex[sel]);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Updates the value of the specified 64 bits general purpose register
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(int) DISWriteReg64(PCPUMCTXCORE pRegFrame, unsigned reg64, uint64_t val64)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync AssertReturn(reg64 < ELEMENTS(g_aReg64Index), VERR_INVALID_PARAMETER);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Updates the value of the specified 32 bits general purpose register
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(int) DISWriteReg32(PCPUMCTXCORE pRegFrame, unsigned reg32, uint32_t val32)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync AssertReturn(reg32 < ELEMENTS(g_aReg32Index), VERR_INVALID_PARAMETER);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Updates the value of the specified 16 bits general purpose register
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(int) DISWriteReg16(PCPUMCTXCORE pRegFrame, unsigned reg16, uint16_t val16)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync AssertReturn(reg16 < ELEMENTS(g_aReg16Index), VERR_INVALID_PARAMETER);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Updates the specified 8 bits general purpose register
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(int) DISWriteReg8(PCPUMCTXCORE pRegFrame, unsigned reg8, uint8_t val8)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync AssertReturn(reg8 < ELEMENTS(g_aReg8Index), VERR_INVALID_PARAMETER);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Updates the specified segment register
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(int) DISWriteRegSeg(PCPUMCTXCORE pCtx, DIS_SELREG sel, RTSEL val)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync AssertReturn((unsigned)sel < ELEMENTS(g_aRegSegIndex), VERR_INVALID_PARAMETER);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Returns the value of the parameter in pParam
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * @returns VBox error code
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * @param pCtx CPU context structure pointer
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * @param pCpu Pointer to cpu structure which have DISCPUSTATE::mode
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * set correctly.
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * @param pParam Pointer to the parameter to parse
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * @param pParamVal Pointer to parameter value (OUT)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * @param parmtype Parameter type
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * @note Currently doesn't handle FPU/XMM/MMX/3DNow! parameters correctly!!
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(int) DISQueryParamVal(PCPUMCTXCORE pCtx, PDISCPUSTATE pCpu, POP_PARAMETER pParam, POP_PARAMVAL pParamVal, PARAM_TYPE parmtype)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync // Effective address
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (VBOX_FAILURE(DISFetchReg8(pCtx, pParam->base.reg_gen, &pParamVal->val.val8))) return VERR_INVALID_PARAMETER;
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (VBOX_FAILURE(DISFetchReg16(pCtx, pParam->base.reg_gen, &pParamVal->val.val16))) return VERR_INVALID_PARAMETER;
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (VBOX_FAILURE(DISFetchReg32(pCtx, pParam->base.reg_gen, &pParamVal->val.val32))) return VERR_INVALID_PARAMETER;
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (VBOX_FAILURE(DISFetchReg64(pCtx, pParam->base.reg_gen, &pParamVal->val.val64))) return VERR_INVALID_PARAMETER;
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync // Note that scale implies index (SIB byte)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (VBOX_FAILURE(DISFetchReg16(pCtx, pParam->index.reg_gen, &val16))) return VERR_INVALID_PARAMETER;
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync Assert(!(pParam->flags & USE_SCALE)); /* shouldn't be possible in 16 bits mode */
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (VBOX_FAILURE(DISFetchReg32(pCtx, pParam->index.reg_gen, &val32))) return VERR_INVALID_PARAMETER;
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (VBOX_FAILURE(DISFetchReg64(pCtx, pParam->index.reg_gen, &val64))) return VERR_INVALID_PARAMETER;
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync pParamVal->val.val64 += pParam->disp32 + pCtx->rip;
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (pParam->flags & (USE_REG_GEN8|USE_REG_GEN16|USE_REG_GEN32|USE_REG_GEN64|USE_REG_FP|USE_REG_MMX|USE_REG_XMM|USE_REG_CR|USE_REG_DBG|USE_REG_SEG|USE_REG_TEST))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync // Caller needs to interpret the register according to the instruction (source/target, special value etc)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync //else PARAM_SOURCE
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (VBOX_FAILURE(DISFetchReg8(pCtx, pParam->base.reg_gen, &pParamVal->val.val8))) return VERR_INVALID_PARAMETER;
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (VBOX_FAILURE(DISFetchReg16(pCtx, pParam->base.reg_gen, &pParamVal->val.val16))) return VERR_INVALID_PARAMETER;
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (VBOX_FAILURE(DISFetchReg32(pCtx, pParam->base.reg_gen, &pParamVal->val.val32))) return VERR_INVALID_PARAMETER;
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (VBOX_FAILURE(DISFetchReg64(pCtx, pParam->base.reg_gen, &pParamVal->val.val64))) return VERR_INVALID_PARAMETER;
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync // Caller needs to interpret the register according to the instruction (source/target, special value etc)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (pParam->flags & (USE_IMMEDIATE8|USE_IMMEDIATE8_REL))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (pParam->flags & (USE_IMMEDIATE16|USE_IMMEDIATE16_REL|USE_IMMEDIATE_ADDR_0_16|USE_IMMEDIATE16_SX8))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync AssertMsg(pParamVal->size == pParam->size || ((pParam->size == 1) && (pParam->flags & USE_IMMEDIATE16_SX8)), ("pParamVal->size %d vs %d EIP=%VGv\n", pParamVal->size, pParam->size, pCtx->eip) );
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (pParam->flags & (USE_IMMEDIATE32|USE_IMMEDIATE32_REL|USE_IMMEDIATE_ADDR_0_32|USE_IMMEDIATE32_SX8))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync Assert(pParamVal->size == pParam->size || ((pParam->size == 1) && (pParam->flags & USE_IMMEDIATE32_SX8)) );
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (pParam->flags & (USE_IMMEDIATE64 | USE_IMMEDIATE64_REL | USE_IMMEDIATE64_SX8))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync Assert(pParamVal->size == pParam->size || ((pParam->size == 1) && (pParam->flags & USE_IMMEDIATE64_SX8)) );
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync pParamVal->val.farptr.sel = (uint16_t)RT_LOWORD(pParam->parval >> 16);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync pParamVal->val.farptr.offset = (uint32_t)RT_LOWORD(pParam->parval);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync pParamVal->size = sizeof(uint16_t) + sizeof(uint32_t);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync pParamVal->val.farptr.sel = (uint16_t)RT_LOWORD(pParam->parval >> 32);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync pParamVal->val.farptr.offset = (uint32_t)(pParam->parval & 0xFFFFFFFF);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Returns the pointer to a register of the parameter in pParam. We need this
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * pointer when an interpreted instruction updates a register as a side effect.
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * In CMPXCHG we know that only [r/e]ax is updated, but with XADD this could
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * be every register.
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * @returns VBox error code
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * @param pCtx CPU context structure pointer
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * @param pCpu Pointer to cpu structure which have DISCPUSTATE::mode
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * set correctly.
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * @param pParam Pointer to the parameter to parse
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * @param pReg Pointer to parameter value (OUT)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * @param cbsize Parameter size (OUT)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * @note Currently doesn't handle FPU/XMM/MMX/3DNow! parameters correctly!!
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(int) DISQueryParamRegPtr(PCPUMCTXCORE pCtx, PDISCPUSTATE pCpu, POP_PARAMETER pParam, void **ppReg, size_t *pcbSize)
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (pParam->flags & (USE_REG_GEN8|USE_REG_GEN16|USE_REG_GEN32|USE_REG_FP|USE_REG_MMX|USE_REG_XMM|USE_REG_CR|USE_REG_DBG|USE_REG_SEG|USE_REG_TEST))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (VBOX_SUCCESS(DISPtrReg8(pCtx, pParam->base.reg_gen, &pu8Reg)))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (VBOX_SUCCESS(DISPtrReg16(pCtx, pParam->base.reg_gen, &pu16Reg)))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (VBOX_SUCCESS(DISPtrReg32(pCtx, pParam->base.reg_gen, &pu32Reg)))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync if (VBOX_SUCCESS(DISPtrReg64(pCtx, pParam->base.reg_gen, &pu64Reg)))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync//*****************************************************************************
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync//*****************************************************************************