RISC-V_Verilog/rtl/risc_v_cpu.v

113 lines
2.6 KiB
Coq
Raw Normal View History

2023-10-23 05:15:21 +00:00
module risc_v_cpu (input clock, reset,
output [31:0] out);
2023-10-23 02:47:43 +00:00
wire [31:0] instruction;
wire [31:0] imm;
2023-10-23 02:24:09 +00:00
2023-10-23 02:32:25 +00:00
wire reg_we;
2023-10-23 02:24:09 +00:00
wire [1:0] reg_sel_data_in;
wire [4:0] reg_sel_out_a, reg_sel_out_b, reg_sel_in;
2023-10-23 02:32:25 +00:00
wire [31:0] reg_data_out_a, reg_data_out_b, reg_data_in;
2023-10-21 13:57:58 +00:00
2023-10-23 02:47:43 +00:00
wire alu_src, alu_not;
wire [3:0] alu_func;
wire [31:0] alu_in_b, alu_out;
2023-10-23 02:24:09 +00:00
wire mem_we;
2023-10-23 02:32:25 +00:00
wire [31:0] mem_out;
2023-10-23 02:24:09 +00:00
2023-10-23 02:47:43 +00:00
wire pc_is_jmp;
wire [1:0] pc_is_branch, pc_sel_in;
wire [31:0] pc_addr, pc_new_addr;
2023-10-21 13:57:58 +00:00
decoder decoder (
.instruction(instruction),
2023-10-23 02:24:09 +00:00
.imm(imm),
.reg_we(reg_we),
.reg_sel_data_in(reg_sel_data_in),
.reg_sel_out_a(reg_sel_out_a),
.reg_sel_out_b(reg_sel_out_b),
.reg_sel_in(reg_sel_in),
.alu_src(alu_src),
.alu_func(alu_func),
2023-10-21 13:57:58 +00:00
.mem_we(mem_we),
2023-10-23 02:47:43 +00:00
.pc_is_branch(pc_is_branch),
.pc_is_jmp(pc_is_jmp),
2023-10-21 13:57:58 +00:00
.alu_not(alu_not)
);
registers_bank registers_bank (
.clock(clock),
.reset(reset),
2023-10-23 02:24:09 +00:00
.we(reg_we),
.sel_in(reg_sel_in),
.sel_out_a(reg_sel_out_a),
.sel_out_b(reg_sel_out_b),
.data_in(reg_data_in),
2023-10-23 02:32:25 +00:00
.data_out_a(reg_data_out_a),
.data_out_b(reg_data_out_b)
2023-10-21 13:57:58 +00:00
);
2023-10-23 05:15:21 +00:00
mux2_1 mux2_alu_in_b (
.in_1(reg_data_out_b),
.in_2(imm),
.sel(alu_src),
.out(alu_in_b)
2023-10-21 13:57:58 +00:00
);
alu alu (
2023-10-23 05:15:21 +00:00
.in_a(reg_data_out_a),
.in_b(alu_in_b),
2023-10-23 02:24:09 +00:00
.op_code(alu_func),
2023-10-21 13:57:58 +00:00
.out(alu_out)
);
2023-10-23 05:15:21 +00:00
mux2_1 #(2) mux2_pc_sel_branch (
.in_1(pc_is_branch),
.in_2({alu_out[1], (alu_not ? ~alu_out[0] : alu_out[0])}),
.sel(pc_is_jmp),
.out(pc_sel_in)
2023-10-21 13:57:58 +00:00
);
2023-10-23 05:15:21 +00:00
mux4_1 mux4_pc_sel_in (
.in_1(pc_addr + 4),
.in_2(pc_addr + imm),
.in_3(alu_out),
.in_4(0),
.sel(pc_sel_in),
.out(pc_new_addr)
2023-10-21 13:57:58 +00:00
);
program_counter program_counter (
.clock(clock),
2023-10-22 13:41:39 +00:00
.reset(reset),
2023-10-23 02:24:09 +00:00
.pc_new_addr(pc_new_addr),
.pc_addr(pc_addr)
2023-10-21 13:57:58 +00:00
);
instruction uut_instruction (
2023-10-23 02:24:09 +00:00
.address(pc_addr),
2023-10-21 13:57:58 +00:00
.instruction(instruction)
);
memory memory (
.clock(clock),
.reset(reset),
.we(mem_we),
.address(alu_out),
2023-10-23 02:32:25 +00:00
.data_in(reg_data_out_b),
.data_out(mem_out)
2023-10-21 13:57:58 +00:00
);
2023-10-23 05:15:21 +00:00
mux4_1 mux4_reg_sel_data_in (
.in_1(alu_out),
.in_2(mem_out),
.in_3(pc_addr + 4),
.in_4(pc_addr + alu_out),
.sel(reg_sel_data_in),
.out(reg_data_in)
2023-10-21 13:57:58 +00:00
);
endmodule