Skip to content

Commit dce4de0

Browse files
committed
Add uses_egpr APX info
1 parent a80aa46 commit dce4de0

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

include/Zydis/DecoderTypes.h

+4
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,10 @@ typedef struct ZydisDecodedInstructionAvx_
12151215
*/
12161216
typedef struct ZydisDecodedInstructionApx_
12171217
{
1218+
/**
1219+
* Signals, if the instruction uses the extended GRP registers (R16..R31).
1220+
*/
1221+
ZyanBool uses_egpr;
12181222
/**
12191223
* Signals, if the APX `no flags` functionality enabled for the instruction.
12201224
*/

src/Decoder.c

+15-2
Original file line numberDiff line numberDiff line change
@@ -4450,7 +4450,7 @@ static ZyanStatus ZydisNodeHandlerMvexE(const ZydisDecodedInstruction* instructi
44504450
* - `def_vvvv` -> `ZydisRegisterKind`
44514451
*/
44524452
static ZyanStatus ZydisPopulateRegisterIds(ZydisDecoderContext* context,
4453-
const ZydisDecodedInstruction* instruction, ZyanU8 def_reg, ZyanU8 def_rm, ZyanU8 def_vvvv)
4453+
ZydisDecodedInstruction* instruction, ZyanU8 def_reg, ZyanU8 def_rm, ZyanU8 def_vvvv)
44544454
{
44554455
ZYAN_ASSERT(context);
44564456
ZYAN_ASSERT(instruction);
@@ -4673,6 +4673,19 @@ static ZyanStatus ZydisPopulateRegisterIds(ZydisDecoderContext* context,
46734673
context->reg_info.id_base = !is_mod_reg ? id_base : -1;
46744674
context->reg_info.id_index = !is_mod_reg ? id_index : -1;
46754675

4676+
// Update APX info
4677+
4678+
const ZyanBool has_egpr_reg = (def_reg == ZYDIS_REGKIND_GPR) && (id_reg >= 16);
4679+
const ZyanBool has_egpr_rm = is_mod_reg && (def_rm == ZYDIS_REGKIND_GPR) && (id_rm >= 16);
4680+
const ZyanBool has_egpr_vvvv = (def_vvvv == ZYDIS_REGKIND_GPR) && (id_vvvv >= 16);
4681+
const ZyanBool has_egpr_base = !is_mod_reg && (id_base >= 16);
4682+
const ZyanBool has_egpr_index = !is_mod_reg && !has_vsib && (id_index >= 16);
4683+
4684+
if (has_egpr_reg || has_egpr_rm || has_egpr_vvvv || has_egpr_base || has_egpr_index)
4685+
{
4686+
instruction->apx.uses_egpr = ZYAN_TRUE;
4687+
}
4688+
46764689
return ZYAN_STATUS_SUCCESS;
46774690
}
46784691

@@ -4688,7 +4701,7 @@ static ZyanStatus ZydisPopulateRegisterIds(ZydisDecoderContext* context,
46884701
* This function is called immediately after a valid instruction-definition was found.
46894702
*/
46904703
static ZyanStatus ZydisCheckErrorConditions(ZydisDecoderState* state,
4691-
const ZydisDecodedInstruction* instruction, const ZydisInstructionDefinition* definition)
4704+
ZydisDecodedInstruction* instruction, const ZydisInstructionDefinition* definition)
46924705
{
46934706
ZYAN_ASSERT(state);
46944707
ZYAN_ASSERT(instruction);

tools/ZydisInfo.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -863,8 +863,9 @@ static void PrintAPXInfo(const ZydisDecodedInstruction* instruction)
863863

864864
PrintSectionHeader("APX");
865865

866-
PRINT_VALUE_B("NF", "%s", instruction->apx.has_nf ? "Y" : "N");
867-
PRINT_VALUE_B("ZU", "%s", instruction->apx.has_zu ? "Y" : "N");
866+
PRINT_VALUE_B("USES_EGPR", "%s", instruction->apx.uses_egpr ? "Y" : "N");
867+
PRINT_VALUE_B("HAS_NF", "%s", instruction->apx.has_nf ? "Y" : "N");
868+
PRINT_VALUE_B("HAS_ZU", "%s", instruction->apx.has_zu ? "Y" : "N");
868869
PRINT_VALUE_B("SCC", "%s", strings_scc[instruction->apx.scc]);
869870
}
870871

0 commit comments

Comments
 (0)