-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
executable file
·70 lines (50 loc) · 1.48 KB
/
main.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
65
66
67
68
69
70
//main.c
#include <stdio.h>
#include <fcntl.h>
#include "simulator/simulator.h"
#include "simulator/opcodes.h"
#include "simulator/decode.h"
#include "simulator/core.h"
memory_t main_memory = {
mem_lower_bound: 0,
mem_upper_bound: MEM_SIZE-1
};
int main(int argc, char** argv){
if(argc != 2 || argv[1] == NULL){
printf("Binary file not supplied.");
return -1;
}
char* filename = argv[1];
FILE* binary_file;
// Open the provided file
binary_file = fopen(filename, "rb");
if(binary_file == NULL){
perror("Error reading binary file: ");
return -1;
}
core_state_t processor_state;
for(int i = 0; i < REGFILE_SIZE; i++){
processor_state.regfile[i] = i;
}
processor_state.pc_reg = 0;
fread(&(main_memory.data), 1, MEM_SIZE, binary_file);
for(int j = 0; j < 8; j++){
printf(" x%d: %d", j, processor_state.regfile[j]);
if(j % 2 != 0 && j != 0) printf("\n");
}
for(int i = 0; i < 1024; i++){
int result = execute_rv32i(&main_memory, &processor_state, &processor_state);
if(result != 0){
printf("Error!\n");
break;
}
for(int j = 0; j < 8; j++){
printf(" x%d: %04x", j, processor_state.regfile[j]);
if(j % 2 != 0 && j != 0) printf("\n");
}
printf("Press any key to continue\n");
getchar();
}
fclose(binary_file);
return 0;
}