Skip to content

Commit

Permalink
Add uses_egpr APX info
Browse files Browse the repository at this point in the history
  • Loading branch information
flobernd committed Oct 31, 2024
1 parent a80aa46 commit dce4de0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 4 additions & 0 deletions include/Zydis/DecoderTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,10 @@ typedef struct ZydisDecodedInstructionAvx_
*/
typedef struct ZydisDecodedInstructionApx_
{
/**
* Signals, if the instruction uses the extended GRP registers (R16..R31).
*/
ZyanBool uses_egpr;
/**
* Signals, if the APX `no flags` functionality enabled for the instruction.
*/
Expand Down
17 changes: 15 additions & 2 deletions src/Decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -4450,7 +4450,7 @@ static ZyanStatus ZydisNodeHandlerMvexE(const ZydisDecodedInstruction* instructi
* - `def_vvvv` -> `ZydisRegisterKind`
*/
static ZyanStatus ZydisPopulateRegisterIds(ZydisDecoderContext* context,
const ZydisDecodedInstruction* instruction, ZyanU8 def_reg, ZyanU8 def_rm, ZyanU8 def_vvvv)
ZydisDecodedInstruction* instruction, ZyanU8 def_reg, ZyanU8 def_rm, ZyanU8 def_vvvv)
{
ZYAN_ASSERT(context);
ZYAN_ASSERT(instruction);
Expand Down Expand Up @@ -4673,6 +4673,19 @@ static ZyanStatus ZydisPopulateRegisterIds(ZydisDecoderContext* context,
context->reg_info.id_base = !is_mod_reg ? id_base : -1;
context->reg_info.id_index = !is_mod_reg ? id_index : -1;

// Update APX info

const ZyanBool has_egpr_reg = (def_reg == ZYDIS_REGKIND_GPR) && (id_reg >= 16);
const ZyanBool has_egpr_rm = is_mod_reg && (def_rm == ZYDIS_REGKIND_GPR) && (id_rm >= 16);
const ZyanBool has_egpr_vvvv = (def_vvvv == ZYDIS_REGKIND_GPR) && (id_vvvv >= 16);
const ZyanBool has_egpr_base = !is_mod_reg && (id_base >= 16);
const ZyanBool has_egpr_index = !is_mod_reg && !has_vsib && (id_index >= 16);

if (has_egpr_reg || has_egpr_rm || has_egpr_vvvv || has_egpr_base || has_egpr_index)
{
instruction->apx.uses_egpr = ZYAN_TRUE;
}

return ZYAN_STATUS_SUCCESS;
}

Expand All @@ -4688,7 +4701,7 @@ static ZyanStatus ZydisPopulateRegisterIds(ZydisDecoderContext* context,
* This function is called immediately after a valid instruction-definition was found.
*/
static ZyanStatus ZydisCheckErrorConditions(ZydisDecoderState* state,
const ZydisDecodedInstruction* instruction, const ZydisInstructionDefinition* definition)
ZydisDecodedInstruction* instruction, const ZydisInstructionDefinition* definition)
{
ZYAN_ASSERT(state);
ZYAN_ASSERT(instruction);
Expand Down
5 changes: 3 additions & 2 deletions tools/ZydisInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,9 @@ static void PrintAPXInfo(const ZydisDecodedInstruction* instruction)

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("USES_EGPR", "%s", instruction->apx.uses_egpr ? "Y" : "N");
PRINT_VALUE_B("HAS_NF", "%s", instruction->apx.has_nf ? "Y" : "N");
PRINT_VALUE_B("HAS_ZU", "%s", instruction->apx.has_zu ? "Y" : "N");
PRINT_VALUE_B("SCC", "%s", strings_scc[instruction->apx.scc]);
}

Expand Down

0 comments on commit dce4de0

Please sign in to comment.