Commit 79a000cb authored by Tomasz Wlostowski's avatar Tomasz Wlostowski

added wait states to the I/D interface. not tested yet

parent 8d0fb7a5
......@@ -41,7 +41,9 @@ module main;
reg [31:0] dm_data_l;
wire [3:0] dm_data_select;
wire dm_write;
reg dm_valid_l = 0;
reg dm_valid_l = 1;
reg dm_ready;
localparam int mem_size = 16384;
......@@ -89,18 +91,21 @@ module main;
if(dm_write && dm_data_select[3])
mem [(dm_addr / 4) % mem_size][31:24] <= dm_data_s[31:24];
if( $dist_uniform(seed, 0, 100 ) <= 50) begin
dm_data_l <= mem[(dm_addr/4) % mem_size];
dm_valid_l <= 1;
end else begin
dm_data_l <= 32'hx;
dm_valid_l <= 0;
end
// dm_data_l <= mem[(dm_addr/4) % mem_size];
end // always@ (posedge clk)
always@(posedge clk)
begin
dm_ready <= 1'b1; // $dist_uniform(seed, 0, 100 ) <= 50;
dm_data_l <= mem[(dm_addr/4) % mem_size];
end
......@@ -119,8 +124,11 @@ module main;
.dm_data_s_o(dm_data_s),
.dm_data_l_i(dm_data_l),
.dm_data_select_o(dm_data_select),
.dm_write_o(dm_write),
.dm_valid_l_i(dm_valid_l)
.dm_store_o(dm_write),
.dm_load_o(),
.dm_store_done_i(1'b1),
.dm_load_done_i(1'b1),
.dm_ready_i(dm_ready)
);
always #5ns clk <= ~clk;
......
......@@ -37,9 +37,12 @@ module rv_cpu
output [31:0] dm_data_s_o,
input [31:0] dm_data_l_i,
output [3:0] dm_data_select_o,
output dm_write_o,
input dm_busy_s_i,
input dm_valid_l_i
input dm_ready_i,
output dm_store_o,
output dm_load_o,
input dm_load_done_i,
input dm_store_done_i
);
wire f_stall;
......@@ -96,6 +99,8 @@ module rv_cpu
.rst_i(rst_i),
.im_data_i(im_data_i),
.f_stall_i(f_stall),
.f_ir_i(f2d_ir),
.f_pc_i(f2d_pc),
......@@ -156,6 +161,8 @@ module rv_cpu
wire [31:0] x2w_dm_addr;
wire x2w_rd_write;
wire [2:0] x2w_fun;
wire x2w_store;
rv_exec execute
......@@ -190,6 +197,7 @@ module rv_cpu
// Writeback stage I/F
.w_fun_o(x2w_fun),
.w_load_o(x2w_load),
.w_store_o(x2w_store),
.w_dm_addr_o(x2w_dm_addr),
.w_rd_o(x2w_rd),
......@@ -199,7 +207,9 @@ module rv_cpu
.dm_addr_o(dm_addr_o),
.dm_data_s_o(dm_data_s_o),
.dm_data_select_o(dm_data_select_o),
.dm_write_o(dm_write_o)
.dm_store_o(dm_store_o),
.dm_load_o(dm_load_o),
.dm_ready_i(dm_ready_i)
);
wire w_stall_req;
......@@ -215,6 +225,7 @@ module rv_cpu
.x_fun_i(x2w_fun),
.x_load_i(x2w_load),
.x_store_i(x2w_store),
.x_rd_i(x2w_rd),
.x_rd_value_i(x2w_rd_value),
......@@ -222,7 +233,9 @@ module rv_cpu
.x_dm_addr_i(x2w_dm_addr),
.dm_data_l_i(dm_data_l_i),
.dm_valid_l_i(dm_valid_l_i),
.dm_load_done_i(dm_load_done_i),
.dm_store_done_i(dm_store_done_i),
.rf_rd_value_o(rf_rd_value),
.rf_rd_o(rf_rd),
......
......@@ -55,6 +55,7 @@ module rv_exec
// Writeback stage I/F
output reg [2:0 ] w_fun_o,
output reg w_load_o,
output reg w_store_o,
output reg [4:0] w_rd_o,
output reg [31:0] w_rd_value_o,
......@@ -65,8 +66,9 @@ module rv_exec
output [31:0] dm_addr_o,
output [31:0] dm_data_s_o,
output [3:0] dm_data_select_o,
// input [31:0] dm_data_l_i,
output dm_write_o
output dm_store_o,
output dm_load_o,
input dm_ready_i
);
wire [31:0] rs1, rs2;
......@@ -84,7 +86,6 @@ module rv_exec
reg [31:0] branch_target;
reg [31:0] dm_addr, dm_data_s, dm_select_s;
reg dm_write_s;
reg rd_write;
......@@ -237,18 +238,6 @@ module rv_exec
shifter_req_d0 <= shifter_req;
wire shifter_stall_req = shifter_req && !shifter_req_d0;
// && !shifter_req_d0;
/* always@(posedge clk_i)
if(shifter_req)
$display("%08x: shifter op %x fun %x %x op1 %x op2 %x", d_pc_i, d_opcode_i, d_fun_i, d_shifter_sign_i, alu_op1, alu_op2);
always@(posedge clk_i)
if(shifter_req_d0)
$display("%08x: shifter result %x", d_pc_i, shifter_result);
*/
// rdest write value
always@*
......@@ -260,36 +249,14 @@ module rv_exec
rd_write <= 1;
end
/* `OPC_JAL, `OPC_JALR:
begin
rd_value <= d_pc_i + 4;
rd_write <= 1;
end
`OPC_LUI:
begin
rd_value <= { d_imm_u_i[31:12] , 12'h0 };
rd_write <= 1;
end
`OPC_AUIPC:
begin
rd_value <= d_pc_i + { d_imm_u_i[31:12], 12'h0 };
rd_write <= 1;
end
*/
default:
begin
rd_value <= 32'hx;
rd_write <= 0;
end
endcase
end
// generate load/store address
always@*
begin
......@@ -351,18 +318,17 @@ module rv_exec
endcase // case (d_opcode_i)
// generate store write
always@*
begin
dm_write_s <= ( (d_opcode_i == `OPC_STORE) && !x_stall_i && d_valid_i);
end
// generate load/store requests
assign dm_addr_o = dm_addr;
assign dm_data_s_o = dm_data_s;
assign dm_data_select_o = dm_select_s;
assign dm_write_o = dm_write_s;
wire is_load = (d_opcode_i == `OPC_LOAD ? 1: 0) && d_valid_i && !x_kill_i;
wire is_store = (d_opcode_i == `OPC_STORE ? 1: 0) && d_valid_i && !x_kill_i;
assign dm_load_o = is_load;
assign dm_store_o = is_store;
always@(posedge clk_i)
if (rst_i) begin
......@@ -372,8 +338,10 @@ module rv_exec
w_rd_o <= 0;
w_fun_o <= 0;
w_load_o <= 0;
w_store_o <= 0;
w_dm_addr_o <= 0;
end else if (!x_stall_i) begin
f_branch_target_o <= branch_target;
f_branch_take_o <= branch_take && !x_kill_i && d_valid_i;
......@@ -386,16 +354,19 @@ module rv_exec
w_rd_write_o <= rd_write && !x_kill_i && d_valid_i;
w_fun_o <= d_fun_i;
w_load_o <= (d_opcode_i == `OPC_LOAD ? 1: 0) && d_valid_i && !x_kill_i;
w_load_o <= is_load;
w_store_o <= is_store;
w_dm_addr_o <= dm_addr;
end else begin // if (!x_stall_i)
f_branch_take_o <= 0;
w_rd_write_o <= 0;
w_load_o <= 0;
w_store_o <= 0;
end
assign x_stall_req_o = shifter_stall_req;
assign x_stall_req_o = shifter_stall_req || ((is_store || is_load) && !dm_ready_i);
endmodule
......
......@@ -32,6 +32,8 @@ module rv_predecode
input [31:0] f_ir_i,
input [31:0] f_pc_i,
input f_stall_i,
output [31:0] x_pc_o,
......@@ -59,8 +61,8 @@ module rv_predecode
wire [4:0] f_opcode = f_ir_i[6:2];
assign rf_rs1_o = im_data_i [19:15];
assign rf_rs2_o = im_data_i [24:20];
assign rf_rs1_o = f_stall_i ? f_ir_i[19:15] : im_data_i [19:15];
assign rf_rs2_o = f_stall_i ? f_ir_i[24:20] : im_data_i [24:20];
assign x_rs1_o = f_ir_i [19:15];
......
......@@ -31,9 +31,10 @@ module rv_writeback
output w_stall_req_o,
input [2:0] x_fun_i,
input x_load_i,
input x_store_i,
input [31:0] x_dm_addr_i,
input [4:0] x_rd_i,
......@@ -41,7 +42,8 @@ module rv_writeback
input x_rd_write_i,
input [31:0] dm_data_l_i,
input dm_valid_l_i,
input dm_load_done_i,
input dm_store_done_i,
output [31:0] rf_rd_value_o,
output [4:0] rf_rd_o,
......@@ -96,8 +98,8 @@ module rv_writeback
assign rf_rd_value_o = (x_load_i ? load_value : x_rd_value_i );
assign rf_rd_o = (x_rd_i);
assign rf_rd_write_o = (w_stall_i ? 1'b0 : (x_load_i && dm_valid_l_i ? 1'b1 : x_rd_write_i ));
assign rf_rd_write_o = (w_stall_i ? 1'b0 : (x_load_i && dm_load_done_i ? 1'b1 : x_rd_write_i ));
assign w_stall_req_o = (x_load_i && !dm_valid_l_i);
assign w_stall_req_o = (x_load_i && !dm_load_done_i) || (x_store_i && !dm_store_done_i);
endmodule // rv_writeback
......@@ -2,35 +2,38 @@ onerror {resume}
quietly WaveActivateNextPane {} 0
add wave -noupdate /main/DUT/clk_i
add wave -noupdate /main/DUT/rst_i
add wave -noupdate -group cpu /main/DUT/clk_i
add wave -noupdate -group cpu /main/DUT/rst_i
add wave -noupdate -group cpu /main/DUT/im_addr_o
add wave -noupdate -group cpu /main/DUT/im_data_i
add wave -noupdate -group cpu /main/DUT/im_valid_i
add wave -noupdate -group cpu /main/DUT/dm_addr_o
add wave -noupdate -group cpu /main/DUT/dm_data_s_o
add wave -noupdate -group cpu /main/DUT/dm_data_l_i
add wave -noupdate -group cpu /main/DUT/dm_data_select_o
add wave -noupdate -group cpu /main/DUT/dm_write_o
add wave -noupdate -group cpu /main/DUT/f_stall
add wave -noupdate -group cpu /main/DUT/f2d_pc
add wave -noupdate -group cpu /main/DUT/f2d_ir
add wave -noupdate -group cpu /main/DUT/f2d_ir_valid
add wave -noupdate -group cpu /main/DUT/x2f_pc_bra
add wave -noupdate -group cpu /main/DUT/x2f_bra
add wave -noupdate -group cpu /main/DUT/d2x_pc
add wave -noupdate -group cpu /main/DUT/rf_rs2
add wave -noupdate -group cpu /main/DUT/rf_rs1
add wave -noupdate -group cpu /main/DUT/d2x_rd
add wave -noupdate -group cpu /main/DUT/d2x_shamt
add wave -noupdate -group cpu /main/DUT/d2x_fun
add wave -noupdate -group cpu /main/DUT/d2x_opcode
add wave -noupdate -group cpu /main/DUT/d2x_shifter_sign
add wave -noupdate -group cpu /main/DUT/d2x_imm_i
add wave -noupdate -group cpu /main/DUT/d2x_imm_s
add wave -noupdate -group cpu /main/DUT/d2x_imm_b
add wave -noupdate -group cpu /main/DUT/d2x_imm_u
add wave -noupdate -group cpu /main/DUT/d2x_imm_j
add wave -noupdate -expand -group cpu /main/DUT/clk_i
add wave -noupdate -expand -group cpu /main/DUT/im_data_i
add wave -noupdate -expand -group cpu /main/DUT/im_valid_i
add wave -noupdate -expand -group cpu /main/DUT/dm_addr_o
add wave -noupdate -expand -group cpu /main/DUT/dm_data_s_o
add wave -noupdate -expand -group cpu /main/DUT/dm_data_l_i
add wave -noupdate -expand -group cpu /main/DUT/dm_data_select_o
add wave -noupdate -expand -group cpu /main/DUT/dm_ready_i
add wave -noupdate -expand -group cpu /main/DUT/dm_store_o
add wave -noupdate -expand -group cpu /main/DUT/dm_load_o
add wave -noupdate -expand -group cpu /main/DUT/dm_load_done_i
add wave -noupdate -expand -group cpu /main/DUT/dm_store_done_i
add wave -noupdate -expand -group cpu /main/DUT/rst_i
add wave -noupdate -expand -group cpu /main/DUT/f_stall
add wave -noupdate -expand -group cpu /main/DUT/f2d_pc
add wave -noupdate -expand -group cpu /main/DUT/f2d_ir
add wave -noupdate -expand -group cpu /main/DUT/f2d_ir_valid
add wave -noupdate -expand -group cpu /main/DUT/x2f_pc_bra
add wave -noupdate -expand -group cpu /main/DUT/x2f_bra
add wave -noupdate -expand -group cpu /main/DUT/d2x_pc
add wave -noupdate -expand -group cpu /main/DUT/rf_rs2
add wave -noupdate -expand -group cpu /main/DUT/rf_rs1
add wave -noupdate -expand -group cpu /main/DUT/d2x_rd
add wave -noupdate -expand -group cpu /main/DUT/d2x_shamt
add wave -noupdate -expand -group cpu /main/DUT/d2x_fun
add wave -noupdate -expand -group cpu /main/DUT/d2x_opcode
add wave -noupdate -expand -group cpu /main/DUT/d2x_shifter_sign
add wave -noupdate -expand -group cpu /main/DUT/d2x_imm_i
add wave -noupdate -expand -group cpu /main/DUT/d2x_imm_s
add wave -noupdate -expand -group cpu /main/DUT/d2x_imm_b
add wave -noupdate -expand -group cpu /main/DUT/d2x_imm_u
add wave -noupdate -expand -group cpu /main/DUT/d2x_imm_j
add wave -noupdate -expand -group fetch /main/DUT/fetch/clk_i
add wave -noupdate -expand -group fetch /main/DUT/fetch/rst_i
add wave -noupdate -expand -group fetch /main/DUT/fetch/im_addr_o
......@@ -104,18 +107,15 @@ add wave -noupdate -expand -group shifter /main/DUT/execute/shifter/shift_1
add wave -noupdate -expand -group shifter /main/DUT/execute/shifter/shift_post
add wave -noupdate -expand -group execute /main/DUT/execute/clk_i
add wave -noupdate -expand -group execute /main/DUT/execute/rst_i
add wave -noupdate -expand -group execute /main/DUT/execute/x_kill_i
add wave -noupdate -expand -group execute /main/DUT/execute/x_stall_i
add wave -noupdate -expand -group execute /main/DUT/execute/x_kill_i
add wave -noupdate -expand -group execute /main/DUT/execute/x_stall_req_o
add wave -noupdate -expand -group execute /main/DUT/execute/d_valid_i
add wave -noupdate -expand -group execute /main/DUT/execute/shifter_req
add wave -noupdate -expand -group execute /main/DUT/execute/shifter_req_d0
add wave -noupdate -expand -group execute /main/DUT/execute/shifter_stall_req
add wave -noupdate -expand -group execute /main/DUT/execute/d_pc_i
add wave -noupdate -expand -group execute /main/DUT/execute/d_rd_i
add wave -noupdate -expand -group execute /main/DUT/execute/d_fun_i
add wave -noupdate -expand -group execute /main/DUT/execute/rf_rs1_value_i
add wave -noupdate -expand -group execute /main/DUT/execute/rf_rs2_value_i
add wave -noupdate -expand -group execute /main/DUT/execute/d_valid_i
add wave -noupdate -expand -group execute /main/DUT/execute/d_opcode_i
add wave -noupdate -expand -group execute /main/DUT/execute/d_shifter_sign_i
add wave -noupdate -expand -group execute /main/DUT/execute/d_imm_i_i
......@@ -127,13 +127,17 @@ add wave -noupdate -expand -group execute /main/DUT/execute/f_branch_target_o
add wave -noupdate -expand -group execute /main/DUT/execute/f_branch_take_o
add wave -noupdate -expand -group execute /main/DUT/execute/w_fun_o
add wave -noupdate -expand -group execute /main/DUT/execute/w_load_o
add wave -noupdate -expand -group execute /main/DUT/execute/w_store_o
add wave -noupdate -expand -group execute /main/DUT/execute/w_rd_o
add wave -noupdate -expand -group execute /main/DUT/execute/w_rd_value_o
add wave -noupdate -expand -group execute /main/DUT/execute/w_rd_write_o
add wave -noupdate -expand -group execute /main/DUT/execute/w_dm_addr_o
add wave -noupdate -expand -group execute /main/DUT/execute/dm_addr_o
add wave -noupdate -expand -group execute /main/DUT/execute/dm_data_s_o
add wave -noupdate -expand -group execute /main/DUT/execute/dm_data_select_o
add wave -noupdate -expand -group execute /main/DUT/execute/dm_write_o
add wave -noupdate -expand -group execute /main/DUT/execute/dm_store_o
add wave -noupdate -expand -group execute /main/DUT/execute/dm_load_o
add wave -noupdate -expand -group execute /main/DUT/execute/dm_ready_i
add wave -noupdate -expand -group execute /main/DUT/execute/rs1
add wave -noupdate -expand -group execute /main/DUT/execute/rs2
add wave -noupdate -expand -group execute /main/DUT/execute/alu_op1
......@@ -141,29 +145,44 @@ add wave -noupdate -expand -group execute /main/DUT/execute/alu_op2
add wave -noupdate -expand -group execute /main/DUT/execute/alu_result
add wave -noupdate -expand -group execute /main/DUT/execute/rd_value
add wave -noupdate -expand -group execute /main/DUT/execute/branch_take
add wave -noupdate -expand -group execute /main/DUT/execute/branch_condition_met
add wave -noupdate -expand -group execute /main/DUT/execute/branch_target
add wave -noupdate -expand -group execute /main/DUT/execute/dm_addr
add wave -noupdate -expand -group execute /main/DUT/execute/dm_data_s
add wave -noupdate -expand -group execute /main/DUT/execute/dm_select_s
add wave -noupdate -expand -group execute /main/DUT/execute/dm_write_s
add wave -noupdate -expand -group execute /main/DUT/execute/rd_write
add wave -noupdate -expand -group execute /main/DUT/execute/cmp_sign_ext
add wave -noupdate -expand -group execute /main/DUT/execute/cmp_op1
add wave -noupdate -expand -group execute /main/DUT/execute/cmp_op2
add wave -noupdate -expand -group execute /main/DUT/execute/cmp_equal
add wave -noupdate -expand -group execute /main/DUT/execute/cmp_lt
add wave -noupdate -expand -group execute /main/DUT/execute/is_subtract
add wave -noupdate -expand -group execute /main/DUT/execute/shifter_result
add wave -noupdate -expand -group execute /main/DUT/execute/shifter_req_d0
add wave -noupdate -expand -group execute /main/DUT/execute/shifter_req
add wave -noupdate -expand -group execute /main/DUT/execute/shifter_stall_req
add wave -noupdate -expand -group execute /main/DUT/execute/is_load
add wave -noupdate -expand -group execute /main/DUT/execute/is_store
add wave -noupdate -expand -group writeback /main/DUT/writeback/clk_i
add wave -noupdate -expand -group writeback /main/DUT/writeback/rst_i
add wave -noupdate -expand -group writeback /main/DUT/writeback/w_stall_i
add wave -noupdate -expand -group writeback /main/DUT/writeback/w_stall_req_o
add wave -noupdate -expand -group writeback /main/DUT/writeback/x_fun_i
add wave -noupdate -expand -group writeback /main/DUT/writeback/x_load_i
add wave -noupdate -expand -group writeback /main/DUT/writeback/x_store_i
add wave -noupdate -expand -group writeback /main/DUT/writeback/x_dm_addr_i
add wave -noupdate -expand -group writeback /main/DUT/writeback/x_rd_i
add wave -noupdate -expand -group writeback /main/DUT/writeback/x_rd_value_i
add wave -noupdate -expand -group writeback /main/DUT/writeback/x_rd_write_i
add wave -noupdate -expand -group writeback /main/DUT/writeback/dm_data_l_i
add wave -noupdate -expand -group writeback /main/DUT/writeback/dm_valid_l_i
add wave -noupdate -expand -group writeback /main/DUT/writeback/dm_load_done_i
add wave -noupdate -expand -group writeback /main/DUT/writeback/dm_store_done_i
add wave -noupdate -expand -group writeback /main/DUT/writeback/rf_rd_value_o
add wave -noupdate -expand -group writeback /main/DUT/writeback/rf_rd_o
add wave -noupdate -expand -group writeback /main/DUT/writeback/rf_rd_write_o
add wave -noupdate -expand -group writeback /main/DUT/writeback/load_value
TreeUpdate [SetDefaultTree]
WaveRestoreCursors {{Cursor 1} {14655000 ps} 0}
WaveRestoreCursors {{Cursor 1} {13680175 ps} 0}
configure wave -namecolwidth 250
configure wave -valuecolwidth 100
configure wave -justifyvalue left
......@@ -178,4 +197,4 @@ configure wave -griddelta 40
configure wave -timeline 0
configure wave -timelineunits ps
update
WaveRestoreZoom {11530808 ps} {16159192 ps}
WaveRestoreZoom {13606882 ps} {13751520 ps}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment