From 664e147d200c98185f573e36fca1a13f9cbdb349 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Thu, 3 Aug 2023 09:24:18 -0700 Subject: [PATCH] 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). --- c_emulator/riscv_sim.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/c_emulator/riscv_sim.c b/c_emulator/riscv_sim.c index 93609b433..8a0f3acaf 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) {