-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyis.c
64 lines (47 loc) · 1.23 KB
/
yis.c
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
/* Instruction set simulator for Y86-64 Architecture */
#include <stdio.h>
#include <stdlib.h>
#include "isa.h"
/* YIS never runs in GUI mode */
int gui_mode = 0;
void usage(char *pname)
{
printf("Usage: %s code_file [max_steps]\n", pname);
exit(0);
}
int main(int argc, char *argv[])
{
FILE *code_file;
int max_steps = 10000;
state_ptr s = new_state(MEM_SIZE);
mem_t saver = copy_reg(s->r);
mem_t savem;
int step = 0;
stat_t e = STAT_AOK;
if (argc < 2 || argc > 3)
usage(argv[0]);
code_file = fopen(argv[1], "r");
if (!code_file) {
fprintf(stderr, "Can't open code file '%s'\n", argv[1]);
exit(1);
}
if (!load_mem(s->m, code_file, 1)) {
printf("Exiting\n");
return 1;
}
savem = copy_mem(s->m);
if (argc > 2)
max_steps = atoi(argv[2]);
for (step = 0; step < max_steps && e == STAT_AOK; step++)
e = step_state(s, stdout);
printf("Stopped in %d steps at PC = 0x%llx. Status '%s', CC %s\n",
step, s->pc, stat_name(e), cc_name(s->cc));
printf("Changes to registers:\n");
diff_reg(saver, s->r, stdout);
printf("\nChanges to memory:\n");
diff_mem(savem, s->m, stdout);
free_state(s);
free_reg(saver);
free_mem(savem);
return 0;
}