mirror of
https://github.com/lifting-bits/remill
synced 2026-06-21 13:56:07 +00:00
6322f794d1
* This branch contains support for new architectures. * Initial start to support for AArch 32 * Progress * Forgot the new files * Added all data Integer processing instructions without S + ADDS and started ANDS * Updated * Finished Integer Data Processing with three registers, added integer data processing with 2 regs + immediate, started MUL instructions * UMULL, UMULLS, UMLAL, UMLALS * Corrected condition for addend or 0 immediate for UMULL/UMLAL + SMULL/SMLAL instructions * Correct ops in Binary.cpp * UMAAL * SMULL, SMULLS, SMLAL, SMLALS + corrected acc was missing shift left in concatination * Updated decoding instructions based on top level encodings * Update returns around kDataProcessingRI and kDataProcessingI with comments to explain the correlation to the instruction rep * Added appropriate inst.category flags to Multiply and accumulate * Load/Store Word, Unsigned Byte (immediate, literal) && start of Logical Arithmetic (three register, immediate shift) * Was missing UMAAL DEF_ISEL in Binary.cpp * AddAddrRegOp * Logical Arithmetic (three register, immediate shift) without accounting for the possible PC jump * Made DecodeA32ExpandImm much much smaller * Replaced some imm ops with AddImmOp calls * Created AddShiftOp * Added interpreter for evaluating new PC value at decoding time to handle direct jumps and conditional jumps * Created EvalPCDest added PC evaluation to Logical Arithmetic Instructions * AddShiftOp -> AddShiftOp, AddShiftThenExtractOp, AddExtractThenShiftOp * Cleaned up some formatting, Renamed DecodeA32ExpandImm to ExpandTo32AddImmAddCarry and added a clarifying comment * Added comment to EvalPCDest for clarity * Cleaned up some things, updated the decoding semantics and semantics for the logical instructions * Shortened kLogArithEvaluators and fixed a bug * Updates from testing instructions * Fixed DEF_ISEL for pre/post index instructions in MEM.cpp * Integer Test and Compare (two register, immediate shift) * Logical Arithmetic (two register and immediate) * Integer Test and Compare (one register and immediate) * Added to the top level encoding infrastructure to handle the Data-processing register (register shift) set of instructions and 3 corresponding subsets * Add structs for the 3 subsets of Data-processing register (register shift) * Code status before refactoring operand types * This branch contains support for new architectures. * Initial start to support for AArch 32 * Progress * Forgot the new files * Added all data Integer processing instructions without S + ADDS and started ANDS * Updated * Finished Integer Data Processing with three registers, added integer data processing with 2 regs + immediate, started MUL instructions * UMULL, UMULLS, UMLAL, UMLALS * Corrected condition for addend or 0 immediate for UMULL/UMLAL + SMULL/SMLAL instructions * Correct ops in Binary.cpp * UMAAL * SMULL, SMULLS, SMLAL, SMLALS + corrected acc was missing shift left in concatination * Updated decoding instructions based on top level encodings * Update returns around kDataProcessingRI and kDataProcessingI with comments to explain the correlation to the instruction rep * Added appropriate inst.category flags to Multiply and accumulate * Load/Store Word, Unsigned Byte (immediate, literal) && start of Logical Arithmetic (three register, immediate shift) * Was missing UMAAL DEF_ISEL in Binary.cpp * AddAddrRegOp * Logical Arithmetic (three register, immediate shift) without accounting for the possible PC jump * Made DecodeA32ExpandImm much much smaller * Replaced some imm ops with AddImmOp calls * Created AddShiftOp * Added interpreter for evaluating new PC value at decoding time to handle direct jumps and conditional jumps * Created EvalPCDest added PC evaluation to Logical Arithmetic Instructions * AddShiftOp -> AddShiftOp, AddShiftThenExtractOp, AddExtractThenShiftOp * Cleaned up some formatting, Renamed DecodeA32ExpandImm to ExpandTo32AddImmAddCarry and added a clarifying comment * Added comment to EvalPCDest for clarity * Cleaned up some things, updated the decoding semantics and semantics for the logical instructions * Shortened kLogArithEvaluators and fixed a bug * Updates from testing instructions * Fixed DEF_ISEL for pre/post index instructions in MEM.cpp * Integer Test and Compare (two register, immediate shift) * Logical Arithmetic (two register and immediate) * Integer Test and Compare (one register and immediate) * Added to the top level encoding infrastructure to handle the Data-processing register (register shift) set of instructions and 3 corresponding subsets * Add structs for the 3 subsets of Data-processing register (register shift) * Code status before refactoring operand types * Finished updates off master * Start of operand refactor * Finished Expression Operand Support * Fix the .gitignore to add AArch32 to lib/Arch && removed all extra rrx ops from semantics * Updated .gitignore again, Added AddShiftRegRegOperand, Updated AddShiftRegImmOperand, Finished Register shift instructions for Integer Test and Compare, Logical Arithmetic, Integer Data Processing * Updated ROR in AddShiftRegRegOperand * Created ExtractAndZExtExpr * Fixed comment formatting in if else statements * Created RORExpr * Small fixes * Small fix in Logical Arithmetic (two register and immediate) * Corrected AddShiftRegRegOperand and cleaned it up. Split the carry op into a separate function. * conditional support + Start of Branch instructions * Created AddExprOp, cleaned up some expressions in reg shifted reg, and updated some occurances of ShiftThenExtractOp with ExtractAndZExtExpr * Updates from testing register shifted by register value inst * Fix to ROR in AddShiftRegCarryOperand * Corrected negation in DecodeCondition * DecodeCondition edit * DecodeCondition and AddShiftRegCarryOperand edits * Updated arch_for_decode to arch * Halfword Multiply and Accumulate * Edits from testing Halfword Multiply and Accumulate * Changed order of operands in Halfword Multiply and Accumulate to better reflect inst format + updated inst errors * Branch (Imm) & BX/BXL * Update aarch32 cmake * cmake update * CLZ * Forgot BITBYTE.cpp * MOVT * Integer Saturating Arithmetic * updated semantics in SMLAWh & SMLAh to use Select for setting PSTATE.Q * Started Load/Store Word, Unsigned Byte (register) & fixed MOV halfword * Load/Store Word, Unsigned Byte (register) * Finished testing load/Store Word, Unsigned Byte (register) * Load/Store Dual, Half, Signed Byte (register) * Rest of Extra load store: Load/Store Dual, Half, Signed Byte (immediate, literal) * Finished testing all the Load/store additions * Signed multiply, Divide * Cleaned up SExt some * Saturate Insts and Start of Load Store Multiple - STMDB and LDM (aliases which support PUSH and POP of multiple regs) * Condensed args in STMDB and LDM semantics * Rest of Multiple Load/Store that do not execute in a different mode * Bitfield Extract * Extend and Add * fix * NOP * Small fix * Simplified the bit reps in TryMoveSpecialRegisterAndHintsI * Moved Bitfield extract semantics out of BINARY and into BITBYTE * Finished correcting S/ZExt and Trunc use * Ran scripts/format-files to format * Smoke Test * Add false delay slot to kCategoryConditionalDirectFunctionCall * CI: Use single packaging job, add changelog support (#491) * CI: Add tag handler (#492) * Delay slot fixes to TraceLifter Co-authored-by: Peter Goodman <peter.goodman@gmail.com> Co-authored-by: Alessandro Gario <5714290+alessandrogario@users.noreply.github.com>
111 lines
3.3 KiB
C++
111 lines
3.3 KiB
C++
/*
|
|
* Copyright (c) 2019 Trail of Bits, Inc.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
// TODO(akshay) Discuss the VIS instructions with pag
|
|
// This is an alternative to SIMD instructions which reuses
|
|
// the floating point unit to perform partitioned Arithematic
|
|
// and logical operations
|
|
namespace {
|
|
|
|
template <typename S1, typename S2, typename D>
|
|
DEF_SEM(PACK_ORS, S1 src1, S2 src2, D dst) {
|
|
UWriteV32(dst, UOrV32(UReadV32(src1), UReadV32(src2)));
|
|
return memory;
|
|
}
|
|
|
|
template <typename S1, typename S2, typename D>
|
|
DEF_SEM(PACK_ORD, S1 src1, S2 src2, D dst) {
|
|
UWriteV64(dst, UOrV64(UReadV64(src1), UReadV64(src2)));
|
|
return memory;
|
|
}
|
|
|
|
template <typename S1, typename S2, typename D>
|
|
DEF_SEM(PACK_XORS, S1 src1, S2 src2, D dst) {
|
|
UWriteV32(dst, UXorV32(UReadV32(src1), UReadV32(src2)));
|
|
return memory;
|
|
}
|
|
|
|
template <typename S1, typename S2, typename D>
|
|
DEF_SEM(PACK_XORD, S1 src1, S2 src2, D dst) {
|
|
UWriteV64(dst, UXorV64(UReadV64(src1), UReadV64(src2)));
|
|
return memory;
|
|
}
|
|
|
|
|
|
// TODO(akshayk) We need to check for the 32 bit addressing
|
|
// in PSTATE.am
|
|
DEF_SEM(EDGE8CC, R64 src1, R64 src2, R64W dst) {
|
|
auto rs1 = Read(src1);
|
|
auto rs2 = Read(src2);
|
|
auto imask = Literal<I64>(0x7);
|
|
auto shift = Literal<I64>(3);
|
|
auto omask = Literal<I8>(0xff);
|
|
|
|
// l1 = rs1 & 0x7 rs[3:0]
|
|
auto l1 = UAnd(rs1, imask);
|
|
auto rs1_shifted = UShr(rs1, shift);
|
|
|
|
// l2 = rs2 & 0x7 rs[3:0]
|
|
auto l2 = UAnd(rs2, imask);
|
|
auto rs2_shifted = UShr(rs2, shift);
|
|
auto left_edge = UShr(omask, decltype(omask)(l1));
|
|
auto right_edge = UShl(omask, decltype(omask)(USub(imask, l2)));
|
|
auto value = Select(UCmpEq(rs1_shifted, rs2_shifted), left_edge,
|
|
UAnd(right_edge, left_edge));
|
|
auto diff = USub(rs1, rs2);
|
|
WriteICCFlagsAddSub<tag_sub>(state, Literal<uint32_t>(rs1),
|
|
Literal<uint32_t>(rs2), Literal<uint32_t>(diff));
|
|
WriteXCCFlagsAddSub<tag_sub>(state, rs1, rs2, diff);
|
|
WriteZExt(dst, value);
|
|
return memory;
|
|
}
|
|
|
|
|
|
} // namespace
|
|
|
|
DEF_ISEL(FORS) = PACK_ORS<V32W, V32W, V32W>;
|
|
DEF_ISEL(FORD) = PACK_ORD<V64W, V64W, V64W>;
|
|
DEF_ISEL(FXORS) = PACK_XORS<V32W, V32W, V32W>;
|
|
DEF_ISEL(FXORD) = PACK_XORD<V64W, V64W, V64W>;
|
|
|
|
|
|
DEF_ISEL(EDGE8cc) = EDGE8CC;
|
|
|
|
namespace {
|
|
|
|
DEF_SEM(IMPDEP1, I32 opf) {
|
|
HYPER_CALL_VECTOR = Literal<decltype(state.hyper_call_vector)>(Read(opf));
|
|
return __remill_sync_hyper_call(
|
|
state, memory,
|
|
SyncHyperCall::IF_32BIT_ELSE(kSPARC32EmulateInstruction,
|
|
kSPARC64EmulateInstruction));
|
|
}
|
|
|
|
DEF_SEM(IMPDEP2, I32 opf) {
|
|
HYPER_CALL_VECTOR = Literal<decltype(state.hyper_call_vector)>(Read(opf));
|
|
return __remill_sync_hyper_call(
|
|
state, memory,
|
|
SyncHyperCall::IF_32BIT_ELSE(kSPARC32EmulateInstruction,
|
|
kSPARC64EmulateInstruction));
|
|
}
|
|
|
|
} // namespace
|
|
|
|
DEF_ISEL(IMPDEP1) = IMPDEP1;
|
|
DEF_ISEL(IMPDEP2) = IMPDEP2;
|