DisasmReg.cpp revision f5eadb22976c1f9813300e4042b8255cfaef7e19
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * VBox disassembler:
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Core components
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2006-2007 Oracle Corporation
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/*******************************************************************************
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[] =
d6d241114679140e07ab40acda5adf0fc87b0c85vboxsync RT_OFFSETOF_ADD(CPUMCTXCORE, eax, 1), /* USE_REG_AH */
d6d241114679140e07ab40acda5adf0fc87b0c85vboxsync RT_OFFSETOF_ADD(CPUMCTXCORE, ecx, 1), /* USE_REG_CH */
d6d241114679140e07ab40acda5adf0fc87b0c85vboxsync RT_OFFSETOF_ADD(CPUMCTXCORE, edx, 1), /* USE_REG_DH */
d6d241114679140e07ab40acda5adf0fc87b0c85vboxsync RT_OFFSETOF_ADD(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)
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync AssertReturn(reg8 < RT_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)
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync AssertReturn(reg16 < RT_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)
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync AssertReturn(reg32 < RT_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)
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync AssertReturn(reg64 < RT_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)
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync AssertReturn(reg8 < RT_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)
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync AssertReturn(reg16 < RT_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)
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync AssertReturn(reg32 < RT_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)
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync AssertReturn(reg64 < RT_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)
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync AssertReturn((unsigned)sel < RT_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)
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync AssertReturn((unsigned)sel < RT_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)
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync AssertReturn(reg64 < RT_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)
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync AssertReturn(reg32 < RT_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)
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync AssertReturn(reg16 < RT_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)
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync AssertReturn(reg8 < RT_ELEMENTS(g_aReg8Index), VERR_INVALID_PARAMETER);
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync * Updates the specified segment register
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsyncDISDECL(int) DISWriteRegSeg(PCPUMCTXCORE pCtx, DIS_SELREG sel, RTSEL val)
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync AssertReturn((unsigned)sel < RT_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
240f7d7012a5f64bcde850bcf048531a710d81cfvboxsync if (RT_FAILURE(DISFetchReg8(pCtx, pParam->base.reg_gen, &pParamVal->val.val8))) return VERR_INVALID_PARAMETER;
240f7d7012a5f64bcde850bcf048531a710d81cfvboxsync if (RT_FAILURE(DISFetchReg16(pCtx, pParam->base.reg_gen, &pParamVal->val.val16))) return VERR_INVALID_PARAMETER;
240f7d7012a5f64bcde850bcf048531a710d81cfvboxsync if (RT_FAILURE(DISFetchReg32(pCtx, pParam->base.reg_gen, &pParamVal->val.val32))) return VERR_INVALID_PARAMETER;
240f7d7012a5f64bcde850bcf048531a710d81cfvboxsync if (RT_FAILURE(DISFetchReg64(pCtx, pParam->base.reg_gen, &pParamVal->val.val64))) return VERR_INVALID_PARAMETER;
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync // Note that scale implies index (SIB byte)
240f7d7012a5f64bcde850bcf048531a710d81cfvboxsync if (RT_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 */
240f7d7012a5f64bcde850bcf048531a710d81cfvboxsync if (RT_FAILURE(DISFetchReg32(pCtx, pParam->index.reg_gen, &val32))) return VERR_INVALID_PARAMETER;
240f7d7012a5f64bcde850bcf048531a710d81cfvboxsync if (RT_FAILURE(DISFetchReg64(pCtx, pParam->index.reg_gen, &val64))) return VERR_INVALID_PARAMETER;
7d126da2d4ddf0f075dbdce89c2fb953a464e6bfvboxsync /* Relative to the RIP of the next instruction. */
7d126da2d4ddf0f075dbdce89c2fb953a464e6bfvboxsync pParamVal->val.val64 += pParam->disp32 + pCtx->rip + pCpu->opsize;
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
240f7d7012a5f64bcde850bcf048531a710d81cfvboxsync if (RT_FAILURE(DISFetchReg8(pCtx, pParam->base.reg_gen, &pParamVal->val.val8))) return VERR_INVALID_PARAMETER;
240f7d7012a5f64bcde850bcf048531a710d81cfvboxsync if (RT_FAILURE(DISFetchReg16(pCtx, pParam->base.reg_gen, &pParamVal->val.val16))) return VERR_INVALID_PARAMETER;
240f7d7012a5f64bcde850bcf048531a710d81cfvboxsync if (RT_FAILURE(DISFetchReg32(pCtx, pParam->base.reg_gen, &pParamVal->val.val32))) return VERR_INVALID_PARAMETER;
240f7d7012a5f64bcde850bcf048531a710d81cfvboxsync if (RT_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))
cca8c8c55206ccd60f1b32843a67ce737447ac60vboxsync AssertMsg(pParamVal->size == pParam->size || ((pParam->size == 1) && (pParam->flags & USE_IMMEDIATE16_SX8)), ("pParamVal->size %d vs %d EIP=%RX32\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))
240f7d7012a5f64bcde850bcf048531a710d81cfvboxsync if (RT_SUCCESS(DISPtrReg8(pCtx, pParam->base.reg_gen, &pu8Reg)))
240f7d7012a5f64bcde850bcf048531a710d81cfvboxsync if (RT_SUCCESS(DISPtrReg16(pCtx, pParam->base.reg_gen, &pu16Reg)))
240f7d7012a5f64bcde850bcf048531a710d81cfvboxsync if (RT_SUCCESS(DISPtrReg32(pCtx, pParam->base.reg_gen, &pu32Reg)))
240f7d7012a5f64bcde850bcf048531a710d81cfvboxsync if (RT_SUCCESS(DISPtrReg64(pCtx, pParam->base.reg_gen, &pu64Reg)))
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync//*****************************************************************************
b4aee06a140a74517eedd6e55625cb88bd7b3d87vboxsync//*****************************************************************************