Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed scc handling #528

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 18 additions & 25 deletions include/Zydis/DecoderTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -718,27 +718,24 @@ typedef enum ZydisConversionMode_
*/
typedef enum ZydisSourceConditionCode_
{
ZYDIS_SCC_O = 0,
ZYDIS_SCC_NO = 1,
ZYDIS_SCC_B = 2,
ZYDIS_SCC_NB = 3,
ZYDIS_SCC_Z = 4,
ZYDIS_SCC_NZ = 5,
ZYDIS_SCC_BE = 6,
ZYDIS_SCC_NBE = 7,
ZYDIS_SCC_S = 8,
ZYDIS_SCC_NS = 9,
ZYDIS_SCC_TRUE = 10,
ZYDIS_SCC_FALSE = 11,
ZYDIS_SCC_L = 12,
ZYDIS_SCC_NL = 13,
ZYDIS_SCC_LE = 14,
ZYDIS_SCC_NLE = 15,

/**
* Minimum value of this enum.
*/
ZYDIS_SCC_MIN_VALUE = ZYDIS_SCC_O,
ZYDIS_SCC_INVALID,
ZYDIS_SCC_O,
ZYDIS_SCC_NO,
ZYDIS_SCC_B,
ZYDIS_SCC_NB,
ZYDIS_SCC_Z,
ZYDIS_SCC_NZ,
ZYDIS_SCC_BE,
ZYDIS_SCC_NBE,
ZYDIS_SCC_S,
ZYDIS_SCC_NS,
ZYDIS_SCC_TRUE,
ZYDIS_SCC_FALSE,
ZYDIS_SCC_L,
ZYDIS_SCC_NL,
ZYDIS_SCC_LE,
ZYDIS_SCC_NLE,

/**
* Maximum value of this enum.
*/
Expand Down Expand Up @@ -1194,10 +1191,6 @@ typedef struct ZydisDecodedInstructionAvx_
ZyanBool has_eviction_hint;
/**
* The AVX-512 APX source condition code.
*
* The `scc` field contains the actual value of the `EVEX.scc` field and therefore defaults
* to `ZYDIS_SCC_O`. Please check for the `ZYDIS_ATTRIB_HAS_SCC` attribute to determine if
* the instruction actually uses the source condition code.
*/
ZydisSourceConditionCode scc;
// TODO: publish EVEX tuple-type and MVEX functionality
Expand Down
2 changes: 1 addition & 1 deletion src/Decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -4394,7 +4394,7 @@ static ZyanStatus ZydisNodeHandlerEvexSCC(ZydisDecoderContext* context,
context->vector_unified.V4 = 0;

instruction->attributes |= ZYDIS_ATTRIB_HAS_SCC;
instruction->avx.scc = ZYDIS_SCC_MIN_VALUE + context->vector_unified.vvvv;
instruction->avx.scc = ZYDIS_SCC_O + instruction->raw.evex.SCC;

*index = instruction->raw.evex.SCC;
return ZYAN_STATUS_SUCCESS;
Expand Down
1 change: 1 addition & 0 deletions src/SharedData.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ void ZydisGetElementInfo(ZydisInternalElementType element, ZydisElementType* typ
{ ZYDIS_ELEMENT_TYPE_INT , 32 }, // TODO: Should indicate 2 INT16 elements
{ ZYDIS_ELEMENT_TYPE_INT , 32 },
{ ZYDIS_ELEMENT_TYPE_INT , 64 },
{ ZYDIS_ELEMENT_TYPE_INT , 128 },
{ ZYDIS_ELEMENT_TYPE_UINT , 8 },
{ ZYDIS_ELEMENT_TYPE_UINT , 32 }, // TODO: Should indicate 4 UINT8 elements
{ ZYDIS_ELEMENT_TYPE_UINT , 16 },
Expand Down
36 changes: 21 additions & 15 deletions tools/ZydisInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ static void PrintOperands(const ZydisDecodedInstruction* instruction,
"POINTER",
"IMMEDIATE"
};
ZYAN_ASSERT(ZYAN_ARRAY_LENGTH(strings_operand_type) == ZYDIS_OPERAND_TYPE_MAX_VALUE + 1);
ZYAN_STATIC_ASSERT(
ZYAN_ARRAY_LENGTH(strings_operand_type) == ZYDIS_OPERAND_TYPE_MAX_VALUE + 1);

static const char* strings_operand_visibility[] =
{
Expand All @@ -412,7 +413,8 @@ static void PrintOperands(const ZydisDecodedInstruction* instruction,
"IMPLICIT",
"HIDDEN"
};
ZYAN_ASSERT(ZYAN_ARRAY_LENGTH(strings_operand_visibility) == ZYDIS_OPERAND_VISIBILITY_MAX_VALUE + 1);
ZYAN_STATIC_ASSERT(ZYAN_ARRAY_LENGTH(strings_operand_visibility) ==
ZYDIS_OPERAND_VISIBILITY_MAX_VALUE + 1);

static const char* strings_operand_actions[] =
{
Expand Down Expand Up @@ -447,7 +449,8 @@ static void PrintOperands(const ZydisDecodedInstruction* instruction,
"LONGBCD",
"CC"
};
ZYAN_ASSERT(ZYAN_ARRAY_LENGTH(strings_element_type) == ZYDIS_ELEMENT_TYPE_MAX_VALUE + 1);
ZYAN_STATIC_ASSERT(
ZYAN_ARRAY_LENGTH(strings_element_type) == ZYDIS_ELEMENT_TYPE_MAX_VALUE + 1);

static const char* strings_operand_encoding[] =
{
Expand Down Expand Up @@ -487,7 +490,8 @@ static void PrintOperands(const ZydisDecodedInstruction* instruction,
"JIMM32_32_64",
"JIMM16_32_32"
};
ZYAN_ASSERT(ZYAN_ARRAY_LENGTH(strings_operand_encoding) == ZYDIS_OPERAND_ENCODING_MAX_VALUE + 1);
ZYAN_STATIC_ASSERT(
ZYAN_ARRAY_LENGTH(strings_operand_encoding) == ZYDIS_OPERAND_ENCODING_MAX_VALUE + 1);

static const char* strings_memop_type[] =
{
Expand All @@ -497,7 +501,7 @@ static void PrintOperands(const ZydisDecodedInstruction* instruction,
"MIB",
"VSIB"
};
ZYAN_ASSERT(ZYAN_ARRAY_LENGTH(strings_memop_type) == ZYDIS_MEMOP_TYPE_MAX_VALUE + 1);
ZYAN_STATIC_ASSERT(ZYAN_ARRAY_LENGTH(strings_memop_type) == ZYDIS_MEMOP_TYPE_MAX_VALUE + 1);

ZYAN_PRINTF("%s%2d %s%9s %10s %6s %12s %s%5d %4d %6d %s%8s%s",
CVT100_OUT(COLOR_VALUE_G),
Expand Down Expand Up @@ -718,7 +722,7 @@ static void PrintAVXInfo(const ZydisDecodedInstruction* instruction)
"4_TO_16",
"8_TO_16"
};
ZYAN_ASSERT(ZYAN_ARRAY_LENGTH(strings_broadcast_mode) == ZYDIS_BROADCAST_MODE_MAX_VALUE + 1);
ZYAN_STATIC_ASSERT(ZYAN_ARRAY_LENGTH(strings_broadcast_mode) == ZYDIS_BROADCAST_MODE_MAX_VALUE + 1);

static const char* strings_mask_mode[] =
{
Expand All @@ -729,7 +733,7 @@ static void PrintAVXInfo(const ZydisDecodedInstruction* instruction)
"CONTROL",
"CONTROL_ZEROING"
};
ZYAN_ASSERT(ZYAN_ARRAY_LENGTH(strings_mask_mode) == ZYDIS_MASK_MODE_MAX_VALUE + 1);
ZYAN_STATIC_ASSERT(ZYAN_ARRAY_LENGTH(strings_mask_mode) == ZYDIS_MASK_MODE_MAX_VALUE + 1);

static const char* strings_rounding_mode[] =
{
Expand All @@ -739,7 +743,7 @@ static void PrintAVXInfo(const ZydisDecodedInstruction* instruction)
"RU",
"RZ"
};
ZYAN_ASSERT(ZYAN_ARRAY_LENGTH(strings_rounding_mode) == ZYDIS_ROUNDING_MODE_MAX_VALUE + 1);
ZYAN_STATIC_ASSERT(ZYAN_ARRAY_LENGTH(strings_rounding_mode) == ZYDIS_ROUNDING_MODE_MAX_VALUE + 1);

static const char* strings_swizzle_mode[] =
{
Expand All @@ -753,7 +757,7 @@ static void PrintAVXInfo(const ZydisDecodedInstruction* instruction)
"CCCC",
"DDDD"
};
ZYAN_ASSERT(ZYAN_ARRAY_LENGTH(strings_swizzle_mode) == ZYDIS_SWIZZLE_MODE_MAX_VALUE + 1);
ZYAN_STATIC_ASSERT(ZYAN_ARRAY_LENGTH(strings_swizzle_mode) == ZYDIS_SWIZZLE_MODE_MAX_VALUE + 1);

static const char* strings_conversion_mode[] =
{
Expand All @@ -764,10 +768,11 @@ static void PrintAVXInfo(const ZydisDecodedInstruction* instruction)
"SINT16",
"UINT16"
};
ZYAN_ASSERT(ZYAN_ARRAY_LENGTH(strings_conversion_mode) == ZYDIS_CONVERSION_MODE_MAX_VALUE + 1);
ZYAN_STATIC_ASSERT(ZYAN_ARRAY_LENGTH(strings_conversion_mode) == ZYDIS_CONVERSION_MODE_MAX_VALUE + 1);

static const char* strings_scc[] =
{
"INVALID",
"O",
"NO",
"B",
Expand All @@ -785,7 +790,7 @@ static void PrintAVXInfo(const ZydisDecodedInstruction* instruction)
"LE",
"NLE"
};
ZYAN_ASSERT(ZYAN_ARRAY_LENGTH(strings_scc) == ZYDIS_SCC_MAX_VALUE + 1);
ZYAN_STATIC_ASSERT(ZYAN_ARRAY_LENGTH(strings_scc) == ZYDIS_SCC_MAX_VALUE + 1);

PrintSectionHeader("AVX");

Expand All @@ -795,7 +800,7 @@ static void PrintAVXInfo(const ZydisDecodedInstruction* instruction)
}
else
{
PRINT_VALUE_R("VECTORLEN", "SCALAR");
PRINT_VALUE_R("VECTORLEN", "%s", "SCALAR");
}

PRINT_VALUE_B("BROADCAST", "%s%s%s", strings_broadcast_mode[instruction->avx.broadcast.mode],
Expand Down Expand Up @@ -917,7 +922,7 @@ static void PrintInstruction(const ZydisDecoder* decoder,
"XOP9",
"XOPA"
};
ZYAN_ASSERT(ZYAN_ARRAY_LENGTH(opcode_maps) == ZYDIS_OPCODE_MAP_MAX_VALUE + 1);
ZYAN_STATIC_ASSERT(ZYAN_ARRAY_LENGTH(opcode_maps) == ZYDIS_OPCODE_MAP_MAX_VALUE + 1);

static const char* instr_encodings[] =
{
Expand All @@ -929,7 +934,8 @@ static void PrintInstruction(const ZydisDecoder* decoder,
"MVEX",
"REX2"
};
ZYAN_ASSERT(ZYAN_ARRAY_LENGTH(instr_encodings) == ZYDIS_INSTRUCTION_ENCODING_MAX_VALUE + 1);
ZYAN_STATIC_ASSERT(
ZYAN_ARRAY_LENGTH(instr_encodings) == ZYDIS_INSTRUCTION_ENCODING_MAX_VALUE + 1);

static const char* exception_classes[] =
{
Expand Down Expand Up @@ -1006,7 +1012,7 @@ static void PrintInstruction(const ZydisDecoder* decoder,
"USER_MSR_EVEX",
"LEGACY_RAO_INT"
};
ZYAN_ASSERT(ZYAN_ARRAY_LENGTH(exception_classes) == ZYDIS_EXCEPTION_CLASS_MAX_VALUE + 1);
ZYAN_STATIC_ASSERT(ZYAN_ARRAY_LENGTH(exception_classes) == ZYDIS_EXCEPTION_CLASS_MAX_VALUE + 1);

static const struct
{
Expand Down
Loading