Commit 7914be3c authored by Alexandre Julliard's avatar Alexandre Julliard

zydis: Import upstream release 4.1.0.

With headers from Zycore version 1.5.0.
parent da627905
The MIT License (MIT)
Copyright (c) 2014-2021 Florian Bernd
Copyright (c) 2014-2021 Joel Höner
Copyright (c) 2014-2024 Florian Bernd
Copyright (c) 2014-2024 Joel Höner
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......@@ -20,4 +20,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
......@@ -97,10 +97,13 @@
#elif defined(__FreeBSD__)
# define ZYAN_FREEBSD
# define ZYAN_POSIX
#elif defined(__NetBSD__)
# define ZYAN_NETBSD
# define ZYAN_POSIX
#elif defined(sun) || defined(__sun)
# define ZYAN_SOLARIS
# define ZYAN_POSIX
#elif defined(__unix)
#elif defined(__unix) || defined(__unix__)
# define ZYAN_UNIX
# define ZYAN_POSIX
#elif defined(__posix)
......@@ -136,6 +139,8 @@
# define ZYAN_ARM
#elif defined(__EMSCRIPTEN__) || defined(__wasm__) || defined(__WASM__)
# define ZYAN_WASM
#elif defined(__loongarch__)
# define ZYAN_LOONGARCH
#elif defined(__powerpc64__)
# define ZYAN_PPC64
#elif defined(__powerpc__)
......@@ -474,6 +479,20 @@
*/
#define ZYAN_ALIGN_DOWN(x, align) (((x) - 1) & ~((align) - 1))
/**
* Divide the 64bit integer value by the given divisor.
*
* @param n Variable containing the dividend that will be updated with the result of the
* division.
* @param divisor The divisor.
*/
#if defined(ZYAN_LINUX) && defined(ZYAN_KERNEL)
# include <asm/div64.h> /* do_div */
# define ZYAN_DIV64(n, divisor) do_div(n, divisor)
#else
# define ZYAN_DIV64(n, divisor) (n /= divisor)
#endif
/* ---------------------------------------------------------------------------------------------- */
/* Bit operations */
/* ---------------------------------------------------------------------------------------------- */
......
......@@ -99,6 +99,7 @@ typedef FILE ZyanFile;
#include <stdlib.h>
#define ZYAN_CALLOC calloc
#define ZYAN_FREE free
#define ZYAN_GETENV getenv
#define ZYAN_MALLOC malloc
#define ZYAN_REALLOC realloc
......
......@@ -62,19 +62,83 @@
typedef ZyanI32 ZyanIPointer;
# endif
# elif defined(ZYAN_GNUC)
# ifdef __UINT8_TYPE__
typedef __UINT8_TYPE__ ZyanU8;
# else
typedef unsigned char ZyanU8;
# endif
# ifdef __UINT16_TYPE__
typedef __UINT16_TYPE__ ZyanU16;
# else
typedef unsigned short int ZyanU16;
# endif
# ifdef __UINT32_TYPE__
typedef __UINT32_TYPE__ ZyanU32;
# else
typedef unsigned int ZyanU32;
# endif
# ifdef __UINT64_TYPE__
typedef __UINT64_TYPE__ ZyanU64;
# else
# if defined(__x86_64__) && !defined(__ILP32__)
typedef unsigned long int ZyanU64;
# else
typedef unsigned long long int ZyanU64;
# endif
# endif
# ifdef __INT8_TYPE__
typedef __INT8_TYPE__ ZyanI8;
# else
typedef signed char ZyanI8;
# endif
# ifdef __INT16_TYPE__
typedef __INT16_TYPE__ ZyanI16;
# else
typedef signed short int ZyanI16;
# endif
# ifdef __INT32_TYPE__
typedef __INT32_TYPE__ ZyanI32;
# else
typedef signed int ZyanI32;
# endif
# ifdef __INT64_TYPE__
typedef __INT64_TYPE__ ZyanI64;
# else
# if defined(__x86_64__) && !defined( __ILP32__)
typedef signed long int ZyanI64;
# else
typedef signed long long int ZyanI64;
# endif
# endif
# ifdef __SIZE_TYPE__
typedef __SIZE_TYPE__ ZyanUSize;
# else
typedef long unsigned int ZyanUSize;
# endif
# ifdef __PTRDIFF_TYPE__
typedef __PTRDIFF_TYPE__ ZyanISize;
# else
typedef long int ZyanISize;
# endif
# ifdef __UINTPTR_TYPE__
typedef __UINTPTR_TYPE__ ZyanUPointer;
# else
# if defined(__x86_64__) && !defined( __ILP32__)
typedef unsigned long int ZyanUPointer;
# else
typedef unsigned int ZyanUPointer;
# endif
# endif
# ifdef __INTPTR_TYPE__
typedef __INTPTR_TYPE__ ZyanIPointer;
# else
# if defined(__x86_64__) && !defined( __ILP32__)
typedef long int ZyanIPointer;
# else
typedef int ZyanIPointer;
# endif
# endif
# else
# error "Unsupported compiler for no-libc mode."
# endif
......@@ -92,18 +156,58 @@
# define ZYAN_UINT32_MAX 0xffffffffui32
# define ZYAN_UINT64_MAX 0xffffffffffffffffui64
# else
# ifdef __INT8_MAX__
# define ZYAN_INT8_MAX __INT8_MAX__
# else
# define ZYAN_INT8_MAX (127)
# endif
# define ZYAN_INT8_MIN (-ZYAN_INT8_MAX - 1)
# ifdef __INT16_MAX__
# define ZYAN_INT16_MAX __INT16_MAX__
# else
# define ZYAN_INT16_MAX (32767)
# endif
# define ZYAN_INT16_MIN (-ZYAN_INT16_MAX - 1)
# ifdef __INT32_MAX__
# define ZYAN_INT32_MAX __INT32_MAX__
# else
# define ZYAN_INT32_MAX (2147483647)
# endif
# define ZYAN_INT32_MIN (-ZYAN_INT32_MAX - 1)
# ifdef __INT64_MAX__
# define ZYAN_INT64_MAX __INT64_MAX__
# else
# if defined(__x86_64__) && !defined( __ILP32__)
# define ZYAN_INT64_MAX (9223372036854775807L)
# else
# define ZYAN_INT64_MAX (9223372036854775807LL)
# endif
# endif
# define ZYAN_INT64_MIN (-ZYAN_INT64_MAX - 1)
# ifdef __UINT8_MAX__
# define ZYAN_UINT8_MAX __UINT8_MAX__
# else
# define ZYAN_UINT8_MAX (255)
# endif
# ifdef __UINT16_MAX__
# define ZYAN_UINT16_MAX __UINT16_MAX__
# else
# define ZYAN_UINT16_MAX (65535)
# endif
# ifdef __UINT32_MAX__
# define ZYAN_UINT32_MAX __UINT32_MAX__
# else
# define ZYAN_UINT32_MAX (4294967295U)
# endif
# ifdef __UINT64_MAX__
# define ZYAN_UINT64_MAX __UINT64_MAX__
# else
# if defined(__x86_64__) && !defined( __ILP32__)
# define ZYAN_UINT64_MAX (18446744073709551615UL)
# else
# define ZYAN_UINT64_MAX (18446744073709551615ULL)
# endif
# endif
# endif
#else
// If is LibC present, we use stdint types.
......
......@@ -136,11 +136,28 @@ typedef enum ZydisDecoderMode_
* This mode is enabled by default.
*/
ZYDIS_DECODER_MODE_CLDEMOTE,
/**
* Enables the `IPREFETCH` mode.
*
* The `IPREFETCH` isa-extension reuses (overrides) some of the widenop instruction opcodes.
*
* This mode is enabled by default.
*/
ZYDIS_DECODER_MODE_IPREFETCH,
/**
* Enables the `UD0` compatibility mode.
*
* Some processors decode the `UD0` instruction without a ModR/M byte. Enable this decoder mode
* to mimic this behavior.
*
* This mode is disabled by default.
*/
ZYDIS_DECODER_MODE_UD0_COMPAT,
/**
* Maximum value of this enum.
*/
ZYDIS_DECODER_MODE_MAX_VALUE = ZYDIS_DECODER_MODE_CLDEMOTE,
ZYDIS_DECODER_MODE_MAX_VALUE = ZYDIS_DECODER_MODE_UD0_COMPAT,
/**
* The minimum number of bits required to represent all values of this enum.
*/
......@@ -168,9 +185,9 @@ typedef struct ZydisDecoder_
*/
ZydisStackWidth stack_width;
/**
* The decoder mode array.
* The decoder mode bitmap.
*/
ZyanBool decoder_mode[ZYDIS_DECODER_MODE_MAX_VALUE + 1];
ZyanU32 decoder_mode;
} ZydisDecoder;
/* ---------------------------------------------------------------------------------------------- */
......
......@@ -221,7 +221,11 @@ typedef struct ZydisEncoderOperand_
*/
ZyanU8 scale;
/**
* The displacement value.
* The displacement value. This value is always treated as 64-bit signed integer, so it's
* important to take this into account when specifying absolute addresses. For example
* to specify a 16-bit address 0x8000 in 16-bit mode it should be sign extended to
* `0xFFFFFFFFFFFF8000`. See `address_size_hint` for more information about absolute
* addresses.
*/
ZyanI64 displacement;
/**
......@@ -302,6 +306,13 @@ typedef struct ZydisEncoderRequest_
* encoder deduces address size from `ZydisEncoderOperand` structures that represent
* explicit and implicit operands. This hint resolves conflicts when instruction's hidden
* operands scale with address size attribute.
*
* This hint is also used for instructions with absolute memory addresses (memory operands with
* displacement and no registers). Since displacement field is a 64-bit signed integer it's not
* possible to determine actual size of the address value in all situations. This hint
* specifies size of the address value provided inside encoder request rather than desired
* address size attribute of encoded instruction. Use `ZYDIS_ADDRESS_SIZE_HINT_NONE` to assume
* address size default for specified machine mode.
*/
ZydisAddressSizeHint address_size_hint;
/**
......
......@@ -176,16 +176,16 @@ typedef enum ZydisFormatterProperty_
/**
* Controls the padding of absolute address values.
*
* Pass `ZYDIS_PADDING_DISABLED` to disable padding, `ZYDIS_PADDING_AUTO` to padd all
* addresses to the current stack width (hexadecimal only), or any other integer value for
* Pass `ZYDIS_PADDING_DISABLED` to disable padding, `ZYDIS_PADDING_AUTO` to pad all
* addresses to the current address width (hexadecimal only), or any other integer value for
* custom padding.
*/
ZYDIS_FORMATTER_PROP_ADDR_PADDING_ABSOLUTE,
/**
* Controls the padding of relative address values.
*
* Pass `ZYDIS_PADDING_DISABLED` to disable padding, `ZYDIS_PADDING_AUTO` to padd all
* addresses to the current stack width (hexadecimal only), or any other integer value for
* Pass `ZYDIS_PADDING_DISABLED` to disable padding, `ZYDIS_PADDING_AUTO` to pad all
* addresses to the current address width (hexadecimal only), or any other integer value for
* custom padding.
*/
ZYDIS_FORMATTER_PROP_ADDR_PADDING_RELATIVE,
......@@ -262,6 +262,8 @@ typedef enum ZydisFormatterProperty_
* Controls the letter-case for decorators.
*
* Pass `ZYAN_TRUE` as value to format in uppercase or `ZYAN_FALSE` to format in lowercase.
*
* WARNING: this is currently not implemented (ignored).
*/
ZYDIS_FORMATTER_PROP_UPPERCASE_DECORATORS,
......@@ -798,75 +800,75 @@ struct ZydisFormatter_
*/
ZyanBool print_branch_size;
/**
* The `ZYDIS_FORMATTER_DETAILED_PREFIXES` property.
* The `ZYDIS_FORMATTER_PROP_DETAILED_PREFIXES` property.
*/
ZyanBool detailed_prefixes;
/**
* The `ZYDIS_FORMATTER_ADDR_BASE` property.
* The `ZYDIS_FORMATTER_PROP_ADDR_BASE` property.
*/
ZydisNumericBase addr_base;
/**
* The `ZYDIS_FORMATTER_ADDR_SIGNEDNESS` property.
* The `ZYDIS_FORMATTER_PROP_ADDR_SIGNEDNESS` property.
*/
ZydisSignedness addr_signedness;
/**
* The `ZYDIS_FORMATTER_ADDR_PADDING_ABSOLUTE` property.
* The `ZYDIS_FORMATTER_PROP_ADDR_PADDING_ABSOLUTE` property.
*/
ZydisPadding addr_padding_absolute;
/**
* The `ZYDIS_FORMATTER_ADDR_PADDING_RELATIVE` property.
* The `ZYDIS_FORMATTER_PROP_ADDR_PADDING_RELATIVE` property.
*/
ZydisPadding addr_padding_relative;
/**
* The `ZYDIS_FORMATTER_DISP_BASE` property.
* The `ZYDIS_FORMATTER_PROP_DISP_BASE` property.
*/
ZydisNumericBase disp_base;
/**
* The `ZYDIS_FORMATTER_DISP_SIGNEDNESS` property.
* The `ZYDIS_FORMATTER_PROP_DISP_SIGNEDNESS` property.
*/
ZydisSignedness disp_signedness;
/**
* The `ZYDIS_FORMATTER_DISP_PADDING` property.
* The `ZYDIS_FORMATTER_PROP_DISP_PADDING` property.
*/
ZydisPadding disp_padding;
/**
* The `ZYDIS_FORMATTER_IMM_BASE` property.
* The `ZYDIS_FORMATTER_PROP_IMM_BASE` property.
*/
ZydisNumericBase imm_base;
/**
* The `ZYDIS_FORMATTER_IMM_SIGNEDNESS` property.
* The `ZYDIS_FORMATTER_PROP_IMM_SIGNEDNESS` property.
*/
ZydisSignedness imm_signedness;
/**
* The `ZYDIS_FORMATTER_IMM_PADDING` property.
* The `ZYDIS_FORMATTER_PROP_IMM_PADDING` property.
*/
ZydisPadding imm_padding;
/**
* The `ZYDIS_FORMATTER_UPPERCASE_PREFIXES` property.
* The `ZYDIS_FORMATTER_PROP_UPPERCASE_PREFIXES` property.
*/
ZyanI32 case_prefixes;
/**
* The `ZYDIS_FORMATTER_UPPERCASE_MNEMONIC` property.
* The `ZYDIS_FORMATTER_PROP_UPPERCASE_MNEMONIC` property.
*/
ZyanI32 case_mnemonic;
/**
* The `ZYDIS_FORMATTER_UPPERCASE_REGISTERS` property.
* The `ZYDIS_FORMATTER_PROP_UPPERCASE_REGISTERS` property.
*/
ZyanI32 case_registers;
/**
* The `ZYDIS_FORMATTER_UPPERCASE_TYPECASTS` property.
* The `ZYDIS_FORMATTER_PROP_UPPERCASE_TYPECASTS` property.
*/
ZyanI32 case_typecasts;
/**
* The `ZYDIS_FORMATTER_UPPERCASE_DECORATORS` property.
* The `ZYDIS_FORMATTER_PROP_UPPERCASE_DECORATORS` property.
*/
ZyanI32 case_decorators;
/**
* The `ZYDIS_FORMATTER_HEX_UPPERCASE` property.
* The `ZYDIS_FORMATTER_PROP_HEX_UPPERCASE` property.
*/
ZyanBool hex_uppercase;
/**
* The `ZYDIS_FORMATTER_HEX_FORCE_LEADING_NUMBER` property.
* The `ZYDIS_FORMATTER_PROP_HEX_FORCE_LEADING_NUMBER` property.
*/
ZyanBool hex_force_leading_number;
/**
......
......@@ -10,6 +10,7 @@ typedef enum ZydisISAExt_
ZYDIS_ISA_EXT_AMD3DNOW_PREFETCH,
ZYDIS_ISA_EXT_AMD_INVLPGB,
ZYDIS_ISA_EXT_AMX_BF16,
ZYDIS_ISA_EXT_AMX_FP16,
ZYDIS_ISA_EXT_AMX_INT8,
ZYDIS_ISA_EXT_AMX_TILE,
ZYDIS_ISA_EXT_AVX,
......@@ -18,7 +19,11 @@ typedef enum ZydisISAExt_
ZYDIS_ISA_EXT_AVX512EVEX,
ZYDIS_ISA_EXT_AVX512VEX,
ZYDIS_ISA_EXT_AVXAES,
ZYDIS_ISA_EXT_AVX_IFMA,
ZYDIS_ISA_EXT_AVX_NE_CONVERT,
ZYDIS_ISA_EXT_AVX_VNNI,
ZYDIS_ISA_EXT_AVX_VNNI_INT16,
ZYDIS_ISA_EXT_AVX_VNNI_INT8,
ZYDIS_ISA_EXT_BASE,
ZYDIS_ISA_EXT_BMI1,
ZYDIS_ISA_EXT_BMI2,
......@@ -34,6 +39,7 @@ typedef enum ZydisISAExt_
ZYDIS_ISA_EXT_FMA4,
ZYDIS_ISA_EXT_GFNI,
ZYDIS_ISA_EXT_HRESET,
ZYDIS_ISA_EXT_ICACHE_PREFETCH,
ZYDIS_ISA_EXT_INVPCID,
ZYDIS_ISA_EXT_KEYLOCKER,
ZYDIS_ISA_EXT_KEYLOCKER_WIDE,
......@@ -49,13 +55,17 @@ typedef enum ZydisISAExt_
ZYDIS_ISA_EXT_MOVBE,
ZYDIS_ISA_EXT_MOVDIR,
ZYDIS_ISA_EXT_MPX,
ZYDIS_ISA_EXT_MSRLIST,
ZYDIS_ISA_EXT_PADLOCK,
ZYDIS_ISA_EXT_PAUSE,
ZYDIS_ISA_EXT_PBNDKB,
ZYDIS_ISA_EXT_PCLMULQDQ,
ZYDIS_ISA_EXT_PCOMMIT,
ZYDIS_ISA_EXT_PCONFIG,
ZYDIS_ISA_EXT_PKU,
ZYDIS_ISA_EXT_PREFETCHWT1,
ZYDIS_ISA_EXT_PT,
ZYDIS_ISA_EXT_RAO_INT,
ZYDIS_ISA_EXT_RDPID,
ZYDIS_ISA_EXT_RDPRU,
ZYDIS_ISA_EXT_RDRAND,
......@@ -67,6 +77,9 @@ typedef enum ZydisISAExt_
ZYDIS_ISA_EXT_SGX,
ZYDIS_ISA_EXT_SGX_ENCLV,
ZYDIS_ISA_EXT_SHA,
ZYDIS_ISA_EXT_SHA512,
ZYDIS_ISA_EXT_SM3,
ZYDIS_ISA_EXT_SM4,
ZYDIS_ISA_EXT_SMAP,
ZYDIS_ISA_EXT_SMX,
ZYDIS_ISA_EXT_SNP,
......@@ -86,6 +99,7 @@ typedef enum ZydisISAExt_
ZYDIS_ISA_EXT_VPCLMULQDQ,
ZYDIS_ISA_EXT_VTX,
ZYDIS_ISA_EXT_WAITPKG,
ZYDIS_ISA_EXT_WRMSRNS,
ZYDIS_ISA_EXT_X87,
ZYDIS_ISA_EXT_XOP,
ZYDIS_ISA_EXT_XSAVE,
......
......@@ -10,6 +10,7 @@ typedef enum ZydisISASet_
ZYDIS_ISA_SET_AMD3DNOW,
ZYDIS_ISA_SET_AMD_INVLPGB,
ZYDIS_ISA_SET_AMX_BF16,
ZYDIS_ISA_SET_AMX_FP16,
ZYDIS_ISA_SET_AMX_INT8,
ZYDIS_ISA_SET_AMX_TILE,
ZYDIS_ISA_SET_AVX,
......@@ -81,7 +82,11 @@ typedef enum ZydisISASet_
ZYDIS_ISA_SET_AVX512_VPOPCNTDQ_512,
ZYDIS_ISA_SET_AVXAES,
ZYDIS_ISA_SET_AVX_GFNI,
ZYDIS_ISA_SET_AVX_IFMA,
ZYDIS_ISA_SET_AVX_NE_CONVERT,
ZYDIS_ISA_SET_AVX_VNNI,
ZYDIS_ISA_SET_AVX_VNNI_INT16,
ZYDIS_ISA_SET_AVX_VNNI_INT8,
ZYDIS_ISA_SET_BMI1,
ZYDIS_ISA_SET_BMI2,
ZYDIS_ISA_SET_CET,
......@@ -96,6 +101,7 @@ typedef enum ZydisISASet_
ZYDIS_ISA_SET_F16C,
ZYDIS_ISA_SET_FAT_NOP,
ZYDIS_ISA_SET_FCMOV,
ZYDIS_ISA_SET_FCOMI,
ZYDIS_ISA_SET_FMA,
ZYDIS_ISA_SET_FMA4,
ZYDIS_ISA_SET_FXSAVE,
......@@ -109,6 +115,7 @@ typedef enum ZydisISASet_
ZYDIS_ISA_SET_I486,
ZYDIS_ISA_SET_I486REAL,
ZYDIS_ISA_SET_I86,
ZYDIS_ISA_SET_ICACHE_PREFETCH,
ZYDIS_ISA_SET_INVPCID,
ZYDIS_ISA_SET_KEYLOCKER,
ZYDIS_ISA_SET_KEYLOCKER_WIDE,
......@@ -128,12 +135,15 @@ typedef enum ZydisISASet_
ZYDIS_ISA_SET_MOVBE,
ZYDIS_ISA_SET_MOVDIR,
ZYDIS_ISA_SET_MPX,
ZYDIS_ISA_SET_MSRLIST,
ZYDIS_ISA_SET_PADLOCK_ACE,
ZYDIS_ISA_SET_PADLOCK_PHE,
ZYDIS_ISA_SET_PADLOCK_PMM,
ZYDIS_ISA_SET_PADLOCK_RNG,
ZYDIS_ISA_SET_PAUSE,
ZYDIS_ISA_SET_PBNDKB,
ZYDIS_ISA_SET_PCLMULQDQ,
ZYDIS_ISA_SET_PCOMMIT,
ZYDIS_ISA_SET_PCONFIG,
ZYDIS_ISA_SET_PENTIUMMMX,
ZYDIS_ISA_SET_PENTIUMREAL,
......@@ -143,6 +153,7 @@ typedef enum ZydisISASet_
ZYDIS_ISA_SET_PREFETCHWT1,
ZYDIS_ISA_SET_PREFETCH_NOP,
ZYDIS_ISA_SET_PT,
ZYDIS_ISA_SET_RAO_INT,
ZYDIS_ISA_SET_RDPID,
ZYDIS_ISA_SET_RDPMC,
ZYDIS_ISA_SET_RDPRU,
......@@ -155,6 +166,9 @@ typedef enum ZydisISASet_
ZYDIS_ISA_SET_SGX,
ZYDIS_ISA_SET_SGX_ENCLV,
ZYDIS_ISA_SET_SHA,
ZYDIS_ISA_SET_SHA512,
ZYDIS_ISA_SET_SM3,
ZYDIS_ISA_SET_SM4,
ZYDIS_ISA_SET_SMAP,
ZYDIS_ISA_SET_SMX,
ZYDIS_ISA_SET_SNP,
......@@ -180,6 +194,7 @@ typedef enum ZydisISASet_
ZYDIS_ISA_SET_VPCLMULQDQ,
ZYDIS_ISA_SET_VTX,
ZYDIS_ISA_SET_WAITPKG,
ZYDIS_ISA_SET_WRMSRNS,
ZYDIS_ISA_SET_X87,
ZYDIS_ISA_SET_XOP,
ZYDIS_ISA_SET_XSAVE,
......
......@@ -17,6 +17,7 @@ typedef enum ZydisInstructionCategory_
ZYDIS_CATEGORY_AVX512_BITALG,
ZYDIS_CATEGORY_AVX512_VBMI,
ZYDIS_CATEGORY_AVX512_VP2INTERSECT,
ZYDIS_CATEGORY_AVX_IFMA,
ZYDIS_CATEGORY_BINARY,
ZYDIS_CATEGORY_BITBYTE,
ZYDIS_CATEGORY_BLEND,
......@@ -63,9 +64,12 @@ typedef enum ZydisInstructionCategory_
ZYDIS_CATEGORY_MMX,
ZYDIS_CATEGORY_MOVDIR,
ZYDIS_CATEGORY_MPX,
ZYDIS_CATEGORY_MSRLIST,
ZYDIS_CATEGORY_NOP,
ZYDIS_CATEGORY_PADLOCK,
ZYDIS_CATEGORY_PBNDKB,
ZYDIS_CATEGORY_PCLMULQDQ,
ZYDIS_CATEGORY_PCOMMIT,
ZYDIS_CATEGORY_PCONFIG,
ZYDIS_CATEGORY_PKU,
ZYDIS_CATEGORY_POP,
......@@ -87,6 +91,7 @@ typedef enum ZydisInstructionCategory_
ZYDIS_CATEGORY_SETCC,
ZYDIS_CATEGORY_SGX,
ZYDIS_CATEGORY_SHA,
ZYDIS_CATEGORY_SHA512,
ZYDIS_CATEGORY_SHIFT,
ZYDIS_CATEGORY_SMAP,
ZYDIS_CATEGORY_SSE,
......@@ -108,6 +113,7 @@ typedef enum ZydisInstructionCategory_
ZYDIS_CATEGORY_VTX,
ZYDIS_CATEGORY_WAITPKG,
ZYDIS_CATEGORY_WIDENOP,
ZYDIS_CATEGORY_WRMSRNS,
ZYDIS_CATEGORY_X87_ALU,
ZYDIS_CATEGORY_XOP,
ZYDIS_CATEGORY_XSAVE,
......
......@@ -6,7 +6,9 @@ typedef enum ZydisMnemonic_
ZYDIS_MNEMONIC_INVALID,
ZYDIS_MNEMONIC_AAA,
ZYDIS_MNEMONIC_AAD,
ZYDIS_MNEMONIC_AADD,
ZYDIS_MNEMONIC_AAM,
ZYDIS_MNEMONIC_AAND,
ZYDIS_MNEMONIC_AAS,
ZYDIS_MNEMONIC_ADC,
ZYDIS_MNEMONIC_ADCX,
......@@ -38,7 +40,9 @@ typedef enum ZydisMnemonic_
ZYDIS_MNEMONIC_ANDNPS,
ZYDIS_MNEMONIC_ANDPD,
ZYDIS_MNEMONIC_ANDPS,
ZYDIS_MNEMONIC_AOR,
ZYDIS_MNEMONIC_ARPL,
ZYDIS_MNEMONIC_AXOR,
ZYDIS_MNEMONIC_BEXTR,
ZYDIS_MNEMONIC_BLCFILL,
ZYDIS_MNEMONIC_BLCI,
......@@ -519,6 +523,7 @@ typedef enum ZydisMnemonic_
ZYDIS_MNEMONIC_PAVGW,
ZYDIS_MNEMONIC_PBLENDVB,
ZYDIS_MNEMONIC_PBLENDW,
ZYDIS_MNEMONIC_PBNDKB,
ZYDIS_MNEMONIC_PCLMULQDQ,
ZYDIS_MNEMONIC_PCMPEQB,
ZYDIS_MNEMONIC_PCMPEQD,
......@@ -532,6 +537,7 @@ typedef enum ZydisMnemonic_
ZYDIS_MNEMONIC_PCMPGTW,
ZYDIS_MNEMONIC_PCMPISTRI,
ZYDIS_MNEMONIC_PCMPISTRM,
ZYDIS_MNEMONIC_PCOMMIT,
ZYDIS_MNEMONIC_PCONFIG,
ZYDIS_MNEMONIC_PDEP,
ZYDIS_MNEMONIC_PEXT,
......@@ -615,6 +621,8 @@ typedef enum ZydisMnemonic_
ZYDIS_MNEMONIC_POPFQ,
ZYDIS_MNEMONIC_POR,
ZYDIS_MNEMONIC_PREFETCH,
ZYDIS_MNEMONIC_PREFETCHIT0,
ZYDIS_MNEMONIC_PREFETCHIT1,
ZYDIS_MNEMONIC_PREFETCHNTA,
ZYDIS_MNEMONIC_PREFETCHT0,
ZYDIS_MNEMONIC_PREFETCHT1,
......@@ -675,6 +683,7 @@ typedef enum ZydisMnemonic_
ZYDIS_MNEMONIC_RDFSBASE,
ZYDIS_MNEMONIC_RDGSBASE,
ZYDIS_MNEMONIC_RDMSR,
ZYDIS_MNEMONIC_RDMSRLIST,
ZYDIS_MNEMONIC_RDPID,
ZYDIS_MNEMONIC_RDPKRU,
ZYDIS_MNEMONIC_RDPMC,
......@@ -788,6 +797,7 @@ typedef enum ZydisMnemonic_
ZYDIS_MNEMONIC_TDPBSUD,
ZYDIS_MNEMONIC_TDPBUSD,
ZYDIS_MNEMONIC_TDPBUUD,
ZYDIS_MNEMONIC_TDPFP16PS,
ZYDIS_MNEMONIC_TEST,
ZYDIS_MNEMONIC_TESTUI,
ZYDIS_MNEMONIC_TILELOADD,
......@@ -839,6 +849,8 @@ typedef enum ZydisMnemonic_
ZYDIS_MNEMONIC_VANDNPS,
ZYDIS_MNEMONIC_VANDPD,
ZYDIS_MNEMONIC_VANDPS,
ZYDIS_MNEMONIC_VBCSTNEBF162PS,
ZYDIS_MNEMONIC_VBCSTNESH2PS,
ZYDIS_MNEMONIC_VBLENDMPD,
ZYDIS_MNEMONIC_VBLENDMPS,
ZYDIS_MNEMONIC_VBLENDPD,
......@@ -880,6 +892,10 @@ typedef enum ZydisMnemonic_
ZYDIS_MNEMONIC_VCVTFXPNTPS2UDQ,
ZYDIS_MNEMONIC_VCVTFXPNTUDQ2PS,
ZYDIS_MNEMONIC_VCVTNE2PS2BF16,
ZYDIS_MNEMONIC_VCVTNEEBF162PS,
ZYDIS_MNEMONIC_VCVTNEEPH2PS,
ZYDIS_MNEMONIC_VCVTNEOBF162PS,
ZYDIS_MNEMONIC_VCVTNEOPH2PS,
ZYDIS_MNEMONIC_VCVTNEPS2BF16,
ZYDIS_MNEMONIC_VCVTPD2DQ,
ZYDIS_MNEMONIC_VCVTPD2PH,
......@@ -1341,10 +1357,22 @@ typedef enum ZydisMnemonic_
ZYDIS_MNEMONIC_VPCOMW,
ZYDIS_MNEMONIC_VPCONFLICTD,
ZYDIS_MNEMONIC_VPCONFLICTQ,
ZYDIS_MNEMONIC_VPDPBSSD,
ZYDIS_MNEMONIC_VPDPBSSDS,
ZYDIS_MNEMONIC_VPDPBSUD,
ZYDIS_MNEMONIC_VPDPBSUDS,
ZYDIS_MNEMONIC_VPDPBUSD,
ZYDIS_MNEMONIC_VPDPBUSDS,
ZYDIS_MNEMONIC_VPDPBUUD,
ZYDIS_MNEMONIC_VPDPBUUDS,
ZYDIS_MNEMONIC_VPDPWSSD,
ZYDIS_MNEMONIC_VPDPWSSDS,
ZYDIS_MNEMONIC_VPDPWSUD,
ZYDIS_MNEMONIC_VPDPWSUDS,
ZYDIS_MNEMONIC_VPDPWUSD,
ZYDIS_MNEMONIC_VPDPWUSDS,
ZYDIS_MNEMONIC_VPDPWUUD,
ZYDIS_MNEMONIC_VPDPWUUDS,
ZYDIS_MNEMONIC_VPERM2F128,
ZYDIS_MNEMONIC_VPERM2I128,
ZYDIS_MNEMONIC_VPERMB,
......@@ -1681,12 +1709,20 @@ typedef enum ZydisMnemonic_
ZYDIS_MNEMONIC_VSCATTERPF1QPS,
ZYDIS_MNEMONIC_VSCATTERQPD,
ZYDIS_MNEMONIC_VSCATTERQPS,
ZYDIS_MNEMONIC_VSHA512MSG1,
ZYDIS_MNEMONIC_VSHA512MSG2,
ZYDIS_MNEMONIC_VSHA512RNDS2,
ZYDIS_MNEMONIC_VSHUFF32X4,
ZYDIS_MNEMONIC_VSHUFF64X2,
ZYDIS_MNEMONIC_VSHUFI32X4,
ZYDIS_MNEMONIC_VSHUFI64X2,
ZYDIS_MNEMONIC_VSHUFPD,
ZYDIS_MNEMONIC_VSHUFPS,
ZYDIS_MNEMONIC_VSM3MSG1,
ZYDIS_MNEMONIC_VSM3MSG2,
ZYDIS_MNEMONIC_VSM3RNDS2,
ZYDIS_MNEMONIC_VSM4KEY4,
ZYDIS_MNEMONIC_VSM4RNDS4,
ZYDIS_MNEMONIC_VSQRTPD,
ZYDIS_MNEMONIC_VSQRTPH,
ZYDIS_MNEMONIC_VSQRTPS,
......@@ -1719,6 +1755,8 @@ typedef enum ZydisMnemonic_
ZYDIS_MNEMONIC_WRFSBASE,
ZYDIS_MNEMONIC_WRGSBASE,
ZYDIS_MNEMONIC_WRMSR,
ZYDIS_MNEMONIC_WRMSRLIST,
ZYDIS_MNEMONIC_WRMSRNS,
ZYDIS_MNEMONIC_WRPKRU,
ZYDIS_MNEMONIC_WRSSD,
ZYDIS_MNEMONIC_WRSSQ,
......
......@@ -173,7 +173,15 @@ enum ZydisDecoderTreeNodeTypes
/**
* Reference to a CLDEMOTE-mode filter.
*/
ZYDIS_NODETYPE_FILTER_MODE_CLDEMOTE = 0x1B
ZYDIS_NODETYPE_FILTER_MODE_CLDEMOTE = 0x1B,
/**
* Reference to a IPREFETCH-mode filter.
*/
ZYDIS_NODETYPE_FILTER_MODE_IPREFETCH = 0x1C,
/**
* Reference to a UD0_COMPAT-mode filter.
*/
ZYDIS_NODETYPE_FILTER_MODE_UD0_COMPAT = 0x1D
};
/* ---------------------------------------------------------------------------------------------- */
......
......@@ -116,11 +116,15 @@ typedef enum ZydisInternalElementType_
ZYDIS_IELEMENT_TYPE_UINT,
ZYDIS_IELEMENT_TYPE_INT1,
ZYDIS_IELEMENT_TYPE_INT8,
ZYDIS_IELEMENT_TYPE_INT8X4,
ZYDIS_IELEMENT_TYPE_INT16,
ZYDIS_IELEMENT_TYPE_INT16X2,
ZYDIS_IELEMENT_TYPE_INT32,
ZYDIS_IELEMENT_TYPE_INT64,
ZYDIS_IELEMENT_TYPE_UINT8,
ZYDIS_IELEMENT_TYPE_UINT8X4,
ZYDIS_IELEMENT_TYPE_UINT16,
ZYDIS_IELEMENT_TYPE_UINT16X2,
ZYDIS_IELEMENT_TYPE_UINT32,
ZYDIS_IELEMENT_TYPE_UINT64,
ZYDIS_IELEMENT_TYPE_UINT128,
......@@ -130,6 +134,7 @@ typedef enum ZydisInternalElementType_
ZYDIS_IELEMENT_TYPE_FLOAT32,
ZYDIS_IELEMENT_TYPE_FLOAT64,
ZYDIS_IELEMENT_TYPE_FLOAT80,
ZYDIS_IELEMENT_TYPE_BFLOAT16X2,
ZYDIS_IELEMENT_TYPE_BCD80,
ZYDIS_IELEMENT_TYPE_CC3,
ZYDIS_IELEMENT_TYPE_CC5,
......
......@@ -282,7 +282,7 @@ ZYDIS_EXPORT ZydisRegisterWidth ZydisRegisterGetWidth(ZydisMachineMode mode, Zyd
* @param reg The register.
*
* @return The largest enclosing register of the given register, or `ZYDIS_REGISTER_NONE` if the
* register is invalid for the active machine-mode or does not have an enclosing-register.
* register is invalid for the active machine-mode.
*/
ZYDIS_EXPORT ZydisRegister ZydisRegisterGetLargestEnclosing(ZydisMachineMode mode,
ZydisRegister reg);
......
......@@ -162,6 +162,10 @@ typedef enum ZydisElementType_
*/
ZYDIS_ELEMENT_TYPE_FLOAT80,
/**
* 16-bit brain floating point value.
*/
ZYDIS_ELEMENT_TYPE_BFLOAT16,
/**
* Binary coded decimal value.
*/
ZYDIS_ELEMENT_TYPE_LONGBCD,
......
......@@ -44,7 +44,7 @@ extern "C" {
/* Enums and types */
/* ============================================================================================== */
#if !(defined(ZYAN_AARCH64) && defined(ZYAN_APPLE))
#if !defined(ZYAN_APPLE)
# pragma pack(push, 1)
#endif
......@@ -68,7 +68,7 @@ typedef struct ZydisShortString_
ZyanU8 size;
} ZydisShortString;
#if !(defined(ZYAN_AARCH64) && defined(ZYAN_APPLE))
#if !defined(ZYAN_APPLE)
# pragma pack(pop)
#endif
......
......@@ -86,7 +86,7 @@ extern "C" {
/**
* A macro that defines the zydis version.
*/
#define ZYDIS_VERSION (ZyanU64)0x0004000000000000
#define ZYDIS_VERSION (ZyanU64)0x0004000100000000
/* ---------------------------------------------------------------------------------------------- */
/* Helper macros */
......@@ -141,7 +141,7 @@ typedef enum ZydisFeature_
/**
* Maximum value of this enum.
*/
ZYDIS_FEATURE_MAX_VALUE = ZYDIS_FEATURE_KNC,
ZYDIS_FEATURE_MAX_VALUE = ZYDIS_FEATURE_SEGMENT,
/**
* The minimum number of bits required to represent all values of this enum.
*/
......
......@@ -1589,7 +1589,7 @@ static void ZydisDecodeOperandImplicitMemory(const ZydisDecoder* decoder,
#endif
#ifndef ZYDIS_MINIMAL_MODE
ZyanStatus ZydisDecodeOperands(const ZydisDecoder* decoder, const ZydisDecoderContext* context,
static ZyanStatus ZydisDecodeOperands(const ZydisDecoder* decoder, const ZydisDecoderContext* context,
const ZydisDecodedInstruction* instruction, ZydisDecodedOperand* operands, ZyanU8 operand_count)
{
ZYAN_ASSERT(decoder);
......@@ -2103,7 +2103,7 @@ static void ZydisSetAttributes(ZydisDecoderState* state, ZydisDecodedInstruction
break;
}
}
if (state->decoder->decoder_mode[ZYDIS_DECODER_MODE_MPX] &&
if ((state->decoder->decoder_mode & (1 << ZYDIS_DECODER_MODE_MPX)) &&
instruction->attributes & ZYDIS_ATTRIB_ACCEPTS_BND)
{
instruction->attributes |= ZYDIS_ATTRIB_HAS_BND;
......@@ -2167,7 +2167,7 @@ static void ZydisSetAttributes(ZydisDecoderState* state, ZydisDecodedInstruction
if (def->accepts_NOTRACK)
{
instruction->attributes |= ZYDIS_ATTRIB_ACCEPTS_NOTRACK;
if (state->decoder->decoder_mode[ZYDIS_DECODER_MODE_CET] &&
if ((state->decoder->decoder_mode & (1 << ZYDIS_DECODER_MODE_CET)) &&
(state->prefixes.offset_notrack >= 0))
{
instruction->attributes |= ZYDIS_ATTRIB_HAS_NOTRACK;
......@@ -4777,28 +4777,34 @@ static ZyanStatus ZydisDecodeInstruction(ZydisDecoderState* state,
break;
#endif
case ZYDIS_NODETYPE_FILTER_MODE_AMD:
index = state->decoder->decoder_mode[ZYDIS_DECODER_MODE_AMD_BRANCHES] ? 1 : 0;
index = !!(state->decoder->decoder_mode & (1 << ZYDIS_DECODER_MODE_AMD_BRANCHES));
break;
case ZYDIS_NODETYPE_FILTER_MODE_KNC:
index = state->decoder->decoder_mode[ZYDIS_DECODER_MODE_KNC] ? 1 : 0;
index = !!(state->decoder->decoder_mode & (1 << ZYDIS_DECODER_MODE_KNC));
break;
case ZYDIS_NODETYPE_FILTER_MODE_MPX:
index = state->decoder->decoder_mode[ZYDIS_DECODER_MODE_MPX] ? 1 : 0;
index = !!(state->decoder->decoder_mode & (1 << ZYDIS_DECODER_MODE_MPX));
break;
case ZYDIS_NODETYPE_FILTER_MODE_CET:
index = state->decoder->decoder_mode[ZYDIS_DECODER_MODE_CET] ? 1 : 0;
index = !!(state->decoder->decoder_mode & (1 << ZYDIS_DECODER_MODE_CET));
break;
case ZYDIS_NODETYPE_FILTER_MODE_LZCNT:
index = state->decoder->decoder_mode[ZYDIS_DECODER_MODE_LZCNT] ? 1 : 0;
index = !!(state->decoder->decoder_mode & (1 << ZYDIS_DECODER_MODE_LZCNT));
break;
case ZYDIS_NODETYPE_FILTER_MODE_TZCNT:
index = state->decoder->decoder_mode[ZYDIS_DECODER_MODE_TZCNT] ? 1 : 0;
index = !!(state->decoder->decoder_mode & (1 << ZYDIS_DECODER_MODE_TZCNT));
break;
case ZYDIS_NODETYPE_FILTER_MODE_WBNOINVD:
index = state->decoder->decoder_mode[ZYDIS_DECODER_MODE_WBNOINVD] ? 1 : 0;
index = !!(state->decoder->decoder_mode & (1 << ZYDIS_DECODER_MODE_WBNOINVD));
break;
case ZYDIS_NODETYPE_FILTER_MODE_CLDEMOTE:
index = state->decoder->decoder_mode[ZYDIS_DECODER_MODE_CLDEMOTE] ? 1 : 0;
index = !!(state->decoder->decoder_mode & (1 << ZYDIS_DECODER_MODE_CLDEMOTE));
break;
case ZYDIS_NODETYPE_FILTER_MODE_IPREFETCH:
index = !!(state->decoder->decoder_mode & (1 << ZYDIS_DECODER_MODE_IPREFETCH));
break;
case ZYDIS_NODETYPE_FILTER_MODE_UD0_COMPAT:
index = !!(state->decoder->decoder_mode & (1 << ZYDIS_DECODER_MODE_UD0_COMPAT));
break;
default:
if (node_type & ZYDIS_NODETYPE_DEFINITION_MASK)
......@@ -4851,7 +4857,7 @@ static ZyanStatus ZydisDecodeInstruction(ZydisDecoderState* state,
(instruction->meta.category == ZYDIS_CATEGORY_RET)));
instruction->meta.exception_class = definition->exception_class;
if (!state->decoder->decoder_mode[ZYDIS_DECODER_MODE_MINIMAL])
if (!(state->decoder->decoder_mode & (1 << ZYDIS_DECODER_MODE_MINIMAL)))
{
ZydisSetAttributes(state, instruction, definition);
switch (instruction->encoding)
......@@ -4896,22 +4902,18 @@ static ZyanStatus ZydisDecodeInstruction(ZydisDecoderState* state,
ZyanStatus ZydisDecoderInit(ZydisDecoder* decoder, ZydisMachineMode machine_mode,
ZydisStackWidth stack_width)
{
static const ZyanBool decoder_modes[ZYDIS_DECODER_MODE_MAX_VALUE + 1] =
{
ZYAN_STATIC_ASSERT(ZYDIS_DECODER_MODE_MAX_VALUE <= 32);
static const ZyanU32 decoder_modes =
#ifdef ZYDIS_MINIMAL_MODE
ZYAN_TRUE , // ZYDIS_DECODER_MODE_MINIMAL
#else
ZYAN_FALSE, // ZYDIS_DECODER_MODE_MINIMAL
(1 << ZYDIS_DECODER_MODE_MINIMAL) |
#endif
ZYAN_FALSE, // ZYDIS_DECODER_MODE_AMD_BRANCHES
ZYAN_FALSE, // ZYDIS_DECODER_MODE_KNC
ZYAN_TRUE , // ZYDIS_DECODER_MODE_MPX
ZYAN_TRUE , // ZYDIS_DECODER_MODE_CET
ZYAN_TRUE , // ZYDIS_DECODER_MODE_LZCNT
ZYAN_TRUE , // ZYDIS_DECODER_MODE_TZCNT
ZYAN_FALSE, // ZYDIS_DECODER_MODE_WBNOINVD
ZYAN_TRUE // ZYDIS_DECODER_MODE_CLDEMOTE
};
(1 << ZYDIS_DECODER_MODE_MPX) |
(1 << ZYDIS_DECODER_MODE_CET) |
(1 << ZYDIS_DECODER_MODE_LZCNT) |
(1 << ZYDIS_DECODER_MODE_TZCNT) |
(1 << ZYDIS_DECODER_MODE_CLDEMOTE) |
(1 << ZYDIS_DECODER_MODE_IPREFETCH);
if (!decoder)
{
......@@ -4941,7 +4943,7 @@ ZyanStatus ZydisDecoderInit(ZydisDecoder* decoder, ZydisMachineMode machine_mode
decoder->machine_mode = machine_mode;
decoder->stack_width = stack_width;
ZYAN_MEMCPY(&decoder->decoder_mode, &decoder_modes, sizeof(decoder_modes));
decoder->decoder_mode = decoder_modes;
return ZYAN_STATUS_SUCCESS;
}
......@@ -4960,7 +4962,14 @@ ZyanStatus ZydisDecoderEnableMode(ZydisDecoder* decoder, ZydisDecoderMode mode,
}
#endif
decoder->decoder_mode[mode] = enabled;
if (enabled)
{
decoder->decoder_mode |= (1 << mode);
}
else
{
decoder->decoder_mode &= ~(1 << mode);
}
return ZYAN_STATUS_SUCCESS;
}
......@@ -4977,7 +4986,7 @@ ZyanStatus ZydisDecoderDecodeFull(const ZydisDecoder* decoder,
{
return ZYDIS_STATUS_NO_MORE_DATA;
}
if (decoder->decoder_mode[ZYDIS_DECODER_MODE_MINIMAL])
if (decoder->decoder_mode & (1 << ZYDIS_DECODER_MODE_MINIMAL))
{
return ZYAN_STATUS_MISSING_DEPENDENCY; // TODO: Introduce better status code
}
......@@ -5055,7 +5064,7 @@ ZyanStatus ZydisDecoderDecodeOperands(const ZydisDecoder* decoder,
return ZYAN_STATUS_INVALID_ARGUMENT;
}
if (decoder->decoder_mode[ZYDIS_DECODER_MODE_MINIMAL])
if (decoder->decoder_mode & (1 << ZYDIS_DECODER_MODE_MINIMAL))
{
return ZYAN_STATUS_MISSING_DEPENDENCY; // TODO: Introduce better status code
}
......
......@@ -155,6 +155,12 @@ const ZydisDecoderTreeNode* ZydisDecoderTreeGetChildNode(const ZydisDecoderTreeN
case ZYDIS_NODETYPE_FILTER_MODE_CLDEMOTE:
ZYAN_ASSERT(index < 2);
return &FILTERS_MODE_CLDEMOTE[parent->value][index];
case ZYDIS_NODETYPE_FILTER_MODE_IPREFETCH:
ZYAN_ASSERT(index < 2);
return &FILTERS_MODE_IPREFETCH[parent->value][index];
case ZYDIS_NODETYPE_FILTER_MODE_UD0_COMPAT:
ZYAN_ASSERT(index < 2);
return &FILTERS_MODE_UD0_COMPAT[parent->value][index];
default:
ZYAN_UNREACHABLE;
}
......
......@@ -55,7 +55,7 @@ static const ZydisFormatter* const FORMATTER_PRESETS[ZYDIS_FORMATTER_STYLE_MAX_V
/* Helper functions */
/* ---------------------------------------------------------------------------------------------- */
void ZydisFormatterBufferInit(ZydisFormatterBuffer* buffer, char* user_buffer,
static void ZydisFormatterBufferInit(ZydisFormatterBuffer* buffer, char* user_buffer,
ZyanUSize length)
{
ZYAN_ASSERT(buffer);
......@@ -77,7 +77,7 @@ void ZydisFormatterBufferInit(ZydisFormatterBuffer* buffer, char* user_buffer,
*user_buffer = '\0';
}
void ZydisFormatterBufferInitTokenized(ZydisFormatterBuffer* buffer,
static void ZydisFormatterBufferInitTokenized(ZydisFormatterBuffer* buffer,
ZydisFormatterToken** first_token, void* user_buffer, ZyanUSize length)
{
ZYAN_ASSERT(buffer);
......@@ -331,6 +331,11 @@ ZyanStatus ZydisFormatterSetProperty(ZydisFormatter* formatter, ZydisFormatterPr
formatter->hex_uppercase = (value) ? ZYAN_TRUE : ZYAN_FALSE;
break;
}
case ZYDIS_FORMATTER_PROP_HEX_FORCE_LEADING_NUMBER:
{
formatter->hex_force_leading_number = (value) ? ZYAN_TRUE : ZYAN_FALSE;
break;
}
case ZYDIS_FORMATTER_PROP_HEX_PREFIX:
{
base = ZYDIS_NUMERIC_BASE_HEX;
......
......@@ -86,12 +86,17 @@ ZyanU32 ZydisFormatterHelperGetExplicitSize(const ZydisFormatter* formatter,
ZYAN_ASSERT(operand->type == ZYDIS_OPERAND_TYPE_MEMORY);
ZYAN_ASSERT((operand->mem.type == ZYDIS_MEMOP_TYPE_MEM) ||
(operand->mem.type == ZYDIS_MEMOP_TYPE_AGEN) ||
(operand->mem.type == ZYDIS_MEMOP_TYPE_VSIB));
if (formatter->force_memory_size)
{
return operand->size;
}
else if (operand->mem.type == ZYDIS_MEMOP_TYPE_AGEN)
{
return 0;
}
if (!context->operands)
{
......@@ -230,7 +235,7 @@ ZyanStatus ZydisFormatterBasePrintAddressABS(const ZydisFormatter* formatter,
if ((formatter->addr_padding_absolute == ZYDIS_PADDING_AUTO) &&
(formatter->addr_base == ZYDIS_NUMERIC_BASE_HEX))
{
switch (context->instruction->stack_width)
switch (context->instruction->address_width)
{
case 16:
padding = 4;
......@@ -270,7 +275,7 @@ ZyanStatus ZydisFormatterBasePrintAddressREL(const ZydisFormatter* formatter,
if ((formatter->addr_padding_relative == ZYDIS_PADDING_AUTO) &&
(formatter->addr_base == ZYDIS_NUMERIC_BASE_HEX))
{
switch (context->instruction->stack_width)
switch (context->instruction->address_width)
{
case 16:
padding = 4;
......
......@@ -201,6 +201,7 @@ ZyanStatus ZydisFormatterIntelFormatOperandMEM(const ZydisFormatter* formatter,
ZYAN_ASSERT(context);
if ((context->operand->mem.type == ZYDIS_MEMOP_TYPE_MEM) ||
(context->operand->mem.type == ZYDIS_MEMOP_TYPE_AGEN) ||
(context->operand->mem.type == ZYDIS_MEMOP_TYPE_VSIB))
{
ZYAN_CHECK(formatter->func_print_typecast(formatter, buffer, context));
......@@ -425,7 +426,7 @@ ZyanStatus ZydisFormatterIntelPrintAddressMASM(const ZydisFormatter* formatter,
if ((formatter->addr_padding_relative == ZYDIS_PADDING_AUTO) &&
(formatter->addr_base == ZYDIS_NUMERIC_BASE_HEX))
{
switch (context->instruction->stack_width)
switch (context->instruction->address_width)
{
case 16:
padding = 4;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -3,7 +3,9 @@ static const ZydisShortString STR_MNEMONIC[] =
ZYDIS_MAKE_SHORTSTRING("invalid"),
ZYDIS_MAKE_SHORTSTRING("aaa"),
ZYDIS_MAKE_SHORTSTRING("aad"),
ZYDIS_MAKE_SHORTSTRING("aadd"),
ZYDIS_MAKE_SHORTSTRING("aam"),
ZYDIS_MAKE_SHORTSTRING("aand"),
ZYDIS_MAKE_SHORTSTRING("aas"),
ZYDIS_MAKE_SHORTSTRING("adc"),
ZYDIS_MAKE_SHORTSTRING("adcx"),
......@@ -35,7 +37,9 @@ static const ZydisShortString STR_MNEMONIC[] =
ZYDIS_MAKE_SHORTSTRING("andnps"),
ZYDIS_MAKE_SHORTSTRING("andpd"),
ZYDIS_MAKE_SHORTSTRING("andps"),
ZYDIS_MAKE_SHORTSTRING("aor"),
ZYDIS_MAKE_SHORTSTRING("arpl"),
ZYDIS_MAKE_SHORTSTRING("axor"),
ZYDIS_MAKE_SHORTSTRING("bextr"),
ZYDIS_MAKE_SHORTSTRING("blcfill"),
ZYDIS_MAKE_SHORTSTRING("blci"),
......@@ -516,6 +520,7 @@ static const ZydisShortString STR_MNEMONIC[] =
ZYDIS_MAKE_SHORTSTRING("pavgw"),
ZYDIS_MAKE_SHORTSTRING("pblendvb"),
ZYDIS_MAKE_SHORTSTRING("pblendw"),
ZYDIS_MAKE_SHORTSTRING("pbndkb"),
ZYDIS_MAKE_SHORTSTRING("pclmulqdq"),
ZYDIS_MAKE_SHORTSTRING("pcmpeqb"),
ZYDIS_MAKE_SHORTSTRING("pcmpeqd"),
......@@ -529,6 +534,7 @@ static const ZydisShortString STR_MNEMONIC[] =
ZYDIS_MAKE_SHORTSTRING("pcmpgtw"),
ZYDIS_MAKE_SHORTSTRING("pcmpistri"),
ZYDIS_MAKE_SHORTSTRING("pcmpistrm"),
ZYDIS_MAKE_SHORTSTRING("pcommit"),
ZYDIS_MAKE_SHORTSTRING("pconfig"),
ZYDIS_MAKE_SHORTSTRING("pdep"),
ZYDIS_MAKE_SHORTSTRING("pext"),
......@@ -612,6 +618,8 @@ static const ZydisShortString STR_MNEMONIC[] =
ZYDIS_MAKE_SHORTSTRING("popfq"),
ZYDIS_MAKE_SHORTSTRING("por"),
ZYDIS_MAKE_SHORTSTRING("prefetch"),
ZYDIS_MAKE_SHORTSTRING("prefetchit0"),
ZYDIS_MAKE_SHORTSTRING("prefetchit1"),
ZYDIS_MAKE_SHORTSTRING("prefetchnta"),
ZYDIS_MAKE_SHORTSTRING("prefetcht0"),
ZYDIS_MAKE_SHORTSTRING("prefetcht1"),
......@@ -672,6 +680,7 @@ static const ZydisShortString STR_MNEMONIC[] =
ZYDIS_MAKE_SHORTSTRING("rdfsbase"),
ZYDIS_MAKE_SHORTSTRING("rdgsbase"),
ZYDIS_MAKE_SHORTSTRING("rdmsr"),
ZYDIS_MAKE_SHORTSTRING("rdmsrlist"),
ZYDIS_MAKE_SHORTSTRING("rdpid"),
ZYDIS_MAKE_SHORTSTRING("rdpkru"),
ZYDIS_MAKE_SHORTSTRING("rdpmc"),
......@@ -785,6 +794,7 @@ static const ZydisShortString STR_MNEMONIC[] =
ZYDIS_MAKE_SHORTSTRING("tdpbsud"),
ZYDIS_MAKE_SHORTSTRING("tdpbusd"),
ZYDIS_MAKE_SHORTSTRING("tdpbuud"),
ZYDIS_MAKE_SHORTSTRING("tdpfp16ps"),
ZYDIS_MAKE_SHORTSTRING("test"),
ZYDIS_MAKE_SHORTSTRING("testui"),
ZYDIS_MAKE_SHORTSTRING("tileloadd"),
......@@ -836,6 +846,8 @@ static const ZydisShortString STR_MNEMONIC[] =
ZYDIS_MAKE_SHORTSTRING("vandnps"),
ZYDIS_MAKE_SHORTSTRING("vandpd"),
ZYDIS_MAKE_SHORTSTRING("vandps"),
ZYDIS_MAKE_SHORTSTRING("vbcstnebf162ps"),
ZYDIS_MAKE_SHORTSTRING("vbcstnesh2ps"),
ZYDIS_MAKE_SHORTSTRING("vblendmpd"),
ZYDIS_MAKE_SHORTSTRING("vblendmps"),
ZYDIS_MAKE_SHORTSTRING("vblendpd"),
......@@ -877,6 +889,10 @@ static const ZydisShortString STR_MNEMONIC[] =
ZYDIS_MAKE_SHORTSTRING("vcvtfxpntps2udq"),
ZYDIS_MAKE_SHORTSTRING("vcvtfxpntudq2ps"),
ZYDIS_MAKE_SHORTSTRING("vcvtne2ps2bf16"),
ZYDIS_MAKE_SHORTSTRING("vcvtneebf162ps"),
ZYDIS_MAKE_SHORTSTRING("vcvtneeph2ps"),
ZYDIS_MAKE_SHORTSTRING("vcvtneobf162ps"),
ZYDIS_MAKE_SHORTSTRING("vcvtneoph2ps"),
ZYDIS_MAKE_SHORTSTRING("vcvtneps2bf16"),
ZYDIS_MAKE_SHORTSTRING("vcvtpd2dq"),
ZYDIS_MAKE_SHORTSTRING("vcvtpd2ph"),
......@@ -1338,10 +1354,22 @@ static const ZydisShortString STR_MNEMONIC[] =
ZYDIS_MAKE_SHORTSTRING("vpcomw"),
ZYDIS_MAKE_SHORTSTRING("vpconflictd"),
ZYDIS_MAKE_SHORTSTRING("vpconflictq"),
ZYDIS_MAKE_SHORTSTRING("vpdpbssd"),
ZYDIS_MAKE_SHORTSTRING("vpdpbssds"),
ZYDIS_MAKE_SHORTSTRING("vpdpbsud"),
ZYDIS_MAKE_SHORTSTRING("vpdpbsuds"),
ZYDIS_MAKE_SHORTSTRING("vpdpbusd"),
ZYDIS_MAKE_SHORTSTRING("vpdpbusds"),
ZYDIS_MAKE_SHORTSTRING("vpdpbuud"),
ZYDIS_MAKE_SHORTSTRING("vpdpbuuds"),
ZYDIS_MAKE_SHORTSTRING("vpdpwssd"),
ZYDIS_MAKE_SHORTSTRING("vpdpwssds"),
ZYDIS_MAKE_SHORTSTRING("vpdpwsud"),
ZYDIS_MAKE_SHORTSTRING("vpdpwsuds"),
ZYDIS_MAKE_SHORTSTRING("vpdpwusd"),
ZYDIS_MAKE_SHORTSTRING("vpdpwusds"),
ZYDIS_MAKE_SHORTSTRING("vpdpwuud"),
ZYDIS_MAKE_SHORTSTRING("vpdpwuuds"),
ZYDIS_MAKE_SHORTSTRING("vperm2f128"),
ZYDIS_MAKE_SHORTSTRING("vperm2i128"),
ZYDIS_MAKE_SHORTSTRING("vpermb"),
......@@ -1678,12 +1706,20 @@ static const ZydisShortString STR_MNEMONIC[] =
ZYDIS_MAKE_SHORTSTRING("vscatterpf1qps"),
ZYDIS_MAKE_SHORTSTRING("vscatterqpd"),
ZYDIS_MAKE_SHORTSTRING("vscatterqps"),
ZYDIS_MAKE_SHORTSTRING("vsha512msg1"),
ZYDIS_MAKE_SHORTSTRING("vsha512msg2"),
ZYDIS_MAKE_SHORTSTRING("vsha512rnds2"),
ZYDIS_MAKE_SHORTSTRING("vshuff32x4"),
ZYDIS_MAKE_SHORTSTRING("vshuff64x2"),
ZYDIS_MAKE_SHORTSTRING("vshufi32x4"),
ZYDIS_MAKE_SHORTSTRING("vshufi64x2"),
ZYDIS_MAKE_SHORTSTRING("vshufpd"),
ZYDIS_MAKE_SHORTSTRING("vshufps"),
ZYDIS_MAKE_SHORTSTRING("vsm3msg1"),
ZYDIS_MAKE_SHORTSTRING("vsm3msg2"),
ZYDIS_MAKE_SHORTSTRING("vsm3rnds2"),
ZYDIS_MAKE_SHORTSTRING("vsm4key4"),
ZYDIS_MAKE_SHORTSTRING("vsm4rnds4"),
ZYDIS_MAKE_SHORTSTRING("vsqrtpd"),
ZYDIS_MAKE_SHORTSTRING("vsqrtph"),
ZYDIS_MAKE_SHORTSTRING("vsqrtps"),
......@@ -1716,6 +1752,8 @@ static const ZydisShortString STR_MNEMONIC[] =
ZYDIS_MAKE_SHORTSTRING("wrfsbase"),
ZYDIS_MAKE_SHORTSTRING("wrgsbase"),
ZYDIS_MAKE_SHORTSTRING("wrmsr"),
ZYDIS_MAKE_SHORTSTRING("wrmsrlist"),
ZYDIS_MAKE_SHORTSTRING("wrmsrns"),
ZYDIS_MAKE_SHORTSTRING("wrpkru"),
ZYDIS_MAKE_SHORTSTRING("wrssd"),
ZYDIS_MAKE_SHORTSTRING("wrssq"),
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -156,6 +156,52 @@ ZydisRegister ZydisRegisterGetLargestEnclosing(ZydisMachineMode mode, ZydisRegis
return ZYDIS_REGISTER_NONE;
}
if (mode > ZYDIS_MACHINE_MODE_MAX_VALUE)
{
return ZYDIS_REGISTER_NONE;
}
const ZydisRegisterClass reg_class = REG_LOOKUP[reg].class;
if ((reg_class == ZYDIS_REGCLASS_INVALID) ||
((reg_class == ZYDIS_REGCLASS_GPR64) && (mode != ZYDIS_MACHINE_MODE_LONG_64)))
{
return ZYDIS_REGISTER_NONE;
}
static const ZydisRegister STATIC_MAPPING[ZYDIS_REGCLASS_MAX_VALUE + 1][3] =
{
/* 16 */ /* 32 */ /* 64 */
[ZYDIS_REGCLASS_FLAGS] = { ZYDIS_REGISTER_FLAGS, ZYDIS_REGISTER_EFLAGS, ZYDIS_REGISTER_RFLAGS },
[ZYDIS_REGCLASS_IP ] = { ZYDIS_REGISTER_IP , ZYDIS_REGISTER_EIP , ZYDIS_REGISTER_RIP },
};
ZYAN_ASSERT(reg_class < ZYAN_ARRAY_LENGTH(STATIC_MAPPING));
ZyanU8 mode_bits;
switch (mode)
{
case ZYDIS_MACHINE_MODE_LONG_64:
mode_bits = 2;
break;
case ZYDIS_MACHINE_MODE_LONG_COMPAT_32:
case ZYDIS_MACHINE_MODE_LEGACY_32:
mode_bits = 1;
break;
case ZYDIS_MACHINE_MODE_LONG_COMPAT_16:
case ZYDIS_MACHINE_MODE_LEGACY_16:
case ZYDIS_MACHINE_MODE_REAL_16:
mode_bits = 0;
break;
default:
ZYAN_UNREACHABLE;
}
const ZydisRegister static_reg = STATIC_MAPPING[reg_class][mode_bits];
if (static_reg != ZYDIS_REGISTER_NONE)
{
return static_reg;
}
static const ZyanU8 GPR8_MAPPING[20] =
{
/* AL */ 0,
......@@ -177,16 +223,9 @@ ZydisRegister ZydisRegisterGetLargestEnclosing(ZydisMachineMode mode, ZydisRegis
/* R12B */ 12,
/* R13B */ 13,
/* R14B */ 14,
/* R15B */ 15,
/* R15B */ 15
};
const ZydisRegisterClass reg_class = REG_LOOKUP[reg].class;
if ((reg_class == ZYDIS_REGCLASS_INVALID) ||
((reg_class == ZYDIS_REGCLASS_GPR64) && (mode != ZYDIS_MACHINE_MODE_LONG_64)))
{
return ZYDIS_REGISTER_NONE;
}
ZyanU8 reg_id = REG_LOOKUP[reg].id;
switch (reg_class)
{
......@@ -196,19 +235,16 @@ ZydisRegister ZydisRegisterGetLargestEnclosing(ZydisMachineMode mode, ZydisRegis
case ZYDIS_REGCLASS_GPR16:
case ZYDIS_REGCLASS_GPR32:
case ZYDIS_REGCLASS_GPR64:
switch (mode)
switch (mode_bits)
{
case ZYDIS_MACHINE_MODE_LONG_64:
case 2:
return REG_CLASS_LOOKUP[ZYDIS_REGCLASS_GPR64].lo + reg_id;
case ZYDIS_MACHINE_MODE_LONG_COMPAT_32:
case ZYDIS_MACHINE_MODE_LEGACY_32:
case 1:
return REG_CLASS_LOOKUP[ZYDIS_REGCLASS_GPR32].lo + reg_id;
case ZYDIS_MACHINE_MODE_LONG_COMPAT_16:
case ZYDIS_MACHINE_MODE_LEGACY_16:
case ZYDIS_MACHINE_MODE_REAL_16:
case 0:
return REG_CLASS_LOOKUP[ZYDIS_REGCLASS_GPR16].lo + reg_id;
default:
return ZYDIS_REGISTER_NONE;
ZYAN_UNREACHABLE;
}
case ZYDIS_REGCLASS_XMM:
case ZYDIS_REGCLASS_YMM:
......
......@@ -141,19 +141,24 @@ void ZydisGetElementInfo(ZydisInternalElementType element, ZydisElementType* typ
{ ZYDIS_ELEMENT_TYPE_UINT , 0 },
{ ZYDIS_ELEMENT_TYPE_INT , 1 },
{ ZYDIS_ELEMENT_TYPE_INT , 8 },
{ ZYDIS_ELEMENT_TYPE_INT , 32 }, // TODO: Should indicate 4 INT8 elements
{ ZYDIS_ELEMENT_TYPE_INT , 16 },
{ ZYDIS_ELEMENT_TYPE_INT , 32 }, // TODO: Should indicate 2 INT16 elements
{ ZYDIS_ELEMENT_TYPE_INT , 32 },
{ ZYDIS_ELEMENT_TYPE_INT , 64 },
{ ZYDIS_ELEMENT_TYPE_UINT , 8 },
{ ZYDIS_ELEMENT_TYPE_UINT , 32 }, // TODO: Should indicate 4 UINT8 elements
{ ZYDIS_ELEMENT_TYPE_UINT , 16 },
{ ZYDIS_ELEMENT_TYPE_UINT , 32 }, // TODO: Should indicate 2 UINT16 elements
{ ZYDIS_ELEMENT_TYPE_UINT , 32 },
{ ZYDIS_ELEMENT_TYPE_UINT , 64 },
{ ZYDIS_ELEMENT_TYPE_UINT , 128 },
{ ZYDIS_ELEMENT_TYPE_UINT , 256 },
{ ZYDIS_ELEMENT_TYPE_FLOAT16 , 16 },
{ ZYDIS_ELEMENT_TYPE_FLOAT16 , 32 }, // TODO: Should indicate 2 float16 elements
{ ZYDIS_ELEMENT_TYPE_FLOAT16 , 32 }, // TODO: Should indicate 2 FLOAT16 elements
{ ZYDIS_ELEMENT_TYPE_FLOAT32 , 32 },
{ ZYDIS_ELEMENT_TYPE_FLOAT64 , 64 },
{ ZYDIS_ELEMENT_TYPE_BFLOAT16 , 32 }, // TODO: Should indicate 2 BFLOAT16 elements
{ ZYDIS_ELEMENT_TYPE_FLOAT80 , 80 },
{ ZYDIS_ELEMENT_TYPE_LONGBCD , 80 },
{ ZYDIS_ELEMENT_TYPE_CC , 3 },
......
......@@ -66,7 +66,7 @@ static const char* const DECIMAL_LOOKUP =
/* ---------------------------------------------------------------------------------------------- */
#if defined(ZYAN_X86) || defined(ZYAN_ARM) || defined(ZYAN_EMSCRIPTEN) || defined(ZYAN_WASM) || defined(ZYAN_PPC)
ZyanStatus ZydisStringAppendDecU32(ZyanString* string, ZyanU32 value, ZyanU8 padding_length)
static ZyanStatus ZydisStringAppendDecU32(ZyanString* string, ZyanU32 value, ZyanU8 padding_length)
{
ZYAN_ASSERT(string);
ZYAN_ASSERT(!string->vector.allocator);
......@@ -110,7 +110,7 @@ ZyanStatus ZydisStringAppendDecU32(ZyanString* string, ZyanU32 value, ZyanU8 pad
}
#endif
ZyanStatus ZydisStringAppendDecU64(ZyanString* string, ZyanU64 value, ZyanU8 padding_length)
static ZyanStatus ZydisStringAppendDecU64(ZyanString* string, ZyanU64 value, ZyanU8 padding_length)
{
ZYAN_ASSERT(string);
ZYAN_ASSERT(!string->vector.allocator);
......@@ -122,7 +122,7 @@ ZyanStatus ZydisStringAppendDecU64(ZyanString* string, ZyanU64 value, ZyanU8 pad
{
const ZyanU64 value_old = value;
buffer_write_pointer -= 2;
value /= 100;
ZYAN_DIV64(value, 100);
ZYAN_MEMCPY(buffer_write_pointer, &DECIMAL_LOOKUP[(value_old - (value * 100)) * 2], 2);
}
buffer_write_pointer -= 2;
......@@ -158,7 +158,7 @@ ZyanStatus ZydisStringAppendDecU64(ZyanString* string, ZyanU64 value, ZyanU8 pad
/* ---------------------------------------------------------------------------------------------- */
#if defined(ZYAN_X86) || defined(ZYAN_ARM) || defined(ZYAN_EMSCRIPTEN) || defined(ZYAN_WASM) || defined(ZYAN_PPC)
ZyanStatus ZydisStringAppendHexU32(ZyanString* string, ZyanU32 value, ZyanU8 padding_length,
static ZyanStatus ZydisStringAppendHexU32(ZyanString* string, ZyanU32 value, ZyanU8 padding_length,
ZyanBool force_leading_number, ZyanBool uppercase)
{
ZYAN_ASSERT(string);
......@@ -231,7 +231,7 @@ ZyanStatus ZydisStringAppendHexU32(ZyanString* string, ZyanU32 value, ZyanU8 pad
}
#endif
ZyanStatus ZydisStringAppendHexU64(ZyanString* string, ZyanU64 value, ZyanU8 padding_length,
static ZyanStatus ZydisStringAppendHexU64(ZyanString* string, ZyanU64 value, ZyanU8 padding_length,
ZyanBool force_leading_number, ZyanBool uppercase)
{
ZYAN_ASSERT(string);
......@@ -322,7 +322,7 @@ ZyanStatus ZydisStringAppendDecU(ZyanString* string, ZyanU64 value, ZyanU8 paddi
ZYAN_CHECK(ZydisStringAppend(string, prefix));
}
#if defined(ZYAN_X64) || defined(ZYAN_AARCH64) || defined(ZYAN_PPC64) || defined(ZYAN_RISCV64)
#if defined(ZYAN_X64) || defined(ZYAN_AARCH64) || defined(ZYAN_PPC64) || defined(ZYAN_RISCV64) || defined(ZYAN_LOONGARCH)
ZYAN_CHECK(ZydisStringAppendDecU64(string, value, padding_length));
#else
if (value & 0xFFFFFFFF00000000)
......@@ -348,7 +348,7 @@ ZyanStatus ZydisStringAppendHexU(ZyanString* string, ZyanU64 value, ZyanU8 paddi
ZYAN_CHECK(ZydisStringAppend(string, prefix));
}
#if defined(ZYAN_X64) || defined(ZYAN_AARCH64) || defined(ZYAN_PPC64) || defined(ZYAN_RISCV64)
#if defined(ZYAN_X64) || defined(ZYAN_AARCH64) || defined(ZYAN_PPC64) || defined(ZYAN_RISCV64) || defined(ZYAN_LOONGARCH)
ZYAN_CHECK(ZydisStringAppendHexU64(string, value, padding_length, force_leading_number,
uppercase));
#else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment