72 lines
1.2 KiB
C
72 lines
1.2 KiB
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <merror.h>
|
|
|
|
#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-j\t\tdisable jump delay slot\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,
|
|
.jdelay = true,
|
|
};
|
|
|
|
int c;
|
|
|
|
while ((c = getopt(argc, argv, "hjd")) != 1) {
|
|
switch (c) {
|
|
case 'h':
|
|
help();
|
|
return M_SUCCESS;
|
|
case 'j':
|
|
args.jdelay = 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);
|
|
}
|