diff options
author | Alex Richardson <alexrichardson@google.com> | 2023-08-03 09:24:18 -0700 |
---|---|---|
committer | Bill McSpadden <bill@riscv.org> | 2023-09-20 13:47:37 -0500 |
commit | 664e147d200c98185f573e36fca1a13f9cbdb349 (patch) | |
tree | 7097ea983821776f12e594362f0952b03e172f43 /c_emulator/riscv_sim.c | |
parent | c60091a6e545534f666448e7ea7514d3b876da93 (diff) | |
download | sail-riscv-664e147d200c98185f573e36fca1a13f9cbdb349.zip sail-riscv-664e147d200c98185f573e36fca1a13f9cbdb349.tar.gz sail-riscv-664e147d200c98185f573e36fca1a13f9cbdb349.tar.bz2 |
Refactor process_args to return the argv index instead of the value
This makes it possible for a follow-up commit to add logic that allows
loading more than one ELF file (e.g. M-mode firmware and S-mode kernel).
Diffstat (limited to 'c_emulator/riscv_sim.c')
-rw-r--r-- | c_emulator/riscv_sim.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/c_emulator/riscv_sim.c b/c_emulator/riscv_sim.c index 93609b4..8a0f3ac 100644 --- a/c_emulator/riscv_sim.c +++ b/c_emulator/riscv_sim.c @@ -226,7 +226,11 @@ static void read_dtb(const char *path) fprintf(stdout, "Read %zd bytes of DTB from %s.\n", dtb_len, path); } -char *process_args(int argc, char **argv) +/** + * Parses the command line arguments and returns the argv index for the ELF file + * that should be loaded. + */ +static int process_args(int argc, char **argv) { int c; uint64_t ram_size = 0; @@ -388,7 +392,7 @@ char *process_args(int argc, char **argv) if (!rvfi_dii) #endif fprintf(stdout, "Running file %s.\n", argv[optind]); - return argv[optind]; + return optind; } void check_elf(bool is32bit) @@ -1044,7 +1048,8 @@ int main(int argc, char **argv) // Initialize model so that we can check or report its architecture. preinit_sail(); - char *file = process_args(argc, argv); + int files_start = process_args(argc, argv); + char *file = argv[files_start]; init_logs(); if (gettimeofday(&init_start, NULL) < 0) { |