summaryrefslogtreecommitdiff
path: root/msim/main.c
blob: 13f638340f85d21291c2149c792122237d5b5195 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#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);
}