-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatapath.v
306 lines (247 loc) · 7.5 KB
/
datapath.v
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
`include "pc_reg.v"
`include "decoder.v"
`include "ex_alu.v"
`include "rf32x32.v"
`include "other_modules.v"
`define START 32'h0001_0000
module Datapath(
// in
input [0 :0 ] clk,
input [0 :0 ] rst_n,
input [0 :0 ] is_type_l,
// i_mem io
input [31:0 ] inst_i,
output [31:0 ] pc_out_o,
// d_mem io
input [31:0 ] mem_read_data_i,
output [31:0 ] mem_address_o,
output [2 :0 ] wr_width_o,
output [0 :0 ] mem_read_ctrl_o,
output [0 :0 ] mem_write_ctrl_o,
output [31:0 ] mem_write_data_o
);
/* * * * * * * wires * * * * * * */
// pc_reg
// pc_in from plus4_plusimm_mux in PC_handle_part
wire [31:0 ] pc_out; // to PC_handle_part & I_mem // maybe module Datapath output
wire [31:0 ] pc_out_;
// I_mem
wire [31:0 ] inst; // to decoder // maybe module Datapath input
// decoder
wire [4 :0 ] rs1, rs2, rd; // to regfile
wire [31:0 ] imm_exten; // to PC_handle_part & reg_imm_mux
wire [9 :0 ] jbs_flag_cache; // to B_J_Jr_judge
wire [2 :0 ] wr_width; // to D_mem // maybe module Datapath output // var width need be correct to 2
wire [3 :0 ] alu_ctrl; // to ALU
wire [0 :0 ] alu_dataB_sel; // to reg_imm_mux
wire [0 :0 ] reg_w_ctrl; // to regfile
wire [0 :0 ] reg_w_data_sel; // to ALU_Dmem_mux
wire [0 :0 ] mem_read_ctrl; // to D_mem // maybe module Datapath output
wire [0 :0 ] mem_write_ctrl; // to D_mem // maybe module Datapath output
// regfile
wire [31:0 ] reg_dataA; // to PC_handle_part & ALU
wire [31:0 ] reg_dataB; // to reg_imm_mux
// reg_imm_mux
wire [31:0 ] mux_ALU_dataB; // to ALU
// ALU
wire [31:0 ] alu_dataC; // to D_mem
wire [0 :0 ] compare_res; // to B_J_Jr_judge
wire [0 :0 ] alu_zero; // to B_J_Jr_judge
// D_mem
wire [31:0 ] r_data; // to ALU_Dmem_mux
// ALU_Dmem_mux
wire [31:0 ] ALU_Dmem_mux_data; // to data_pc_mux
// data_pc_mux
wire [31:0 ] rd_data; // to regfile
// B_J_Jr_judge
wire [0 :0 ] judge_a; // to pc_reg_mux
wire [0 :0 ] judge_b; // to plus4_plusimm_mux
wire [0 :0 ] judge_c; // to data_pc_mux
wire [0 :0 ] judge_d, judge_e; // to typeu_1_mux; typeu_2_mux
// pc_reg_mux
wire [31:0 ] pc_reg_data; // to pcoreg_imm_add
// typeu_1_mux
wire [31:0 ] typeu_1_wire;
// pc_4_add
wire [31:0 ] pc_plus4; // to plus4_plusimm_mux & data_pc_mux
// pcoreg_imm_add
wire [31:0 ] pcreg_plusimm; // to plus4_plusimm_mux
// plus4_plusimm_mux
wire [31:0 ] pc_in; // to pc_reg
// typeu_2_mux
wire [31:0 ] typeu_2_wire;
/* * * * * * * wires * * * * * * */
/* * * * * * * modules * * * * * * */
// pc_reg
Pc_reg pc_reg(
.clk(clk),
.rst_n(rst_n),
.pc_in(pc_in),
.pc_out(pc_out),
.pc_out_(pc_out_),
.is_type_l(is_type_l)
);
// I_mem
// in : pc_out
// out: inst
assign inst = inst_i;
assign pc_out_o = pc_out;
// decoder
Decoder decoder(
.inst(inst),
.is_type_l(is_type_l),
.rs1(rs1),
.rs2(rs2),
.rd(rd),
.imm_exten(imm_exten),
.jbs_flag_cache(jbs_flag_cache),
.wr_width(wr_width),
.alu_ctrl(alu_ctrl),
.alu_dataB_sel(alu_dataB_sel),
.reg_w_ctrl(reg_w_ctrl),
.reg_w_data_sel(reg_w_data_sel),
.mem_read_ctrl(mem_read_ctrl),
.mem_write_ctrl(mem_write_ctrl),
.alu_op(),.pc_add_sel()
);
rf32x32 rf(
.clk(clk),
.reset(rst_n),
//.wr_n(rst_n & (is_type_l | reg_w_ctrl)),
.wr_n(reg_w_ctrl),
.rd1_addr(rs1),
.rd2_addr(rs2),
.wr_addr(rd),
.data_in(rd_data),
.data1_out(reg_dataA),
.data2_out(reg_dataB)
);
// reg_imm_mux
Mux reg_imm_mux(
.select(alu_dataB_sel),
.dataA(reg_dataB),
.dataB(imm_exten),
.dataC(mux_ALU_dataB)
);
// ALU
Ex_alu alu(
//.clk(clk),
.rst_n(rst_n),
.alu_ctrl(alu_ctrl),
.alu_dataA(reg_dataA),
.alu_dataB(mux_ALU_dataB),
.alu_dataC(alu_dataC),
.alu_zero(alu_zero),
.alu_overflow(alu_overflow),
.compare_res(compare_res)
);
// D_mem
// in :
// out: mem_read_data
assign mem_address_o = alu_dataC;
assign wr_width_o = wr_width;
assign mem_read_ctrl_o = mem_read_ctrl;
assign mem_write_ctrl_o = mem_write_ctrl;
assign mem_write_data_o = reg_dataB;
// ALU_Dmem_mux
Mux ALU_Dmem_mux(
.select(reg_w_data_sel),
.dataA(alu_dataC),
.dataB(mem_read_data_i),
.dataC(ALU_Dmem_mux_data)
);
// data_pc_mux
Mux data_pc_mux(
.select(judge_c),
.dataA(ALU_Dmem_mux_data),
.dataB(typeu_2_wire),
.dataC(rd_data) //rd_data
);
/* * * * * * * modules * * * * * * */
// Judger B_J_Jr_judge(
// .jbs_flag_cache(jbs_flag_cache),
// .compare_res(compare_res),
// .alu_zero(alu_zero),
// .judge_a(judge_a),
// .judge_b(judge_b),
// .judge_c(judge_c),
// .judge_d(judge_d),
// .judge_e(judge_e)
// );
// ---------------------------
// devide Judger into
// JJrU_Judger & Branch_Judger
// ---------------------------
wire judge_b1, judge_b2, jjruF;
JJrUJudger jjru_judger(
.jjru_flag_cache(jbs_flag_cache[3:0]),
.judge_a(judge_a),
.judge_b1(judge_b1),
.judge_d(judge_d),
.judge_e(judge_e),
.jjruF(jjruF)
);
BranchJudger branch_judger(
.jjruF(jjruF),
.b_flag_cache(jbs_flag_cache[9:4]),
.compare_res(compare_res),
.alu_zero(alu_zero),
.judge_b2(judge_b2),
.judge_c(judge_c)
);
assign judge_b = judge_b1 | judge_b2;
/* * * * * * PC handle part* * * * * */
// pc_reg_mux
Mux pc_reg_mux(
.select(judge_a),
.dataA(pc_out_),
.dataB(reg_dataA), // reg_dataA
.dataC(pc_reg_data)
);
// typeu_1_mux
Mux typeu_1_mux(
.select(judge_d),
.dataA(pc_reg_data),
.dataB(32'b0),
.dataC(typeu_1_wire)
);
// pc_4_add
Add pc_4_add (
.dataA(pc_out_),
.dataB(32'd4),
.cin(1'd0),
.cout(),
.dataC(pc_plus4)
);
// pcoreg_imm_add
Add pcoreg_imm_add (
.dataA(typeu_1_wire),
.dataB(imm_exten), // imm << 1
.cin(1'd0),
.cout(),
.dataC(pcreg_plusimm)
);
// plus4_plusimm_mux
Mux plus4_plusimm_mux(
.select(judge_b),
.dataA(pc_plus4),
.dataB(pcreg_plusimm),
.dataC(pc_in)
);
// typeu_2_mux
Mux typeu_2_mux(
.select(judge_e),
.dataA(pc_plus4),
.dataB(pcreg_plusimm),
.dataC(typeu_2_wire)
);
/*- TEST AREA -*/
wire rst_n_o;
RegCondRster rster1(
.clk(clk),
.rst_n_i(rst_n),
.ctrl_sig(judge_b1),
.times(2'b10),
.rst_n_o(rst_n_o)
);
endmodule // endlodule Datapath