Skip to content

Commit

Permalink
Fix RDSSPq/RDSSPd.
Browse files Browse the repository at this point in the history
  • Loading branch information
can1357 committed Dec 2, 2021
1 parent a33f3d4 commit d7f9179
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,6 @@ constexpr std::pair<uint16_t, const char*> simple_instruction_list[] =
{ NN_setssbsy, "__setssbsy" },
{ NN_endbr64, "__endbr64" },
{ NN_endbr32, "__endbr32" },
{ NN_rdsspd, "__rdsspd" },
{ NN_rdsspq, "__rdsspq" },
{ NN_incsspq, "__incsspq" },
{ NN_incsspd, "__incsspd" },
{ NN_rstorssp, "__rstorssp" },
Expand Down Expand Up @@ -494,6 +492,44 @@ hex::microcode_filter rdrand_rdseed_lifter = [ ] ( codegen_t& cg )
return true;
};

// Lifts RDSSP.
//
hex::microcode_filter rdssp_lifter = [ ] ( codegen_t& cg )
{
// Pick the intrinsic.
//
hex::helper helper{};
if ( cg.insn.itype == NN_rdsspd )
helper = hex::helper{ "__rdsspd" };
else if ( cg.insn.itype == NN_rdsspq )
helper = hex::helper{ "__rdsspq" };
else
return false;

// Create the call information.
//
tinfo_t t;
switch ( cg.insn.ops[ 0 ].dtype )
{
case dt_byte: t = tinfo_t{ BT_INT8 }; break;
case dt_word: t = tinfo_t{ BT_INT16 }; break;
case dt_dword: t = tinfo_t{ BT_INT32 }; break;
case dt_qword: t = tinfo_t{ BT_INT64 }; break;
default: return false;
}
auto ci = hex::call_info( t );
auto call = hex::make_call( cg.insn.ea, helper, std::move( ci ) );

// Emit the mov of the result.
//
cg.mb->insert_into_block(
hex::make_mov( cg.insn.ea, std::move( call ), hex::phys_reg( cg.insn.ops[ 0 ].reg, t.get_size() ) ).release(),
cg.mb->tail
);
cg.mb->mark_lists_dirty();
return true;
};

// Lifts RCL/RCR.
//
hex::microcode_filter rcl_rcr_lifter = [ ] ( codegen_t& cg )
Expand Down Expand Up @@ -902,7 +938,8 @@ constexpr hex::component* component_list[] = {
&xsetbv_lifter, &simple_instruction_lifter,
&rcl_rcr_lifter, &trapframe_lifter,
&iretq_lifter, &sysretq_lifter,
&type_enforcer, &rdrand_rdseed_lifter
&type_enforcer, &rdrand_rdseed_lifter,
&rdssp_lifter
};

// Plugin declaration.
Expand Down

0 comments on commit d7f9179

Please sign in to comment.