From 4d3a71369b77bc7bf3e773a732282008886c6cd9 Mon Sep 17 00:00:00 2001 From: flobernd Date: Thu, 22 Jun 2017 19:54:35 +0200 Subject: [PATCH] Removed EVEX tuple-type and element-size from the public info-struct --- include/Zydis/InstructionInfo.h | 102 ++++------------------ include/Zydis/Internal/InstructionTable.h | 77 +++++++++++++++- src/Decoder.c | 69 +++++++++------ 3 files changed, 132 insertions(+), 116 deletions(-) diff --git a/include/Zydis/InstructionInfo.h b/include/Zydis/InstructionInfo.h index 8f5d94a..31315cc 100644 --- a/include/Zydis/InstructionInfo.h +++ b/include/Zydis/InstructionInfo.h @@ -708,83 +708,6 @@ enum ZydisVectorLengths ZYDIS_VECTOR_LENGTH_512 = 512 }; -/* ---------------------------------------------------------------------------------------------- */ -/* EVEX tuple-type */ -/* ---------------------------------------------------------------------------------------------- */ - -/** - * @brief Defines the @c ZydisTupleType datatype. - */ -typedef uint8_t ZydisTupleType; - -/** - * @brief Values that represent EVEX tuple-types. - */ -enum ZydisTupleTypes -{ - ZYDIS_TUPLETYPE_INVALID, - /** - * @brief Full Vector - */ - ZYDIS_TUPLETYPE_FV, - /** - * @brief Half Vector - */ - ZYDIS_TUPLETYPE_HV, - /** - * @brief Full Vector Mem - */ - ZYDIS_TUPLETYPE_FVM, - /** - * @brief Tuple1 Scalar - */ - ZYDIS_TUPLETYPE_T1S, - /** - * @brief Tuple1 Fixed - */ - ZYDIS_TUPLETYPE_T1F, - /** - * @brief Tuple1 4x32 - */ - ZYDIS_TUPLETYPE_T1_4X, - /** - * @brief Gather / Scatter - */ - ZYDIS_TUPLETYPE_GSCAT, - /** - * @brief Tuple2 - */ - ZYDIS_TUPLETYPE_T2, - /** - * @brief Tuple4 - */ - ZYDIS_TUPLETYPE_T4, - /** - * @brief Tuple8 - */ - ZYDIS_TUPLETYPE_T8, - /** - * @brief Half Mem - */ - ZYDIS_TUPLETYPE_HVM, - /** - * @brief QuarterMem - */ - ZYDIS_TUPLETYPE_QVM, - /** - * @brief OctMem - */ - ZYDIS_TUPLETYPE_OVM, - /** - * @brief Mem128 - */ - ZYDIS_TUPLETYPE_M128, - /** - * @brief MOVDDUP - */ - ZYDIS_TUPLETYPE_DUP -}; - /* ---------------------------------------------------------------------------------------------- */ /* AVX mask mode */ /* ---------------------------------------------------------------------------------------------- */ @@ -1007,14 +930,6 @@ typedef struct ZydisInstructionInfo_ * @brief The AVX vector-length. */ ZydisVectorLength vectorLength; - /** - * @brief The AVX tuple-type (EVEX only). - */ - ZydisTupleType tupleType; - /** - * @brief The AVX element-size. - */ - uint8_t elementSize; /** * @brief The scale-factor for compressed 8-bit displacement values. */ @@ -1031,13 +946,26 @@ typedef struct ZydisInstructionInfo_ * @brief The AVX rounding-mode. */ ZydisRoundingMode roundingMode; + /** + * @brief The AVX register-swizzle mode (MVEX only). + */ + ZydisSwizzleMode swizzleMode; + /** + * @brief The AVX data-conversion mode (MVEX only). + */ + ZydisConversionMode conversionMode; // TODO: Remove SAE from the rounding-mode enum and always add it as extra value + /** + * @brief Signals, if the sae functionality is enabled for the instruction. + */ ZydisBool hasSAE; + /** + * @brief Signals, if the instruction has a memory eviction-hint (MVEX only). + */ ZydisBool hasEvictionHint; - ZydisSwizzleMode swizzleMode; - ZydisConversionMode conversionMode; + } avx; /** * @brief Extended info about different instruction-parts like ModRM, SIB or diff --git a/include/Zydis/Internal/InstructionTable.h b/include/Zydis/Internal/InstructionTable.h index 5614bca..8ff94e2 100644 --- a/include/Zydis/Internal/InstructionTable.h +++ b/include/Zydis/Internal/InstructionTable.h @@ -355,6 +355,81 @@ enum ZydisEVEXFunctionalities /* ---------------------------------------------------------------------------------------------- */ +/** + * @brief Defines the @c ZydisEVEXTupleType datatype. + */ +typedef uint8_t ZydisEVEXTupleType; + +/** + * @brief Values that represent EVEX tuple-types. + */ +enum ZydisEVEXTupleTypes +{ + ZYDIS_TUPLETYPE_INVALID, + /** + * @brief Full Vector + */ + ZYDIS_TUPLETYPE_FV, + /** + * @brief Half Vector + */ + ZYDIS_TUPLETYPE_HV, + /** + * @brief Full Vector Mem + */ + ZYDIS_TUPLETYPE_FVM, + /** + * @brief Tuple1 Scalar + */ + ZYDIS_TUPLETYPE_T1S, + /** + * @brief Tuple1 Fixed + */ + ZYDIS_TUPLETYPE_T1F, + /** + * @brief Tuple1 4x32 + */ + ZYDIS_TUPLETYPE_T1_4X, + /** + * @brief Gather / Scatter + */ + ZYDIS_TUPLETYPE_GSCAT, + /** + * @brief Tuple2 + */ + ZYDIS_TUPLETYPE_T2, + /** + * @brief Tuple4 + */ + ZYDIS_TUPLETYPE_T4, + /** + * @brief Tuple8 + */ + ZYDIS_TUPLETYPE_T8, + /** + * @brief Half Mem + */ + ZYDIS_TUPLETYPE_HVM, + /** + * @brief QuarterMem + */ + ZYDIS_TUPLETYPE_QVM, + /** + * @brief OctMem + */ + ZYDIS_TUPLETYPE_OVM, + /** + * @brief Mem128 + */ + ZYDIS_TUPLETYPE_M128, + /** + * @brief MOVDDUP + */ + ZYDIS_TUPLETYPE_DUP +}; + +/* ---------------------------------------------------------------------------------------------- */ + /** * @brief Defines the @c ZydisMVEXFunctionality datatype. */ @@ -510,7 +585,7 @@ typedef struct ZydisInstructionDefinitionEVEX_ { ZYDIS_INSTRUCTION_DEFINITION_BASE; ZydisInternalVectorLength vectorLength: 2; - ZydisTupleType tupleType : 4; + ZydisEVEXTupleType tupleType : 4; ZydisInternalElementSize elementSize : 4; ZydisEVEXFunctionality functionality : 2; ZydisMaskPolicy maskPolicy : 2; diff --git a/src/Decoder.c b/src/Decoder.c index 218ca68..abac8c8 100644 --- a/src/Decoder.c +++ b/src/Decoder.c @@ -97,14 +97,28 @@ typedef struct ZydisDecoderContext_ uint8_t v_vvvv; uint8_t mask; } cache; - + /** + * @brief Internal EVEX-specific information. + */ struct { - int dummy; + /** + * @brief The EVEX tuple-type. + */ + ZydisEVEXTupleType tupleType; + /** + * @brief The EVEX element-size. + */ + uint8_t elementSize; } evex; - + /** + * @brief Internal MVEX-specific information. + */ struct { + /** + * @brief The MVEX functionality. + */ ZydisMVEXFunctionality functionality; } mvex; } ZydisDecoderContext; @@ -992,13 +1006,13 @@ static void ZydisSetOperandSizeAndElementInfo(ZydisDecoderContext* context, // Operand size depends on the tuple-type, the element-size and the number of // elements ZYDIS_ASSERT(info->avx.vectorLength); - ZYDIS_ASSERT(info->avx.elementSize); - switch (info->avx.tupleType) + ZYDIS_ASSERT(context->evex.elementSize); + switch (context->evex.tupleType) { case ZYDIS_TUPLETYPE_FV: if (info->avx.broadcastMode) { - operand->size = info->avx.elementSize; + operand->size = context->evex.elementSize; } else { operand->size = info->avx.vectorLength; @@ -1007,7 +1021,7 @@ static void ZydisSetOperandSizeAndElementInfo(ZydisDecoderContext* context, case ZYDIS_TUPLETYPE_HV: if (info->avx.broadcastMode) { - operand->size = info->avx.elementSize; + operand->size = context->evex.elementSize; } else { operand->size = info->avx.vectorLength / 2; @@ -2263,8 +2277,8 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, ZYDIS_UNREACHABLE; } - info->avx.tupleType = def->tupleType; - if (info->avx.tupleType) + context->evex.tupleType = def->tupleType; + if (def->tupleType) { ZYDIS_ASSERT(info->details.modrm.mod != 3); ZYDIS_ASSERT(def->elementSize); @@ -2273,23 +2287,23 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, switch (def->elementSize) { case ZYDIS_IELEMENT_SIZE_8: - info->avx.elementSize = 8; + context->evex.elementSize = 8; break; case ZYDIS_IELEMENT_SIZE_16: - info->avx.elementSize = 16; + context->evex.elementSize = 16; break; case ZYDIS_IELEMENT_SIZE_32: - info->avx.elementSize = 32; + context->evex.elementSize = 32; break; case ZYDIS_IELEMENT_SIZE_64: - info->avx.elementSize = 64; + context->evex.elementSize = 64; break; default: ZYDIS_UNREACHABLE; } // Compressed disp8 scale and broadcast-factor - switch (info->avx.tupleType) + switch (def->tupleType) { case ZYDIS_TUPLETYPE_FV: switch (info->details.evex.b) @@ -2315,7 +2329,7 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, switch (context->cache.W) { case 0: - ZYDIS_ASSERT(info->avx.elementSize == 32); + ZYDIS_ASSERT(context->evex.elementSize == 32); info->avx.compressedDisp8Scale = 4; switch (info->avx.vectorLength) { @@ -2333,7 +2347,7 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, } break; case 1: - ZYDIS_ASSERT(info->avx.elementSize == 64); + ZYDIS_ASSERT(context->evex.elementSize == 64); info->avx.compressedDisp8Scale = 8; switch (info->avx.vectorLength) { @@ -2359,7 +2373,7 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, } break; case ZYDIS_TUPLETYPE_HV: - ZYDIS_ASSERT(info->avx.elementSize == 32); + ZYDIS_ASSERT(context->evex.elementSize == 32); switch (info->details.evex.b) { case 0: @@ -2419,19 +2433,19 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, switch (context->cache.W) { case 0: - ZYDIS_ASSERT(info->avx.elementSize == 32); + ZYDIS_ASSERT(context->evex.elementSize == 32); break; case 1: - ZYDIS_ASSERT(info->avx.elementSize == 64); + ZYDIS_ASSERT(context->evex.elementSize == 64); break; default: ZYDIS_UNREACHABLE; } case ZYDIS_TUPLETYPE_T1S: - info->avx.compressedDisp8Scale = info->avx.elementSize / 8; + info->avx.compressedDisp8Scale = context->evex.elementSize / 8; break; case ZYDIS_TUPLETYPE_T1F: - switch (info->avx.elementSize) + switch (context->evex.elementSize) { case 32: info->avx.compressedDisp8Scale = 4; @@ -2444,7 +2458,7 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, } break; case ZYDIS_TUPLETYPE_T1_4X: - ZYDIS_ASSERT(info->avx.elementSize == 32); + ZYDIS_ASSERT(context->evex.elementSize == 32); ZYDIS_ASSERT(context->cache.W == 0); info->avx.compressedDisp8Scale = 16; break; @@ -2452,11 +2466,11 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, switch (context->cache.W) { case 0: - ZYDIS_ASSERT(info->avx.elementSize == 32); + ZYDIS_ASSERT(context->evex.elementSize == 32); info->avx.compressedDisp8Scale = 8; break; case 1: - ZYDIS_ASSERT(info->avx.elementSize == 64); + ZYDIS_ASSERT(context->evex.elementSize == 64); ZYDIS_ASSERT((info->avx.vectorLength == 256) || (info->avx.vectorLength == 512)); info->avx.compressedDisp8Scale = 16; @@ -2469,13 +2483,13 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, switch (context->cache.W) { case 0: - ZYDIS_ASSERT(info->avx.elementSize == 32); + ZYDIS_ASSERT(context->evex.elementSize == 32); ZYDIS_ASSERT((info->avx.vectorLength == 256) || (info->avx.vectorLength == 512)); info->avx.compressedDisp8Scale = 16; break; case 1: - ZYDIS_ASSERT(info->avx.elementSize == 64); + ZYDIS_ASSERT(context->evex.elementSize == 64); ZYDIS_ASSERT(info->avx.vectorLength == 512); info->avx.compressedDisp8Scale = 32; break; @@ -2486,7 +2500,7 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, case ZYDIS_TUPLETYPE_T8: ZYDIS_ASSERT(!context->cache.W); ZYDIS_ASSERT(info->avx.vectorLength == 512); - ZYDIS_ASSERT(info->avx.elementSize == 32); + ZYDIS_ASSERT(context->evex.elementSize == 32); info->avx.compressedDisp8Scale = 32; break; case ZYDIS_TUPLETYPE_HVM: @@ -2598,7 +2612,6 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context, (const ZydisInstructionDefinitionMVEX*)definition; // Compressed disp8 scale - info->avx.compressedDisp8Scale = 1; switch (def->functionality) { case ZYDIS_MVEX_FUNC_INVALID: