Skip to content

Commit 3f03f91

Browse files
stettbergerMalte Bargholzgravitybone
committed
[SAIL] Integration of RISC-V and CHERI-RISCV
With this (large) patch, we integrate the riscv and cheri-riscv model as potential tracing and injection targets. This change also introduces the infratstructure to integrate other models with a relatively low overhead. Mixed into this patch are a few changes that are unrelated. I'm aware of this, but I have no desire to pull everything appart. The effort was large enough. - llvmdisassembler: bump version to 11.0.0 With 11.0.0, the llvmdisassemble broke FAIL*, since the LLVM's ELF.h used enums to define constants, while the system elf.h used preprocessor #define to define the same constants. Depending on the inclusion order, this broke horribly. Co-authored-by: Christian Dietrich <dietrich@sra.uni-hannover.de> Co-authored-by: Malte Bargholz <malte@screenri.de> Co-authored-by: Marcel Budoj <marcel.budoj@googlemail.com>
1 parent 535f28f commit 3f03f91

62 files changed

Lines changed: 3421 additions & 138 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# cmake 2.6 might suffice, but we don't test it (even Debian stable has 2.8.2)
2-
cmake_minimum_required(VERSION 2.8.2)
1+
# cmake 2.6 might suffice, but we don't test it (even Debian stable has 3.12)
2+
cmake_minimum_required(VERSION 3.12)
33
if("${CMAKE_VERSION}" VERSION_GREATER 2.8.3)
44
# system cmake modules take precedence over those in CMAKE_MODULE_PATH
55
# (makes cmake 2.8.4 and newer)
@@ -15,6 +15,8 @@ else()
1515
set(PROJECT_VERSION "1.0.1" CACHE INTERNAL "FAIL* version number" FORCE)
1616
endif()
1717

18+
cmake_policy(SET CMP0074 NEW)
19+
1820
ENABLE_TESTING()
1921

2022
#### Put all resulting library files in <your_build_dir>/lib ####
@@ -43,13 +45,18 @@ include(doxygen)
4345

4446
#### Backend selection ####
4547
OPTION( BUILD_BOCHS "Build Bochs Variant?" ON)
48+
OPTION( BUILD_SAIL "Build Sail Variant" OFF)
4649
OPTION( BUILD_GEM5 "Build gem5 Variant?" OFF)
4750
OPTION( BUILD_QEMU "Build QEMU Variant?" OFF)
4851
OPTION( BUILD_T32 "Build Lauterbach Trace32 Variant?" OFF)
4952
OPTION( BUILD_PANDA "Build Pandaboard ES + Flyswatter2 Variant?" OFF)
5053

51-
OPTION( BUILD_X86 "Build for x86 guests?" ON)
52-
OPTION( BUILD_ARM "Build for ARM guests?" OFF)
54+
OPTION( BUILD_X86 "Build for x86 guests?" ON)
55+
OPTION( BUILD_ARM "Build for ARM guests?" OFF)
56+
OPTION( BUILD_RISCV_CHERI "Build for CHERI enabled RISC-V guests?" OFF)
57+
OPTION( BUILD_RISCV "Build for RISC-V guests?" OFF)
58+
59+
OPTION( BUILD_64BIT "Build RISCV or CHERI RISC-V with 64-bit support" OFF)
5360

5461
# FIXME: only add simulators/ to include_directories, and include, e.g.,
5562
# bochs/bochs.h in FAIL*. -> avoids naming conflicts (e.g., /usr/include/elf.h
@@ -69,8 +76,61 @@ elseif(BUILD_T32)
6976
add_subdirectory(scripts/t32cmm)
7077
elseif(BUILD_PANDA)
7178
include_directories(debuggers/openocd/src debuggers/openocd/jimtcl src/core)
79+
elseif(BUILD_SAIL)
80+
message(STATUS "[${PROJECT_NAME}] Building Sail ...")
81+
SET(VARIANT sail)
82+
83+
if(BUILD_64BIT)
84+
message(STATUS "[${PROJECT_NAME}] Building 64-bit Sail Simulator ...")
85+
set(ARCH_SUFFIX "RV64")
86+
else()
87+
message(STATUS "[${PROJECT_NAME}] Building 32-bit Sail Simulator ...")
88+
set(ARCH_SUFFIX "RV32")
89+
endif()
90+
91+
if (BUILD_RISCV)
92+
message(STATUS "[${PROJECT_NAME}] Building Sail RISC-V Variant ...")
93+
set(SAIL_ARCH riscv)
94+
set(SAIL_SIMULATOR build/riscv_sim_${ARCH_SUFFIX}.a)
95+
set(SAIL_SOFTFLOAT_DIR c_emulator/SoftFloat-3e/build/Linux-RISCV-GCC)
96+
set(SAIL_SOFTFLOAT_BUILD_ARGS SPECIALIZE_TYPE=RISCV)
97+
set(SAIL_BUILD_ARGS ${SAIL_SIMULATOR} ARCH=${ARCH_SUFFIX})
98+
elseif(BUILD_RISCV_CHERI)
99+
message(STATUS "[${PROJECT_NAME}] Building Sail CHERI RISC-V Variant")
100+
set(SAIL_ARCH cheri-riscv)
101+
set(SAIL_SIMULATOR build/cheri_riscv_sim_${ARCH_SUFFIX}.a)
102+
set(SAIL_SOFTFLOAT_DIR sail-riscv/c_emulator/SoftFloat-3e/build/Linux-RISCV-GCC)
103+
set(SAIL_SOFTFLOAT_BUILD_ARGS SPECIALIZE_TYPE=RISCV)
104+
set(SAIL_BUILD_ARGS ${SAIL_SIMULATOR} ARCH=${ARCH_SUFFIX})
105+
else()
106+
message( FATAL_ERROR "No supported architecture selected" )
107+
endif()
108+
# Architecture specific include directory
109+
message("Add include: ${PROJECT_SOURCE_DIR}/src/core/sal/sail/${SAIL_ARCH}")
110+
include_directories("${PROJECT_SOURCE_DIR}/src/core/sal/sail/${SAIL_ARCH}")
72111
endif(BUILD_BOCHS)
73112

113+
if(BUILD_LLVM_DISASSEMBLER)
114+
if (BUILD_RISCV_CHERI)
115+
set(FIND_PACKAGE_VERSION 11.0.0)
116+
set(LLVM_ROOT /opt/llvm-cheri-05.2020 CACHE STRING "Where is LLVM located")
117+
set(LLVM_FIND_PACKAGE_ARGS HINTS ${LLVM_ROOT} NO_DEFAULT_PATH)
118+
else()
119+
set(FIND_PACKAGE_VERSION 11.0.0)
120+
set(LLVM_FIND_PACKAGE_ARGS HINTS)
121+
endif()
122+
123+
find_package(LLVM ${FIND_PACKAGE_VERSION}
124+
REQUIRED
125+
CONFIG
126+
${FIND_PACKAGE_ARGS}
127+
)
128+
129+
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
130+
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
131+
132+
endif(BUILD_LLVM_DISASSEMBLER)
133+
74134
## Tell the linker where to find the FAIL* libraries
75135
link_directories("${LIBRARY_OUTPUT_PATH}")
76136

@@ -84,10 +144,11 @@ add_subdirectory(tools)
84144
add_subdirectory(src)
85145

86146

87-
#### Backend-related build system stuff
147+
#### Backend-related build system stuff [cmake/{name}.cmake]
88148
include(bochs)
89149
include(gem5)
90150
include(qemu)
91151
include(t32)
92152
include(panda)
153+
include(sail)
93154

cmake/FindLLVM.cmake

Lines changed: 0 additions & 34 deletions
This file was deleted.

cmake/sail.cmake

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
if(BUILD_SAIL)
2+
find_package(ZLIB REQUIRED) # -lz
3+
if(ZLIB_FOUND)
4+
set(sail_library_dependencies ${sail_library_dependencies} ${ZLIB_LIBRARIES})
5+
endif(ZLIB_FOUND)
6+
7+
#FIXME: find package GMP dynamically
8+
9+
#find_package(GMP REQUIRED)
10+
#if(GMP_FOUND)
11+
# set(sail_library_dependencies ${sail_library_dependencies} ${GMP_LIBRARIES})
12+
#endif(GMP_FOUND)
13+
14+
set(sail_library_dependencies ${sail_library_dependencies} -lgmp)
15+
16+
set(SAIL_SIMULATOR_DIR ${PROJECT_SOURCE_DIR}/simulators/sail)
17+
set(sail_src_dir ${SAIL_SIMULATOR_DIR}/${SAIL_ARCH})
18+
add_executable(fail-client ${SAIL_SIMULATOR_DIR}/fail_empty_source_file_for_build.cc)
19+
20+
# make sure aspects don't fail to match in entry.cc and the experiment headers are found
21+
include_directories(${PROJECT_SOURCE_DIR}/src/core ${CMAKE_BINARY_DIR}/src/core)
22+
23+
set(sail_build_CC "${CMAKE_C_COMPILER}")
24+
set(sail_build_CFLAGS "-I${PROJECT_SOURCE_DIR}/src/core -I${CMAKE_BINARY_DIR}/src/core")
25+
configure_file(${PROJECT_SOURCE_DIR}/simulators/sail/sail-cc.in
26+
${CMAKE_CURRENT_BINARY_DIR}/sail-cc)
27+
28+
include(ExternalProject)
29+
ExternalProject_Add(
30+
libsail-emu_external
31+
SOURCE_DIR ${sail_src_dir}
32+
## Put configure command here, to prevent cmake calling make configure
33+
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E echo "[${PROJECT_NAME}] No configure for libsail-emu"
34+
BUILD_COMMAND
35+
${CMAKE_COMMAND} -E env CC=${CMAKE_CURRENT_BINARY_DIR}/sail-cc $(MAKE) -C ${sail_src_dir} ${SAIL_BUILD_ARGS}
36+
BUILD_IN_SOURCE 1
37+
BUILD_ALWAYS true
38+
## Put install command here, to prevent cmake calling make install
39+
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "[${PROJECT_NAME}] No install for libsail-emu"
40+
41+
)
42+
43+
add_library(libsail-emu STATIC IMPORTED GLOBAL)
44+
add_dependencies(libsail-emu libsail-emu_external)
45+
set_property(TARGET libsail-emu PROPERTY IMPORTED_LOCATION ${sail_src_dir}/${SAIL_SIMULATOR})
46+
47+
set(SAIL_SOFTFLOAT_LIB ${SAIL_SOFTFLOAT_DIR}/softfloat.a)
48+
ExternalProject_Add(
49+
libsail-softfloat_external
50+
SOURCE_DIR ${sail_src_dir}
51+
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E echo "[${PROJECT_NAME}] no configure for libsail-softfloat"
52+
BUILD_COMMAND
53+
${CMAKE_COMMAND} -E env CC=${CMAKE_CURRENT_BINARY_DIR}/sail-cc $(MAKE) -C ${SAIL_SOFTFLOAT_DIR} ${SAIL_SOFTFLOAT_BUILD_ARGS}
54+
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "[${PROJECT_NAME}] no install for libsail-softfloat"
55+
BUILD_IN_SOURCE 1
56+
)
57+
add_library(libsail-softfloat STATIC IMPORTED GLOBAL)
58+
set_property(TARGET libsail-softfloat PROPERTY IMPORTED_LOCATION ${sail_src_dir}/${SAIL_SOFTFLOAT_LIB})
59+
add_dependencies(libsail-softfloat libsail-softfloat_external)
60+
#set(sail_library_dependencies ${sail_library_dependencies}
61+
#libsail-softfloat)
62+
63+
# add all libraries which need to be linked with libsail-emu to the target INTERFACE_LINK_LIBRARIES
64+
# this way they get linked too when libsail-emu gets linked to a target.
65+
set_property(TARGET libsail-emu PROPERTY INTERFACE_LINK_LIBRARIES ${sail_library_dependencies})
66+
67+
add_dependencies(fail-client libsail-emu libsail-softfloat)
68+
target_link_libraries(fail-client fail libsail-emu libsail-softfloat fail-sal fail-sail fail-fsp fail-sal)
69+
install(TARGETS fail-client RUNTIME DESTINATION bin)
70+
71+
# Get stamp directory to touch files for forcing rebuilds.
72+
ExternalProject_Get_Property(libsail-emu_external stamp_dir)
73+
74+
add_custom_target(libsailclean
75+
COMMAND +make -C ${sail_src_dir} clean
76+
COMMAND +make -C ${sail_src_dir}/${SAIL_SOFTFLOAT_DIR} clean
77+
# touch stamp file to force rebuild, without calling configure again.
78+
COMMAND ${CMAKE_COMMAND} -E touch_nocreate ${stamp_dir}/libsail-emu_external-configure || true
79+
COMMAND ${CMAKE_COMMAND} -E touch_nocreate ${stamp_dir}/libsail-softfloat_external-configure || true
80+
COMMENT "[${PROJECT_NAME}] Cleaning all up (clean in sail)"
81+
)
82+
endif(BUILD_SAIL)

configurations/sail.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
FAILPATH=$(dirname $0)/..
3+
ARCH=$1; shift
4+
DEBUG=$1; shift
5+
6+
USE_64=OFF
7+
RISCV=OFF
8+
RISCV_CHERI=OFF
9+
10+
case $ARCH in
11+
riscv32)
12+
RISCV=ON
13+
;;
14+
riscv64)
15+
USE_64=ON
16+
RISCV=ON
17+
;;
18+
cheri32)
19+
RISCV_CHERI=ON
20+
;;
21+
cheri64)
22+
USE_64=ON
23+
RISCV_CHERI=ON
24+
;;
25+
*)
26+
echo "Unknown ARCH argument"
27+
exit 1
28+
;;
29+
esac
30+
31+
case $DEBUG in
32+
ON)
33+
TYPE=Debug
34+
;;
35+
36+
OFF|"")
37+
TYPE=Release
38+
;;
39+
40+
*)
41+
echo "Unknown DEBUG Arg"
42+
exit 1
43+
esac
44+
45+
46+
cmake \
47+
-DCMAKE_AGPP_FLAGS:STRING="--c_compiler clang++" \
48+
-DBUILD_64BIT:BOOL="${USE_64}"\
49+
-DVERBOSE_MAKE:BOOL="${DEBUG}" \
50+
-DCMAKE_BUILD_TYPE="${TYPE}" \
51+
-DBUILD_SAIL:BOOL=ON \
52+
-DBUILD_RISCV_CHERI:BOOL=${RISCV_CHERI} \
53+
-DBUILD_RISCV:BOOL=${RISCV} \
54+
-DBUILD_BOCHS:BOOL=OFF \
55+
-DBUILD_GEM5:BOOL=OFF \
56+
-DBUILD_X86:BOOL=OFF \
57+
-DBUILD_ARM:BOOL=OFF \
58+
-DCONFIG_EVENT_BREAKPOINTS:BOOL=ON \
59+
-DCONFIG_EVENT_IOPORT:BOOL=ON \
60+
-DCONFIG_EVENT_MEMREAD:BOOL=ON \
61+
-DCONFIG_EVENT_MEMWRITE:BOOL=ON \
62+
-DCONFIG_EVENT_TRAP:BOOL=ON \
63+
-DCONFIG_SR_RESTORE:BOOL=ON \
64+
-DCONFIG_SR_SAVE:BOOL=ON \
65+
-DEXPERIMENTS_ACTIVATED:STRING="generic-tracing;generic-experiment" \
66+
-DPLUGINS_ACTIVATED:STRING="tracing;serialoutput" \
67+
-DBUILD_DUMP_TRACE:BOOL=ON \
68+
-DBUILD_IMPORT_TRACE:BOOL=ON \
69+
-DBUILD_PRUNE_TRACE:BOOL=ON \
70+
-DBUILD_LLVM_DISASSEMBLER=ON \
71+
-DCLIENT_RETRY_COUNT=1 \
72+
-H${FAILPATH}

simulators/sail/README

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# steps to take to implement a new architecture
2+
3+
4+
- include fail_defs.sail into sail spec
5+
- define xlenbits to architecture instruction length
6+
- call functions defined in fail_defs.sail from model sail code
7+

simulators/sail/fail_defs.sail

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
val fail_executeRequests = {c: "fail_executeRequests"} : unit -> unit
2+
val fail_onTrap = {c: "fail_onTrap"} : bits(8) -> unit
3+
val fail_onInterrupt = {c: "fail_onInterrupt"} : (bits(8), bool) -> unit
4+
val fail_isSuppressedInterrupt = {c: "fail_isSuppressedInterrupt"} : bits(8) -> bool
5+
val fail_willExecuteInstruction = {c: "fail_willExecuteInstruction" } : (xlenbits) -> unit
6+
val fail_didExecuteInstruction = {c: "fail_didExecuteInstruction"} : (xlenbits, xlenbits) -> unit
7+
val fail_setInstructionFetch = {c: "fail_setInstructionFetch"} : bool -> unit
8+
9+
let fail_memtype_ram : bits(8) = 0b00000001
10+
let fail_memtype_tags : bits(8) = 0b00000011
11+
val fail_onMemoryRead = {c: "fail_onMemoryRead"} : (xlenbits, int, int, bits(8), xlenbits) -> unit
12+
val fail_onMemoryWrite = {c: "fail_onMemoryWrite"} : (xlenbits, int, int, bits(8), xlenbits) -> unit

simulators/sail/fail_empty_source_file_for_build.cc

Whitespace-only changes.

simulators/sail/sail-cc.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
echo @sail_build_CC@ @sail_build_CFLAGS@ $*
4+
exec @sail_build_CC@ @sail_build_CFLAGS@ $*

src/core/config/VariantConfig.hpp.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
#cmakedefine BUILD_T32
88
#cmakedefine BUILD_PANDA
99
#cmakedefine T32_MOCK_API
10+
#cmakedefine BUILD_SAIL
11+
#cmakedefine BUILD_RISCV
12+
#cmakedefine BUILD_RISCV_CHERI
1013

1114
#cmakedefine BUILD_X86
1215
#cmakedefine BUILD_ARM
16+
#cmakedefine BUILD_64BIT
1317

1418
#cmakedefine BUILD_LLVM_DISASSEMBLER
1519
#cmakedefine BUILD_CAPSTONE_DISASSEMBLER

src/core/sal/Architecture.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@
1414
#include "arm/ArmArchitecture.hpp"
1515
#endif
1616

17+
#ifdef BUILD_SAIL
18+
#include "sail/SailArchitecture.hpp"
19+
#endif
20+
1721
#endif

0 commit comments

Comments
 (0)