Skip to content

Commit

Permalink
Refactor process_args to return the argv index instead of the value
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
arichardson authored and billmcspadden-riscv committed Sep 20, 2023
1 parent c60091a commit 664e147
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions c_emulator/riscv_sim.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 664e147

Please sign in to comment.