-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathcomponents.vhd
420 lines (378 loc) · 16.3 KB
/
components.vhd
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.all;
library work;
use work.utils.all;
package rv_components is
component riscV is
generic (
REGISTER_SIZE : integer := 32;
RESET_VECTOR : natural := 16#00000200#;
MULTIPLY_ENABLE : natural range 0 to 1 := 0;
DIVIDE_ENABLE : natural range 0 to 1 := 0;
SHIFTER_SINGLE_CYCLE : natural range 0 to 2 := 0;
INCLUDE_COUNTERS : natural range 0 to 1 := 0;
BRANCH_PREDICTORS : natural := 0;
FORWARD_ALU_ONLY : natural range 0 to 1 := 1);
port(
clk : in std_logic;
reset : in std_logic;
--conduit end point
coe_to_host : out std_logic_vector(REGISTER_SIZE -1 downto 0);
coe_from_host : in std_logic_vector(REGISTER_SIZE -1 downto 0);
coe_program_counter : out std_logic_vector(REGISTER_SIZE -1 downto 0);
--avalon master bus
avm_data_address : out std_logic_vector(REGISTER_SIZE-1 downto 0);
avm_data_byteenable : out std_logic_vector(REGISTER_SIZE/8 -1 downto 0);
avm_data_read : out std_logic;
avm_data_readdata : in std_logic_vector(REGISTER_SIZE-1 downto 0) := (others => 'X');
avm_data_response : in std_logic_vector(1 downto 0) := (others => 'X');
avm_data_write : out std_logic;
avm_data_writedata : out std_logic_vector(REGISTER_SIZE-1 downto 0);
avm_data_lock : out std_logic;
avm_data_waitrequest : in std_logic := '0';
avm_data_readdatavalid : in std_logic := '0';
--avalon master bus
avm_instruction_address : out std_logic_vector(REGISTER_SIZE-1 downto 0);
avm_instruction_byteenable : out std_logic_vector(REGISTER_SIZE/8 -1 downto 0);
avm_instruction_read : out std_logic;
avm_instruction_readdata : in std_logic_vector(REGISTER_SIZE-1 downto 0) := (others => 'X');
avm_instruction_response : in std_logic_vector(1 downto 0) := (others => 'X');
avm_instruction_write : out std_logic;
avm_instruction_writedata : out std_logic_vector(REGISTER_SIZE-1 downto 0);
avm_instruction_lock : out std_logic;
avm_instruction_waitrequest : in std_logic := '0';
avm_instruction_readdatavalid : in std_logic := '0'
);
end component riscV;
component decode is
generic(
REGISTER_SIZE : positive;
REGISTER_NAME_SIZE : positive;
INSTRUCTION_SIZE : positive;
SIGN_EXTENSION_SIZE : positive;
PIPELINE_STAGES : natural range 1 to 2);
port(
clk : in std_logic;
reset : in std_logic;
stall : in std_logic;
flush : in std_logic;
instruction : in std_logic_vector(INSTRUCTION_SIZE-1 downto 0);
valid_input : in std_logic;
--writeback signals
wb_sel : in std_logic_vector(REGISTER_NAME_SIZE -1 downto 0);
wb_data : in std_logic_vector(REGISTER_SIZE -1 downto 0);
wb_enable : in std_logic;
--output signals
rs1_data : out std_logic_vector(REGISTER_SIZE -1 downto 0);
rs2_data : out std_logic_vector(REGISTER_SIZE -1 downto 0);
sign_extension : out std_logic_vector(SIGN_EXTENSION_SIZE -1 downto 0);
--inputs just for carrying to next pipeline stage
br_taken_in : in std_logic;
pc_curr_in : in std_logic_vector(REGISTER_SIZE-1 downto 0);
br_taken_out : out std_logic;
pc_curr_out : out std_logic_vector(REGISTER_SIZE-1 downto 0);
instr_out : out std_logic_vector(INSTRUCTION_SIZE-1 downto 0);
subseq_instr : out std_logic_vector(INSTRUCTION_SIZE-1 downto 0);
valid_output : out std_logic);
end component decode;
component execute is
generic(
REGISTER_SIZE : positive;
REGISTER_NAME_SIZE : positive;
INSTRUCTION_SIZE : positive;
SIGN_EXTENSION_SIZE : positive;
RESET_VECTOR : natural;
MULTIPLY_ENABLE : boolean;
DIVIDE_ENABLE : boolean;
SHIFTER_SINGLE_CYCLE : natural range 0 to 2;
INCLUDE_COUNTERS : boolean;
FORWARD_ALU_ONLY : boolean);
port(
clk : in std_logic;
reset : in std_logic;
valid_input : in std_logic;
br_taken_in : in std_logic;
pc_current : in std_logic_vector(REGISTER_SIZE-1 downto 0);
instruction : in std_logic_vector(INSTRUCTION_SIZE-1 downto 0);
subseq_instr : in std_logic_vector(INSTRUCTION_SIZE-1 downto 0);
rs1_data : in std_logic_vector(REGISTER_SIZE-1 downto 0);
rs2_data : in std_logic_vector(REGISTER_SIZE-1 downto 0);
sign_extension : in std_logic_vector(SIGN_EXTENSION_SIZE-1 downto 0);
wb_sel : buffer std_logic_vector(REGISTER_NAME_SIZE-1 downto 0);
wb_data : buffer std_logic_vector(REGISTER_SIZE-1 downto 0);
wb_en : buffer std_logic;
to_host : out std_logic_vector(REGISTER_SIZE-1 downto 0);
from_host : in std_logic_vector(REGISTER_SIZE-1 downto 0);
branch_pred : out std_logic_vector(REGISTER_SIZE*2+3-1 downto 0);
stall_pipeline : buffer std_logic;
--memory-bus
address : out std_logic_vector(REGISTER_SIZE-1 downto 0);
byte_en : out std_logic_vector(REGISTER_SIZE/8 -1 downto 0);
write_en : out std_logic;
read_en : out std_logic;
write_data : out std_logic_vector(REGISTER_SIZE-1 downto 0);
read_data : in std_logic_vector(REGISTER_SIZE-1 downto 0);
waitrequest : in std_logic;
datavalid : in std_logic);
end component execute;
component instruction_fetch is
generic (
REGISTER_SIZE : positive;
INSTRUCTION_SIZE : positive;
RESET_VECTOR : natural;
BRANCH_PREDICTORS : natural);
port (
clk : in std_logic;
reset : in std_logic;
stall : in std_logic;
branch_pred : in std_logic_vector(REGISTER_SIZE*2+3-1 downto 0);
instr_out : out std_logic_vector(INSTRUCTION_SIZE-1 downto 0);
pc_out : out std_logic_vector(REGISTER_SIZE-1 downto 0);
br_taken : out std_logic;
valid_instr_out : out std_logic;
read_address : out std_logic_vector(REGISTER_SIZE-1 downto 0);
read_en : out std_logic;
read_data : in std_logic_vector(INSTRUCTION_SIZE-1 downto 0);
read_datavalid : in std_logic;
read_wait : in std_logic
);
end component instruction_fetch;
component arithmetic_unit is
generic (
INSTRUCTION_SIZE : integer;
REGISTER_SIZE : integer;
SIGN_EXTENSION_SIZE : integer;
MULTIPLY_ENABLE : boolean;
DIVIDE_ENABLE : boolean;
SHIFTER_SINGLE_CYCLE : natural range 0 to 2
);
port (
clk : in std_logic;
stall_in : in std_logic;
valid : in std_logic;
rs1_data : in std_logic_vector(REGISTER_SIZE-1 downto 0);
rs2_data : in std_logic_vector(REGISTER_SIZE-1 downto 0);
instruction : in std_logic_vector(INSTRUCTION_SIZE-1 downto 0);
sign_extension : in std_logic_vector(SIGN_EXTENSION_SIZE-1 downto 0);
program_counter : in std_logic_vector(REGISTER_SIZE-1 downto 0);
data_out : out std_logic_vector(REGISTER_SIZE-1 downto 0);
data_enable : out std_logic;
illegal_alu_instr : out std_logic;
less_than : out std_logic;
stall_out : out std_logic);
end component arithmetic_unit;
component branch_unit is
generic (
REGISTER_SIZE : integer;
INSTRUCTION_SIZE : integer;
SIGN_EXTENSION_SIZE : integer);
port (
clk : in std_logic;
stall : in std_logic;
valid : in std_logic;
reset : in std_logic;
rs1_data : in std_logic_vector(REGISTER_SIZE-1 downto 0);
rs2_data : in std_logic_vector(REGISTER_SIZE-1 downto 0);
current_pc : in std_logic_vector(REGISTER_SIZE-1 downto 0);
br_taken_in : in std_logic;
instr : in std_logic_vector(INSTRUCTION_SIZE-1 downto 0);
sign_extension : in std_logic_vector(SIGN_EXTENSION_SIZE-1 downto 0);
data_out : out std_logic_vector(REGISTER_SIZE-1 downto 0);
data_out_en : out std_logic;
is_branch : out std_logic;
br_taken_out : out std_logic;
new_pc : out std_logic_vector(REGISTER_SIZE-1 downto 0); --next pc
bad_predict : out std_logic
);
end component branch_unit;
component load_store_unit is
generic (
REGISTER_SIZE : integer;
SIGN_EXTENSION_SIZE : integer;
INSTRUCTION_SIZE : integer);
port (
clk : in std_logic;
reset : in std_logic;
valid : in std_logic;
rs1_data : in std_logic_vector(REGISTER_SIZE-1 downto 0);
rs2_data : in std_logic_vector(REGISTER_SIZE-1 downto 0);
instruction : in std_logic_vector(INSTRUCTION_SIZE-1 downto 0);
sign_extension : in std_logic_vector(SIGN_EXTENSION_SIZE-1 downto 0);
waiting : buffer std_logic;
data_out : out std_logic_vector(REGISTER_SIZE-1 downto 0);
data_enable : out std_logic;
--memory-bus
address : out std_logic_vector(REGISTER_SIZE-1 downto 0);
byte_en : out std_logic_vector(REGISTER_SIZE/8 -1 downto 0);
write_en : out std_logic;
read_en : out std_logic;
write_data : out std_logic_vector(REGISTER_SIZE-1 downto 0);
read_data : in std_logic_vector(REGISTER_SIZE-1 downto 0);
waitrequest : in std_logic;
readvalid : in std_logic);
end component load_store_unit;
component true_dual_port_ram_single_clock is
generic (
DATA_WIDTH : natural := 8;
ADDR_WIDTH : natural := 6
);
port (
clk : in std_logic;
addr_a : in natural range 0 to 2**ADDR_WIDTH - 1;
addr_b : in natural range 0 to 2**ADDR_WIDTH - 1;
data_a : in std_logic_vector((DATA_WIDTH-1) downto 0);
data_b : in std_logic_vector((DATA_WIDTH-1) downto 0);
we_a : in std_logic := '1';
we_b : in std_logic := '1';
q_a : out std_logic_vector((DATA_WIDTH -1) downto 0);
q_b : out std_logic_vector((DATA_WIDTH -1) downto 0)
);
end component true_dual_port_ram_single_clock;
component byte_enabled_true_dual_port_ram is
generic (
BYTES : natural := 4;
ADDR_WIDTH : natural);
port (
clk : in std_logic;
addr1 : in natural range 0 to 2**ADDR_WIDTH-1;
addr2 : in natural range 0 to 2**ADDR_WIDTH-1;
wdata1 : in std_logic_vector(BYTES*8-1 downto 0);
wdata2 : in std_logic_vector(BYTES*8-1 downto 0);
we1 : in std_logic;
be1 : in std_logic_vector(BYTES-1 downto 0);
we2 : in std_logic;
be2 : in std_logic_vector(BYTES-1 downto 0);
rdata1 : out std_logic_vector(BYTES*8-1 downto 0);
rdata2 : out std_logic_vector(BYTES*8-1 downto 0));
end component byte_enabled_true_dual_port_ram;
component instruction_rom is
generic (
REGISTER_SIZE : integer;
ROM_SIZE : integer;
PORTS : natural range 1 to 2);
port (
clk : in std_logic;
instr_addr : in natural range 0 to ROM_SIZE -1;
data_addr : in natural range 0 to ROM_SIZE -1;
instr_re : in std_logic;
data_re : in std_logic;
data_out : out std_logic_vector(REGISTER_SIZE-1 downto 0);
instr_out : out std_logic_vector(REGISTER_SIZE-1 downto 0);
instr_wait : out std_logic;
data_wait : out std_logic;
instr_readvalid : out std_logic;
data_readvalid : out std_logic);
end component instruction_rom;
component single_port_rom is
generic (
DATA_WIDTH : natural := 8;
ADDR_WIDTH : natural := 8
);
port (
clk : in std_logic;
addr : in natural range 0 to 2**ADDR_WIDTH - 1;
q : out std_logic_vector((DATA_WIDTH -1) downto 0)
);
end component single_port_rom;
component dual_port_rom is
generic (
DATA_WIDTH : natural := 8;
ADDR_WIDTH : natural := 8
);
port (
clk : in std_logic;
addr_a : in natural range 0 to 2**ADDR_WIDTH - 1;
addr_b : in natural range 0 to 2**ADDR_WIDTH - 1;
q_a : out std_logic_vector((DATA_WIDTH -1) downto 0);
q_b : out std_logic_vector((DATA_WIDTH -1) downto 0)
);
end component dual_port_rom;
component register_file
generic(
REGISTER_SIZE : positive;
REGISTER_NAME_SIZE : positive);
port(
clk : in std_logic;
stall : in std_logic;
valid_input : in std_logic;
rs1_sel : in std_logic_vector(REGISTER_NAME_SIZE -1 downto 0);
rs2_sel : in std_logic_vector(REGISTER_NAME_SIZE -1 downto 0);
writeback_sel : in std_logic_vector(REGISTER_NAME_SIZE -1 downto 0);
writeback_data : in std_logic_vector(REGISTER_SIZE -1 downto 0);
writeback_enable : in std_logic;
rs1_data : out std_logic_vector(REGISTER_SIZE -1 downto 0);
rs2_data : out std_logic_vector(REGISTER_SIZE -1 downto 0));
end component register_file;
component pc_incr is
generic (
REGISTER_SIZE : positive;
INSTRUCTION_SIZE : positive);
port (
pc : in std_logic_vector(REGISTER_SIZE-1 downto 0);
instr : in std_logic_vector(INSTRUCTION_SIZE-1 downto 0);
valid_instr : in std_logic;
next_pc : out std_logic_vector(REGISTER_SIZE-1 downto 0));
end component pc_incr;
component wait_cycle_bram is
generic (
BYTES : natural;
ADDR_WIDTH : natural;
WAIT_STATES : natural);
port (
clk : in std_logic;
addr1 : in natural range 0 to 2**ADDR_WIDTH-1;
addr2 : in natural range 0 to 2**ADDR_WIDTH-1;
wdata1 : in std_logic_vector(BYTES*8-1 downto 0);
wdata2 : in std_logic_vector(BYTES*8-1 downto 0);
re1 : in std_logic;
re2 : in std_logic;
we1 : in std_logic;
be1 : in std_logic_vector(BYTES-1 downto 0);
we2 : in std_logic;
be2 : in std_logic_vector(BYTES-1 downto 0);
rdata1 : out std_logic_vector(BYTES*8-1 downto 0);
rdata2 : out std_logic_vector(BYTES*8-1 downto 0);
wait1 : out std_logic;
wait2 : out std_logic;
readvalid1 : out std_logic;
readvalid2 : out std_logic);
end component wait_cycle_bram;
component upper_immediate is
generic (
REGISTER_SIZE : positive;
INSTRUCTION_SIZE : positive);
port (
clk : in std_logic;
valid : in std_logic;
instr : in std_logic_vector(INSTRUCTION_SIZE-1 downto 0);
pc_current : in std_logic_vector(REGISTER_SIZE-1 downto 0);
data_out : out std_logic_vector(REGISTER_SIZE-1 downto 0);
data_en : out std_logic);
end component upper_immediate;
component system_calls is
generic (
REGISTER_SIZE : natural;
INSTRUCTION_SIZE : natural;
RESET_VECTOR : natural;
INCLUDE_COUNTERS : boolean);
port (
clk : in std_logic;
reset : in std_logic;
valid : in std_logic;
rs1_data : in std_logic_vector(REGISTER_SIZE-1 downto 0);
instruction : in std_logic_vector(INSTRUCTION_SIZE-1 downto 0);
finished_instr : in std_logic;
wb_data : out std_logic_vector(REGISTER_SIZE-1 downto 0);
wb_en : out std_logic;
to_host : out std_logic_vector(REGISTER_SIZE-1 downto 0);
from_host : in std_logic_vector(REGISTER_SIZE-1 downto 0);
current_pc : in std_logic_vector(REGISTER_SIZE-1 downto 0);
pc_correction : out std_logic_vector(REGISTER_SIZE -1 downto 0);
pc_corr_en : out std_logic;
illegal_alu_instr : in std_logic;
use_after_load_stall : in std_logic;
predict_corr : in std_logic;
load_stall : in std_logic);
end component system_calls;
end package rv_components;