-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathex2.cpp
More file actions
256 lines (244 loc) · 5.93 KB
/
ex2.cpp
File metadata and controls
256 lines (244 loc) · 5.93 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#include "ex2.h"
EX2::EX2()
{
available = false;
rd = -1;
ALU_output = 0;
pc = 0;
ctrl.BrEq = false;
ctrl.BrLT = false;
ctrl.inst32_25_31 = 0;
ctrl.inst32_2_6 = 0;
ctrl.inst32_12_14 = 0;
err_no = NOTHING;
}
void EX2::set_pc(REG arg_pc)
{
pc = arg_pc;
}
REG EX2::get_pc()
{
return pc;
}
bool EX2::get_available()
{
return available;
}
void EX2::set_available()
{
switch(get_ALUSel())
{
case MUL64:
case MUL64H:
case MUL64HSU:
case MUL64HU:
available = true;
break;
default:
available = false;
break;
}
}
INST32_CTRL_BIT EX2::get_ctrl()
{
return ctrl;
}
void EX2::set_ctrl(INST32_CTRL_BIT arg_ctrl)
{
ctrl.BrEq = arg_ctrl.BrEq;
ctrl.BrLT = arg_ctrl.BrLT;
ctrl.inst32_25_31 = arg_ctrl.inst32_25_31;
ctrl.inst32_2_6 = arg_ctrl.inst32_2_6;
ctrl.inst32_12_14 = arg_ctrl.inst32_12_14;
}
unsigned int EX2::get_rd()
{
return rd;
}
unsigned long long EX2::get_ALU_output()
{
return ALU_output;
}
void EX2::set_Reg(unsigned int arg_rd, unsigned long long arg_ALU_output)
{
rd = arg_rd;
ALU_output = arg_ALU_output;
}
ALUSEL_CTRL EX2::get_ALUSel()
{
switch(ctrl.inst32_2_6)
{
case (0x37 >> 2):
return PASSB;
case (0x17 >> 2):
return ADD64;
case (0x6f >> 2):
return ADD64;
case (0x63 >> 2):
return ADD64;
case (0x23 >> 2):
return ADD64;
case (0x33 >> 2):
switch(ctrl.inst32_12_14)
{
case 0x0:
switch(ctrl.inst32_25_31)
{
case 0x00: return ADD64;
case 0x20: return SUB64;
case 0x01: return MUL64;
default: return ALU_UNKNOWN;
}
case 0x1:
switch(ctrl.inst32_25_31)
{
case 0x00: return SLL64;
case 0x01: return MUL64H;
default: return ALU_UNKNOWN;
}
case 0x2:
switch(ctrl.inst32_25_31)
{
case 0x00: return SLT64;
case 0x01: return MUL64HSU;
default: return ALU_UNKNOWN;
}
case 0x3:
switch(ctrl.inst32_25_31)
{
case 0x00: return SLT64U;
case 0x01: return MUL64HU;
default: return ALU_UNKNOWN;
}
case 0x4:
switch(ctrl.inst32_25_31)
{
case 0x00: return XOR64;
case 0x01: return DIV64;
default: return ALU_UNKNOWN;
}
case 0x6:
switch(ctrl.inst32_25_31)
{
case 0x00: return OR64;
case 0x01: return REM64;
default: return ALU_UNKNOWN;
}
case 0x7:
switch(ctrl.inst32_25_31)
{
case 0x00: return AND64;
case 0x01: return REM64U;
default: return ALU_UNKNOWN;
}
case 0x5:
switch(ctrl.inst32_25_31)
{
case 0x00: return SRL64;
case 0x20: return SRA64;
case 0x01: return DIV64U;
default: return ALU_UNKNOWN;
}
default:
return ALU_UNKNOWN;
}
case (0x3b >> 2):
switch(ctrl.inst32_12_14)
{
case 0x0:
switch(ctrl.inst32_25_31)
{
case 0x00: return ADD32;
case 0x20: return SUB32;
case 0x01: return MUL32;
default: return ALU_UNKNOWN;
}
case 0x1:
if (ctrl.inst32_25_31 != 0x00)
return ALU_UNKNOWN;
return SLL32;
case 0x5:
switch(ctrl.inst32_25_31)
{
case 0x00: return SRL32;
case 0x20: return SRA32;
case 0x01: return DIV32U;
default: return ALU_UNKNOWN;
}
case 0x4:
if (ctrl.inst32_25_31 != 0x01)
return ALU_UNKNOWN;
return DIV32;
case 0x6:
if (ctrl.inst32_25_31 != 0x01)
return ALU_UNKNOWN;
return REM32;
case 0x7: // remuw rd, rs1, rs2
if (ctrl.inst32_25_31 != 0x01)
return ALU_UNKNOWN;
return REM32U;
default:
return ALU_UNKNOWN;
}
case (0x67 >> 2):
return ADD64ALIGN;
case (0x03 >> 2):
return ADD64;
case (0x13 >> 2):
switch(ctrl.inst32_12_14)
{
case 0x0: return ADD64;
case 0x2: return SLT64;
case 0x3: return SLT64U;
case 0x4: return XOR64;
case 0x6: return OR64;
case 0x7: return AND64;
case 0x1:
if ((ctrl.inst32_25_31 >> 1) != 0x00)
return ALU_UNKNOWN;
return SLL64;
case 0x5:
switch(ctrl.inst32_25_31 >> 1)
{
case 0x00: return SRL64;
case 0x10: return SRA64;
default: return ALU_UNKNOWN;
}
default: return ALU_UNKNOWN;
}
case (0x1b >> 2):
switch(ctrl.inst32_12_14)
{
case 0x0: return ADD32;
case 0x1:
if (ctrl.inst32_25_31 != 0x00)
return ALU_UNKNOWN;
return SLL32;
case 0x5:
switch(ctrl.inst32_25_31)
{
case 0x00: return SRL32;
case 0x20: return SRA32;
default: return ALU_UNKNOWN;
}
default: return ALU_UNKNOWN;
}
default:
return ALU_UNKNOWN;
}
}
void EX2::print()
{
printf(" EX2:\n");
if (get_available())
{
printf(" Activated!\n");
printf(" status = %s\n", (err_no==NOTHING?"NTH":"STH"));
printf(" PC = %llx\n", pc);
printf(" inst type = %x", (unsigned char)type);
printf(" ALU output = %llx\n", get_ALU_output());
printf(" rd = %x", rd);
}
else
printf(" Inactivated!\n");
}