2024-09-30 22:52:25 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <merror.h>
|
2024-09-23 03:41:05 +00:00
|
|
|
|
2024-09-30 22:52:25 +00:00
|
|
|
#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");
|
2024-10-01 22:20:50 +00:00
|
|
|
printf("\t-j\t\tdisable jump delay slot\n");
|
2024-09-30 22:52:25 +00:00
|
|
|
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,
|
2024-10-01 22:20:50 +00:00
|
|
|
.jdelay = true,
|
2024-09-30 22:52:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int c;
|
|
|
|
|
2024-10-01 22:20:50 +00:00
|
|
|
while ((c = getopt(argc, argv, "hjd")) != 1) {
|
2024-09-30 22:52:25 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'h':
|
|
|
|
help();
|
|
|
|
return M_SUCCESS;
|
2024-10-01 22:20:50 +00:00
|
|
|
case 'j':
|
|
|
|
args.jdelay = false;
|
2024-09-30 22:52:25 +00:00
|
|
|
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);
|
2024-09-23 03:41:05 +00:00
|
|
|
}
|