Skip to content

Commit

Permalink
Config: Update CMake build system for Sail configuration
Browse files Browse the repository at this point in the history
Because passing in a configuration file is something we need to
do every time, re-purpose the '-c' short option from the optional
SAILCOV feature.
  • Loading branch information
Alasdair committed Mar 7, 2025
1 parent 40d26b5 commit 7ef403c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
32 changes: 26 additions & 6 deletions c_emulator/riscv_sim.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "elf.h"
#include "sail.h"
#include "sail_config.h"
#include "rts.h"
#ifdef SAILCOV
#include "sail_coverage.h"
Expand Down Expand Up @@ -54,6 +55,7 @@ enum {
OPT_ENABLE_ZICBOZ,
OPT_ENABLE_SSTC,
OPT_CACHE_BLOCK_SIZE,
OPT_SAILCOV,
};

static bool do_show_times = false;
Expand Down Expand Up @@ -118,6 +120,8 @@ uint64_t insn_limit = 0;
char *sailcov_file = NULL;
#endif

int have_config = 0;

static struct option options[] = {
{"enable-dirty-update", no_argument, 0, 'd' },
{"enable-misaligned", no_argument, 0, 'm' },
Expand All @@ -138,7 +142,8 @@ static struct option options[] = {
#ifdef RVFI_DII
{"rvfi-dii", required_argument, 0, 'r' },
#endif
{"help", no_argument, 0, 'h' },
{"help", no_argument, 0, 1 },
{"config", required_argument, 0, 'c' },
{"trace", optional_argument, 0, 'v' },
{"no-trace", optional_argument, 0, 'V' },
{"trace-output", required_argument, 0, OPT_TRACE_OUTPUT },
Expand All @@ -152,7 +157,7 @@ static struct option options[] = {
{"enable-zicboz", no_argument, 0, OPT_ENABLE_ZICBOZ },
{"cache-block-size", required_argument, 0, OPT_CACHE_BLOCK_SIZE },
#ifdef SAILCOV
{"sailcov-file", required_argument, 0, 'c' },
{"sailcov-file", required_argument, 0, OPT_SAILCOV },
#endif
{0, 0, 0, 0 }
};
Expand Down Expand Up @@ -240,6 +245,7 @@ static int process_args(int argc, char **argv)
uint64_t pmp_count = 0;
uint64_t pmp_grain = 0;
uint64_t block_size_exp = 0;
bool have_config = false;
while (true) {
c = getopt_long(argc, argv,
"a"
Expand All @@ -258,11 +264,9 @@ static int process_args(int argc, char **argv)
"T:"
"g:"
"h"
"c:"
#ifdef RVFI_DII
"r:"
#endif
#ifdef SAILCOV
"c:"
#endif
"V::"
"v::"
Expand Down Expand Up @@ -364,6 +368,16 @@ static int process_args(int argc, char **argv)
case 'h':
print_usage(argv[0], 0);
break;
case 'c': {
if (access(optarg, R_OK) == 0) {
sail_config_set_file(optarg);
have_config = true;
} else {
fprintf(stderr, "configuration file '%s' does not exist.\n", optarg);
exit(1);
}
break;
}
#ifdef RVFI_DII
case 'r':
rvfi_dii = true;
Expand Down Expand Up @@ -427,7 +441,7 @@ static int process_args(int argc, char **argv)
rv_enable_fdext = false;
break;
#ifdef SAILCOV
case 'c':
case OPT_SAILCOV:
sailcov_file = strdup(optarg);
break;
#endif
Expand All @@ -440,6 +454,12 @@ static int process_args(int argc, char **argv)
break;
}
}

if (!have_config) {
fprintf(stderr, "No configuration file provided.\n");
print_usage(argv[0], 0);
}

#ifdef RVFI_DII
if (optind > argc || (optind == argc && !rvfi_dii))
print_usage(argv[0], 0);
Expand Down
2 changes: 2 additions & 0 deletions config/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
5 changes: 4 additions & 1 deletion sail_runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ add_library(sail_runtime
"${sail_dir}/lib/sail_failure.c"
"${sail_dir}/lib/sail_failure.h"
"${sail_dir}/lib/sail_coverage.h"
"${sail_dir}/lib/sail_state.h"
"${sail_dir}/lib/cJSON.c"
"${sail_dir}/lib/cJSON.h"
"${sail_dir}/lib/sail_config.c"
"${sail_dir}/lib/sail_config.h"
)

target_include_directories(sail_runtime
Expand Down
5 changes: 4 additions & 1 deletion test/riscv-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ foreach (arch IN ITEMS "rv32d" "rv64d")

add_test(
NAME "${arch}_${elf_name}"
COMMAND $<TARGET_FILE:riscv_sim_${arch}> ${elf}
COMMAND
$<TARGET_FILE:riscv_sim_${arch}>
--config "${CMAKE_SOURCE_DIR}/config/default.json"
${elf}
)
endforeach()
endforeach()

0 comments on commit 7ef403c

Please sign in to comment.