From a80aa466a77e80cb456309449c197360240d3b3d Mon Sep 17 00:00:00 2001 From: Florian Bernd Date: Wed, 30 Oct 2024 21:55:30 +0100 Subject: [PATCH] Move apx info --- include/Zydis/DecoderTypes.h | 31 ++++++++++++++++-------- src/Decoder.c | 6 ++--- tools/ZydisInfo.c | 46 +++++++++++++++++++++++++++++++++--- 3 files changed, 67 insertions(+), 16 deletions(-) diff --git a/include/Zydis/DecoderTypes.h b/include/Zydis/DecoderTypes.h index 8ef3aeb3..3c7a3312 100644 --- a/include/Zydis/DecoderTypes.h +++ b/include/Zydis/DecoderTypes.h @@ -1207,26 +1207,33 @@ typedef struct ZydisDecodedInstructionAvx_ * Signals, if the instruction has a memory-eviction-hint (`KNC` only). */ ZyanBool has_eviction_hint; - /** - * The AVX-512 APX source condition code. - */ - ZydisSourceConditionCode apx_scc; + // TODO: publish EVEX tuple-type and MVEX functionality +} ZydisDecodedInstructionAvx; + +/** + * Extended info for `APX` instructions. + */ +typedef struct ZydisDecodedInstructionApx_ +{ /** * Signals, if the APX `no flags` functionality enabled for the instruction. */ - ZyanBool has_apx_nf; + ZyanBool has_nf; /** * Signals, if the APX `zero upper` functionality enabled for the instruction. */ - ZyanBool has_apx_zu; + ZyanBool has_zu; /** * Signals, if the APX push/pop performance-hint (`PPX`) is enabled for the instruction. * - * This flag is only valid for `push2` and `pop2`. + * This flag is only valid for `push2p` and `pop2p`. */ - ZyanBool has_apx_ppx; - // TODO: publish EVEX tuple-type and MVEX functionality -} ZydisDecodedInstructionAvx; + ZyanBool has_ppx; + /** + * The AVX-512 APX source condition code. + */ + ZydisSourceConditionCode scc; +} ZydisDecodedInstructionApx; /** * Instruction meta info. @@ -1481,6 +1488,10 @@ typedef struct ZydisDecodedInstruction_ * Extended info for `AVX` instructions. */ ZydisDecodedInstructionAvx avx; + /** + * Extended info for `APX` instructions. + */ + ZydisDecodedInstructionApx apx; /** * Meta info. */ diff --git a/src/Decoder.c b/src/Decoder.c index 8a02caf5..5098016f 100644 --- a/src/Decoder.c +++ b/src/Decoder.c @@ -4408,7 +4408,7 @@ static ZyanStatus ZydisNodeHandlerEvexSCC(ZydisDecoderContext* context, context->vector_unified.vvvv = (~context->vector_unified.vvvv) & 0x0F; context->vector_unified.V4 = 0; - instruction->avx.apx_scc = ZYDIS_SCC_O + instruction->raw.evex.SCC; + instruction->apx.scc = ZYDIS_SCC_O + instruction->raw.evex.SCC; *index = instruction->raw.evex.SCC; return ZYAN_STATUS_SUCCESS; @@ -5211,8 +5211,8 @@ static ZyanStatus ZydisDecodeInstruction(ZydisDecoderState* state, instruction->attributes |= ZYDIS_ATTRIB_HAS_EEVEX; } - instruction->avx.has_apx_nf = evex_definition->has_apx_nf; - instruction->avx.has_apx_zu = evex_definition->has_apx_zu; + instruction->apx.has_nf = evex_definition->has_apx_nf; + instruction->apx.has_zu = evex_definition->has_apx_zu; } instruction->mnemonic = definition->mnemonic; diff --git a/tools/ZydisInfo.c b/tools/ZydisInfo.c index b6bdf06e..8a81e6ab 100644 --- a/tools/ZydisInfo.c +++ b/tools/ZydisInfo.c @@ -815,9 +815,6 @@ static void PrintAVXInfo(const ZydisDecodedInstruction* instruction) ZydisRegisterGetString(instruction->avx.mask.reg), CVT100_OUT(COLOR_VALUE_LABEL), CVT100_OUT(COLOR_VALUE_B), strings_mask_mode[instruction->avx.mask.mode], CVT100_OUT(COLOR_VALUE_LABEL)); - PRINT_VALUE_B("APX_NF", "%s", instruction->avx.has_apx_nf ? "Y" : "N"); - PRINT_VALUE_B("APX_ZU", "%s", instruction->avx.has_apx_zu ? "Y" : "N"); - PRINT_VALUE_B("APX_SCC", "%s", strings_scc[instruction->avx.apx_scc]); break; case ZYDIS_INSTRUCTION_ENCODING_MVEX: PRINT_VALUE_B("ROUNDING", "%s", strings_rounding_mode[instruction->avx.rounding.mode]); @@ -835,6 +832,42 @@ static void PrintAVXInfo(const ZydisDecodedInstruction* instruction) } } +/** + * Prints instruction APX info. + * + * @param instruction A pointer to the `ZydisDecodedInstruction` struct. + */ +static void PrintAPXInfo(const ZydisDecodedInstruction* instruction) +{ + static const char* strings_scc[] = + { + "NONE", + "O", + "NO", + "B", + "NB", + "Z", + "NZ", + "BE", + "NBE", + "S", + "NS", + "TRUE", + "FALSE", + "L", + "NL", + "LE", + "NLE" + }; + ZYAN_STATIC_ASSERT(ZYAN_ARRAY_LENGTH(strings_scc) == ZYDIS_SCC_MAX_VALUE + 1); + + PrintSectionHeader("APX"); + + PRINT_VALUE_B("NF", "%s", instruction->apx.has_nf ? "Y" : "N"); + PRINT_VALUE_B("ZU", "%s", instruction->apx.has_zu ? "Y" : "N"); + PRINT_VALUE_B("SCC", "%s", strings_scc[instruction->apx.scc]); +} + /** * Prints the formatted instruction disassembly. * @@ -1145,6 +1178,13 @@ static void PrintInstruction(const ZydisDecoder* decoder, PrintAVXInfo(instruction); } + if ((instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_REX2) || + (instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_EVEX)) + { + ZYAN_PUTS(""); + PrintAPXInfo(instruction); + } + ZYAN_PUTS(""); PrintDisassembly(instruction, operands, ZYDIS_FORMATTER_STYLE_ATT); ZYAN_PUTS("");