Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new type 'MV256W' and enabling AArch64 STP SIMD semantics. #636

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ find_package(glog CONFIG REQUIRED)
# Google gflags
find_package(gflags CONFIG REQUIRED)

# Python interpreter
find_package(Python COMPONENTS Interpreter)

set(sleigh_ENABLE_TESTS OFF)
set(sleigh_ADDITIONAL_PATCHES "${CMAKE_CURRENT_SOURCE_DIR}/patches/sleigh/x86-ia.patch;${CMAKE_CURRENT_SOURCE_DIR}/patches/sleigh/arm-thumb.patch" CACHE STRING "" FORCE)

Expand Down
1 change: 0 additions & 1 deletion bin/differential_tester_x86/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

find_package(Python COMPONENTS Interpreter)
add_executable(
lift-and-compare
LiftAndCompare.cpp
Expand Down
7 changes: 6 additions & 1 deletion cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUA
message(STATUS "aarch64 tests enabled")
set(can_enable_testing_aarch64 TRUE)
endif()

if("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "arm64" AND "${PLATFORM_NAME}" STREQUAL "macos")
message(STATUS "aarch64 tests enabled")
set(can_enable_testing_aarch64 TRUE)
endif()
endif()

set(REMILL_SOURCE_DIR "${PROJECT_SOURCE_DIR}" CACHE PATH "Root directory of remill source code")
Expand All @@ -29,4 +34,4 @@ cmake_dependent_option(REMILL_ENABLE_TESTING "Build your tests" ON "can_enable_t
cmake_dependent_option(REMILL_ENABLE_TESTING_X86 "Build your tests" ON "REMILL_ENABLE_TESTING;can_enable_testing_x86" OFF)
cmake_dependent_option(REMILL_ENABLE_TESTING_AARCH64 "Build your tests" ON "REMILL_ENABLE_TESTING;can_enable_testing_aarch64" OFF)
cmake_dependent_option(REMILL_ENABLE_TESTING_SLEIGH_THUMB "Build cross platform sliegh tests" ON "REMILL_ENABLE_TESTING" OFF)
cmake_dependent_option(REMILL_ENABLE_DIFFERENTIAL_TESTING "Build cross platform differential testing of sleigh x86" ON "REMILL_ENABLE_TESTING" OFF)
cmake_dependent_option(REMILL_ENABLE_DIFFERENTIAL_TESTING "Build cross platform differential testing of sleigh x86" ON "REMILL_ENABLE_TESTING" OFF)
1 change: 1 addition & 0 deletions include/remill/Arch/AArch64/Runtime/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ typedef MVnW<vec16_t> MV16W;
typedef MVnW<vec32_t> MV32W;
typedef MVnW<vec64_t> MV64W;
typedef MVnW<vec128_t> MV128W;
typedef MVnW<vec256_t> MV256W;

typedef Mn<uint8_t> M8;
typedef Mn<uint16_t> M16;
Expand Down
20 changes: 10 additions & 10 deletions lib/Arch/AArch64/Semantics/DATAXFER.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ DEF_SEM(STP_D, V64 src1, V64 src2, MV128W dst) {
// remill/remill/Arch/Runtime/Operators.h:437:1: error: static_assert failed "Invalid value size for MVnW."
// MAKE_MWRITEV(U, 128, dqwords, 128, uint128_t)

// DEF_SEM(STP_Q, V128 src1, V128 src2, MV128W dst) {
// auto src1_vec = UReadV128(src1);
// auto src2_vec = UReadV128(src2);
// uint128v2_t tmp_vec = {};
// tmp_vec = UInsertV128(tmp_vec, 0, UExtractV128(src1_vec, 0));
// tmp_vec = UInsertV128(tmp_vec, 1, UExtractV128(src2_vec, 0));
// UWriteV128(dst, tmp_vec);
// return memory;
// }
DEF_SEM(STP_Q, V128 src1, V128 src2, MV256W dst) {
auto src1_vec = UReadV128(src1);
auto src2_vec = UReadV128(src2);
uint128v2_t tmp_vec = {};
tmp_vec = UInsertV128(tmp_vec, 0, UExtractV128(src1_vec, 0));
tmp_vec = UInsertV128(tmp_vec, 1, UExtractV128(src2_vec, 0));
UWriteV128(dst, tmp_vec);
return memory;
}
} // namespace

DEF_ISEL(STP_32_LDSTPAIR_PRE) = StorePairUpdateIndex32;
Expand All @@ -95,7 +95,7 @@ DEF_ISEL(STP_64_LDSTPAIR_OFF) = StorePair64;
DEF_ISEL(STP_S_LDSTPAIR_OFF) = STP_S;
DEF_ISEL(STP_D_LDSTPAIR_OFF) = STP_D;

// DEF_ISEL(STP_Q_LDSTPAIR_OFF) = STP_Q;
DEF_ISEL(STP_Q_LDSTPAIR_OFF) = STP_Q;

namespace {

Expand Down
4 changes: 3 additions & 1 deletion lib/Arch/Runtime/HyperCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ Memory *__remill_sync_hyper_call(State &state, Memory *mem,
mem = __remill_aarch64_emulate_instruction(mem);
break;

case SyncHyperCall::kAArch64Breakpoint: asm volatile("bkpt" :); break;
case SyncHyperCall::kAArch64Breakpoint:
asm volatile("brk #0x0");
break;

#elif REMILL_HYPERCALL_SPARC32 || REMILL_HYPERCALL_SPARC64

Expand Down
32 changes: 32 additions & 0 deletions scripts/post_process_asm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) 2022 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.

"""
Post-process an assembly file and replace all @N@ symbols with newlines.

In Remill, we use pre-processor macros to generate assembly code. However,
macros cannot expand across multiple lines so there isn't a way to delimit
statements. To get around this limitation, we use the @N@ symbol to represent
a new line in the macro expansion and then use this post-processing script to
translate them into actual newlines.

Usage: post_process_asm.py INPUT_FILE OUTPUT_FILE
"""

import sys

with open(sys.argv[1]) as pre_processed, open(sys.argv[2], "w") as post_processed:
for line in pre_processed:
line = line.replace("@N@", "\n")
post_processed.write(line)
36 changes: 29 additions & 7 deletions tests/AArch64/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ enable_testing()
enable_language(ASM)

add_executable(lift-aarch64-tests
EXCLUDE_FROM_ALL
Lift.cpp
Tests.S
lift-post-processed-tests.S
)

set_target_properties(lift-aarch64-tests PROPERTIES
POSITION_INDEPENDENT_CODE ON
COMPILE_FLAGS "-fPIC -pie"
COMPILE_FLAGS "-fPIC"
)

target_compile_options(lift-aarch64-tests
Expand All @@ -46,15 +45,14 @@ target_include_directories(lift-aarch64-tests PUBLIC ${PROJECT_INCLUDEDIRECTORIE
target_include_directories(lift-aarch64-tests PRIVATE ${CMAKE_SOURCE_DIR})

add_executable(run-aarch64-tests
EXCLUDE_FROM_ALL
Run.cpp
Tests.S
run-post-processed-tests.S
tests_aarch64.S
)

set_target_properties(run-aarch64-tests PROPERTIES
POSITION_INDEPENDENT_CODE ON
COMPILE_FLAGS "-fPIC -pie"
COMPILE_FLAGS "-fPIC"
OBJECT_DEPENDS "${AARCH64_TEST_FILES}"
)

Expand All @@ -68,11 +66,35 @@ add_custom_command(
OUTPUT tests_aarch64.S
COMMAND ${CMAKE_BC_COMPILER}
-Wno-override-module
-S -O1 -g0
-S -O0 -g0
-c tests_aarch64.bc
-o tests_aarch64.S
-mllvm -opaque-pointers
DEPENDS tests_aarch64.bc
)

add_custom_command(
OUTPUT run-pre-processed-tests.S
COMMAND ${CMAKE_CXX_COMPILER} "-I${REMILL_SOURCE_DIR}" -o run-pre-processed-tests.S -E "${CMAKE_CURRENT_SOURCE_DIR}/Tests.S"
DEPENDS Tests.S
)

add_custom_command(
OUTPUT lift-pre-processed-tests.S
COMMAND ${CMAKE_CXX_COMPILER} "-I${REMILL_SOURCE_DIR}" -D IN_TEST_GENERATOR -o lift-pre-processed-tests.S -E "${CMAKE_CURRENT_SOURCE_DIR}/Tests.S"
DEPENDS Tests.S
)

add_custom_command(
OUTPUT run-post-processed-tests.S
COMMAND ${Python_EXECUTABLE} "${REMILL_SOURCE_DIR}/scripts/post_process_asm.py" run-pre-processed-tests.S run-post-processed-tests.S
DEPENDS run-pre-processed-tests.S
)

add_custom_command(
OUTPUT lift-post-processed-tests.S
COMMAND ${Python_EXECUTABLE} "${REMILL_SOURCE_DIR}/scripts/post_process_asm.py" lift-pre-processed-tests.S lift-post-processed-tests.S
DEPENDS lift-pre-processed-tests.S
)

target_link_libraries(run-aarch64-tests PUBLIC remill ${PROJECT_LIBRARIES})
Expand Down
18 changes: 7 additions & 11 deletions tests/AArch64/DATAXFER/STP_n_LDSTPAIR_OFF.S
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,12 @@ TEST_INPUTS(0)
stp d4, d5, [x3, #64]
TEST_END

// MvW type isnt supported
// remill/remill/Arch/Runtime/Operators.h:437:1: error: static_assert failed "Invalid value size for MVnW."
// MAKE_MWRITEV(U, 128, dqwords, 128, uint128_t)

/* STP <Qt1>, <Qt2>, [<Xn|SP>{, #<imm>}] */
// TEST_BEGIN(STP_Q_LDSTPAIR_OFF, stp_q0_q1_m256_off, 1)
// TEST_INPUTS(0)
TEST_BEGIN(STP_Q_LDSTPAIR_OFF, stp_q0_q1_m256_off, 1)
TEST_INPUTS(0)

// add x3, sp, #-256
// stp q0, q1, [x3, #0]
// stp q2, q3, [x3, #32]
// stp q4, q5, [x3, #64]
// TEST_END
add x3, sp, #-256
stp q0, q1, [x3, #0]
stp q2, q3, [x3, #32]
stp q4, q5, [x3, #64]
TEST_END
1 change: 1 addition & 0 deletions tests/AArch64/Lift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "remill/BC/IntrinsicTable.h"
#include "remill/BC/Lifter.h"
#include "remill/BC/Util.h"
#include "remill/BC/Version.h"
#include "remill/OS/OS.h"
#include "tests/AArch64/Test.h"

Expand Down
Loading