diff options
author | Freya Murphy <freya@freyacat.org> | 2024-09-30 18:52:25 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-09-30 18:52:25 -0400 |
commit | 4af200b00188e02b2c6207dfe494a3dd12556c5f (patch) | |
tree | 25d993117e6306907d1d3821ef4fca729390d221 /msim/main.c | |
parent | update runtime to return exit code from main (diff) | |
download | mips-4af200b00188e02b2c6207dfe494a3dd12556c5f.tar.gz mips-4af200b00188e02b2c6207dfe494a3dd12556c5f.tar.bz2 mips-4af200b00188e02b2c6207dfe494a3dd12556c5f.zip |
msim done (ish)
Diffstat (limited to 'msim/main.c')
-rw-r--r-- | msim/main.c | 74 |
1 files changed, 71 insertions, 3 deletions
diff --git a/msim/main.c b/msim/main.c index 7afb34e..f8a0999 100644 --- a/msim/main.c +++ b/msim/main.c @@ -1,5 +1,73 @@ +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include <merror.h> +#include <signal.h> -int main(void) { - // NOT YET IMPLEMENTED - return 1; +#include "fault.h" +#include "sim.h" + +static void help(void) { + printf("usage: msim [options] executable\n\n"); + printf("options:\n"); + printf("\t-h\t\tprints this help messaage\n"); + printf("\t-c\t\tdisable runtime memory checks (allows segfault)\n"); + printf("\t-d\t\truns the debugger\n"); +} + +int main(int argc, char **argv) { + + struct simulator sim; + struct simulator_args args = { + .executable = NULL, + .debug = false, + .memchk = true, + }; + + int c; + + while ((c = getopt(argc, argv, "hcd")) != 1) { + switch (c) { + case 'h': + help(); + return M_SUCCESS; + case 'c': + args.memchk = false; + break; + case 'd': + args.debug = true; + break; + case '?': + return M_ERROR; + default: + goto next; + } + } + +next: + if (optind < argc - 1) { + ERROR("too many executables passed"); + return M_ERROR; + } + + if (optind >= argc) { + ERROR("no executable passed"); + return M_ERROR; + } + + /// set file name + args.executable = argv[optind]; + + /// create handlers + init_handlers(&sim); + + /// init + if (sim_init(&sim, &args)) + return M_ERROR; + + /* _Noreturn */ + if (args.debug) + sim_debug(&sim); + else + sim_run(&sim); } |