* Copyright (c) 2010-2023 Google, Inc. All rights reserved.
* Copyright (c) 2002-2010 VMware, Inc. All rights reserved.
* **********************************************************/
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of VMware, Inc. nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/
#ifndef _DR_IR_OPND_H_
#define _DR_IR_OPND_H_ 1
* OPERAND ROUTINES
*/
* @file dr_ir_opnd.h
* @brief Functions and defines to create and manipulate instruction operands.
*/
#if defined(DR_REG_ENUM_COMPATIBILITY) && (defined(REG_EAX) || defined(REG_RAX))
# error REG_ enum conflict between DR and ucontext.h! Use DR_REG_ constants instead.
#endif
#ifndef INSTR_INLINE
# ifdef DR_FAST_IR
# define INSTR_INLINE inline
# else
# define INSTR_INLINE
# endif
#endif
*
* Intel's size names are listed in 'Appendix A Opcode Map (Intel SDM Volume 2)'
* specifically A.2.2 Codes for Operand Type
*
* For register operands, the DR_REG_ constants are used, which implicitly
* state a size (e.g., DR_REG_CX is 2 bytes).
* Use the type opnd_size_t for these values (we avoid typedef-ing the
* enum, as its storage size is compiler-specific). opnd_size_t is a
* byte, so the largest value here needs to be <= 255.
*/
enum {
* as opnd_size_t when we have the type available, so we can overlap
* the two enums. If needed, the function template_optype_is_reg can be used
* to check whether the operand type has an implicit size and stores the reg enum
* instead of the size enum.
* The reg_id_t type is now wider, but for x86 we ensure our values
* all fit via an assert in d_r_arch_init().
*/
OPSZ_NA = 0,
OPSZ_FIRST = OPSZ_NA,
OPSZ_0,
* 'm': used for both start addresses (lea, invlpg) and
* implicit constants (rol, fldl2e, etc.) */
OPSZ_1,
OPSZ_2,
OPSZ_4,
OPSZ_6,
OPSZ_8,
OPSZ_10,
* (latter used by fld, fstp, fbld, fbstp) */
OPSZ_16,
OPSZ_14,
OPSZ_28,
OPSZ_94,
OPSZ_108,
OPSZ_512,
* The following sizes (OPSZ_*_short*) vary according to the cs segment and the
* operand size prefix. This IR assumes that the cs segment is set to the
* default operand size. The operand size prefix then functions to shrink the
* size. The IR does not explicitly mark the prefix; rather, a shortened size is
* requested in the operands themselves, with the IR adding the prefix at encode
* time. Normally the fixed sizes above should be used rather than these
* variable sizes, which are used internally by the IR and should only be
* externally specified when building an operand in order to be flexible and
* allow other operands to decide the size for the instruction (the prefix
* applies to the entire instruction).
*/
OPSZ_2_short1,
* another operand requests a short size then this size can
* accommodate by shifting to its short size, which is 1
* byte). */
OPSZ_4_short2,
OPSZ_4_rex8_short2,
OPSZ_4_rex8,
OPSZ_6_irex10_short4,
* segment selector + address. On AMD processors this is
* 6/4 bytes for segment selector + address (rex is ignored). */
OPSZ_8_short2,
OPSZ_8_short4,
OPSZ_28_short14,
OPSZ_108_short94,
OPSZ_4x8,
* Used for control and debug register moves and for Intel MPX. */
OPSZ_6x10,
* Stack operands not only vary by operand size specifications but also
* by 32-bit versus 64-bit processor mode.
*/
OPSZ_4x8_short2,
* Also 64-bit address-size specified operands, which are
* short4 rather than short2 in 64-bit mode (but short2 in
* 32-bit mode).
* Note that this IR does not distinguish extra stack
* operations performed by OP_enter w/ non-zero immed.
*/
OPSZ_4x8_short2xi8,
* always 8 for 64-bit Intel */
OPSZ_4_short2xi4,
* always 4 for 64-bit Intel */
* The following 3 sizes differ based on whether the modrm chooses a
* register or memory.
*/
OPSZ_1_reg4,
OPSZ_2_reg4,
OPSZ_4_reg16,
* used by insertps. */
OPSZ_xsave,
* Used for FPU, MMX, XMM, etc. state by xsave and xrstor. */
OPSZ_12,
OPSZ_32,
* Also Intel 'qq','pd','ps','x': 32 bytes (256 bits) */
OPSZ_40,
OPSZ_32_short16,
OPSZ_8_rex16,
OPSZ_8_rex16_short4,
OPSZ_12_rex40_short6,
OPSZ_16_vex32,
OPSZ_15,
OPSZ_3,
* (except 8b/OPSZ_1) in order
*/
OPSZ_1b,
OPSZ_2b,
OPSZ_3b,
OPSZ_4b,
OPSZ_5b,
OPSZ_6b,
OPSZ_7b,
OPSZ_9b,
OPSZ_10b,
OPSZ_11b,
OPSZ_12b,
OPSZ_20b,
OPSZ_25b,
* At encode or decode time, the size will match the size of the
* register list operand in the containing instruction's operands.
*/
OPSZ_VAR_REGLIST,
OPSZ_20,
OPSZ_24,
OPSZ_36,
OPSZ_44,
OPSZ_48,
OPSZ_52,
OPSZ_56,
OPSZ_60,
OPSZ_64,
* Also Intel: 64 bytes (512 bits) */
OPSZ_68,
OPSZ_72,
OPSZ_76,
OPSZ_80,
OPSZ_84,
OPSZ_88,
OPSZ_92,
OPSZ_96,
OPSZ_100,
OPSZ_104,
OPSZ_112,
OPSZ_116,
OPSZ_120,
OPSZ_124,
OPSZ_128,
OPSZ_SCALABLE,
OPSZ_SCALABLE_PRED,
OPSZ_16_vex32_evex64,
OPSZ_vex32_evex64,
OPSZ_16_of_32_evex64,
* EVEX.LL'.
*/
OPSZ_32_of_64,
OPSZ_4_of_32_evex64,
OPSZ_8_of_32_evex64,
OPSZ_8x16,
* on 32-bit/64-bit mode.
*/
* the size routines in opnd_shared.c.
*/
OPSZ_LAST,
};
#ifdef X64
# define OPSZ_PTR OPSZ_8
# define OPSZ_STACK OPSZ_8
# define OPSZ_PTR_DBL OPSZ_16
# define OPSZ_PTR_HALF OPSZ_4
#else
# define OPSZ_PTR OPSZ_4
# define OPSZ_STACK OPSZ_4
# define OPSZ_PTR_DBL OPSZ_8
# define OPSZ_PTR_HALF OPSZ_2
#endif
#define OPSZ_VARSTACK \
OPSZ_4x8_short2
* push/pop operand sizes. */
#define OPSZ_REXVARSTACK \
OPSZ_4_rex8_short2
* stack push/pop like operand sizes. */
#define OPSZ_ret OPSZ_4x8_short2xi8
#define OPSZ_call OPSZ_ret
#define OPSZ_lea OPSZ_0
#define OPSZ_invlpg OPSZ_0
#define OPSZ_bnd OPSZ_0
#define OPSZ_xlat OPSZ_1
#define OPSZ_clflush OPSZ_1
#define OPSZ_prefetch OPSZ_1
#define OPSZ_lgdt OPSZ_6x10
#define OPSZ_sgdt OPSZ_6x10
#define OPSZ_lidt OPSZ_6x10
#define OPSZ_sidt OPSZ_6x10
#define OPSZ_bound OPSZ_8_short4
#define OPSZ_maskmovq OPSZ_8
#define OPSZ_maskmovdqu OPSZ_16
#define OPSZ_fldenv OPSZ_28_short14
#define OPSZ_fnstenv OPSZ_28_short14
#define OPSZ_fnsave OPSZ_108_short94
#define OPSZ_frstor OPSZ_108_short94
#define OPSZ_fxsave OPSZ_512
#define OPSZ_fxrstor OPSZ_512
#define OPSZ_ptwrite OPSZ_4_rex8
#ifdef AARCH64
# define OPSZ_sys OPSZ_1
#endif
* at most 256 total DR_REG_ plus OPSZ_ values. Currently there are 165-odd.
* Decoder assumes 32-bit, 16-bit, and 8-bit are in specific order
* corresponding to modrm encodings.
* We also assume that the DR_SEG_ constants are invalid as pointers for
* our use in instr_info_t.code.
* Also, reg_names array in encode.c corresponds to this enum order.
* Plus, dr_reg_fixer array in encode.c.
* Lots of optimizations assume same ordering of registers among
* 32, 16, and 8 i.e. eax same position (first) in each etc.
* reg_rm_selectable() assumes the GPR registers, mmx, and xmm are all in a row.
*/
enum {
* used in the same field (instr_info_t operand sizes) have the type and distinguish
* properly.
* XXX i#3528: Switch from guaranteed-contiguous exposed enum ranges, which are not
* possible to maintain long-term, to function interfaces.
*/
DR_REG_NULL,
#ifdef X86
DR_REG_RAX,
DR_REG_RCX,
DR_REG_RDX,
DR_REG_RBX,
DR_REG_RSP,
DR_REG_RBP,
DR_REG_RSI,
DR_REG_RDI,
DR_REG_R8,
DR_REG_R9,
DR_REG_R10,
DR_REG_R11,
DR_REG_R12,
DR_REG_R13,
DR_REG_R14,
DR_REG_R15,
DR_REG_EAX,
DR_REG_ECX,
DR_REG_EDX,
DR_REG_EBX,
DR_REG_ESP,
DR_REG_EBP,
DR_REG_ESI,
DR_REG_EDI,
DR_REG_R8D,
DR_REG_R9D,
DR_REG_R10D,
DR_REG_R11D,
DR_REG_R12D,
DR_REG_R13D,
DR_REG_R14D,
DR_REG_R15D,
DR_REG_AX,
DR_REG_CX,
DR_REG_DX,
DR_REG_BX,
DR_REG_SP,
DR_REG_BP,
DR_REG_SI,
DR_REG_DI,
DR_REG_R8W,
DR_REG_R9W,
DR_REG_R10W,
DR_REG_R11W,
DR_REG_R12W,
DR_REG_R13W,
DR_REG_R14W,
DR_REG_R15W,
DR_REG_AL,
DR_REG_CL,
DR_REG_DL,
DR_REG_BL,
DR_REG_AH,
DR_REG_CH,
DR_REG_DH,
DR_REG_BH,
DR_REG_R8L,
DR_REG_R9L,
DR_REG_R10L,
DR_REG_R11L,
DR_REG_R12L,
DR_REG_R13L,
DR_REG_R14L,
DR_REG_R15L,
DR_REG_SPL,
DR_REG_BPL,
DR_REG_SIL,
DR_REG_DIL,
DR_REG_MM0,
DR_REG_MM1,
DR_REG_MM2,
DR_REG_MM3,
DR_REG_MM4,
DR_REG_MM5,
DR_REG_MM6,
DR_REG_MM7,
DR_REG_XMM0,
DR_REG_XMM1,
DR_REG_XMM2,
DR_REG_XMM3,
DR_REG_XMM4,
DR_REG_XMM5,
DR_REG_XMM6,
DR_REG_XMM7,
DR_REG_XMM8,
DR_REG_XMM9,
DR_REG_XMM10,
DR_REG_XMM11,
DR_REG_XMM12,
DR_REG_XMM13,
DR_REG_XMM14,
DR_REG_XMM15,
DR_REG_XMM16,
DR_REG_XMM17,
DR_REG_XMM18,
DR_REG_XMM19,
DR_REG_XMM20,
DR_REG_XMM21,
DR_REG_XMM22,
DR_REG_XMM23,
DR_REG_XMM24,
DR_REG_XMM25,
DR_REG_XMM26,
DR_REG_XMM27,
DR_REG_XMM28,
DR_REG_XMM29,
DR_REG_XMM30,
DR_REG_XMM31,
RESERVED_XMM = DR_REG_XMM31 + 32,
DR_REG_ST0,
DR_REG_ST1,
DR_REG_ST2,
DR_REG_ST3,
DR_REG_ST4,
DR_REG_ST5,
DR_REG_ST6,
DR_REG_ST7,
DR_SEG_ES,
DR_SEG_CS,
DR_SEG_SS,
DR_SEG_DS,
DR_SEG_FS,
DR_SEG_GS,
*/
DR_REG_DR0,
DR_REG_DR1,
DR_REG_DR2,
DR_REG_DR3,
DR_REG_DR4,
DR_REG_DR5,
DR_REG_DR6,
DR_REG_DR7,
DR_REG_DR8,
DR_REG_DR9,
DR_REG_DR10,
DR_REG_DR11,
DR_REG_DR12,
DR_REG_DR13,
DR_REG_DR14,
DR_REG_DR15,
DR_REG_CR0,
DR_REG_CR1,
DR_REG_CR2,
DR_REG_CR3,
DR_REG_CR4,
DR_REG_CR5,
DR_REG_CR6,
DR_REG_CR7,
DR_REG_CR8,
DR_REG_CR9,
DR_REG_CR10,
DR_REG_CR11,
DR_REG_CR12,
DR_REG_CR13,
DR_REG_CR14,
DR_REG_CR15,
* need to fit into a byte (checked in d_r_arch_init()). Register enums
* below this point must not be used as opnd_size_t.
*/
DR_REG_MAX_AS_OPSZ = DR_REG_CR15,
DR_REG_INVALID,
DR_REG_YMM0,
DR_REG_YMM1,
DR_REG_YMM2,
DR_REG_YMM3,
DR_REG_YMM4,
DR_REG_YMM5,
DR_REG_YMM6,
DR_REG_YMM7,
DR_REG_YMM8,
DR_REG_YMM9,
DR_REG_YMM10,
DR_REG_YMM11,
DR_REG_YMM12,
DR_REG_YMM13,
DR_REG_YMM14,
DR_REG_YMM15,
DR_REG_YMM16,
DR_REG_YMM17,
DR_REG_YMM18,
DR_REG_YMM19,
DR_REG_YMM20,
DR_REG_YMM21,
DR_REG_YMM22,
DR_REG_YMM23,
DR_REG_YMM24,
DR_REG_YMM25,
DR_REG_YMM26,
DR_REG_YMM27,
DR_REG_YMM28,
DR_REG_YMM29,
DR_REG_YMM30,
DR_REG_YMM31,
RESERVED_YMM = DR_REG_YMM31 + 32,
DR_REG_ZMM0,
DR_REG_ZMM1,
DR_REG_ZMM2,
DR_REG_ZMM3,
DR_REG_ZMM4,
DR_REG_ZMM5,
DR_REG_ZMM6,
DR_REG_ZMM7,
DR_REG_ZMM8,
DR_REG_ZMM9,
DR_REG_ZMM10,
DR_REG_ZMM11,
DR_REG_ZMM12,
DR_REG_ZMM13,
DR_REG_ZMM14,
DR_REG_ZMM15,
DR_REG_ZMM16,
DR_REG_ZMM17,
DR_REG_ZMM18,
DR_REG_ZMM19,
DR_REG_ZMM20,
DR_REG_ZMM21,
DR_REG_ZMM22,
DR_REG_ZMM23,
DR_REG_ZMM24,
DR_REG_ZMM25,
DR_REG_ZMM26,
DR_REG_ZMM27,
DR_REG_ZMM28,
DR_REG_ZMM29,
DR_REG_ZMM30,
DR_REG_ZMM31,
RESERVED_ZMM = DR_REG_ZMM31 + 32,
DR_REG_K0,
DR_REG_K1,
DR_REG_K2,
DR_REG_K3,
DR_REG_K4,
DR_REG_K5,
DR_REG_K6,
DR_REG_K7,
RESERVED_OPMASK = DR_REG_K7 + 8,
DR_REG_BND0,
DR_REG_BND1,
DR_REG_BND2,
DR_REG_BND3,
#elif defined(AARCHXX)
DR_REG_INVALID,
# ifdef AARCH64
DR_REG_X0,
DR_REG_X1,
DR_REG_X2,
DR_REG_X3,
DR_REG_X4,
DR_REG_X5,
DR_REG_X6,
DR_REG_X7,
DR_REG_X8,
DR_REG_X9,
DR_REG_X10,
DR_REG_X11,
DR_REG_X12,
DR_REG_X13,
DR_REG_X14,
DR_REG_X15,
DR_REG_X16,
DR_REG_X17,
DR_REG_X18,
DR_REG_X19,
DR_REG_X20,
DR_REG_X21,
DR_REG_X22,
DR_REG_X23,
DR_REG_X24,
DR_REG_X25,
DR_REG_X26,
DR_REG_X27,
DR_REG_X28,
DR_REG_X29,
DR_REG_X30,
DR_REG_XSP,
DR_REG_XZR,
DR_REG_W0,
DR_REG_W1,
DR_REG_W2,
DR_REG_W3,
DR_REG_W4,
DR_REG_W5,
DR_REG_W6,
DR_REG_W7,
DR_REG_W8,
DR_REG_W9,
DR_REG_W10,
DR_REG_W11,
DR_REG_W12,
DR_REG_W13,
DR_REG_W14,
DR_REG_W15,
DR_REG_W16,
DR_REG_W17,
DR_REG_W18,
DR_REG_W19,
DR_REG_W20,
DR_REG_W21,
DR_REG_W22,
DR_REG_W23,
DR_REG_W24,
DR_REG_W25,
DR_REG_W26,
DR_REG_W27,
DR_REG_W28,
DR_REG_W29,
DR_REG_W30,
DR_REG_WSP,
DR_REG_WZR,
# else
DR_REG_R0,
DR_REG_R1,
DR_REG_R2,
DR_REG_R3,
DR_REG_R4,
DR_REG_R5,
DR_REG_R6,
DR_REG_R7,
DR_REG_R8,
DR_REG_R9,
DR_REG_R10,
DR_REG_R11,
DR_REG_R12,
DR_REG_R13,
DR_REG_R14,
DR_REG_R15,
# endif
# ifdef AARCH64
DR_REG_Z0,
DR_REG_Z1,
DR_REG_Z2,
DR_REG_Z3,
DR_REG_Z4,
DR_REG_Z5,
DR_REG_Z6,
DR_REG_Z7,
DR_REG_Z8,
DR_REG_Z9,
DR_REG_Z10,
DR_REG_Z11,
DR_REG_Z12,
DR_REG_Z13,
DR_REG_Z14,
DR_REG_Z15,
DR_REG_Z16,
DR_REG_Z17,
DR_REG_Z18,
DR_REG_Z19,
DR_REG_Z20,
DR_REG_Z21,
DR_REG_Z22,
DR_REG_Z23,
DR_REG_Z24,
DR_REG_Z25,
DR_REG_Z26,
DR_REG_Z27,
DR_REG_Z28,
DR_REG_Z29,
DR_REG_Z30,
DR_REG_Z31,
# endif
*
* Base+disp operands do not store the full reg_id_t value, only the lower
* REG_SPECIFIER_BITS, so any register used in addressing must be less than
* 1 << REG_SPECIFIER_BITS. This is checked in d_r_arch_init().
*/
# if defined(AARCH64)
DR_REG_MAX_ADDRESSING_REG = DR_REG_Z31,
# else
DR_REG_MAX_ADDRESSING_REG = DR_REG_R15,
# endif
DR_REG_Q0,
DR_REG_Q1,
DR_REG_Q2,
DR_REG_Q3,
DR_REG_Q4,
DR_REG_Q5,
DR_REG_Q6,
DR_REG_Q7,
DR_REG_Q8,
DR_REG_Q9,
DR_REG_Q10,
DR_REG_Q11,
DR_REG_Q12,
DR_REG_Q13,
DR_REG_Q14,
DR_REG_Q15,
DR_REG_Q16,
DR_REG_Q17,
DR_REG_Q18,
DR_REG_Q19,
DR_REG_Q20,
DR_REG_Q21,
DR_REG_Q22,
DR_REG_Q23,
DR_REG_Q24,
DR_REG_Q25,
DR_REG_Q26,
DR_REG_Q27,
DR_REG_Q28,
DR_REG_Q29,
DR_REG_Q30,
DR_REG_Q31,
DR_REG_D0,
DR_REG_D1,
DR_REG_D2,
DR_REG_D3,
DR_REG_D4,
DR_REG_D5,
DR_REG_D6,
DR_REG_D7,
DR_REG_D8,
DR_REG_D9,
DR_REG_D10,
DR_REG_D11,
DR_REG_D12,
DR_REG_D13,
DR_REG_D14,
DR_REG_D15,
DR_REG_D16,
DR_REG_D17,
DR_REG_D18,
DR_REG_D19,
DR_REG_D20,
DR_REG_D21,
DR_REG_D22,
DR_REG_D23,
DR_REG_D24,
DR_REG_D25,
DR_REG_D26,
DR_REG_D27,
DR_REG_D28,
DR_REG_D29,
DR_REG_D30,
DR_REG_D31,
DR_REG_S0,
DR_REG_S1,
DR_REG_S2,
DR_REG_S3,
DR_REG_S4,
DR_REG_S5,
DR_REG_S6,
DR_REG_S7,
DR_REG_S8,
DR_REG_S9,
DR_REG_S10,
DR_REG_S11,
DR_REG_S12,
DR_REG_S13,
DR_REG_S14,
DR_REG_S15,
DR_REG_S16,
DR_REG_S17,
DR_REG_S18,
DR_REG_S19,
DR_REG_S20,
DR_REG_S21,
DR_REG_S22,
DR_REG_S23,
DR_REG_S24,
DR_REG_S25,
DR_REG_S26,
DR_REG_S27,
DR_REG_S28,
DR_REG_S29,
DR_REG_S30,
DR_REG_S31,
DR_REG_H0,
DR_REG_H1,
DR_REG_H2,
DR_REG_H3,
DR_REG_H4,
DR_REG_H5,
DR_REG_H6,
DR_REG_H7,
DR_REG_H8,
DR_REG_H9,
DR_REG_H10,
DR_REG_H11,
DR_REG_H12,
DR_REG_H13,
DR_REG_H14,
DR_REG_H15,
DR_REG_H16,
DR_REG_H17,
DR_REG_H18,
DR_REG_H19,
DR_REG_H20,
DR_REG_H21,
DR_REG_H22,
DR_REG_H23,
DR_REG_H24,
DR_REG_H25,
DR_REG_H26,
DR_REG_H27,
DR_REG_H28,
DR_REG_H29,
DR_REG_H30,
DR_REG_H31,
DR_REG_B0,
DR_REG_B1,
DR_REG_B2,
DR_REG_B3,
DR_REG_B4,
DR_REG_B5,
DR_REG_B6,
DR_REG_B7,
DR_REG_B8,
DR_REG_B9,
DR_REG_B10,
DR_REG_B11,
DR_REG_B12,
DR_REG_B13,
DR_REG_B14,
DR_REG_B15,
DR_REG_B16,
DR_REG_B17,
DR_REG_B18,
DR_REG_B19,
DR_REG_B20,
DR_REG_B21,
DR_REG_B22,
DR_REG_B23,
DR_REG_B24,
DR_REG_B25,
DR_REG_B26,
DR_REG_B27,
DR_REG_B28,
DR_REG_B29,
DR_REG_B30,
DR_REG_B31,
# ifndef AARCH64
DR_REG_CR0,
DR_REG_CR1,
DR_REG_CR2,
DR_REG_CR3,
DR_REG_CR4,
DR_REG_CR5,
DR_REG_CR6,
DR_REG_CR7,
DR_REG_CR8,
DR_REG_CR9,
DR_REG_CR10,
DR_REG_CR11,
DR_REG_CR12,
DR_REG_CR13,
DR_REG_CR14,
DR_REG_CR15,
# endif
* for 32-bit as we have the W versions for 64-bit), and DR_REG_RN_BB
* (bottom byte) as they are not available in the ISA and which portion
* of a GPR is selected purely by the opcode. Our decoder will create
* a partial register for these to help tools, but it won't specify which
* part of the register.
*/
* other bits beyond aflags, here we do explicitly list cpsr and spsr for
* OP_mrs and OP_msr to distinguish them and make things clearer.
*/
# ifdef AARCH64
DR_REG_NZCV,
DR_REG_FPCR,
DR_REG_FPSR,
DR_REG_MDCCSR_EL0,
DR_REG_DBGDTR_EL0,
DR_REG_DBGDTRRX_EL0,
DR_REG_SP_EL0,
DR_REG_SPSEL,
DR_REG_DAIFSET,
DR_REG_DAIFCLR,
DR_REG_CURRENTEL,
DR_REG_PAN,
DR_REG_UAO,
DR_REG_CTR_EL0,
DR_REG_DCZID_EL0,
DR_REG_RNDR,
DR_REG_RNDRRS,
DR_REG_DAIF,
DR_REG_DIT,
DR_REG_SSBS,
DR_REG_TCO,
DR_REG_DSPSR_EL0,
DR_REG_DLR_EL0,
DR_REG_PMCR_EL0,
DR_REG_PMCNTENSET_EL0,
DR_REG_PMCNTENCLR_EL0,
DR_REG_PMOVSCLR_EL0,
DR_REG_PMSWINC_EL0,
DR_REG_PMSELR_EL0,
DR_REG_PMCEID0_EL0,
DR_REG_PMCEID1_EL0,
DR_REG_PMCCNTR_EL0,
DR_REG_PMXEVTYPER_EL0,
DR_REG_PMXEVCNTR_EL0,
DR_REG_PMUSERENR_EL0,
DR_REG_PMOVSSET_EL0,
DR_REG_SCXTNUM_EL0,
DR_REG_CNTFRQ_EL0,
DR_REG_CNTPCT_EL0,
DR_REG_CNTP_TVAL_EL0,
DR_REG_CNTP_CTL_EL0,
DR_REG_CNTP_CVAL_EL0,
DR_REG_CNTV_TVAL_EL0,
DR_REG_CNTV_CTL_EL0,
DR_REG_CNTV_CVAL_EL0,
DR_REG_PMEVCNTR0_EL0,
DR_REG_PMEVCNTR1_EL0,
DR_REG_PMEVCNTR2_EL0,
DR_REG_PMEVCNTR3_EL0,
DR_REG_PMEVCNTR4_EL0,
DR_REG_PMEVCNTR5_EL0,
DR_REG_PMEVCNTR6_EL0,
DR_REG_PMEVCNTR7_EL0,
DR_REG_PMEVCNTR8_EL0,
DR_REG_PMEVCNTR9_EL0,
DR_REG_PMEVCNTR10_EL0,
DR_REG_PMEVCNTR11_EL0,
DR_REG_PMEVCNTR12_EL0,
DR_REG_PMEVCNTR13_EL0,
DR_REG_PMEVCNTR14_EL0,
DR_REG_PMEVCNTR15_EL0,
DR_REG_PMEVCNTR16_EL0,
DR_REG_PMEVCNTR17_EL0,
DR_REG_PMEVCNTR18_EL0,
DR_REG_PMEVCNTR19_EL0,
DR_REG_PMEVCNTR20_EL0,
DR_REG_PMEVCNTR21_EL0,
DR_REG_PMEVCNTR22_EL0,
DR_REG_PMEVCNTR23_EL0,
DR_REG_PMEVCNTR24_EL0,
DR_REG_PMEVCNTR25_EL0,
DR_REG_PMEVCNTR26_EL0,
DR_REG_PMEVCNTR27_EL0,
DR_REG_PMEVCNTR28_EL0,
DR_REG_PMEVCNTR29_EL0,
DR_REG_PMEVCNTR30_EL0,
DR_REG_PMEVTYPER0_EL0,
DR_REG_PMEVTYPER1_EL0,
DR_REG_PMEVTYPER2_EL0,
DR_REG_PMEVTYPER3_EL0,
DR_REG_PMEVTYPER4_EL0,
DR_REG_PMEVTYPER5_EL0,
DR_REG_PMEVTYPER6_EL0,
DR_REG_PMEVTYPER7_EL0,
DR_REG_PMEVTYPER8_EL0,
DR_REG_PMEVTYPER9_EL0,
DR_REG_PMEVTYPER10_EL0,
DR_REG_PMEVTYPER11_EL0,
DR_REG_PMEVTYPER12_EL0,
DR_REG_PMEVTYPER13_EL0,
DR_REG_PMEVTYPER14_EL0,
DR_REG_PMEVTYPER15_EL0,
DR_REG_PMEVTYPER16_EL0,
DR_REG_PMEVTYPER17_EL0,
DR_REG_PMEVTYPER18_EL0,
DR_REG_PMEVTYPER19_EL0,
DR_REG_PMEVTYPER20_EL0,
DR_REG_PMEVTYPER21_EL0,
DR_REG_PMEVTYPER22_EL0,
DR_REG_PMEVTYPER23_EL0,
DR_REG_PMEVTYPER24_EL0,
DR_REG_PMEVTYPER25_EL0,
DR_REG_PMEVTYPER26_EL0,
DR_REG_PMEVTYPER27_EL0,
DR_REG_PMEVTYPER28_EL0,
DR_REG_PMEVTYPER29_EL0,
DR_REG_PMEVTYPER30_EL0,
DR_REG_PMCCFILTR_EL0,
DR_REG_SPSR_IRQ,
DR_REG_SPSR_ABT,
DR_REG_SPSR_UND,
DR_REG_SPSR_FIQ,
# else
DR_REG_CPSR,
DR_REG_SPSR,
DR_REG_FPSCR,
# endif
DR_REG_TPIDRURW,
DR_REG_TPIDRURO,
# ifdef AARCH64
DR_REG_P0,
DR_REG_P1,
DR_REG_P2,
DR_REG_P3,
DR_REG_P4,
DR_REG_P5,
DR_REG_P6,
DR_REG_P7,
DR_REG_P8,
DR_REG_P9,
DR_REG_P10,
DR_REG_P11,
DR_REG_P12,
DR_REG_P13,
DR_REG_P14,
DR_REG_P15,
DR_REG_FFR,
# endif
# ifdef AARCH64
DR_REG_CNTVCT_EL0,
# endif
# ifdef AARCH64
DR_REG_R0 = DR_REG_X0,
DR_REG_R1 = DR_REG_X1,
DR_REG_R2 = DR_REG_X2,
DR_REG_R3 = DR_REG_X3,
DR_REG_R4 = DR_REG_X4,
DR_REG_R5 = DR_REG_X5,
DR_REG_R6 = DR_REG_X6,
DR_REG_R7 = DR_REG_X7,
DR_REG_R8 = DR_REG_X8,
DR_REG_R9 = DR_REG_X9,
DR_REG_R10 = DR_REG_X10,
DR_REG_R11 = DR_REG_X11,
DR_REG_R12 = DR_REG_X12,
DR_REG_R13 = DR_REG_X13,
DR_REG_R14 = DR_REG_X14,
DR_REG_R15 = DR_REG_X15,
DR_REG_R16 = DR_REG_X16,
DR_REG_R17 = DR_REG_X17,
DR_REG_R18 = DR_REG_X18,
DR_REG_R19 = DR_REG_X19,
DR_REG_R20 = DR_REG_X20,
DR_REG_R21 = DR_REG_X21,
DR_REG_R22 = DR_REG_X22,
DR_REG_R23 = DR_REG_X23,
DR_REG_R24 = DR_REG_X24,
DR_REG_R25 = DR_REG_X25,
DR_REG_R26 = DR_REG_X26,
DR_REG_R27 = DR_REG_X27,
DR_REG_R28 = DR_REG_X28,
DR_REG_R29 = DR_REG_X29,
DR_REG_R30 = DR_REG_X30,
DR_REG_SP = DR_REG_XSP,
DR_REG_LR = DR_REG_X30,
# else
DR_REG_SP = DR_REG_R13,
DR_REG_LR = DR_REG_R14,
DR_REG_PC = DR_REG_R15,
# endif
DR_REG_SL = DR_REG_R10,
DR_REG_FP = DR_REG_R11,
DR_REG_IP = DR_REG_R12,
# ifndef AARCH64
DR_REG_APSR = DR_REG_CPSR,
# endif
DR_REG_TPIDR_EL0 = DR_REG_TPIDRURW,
DR_REG_TPIDRRO_EL0 = DR_REG_TPIDRURO,
DR_REG_CP15_C13_2 = DR_REG_TPIDRURW,
DR_REG_CP15_C13_3 = DR_REG_TPIDRURO,
# ifdef AARCH64
DR_REG_LAST_VALID_ENUM = DR_REG_CNTVCT_EL0,
DR_REG_LAST_ENUM = DR_REG_CNTVCT_EL0,
# else
DR_REG_LAST_VALID_ENUM = DR_REG_TPIDRURO,
DR_REG_LAST_ENUM = DR_REG_TPIDRURO,
# endif
# ifdef AARCH64
DR_REG_START_64 = DR_REG_X0,
DR_REG_STOP_64 = DR_REG_XSP,
DR_REG_START_32 = DR_REG_W0,
DR_REG_STOP_32 = DR_REG_WSP,
DR_REG_START_GPR = DR_REG_X0,
DR_REG_STOP_GPR = DR_REG_XSP,
# else
DR_REG_START_32 = DR_REG_R0,
DR_REG_STOP_32 = DR_REG_R15,
DR_REG_START_GPR = DR_REG_R0,
DR_REG_STOP_GPR = DR_REG_R15,
# endif
DR_NUM_GPR_REGS = DR_REG_STOP_GPR - DR_REG_START_GPR + 1,
# ifdef AARCH64
DR_NUM_SIMD_VECTOR_REGS = DR_REG_Z31 - DR_REG_Z0 + 1,
# else
* S registers.
*/
DR_NUM_SIMD_VECTOR_REGS = DR_REG_Q15 - DR_REG_Q0 + 1,
# endif
# ifndef AARCH64
DR_REG_XSP = DR_REG_SP,
# endif
#elif defined(RISCV64)
DR_REG_INVALID,
DR_REG_X0,
DR_REG_X1,
DR_REG_X2,
DR_REG_X3,
DR_REG_X4,
DR_REG_X5,
DR_REG_X6,
DR_REG_X7,
DR_REG_X8,
DR_REG_X9,
DR_REG_X10,
DR_REG_X11,
DR_REG_X12,
DR_REG_X13,
DR_REG_X14,
DR_REG_X15,
DR_REG_X16,
DR_REG_X17,
DR_REG_X18,
DR_REG_X19,
DR_REG_X20,
DR_REG_X21,
DR_REG_X22,
DR_REG_X23,
DR_REG_X24,
DR_REG_X25,
DR_REG_X26,
DR_REG_X27,
DR_REG_X28,
DR_REG_X29,
DR_REG_X30,
DR_REG_X31,
DR_REG_ZERO = DR_REG_X0,
DR_REG_RA = DR_REG_X1,
DR_REG_SP = DR_REG_X2,
DR_REG_GP = DR_REG_X3,
DR_REG_TP = DR_REG_X4,
DR_REG_T0 = DR_REG_X5,
DR_REG_T1 = DR_REG_X6,
DR_REG_T2 = DR_REG_X7,
DR_REG_S0 = DR_REG_X8,
DR_REG_FP = DR_REG_X8,
DR_REG_S1 = DR_REG_X9,
DR_REG_A0 = DR_REG_X10,
DR_REG_A1 = DR_REG_X11,
DR_REG_A2 = DR_REG_X12,
DR_REG_A3 = DR_REG_X13,
DR_REG_A4 = DR_REG_X14,
DR_REG_A5 = DR_REG_X15,
DR_REG_A6 = DR_REG_X16,
DR_REG_A7 = DR_REG_X17,
DR_REG_S2 = DR_REG_X18,
DR_REG_S3 = DR_REG_X19,
DR_REG_S4 = DR_REG_X20,
DR_REG_S5 = DR_REG_X21,
DR_REG_S6 = DR_REG_X22,
DR_REG_S7 = DR_REG_X23,
DR_REG_S8 = DR_REG_X24,
DR_REG_S9 = DR_REG_X25,
DR_REG_S10 = DR_REG_X26,
DR_REG_S11 = DR_REG_X27,
DR_REG_T3 = DR_REG_X28,
DR_REG_T4 = DR_REG_X29,
DR_REG_T5 = DR_REG_X30,
DR_REG_T6 = DR_REG_X31,
DR_REG_PC,
DR_REG_F0,
DR_REG_F1,
DR_REG_F2,
DR_REG_F3,
DR_REG_F4,
DR_REG_F5,
DR_REG_F6,
DR_REG_F7,
DR_REG_F8,
DR_REG_F9,
DR_REG_F10,
DR_REG_F11,
DR_REG_F12,
DR_REG_F13,
DR_REG_F14,
DR_REG_F15,
DR_REG_F16,
DR_REG_F17,
DR_REG_F18,
DR_REG_F19,
DR_REG_F20,
DR_REG_F21,
DR_REG_F22,
DR_REG_F23,
DR_REG_F24,
DR_REG_F25,
DR_REG_F26,
DR_REG_F27,
DR_REG_F28,
DR_REG_F29,
DR_REG_F30,
DR_REG_F31,
DR_REG_FCSR,
DR_REG_FT0 = DR_REG_F0,
DR_REG_FT1 = DR_REG_F1,
DR_REG_FT2 = DR_REG_F2,
DR_REG_FT3 = DR_REG_F3,
DR_REG_FT4 = DR_REG_F4,
DR_REG_FT5 = DR_REG_F5,
DR_REG_FT6 = DR_REG_F6,
DR_REG_FT7 = DR_REG_F7,
DR_REG_FS0 = DR_REG_F8,
DR_REG_FS1 = DR_REG_F9,
DR_REG_FA0 = DR_REG_F10,
DR_REG_FA1 = DR_REG_F11,
DR_REG_FA2 = DR_REG_F12,
DR_REG_FA3 = DR_REG_F13,
DR_REG_FA4 = DR_REG_F14,
DR_REG_FA5 = DR_REG_F15,
DR_REG_FA6 = DR_REG_F16,
DR_REG_FA7 = DR_REG_F17,
DR_REG_FS2 = DR_REG_F18,
DR_REG_FS3 = DR_REG_F19,
DR_REG_FS4 = DR_REG_F20,
DR_REG_FS5 = DR_REG_F21,
DR_REG_FS6 = DR_REG_F22,
DR_REG_FS7 = DR_REG_F23,
DR_REG_FS8 = DR_REG_F24,
DR_REG_FS9 = DR_REG_F25,
DR_REG_FS10 = DR_REG_F26,
DR_REG_FS11 = DR_REG_F27,
DR_REG_FT8 = DR_REG_F28,
DR_REG_FT9 = DR_REG_F29,
DR_REG_FT10 = DR_REG_F30,
DR_REG_FT11 = DR_REG_F31,
DR_REG_LAST_VALID_ENUM = DR_REG_FCSR,
DR_REG_LAST_ENUM = DR_REG_FCSR,
DR_REG_START_64 = DR_REG_X0,
DR_REG_STOP_64 = DR_REG_F31,
DR_REG_START_32 = DR_REG_X0,
DR_REG_STOP_32 = DR_REG_F31,
DR_REG_START_GPR = DR_REG_X0,
DR_REG_STOP_GPR = DR_REG_X31,
DR_REG_XSP = DR_REG_SP,
DR_NUM_GPR_REGS = DR_REG_STOP_GPR - DR_REG_START_GPR + 1,
DR_NUM_SIMD_VECTOR_REGS = 0,
#else
# error Register definitions missing for this platform.
#endif
};
typedef ushort reg_id_t;
* (checked in d_r_arch_init()).
*/
typedef byte opnd_size_t;
#ifdef X86
# ifdef X64
# define DR_REG_XAX \
DR_REG_RAX
# define DR_REG_XCX \
DR_REG_RCX
# define DR_REG_XDX \
DR_REG_RDX
# define DR_REG_XBX \
DR_REG_RBX
# define DR_REG_XSP \
DR_REG_RSP
# define DR_REG_XBP \
DR_REG_RBP
# define DR_REG_XSI \
DR_REG_RSI
# define DR_REG_XDI \
DR_REG_RDI
# else
# define DR_REG_XAX \
DR_REG_EAX
# define DR_REG_XCX \
DR_REG_ECX
# define DR_REG_XDX \
DR_REG_EDX
# define DR_REG_XBX \
DR_REG_EBX
# define DR_REG_XSP \
DR_REG_ESP
# define DR_REG_XBP \
DR_REG_EBP
# define DR_REG_XSI \
DR_REG_ESI
# define DR_REG_XDI \
DR_REG_EDI
# endif
#endif
#ifdef X86
# define DR_REG_START_GPR DR_REG_XAX
# ifdef X64
# define DR_REG_STOP_GPR DR_REG_R15
# else
# define DR_REG_STOP_GPR DR_REG_XDI
# endif
# define DR_NUM_GPR_REGS (DR_REG_STOP_GPR - DR_REG_START_GPR + 1)
# define DR_NUM_SIMD_VECTOR_REGS (DR_REG_STOP_ZMM - DR_REG_START_ZMM + 1)
# define DR_REG_START_64 \
DR_REG_RAX
# define DR_REG_STOP_64 DR_REG_R15
# define DR_REG_START_32 \
DR_REG_EAX
# define DR_REG_STOP_32 \
DR_REG_R15D
*/
# define DR_REG_START_16 \
DR_REG_AX
*/
# define DR_REG_STOP_16 \
DR_REG_R15W
*/
# define DR_REG_START_8 DR_REG_AL
# define DR_REG_STOP_8 DR_REG_DIL
# define DR_REG_START_8HL \
DR_REG_AL
# define DR_REG_STOP_8HL DR_REG_BH
# define DR_REG_START_x86_8 \
DR_REG_AH
# define DR_REG_STOP_x86_8 \
DR_REG_BH
# define DR_REG_START_x64_8 \
DR_REG_SPL
# define DR_REG_STOP_x64_8 \
DR_REG_DIL
# define DR_REG_START_MMX DR_REG_MM0
# define DR_REG_STOP_MMX DR_REG_MM7
# define DR_REG_START_XMM DR_REG_XMM0
# define DR_REG_START_YMM DR_REG_YMM0
# define DR_REG_START_ZMM DR_REG_ZMM0
# ifdef X64
# define DR_REG_STOP_XMM DR_REG_XMM31
# define DR_REG_STOP_YMM DR_REG_YMM31
# define DR_REG_STOP_ZMM DR_REG_ZMM31
# else
# define DR_REG_STOP_XMM DR_REG_XMM7
# define DR_REG_STOP_YMM DR_REG_YMM7
# define DR_REG_STOP_ZMM DR_REG_ZMM7
# endif
# define DR_REG_START_OPMASK DR_REG_K0
# define DR_REG_STOP_OPMASK DR_REG_K7
# define DR_REG_START_BND DR_REG_BND0
# define DR_REG_STOP_BND DR_REG_BND3
# define DR_REG_START_FLOAT \
DR_REG_ST0
# define DR_REG_STOP_FLOAT \
DR_REG_ST7
# define DR_REG_START_SEGMENT DR_SEG_ES
# define DR_REG_START_SEGMENT_x64 \
DR_SEG_FS
# define DR_REG_STOP_SEGMENT DR_SEG_GS
# define DR_REG_START_DR DR_REG_DR0
# define DR_REG_STOP_DR DR_REG_DR15
# define DR_REG_START_CR DR_REG_CR0
# define DR_REG_STOP_CR DR_REG_CR15
* Last valid register enum value. Note: DR_REG_INVALID is now smaller
* than this value.
*/
# define DR_REG_LAST_VALID_ENUM DR_REG_K7
# define DR_REG_LAST_ENUM DR_REG_BND3
#endif
#define REG_NULL DR_REG_NULL
#define REG_INVALID DR_REG_INVALID
#ifndef ARM
# define REG_START_64 DR_REG_START_64
# define REG_STOP_64 DR_REG_STOP_64
#endif
#define REG_START_32 DR_REG_START_32
#define REG_STOP_32 DR_REG_STOP_32
#define REG_LAST_VALID_ENUM DR_REG_LAST_VALID_ENUM
#define REG_LAST_ENUM DR_REG_LAST_ENUM
#define REG_XSP DR_REG_XSP
* conflicts with the REG_ enum in <sys/ucontext.h>: i#34).
* Clients should set(DynamoRIO_REG_COMPATIBILITY ON) prior to
* configure_DynamoRIO_client() to set this define.
*/
#if defined(X86) && defined(DR_REG_ENUM_COMPATIBILITY)
# define REG_START_16 DR_REG_START_16
# define REG_STOP_16 DR_REG_STOP_16
# define REG_START_8 DR_REG_START_8
# define REG_STOP_8 DR_REG_STOP_8
# define REG_RAX DR_REG_RAX
# define REG_RCX DR_REG_RCX
# define REG_RDX DR_REG_RDX
# define REG_RBX DR_REG_RBX
# define REG_RSP DR_REG_RSP
# define REG_RBP DR_REG_RBP
# define REG_RSI DR_REG_RSI
# define REG_RDI DR_REG_RDI
# define REG_R8 DR_REG_R8
# define REG_R9 DR_REG_R9
# define REG_R10 DR_REG_R10
# define REG_R11 DR_REG_R11
# define REG_R12 DR_REG_R12
# define REG_R13 DR_REG_R13
# define REG_R14 DR_REG_R14
# define REG_R15 DR_REG_R15
# define REG_EAX DR_REG_EAX
# define REG_ECX DR_REG_ECX
# define REG_EDX DR_REG_EDX
# define REG_EBX DR_REG_EBX
# define REG_ESP DR_REG_ESP
# define REG_EBP DR_REG_EBP
# define REG_ESI DR_REG_ESI
# define REG_EDI DR_REG_EDI
# define REG_R8D DR_REG_R8D
# define REG_R9D DR_REG_R9D
# define REG_R10D DR_REG_R10D
# define REG_R11D DR_REG_R11D
# define REG_R12D DR_REG_R12D
# define REG_R13D DR_REG_R13D
# define REG_R14D DR_REG_R14D
# define REG_R15D DR_REG_R15D
# define REG_AX DR_REG_AX
# define REG_CX DR_REG_CX
# define REG_DX DR_REG_DX
# define REG_BX DR_REG_BX
# define REG_SP DR_REG_SP
# define REG_BP DR_REG_BP
# define REG_SI DR_REG_SI
# define REG_DI DR_REG_DI
# define REG_R8W DR_REG_R8W
# define REG_R9W DR_REG_R9W
# define REG_R10W DR_REG_R10W
# define REG_R11W DR_REG_R11W
# define REG_R12W DR_REG_R12W
# define REG_R13W DR_REG_R13W
# define REG_R14W DR_REG_R14W
# define REG_R15W DR_REG_R15W
# define REG_AL DR_REG_AL
# define REG_CL DR_REG_CL
# define REG_DL DR_REG_DL
# define REG_BL DR_REG_BL
# define REG_AH DR_REG_AH
# define REG_CH DR_REG_CH
# define REG_DH DR_REG_DH
# define REG_BH DR_REG_BH
# define REG_R8L DR_REG_R8L
# define REG_R9L DR_REG_R9L
# define REG_R10L DR_REG_R10L
# define REG_R11L DR_REG_R11L
# define REG_R12L DR_REG_R12L
# define REG_R13L DR_REG_R13L
# define REG_R14L DR_REG_R14L
# define REG_R15L DR_REG_R15L
# define REG_SPL DR_REG_SPL
# define REG_BPL DR_REG_BPL
# define REG_SIL DR_REG_SIL
# define REG_DIL DR_REG_DIL
# define REG_MM0 DR_REG_MM0
# define REG_MM1 DR_REG_MM1
# define REG_MM2 DR_REG_MM2
# define REG_MM3 DR_REG_MM3
# define REG_MM4 DR_REG_MM4
# define REG_MM5 DR_REG_MM5
# define REG_MM6 DR_REG_MM6
# define REG_MM7 DR_REG_MM7
# define REG_XMM0 DR_REG_XMM0
# define REG_XMM1 DR_REG_XMM1
# define REG_XMM2 DR_REG_XMM2
# define REG_XMM3 DR_REG_XMM3
# define REG_XMM4 DR_REG_XMM4
# define REG_XMM5 DR_REG_XMM5
# define REG_XMM6 DR_REG_XMM6
# define REG_XMM7 DR_REG_XMM7
# define REG_XMM8 DR_REG_XMM8
# define REG_XMM9 DR_REG_XMM9
# define REG_XMM10 DR_REG_XMM10
# define REG_XMM11 DR_REG_XMM11
# define REG_XMM12 DR_REG_XMM12
# define REG_XMM13 DR_REG_XMM13
# define REG_XMM14 DR_REG_XMM14
# define REG_XMM15 DR_REG_XMM15
# define REG_ST0 DR_REG_ST0
# define REG_ST1 DR_REG_ST1
# define REG_ST2 DR_REG_ST2
# define REG_ST3 DR_REG_ST3
# define REG_ST4 DR_REG_ST4
# define REG_ST5 DR_REG_ST5
# define REG_ST6 DR_REG_ST6
# define REG_ST7 DR_REG_ST7
# define SEG_ES DR_SEG_ES
# define SEG_CS DR_SEG_CS
# define SEG_SS DR_SEG_SS
# define SEG_DS DR_SEG_DS
# define SEG_FS DR_SEG_FS
# define SEG_GS DR_SEG_GS
# define REG_DR0 DR_REG_DR0
# define REG_DR1 DR_REG_DR1
# define REG_DR2 DR_REG_DR2
# define REG_DR3 DR_REG_DR3
# define REG_DR4 DR_REG_DR4
# define REG_DR5 DR_REG_DR5
# define REG_DR6 DR_REG_DR6
# define REG_DR7 DR_REG_DR7
# define REG_DR8 DR_REG_DR8
# define REG_DR9 DR_REG_DR9
# define REG_DR10 DR_REG_DR10
# define REG_DR11 DR_REG_DR11
# define REG_DR12 DR_REG_DR12
# define REG_DR13 DR_REG_DR13
# define REG_DR14 DR_REG_DR14
# define REG_DR15 DR_REG_DR15
# define REG_CR0 DR_REG_CR0
# define REG_CR1 DR_REG_CR1
# define REG_CR2 DR_REG_CR2
# define REG_CR3 DR_REG_CR3
# define REG_CR4 DR_REG_CR4
# define REG_CR5 DR_REG_CR5
# define REG_CR6 DR_REG_CR6
# define REG_CR7 DR_REG_CR7
# define REG_CR8 DR_REG_CR8
# define REG_CR9 DR_REG_CR9
# define REG_CR10 DR_REG_CR10
# define REG_CR11 DR_REG_CR11
# define REG_CR12 DR_REG_CR12
# define REG_CR13 DR_REG_CR13
# define REG_CR14 DR_REG_CR14
# define REG_CR15 DR_REG_CR15
# define REG_XAX DR_REG_XAX
# define REG_XCX DR_REG_XCX
# define REG_XDX DR_REG_XDX
# define REG_XBX DR_REG_XBX
# define REG_XBP DR_REG_XBP
# define REG_XSI DR_REG_XSI
# define REG_XDI DR_REG_XDI
# define REG_START_8HL DR_REG_START_8HL
# define REG_STOP_8HL DR_REG_STOP_8HL
# define REG_START_x86_8 DR_REG_START_x86_8
# define REG_STOP_x86_8 DR_REG_STOP_x86_8
# define REG_START_x64_8 DR_REG_START_x64_8
# define REG_STOP_x64_8 DR_REG_STOP_x64_8
# define REG_START_MMX DR_REG_START_MMX
# define REG_STOP_MMX DR_REG_STOP_MMX
# define REG_START_XMM DR_REG_START_XMM
# define REG_STOP_XMM DR_REG_STOP_XMM
# define REG_START_YMM DR_REG_START_YMM
# define REG_STOP_YMM DR_REG_STOP_YMM
# define REG_START_FLOAT DR_REG_START_FLOAT
# define REG_STOP_FLOAT DR_REG_STOP_FLOAT
# define REG_START_SEGMENT DR_REG_START_SEGMENT
# define REG_START_SEGMENT_x64 DR_REG_START_SEGMENT_x64
# define REG_STOP_SEGMENT DR_REG_STOP_SEGMENT
# define REG_START_DR DR_REG_START_DR
# define REG_STOP_DR DR_REG_STOP_DR
# define REG_START_CR DR_REG_START_CR
# define REG_STOP_CR DR_REG_STOP_CR
# define REG_YMM0 DR_REG_YMM0
# define REG_YMM1 DR_REG_YMM1
# define REG_YMM2 DR_REG_YMM2
# define REG_YMM3 DR_REG_YMM3
# define REG_YMM4 DR_REG_YMM4
# define REG_YMM5 DR_REG_YMM5
# define REG_YMM6 DR_REG_YMM6
# define REG_YMM7 DR_REG_YMM7
# define REG_YMM8 DR_REG_YMM8
# define REG_YMM9 DR_REG_YMM9
# define REG_YMM10 DR_REG_YMM10
# define REG_YMM11 DR_REG_YMM11
# define REG_YMM12 DR_REG_YMM12
# define REG_YMM13 DR_REG_YMM13
# define REG_YMM14 DR_REG_YMM14
# define REG_YMM15 DR_REG_YMM15
#endif
* These flags describe how the index register in a memory reference is shifted
* before being added to or subtracted from the base register. They also describe
* how a general source register is shifted before being used in its containing
* instruction.
*/
typedef enum _dr_shift_type_t {
DR_SHIFT_LSL,
DR_SHIFT_LSR,
DR_SHIFT_ASR,
DR_SHIFT_ROR,
DR_SHIFT_MUL,
* The register is rotated right by 1 bit, with the carry flag (rather than
* bit 0) being shifted in to the most-significant bit. (For shifts of
* general source registers, if the instruction writes the condition codes,
* bit 0 is then shifted into the carry flag: but for memory references bit
* 0 is simply dropped.)
* Only valid for shifts whose amount is stored in an immediate, not a register.
*/
DR_SHIFT_RRX,
* No shift.
* Only valid for shifts whose amount is stored in an immediate, not a register.
*/
DR_SHIFT_NONE,
} dr_shift_type_t;
* These flags describe how the index register in a memory reference is extended
* before being optionally shifted and added to the base register. They also describe
* how a general source register is extended before being used in its containing
* instruction.
*/
typedef enum _dr_extend_type_t {
DR_EXTEND_DEFAULT = 0,
DR_EXTEND_UXTB = 0,
DR_EXTEND_UXTH,
DR_EXTEND_UXTW,
DR_EXTEND_UXTX,
DR_EXTEND_SXTB,
DR_EXTEND_SXTH,
DR_EXTEND_SXTW,
DR_EXTEND_SXTX,
} dr_extend_type_t;
* These flags describe the values for "pattern" operands for aarch64
* predicate count instructions. They are always set for imms with the
* flag #DR_OPND_IS_PREDICATE_CONSTRAINT
*/
typedef enum _dr_pred_constr_type_t {
DR_PRED_CONSTR_POW2 = 0,
DR_PRED_CONSTR_VL1,
DR_PRED_CONSTR_VL2,
DR_PRED_CONSTR_VL3,
DR_PRED_CONSTR_VL4,
DR_PRED_CONSTR_VL5,
DR_PRED_CONSTR_VL6,
DR_PRED_CONSTR_VL7,
DR_PRED_CONSTR_VL8,
DR_PRED_CONSTR_VL16,
DR_PRED_CONSTR_VL32,
DR_PRED_CONSTR_VL64,
DR_PRED_CONSTR_VL128,
DR_PRED_CONSTR_VL256,
DR_PRED_CONSTR_UIMM5_14,
DR_PRED_CONSTR_UIMM5_15,
DR_PRED_CONSTR_UIMM5_16,
DR_PRED_CONSTR_UIMM5_17,
DR_PRED_CONSTR_UIMM5_18,
DR_PRED_CONSTR_UIMM5_19,
DR_PRED_CONSTR_UIMM5_20,
DR_PRED_CONSTR_UIMM5_21,
DR_PRED_CONSTR_UIMM5_22,
DR_PRED_CONSTR_UIMM5_23,
DR_PRED_CONSTR_UIMM5_24,
DR_PRED_CONSTR_UIMM5_25,
DR_PRED_CONSTR_UIMM5_26,
DR_PRED_CONSTR_UIMM5_27,
DR_PRED_CONSTR_UIMM5_28,
DR_PRED_CONSTR_MUL4,
DR_PRED_CONSTR_MUL3,
DR_PRED_CONSTR_ALL,
DR_PRED_CONSTR_FIRST_NUMBER = DR_PRED_CONSTR_UIMM5_14,
DR_PRED_CONSTR_LAST_NUMBER = DR_PRED_CONSTR_UIMM5_28,
} dr_pred_constr_type_t;
* These flags describe operations performed on the value of a source register
* before it is combined with other sources as part of the behavior of the
* containing instruction, or operations performed on an index register or
* displacement before it is added to or subtracted from the base register.
*/
typedef enum _dr_opnd_flags_t {
DR_OPND_DEFAULT = 0x00,
DR_OPND_NEGATED = 0x01,
* This register's value is shifted prior to use in the containing instruction.
* This flag is for informational purposes only and is not guaranteed to
* be consistent with the shift type of an index register or displacement
* if the latter are set without using opnd_set_index_shift() or if an
* instruction is created without using high-level API routines.
* This flag is also ignored for encoding and will not apply a shift
* on its own.
*/
DR_OPND_SHIFTED = 0x02,
* This operand should be combined with an adjacent operand to create a
* single value. This flag is typically used on immediates: e.g., for ARM's
* OP_vbic_i64, two 32-bit immediate operands should be interpreted as the
* low and high parts of a 64-bit value.
*/
DR_OPND_MULTI_PART = 0x04,
* This immediate integer operand should be interpreted as an ARM/AArch64 shift type.
*/
DR_OPND_IS_SHIFT = 0x08,
DR_OPND_IN_LIST = 0x10,
* This register's value is extended prior to use in the containing instruction.
* This flag is for informational purposes only and is not guaranteed to
* be consistent with the shift type of an index register or displacement
* if the latter are set without using opnd_set_index_extend() or if an
* instruction is created without using high-level API routines.
* This flag is also ignored for encoding and will not apply a shift
* on its own.
*/
DR_OPND_EXTENDED = 0x20,
DR_OPND_IS_EXTEND = 0x40,
DR_OPND_IS_CONDITION = 0x80,
* Registers with this flag should be considered vectors and have an element size
* representing their element size.
*/
DR_OPND_IS_VECTOR = 0x100,
* Predicate registers can either be merging, zero or neither. If one of these
* are set then they are either a merge or zero otherwise aren't either.
*/
DR_OPND_IS_MERGE_PREDICATE = 0x200,
DR_OPND_IS_ZERO_PREDICATE = 0x400,
* This immediate integer operand should be treated as an AArch64
* SVE predicate constraint
*/
DR_OPND_IS_PREDICATE_CONSTRAINT = 0x800,
* This is used by RISCV64 for immediates display format.
*/
DR_OPND_IMM_PRINT_DECIMAL = 0x1000,
} dr_opnd_flags_t;
#ifdef DR_FAST_IR
# define REG_SPECIFIER_BITS 8
# define SCALE_SPECIFIER_BITS 4
* opnd_t type exposed for optional "fast IR" access. Note that DynamoRIO
* reserves the right to change this structure across releases and does
* not guarantee binary or source compatibility when this structure's fields
* are directly accessed. If the OPND_ macros are used, DynamoRIO does
* guarantee source compatibility, but not binary compatibility. If binary
* compatibility is desired, do not use the fast IR feature.
*/
struct _opnd_t {
byte kind;
* but for registers, if 0, the full size of the register is assumed.
* It holds a OPSZ_ field from decode.h.
* We need it so we can pick the proper instruction form for
* encoding -- an alternative would be to split all the opcodes
* up into different data size versions.
*/
opnd_size_t size;
* needed for x64 operand types here in the alignment padding.
*/
union {
ushort far_pc_seg_selector;
reg_id_t segment : REG_SPECIFIER_BITS;
* and ABS_ADDR_kind, on x86 */
ushort disp;
ushort shift;
ushort flags;
} aux;
union {
ptr_int_t immed_int;
struct {
int low;
int high;
} immed_int_multi_part;
float immed_float;
# ifndef WINDOWS
* Currently not included for Windows because sizeof(opnd_t) does not
* equal EXPECTED_SIZEOF_OPND, triggering the ASSERT in d_r_arch_init().
*/
* Marking this field as packed seems to do it and avoids other changes
* that might occur if packing the whole struct.
* XXX i#4488: Do any double-loading instructions require 8-byte alignment?
* Perhaps we should just break compatibility and align this to 8 for
* x86 and ARM 32-bit.
*/
double immed_double IF_ARM(__attribute__((__packed__)));
# endif
* (encoded as a data16 prefix, which also implies a 16-bit EIP,
* making it only useful for far pcs)
*/
app_pc pc;
* segment selector (which is NOT a DR_SEG_ constant) in far_pc_seg_selector
* above, to save space.
*/
instr_t *instr;
struct {
reg_id_t reg;
opnd_size_t element_size;
} reg_and_element_size;
struct {
int disp;
reg_id_t base_reg : REG_SPECIFIER_BITS;
reg_id_t index_reg : REG_SPECIFIER_BITS;
* when we have reg_id_t elsewhere: it won't combine them
* (gcc will). alternative is all uint and no reg_id_t.
* We also have to use byte and not dr_shift_type_t
* to get cl to not align.
*/
# if defined(AARCH64)
* offset is zero, for example: ldr w1,[x2,#0]! from ldr w1,[x0],#0.
*/
byte pre_index : 1;
byte extend_type : 3;
byte scaled : 1;
byte scaled_value : 3;
* Only 2 element sizes are used for vector base/index registers in SVE:
* Single (OPSZ_4)
* Double (OPSZ_8)
* so we only need one bit to store the value (see ELEMENT_SIZE_* enum in
* opnd_shared.c).
* This is ignored if the base and index registers are scalar registers.
*/
byte element_size : 1;
# elif defined(ARM)
byte shift_type : 3;
byte shift_amount_minus_1 : 5;
# elif defined(X86)
byte scale : SCALE_SPECIFIER_BITS;
byte encode_zero_disp : 1;
byte force_full_disp : 1;
byte disp_short_addr : 1;
byte index_reg_is_zmm : 1;
* VSIB address is of length ZMM. This
* flag is not exposed and serves as an
* internal AVX-512 extension of
* index_reg, leaving index_reg binary
* compatible at 8 bits.
*/
# endif
} base_disp;
void *addr;
} value;
};
#endif
#ifdef DR_FAST_IR
enum {
NULL_kind,
IMMED_INTEGER_kind,
IMMED_FLOAT_kind,
PC_kind,
INSTR_kind,
REG_kind,
BASE_DISP_kind,
FAR_PC_kind,
FAR_INSTR_kind,
# if defined(X64) || defined(ARM)
REL_ADDR_kind,
# endif
# ifdef X64
ABS_ADDR_kind,
# endif
MEM_INSTR_kind,
IMMED_DOUBLE_kind,
LAST_kind,
};
#endif
DR_API
INSTR_INLINE
opnd_t
opnd_create_null(void);
DR_API
INSTR_INLINE
opnd_t
opnd_create_reg(reg_id_t r);
DR_API
INSTR_INLINE
* Returns a register operand corresponding to a part of the
* register represented by the DR_REG_ constant \p r.
*
* On x86, \p r must be a multimedia (mmx, xmm, ymm, zmm) register. For
* partial general-purpose registers on x86, use the appropriate
* sub-register name with opnd_create_reg() instead.
*/
opnd_t
opnd_create_reg_partial(reg_id_t r, opnd_size_t subsize);
DR_API
INSTR_INLINE
* Returns a register operand corresponding to a vector
* register that has an element size.
*/
opnd_t
opnd_create_reg_element_vector(reg_id_t r, opnd_size_t element_size);
#ifdef AARCH64
DR_API
INSTR_INLINE
* Returns a SVE predicate register for use as a governing predicate
* with either "/m" merge mode set or "/z" zeroing mode set depending
* on /p is_merge
* For creating general (non-governing) predicate registers,
* use opnd_create_reg() for scalar predicates and
* opnd_create_reg_element_vector() for vector predicates.
*/
opnd_t
opnd_create_predicate_reg(reg_id_t r, bool is_merge);
#endif
DR_API
INSTR_INLINE
* Returns a register operand with additional properties specified by \p flags.
* If \p subsize is 0, creates a full-sized register; otherwise, creates a
* partial register in the manner of opnd_create_reg_partial().
*/
opnd_t
opnd_create_reg_ex(reg_id_t r, opnd_size_t subsize, dr_opnd_flags_t flags);
DR_API
* Returns a signed immediate integer operand with value \p i and size
* \p data_size; \p data_size must be a OPSZ_ constant.
*/
opnd_t
opnd_create_immed_int(ptr_int_t i, opnd_size_t data_size);
DR_API
* Returns an unsigned immediate integer operand with value \p i and size
* \p data_size; \p data_size must be a OPSZ_ constant.
*/
opnd_t
opnd_create_immed_uint(ptr_uint_t i, opnd_size_t data_size);
DR_API
* Returns an unsigned immediate integer operand with value \p i and size
* \p data_size; \p data_size must be a OPSZ_ constant.
* This operand can be distinguished from a regular immediate integer
* operand by the flag #DR_OPND_MULTI_PART in opnd_get_flags() which tells
* the caller to use opnd_get_immed_int64() to retrieve the full value.
* \note 32-bit only: use opnd_create_immed_int() for 64-bit architectures.
*/
opnd_t
opnd_create_immed_int64(int64 i, opnd_size_t data_size);
DR_API
* Performs a bitwise NOT operation on the integer value in \p opnd, but only on the LSB
* bits provided by opnd_size_in_bits(opnd). \p opnd must carry an immed integer.
*/
opnd_t
opnd_invert_immed_int(opnd_t opnd);
DR_API
* Returns an immediate float operand with value \p f.
* The caller's code should use proc_save_fpstate() or be inside a
* clean call that has requested to preserve the floating-point state.
*/
opnd_t
opnd_create_immed_float(float f);
#ifndef WINDOWS
* Type double currently not included for Windows because sizeof(opnd_t) does
* not equal EXPECTED_SIZEOF_OPND, triggering the ASSERT in d_r_arch_init().
*/
DR_API
* Returns an immediate double operand with value \p d.
* The caller's code should use proc_save_fpstate() or be inside a
* clean call that has requested to preserve the floating-point state.
*/
opnd_t
opnd_create_immed_double(double d);
#endif
#ifdef AARCH64
DR_API
* Returns an immediate operand for use in SVE predicate constraint
* operands.
*/
opnd_t
opnd_create_immed_pred_constr(dr_pred_constr_type_t p);
#endif
DR_API
INSTR_INLINE
opnd_t
opnd_create_pc(app_pc pc);
DR_API
* Returns a far program address operand with value \p seg_selector:pc.
* \p seg_selector is a segment selector, not a DR_SEG_ constant.
*/
opnd_t
opnd_create_far_pc(ushort seg_selector, app_pc pc);
DR_API
* Returns an operand whose value will be the encoded address of \p
* instr. This operand can be used as an immediate integer or as a
* direct call or jump target. Its size is always #OPSZ_PTR.
*/
opnd_t
opnd_create_instr(instr_t *instr);
DR_API
* Returns an operand whose value will be the encoded address of \p
* instr. This operand can be used as an immediate integer or as a
* direct call or jump target. Its size is the specified \p size.
* Its value can be optionally right-shifted by \p shift from the
* encoded address.
*/
opnd_t
opnd_create_instr_ex(instr_t *instr, opnd_size_t size, ushort shift);
DR_API
* Returns a far instr_t pointer address with value \p seg_selector:instr.
* \p seg_selector is a segment selector, not a DR_SEG_ constant.
*/
opnd_t
opnd_create_far_instr(ushort seg_selector, instr_t *instr);
DR_API
* Returns a memory reference operand whose value will be the encoded
* address of \p instr plus the 16-bit displacement \p disp. For 32-bit
* mode, it will be encoded just like an absolute address
* (opnd_create_abs_addr()); for 64-bit mode, it will be encoded just
* like a pc-relative address (opnd_create_rel_addr()). This operand
* can be used anywhere a regular memory operand can be used. Its
* size is \p data_size.
*
* \note This operand will return false to opnd_is_instr(), opnd_is_rel_addr(),
* and opnd_is_abs_addr(). It is a separate type.
*/
opnd_t
opnd_create_mem_instr(instr_t *instr, short disp, opnd_size_t data_size);
DR_API
* Returns a memory reference operand that refers to the address:
* - disp(base_reg, index_reg, scale)
*
* or, in other words,
* - base_reg + index_reg*scale + disp
*
* The operand has data size data_size (must be a OPSZ_ constant).
* Both \p base_reg and \p index_reg must be DR_REG_ constants.
* \p scale must be either 0, 1, 2, 4, or 8.
* On ARM, opnd_set_index_shift() can be used for further manipulation
* of the index register.
* On ARM, a negative value for \p disp will be converted into a positive
* value with #DR_OPND_NEGATED set in opnd_get_flags().
* On ARM, either \p index_reg must be #DR_REG_NULL or disp must be 0.
*
* Also use this function to create VSIB operands, passing a SIMD register as
* the index register.
*/
opnd_t
opnd_create_base_disp(reg_id_t base_reg, reg_id_t index_reg, int scale, int disp,
opnd_size_t data_size);
DR_API
* Returns a memory reference operand that refers to the address:
* - disp(base_reg, index_reg, scale)
*
* or, in other words,
* - base_reg + index_reg*scale + disp
*
* The operand has data size \p data_size (must be a OPSZ_ constant).
* Both \p base_reg and \p index_reg must be DR_REG_ constants.
* \p scale must be either 0, 1, 2, 4, or 8.
* On ARM, a negative value for \p disp will be converted into a positive
* value with #DR_OPND_NEGATED set in opnd_get_flags().
* On ARM, either \p index_reg must be #DR_REG_NULL or disp must be 0.
*
* On x86, three boolean parameters give control over encoding optimizations
* (these are ignored on other architectures):
* - If \p encode_zero_disp, a zero value for disp will not be omitted;
* - If \p force_full_disp, a small value for disp will not occupy only one byte.
* - If \p disp_short_addr, short (16-bit for 32-bit mode, 32-bit for
* 64-bit mode) addressing will be used (note that this normally only
* needs to be specified for an absolute address; otherwise, simply
* use the desired short registers for base and/or index).
*
* (The encoding optimization flags are all false when using
* opnd_create_base_disp()).
*/
opnd_t
opnd_create_base_disp_ex(reg_id_t base_reg, reg_id_t index_reg, int scale, int disp,
opnd_size_t size, bool encode_zero_disp, bool force_full_disp,
bool disp_short_addr);
DR_API
* Returns a far memory reference operand that refers to the address:
* - seg : disp(base_reg, index_reg, scale)
*
* or, in other words,
* - seg : base_reg + index_reg*scale + disp
*
* The operand has data size \p data_size (must be a OPSZ_ constant).
* \p seg must be a DR_SEG_ constant.
* Both \p base_reg and \p index_reg must be DR_REG_ constants.
* \p scale must be either 0, 1, 2, 4, or 8.
* On ARM, a negative value for \p disp will be converted into a positive
* value with #DR_OPND_NEGATED set in opnd_get_flags().
* On ARM, either \p index_reg must be #DR_REG_NULL or disp must be 0.
*/
opnd_t
opnd_create_far_base_disp(reg_id_t seg, reg_id_t base_reg, reg_id_t index_reg, int scale,
int disp, opnd_size_t data_size);
DR_API
* Returns a far memory reference operand that refers to the address:
* - seg : disp(base_reg, index_reg, scale)
*
* or, in other words,
* - seg : base_reg + index_reg*scale + disp
*
* The operand has data size \p size (must be an OPSZ_ constant).
* \p seg must be a DR_SEG_ constant.
* Both \p base_reg and \p index_reg must be DR_REG_ constants.
* scale must be either 0, 1, 2, 4, or 8.
* On ARM, a negative value for \p disp will be converted into a positive
* value with #DR_OPND_NEGATED set in opnd_get_flags().
* On ARM, either \p index_reg must be #DR_REG_NULL or disp must be 0.
*
* On x86, three boolean parameters give control over encoding optimizations
* (these are ignored on ARM):
* - If \p encode_zero_disp, a zero value for disp will not be omitted;
* - If \p force_full_disp, a small value for disp will not occupy only one byte.
* - If \p disp_short_addr, short (16-bit for 32-bit mode, 32-bit for
* 64-bit mode) addressing will be used (note that this normally only
* needs to be specified for an absolute address; otherwise, simply
* use the desired short registers for base and/or index).
*
* (All of these are false when using opnd_create_far_base_disp()).
*/
opnd_t
opnd_create_far_base_disp_ex(reg_id_t seg, reg_id_t base_reg, reg_id_t index_reg,
int scale, int disp, opnd_size_t size, bool encode_zero_disp,
bool force_full_disp, bool disp_short_addr);
#ifdef ARM
DR_API
* Returns a memory reference operand that refers to either a base
* register plus or minus a constant displacement:
* - [base_reg, disp]
*
* Or a base register plus or minus an optionally shifted index register:
* - [base_reg, index_reg, shift_type, shift_amount]
*
* For an index register, the plus or minus is determined by the presence
* or absence of #DR_OPND_NEGATED in \p flags.
*
* The resulting operand has data size \p size (must be an OPSZ_ constant).
* Both \p base_reg and \p index_reg must be DR_REG_ constants.
* A negative value for \p disp will be converted into a positive
* value with #DR_OPND_NEGATED set in opnd_get_flags().
* Either \p index_reg must be #DR_REG_NULL or disp must be 0.
*
* \note ARM-only.
*/
opnd_t
opnd_create_base_disp_arm(reg_id_t base_reg, reg_id_t index_reg,
dr_shift_type_t shift_type, uint shift_amount, int disp,
dr_opnd_flags_t flags, opnd_size_t size);
#endif
#ifdef AARCH64
DR_API
* Returns the left shift amount from \p size.
*/
uint
opnd_size_to_shift_amount(opnd_size_t size);
DR_API
* Returns a memory reference operand that refers to either a base
* register with a constant displacement:
* - [base_reg, disp]
*
* Or a base register plus an optionally extended and shifted index register:
* - [base_reg, index_reg, extend_type, shift_amount]
*
* If \p scaled is enabled, \p shift determines the shift amount.
*
* The resulting operand has data size \p size (must be an OPSZ_ constant).
* Both \p base_reg and \p index_reg must be DR_REG_ constants.
* Either \p index_reg must be #DR_REG_NULL or disp must be 0.
*
* TODO i#3044: WARNING this function may change during SVE development of
* DynamoRIO. The function will be considered stable when this warning has been
* removed.
*
* \note AArch64-only.
*/
opnd_t
opnd_create_base_disp_shift_aarch64(reg_id_t base_reg, reg_id_t index_reg,
dr_extend_type_t extend_type, bool scaled, int disp,
dr_opnd_flags_t flags, opnd_size_t size, uint shift);
DR_API
* Same as opnd_create_base_disp_shift_aarch64 but if \p scaled is true then the extend
* amount is calculated from the operand size (otherwise it is zero).
*
* \note AArch64-only.
*/
opnd_t
opnd_create_base_disp_aarch64(reg_id_t base_reg, reg_id_t index_reg,
dr_extend_type_t extend_type, bool scaled, int disp,
dr_opnd_flags_t flags, opnd_size_t size);
DR_API
* Same as opnd_create_base_disp_shift_aarch64 but creates an operand that uses vector
* registers for the base and/or index.
* At least one of \p base_reg and \p index_reg should be a vector register.
* \p element_size indicates the element size for any vector registers used and must be
* one of:
* OPSZ_4 (single, 32-bit)
* OPSZ_8 (double, 64-bit)
*
* TODO i#3044: WARNING this function may change during SVE development of
* DynamoRIO. The function will be considered stable when this warning has been
* removed.
*
* \note AArch64-only.
*/
opnd_t
opnd_create_vector_base_disp_aarch64(reg_id_t base_reg, reg_id_t index_reg,
opnd_size_t element_size,
dr_extend_type_t extend_type, bool scaled, int disp,
dr_opnd_flags_t flags, opnd_size_t size, uint shift);
#endif
DR_API
* Returns a memory reference operand that refers to the address \p addr.
* The operand has data size \p data_size (must be a OPSZ_ constant).
*
* If \p addr <= 2^32 (which is always true in 32-bit mode), this routine
* is equivalent to
* opnd_create_base_disp(DR_REG_NULL, DR_REG_NULL, 0, (int)addr, data_size).
*
* Otherwise, this routine creates a separate operand type with an
* absolute 64-bit memory address. Such an operand can only be
* guaranteed to be encodable in absolute form as a load or store from
* or to the rax (or eax) register. It will automatically be
* converted to a pc-relative operand (as though
* opnd_create_rel_addr() had been called) if it is used in any other
* way.
*/
opnd_t
opnd_create_abs_addr(void *addr, opnd_size_t data_size);
DR_API
* Returns a memory reference operand that refers to the address
* \p seg: \p addr.
* The operand has data size \p data_size (must be a OPSZ_ constant).
*
* If \p addr <= 2^32 (which is always true in 32-bit mode), this routine
* is equivalent to
* opnd_create_far_base_disp(seg, DR_REG_NULL, DR_REG_NULL, 0, (int)addr, data_size).
*
* Otherwise, this routine creates a separate operand type with an
* absolute 64-bit memory address. Such an operand can only be
* guaranteed to be encodable in absolute form as a load or store from
* or to the rax (or eax) register. It will automatically be
* converted to a pc-relative operand (as though
* opnd_create_far_rel_addr() had been called) if it is used in any
* other way.
*/
opnd_t
opnd_create_far_abs_addr(reg_id_t seg, void *addr, opnd_size_t data_size);
#if defined(X64) || defined(ARM)
DR_API
* Returns a memory reference operand that refers to the address \p
* addr, but will be encoded as a pc-relative address. At emit time,
* if \p addr is out of reach of the maximum encodable displacement
* (signed 32-bit for x86) from the next instruction, encoding will
* fail.
*
* DR guarantees that all of its code caches, all client libraries and
* Extensions (though not copies of system libraries), and all client
* memory allocated through dr_thread_alloc(), dr_global_alloc(),
* dr_nonheap_alloc(), or dr_custom_alloc() with
* #DR_ALLOC_CACHE_REACHABLE, can reach each other with a 32-bit
* displacement. Thus, any normally-allocated data or any static data
* or code in a client library is guaranteed to be reachable from code
* cache code. Memory allocated through system libraries (including
* malloc, operator new, and HeapAlloc) is not guaranteed to be
* reachable: only memory directly allocated via DR's API. The
* runtime option -reachable_heap can be used to guarantee that
* all memory is reachable.
*
* On x86, if \p addr is not pc-reachable at encoding time and this
* operand is used in a load or store to or from the rax (or eax)
* register, an absolute form will be used (as though
* opnd_create_abs_addr() had been called).
*
* The operand has data size data_size (must be a OPSZ_ constant).
*
* To represent a 32-bit address (i.e., what an address size prefix
* indicates), simply zero out the top 32 bits of the address before
* passing it to this routine.
*
* On ARM, the resulting operand will not contain an explicit PC
* register, and thus will not return true on queries to whether the
* operand reads the PC. Explicit use of opnd_is_rel_addr() is
* required. However, DR does not decode any PC-using instructions
* into this type of relative address operand: decoding will always
* produce a regular base + displacement operand.
*
* \note For ARM or 64-bit X86 DR builds only.
*/
opnd_t
opnd_create_rel_addr(void *addr, opnd_size_t data_size);
DR_API
* Returns a memory reference operand that refers to the address \p
* seg : \p addr, but will be encoded as a pc-relative address. It is
* up to the caller to ensure that the resulting address is reachable
* via a 32-bit signed displacement from the next instruction at emit
* time.
*
* DR guarantees that all of its code caches, all client libraries and
* Extensions (though not copies of system libraries), and all client
* memory allocated through dr_thread_alloc(), dr_global_alloc(),
* dr_nonheap_alloc(), or dr_custom_alloc() with
* #DR_ALLOC_CACHE_REACHABLE, can reach each other with a 32-bit
* displacement. Thus, any normally-allocated data or any static data
* or code in a client library is guaranteed to be reachable from code
* cache code. Memory allocated through system libraries (including
* malloc, operator new, and HeapAlloc) is not guaranteed to be
* reachable: only memory directly allocated via DR's API. The
* runtime option -reachable_heap can be used to guarantee that
* all memory is reachable.
*
* If \p addr is not pc-reachable at encoding time and this operand is
* used in a load or store to or from the rax (or eax) register, an
* absolute form will be used (as though opnd_create_far_abs_addr()
* had been called).
*
* The operand has data size \p data_size (must be a OPSZ_ constant).
*
* To represent a 32-bit address (i.e., what an address size prefix
* indicates), simply zero out the top 32 bits of the address before
* passing it to this routine.
*
* \note For 64-bit X86 DR builds only.
*/
opnd_t
opnd_create_far_rel_addr(reg_id_t seg, void *addr, opnd_size_t data_size);
#endif
DR_API
bool
opnd_is_null(opnd_t opnd);
DR_API
bool
opnd_is_reg(opnd_t opnd);
DR_API
bool
opnd_is_reg_partial(opnd_t opnd);
DR_API
INSTR_INLINE
bool
opnd_is_immed(opnd_t opnd);
DR_API
bool
opnd_is_immed_int(opnd_t opnd);
DR_API
* Returns true iff \p opnd is a special 64-bit immediate integer operand
* on a 32-bit architecture.
*/
bool
opnd_is_immed_int64(opnd_t opnd);
DR_API
bool
opnd_is_immed_float(opnd_t opnd);
DR_API
INSTR_INLINE
bool
opnd_is_pc(opnd_t opnd);
DR_API
bool
opnd_is_near_pc(opnd_t opnd);
DR_API
bool
opnd_is_far_pc(opnd_t opnd);
DR_API
INSTR_INLINE
bool
opnd_is_instr(opnd_t opnd);
DR_API
bool
opnd_is_near_instr(opnd_t opnd);
DR_API
bool
opnd_is_far_instr(opnd_t opnd);
DR_API
bool
opnd_is_mem_instr(opnd_t opnd);
DR_API
bool
opnd_is_base_disp(opnd_t opnd);
DR_API
INSTR_INLINE
* Returns true iff \p opnd is a near (i.e., default segment) base+disp memory
* reference operand.
*/
bool
opnd_is_near_base_disp(opnd_t opnd);
DR_API
INSTR_INLINE
bool
opnd_is_far_base_disp(opnd_t opnd);
DR_API
INSTR_INLINE
bool
opnd_is_element_vector_reg(opnd_t opnd);
DR_API
INSTR_INLINE
bool
opnd_is_predicate_reg(opnd_t opnd);
DR_API
INSTR_INLINE
bool
opnd_is_predicate_merge(opnd_t opnd);
DR_API
INSTR_INLINE
bool
opnd_is_predicate_zero(opnd_t opnd);
DR_API
* Returns true iff \p opnd uses vector indexing via a VSIB byte. This
* memory addressing form was introduced in Intel AVX2.
*/
bool
opnd_is_vsib(opnd_t opnd);
DR_API
* Returns true iff \p opnd is a (near or far) absolute address operand.
* Returns true for both base-disp operands with no base or index and
* 64-bit non-base-disp absolute address operands.
*/
bool
opnd_is_abs_addr(opnd_t opnd);
DR_API
* Returns true iff \p opnd is a near (i.e., default segment) absolute address operand.
* Returns true for both base-disp operands with no base or index and
* 64-bit non-base-disp absolute address operands.
*/
bool
opnd_is_near_abs_addr(opnd_t opnd);
DR_API
* Returns true iff \p opnd is a far absolute address operand.
* Returns true for both base-disp operands with no base or index and
* 64-bit non-base-disp absolute address operands.
*/
bool
opnd_is_far_abs_addr(opnd_t opnd);
#if defined(X64) || defined(ARM)
DR_API
* Returns true iff \p opnd is a (near or far) pc-relative memory reference operand.
* Returns true for base-disp operands on ARM that use the PC as the base register.
*/
bool
opnd_is_rel_addr(opnd_t opnd);
DR_API
INSTR_INLINE
* Returns true iff \p opnd is a near (i.e., default segment) pc-relative memory
* reference operand.
*
* \note For 64-bit x86 DR builds only. Equivalent to opnd_is_rel_addr() for ARM.
*/
bool
opnd_is_near_rel_addr(opnd_t opnd);
DR_API
INSTR_INLINE
* Returns true iff \p opnd is a far pc-relative memory reference operand.
*
* \note For 64-bit x86 DR builds only. Always returns false on ARM.
*/
bool
opnd_is_far_rel_addr(opnd_t opnd);
#endif
DR_API
* Returns true iff \p opnd is a (near or far) memory reference operand
* of any type: base-disp, absolute address, or pc-relative address.
*
* This routine (along with all other opnd_ routines) does consider
* multi-byte nops that use addressing operands, or the #OP_lea
* instruction's source operand, to be memory references: i.e., it
* only considers whether the operand calculates an address. Use
* instr_reads_memory() to operate on a higher semantic level and rule
* out these corner cases.
*/
bool
opnd_is_memory_reference(opnd_t opnd);
DR_API
* Returns true iff \p opnd is a far memory reference operand
* of any type: base-disp, absolute address, or pc-relative address.
*/
bool
opnd_is_far_memory_reference(opnd_t opnd);
DR_API
* Returns true iff \p opnd is a near memory reference operand
* of any type: base-disp, absolute address, or pc-relative address.
*/
bool
opnd_is_near_memory_reference(opnd_t opnd);
DR_API
* Return the data size of \p opnd as a OPSZ_ constant.
* Returns OPSZ_NA if \p opnd does not have a valid size.
* \note A register operand may have a size smaller than the full size
* of its DR_REG_* register specifier.
*/
opnd_size_t
opnd_get_size(opnd_t opnd);
DR_API
* Sets the data size of \p opnd.
* Assumes \p opnd is an immediate integer, a memory reference,
* or an instr_t pointer address operand.
*/
void
opnd_set_size(opnd_t *opnd, opnd_size_t newsize);
DR_API
* Return the element size of \p opnd as a OPSZ_ constant.
* Returns #OPSZ_NA if \p opnd does not have a valid size.
*/
opnd_size_t
opnd_get_vector_element_size(opnd_t opnd);
DR_API
* Assumes \p opnd is a register operand.
* Returns the register it refers to (a DR_REG_ constant).
*/
reg_id_t
opnd_get_reg(opnd_t opnd);
DR_API
* Assumes \p opnd is a register operand, base+disp memory reference, or
* an immediate integer.
* Returns the flags describing additional properties of the register,
* the index register or displacement component of the memory reference,
* or the immediate operand \p opnd.
*/
dr_opnd_flags_t
opnd_get_flags(opnd_t opnd);
DR_API
* Assumes \p opnd is a register operand, base+disp memory reference, or
* an immediate integer.
* Sets the flags describing additional properties of the operand to \p flags.
*/
void
opnd_set_flags(opnd_t *opnd, dr_opnd_flags_t flags);
DR_API
* Assumes \p opnd is a register operand, base+disp memory reference, or
* an immediate integer.
* Sets the flags describing additional properties of the operand to
* be the current flags plus the \p flags parameter and returns the
* new operand value.
*/
opnd_t
opnd_add_flags(opnd_t opnd, dr_opnd_flags_t flags);
DR_API
ptr_int_t
opnd_get_immed_int(opnd_t opnd);
DR_API
* Assumes opnd is an immediate integer with DR_OPND_MULTI_PART set.
* Returns its value.
* \note 32-bit only.
*/
int64
opnd_get_immed_int64(opnd_t opnd);
DR_API
* Assumes \p opnd is an immediate float and returns its value.
* The caller's code should use proc_save_fpstate() or be inside a
* clean call that has requested to preserve the floating-point state.
*/
float
opnd_get_immed_float(opnd_t opnd);
#ifndef WINDOWS
* Type double currently not included for Windows because sizeof(opnd_t) does
* not equal EXPECTED_SIZEOF_OPND, triggering the ASSERT in d_r_arch_init().
*/
DR_API
* Assumes \p opnd is an immediate double and returns its value.
* The caller's code should use proc_save_fpstate() or be inside a
* clean call that has requested to preserve the floating-point state.
*/
double
opnd_get_immed_double(opnd_t opnd);
#endif
DR_API
app_pc
opnd_get_pc(opnd_t opnd);
DR_API
* Assumes \p opnd is a far program address.
* Returns \p opnd's segment, a segment selector (not a DR_SEG_ constant).
*/
ushort
opnd_get_segment_selector(opnd_t opnd);
DR_API
instr_t *
opnd_get_instr(opnd_t opnd);
DR_API
ushort
opnd_get_shift(opnd_t opnd);
DR_API
* Assumes \p opnd is a memory instr operand. Returns its displacement.
*/
short
opnd_get_mem_instr_disp(opnd_t opnd);
DR_API
* Assumes \p opnd is a (near or far) base+disp memory reference. Returns the base
* register (a DR_REG_ constant).
*/
reg_id_t
opnd_get_base(opnd_t opnd);
DR_API
* Assumes \p opnd is a (near or far) base+disp memory reference.
* Returns the displacement.
* On ARM, the displacement is always a non-negative value, and the
* presence or absence of #DR_OPND_NEGATED in opnd_get_flags()
* determines whether to add or subtract from the base register.
*/
int
opnd_get_disp(opnd_t opnd);
DR_API
* Assumes \p opnd is a (near or far) base+disp memory reference; returns whether
* encode_zero_disp has been specified for \p opnd.
*/
bool
opnd_is_disp_encode_zero(opnd_t opnd);
DR_API
* Assumes \p opnd is a (near or far) base+disp memory reference; returns whether
* force_full_disp has been specified for \p opnd.
*/
bool
opnd_is_disp_force_full(opnd_t opnd);
DR_API
* Assumes \p opnd is a (near or far) base+disp memory reference; returns whether
* disp_short_addr has been specified for \p opnd.
*/
bool
opnd_is_disp_short_addr(opnd_t opnd);
DR_API
* Assumes \p opnd is a (near or far) base+disp memory reference.
* Returns the index register (a DR_REG_ constant).
*/
reg_id_t
opnd_get_index(opnd_t opnd);
DR_API
* Assumes \p opnd is a (near or far) base+disp memory reference. Returns the scale.
* \note x86-only. On ARM use opnd_get_index_shift().
*/
int
opnd_get_scale(opnd_t opnd);
DR_API
* Assumes \p opnd is a (near or far) memory reference of any type.
* Returns \p opnd's segment (a DR_SEG_ constant), or DR_REG_NULL if it is a near
* memory reference.
*/
reg_id_t
opnd_get_segment(opnd_t opnd);
#ifdef ARM
DR_API
* Assumes \p opnd is a (near or far) base+disp memory reference.
* Returns DR_SHIFT_NONE if the index register is not shifted.
* Returns the shift type and \p amount if the index register is shifted (this
* shift will occur prior to being added to or subtracted from the base
* register).
* \note ARM-only.
*/
dr_shift_type_t
opnd_get_index_shift(opnd_t opnd, uint *amount OUT);
DR_API
* Assumes \p opnd is a near base+disp memory reference.
* Sets the index register to be shifted by \p amount according to \p shift.
* Returns whether successful.
* If the shift amount is out of allowed ranges, returns false.
* \note ARM-only.
*/
bool
opnd_set_index_shift(opnd_t *opnd, dr_shift_type_t shift, uint amount);
#endif
#ifdef AARCH64
DR_API
* Assumes \p opnd is a base+disp memory reference.
* Returns the extension type, whether the offset is \p scaled, and the shift \p amount.
* The register offset will be extended, then shifted, then added to the base register.
* If there is no extension and no shift the values returned will be #DR_EXTEND_UXTX,
* false, and zero.
* \note AArch64-only.
*/
dr_extend_type_t
opnd_get_index_extend(opnd_t opnd, OUT bool *scaled, OUT uint *amount);
DR_API
* Assumes \p opnd is a base+disp memory reference.
* Sets the index register to be extended by \p extend and optionally \p scaled.
* Returns whether successful. If \p scaled is zero, the offset is not scaled.
* \note AArch64-only.
*/
bool
opnd_set_index_extend_value(opnd_t *opnd, dr_extend_type_t extend, bool scaled,
uint scaled_value);
DR_API
* Assumes \p opnd is a base+disp memory reference.
* Sets the index register to be extended by \p extend and optionally \p scaled.
* Returns whether successful. If \p scaled is zero, the offset is not scaled; otherwise
* is calculated from the operand size.
* \note AArch64-only.
*/
bool
opnd_set_index_extend(opnd_t *opnd, dr_extend_type_t extend, bool scaled);
#endif
DR_API
* Assumes \p opnd is a (near or far) absolute or pc-relative memory reference,
* or a base+disp memory reference with no base or index register.
* Returns \p opnd's absolute address (which will be pc-relativized on encoding
* for pc-relative memory references).
*/
void *
opnd_get_addr(opnd_t opnd);
DR_API
* Returns the number of registers referred to by \p opnd. This will only
* be non-zero for register operands and memory references.
*/
int
opnd_num_regs_used(opnd_t opnd);
DR_API
* Used in conjunction with opnd_num_regs_used(), this routine can be used
* to iterate through all registers used by \p opnd.
* The index values begin with 0 and proceed through opnd_num_regs_used(opnd)-1.
*/
reg_id_t
opnd_get_reg_used(opnd_t opnd, int index);
DR_API
* Assumes that \p reg is a DR_REG_ 32-bit register constant.
* Returns the string name for \p reg.
*/
const char *
get_register_name(reg_id_t reg);
DR_API
* Assumes that \p reg is a DR_REG_ 32-bit register constant.
* Returns the 16-bit version of \p reg.
* \note x86-only.
*/
reg_id_t
reg_32_to_16(reg_id_t reg);
DR_API
* Assumes that \p reg is a DR_REG_ 32-bit register constant.
* Returns the 8-bit version of \p reg (the least significant byte:
* DR_REG_AL instead of DR_REG_AH if passed DR_REG_EAX, e.g.). For 32-bit DR
* builds, returns DR_REG_NULL if passed DR_REG_ESP, DR_REG_EBP, DR_REG_ESI, or
* DR_REG_EDI.
* \note x86-only.
*/
reg_id_t
reg_32_to_8(reg_id_t reg);
#ifdef X64
DR_API
* Assumes that \p reg is a DR_REG_ 32-bit register constant.
* Returns the 64-bit version of \p reg.
*
* \note For 64-bit DR builds only.
*/
reg_id_t
reg_32_to_64(reg_id_t reg);
DR_API
* Assumes that \p reg is a DR_REG_ 64-bit register constant.
* Returns the 32-bit version of \p reg.
*
* \note For 64-bit DR builds only.
*/
reg_id_t
reg_64_to_32(reg_id_t reg);
DR_API
* Returns true iff \p reg refers to an extended register only available in 64-bit
* mode and not in 32-bit mode. For AVX-512, it also returns true for the upper 8
* SIMD registers (e.g., R8-R15, XMM8-XMM15, XMM24-XMM31, ZMM24-ZMM31 etc.)
*
* \note For 64-bit DR builds only.
*/
bool
reg_is_extended(reg_id_t reg);
DR_API
* Returns true iff \p reg refers to an extended AVX-512 register only available
* in 64-bit mode and not in 32-bit mode (e.g., XMM16-XMM31, ZMM16-ZMM31 etc.)
*
* \note For 64-bit DR builds only.
*/
bool
reg_is_avx512_extended(reg_id_t reg);
#endif
DR_API
* Assumes that \p reg is a DR_REG_ 32-bit register constant.
* If \p sz == OPSZ_2, returns the 16-bit version of \p reg.
* For 64-bit versions of this library, if \p sz == OPSZ_8, returns
* the 64-bit version of \p reg.
* Returns \p DR_REG_NULL when trying to get the 8-bit subregister of \p
* DR_REG_ESI, \p DR_REG_EDI, \p DR_REG_EBP, or \p DR_REG_ESP in 32-bit mode.
*
* \deprecated Prefer reg_resize_to_opsz() which is more general.
*/
reg_id_t
reg_32_to_opsz(reg_id_t reg, opnd_size_t sz);
DR_API
* Given a general-purpose or SIMD register of any size, returns a register in the same
* class of the given size.
*
* For example, given \p DR_REG_AX or \p DR_REG_RAX and \p OPSZ_1, this routine will
* return \p DR_REG_AL. Given \p DR_REG_XMM0 and \p OPSZ_64, it will return \p
* DR_REG_ZMM0.
*
* Returns \p DR_REG_NULL when trying to get the 8-bit subregister of \p
* DR_REG_ESI, \p DR_REG_EDI, \p DR_REG_EBP, or \p DR_REG_ESP in 32-bit mode.
* For 64-bit versions of this library, if \p sz == OPSZ_8, returns the 64-bit
* version of \p reg.
*
* MMX registers are not yet supported.
* Moreover, ARM is not yet supported for resizing SIMD registers.
*/
reg_id_t
reg_resize_to_opsz(reg_id_t reg, opnd_size_t sz);
DR_API
* Assumes that \p reg is a DR_REG_ register constant.
* If reg is used as part of the calling convention, returns which
* parameter ordinal it matches (0-based); otherwise, returns -1.
*/
int
reg_parameter_num(reg_id_t reg);
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns true iff it refers to a General Purpose Register,
* i.e., rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, or a subset.
*/
bool
reg_is_gpr(reg_id_t reg);
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns true iff it refers to a segment (i.e., it's really a DR_SEG_
* constant).
*/
bool
reg_is_segment(reg_id_t reg);
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns true iff it refers to a multimedia register used for
* SIMD instructions.
*/
bool
reg_is_simd(reg_id_t reg);
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns true iff it refers to an SSE or AVX register.
* In particular, the register must be either an xmm, ymm, or
* zmm for the function to return true.
*
* This function is subject to include any future vector register
* that x86 may add.
*/
bool
reg_is_vector_simd(reg_id_t reg);
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns true iff it refers to an xmm (128-bit SSE/SSE2) x86 register
* or a ymm (256-bit multimedia) register.
* \deprecated Prefer reg_is_strictly_xmm() || reg_is_strictly_ymm().
*/
bool
reg_is_xmm(reg_id_t reg);
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns true iff it refers to an xmm (128-bit SSE/SSE2) x86 register.
*/
bool
reg_is_strictly_xmm(reg_id_t reg);
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns true iff it refers to a ymm (256-bit multimedia) x86 register.
* \deprecated Prefer reg_is_strictly_ymm().
*/
bool
reg_is_ymm(reg_id_t reg);
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns true iff it refers to a ymm (256-bit multimedia) x86 register.
*/
bool
reg_is_strictly_ymm(reg_id_t reg);
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns true iff it refers to a zmm (512-bit multimedia) x86 register.
*/
bool
reg_is_strictly_zmm(reg_id_t reg);
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns true iff it refers to an opmask x86 register.
*/
bool
reg_is_opmask(reg_id_t reg);
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns true iff it refers to an x86 MPX bounds register.
*/
bool
reg_is_bnd(reg_id_t reg);
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns true iff it refers to an mmx (64-bit) register.
*/
bool
reg_is_mmx(reg_id_t reg);
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns true iff it refers to a floating-point register.
*/
bool
reg_is_fp(reg_id_t reg);
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns true iff it refers to a 32-bit general-purpose register.
*/
bool
reg_is_32bit(reg_id_t reg);
#if defined(AARCH64)
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns true iff it refers to a Z (SVE scalable vector) register.
*/
bool
reg_is_z(reg_id_t reg);
#endif
DR_API
* Returns true iff \p opnd is a register operand that refers to a 32-bit
* general-purpose register.
*/
bool
opnd_is_reg_32bit(opnd_t opnd);
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns true iff it refers to a 64-bit general-purpose register.
*/
bool
reg_is_64bit(reg_id_t reg);
DR_API
* Returns true iff \p opnd is a register operand that refers to a 64-bit
* general-purpose register.
*/
bool
opnd_is_reg_64bit(opnd_t opnd);
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns true iff it refers to a pointer-sized general-purpose register.
*/
bool
reg_is_pointer_sized(reg_id_t reg);
DR_API
* Assumes that \p reg is a DR_REG_ 32-bit register constant.
* Returns the pointer-sized version of \p reg.
*/
reg_id_t
reg_to_pointer_sized(reg_id_t reg);
DR_API
* Returns true iff \p opnd is a register operand that refers to a
* pointer-sized general-purpose register.
*/
bool
opnd_is_reg_pointer_sized(opnd_t opnd);
DR_API
* Assumes that \p r1 and \p r2 are both DR_REG_ constants.
* Returns true iff \p r1's register overlaps \p r2's register
* (e.g., if \p r1 == DR_REG_AX and \p r2 == DR_REG_EAX).
*/
bool
reg_overlap(reg_id_t r1, reg_id_t r2);
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns \p reg's representation as 3 bits in a modrm byte
* (the 3 bits are the lower-order bits in the return value).
*/
byte
reg_get_bits(reg_id_t reg);
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns the OPSZ_ constant corresponding to the register size.
* Returns OPSZ_NA if reg is not a DR_REG_ constant.
*/
opnd_size_t
reg_get_size(reg_id_t reg);
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns true iff \p opnd refers to reg directly or refers to a register
* that overlaps \p reg (e.g., DR_REG_AX overlaps DR_REG_EAX).
*/
bool
opnd_uses_reg(opnd_t opnd, reg_id_t reg);
DR_API
* Set the displacement of a memory reference operand \p opnd to \p disp.
* On ARM, a negative value for \p disp will be converted into a positive
* value with #DR_OPND_NEGATED set in opnd_get_flags().
*/
void
opnd_set_disp(opnd_t *opnd, int disp);
#ifdef X86
DR_API
* Set the displacement and the encoding controls of a memory
* reference operand:
* - If \p encode_zero_disp, a zero value for \p disp will not be omitted;
* - If \p force_full_disp, a small value for \p disp will not occupy only one byte.
* - If \p disp_short_addr, short (16-bit for 32-bit mode, 32-bit for
* 64-bit mode) addressing will be used (note that this normally only
* needs to be specified for an absolute address; otherwise, simply
* use the desired short registers for base and/or index).
* \note x86-only.
*/
void
opnd_set_disp_ex(opnd_t *opnd, int disp, bool encode_zero_disp, bool force_full_disp,
bool disp_short_addr);
#endif
DR_API
* Assumes that both \p old_reg and \p new_reg are DR_REG_ constants.
* Replaces all occurrences of \p old_reg in \p *opnd with \p new_reg.
* Only replaces exact matches (use opnd_replace_reg_resize() to match
* size variants).
* Returns whether it replaced anything.
*/
bool
opnd_replace_reg(opnd_t *opnd, reg_id_t old_reg, reg_id_t new_reg);
DR_API
* Creates a reg incremented from an existing \p opnd by the \p increment value,
* modulo the reg size.
* Returns the new reg.
*/
opnd_t
opnd_create_increment_reg(opnd_t opnd, uint increment);
DR_API
* Replaces all instances of \p old_reg (or any size variant) in \p *opnd
* with \p new_reg. Resizes \p new_reg to match sub-full-size uses of \p old_reg.
* Returns whether it replaced anything.
*/
bool
opnd_replace_reg_resize(opnd_t *opnd, reg_id_t old_reg, reg_id_t new_reg);
bool
opnd_same_sizes_ok(opnd_size_t s1, opnd_size_t s2, bool is_reg);
DR_API
* If either uses variable operand sizes, the default size is assumed.
*/
bool
opnd_same(opnd_t op1, opnd_t op2);
DR_API
* Returns true iff \p op1 and \p op2 are both memory references and they
* are indistinguishable, ignoring data size.
*/
bool
opnd_same_address(opnd_t op1, opnd_t op2);
DR_API
* Returns true iff there exists some register that is referred to (directly
* or overlapping) by both \p op1 and \p op2.
*/
bool
opnd_share_reg(opnd_t op1, opnd_t op2);
DR_API
* Returns true iff \p def, considered as a write, affects \p use.
* Is conservative, so if both \p def and \p use are memory references,
* will return true unless it can disambiguate them based on their
* registers and displacement.
*/
bool
opnd_defines_use(opnd_t def, opnd_t use);
DR_API
* Assumes \p size is an OPSZ_ constant, typically obtained from
* opnd_get_size() or reg_get_size().
* Returns the number of bytes the OPSZ_ constant represents.
* If OPSZ_ is a variable-sized size, returns the default size,
* which may or may not match the actual size decided up on at
* encoding time (that final size depends on other operands).
*/
uint
opnd_size_in_bytes(opnd_size_t size);
DR_API
* Assumes \p size is an OPSZ_ constant, typically obtained from
* opnd_get_size() or reg_get_size().
* Returns the number of bits the OPSZ_ constant represents.
* If OPSZ_ is a variable-sized size, returns the default size,
* which may or may not match the actual size decided up on at
* encoding time (that final size depends on other operands).
*/
uint
opnd_size_in_bits(opnd_size_t size);
DR_API
* Returns the appropriate OPSZ_ constant for the given number of bytes.
* Returns OPSZ_NA if there is no such constant.
* The intended use case is something like "opnd_size_in_bytes(sizeof(foo))" for
* integer/pointer types. This routine returns simple single-size
* types and will not return complex/variable size types.
*/
opnd_size_t
opnd_size_from_bytes(uint bytes);
DR_API
* Shrinks all 32-bit registers in \p opnd to their 16-bit versions.
* Also shrinks the size of immediate integers and memory references from
* OPSZ_4 to OPSZ_2.
*/
opnd_t
opnd_shrink_to_16_bits(opnd_t opnd);
#ifdef X64
DR_API
* Shrinks all 64-bit registers in \p opnd to their 32-bit versions.
* Also shrinks the size of immediate integers and memory references from
* OPSZ_8 to OPSZ_4.
*
* \note For 64-bit DR builds only.
*/
opnd_t
opnd_shrink_to_32_bits(opnd_t opnd);
#endif
DR_API
* Returns the value of the register \p reg, selected from the passed-in
* register values. Supports only general-purpose registers.
* \p mc->flags must include DR_MC_CONTROL and DR_MC_INTEGER.
*/
reg_t
reg_get_value(reg_id_t reg, dr_mcontext_t *mc);
DR_API
* Returns the value of the register \p reg as stored in \p mc, or
* for an mmx register as stored in the physical register.
* Up to sizeof(dr_zmm_t) bytes will be written to \p val.
*
* This routine also supports reading AVX-512 mask registers. In this
* case, sizeof(dr_opmask_t) bytes will be written to \p val.
*
* This routine does not support floating-point registers.
*
*
* \note \p mc->flags must include the appropriate flag for the
* requested register.
*/
bool
reg_get_value_ex(reg_id_t reg, dr_mcontext_t *mc, OUT byte *val);
DR_API
* Sets the register \p reg in the passed in mcontext \p mc to \p value.
* \p mc->flags must include DR_MC_CONTROL and DR_MC_INTEGER.
* \note This function is limited to setting pointer-sized registers only
* (no sub-registers, and no non-general-purpose registers).
* See \p reg_set_value_ex for setting other register values.
*/
void
reg_set_value(reg_id_t reg, dr_mcontext_t *mc, reg_t value);
DR_API
* Sets the register \p reg in the passed in mcontext \p mc to the value
* stored in the buffer \p val_buf.
*
* \p mc->flags must include DR_MC_CONTROL and DR_MC_INTEGER.
*
* Unlike \p reg_set_value, this function supports not only general purpose
* registers, but SIMD registers too. Does not yet support MMX registers.
*
* Up to sizeof(dr_zmm_t) bytes will be read from \p val_buf. It is up
* to the user to ensure correct buffer size.
*
* Returns false if the register is not supported.
*/
bool
reg_set_value_ex(reg_id_t reg, dr_mcontext_t *mc, IN byte *val_buf);
DR_API
* Returns the effective address of \p opnd, computed using the passed-in
* register values. If \p opnd is a far address, ignores that aspect
* except for TLS references on Windows (fs: for 32-bit, gs: for 64-bit)
* or typical fs: or gs: references on Linux. For far addresses the
* calling thread's segment selector is used.
* \p mc->flags must include DR_MC_CONTROL and DR_MC_INTEGER.
*
* \note This routine does not support vector addressing (via VSIB,
* introduced in AVX2). Use instr_compute_address(),
* instr_compute_address_ex(), or instr_compute_address_ex_pos()
* instead.
*/
app_pc
opnd_compute_address(opnd_t opnd, dr_mcontext_t *mc);
DR_API
* Assumes that \p reg is a DR_REG_ constant.
* Returns true iff \p reg is stolen by DynamoRIO for internal use.
*
* \note The register stolen by DynamoRIO may not be used by the client
* for instrumentation. Use dr_insert_get_stolen_reg() and
* dr_insert_set_stolen_reg() to get and set the application value of
* the stolen register in the instrumentation.
* Reference \ref sec_reg_stolen for more information.
*/
bool
reg_is_stolen(reg_id_t reg);
#endif