-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
119 lines (98 loc) · 2.04 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <stdio.h>
#include <limits.h>
#include "types.h"
#include "tools.h"
#include "memory.h"
#include "registers.h"
#include "loader.h"
#include "dump.h"
#include "fetchStage.h"
#include "decodeStage.h"
#include "executeStage.h"
#include "memoryStage.h"
#include "writebackStage.h"
int clockCount;
bool stop;
static fwdStruct fwd;
void initialize();
void initFwdStruct();
int main(int argc, char * argv[]) {
if (argc < 2) {
printf("Please provide a filename.\n");
return 0;
}
if (!openFile(argv[1])) {
printf("Failed to open file.\nUsage: yess <filename>.yo\n");
return 0;
}
initialize();
if (!load()) {
dumpMemory();
return 0;
}
while(!stop) {
stop = writebackStage(&fwd);
memoryStage(&fwd);
executeStage(&fwd);
decodeStage(&fwd);
fetchStage(&fwd);
clockCount++;
}
printf("\nTotal clock cycles = %d\n", clockCount);
return 0;
}
/* initialize
* Initializes a bunch of stuff.
* Params: none
* Returns: void
* Modifies: W_valE, W_dstE
*/
void initialize() {
clockCount = 0;
stop = FALSE;
initFwdStruct();
initializeFuncPtrArray();
initializeCC();
clearMemory();
clearRegisters();
clearFregister();
clearDregister();
clearEregister();
clearMregister();
clearWregister();
}
/* initFwdStuct
* Initializes the fowarding struct.
* Params: none
* Returns: void
* Modifies: fwd
*/
void initFwdStruct() {
//fetch
fwd.d_srcA = 0;
fwd.d_srcB = 0;
//decode
fwd.D_icode = 0;
//execute
fwd.E_icode = 0;
fwd.e_Cnd = 0;
fwd.e_dstE = 0;
fwd.e_valE = 0;
fwd.E_dstM = 0;
//memory
fwd.M_icode = 0;
fwd.M_Cnd = 0;
fwd.m_stat = 0;
fwd.M_dstM = 0;
fwd.M_dstE = 0;
fwd.m_valM = 0;
fwd.M_valE = 0;
fwd.M_valA = 0;
//writeback
fwd.W_icode = 0;
fwd.W_stat = 0;
fwd.W_dstM = 0;
fwd.W_dstE = 0;
fwd.W_valM = 0;
fwd.W_valE = 0;
}