RISC-V base implementation #1

Merged
BriceBoisson merged 17 commits from risc-v into main 2023-10-24 12:20:46 +00:00
2 changed files with 16 additions and 39 deletions
Showing only changes of commit dc087b24f2 - Show all commits

View File

@ -1,41 +1,20 @@
module registers_bank (input clock, reset, we, module registers_bank (input clock, reset, we,
input [4:0] sel_in, sel_out_a, sel_out_b, input [4:0] sel_in, sel_out_a, sel_out_b,
input [31:0] data_in, input [31:0] data_in,
output [31:0] output_a, output_b); output [31:0] data_out_a, data_out_b);
reg [31:0] registers[31:0]; reg [31:0] registers[31:0];
assign registers[0] = 32'b0; assign registers[0] = 32'b0;
assign registers[1] = 32'b0;
assign registers[2] = 32'b0;
assign registers[3] = 32'b0;
assign registers[4] = 32'b0;
assign registers[5] = 32'b0;
assign registers[6] = 32'b0;
assign registers[7] = 32'b0;
assign registers[8] = 32'b0;
assign registers[9] = 32'b0;
assign registers[10] = 32'b0;
assign registers[11] = 32'b0;
assign registers[12] = 32'b0;
assign registers[13] = 32'b0;
assign registers[14] = 32'b0;
assign registers[15] = 32'b0;
assign registers[16] = 32'b0;
assign registers[17] = 32'b0;
assign registers[18] = 32'b0;
assign registers[19] = 32'b0;
assign registers[20] = 32'b0;
assign registers[21] = 32'b0;
always @(posedge clock, posedge reset) begin always @(posedge clock, posedge reset) begin
if (reset == 1) if (reset == 1)
registers[0] <= 32'b0; registers[0] <= 32'b0;
else if (we == 1) else if (we == 1 && sel_in != 5'b00000)
registers[sel_in] <= data_in; registers[sel_in] <= data_in;
end end
assign output_a = registers[sel_out_a]; assign data_out_a = registers[sel_out_a];
assign output_b = registers[sel_out_b]; assign data_out_b = registers[sel_out_b];
endmodule endmodule

View File

@ -1,24 +1,23 @@
module risc_v_cpu (input clock, reset, output [31:0] out); module risc_v_cpu (input clock, reset, output [31:0] out);
wire [31:0] alu_in_b;
wire [31:0] alu_out;
wire alu_src, alu_not; wire alu_src, alu_not;
wire [3:0] alu_func; wire [3:0] alu_func;
wire [31:0] alu_in_b, alu_out;
wire reg_we, adder_pc; wire reg_we;
wire [1:0] reg_sel_data_in; wire [1:0] reg_sel_data_in;
wire [4:0] reg_sel_out_a, reg_sel_out_b, reg_sel_in; wire [4:0] reg_sel_out_a, reg_sel_out_b, reg_sel_in;
wire [31:0] reg_data_out_a, reg_data_out_b, reg_data_in;
wire [31:0] instruction; wire [31:0] instruction;
wire mem_we; wire mem_we;
wire [31:0] mem_out;
wire [1:0] jmp_pc; wire [1:0] jmp_pc;
wire b_pc; wire b_pc;
wire [31:0] reg_data_in; wire adder_pc;
wire [31:0] output_a, output_b;
wire [31:0] imm; wire [31:0] imm;
wire [31:0] pc_addr; wire [31:0] pc_addr;
@ -26,7 +25,6 @@ module risc_v_cpu (input clock, reset, output [31:0] out);
wire [1:0] pc_in; wire [1:0] pc_in;
wire [31:0] memory_out;
wire [31:0] pc_store; wire [31:0] pc_store;
@ -55,19 +53,19 @@ module risc_v_cpu (input clock, reset, output [31:0] out);
.sel_out_a(reg_sel_out_a), .sel_out_a(reg_sel_out_a),
.sel_out_b(reg_sel_out_b), .sel_out_b(reg_sel_out_b),
.data_in(reg_data_in), .data_in(reg_data_in),
.output_a(output_a), .data_out_a(reg_data_out_a),
.output_b(output_b) .data_out_b(reg_data_out_b)
); );
mux2_1 mux2_1_1 ( mux2_1 mux2_1_1 (
.A(output_b), .A(reg_data_out_b),
.B(imm), .B(imm),
.S(alu_src), .S(alu_src),
.O(alu_in_b) .O(alu_in_b)
); );
alu alu ( alu alu (
.input_a(output_a), .input_a(reg_data_out_a),
.input_b(alu_in_b), .input_b(alu_in_b),
.op_code(alu_func), .op_code(alu_func),
.out(alu_out) .out(alu_out)
@ -106,13 +104,13 @@ module risc_v_cpu (input clock, reset, output [31:0] out);
.reset(reset), .reset(reset),
.we(mem_we), .we(mem_we),
.address(alu_out), .address(alu_out),
.data_in(output_b), .data_in(reg_data_out_b),
.data_out(memory_out) .data_out(mem_out)
); );
mux4_1 mux4_1_2 ( mux4_1 mux4_1_2 (
.A(alu_out), .A(alu_out),
.B(memory_out), .B(mem_out),
.C(pc_addr + 4), .C(pc_addr + 4),
.D(pc_addr + alu_out), .D(pc_addr + alu_out),
.S(reg_sel_data_in), .S(reg_sel_data_in),