From 1c6f11277096534479c958b6d9fc5265d318ca2a Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Mon, 18 Sep 2017 23:25:08 -0400 Subject: Add basic floating point instructions --- mediumlevelilinstruction.cpp | 250 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 197 insertions(+), 53 deletions(-) (limited to 'mediumlevelilinstruction.cpp') diff --git a/mediumlevelilinstruction.cpp b/mediumlevelilinstruction.cpp index ec6aa1c6..b0e607b2 100644 --- a/mediumlevelilinstruction.cpp +++ b/mediumlevelilinstruction.cpp @@ -45,8 +45,6 @@ unordered_map {LeftExprMediumLevelOperandUsage, ExprMediumLevelOperand}, {RightExprMediumLevelOperandUsage, ExprMediumLevelOperand}, {CarryExprMediumLevelOperandUsage, ExprMediumLevelOperand}, - {HighExprMediumLevelOperandUsage, ExprMediumLevelOperand}, - {LowExprMediumLevelOperandUsage, ExprMediumLevelOperand}, {StackExprMediumLevelOperandUsage, ExprMediumLevelOperand}, {ConditionExprMediumLevelOperandUsage, ExprMediumLevelOperand}, {HighVariableMediumLevelOperandUsage, VariableMediumLevelOperand}, @@ -112,10 +110,12 @@ unordered_map> SourceExprMediumLevelOperandUsage}}, {MLIL_VAR, {SourceVariableMediumLevelOperandUsage}}, {MLIL_VAR_FIELD, {SourceVariableMediumLevelOperandUsage, OffsetMediumLevelOperandUsage}}, + {MLIL_VAR_SPLIT, {HighVariableMediumLevelOperandUsage, LowVariableMediumLevelOperandUsage}}, {MLIL_VAR_SSA, {SourceSSAVariableMediumLevelOperandUsage}}, {MLIL_VAR_SSA_FIELD, {SourceSSAVariableMediumLevelOperandUsage, OffsetMediumLevelOperandUsage}}, {MLIL_VAR_ALIASED, {SourceSSAVariableMediumLevelOperandUsage}}, {MLIL_VAR_ALIASED_FIELD, {SourceSSAVariableMediumLevelOperandUsage, OffsetMediumLevelOperandUsage}}, + {MLIL_VAR_SPLIT_SSA, {HighSSAVariableMediumLevelOperandUsage, LowSSAVariableMediumLevelOperandUsage}}, {MLIL_ADDRESS_OF, {SourceVariableMediumLevelOperandUsage}}, {MLIL_ADDRESS_OF_FIELD, {SourceVariableMediumLevelOperandUsage, OffsetMediumLevelOperandUsage}}, {MLIL_JUMP, {DestExprMediumLevelOperandUsage}}, @@ -187,21 +187,34 @@ unordered_map> CarryExprMediumLevelOperandUsage}}, {MLIL_RRC, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage, CarryExprMediumLevelOperandUsage}}, - {MLIL_DIVU_DP, {HighExprMediumLevelOperandUsage, LowExprMediumLevelOperandUsage, - RightExprMediumLevelOperandUsage}}, - {MLIL_DIVS_DP, {HighExprMediumLevelOperandUsage, LowExprMediumLevelOperandUsage, - RightExprMediumLevelOperandUsage}}, - {MLIL_MODU_DP, {HighExprMediumLevelOperandUsage, LowExprMediumLevelOperandUsage, - RightExprMediumLevelOperandUsage}}, - {MLIL_MODS_DP, {HighExprMediumLevelOperandUsage, LowExprMediumLevelOperandUsage, - RightExprMediumLevelOperandUsage}}, + {MLIL_DIVU_DP, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_DIVS_DP, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_MODU_DP, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_MODS_DP, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, {MLIL_NEG, {SourceExprMediumLevelOperandUsage}}, {MLIL_NOT, {SourceExprMediumLevelOperandUsage}}, {MLIL_SX, {SourceExprMediumLevelOperandUsage}}, {MLIL_ZX, {SourceExprMediumLevelOperandUsage}}, {MLIL_LOW_PART, {SourceExprMediumLevelOperandUsage}}, {MLIL_BOOL_TO_INT, {SourceExprMediumLevelOperandUsage}}, - {MLIL_UNIMPL_MEM, {SourceExprMediumLevelOperandUsage}} + {MLIL_UNIMPL_MEM, {SourceExprMediumLevelOperandUsage}}, + {MLIL_FADD, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_FSUB, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_FMUL, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_FDIV, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_FSQRT, {SourceExprMediumLevelOperandUsage}}, + {MLIL_FNEG, {SourceExprMediumLevelOperandUsage}}, + {MLIL_FABS, {SourceExprMediumLevelOperandUsage}}, + {MLIL_FLOAT_TO_INT, {SourceExprMediumLevelOperandUsage}}, + {MLIL_INT_TO_FLOAT, {SourceExprMediumLevelOperandUsage}}, + {MLIL_FLOAT_CONV, {SourceExprMediumLevelOperandUsage}}, + {MLIL_FCMP_E, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_FCMP_NE, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_FCMP_LT, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_FCMP_LE, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_FCMP_GE, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_FCMP_GT, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_FCMP_UO, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}} }; @@ -1266,6 +1279,12 @@ void MediumLevelILInstruction::VisitExprs(const std::functionVarField(size, GetSourceVariable(), GetOffset(), *this); + case MLIL_VAR_SPLIT: + return dest->VarSplit(size, GetHighVariable(), + GetLowVariable(), *this); case MLIL_VAR_SSA: return dest->VarSSA(size, GetSourceSSAVariable(), *this); case MLIL_VAR_SSA_FIELD: @@ -1392,6 +1421,9 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, return dest->VarAliasedField(size, GetSourceSSAVariable().var, GetSourceSSAVariable().version, GetOffset(), *this); + case MLIL_VAR_SPLIT_SSA: + return dest->VarSplitSSA(size, GetHighSSAVariable(), + GetLowSSAVariable(), *this); case MLIL_ADDRESS_OF: return dest->AddressOf(GetSourceVariable(), *this); case MLIL_ADDRESS_OF_FIELD: @@ -1477,6 +1509,12 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, case MLIL_BOOL_TO_INT: case MLIL_JUMP: case MLIL_UNIMPL_MEM: + case MLIL_FSQRT: + case MLIL_FNEG: + case MLIL_FABS: + case MLIL_FLOAT_TO_INT: + case MLIL_INT_TO_FLOAT: + case MLIL_FLOAT_CONV: return dest->AddExprWithLocation(operation, *this, size, subExprHandler(AsOneOperand().GetSourceExpr())); case MLIL_ADD: @@ -1496,6 +1534,10 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, case MLIL_DIVS: case MLIL_MODU: case MLIL_MODS: + case MLIL_DIVU_DP: + case MLIL_DIVS_DP: + case MLIL_MODU_DP: + case MLIL_MODS_DP: case MLIL_CMP_E: case MLIL_CMP_NE: case MLIL_CMP_SLT: @@ -1508,6 +1550,17 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, case MLIL_CMP_UGT: case MLIL_TEST_BIT: case MLIL_ADD_OVERFLOW: + case MLIL_FADD: + case MLIL_FSUB: + case MLIL_FMUL: + case MLIL_FDIV: + case MLIL_FCMP_E: + case MLIL_FCMP_NE: + case MLIL_FCMP_LT: + case MLIL_FCMP_LE: + case MLIL_FCMP_GE: + case MLIL_FCMP_GT: + case MLIL_FCMP_UO: return dest->AddExprWithLocation(operation, *this, size, subExprHandler(AsTwoOperand().GetLeftExpr()), subExprHandler(AsTwoOperand().GetRightExpr())); case MLIL_ADC: @@ -1518,14 +1571,6 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, subExprHandler(AsTwoOperandWithCarry().GetLeftExpr()), subExprHandler(AsTwoOperandWithCarry().GetRightExpr()), subExprHandler(AsTwoOperandWithCarry().GetCarryExpr())); - case MLIL_DIVU_DP: - case MLIL_DIVS_DP: - case MLIL_MODU_DP: - case MLIL_MODS_DP: - return dest->AddExprWithLocation(operation, *this, size, - subExprHandler(AsDoublePrecision().GetHighExpr()), - subExprHandler(AsDoublePrecision().GetLowExpr()), - subExprHandler(AsDoublePrecision().GetRightExpr())); case MLIL_JUMP_TO: for (auto target : GetTargetList()) { @@ -1665,24 +1710,6 @@ MediumLevelILInstruction MediumLevelILInstruction::GetCarryExpr() const } -MediumLevelILInstruction MediumLevelILInstruction::GetHighExpr() const -{ - size_t operandIndex; - if (GetOperandIndexForUsage(HighExprMediumLevelOperandUsage, operandIndex)) - return GetRawOperandAsExpr(operandIndex); - throw MediumLevelILInstructionAccessException(); -} - - -MediumLevelILInstruction MediumLevelILInstruction::GetLowExpr() const -{ - size_t operandIndex; - if (GetOperandIndexForUsage(LowExprMediumLevelOperandUsage, operandIndex)) - return GetRawOperandAsExpr(operandIndex); - throw MediumLevelILInstructionAccessException(); -} - - MediumLevelILInstruction MediumLevelILInstruction::GetStackExpr() const { size_t operandIndex; @@ -2036,6 +2063,13 @@ ExprId MediumLevelILFunction::VarField(size_t size, const Variable& src, uint64_ } +ExprId MediumLevelILFunction::VarSplit(size_t size, const Variable& high, const Variable& low, + const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_VAR_SPLIT, loc, size, high.ToIdentifier(), low.ToIdentifier()); +} + + ExprId MediumLevelILFunction::VarSSA(size_t size, const SSAVariable& src, const ILSourceLocation& loc) { @@ -2064,6 +2098,14 @@ ExprId MediumLevelILFunction::VarAliasedField(size_t size, const Variable& src, } +ExprId MediumLevelILFunction::VarSplitSSA(size_t size, const SSAVariable& high, const SSAVariable& low, + const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_VAR_SPLIT_SSA, loc, size, high.var.ToIdentifier(), high.version, + low.var.ToIdentifier(), low.version); +} + + ExprId MediumLevelILFunction::AddressOf(const Variable& var, const ILSourceLocation& loc) { return AddExprWithLocation(MLIL_ADDRESS_OF, loc, 0, var.ToIdentifier()); @@ -2223,17 +2265,17 @@ ExprId MediumLevelILFunction::DivUnsigned(size_t size, ExprId left, ExprId right } -ExprId MediumLevelILFunction::DivDoublePrecSigned(size_t size, ExprId high, ExprId low, ExprId right, +ExprId MediumLevelILFunction::DivDoublePrecSigned(size_t size, ExprId left, ExprId right, const ILSourceLocation& loc) { - return AddExprWithLocation(MLIL_DIVS_DP, loc, size, high, low, right); + return AddExprWithLocation(MLIL_DIVS_DP, loc, size, left, right); } -ExprId MediumLevelILFunction::DivDoublePrecUnsigned(size_t size, ExprId high, ExprId low, ExprId right, +ExprId MediumLevelILFunction::DivDoublePrecUnsigned(size_t size, ExprId left, ExprId right, const ILSourceLocation& loc) { - return AddExprWithLocation(MLIL_DIVU_DP, loc, size, high, low, right); + return AddExprWithLocation(MLIL_DIVU_DP, loc, size, left, right); } @@ -2251,17 +2293,17 @@ ExprId MediumLevelILFunction::ModUnsigned(size_t size, ExprId left, ExprId right } -ExprId MediumLevelILFunction::ModDoublePrecSigned(size_t size, ExprId high, ExprId low, ExprId right, +ExprId MediumLevelILFunction::ModDoublePrecSigned(size_t size, ExprId left, ExprId right, const ILSourceLocation& loc) { - return AddExprWithLocation(MLIL_MODS_DP, loc, size, high, low, right); + return AddExprWithLocation(MLIL_MODS_DP, loc, size, left, right); } -ExprId MediumLevelILFunction::ModDoublePrecUnsigned(size_t size, ExprId high, ExprId low, ExprId right, +ExprId MediumLevelILFunction::ModDoublePrecUnsigned(size_t size, ExprId left, ExprId right, const ILSourceLocation& loc) { - return AddExprWithLocation(MLIL_MODU_DP, loc, size, high, low, right); + return AddExprWithLocation(MLIL_MODU_DP, loc, size, left, right); } @@ -2533,3 +2575,105 @@ ExprId MediumLevelILFunction::MemoryPhi(size_t destMemVersion, const vector