dis.h revision 2e65d8da6ef2ef03491ebb4c3f065f10dd912b36
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * DIS - The VirtualBox Disassembler.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * Copyright (C) 2006-2012 Oracle Corporation
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * available from http://www.virtualbox.org. This file is free software;
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * you can redistribute it and/or modify it under the terms of the GNU
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * General Public License (GPL) as published by the Free Software
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * The contents of this file may alternatively be used under the terms
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * of the Common Development and Distribution License Version 1.0
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * VirtualBox OSE distribution, in which case the provisions of the
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * CDDL are applicable instead of those of the GPL.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * You may elect to license modified versions of this file under the
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * terms and conditions of either the GPL or the CDDL or both.
174e1d5b2d6b6d7c92271d7fcc070c6d0cc92312vboxsync * CPU mode flags (DISSTATE::mode).
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** hack forcing the size of the enum to 32-bits. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** @name Prefix byte flags (DISSTATE::fPrefix).
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** non-default address size. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** non-default operand size. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** lock prefix. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** segment prefix. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** rep(e) prefix (not a prefix, but we'll treat is as one). */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** rep(e) prefix (not a prefix, but we'll treat is as one). */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** REX prefix (64 bits) */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** @name 64 bits prefix byte flags (DISSTATE::fRexPrefix).
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync#define DISPREFIX_REX_OP_2_FLAGS(a) (a - OP_PARM_REX_START)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync#define DISPREFIX_REX_FLAGS DISPREFIX_REX_OP_2_FLAGS(OP_PARM_REX)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync#define DISPREFIX_REX_FLAGS_B DISPREFIX_REX_OP_2_FLAGS(OP_PARM_REX_B)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync#define DISPREFIX_REX_FLAGS_X DISPREFIX_REX_OP_2_FLAGS(OP_PARM_REX_X)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync#define DISPREFIX_REX_FLAGS_XB DISPREFIX_REX_OP_2_FLAGS(OP_PARM_REX_XB)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync#define DISPREFIX_REX_FLAGS_R DISPREFIX_REX_OP_2_FLAGS(OP_PARM_REX_R)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync#define DISPREFIX_REX_FLAGS_RB DISPREFIX_REX_OP_2_FLAGS(OP_PARM_REX_RB)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync#define DISPREFIX_REX_FLAGS_RX DISPREFIX_REX_OP_2_FLAGS(OP_PARM_REX_RX)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync#define DISPREFIX_REX_FLAGS_RXB DISPREFIX_REX_OP_2_FLAGS(OP_PARM_REX_RXB)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync#define DISPREFIX_REX_FLAGS_W DISPREFIX_REX_OP_2_FLAGS(OP_PARM_REX_W)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync#define DISPREFIX_REX_FLAGS_WB DISPREFIX_REX_OP_2_FLAGS(OP_PARM_REX_WB)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync#define DISPREFIX_REX_FLAGS_WX DISPREFIX_REX_OP_2_FLAGS(OP_PARM_REX_WX)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync#define DISPREFIX_REX_FLAGS_WXB DISPREFIX_REX_OP_2_FLAGS(OP_PARM_REX_WXB)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync#define DISPREFIX_REX_FLAGS_WR DISPREFIX_REX_OP_2_FLAGS(OP_PARM_REX_WR)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync#define DISPREFIX_REX_FLAGS_WRB DISPREFIX_REX_OP_2_FLAGS(OP_PARM_REX_WRB)
9474d83dcac691984017f8255821b95ec7642804vboxsync#define DISPREFIX_REX_FLAGS_WRX DISPREFIX_REX_OP_2_FLAGS(OP_PARM_REX_WRX)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync#define DISPREFIX_REX_FLAGS_WRXB DISPREFIX_REX_OP_2_FLAGS(OP_PARM_REX_WRXB)
9474d83dcac691984017f8255821b95ec7642804vboxsync/** @name Operand type (DISOPCODE::fOpType).
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync#define DISOPTYPE_POTENTIALLY_DANGEROUS RT_BIT_32(3)
9474d83dcac691984017f8255821b95ec7642804vboxsync#define DISOPTYPE_RRM_DANGEROUS RT_BIT_32(14) /**< Some additional dangerous ones when recompiling raw r0. */
9474d83dcac691984017f8255821b95ec7642804vboxsync#define DISOPTYPE_RRM_DANGEROUS_16 RT_BIT_32(15) /**< Some additional dangerous ones when recompiling 16-bit raw r0. */
9474d83dcac691984017f8255821b95ec7642804vboxsync#define DISOPTYPE_RRM_MASK (DISOPTYPE_RRM_DANGEROUS | DISOPTYPE_RRM_DANGEROUS_16)
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync#define DISOPTYPE_INHIBIT_IRQS RT_BIT_32(16) /**< Will or can inhibit irqs (sti, pop ss, mov ss) */
9474d83dcac691984017f8255821b95ec7642804vboxsync#define DISOPTYPE_INVALID_64 RT_BIT_32(19) /**< Invalid in 64 bits mode */
9474d83dcac691984017f8255821b95ec7642804vboxsync#define DISOPTYPE_ONLY_64 RT_BIT_32(20) /**< Only valid in 64 bits mode */
9474d83dcac691984017f8255821b95ec7642804vboxsync#define DISOPTYPE_DEFAULT_64_OP_SIZE RT_BIT_32(21) /**< Default 64 bits operand size */
9474d83dcac691984017f8255821b95ec7642804vboxsync#define DISOPTYPE_FORCED_64_OP_SIZE RT_BIT_32(22) /**< Forced 64 bits operand size; regardless of prefix bytes */
9474d83dcac691984017f8255821b95ec7642804vboxsync#define DISOPTYPE_REXB_EXTENDS_OPREG RT_BIT_32(23) /**< REX.B extends the register field in the opcode byte */
9474d83dcac691984017f8255821b95ec7642804vboxsync#define DISOPTYPE_MOD_FIXED_11 RT_BIT_32(24) /**< modrm.mod is always 11b */
9474d83dcac691984017f8255821b95ec7642804vboxsync#define DISOPTYPE_FORCED_32_OP_SIZE_X86 RT_BIT_32(25) /**< Forced 32 bits operand size; regardless of prefix bytes (only in 16 & 32 bits mode!) */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** @name Parameter usage flags.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** DS:ESI */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** ES:EDI */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** Mask of immediate use flags. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** Check if the use flags indicates an effective address. */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync#define DISUSE_IS_EFFECTIVE_ADDR(a_fUseFlags) (!!( (a_fUseFlags) \
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** @name 64-bit general register indexes.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * This matches the AMD64 register encoding. It is found used in
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * DISOPPARAM::Base.idxGenReg and DISOPPARAM::Index.idxGenReg.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * @note Safe to assume same values as the 16-bit and 32-bit general registers.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** @name 32-bit general register indexes.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * This matches the AMD64 register encoding. It is found used in
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * DISOPPARAM::Base.idxGenReg and DISOPPARAM::Index.idxGenReg.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * @note Safe to assume same values as the 16-bit and 64-bit general registers.
9474d83dcac691984017f8255821b95ec7642804vboxsync/** @name 16-bit general register indexes.
9474d83dcac691984017f8255821b95ec7642804vboxsync * This matches the AMD64 register encoding. It is found used in
69891f8dd7430725700b34d2c6b0222c69c69c53vboxsync * DISOPPARAM::Base.idxGenReg and DISOPPARAM::Index.idxGenReg.
9474d83dcac691984017f8255821b95ec7642804vboxsync * @note Safe to assume same values as the 32-bit and 64-bit general registers.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** @name 8-bit general register indexes.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * This mostly (?) matches the AMD64 register encoding. It is found used in
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * DISOPPARAM::Base.idxGenReg and DISOPPARAM::Index.idxGenReg.
d544fe535c163a24bf8cd831b39264da292b8adfvboxsync/** @name Segment registerindexes.
d544fe535c163a24bf8cd831b39264da292b8adfvboxsync * This matches the AMD64 register encoding. It is found used in
d544fe535c163a24bf8cd831b39264da292b8adfvboxsync * DISOPPARAM::Base.idxSegReg.
d544fe535c163a24bf8cd831b39264da292b8adfvboxsynctypedef enum
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync /** End of the valid register index values. */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync /** The usual 32-bit paranoia. */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** @name FPU register indexes.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * This matches the AMD64 register encoding. It is found used in
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * DISOPPARAM::Base.idxFpuReg.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** @name Control register indexes.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * This matches the AMD64 register encoding. It is found used in
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * DISOPPARAM::Base.idxCtrlReg.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** @name Debug register indexes.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * This matches the AMD64 register encoding. It is found used in
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * DISOPPARAM::Base.idxDbgReg.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** @name MMX register indexes.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * This matches the AMD64 register encoding. It is found used in
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * DISOPPARAM::Base.idxMmxReg.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** @name SSE register indexes.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * This matches the AMD64 register encoding. It is found used in
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * DISOPPARAM::Base.idxXmmReg.
9c77b083e2ca3a9b509faa9789072f2527422e22vboxsync * Opcode parameter (operand) details.
174e1d5b2d6b6d7c92271d7fcc070c6d0cc92312vboxsynctypedef struct DISOPPARAM
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** A combination of DISUSE_XXX. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Immediate value or address, applicable if any of the flags included in
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * DISUSE_IMMEDIATE are set in fUse. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Disposition. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** 64-bit displacement, applicable if DISUSE_DISPLACEMENT64 is set in fUse. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** 32-bit displacement, applicable if DISUSE_DISPLACEMENT32 or
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * DISUSE_RIPDISPLACEMENT32 is set in fUse. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** 16-bit displacement, applicable if DISUSE_DISPLACEMENT16 is set in fUse. */
50ba3040a0c2b77a195a8239e3572d0036e4b86dvboxsync /** 8-bit displacement, applicable if DISUSE_DISPLACEMENT8 is set in fUse. */
50ba3040a0c2b77a195a8239e3572d0036e4b86dvboxsync /** The base register from ModR/M or SIB, applicable if DISUSE_BASE is
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * set in fUse. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** General register index (DISGREG_XXX), applicable if DISUSE_REG_GEN8,
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * DISUSE_REG_GEN16, DISUSE_REG_GEN32 or DISUSE_REG_GEN64 is set in fUse. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** FPU stack register index (DISFPREG_XXX), applicable if DISUSE_REG_FP is
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * set in fUse. 1:1 indexes. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** MMX register index (DISMREG_XXX), applicable if DISUSE_REG_MMX is
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * set in fUse. 1:1 indexes. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** SSE register index (DISXREG_XXX), applicable if DISUSE_REG_XMM is
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * set in fUse. 1:1 indexes. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Segment register index (DISSELREG_XXX), applicable if DISUSE_REG_SEG is
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * set in fUse. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Test register, TR0-TR7, present on early IA32 CPUs, applicable if
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * DISUSE_REG_TEST is set in fUse. No index defines for these. */
9474d83dcac691984017f8255821b95ec7642804vboxsync /** Control register index (DISCREG_XXX), applicable if DISUSE_REG_CR is
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * set in fUse. 1:1 indexes. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Debug register index (DISDREG_XXX), applicable if DISUSE_REG_DBG is
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * set in fUse. 1:1 indexes. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** The SIB index register meaning, applicable if DISUSE_INDEX is
da769a9c0c94bad4a9c3bd895ea53837b58dc4d4vboxsync * set in fUse. */
da769a9c0c94bad4a9c3bd895ea53837b58dc4d4vboxsync /** General register index (DISGREG_XXX), applicable if DISUSE_REG_GEN8,
da769a9c0c94bad4a9c3bd895ea53837b58dc4d4vboxsync * DISUSE_REG_GEN16, DISUSE_REG_GEN32 or DISUSE_REG_GEN64 is set in fUse. */
da769a9c0c94bad4a9c3bd895ea53837b58dc4d4vboxsync /** 2, 4 or 8, if DISUSE_SCALE is set in fUse. */
da769a9c0c94bad4a9c3bd895ea53837b58dc4d4vboxsync /** Parameter size. */
da769a9c0c94bad4a9c3bd895ea53837b58dc4d4vboxsync /** Copy of the corresponding DISOPCODE::fParam1 / DISOPCODE::fParam2 /
da769a9c0c94bad4a9c3bd895ea53837b58dc4d4vboxsync * DISOPCODE::fParam3. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** Pointer to opcode parameter. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** Pointer to opcode parameter. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * Opcode descriptor.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsynctypedef struct DISOPCODE
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Parameter \#1 parser index. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Parameter \#2 parser index. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Parameter \#3 parser index. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Unused padding. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** The opcode identifier. This DIS specific, @see grp_dis_opcodes and
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Parameter \#1 info, @see grp_dis_opparam. */
74407ed9ebae51fb7a33c31f2965f7e105a626ebvboxsync /** Parameter \#2 info, @see grp_dis_opparam. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Parameter \#3 info, @see grp_dis_opparam. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Operand type flags, DISOPTYPE_XXX. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** Pointer to const opcode. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * Callback for reading instruction bytes.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * @returns VBox status code, bytes in DISSTATE::abInstr and byte count in
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * DISSTATE::cbCachedInstr.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * @param pDis Pointer to the disassembler state. The user
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * argument can be found in DISSTATE::pvUser if needed.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * @param offInstr The offset relative to the start of the instruction.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * To get the source address, add this to
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * DISSTATE::uInstrAddr.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * To calculate the destination buffer address, use it
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * as an index into DISSTATE::abInstr.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * @param cbMinRead The minimum number of bytes to read.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * @param cbMaxRead The maximum number of bytes that may be read.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsynctypedef DECLCALLBACK(int) FNDISREADBYTES(PDISSTATE pDis, uint8_t offInstr, uint8_t cbMinRead, uint8_t cbMaxRead);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** Pointer to a opcode byte reader. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** Parser callback.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * @remark no DECLCALLBACK() here because it's considered to be internal and
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * there is no point in enforcing CDECL. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsynctypedef size_t FNDISPARSE(size_t offInstr, PCDISOPCODE pOp, PDISSTATE pDis, PDISOPPARAM pParam);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** Pointer to a disassembler parser function. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** Pointer to a const disassembler parser function pointer. */
c307f0d7384bfc4d19d2290a28be89868f02f42avboxsync * The diassembler state and result.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsynctypedef struct DISSTATE
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** The number of valid bytes in abInstr. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** SIB fields. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Bitfield view */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** ModRM fields. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Bitfield view */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** The CPU mode (DISCPUMODE). */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** The addressing mode (DISCPUMODE). */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** The operand mode (DISCPUMODE). */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Per instruction prefix settings. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** REX prefix value (64 bits only). */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Segment prefix value (DISSELREG). */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Last prefix byte (for SSE2 extension tables). */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Last significan opcode byte of instruction. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** The size of the prefix bytes. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** The instruction size. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Unused bytes. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Internal: instruction filter */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Internal: pointer to disassembly function table */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Pointer to the current instruction. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** The instruction bytes. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** SIB displacment. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Return code set by a worker function like the opcode bytes readers. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** The address of the instruction. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Optional read function */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** User data supplied as an argument to the APIs. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync /** Parameters. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/** @deprecated Use DISSTATE and change Cpu and DisState to Dis. */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsyncDISDECL(int) DISInstrToStr(void const *pvInstr, DISCPUMODE enmCpuMode,
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync PDISSTATE pDis, uint32_t *pcbInstr, char *pszOutput, size_t cbOutput);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsyncDISDECL(int) DISInstrToStrWithReader(RTUINTPTR uInstrAddr, DISCPUMODE enmCpuMode, PFNDISREADBYTES pfnReadBytes, void *pvUser,
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync PDISSTATE pDis, uint32_t *pcbInstr, char *pszOutput, size_t cbOutput);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsyncDISDECL(int) DISInstrToStrEx(RTUINTPTR uInstrAddr, DISCPUMODE enmCpuMode,
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync PFNDISREADBYTES pfnReadBytes, void *pvUser, uint32_t uFilter,
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync PDISSTATE pDis, uint32_t *pcbInstr, char *pszOutput, size_t cbOutput);
0b07f19b2d822b86714ed48e3581477a046f1c79vboxsyncDISDECL(int) DISInstr(void const *pvInstr, DISCPUMODE enmCpuMode, PDISSTATE pDis, uint32_t *pcbInstr);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsyncDISDECL(int) DISInstrWithReader(RTUINTPTR uInstrAddr, DISCPUMODE enmCpuMode, PFNDISREADBYTES pfnReadBytes, void *pvUser,
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsyncDISDECL(int) DISInstrEx(RTUINTPTR uInstrAddr, DISCPUMODE enmCpuMode, uint32_t uFilter,
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(int) DISInstrWithPrefetchedBytes(RTUINTPTR uInstrAddr, DISCPUMODE enmCpuMode, uint32_t fFilter,
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(int) DISGetParamSize(PCDISSTATE pDis, PCDISOPPARAM pParam);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(DISSELREG) DISDetectSegReg(PCDISSTATE pDis, PCDISOPPARAM pParam);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(uint8_t) DISQuerySegPrefixByte(PCDISSTATE pDis);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** @name Flags returned by DISQueryParamVal (DISQPVPARAMVAL::flags).
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** @name Types returned by DISQueryParamVal (DISQPVPARAMVAL::flags).
97566036db1dc1dba46ed21be4e147c728fd1027vboxsynctypedef struct
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** Pointer to opcode parameter value. */
666e2c9af6a34f7a05d8069a11194756312f5be6vboxsync/** Indicates which parameter DISQueryParamVal should operate on. */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(int) DISQueryParamVal(PCPUMCTXCORE pCtx, PCDISSTATE pDis, PCDISOPPARAM pParam, PDISQPVPARAMVAL pParamVal, DISQPVWHICH parmtype);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(int) DISQueryParamRegPtr(PCPUMCTXCORE pCtx, PCDISSTATE pDis, PCDISOPPARAM pParam, void **ppReg, size_t *pcbSize);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(int) DISFetchReg8(PCCPUMCTXCORE pCtx, unsigned reg8, uint8_t *pVal);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(int) DISFetchReg16(PCCPUMCTXCORE pCtx, unsigned reg16, uint16_t *pVal);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(int) DISFetchReg32(PCCPUMCTXCORE pCtx, unsigned reg32, uint32_t *pVal);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(int) DISFetchReg64(PCCPUMCTXCORE pCtx, unsigned reg64, uint64_t *pVal);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(int) DISFetchRegSeg(PCCPUMCTXCORE pCtx, DISSELREG sel, RTSEL *pVal);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(int) DISFetchRegSegEx(PCCPUMCTXCORE pCtx, DISSELREG sel, RTSEL *pVal, PCPUMSELREGHID *ppSelHidReg);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(int) DISWriteReg8(PCPUMCTXCORE pRegFrame, unsigned reg8, uint8_t val8);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(int) DISWriteReg16(PCPUMCTXCORE pRegFrame, unsigned reg32, uint16_t val16);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(int) DISWriteReg32(PCPUMCTXCORE pRegFrame, unsigned reg32, uint32_t val32);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(int) DISWriteReg64(PCPUMCTXCORE pRegFrame, unsigned reg64, uint64_t val64);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(int) DISWriteRegSeg(PCPUMCTXCORE pCtx, DISSELREG sel, RTSEL val);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(int) DISPtrReg8(PCPUMCTXCORE pCtx, unsigned reg8, uint8_t **ppReg);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(int) DISPtrReg16(PCPUMCTXCORE pCtx, unsigned reg16, uint16_t **ppReg);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(int) DISPtrReg32(PCPUMCTXCORE pCtx, unsigned reg32, uint32_t **ppReg);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(int) DISPtrReg64(PCPUMCTXCORE pCtx, unsigned reg64, uint64_t **ppReg);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * Try resolve an address into a symbol name.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * For use with DISFormatYasmEx(), DISFormatMasmEx() and DISFormatGasEx().
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * @returns VBox status code.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * @retval VINF_SUCCESS on success, pszBuf contains the full symbol name.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * @retval VINF_BUFFER_OVERFLOW if pszBuf is too small the symbol name. The
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * content of pszBuf is truncated and zero terminated.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * @retval VERR_SYMBOL_NOT_FOUND if no matching symbol was found for the address.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * @param pDis Pointer to the disassembler CPU state.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * @param u32Sel The selector value. Use DIS_FMT_SEL_IS_REG, DIS_FMT_SEL_GET_VALUE,
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * DIS_FMT_SEL_GET_REG to access this.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * @param uAddress The segment address.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * @param pszBuf Where to store the symbol name
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * @param cchBuf The size of the buffer.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * @param poff If not a perfect match, then this is where the offset from the return
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * symbol to the specified address is returned.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * @param pvUser The user argument.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsynctypedef DECLCALLBACK(int) FNDISGETSYMBOL(PCDISSTATE pDis, uint32_t u32Sel, RTUINTPTR uAddress, char *pszBuf, size_t cchBuf, RTINTPTR *poff, void *pvUser);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** Pointer to a FNDISGETSYMBOL(). */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * Checks if the FNDISGETSYMBOL argument u32Sel is a register or not.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync#define DIS_FMT_SEL_IS_REG(u32Sel) ( !!((u32Sel) & RT_BIT(31)) )
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * Extracts the selector value from the FNDISGETSYMBOL argument u32Sel.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * @returns Selector value.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync#define DIS_FMT_SEL_GET_VALUE(u32Sel) ( (RTSEL)(u32Sel) )
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * Extracts the register number from the FNDISGETSYMBOL argument u32Sel.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * @returns USE_REG_CS, USE_REG_SS, USE_REG_DS, USE_REG_ES, USE_REG_FS or USE_REG_FS.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync#define DIS_FMT_SEL_GET_REG(u32Sel) ( ((u32Sel) >> 16) & 0xf )
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** @internal */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync#define DIS_FMT_SEL_FROM_REG(uReg) ( ((uReg) << 16) | RT_BIT(31) | 0xffff )
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** @internal */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync#define DIS_FMT_SEL_FROM_VALUE(Sel) ( (Sel) & 0xffff )
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** @name Flags for use with DISFormatYasmEx(), DISFormatMasmEx() and DISFormatGasEx().
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** Put the address to the right. */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** Put the address to the left. */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** Put the address in comments.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * For some assemblers this implies placing it to the right. */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** Put the instruction bytes to the right of the disassembly. */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** Put the instruction bytes to the left of the disassembly. */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** Put the instruction bytes in comments.
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * For some assemblers this implies placing the bytes to the right. */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** Put the bytes in square brackets. */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** Put spaces between the bytes. */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** Display the relative +/- offset of branch instructions that uses relative addresses,
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * and put the target address in parenthesis. */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** Strict assembly. The assembly should, when ever possible, make the
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * assembler reproduce the exact same binary. (Refers to the yasm
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * strict keyword.) */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** Checks if the given flags are a valid combination. */
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync && ((fFlags) & (DIS_FMT_FLAGS_ADDR_RIGHT | DIS_FMT_FLAGS_ADDR_LEFT)) != (DIS_FMT_FLAGS_ADDR_RIGHT | DIS_FMT_FLAGS_ADDR_LEFT) \
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync || (fFlags & (DIS_FMT_FLAGS_ADDR_RIGHT | DIS_FMT_FLAGS_ADDR_LEFT)) ) \
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync && ((fFlags) & (DIS_FMT_FLAGS_BYTES_RIGHT | DIS_FMT_FLAGS_BYTES_LEFT)) != (DIS_FMT_FLAGS_BYTES_RIGHT | DIS_FMT_FLAGS_BYTES_LEFT) \
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync && ( !((fFlags) & (DIS_FMT_FLAGS_BYTES_COMMENT | DIS_FMT_FLAGS_BYTES_BRACKETS)) \
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync || (fFlags & (DIS_FMT_FLAGS_BYTES_RIGHT | DIS_FMT_FLAGS_BYTES_LEFT)) ) \
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(size_t) DISFormatYasm( PCDISSTATE pDis, char *pszBuf, size_t cchBuf);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(size_t) DISFormatYasmEx(PCDISSTATE pDis, char *pszBuf, size_t cchBuf, uint32_t fFlags, PFNDISGETSYMBOL pfnGetSymbol, void *pvUser);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(size_t) DISFormatMasm( PCDISSTATE pDis, char *pszBuf, size_t cchBuf);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(size_t) DISFormatMasmEx(PCDISSTATE pDis, char *pszBuf, size_t cchBuf, uint32_t fFlags, PFNDISGETSYMBOL pfnGetSymbol, void *pvUser);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(size_t) DISFormatGas( PCDISSTATE pDis, char *pszBuf, size_t cchBuf);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncDISDECL(size_t) DISFormatGasEx( PCDISSTATE pDis, char *pszBuf, size_t cchBuf, uint32_t fFlags, PFNDISGETSYMBOL pfnGetSymbol, void *pvUser);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync/** @todo DISAnnotate(PCDISSTATE pDis, char *pszBuf, size_t cchBuf, register
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync * reader, memory reader); */