diff --git a/.gitignore b/.gitignore index 0079a6798..72da15507 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,7 @@ _build/ _sbuild/ *.o *.a -/z3_problems +z3_problems + +# Typical CMake build directory. +/build diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..4ff7aaee5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,76 @@ +cmake_minimum_required(VERSION 3.22) + +project(sail_riscv) + +# Enable CTest +enable_testing() + +# We technically require C++20 since the C generated by Sail - which we compile +# as C++ - uses designated initialisers, a C++20 feature. However in practice +# much older compilers support this feature so everything does work with C++17, +# but you get lots of warnings on compilers that support C++20 if you use +# this feature without -std=c++20. +if (cxx_std_20 IN_LIST CMAKE_CXX_COMPILE_FEATURES) + set(CMAKE_CXX_STANDARD 20) +else() + set(CMAKE_CXX_STANDARD 17) +endif() +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) + +# Export compile_commands.json for IDE support. +set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) + +# Always use Position Independent Code. By default it is only used for +# shared libraries (which require it), but you also need it for static +# libraries if you link them into shared libraries. +# Generally it just simplifies everything for a negligable performance cost. +set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) + +# Don't allow undefined symbols in shared libraries. This is generally a pain. +if (UNIX) + set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined") +endif() + +# Optional faster binary. Increases compilation time a lot though due to LTO. +option(EXTRA_FAST "Enable aggressive optimisation flags (-march=native, -flto, etc)" FALSE) + +if (EXTRA_FAST) + include("cmake/extra_fast.cmake") +endif() + +# Extra CMake files. +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") + +# These are the main requirements. +# Don't use `REQUIRED` so that we can print custom help messages. +find_package(ZLIB) +if (NOT ZLIB_FOUND) + message(FATAL_ERROR "Zlib not found. Try 'sudo apt install zlib1g-dev' or 'sudo dnf install zlib-devel'.") +endif() + +find_package(GMP) +if (NOT GMP_FOUND) + message(FATAL_ERROR "GMP not found. Try 'sudo apt install libgmp3-dev' or 'sudo dnf install gmp-devel'.") +endif() + +find_program(SAIL_BIN "sail") +if (NOT SAIL_BIN) + message(FATAL_ERROR "Sail not found. See README.md for installation instructions.") +endif() + +set(ENABLED_ARCHITECTURES "rv32;rv64" CACHE STRING "Enabled architectures to build (rv32, rv64, rv32d, rv64f)" ) + +# Softfloat support. +add_subdirectory("dependencies/softfloat") + +# Sail C runtime. +add_subdirectory("sail_runtime") + +# Sail model generated C code. +add_subdirectory("model") + +# Emulator binary. +add_subdirectory("emulator") + +# Old pre-compiled riscv-tests. +add_subdirectory("test/riscv-tests") diff --git a/cmake/extra_fast.cmake b/cmake/extra_fast.cmake new file mode 100644 index 000000000..745d52d0c --- /dev/null +++ b/cmake/extra_fast.cmake @@ -0,0 +1,28 @@ +include(CheckCXXCompilerFlag) + +# Enable agressive optimisation flags. + +# Try to use -march=x86-64-v3, but fall back to -march=native if we are +# using an old compiler that doesn't support that flag. +check_cxx_compiler_flag("-march=x86-64-v3" COMPILER_SUPPORTS_MARCH_X86_V3) +if (COMPILER_SUPPORTS_MARCH_X86_V3) + message(STATUS "Enabling -march=x86-64-v3") + add_compile_options("-march=x86-64-v3") +else() + # Must be quite old so try -march=native. + check_cxx_compiler_flag("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) + if (COMPILER_SUPPORTS_MARCH_NATIVE) + message(STATUS "Enabling -march=native") + add_compile_options("-march=native") + endif() +endif() + +# This makes a measurable difference. +check_cxx_compiler_flag("-fomit-frame-pointer" COMPILER_SUPPORTS_FOMIT_FRAME_POINTER) +if (COMPILER_SUPPORTS_FOMIT_FRAME_POINTER) + message(STATUS "Enabling -fomit-frame-pointer") + add_compile_options("-fomit-frame-pointer") +endif() + +# LTO +set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) diff --git a/cmake/modules/FindGMP.cmake b/cmake/modules/FindGMP.cmake new file mode 100644 index 000000000..7c2c8ca2b --- /dev/null +++ b/cmake/modules/FindGMP.cmake @@ -0,0 +1,46 @@ +# From https://github.com/Z3Prover/z3/blob/7f8e2a9f75f6c8b4b8ab05b87ea6a343d9a0b88d/cmake/modules/FindGMP.cmake +# with minor simplication to remove gmp++ and try pkg-config. + +# Tries to find an install of the GNU multiple precision library +# +# Once done this will define +# GMP_FOUND - BOOL: System has the GMP library installed +# GMP_C_LIBRARIES - LIST: The libraries needed to use GMP via it's C interface +# GMP_C_INCLUDES - LIST: The GMP include directories + +include(FindPackageHandleStandardArgs) + +find_package(PkgConfig) +if (PKG_CONFIG_FOUND) + pkg_check_modules(PC_GMP QUIET gmp) +endif() + +# Try to find libraries +find_library(GMP_C_LIBRARIES + NAMES gmp + PATHS ${PC_GMP_LIBRARY_DIRS} + DOC "GMP C libraries" +) + +# Try to find headers +find_path(GMP_C_INCLUDES + NAMES gmp.h + PATHS ${PC_GMP_INCLUDE_DIRS} + DOC "GMP C header" +) + +# TODO: We should check we can link some simple code against libgmp + +# Handle QUIET and REQUIRED and check the necessary variables were set and if so +# set ``GMP_FOUND`` +find_package_handle_standard_args(GMP + REQUIRED_VARS GMP_C_LIBRARIES GMP_C_INCLUDES) + +if (GMP_FOUND) + if (NOT TARGET GMP::GMP) + add_library(GMP::GMP UNKNOWN IMPORTED) + set_target_properties(GMP::GMP PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${GMP_C_INCLUDES}" + IMPORTED_LOCATION "${GMP_C_LIBRARIES}") + endif() +endif() diff --git a/dependencies/softfloat/CMakeLists.txt b/dependencies/softfloat/CMakeLists.txt new file mode 100644 index 000000000..665017009 --- /dev/null +++ b/dependencies/softfloat/CMakeLists.txt @@ -0,0 +1,44 @@ +SET(source_dir "${CMAKE_CURRENT_SOURCE_DIR}/berkeley-softfloat-3") + +# Generic source plus RISC-V specific source. +file(GLOB riscv_source + "${source_dir}/source/*.c" + "${source_dir}/source/include/*.h" + "${source_dir}/source/RISCV/*.c" + "${source_dir}/source/RISCV/*.h" + "${source_dir}/build/Linux-RISCV-GCC/platform.h" +) + +# Some files do not work with SOFTFLOAT_FAST_INT64 +list(REMOVE_ITEM riscv_source + "${source_dir}/source/s_addExtF80M.c" + "${source_dir}/source/s_addF128M.c" + "${source_dir}/source/s_compareNonnormExtF80M.c" + "${source_dir}/source/s_invalidF128M.c" + "${source_dir}/source/s_mulAddF128M.c" + "${source_dir}/source/s_normRoundPackMToExtF80M.c" + "${source_dir}/source/s_normRoundPackMToF128M.c" + "${source_dir}/source/s_normSubnormalF128SigM.c" + "${source_dir}/source/s_roundPackMToExtF80M.c" + "${source_dir}/source/s_roundPackMToF128M.c" + "${source_dir}/source/s_shiftLeftM.c" + "${source_dir}/source/s_shiftNormSigF128M.c" + "${source_dir}/source/s_shiftRightJamM.c" + "${source_dir}/source/s_shiftRightM.c" + "${source_dir}/source/s_tryPropagateNaNExtF80M.c" + "${source_dir}/source/s_tryPropagateNaNF128M.c" + "${source_dir}/source/RISCV/s_propagateNaNF128M.c" + "${source_dir}/source/RISCV/s_commonNaNToF128M.c" +) + +add_library(softfloat + ${riscv_source} +) + +target_include_directories(softfloat PUBLIC + "${source_dir}/source/include" + "${source_dir}/source/RISCV" + "${source_dir}/build/Linux-RISCV-GCC" +) + +target_compile_options(softfloat PRIVATE "-Werror=implicit-function-declaration" "-DSOFTFLOAT_ROUND_ODD") diff --git a/emulator/CMakeLists.txt b/emulator/CMakeLists.txt new file mode 100644 index 000000000..764163a20 --- /dev/null +++ b/emulator/CMakeLists.txt @@ -0,0 +1,44 @@ +set(EMULATOR_COMMON_SRCS + riscv_config.h + riscv_platform.c + riscv_platform.h + riscv_platform_impl.c + riscv_platform_impl.h + riscv_prelude.c + riscv_prelude.h + riscv_sail.h + riscv_sim.c + riscv_softfloat.c + riscv_softfloat.h +) + +foreach (arch IN LISTS ENABLED_ARCHITECTURES) + add_executable(emulator_${arch} + "${CMAKE_BINARY_DIR}/riscv_model_${arch}.c" + ${EMULATOR_COMMON_SRCS} + ) + + add_dependencies(emulator_${arch} generated_model_${arch}) + + target_link_libraries(emulator_${arch} + PRIVATE softfloat sail_runtime GMP::GMP ZLIB::ZLIB + ) + + target_include_directories(emulator_${arch} + # So the generated C can find riscv_platform/prelude.h" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" + ) + + # TODO: Enable warnings when we use the #include trick + # to include the generated Sail code. Currently it + # generates too many warnings to turn these on globally. + + # target_compile_options(emulator_${arch} PRIVATE + # -Wall -Wextra + # # Too annoying at the moment. + # -Wno-unused-parameter + # ) + + install(TARGETS emulator_${arch}) + +endforeach() diff --git a/model/CMakeLists.txt b/model/CMakeLists.txt new file mode 100644 index 000000000..bb55e3168 --- /dev/null +++ b/model/CMakeLists.txt @@ -0,0 +1,266 @@ +foreach (arch IN LISTS ENABLED_ARCHITECTURES) + if (arch STREQUAL "rv32") + set(xlen 32) + set(flen 32) + elseif (arch STREQUAL "rv64") + set(xlen 64) + set(flen 64) + elseif (arch STREQUAL "rv32d") + set(xlen 32) + set(flen 64) + elseif (arch STREQUAL "rv64f") + set(xlen 64) + set(flen 32) + else() + message(FATAL_ERROR "Invalid architecture: ${arch}") + endif() + + set(sail_xlen + "riscv_xlen${xlen}.sail" + "riscv_xlen.sail" + ) + + # TODO: Unfortunately 32 or 64 bit float support is a compile time. + # See https://github.com/riscv/sail-riscv/issues/348 + if (flen EQUAL 64) + set(sail_flen "riscv_flen_D.sail") + else() + set(sail_flen "riscv_flen_F.sail") + endif() + list(APPEND sail_flen "riscv_flen.sail") + + set(sail_vlen "riscv_vlen.sail") + + # Instruction sources, depending on target + set(sail_check_srcs + "riscv_addr_checks_common.sail" + "riscv_addr_checks.sail" + "riscv_misa_ext.sail" + ) + + set(vext_srcs + "riscv_insts_vext_utils.sail" + "riscv_insts_vext_fp_utils.sail" + "riscv_insts_vext_vset.sail" + "riscv_insts_vext_arith.sail" + "riscv_insts_vext_fp.sail" + "riscv_insts_vext_mem.sail" + "riscv_insts_vext_mask.sail" + "riscv_insts_vext_vm.sail" + "riscv_insts_vext_fp_vm.sail" + "riscv_insts_vext_red.sail" + "riscv_insts_vext_fp_red.sail" + ) + + set(sail_default_inst + "riscv_insts_base.sail" + "riscv_insts_zifencei.sail" + "riscv_insts_aext.sail" + "riscv_insts_zca.sail" + "riscv_insts_mext.sail" + "riscv_insts_zicsr.sail" + "riscv_insts_hints.sail" + "riscv_insts_fext.sail" + "riscv_insts_zcf.sail" + "riscv_insts_dext.sail" + "riscv_insts_zcd.sail" + "riscv_insts_svinval.sail" + "riscv_insts_zba.sail" + "riscv_insts_zbb.sail" + "riscv_insts_zbc.sail" + "riscv_insts_zbs.sail" + "riscv_insts_zfh.sail" + # Zfa needs to be added after fext, dext and Zfh (as it needs + # definitions from those) + "riscv_insts_zfa.sail" + "riscv_insts_zkn.sail" + "riscv_insts_zks.sail" + "riscv_insts_zbkb.sail" + "riscv_insts_zbkx.sail" + "riscv_insts_zicond.sail" + ${vext_srcs} + "riscv_insts_zicbom.sail" + "riscv_insts_zicboz.sail" + ) + + set(sail_seq_inst + ${sail_default_inst} + "riscv_jalr_seq.sail" + ) + + set(sail_seq_inst_srcs + "riscv_insts_begin.sail" + ${sail_seq_inst} + "riscv_insts_end.sail" + "riscv_csr_end.sail" + ) + + set(sail_sys_srcs + "riscv_vext_control.sail" + "riscv_sys_exceptions.sail" + "riscv_sync_exception.sail" + "riscv_zihpm.sail" + "riscv_zkr_control.sail" + "riscv_zicntr_control.sail" + "riscv_softfloat_interface.sail" + "riscv_fdext_regs.sail" + "riscv_fdext_control.sail" + "riscv_sys_control.sail" + ) + + set(sail_vm_srcs + "riscv_vmem_common.sail" + "riscv_vmem_pte.sail" + "riscv_vmem_ptw.sail" + "riscv_vmem_tlb.sail" + "riscv_vmem.sail" + ) + + set(prelude + "prelude.sail" + "riscv_errors.sail" + ${sail_xlen} + ${sail_flen} + ${sail_vlen} + "prelude_mem_addrtype.sail" + "prelude_mem_metadata.sail" + "prelude_mem.sail" + ) + + set(sail_regs_srcs + "riscv_csr_begin.sail" + "riscv_reg_type.sail" + "riscv_freg_type.sail" + "riscv_regs.sail" + "riscv_pc_access.sail" + "riscv_sys_regs.sail" + "riscv_pmp_regs.sail" + "riscv_pmp_control.sail" + "riscv_ext_regs.sail" + ${sail_check_srcs} + "riscv_vreg_type.sail" + "riscv_vext_regs.sail" + ) + + set(sail_arch_srcs + ${prelude} + "riscv_types_common.sail" + "riscv_types_ext.sail" + "riscv_types.sail" + "riscv_vmem_types.sail" + ${sail_regs_srcs} + ${sail_sys_srcs} + "riscv_platform.sail" + "riscv_mem.sail" + ${sail_vm_srcs} + # Shared/common code for the cryptography extension. + "riscv_types_kext.sail" + ) + + set(sail_step_srcs + "riscv_step_common.sail" + "riscv_step_ext.sail" + "riscv_decode_ext.sail" + "riscv_fetch.sail" + "riscv_step.sail" + ) + + # Final file list. + set(sail_srcs + ${sail_arch_srcs} + ${sail_seq_inst_srcs} + ${sail_step_srcs} + "main.sail" + ) + + # The list above can be compared with the ones you get from + # + # VERBOSE=1 make ARCH=RV32 c_emulator/riscv_sim_RV32 + # VERBOSE=1 make ARCH=RV64 c_emulator/riscv_sim_RV64 + # VERBOSE=1 make ARCH=RV32 c_emulator/cheri_riscv_sim_rv32 + # VERBOSE=1 make ARCH=RV64 c_emulator/cheri_riscv_sim_rv64 + # + # The order is sometimes important because Sail is single pass. Code can't + # see declarations that come later. + + # Generate C code from Sail model. This is a single C file. + set(c_model_no_ext "${CMAKE_BINARY_DIR}/riscv_model_${arch}") + set(c_model "${c_model_no_ext}.c") + set(branch_info_file "${c_model_no_ext}.branch_info") + + add_custom_command( + DEPENDS ${sail_srcs} + OUTPUT ${c_model} ${branch_info_file} + VERBATIM + COMMENT "Building C code from Sail model (${arch})" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND + sail + # Output file (without extension). + -o ${c_model_no_ext} + # Generate a file containing information about all possible branches. + # See https://github.com/rems-project/sail/blob/sail2/sailcov/README.md + # --c-coverage ${branch_info_file} + # Don't allow implicit var declaration (like Python). This is + # deprecated because it is error-prone. + --strict-var + # Optimisations. + -O --Oconstant-fold + # Cache Z3 results in z3_problems file to speed up incremental compilation. + --memo-z3 + # Output C code. + -c + # Don't generate a main() function. + --c-no-main + # Extra #include's. + --c-include riscv_prelude.h + --c-include riscv_platform.h + # Don't dead-code eliminate these functions. These should match the + # ones used from riscv_sail.h + --c-preserve init_model + --c-preserve step + --c-preserve tick_clock + --c-preserve tick_platform + --c-preserve _set_Misa_C + --c-preserve _set_Misa_D + --c-preserve _set_Misa_F + # Input files. + ${sail_srcs} + ) + + add_custom_target(generated_model_${arch} DEPENDS ${c_model}) + + set(model_doc "riscv_model_${arch}.json") + + # JSON code snippets output. + add_custom_command( + DEPENDS ${sail_srcs} + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${model_doc}" + VERBATIM + COMMENT "Building documentation JSON from Sail model (${arch})" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND + ${SAIL_BIN} + # Generate JSON documentation file. + -doc + # Format to interpret comments as. You can also use 'asciidoc' + # in which case it will interpret them as Markdown and output them + # as Asciidoc, but there's a bug in the Sail compiler so it can't + # parse the Markdown and it doesn't seem to output the comments + # anyway. + -doc_format identity + # Don't pretty-print the JSON output. It's too big to be readable anyway. + -doc_compact + # Actually embed the code snippets in the JSON as plain text rather + # than referencing them. The other option is base64. + -doc_embed plain + # The directory that the JSON will be saved in. + -o ${CMAKE_CURRENT_BINARY_DIR} + # The name of the JSON file. + -doc_bundle ${model_doc} + # Input files. + ${sail_srcs} + ) + + add_custom_target(generated_docs_${arch} DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${model_doc}") +endforeach() diff --git a/sail_runtime/CMakeLists.txt b/sail_runtime/CMakeLists.txt new file mode 100644 index 000000000..c6f39a310 --- /dev/null +++ b/sail_runtime/CMakeLists.txt @@ -0,0 +1,23 @@ +execute_process( + COMMAND ${sail} --dir + OUTPUT_VARIABLE sail_dir + OUTPUT_STRIP_TRAILING_WHITESPACE + COMMAND_ERROR_IS_FATAL ANY +) + +add_library(sail_runtime + "${sail_dir}/lib/elf.c" + "${sail_dir}/lib/elf.h" + "${sail_dir}/lib/rts.c" + "${sail_dir}/lib/rts.h" + "${sail_dir}/lib/sail.c" + "${sail_dir}/lib/sail.h" + "${sail_dir}/lib/sail_failure.c" + "${sail_dir}/lib/sail_failure.h" + "${sail_dir}/lib/sail_coverage.h" + "${sail_dir}/lib/sail_state.h" +) + +target_include_directories(sail_runtime + PUBLIC "${sail_dir}/lib" +) diff --git a/test/get_perf.py b/test/get_perf.py deleted file mode 100755 index 1570cac4f..000000000 --- a/test/get_perf.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/python -# Estimates the performance of the C backend based on aggregating the unit-tests. -# Assumes a complete run over the unit-tests has been done. - -import os, glob - -def test_perf(d, test_pat, test_type): - couts = glob.glob(os.path.join(d, test_pat)) - if len(couts) == 0: return - - total_insts = 0 - total_msecs = 0 - for c in couts: - with open(c, "r") as f: - insts = 0 - msecs = 0 - perf = None - for l in f.readlines(): - if l.startswith("Instructions:"): insts = int(l.split()[1]) - if l.startswith("Execution:"): msecs = int(l.split()[1]) - if l.startswith("Perf:"): perf = l - #print("Test {0}: {1} insts, {2} msecs".format(c, insts, msecs)) - #if perf: print(perf) - total_insts += insts - total_msecs += msecs - - Kips = total_insts/total_msecs if total_msecs != 0 else float("nan") - print("Average {0} performance: {1} Kips".format(test_type, Kips)) - -def get_test_pat(iset, emode): - return "rv64{0}-{1}-*.cout".format(iset, emode) - -if __name__ == '__main__': - test_dir = os.path.join(os.path.dirname(__file__), "riscv-tests") - for mode in ["p", "v"]: - test_perf(test_dir, get_test_pat("ui", mode), "ui-{0}".format(mode)) - test_perf(test_dir, get_test_pat("um", mode), "um-{0}".format(mode)) - test_perf(test_dir, get_test_pat("ua", mode), "ua-{0}".format(mode)) - test_perf(test_dir, get_test_pat("uc", mode), "uc-{0}".format(mode)) - test_perf(test_dir, get_test_pat("si", mode), "si-{0}".format(mode)) - test_perf(test_dir, get_test_pat("mi", mode), "mi-{0}".format(mode)) - test_perf(test_dir, get_test_pat("*", mode), mode) diff --git a/test/riscv-tests/.gitignore b/test/riscv-tests/.gitignore deleted file mode 100644 index 72a5e441e..000000000 --- a/test/riscv-tests/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.out -*.cout diff --git a/test/riscv-tests/CMakeLists.txt b/test/riscv-tests/CMakeLists.txt new file mode 100644 index 000000000..c5304284f --- /dev/null +++ b/test/riscv-tests/CMakeLists.txt @@ -0,0 +1,46 @@ +# Run the emulator with all the ELF files in lib/sail-riscv/test/riscv-tests/rv32*.elf etc. +# +# On success or failure they write to the `tohost` symbol. See this code: +# https://github.com/riscv/riscv-test-env/blob/4fabfb4e0d3eacc1dc791da70e342e4b68ea7e46/p/riscv_test.h#L200 + +file(GLOB elfs_rv32 CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/rv32*.elf") +file(GLOB elfs_rv64 CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/rv64*.elf") + +foreach (arch IN LISTS ENABLED_ARCHITECTURES) + set(elfs) + if (arch STREQUAL "rv32") + list(APPEND elfs ${elfs_rv32}) + endif() + if (arch STREQUAL "rv64") + list(APPEND elfs ${elfs_rv64}) + endif() + + foreach(elf IN LISTS elfs) + file(RELATIVE_PATH elf_name "${CMAKE_CURRENT_SOURCE_DIR}" ${elf}) + + if (elf_name MATCHES "breakpoint") + continue() + endif() + + # rv64mi-p-access jumps to an address with the top bit set. It expects an + # access fault, but that isn't necessarily the case. + if (elf_name STREQUAL "rv64mi-p-access.elf") + continue() + endif() + # These test RV32 with the D extension, but we have disabled D on RV32. + if (elf_name MATCHES "rv32ud") + continue() + endif() + + # These tests assume that certain bits of medeleg are writable, which + # isn't necessarily the case. + if (elf_name MATCHES "rv(32|64)si-p-(csr|ma_fetch|sbreak|scall).elf") + continue() + endif() + + add_test( + NAME "${arch}_${elf_name}" + COMMAND $ ${elf} + ) + endforeach() +endforeach() diff --git a/test/run_fp_tests.sh b/test/run_fp_tests.sh deleted file mode 100755 index 6d48fdb5c..000000000 --- a/test/run_fp_tests.sh +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env bash -set -e - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -cd $DIR -RISCVDIR="$DIR/.." - -RED='\033[0;91m' -GREEN='\033[0;92m' -YELLOW='\033[0;93m' -NC='\033[0m' - -rm -f $DIR/tests.xml - -pass=0 -fail=0 -all_pass=0 -all_fail=0 -SUITE_XML="" -SUITES_XML="" - -function green { - (( pass += 1 )) - printf "$1: ${GREEN}$2${NC}\n" - SUITE_XML+=" \n" -} - -function yellow { - (( fail += 1 )) - printf "$1: ${YELLOW}$2${NC}\n" - SUITE_XML+=" \n $2\n \n" -} - -function red { - (( fail += 1 )) - printf "$1: ${RED}$2${NC}\n" - SUITE_XML+=" \n $2\n \n" -} - -function finish_suite { - printf "$1: Passed ${pass} out of $(( pass + fail ))\n\n" - SUITES_XML+=" \n$SUITE_XML \n" - SUITE_XML="" - (( all_pass += pass )) || : - (( all_fail += fail )) || : - pass=0 - fail=0 -} - -SAILLIBDIR="$DIR/../../lib/" - -cd $RISCVDIR - -# Do 'make clean' to avoid cross-arch pollution. -make clean - -if make emulator/riscv_sim_RV64; -then - green "Building 64-bit RISCV C emulator" "ok" -else - red "Building 64-bit RISCV C emulator" "fail" -fi -for test in $DIR/riscv-tests/rv64u{f,d}*.elf $DIR/riscv-tests/rv64mi-p-csr.elf; do - if timeout 5 $RISCVDIR/emulator/riscv_sim_RV64 -p $test > ${test%.elf}.cout 2>&1 && grep -q SUCCESS ${test%.elf}.cout - then - green "C-64 $(basename $test)" "ok" - else - red "C-64 $(basename $test)" "fail" - fi -done -finish_suite "64-bit RISCV C tests" - - -if ARCH=RV32 make emulator/riscv_sim_RV32; -then - green "Building 32-bit RISCV C emulator" "ok" -else - red "Building 32-bit RISCV C emulator" "fail" -fi -for test in $DIR/riscv-tests/rv32u{f,d}*.elf $DIR/riscv-tests/rv32mi-p-csr.elf; do - if timeout 5 $RISCVDIR/emulator/riscv_sim_RV32 -p $test > ${test%.elf}.cout 2>&1 && grep -q SUCCESS ${test%.elf}.cout - then - green "C-32 $(basename $test)" "ok" - else - red "C-32 $(basename $test)" "fail" - fi -done -finish_suite "32-bit RISCV C tests" - -printf "Passed ${all_pass} out of $(( all_pass + all_fail ))\n\n" -XML="\n$SUITES_XML\n" -printf "$XML" > $DIR/tests.xml - -if [ $all_fail -gt 0 ] -then - exit 1 -fi diff --git a/test/run_tests.sh b/test/run_tests.sh deleted file mode 100755 index 106bbc9bb..000000000 --- a/test/run_tests.sh +++ /dev/null @@ -1,125 +0,0 @@ -#!/usr/bin/env bash -set -e - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -cd $DIR -RISCVDIR="$DIR/.." - -RED='\033[0;91m' -GREEN='\033[0;92m' -YELLOW='\033[0;93m' -NC='\033[0m' - -rm -f $DIR/tests.xml - -pass=0 -fail=0 -all_pass=0 -all_fail=0 -SUITE_XML="" -SUITES_XML="" - -function green { - (( pass += 1 )) - printf "$1: ${GREEN}$2${NC}\n" - SUITE_XML+=" \n" -} - -function yellow { - (( fail += 1 )) - printf "$1: ${YELLOW}$2${NC}\n" - SUITE_XML+=" \n $2\n \n" -} - -function red { - (( fail += 1 )) - printf "$1: ${RED}$2${NC}\n" - SUITE_XML+=" \n $2\n \n" -} - -function finish_suite { - printf "$1: Passed ${pass} out of $(( pass + fail ))\n\n" - SUITES_XML+=" \n$SUITE_XML \n" - SUITE_XML="" - (( all_pass += pass )) || : - (( all_fail += fail )) || : - pass=0 - fail=0 -} - -SAILLIBDIR="$DIR/../../lib/" - -cd $RISCVDIR - -# Do 'make clean' to avoid cross-arch pollution. -make clean - -printf "Building 32-bit RISCV specification...\n" - -if ARCH=RV32 make emulator/riscv_sim_RV32; -then - green "Building 32-bit RISCV C emulator" "ok" -else - red "Building 32-bit RISCV C emulator" "fail" -fi -for test in $DIR/riscv-tests/rv32*.elf; do - if timeout 5 $RISCVDIR/emulator/riscv_sim_RV32 -p $test > ${test%.elf}.cout 2>&1 && grep -q SUCCESS ${test%.elf}.cout - then - green "C-32 $(basename $test)" "ok" - else - red "C-32 $(basename $test)" "fail" - fi -done -finish_suite "32-bit RISCV C tests" - -# Do 'make clean' to avoid cross-arch pollution. -make clean - -printf "Building 64-bit RISCV specification...\n" - -if make emulator/riscv_sim_RV64; -then - green "Building 64-bit RISCV C emulator" "ok" -else - red "Building 64-bit RISCV C emulator" "fail" -fi -for test in $DIR/riscv-tests/rv64*.elf; do - if timeout 5 $RISCVDIR/emulator/riscv_sim_RV64 -p $test > ${test%.elf}.cout 2>&1 && grep -q SUCCESS ${test%.elf}.cout - then - green "C-64 $(basename $test)" "ok" - else - red "C-64 $(basename $test)" "fail" - fi -done -finish_suite "64-bit RISCV C tests" - -# Do 'make clean' to avoid cross-arch pollution. -make clean - -if ARCH=RV32 make emulator/riscv_rvfi_RV32; -then - green "Building 32-bit RISCV RVFI C emulator" "ok" -else - red "Building 32-bit RISCV RVFI C emulator" "fail" -fi -finish_suite "32-bit RISCV RVFI C tests" - -# Do 'make clean' to avoid cross-arch pollution. -make clean - -if ARCH=RV64 make emulator/riscv_rvfi_RV64; -then - green "Building 64-bit RISCV RVFI C emulator" "ok" -else - red "Building 64-bit RISCV RVFI C emulator" "fail" -fi -finish_suite "64-bit RISCV RVFI C tests" - -printf "Passed ${all_pass} out of $(( all_pass + all_fail ))\n\n" -XML="\n$SUITES_XML\n" -printf "$XML" > $DIR/tests.xml - -if [ $all_fail -gt 0 ] -then - exit 1 -fi