Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8e37d80
Create initial implementation of `__remill_sync_hyper_call`
tetsuo-cpp Jul 27, 2022
a416078
Fill in a few more cases
tetsuo-cpp Jul 28, 2022
24e29a3
Merge remote-tracking branch 'origin/master' into alex/x86-sync-hyper…
tetsuo-cpp Aug 4, 2022
e58a2f2
Use `state.addr_to_load` for LGDT and LIDT operands
tetsuo-cpp Aug 4, 2022
d53129d
Fix variable names
tetsuo-cpp Aug 8, 2022
41862cb
Cross-compile the Remill runtimes
tetsuo-cpp Aug 9, 2022
fcd24b2
Create temp variable for `lgdt` and `lidt` handling
tetsuo-cpp Aug 10, 2022
a544677
Add intrinsics for SPARC emulate instruction calls
tetsuo-cpp Aug 10, 2022
72035aa
Create intrinsics for remaining hyper calls
tetsuo-cpp Aug 10, 2022
295da65
Remove `__remill_sync_hyper_call` implementations in tests
tetsuo-cpp Aug 10, 2022
0abe52a
Create the target triple based on the provided arch
tetsuo-cpp Aug 10, 2022
09f16b7
Provide ARCH parameter for SPARC archs
tetsuo-cpp Aug 10, 2022
2d85bb0
CMake formatting
tetsuo-cpp Aug 10, 2022
1b3bbe6
Switch the conditions around
tetsuo-cpp Aug 10, 2022
03f764c
Adjust target triple
tetsuo-cpp Aug 10, 2022
65ccf60
Cross-compile the hyper calls and then link them into the runtime
tetsuo-cpp Aug 12, 2022
76e48b1
Cleanup
tetsuo-cpp Aug 12, 2022
85eebbe
Prefix int types with namespace
tetsuo-cpp Aug 12, 2022
a8c4174
Include `<limits>`
tetsuo-cpp Aug 14, 2022
20a749c
Fix `lgdt` and `lidt` handling
tetsuo-cpp Aug 14, 2022
79657e6
Mark new intrinsics as "used"
tetsuo-cpp Aug 14, 2022
9c8cf03
Add placeholder intrinsic definitions to tests
tetsuo-cpp Aug 14, 2022
db18a75
Complete list of intrinsic definitions
tetsuo-cpp Aug 14, 2022
f33de27
Merge remote-tracking branch 'origin/master' into alex/x86-sync-hyper…
tetsuo-cpp Aug 14, 2022
35a9723
Mark hyper call definition with `always_inline`
tetsuo-cpp Aug 19, 2022
e49e709
Use `_BitInt` if available
tetsuo-cpp Aug 19, 2022
de9e5e5
Merge remote-tracking branch 'origin/master' into alex/x86-sync-hyper…
tetsuo-cpp Aug 22, 2022
b93978a
Use `__builtin_unreachable` instead of `abort`
tetsuo-cpp Aug 22, 2022
0574f2a
Leave comment explaining `always_inline` attribute
tetsuo-cpp Aug 22, 2022
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
16 changes: 13 additions & 3 deletions cmake/BCCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ function(add_runtime target_name)
set(state "${macro_parameter}")
continue()

elseif("${macro_parameter}" STREQUAL "TARGET_TRIPLE")
# TODO(alex): Perhaps this parameter should be just the architecture and
# this function should assemble the target triple based on what OS we're
# running on.
set(state "${macro_parameter}")
continue()

elseif("${macro_parameter}" STREQUAL "DEPENDENCIES")
set(state "${macro_parameter}")
continue()
Expand Down Expand Up @@ -127,6 +134,9 @@ function(add_runtime target_name)

set(install_destination "${macro_parameter}")

elseif("${state}" STREQUAL "TARGET_TRIPLE")
set(target_triple "${macro_parameter}")

elseif("${state}" STREQUAL "DEPENDENCIES")
list(APPEND dependency_list "${macro_parameter}")

Expand Down Expand Up @@ -164,8 +174,8 @@ function(add_runtime target_name)
set(additional_windows_settings "-D_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH")
endif()

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(target_decl "-target" "x86_64-apple-macosx11.0.0")
if (NOT "${target_triple}" STREQUAL "")
set(target_decl "-target" ${target_triple})
endif()


Expand All @@ -192,7 +202,7 @@ function(add_runtime target_name)

add_custom_target("${target_name}" ALL DEPENDS "${absolute_target_path}")
set_property(TARGET "${target_name}" PROPERTY LOCATION "${absolute_target_path}")

if(REMILL_ENABLE_INSTALL_TARGET)
if(DEFINED install_destination)
install(FILES "${absolute_target_path}" DESTINATION "${install_destination}")
Expand Down
2 changes: 1 addition & 1 deletion include/remill/Arch/Name.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# define REMILL_ON_AARCH64 0
# define REMILL_ON_SPARC64 0
# define REMILL_ON_SPARC32 0
# elif defined(__aarch64__)
# elif defined(__aarch64__) || defined(__arm__)
# define REMILL_ARCH "aarch64"
# define REMILL_ON_AMD64 0
# define REMILL_ON_X86 0
Expand Down
9 changes: 9 additions & 0 deletions include/remill/Arch/Runtime/Intrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,13 @@ __remill_write_io_port_16(Memory *, addr_t, uint16_t);
[[gnu::used, gnu::const]] extern Memory *
__remill_write_io_port_32(Memory *, addr_t, uint32_t);

[[gnu::used, gnu::const]] extern Memory *
__remill_aarch64_emulate_instruction(Memory *);

[[gnu::used, gnu::const]] extern Memory *
__remill_aarch32_emulate_instruction(Memory *);

[[gnu::used, gnu::const]] extern Memory *
__remill_aarch32_check_not_el2(Memory *);

} // extern C
13 changes: 8 additions & 5 deletions lib/Arch/AArch32/Runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ project(arm_runtime)
set(ARMRUNTIME_SOURCEFILES
Instructions.cpp
BasicBlock.cpp

"${REMILL_LIB_DIR}/Arch/Runtime/Intrinsics.cpp"
)

Expand Down Expand Up @@ -50,16 +50,19 @@ function(add_runtime_helper target_name little_endian)
BCFLAGS "${arch_flags}" "-std=${required_cpp_standard}"
INCLUDEDIRECTORIES "${REMILL_INCLUDE_DIR}" "${REMILL_SOURCE_DIR}"
INSTALLDESTINATION "${REMILL_INSTALL_SEMANTICS_DIR}"
TARGET_TRIPLE "arm-darwin-macho"

DEPENDENCIES
"${REMILL_LIB_DIR}/Arch/AArch32/Semantics/BINARY.cpp"
"${REMILL_LIB_DIR}/Arch/AArch32/Semantics/FLAGS.cpp"
"${REMILL_LIB_DIR}/Arch/AArch32/Semantics/COND.cpp"
"${REMILL_LIB_DIR}/Arch/AArch32/Semantics/LOGICAL.cpp"
"${REMILL_LIB_DIR}/Arch/AArch32/Semantics/MEM.cpp"
"${REMILL_LIB_DIR}/Arch/AArch32/Semantics/BRANCH.cpp"
"${REMILL_LIB_DIR}/Arch/AArch32/Semantics/BITBYTE.cpp"
"${REMILL_LIB_DIR}/Arch/AArch32/Semantics/MISC.cpp"
"${REMILL_LIB_DIR}/Arch/AArch32/Semantics/MEM.cpp"
"${REMILL_LIB_DIR}/Arch/AArch32/Semantics/BRANCH.cpp"
"${REMILL_LIB_DIR}/Arch/AArch32/Semantics/BITBYTE.cpp"
"${REMILL_LIB_DIR}/Arch/AArch32/Semantics/MISC.cpp"

"${REMILL_LIB_DIR}/Arch/Runtime/HyperCall.cpp"
)
endfunction()

Expand Down
3 changes: 3 additions & 0 deletions lib/Arch/AArch32/Runtime/Instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <cmath>

// clang-format off
#include "remill/Arch/Name.h"
#include "remill/Arch/Runtime/Float.h"
#include "remill/Arch/Runtime/Intrinsics.h"
#include "remill/Arch/Runtime/Operators.h"
Expand Down Expand Up @@ -75,4 +76,6 @@ DEF_ISEL(INVALID_INSTRUCTION) = HandleInvalidInstruction;
// #include "lib/Arch/AArch32/Semantics/SIMD.cpp"
// #include "lib/Arch/AArch32/Semantics/SYSTEM.cpp"

#include "lib/Arch/Runtime/HyperCall.cpp"

// clang-format on
11 changes: 7 additions & 4 deletions lib/Arch/AArch64/Runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ project(AARCH64_runtime)
set(AARCH64RUNTIME_SOURCEFILES
Instructions.cpp
BasicBlock.cpp

"${REMILL_LIB_DIR}/Arch/Runtime/Intrinsics.cpp"
)

Expand All @@ -42,6 +42,7 @@ function(add_runtime_helper target_name address_bit_size little_endian)
BCFLAGS "-std=${required_cpp_standard}"
INCLUDEDIRECTORIES "${REMILL_INCLUDE_DIR}" "${REMILL_SOURCE_DIR}"
INSTALLDESTINATION "${REMILL_INSTALL_SEMANTICS_DIR}"
TARGET_TRIPLE "aarch64-darwin-macho"

DEPENDENCIES
"${REMILL_INCLUDE_DIR}/remill/Arch/Runtime/Float.h"
Expand All @@ -51,11 +52,11 @@ function(add_runtime_helper target_name address_bit_size little_endian)
"${REMILL_INCLUDE_DIR}/remill/Arch/Runtime/Intrinsics.h"
"${REMILL_INCLUDE_DIR}/remill/Arch/Runtime/HyperCall.h"
"${REMILL_INCLUDE_DIR}/remill/Arch/Runtime/Definitions.h"

"${REMILL_INCLUDE_DIR}/remill/Arch/AArch64/Runtime/Operators.h"
"${REMILL_INCLUDE_DIR}/remill/Arch/AArch64/Runtime/State.h"
"${REMILL_INCLUDE_DIR}/remill/Arch/AArch64/Runtime/Types.h"

"${REMILL_LIB_DIR}/Arch/AArch64/Semantics/CONVERT.cpp"
"${REMILL_LIB_DIR}/Arch/AArch64/Semantics/BITBYTE.cpp"
"${REMILL_LIB_DIR}/Arch/AArch64/Semantics/SIMD.cpp"
Expand All @@ -68,7 +69,9 @@ function(add_runtime_helper target_name address_bit_size little_endian)
"${REMILL_LIB_DIR}/Arch/AArch64/Semantics/MISC.cpp"
"${REMILL_LIB_DIR}/Arch/AArch64/Semantics/FLAGS.cpp"
"${REMILL_LIB_DIR}/Arch/AArch64/Semantics/LOGICAL.cpp"
"${REMILL_LIB_DIR}/Arch/AArch64/Semantics/SYSTEM.cpp"
"${REMILL_LIB_DIR}/Arch/AArch64/Semantics/SYSTEM.cpp"

"${REMILL_LIB_DIR}/Arch/Runtime/HyperCall.cpp"
)
endfunction()

Expand Down
3 changes: 3 additions & 0 deletions lib/Arch/AArch64/Runtime/Instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <cmath>

// clang-format off
#include "remill/Arch/Name.h"
#include "remill/Arch/Runtime/Float.h"
#include "remill/Arch/Runtime/Intrinsics.h"
#include "remill/Arch/Runtime/Operators.h"
Expand Down Expand Up @@ -118,4 +119,6 @@ DEF_ISEL(INVALID_INSTRUCTION) = HandleInvalidInstruction;
#include "lib/Arch/AArch64/Semantics/SIMD.cpp"
#include "lib/Arch/AArch64/Semantics/SYSTEM.cpp"

#include "lib/Arch/Runtime/HyperCall.cpp"

// clang-format on
29 changes: 17 additions & 12 deletions lib/Arch/Runtime/HyperCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Memory *__remill_sync_hyper_call(State &state, Memory *mem,
SyncHyperCall::Name call) {
switch (call) {

#if defined(REMILL_ON_X86) or defined(REMILL_ON_AMD64)
#if REMILL_ON_X86 || REMILL_ON_AMD64

case SyncHyperCall::kX86CPUID:
asm volatile("cpuid"
Expand All @@ -44,13 +44,13 @@ Memory *__remill_sync_hyper_call(State &state, Memory *mem,
case SyncHyperCall::kX86LoadGlobalDescriptorTable:
asm volatile("lgdt"
:
: "=m"(__remill_read_memory_64(memory, state.addr_to_load)));
: "=m"(__remill_read_memory_64(mem, state.addr_to_load)));
break;

case SyncHyperCall::kX86LoadInterruptDescriptorTable:
asm volatile("lidt"
:
: "m"(__remill_read_memory_64(memory, state.addr_to_load)));
: "m"(__remill_read_memory_64(mem, state.addr_to_load)));
break;

case SyncHyperCall::kX86ReadModelSpecificRegister:
Expand Down Expand Up @@ -84,7 +84,7 @@ Memory *__remill_sync_hyper_call(State &state, Memory *mem,

case SyncHyperCall::kX86SetSegmentGS: break;

# if defined(REMILL_ON_X86)
# if REMILL_ON_X86

case SyncHyperCall::kX86SetDebugReg: break;

Expand All @@ -98,7 +98,7 @@ Memory *__remill_sync_hyper_call(State &state, Memory *mem,

case SyncHyperCall::kX86SetControlReg4: break;

# elif defined(REMILL_ON_AMD64)
# elif REMILL_ON_AMD64

case SyncHyperCall::kAMD64SetDebugReg: break;

Expand All @@ -116,18 +116,23 @@ Memory *__remill_sync_hyper_call(State &state, Memory *mem,

# endif

// TODO(alex): What variable gets set for ARM32?
#elif defined(REMILL_ON_AARCH64)
#elif REMILL_ON_AARCH64

case SyncHyperCall::kAArch64EmulateInstruction: break;
case SyncHyperCall::kAArch64EmulateInstruction:
mem = __remill_aarch64_emulate_instruction(mem);
break;

case SyncHyperCall::kAArch64Breakpoint: break;
case SyncHyperCall::kAArch64Breakpoint: asm volatile("bkpt" :); break;

case SyncHyperCall::kAArch32EmulateInstruction: break;
case SyncHyperCall::kAArch32EmulateInstruction:
mem = __remill_aarch32_emulate_instruction(mem);
break;

case SyncHyperCall::kAArch32CheckNotEL2: break;
case SyncHyperCall::kAArch32CheckNotEL2:
mem = __remill_aarch32_check_not_el2(mem);
break;

#elif defined(REMILL_ON_SPARC32) or defined(REMILL_ON_SPARC64)
#elif REMILL_ON_SPARC32 || REMILL_ON_SPARC64

case SyncHyperCall::kSPARCSetAsiRegister: break;

Expand Down
1 change: 1 addition & 0 deletions lib/Arch/X86/Runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function(add_runtime_helper target_name address_bit_size enable_avx enable_avx51
BCFLAGS "-std=${required_cpp_standard}"
INCLUDEDIRECTORIES "${REMILL_INCLUDE_DIR}" "${REMILL_SOURCE_DIR}"
INSTALLDESTINATION "${REMILL_INSTALL_SEMANTICS_DIR}"
TARGET_TRIPLE "x86_64-darwin-macho"

DEPENDENCIES
"${REMILL_INCLUDE_DIR}/remill/Arch/Runtime/Float.h"
Expand Down