Skip to content

Commit

Permalink
Add IL implementation for FABS
Browse files Browse the repository at this point in the history
    * Also add `x86_il_{get,set}_st_reg` helper functions
  • Loading branch information
DMaroo committed Sep 16, 2023
1 parent 5cdddcf commit df8b835
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
20 changes: 20 additions & 0 deletions librz/analysis/arch/x86/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1077,4 +1077,24 @@ RzILOpEffect *x86_il_set_flags(RZ_OWN RzILOpPure *val, unsigned int size) {
return SEQ2(set_val, eff);
}

static bool check_st_reg(X86Reg reg) {
return reg >= X86_REG_ST0 && reg <= X86_REG_ST7;
}

RzILOpFloat *x86_il_get_st_reg(X86Reg reg) {
if (check_st_reg(reg)) {
return BV2F(RZ_FLOAT_IEEE754_BIN_64, VARG(x86_registers[reg]));
}

return NULL;
}

RzILOpEffect *x86_il_set_st_reg(X86Reg reg, RzILOpFloat *val) {
if (check_st_reg(reg)) {
return SETG(x86_registers[reg], F2BV(val));
}

return NULL;
}

#include <rz_il/rz_il_opbuilder_end.h>
3 changes: 3 additions & 0 deletions librz/analysis/arch/x86/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,7 @@ RzILOpEffect *x86_il_set_arithmetic_flags_except_cf_bits(RZ_OWN RzILOpPure *res,
RzILOpPure *x86_il_get_flags(unsigned int size);
RzILOpEffect *x86_il_set_flags(RZ_OWN RzILOpPure *val, unsigned int size);

RzILOpFloat *x86_il_get_st_reg(X86Reg reg);
RzILOpEffect *x86_il_set_st_reg(X86Reg reg, RzILOpFloat *val);

#endif // X86_IL_COMMON_H
14 changes: 14 additions & 0 deletions librz/analysis/arch/x86/il_fp_ops.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,17 @@
* - https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_Languages/x86-64_Assembly_Language_Programming_with_Ubuntu_(Jorgensen)/18%3A_Floating-Point_Instructions
* - https://en.wikibooks.org/wiki/X86_Assembly/Floating_Point#Floating-Point_Instruction_Set
*/

#include "common.h"
#include <rz_il/rz_il_opbuilder_begin.h>

/* Arithmetic instructions */

/**
* FABS
* Clears the sign bit of st(0) to create absolute value
*/
IL_LIFTER(fabs) {
RzILOpFloat *abs_value = FABS(x86_il_get_st_reg(X86_REG_ST0));
return x86_il_set_st_reg(X86_REG_ST0, abs_value);
}
1 change: 1 addition & 0 deletions librz/analysis/arch/x86/x86_il.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "x86_il.h"
#include "il_ops.inc"
#include "il_fp_ops.inc"

#define COMMON_REGS \
"cs", /* X86_REG_CS */ \
Expand Down

0 comments on commit df8b835

Please sign in to comment.