aboutsummaryrefslogtreecommitdiff
path: root/rv64cpu/rtl/core
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-03-17 17:32:50 +0000
committerRichard Qin <richard.qin.x@gmail.com>2026-03-17 17:32:50 +0000
commitf29e711b76e7c6bb436111609fa0b14e5c448fb7 (patch)
tree779b66de49904bca8d5cb0f76ae0e28f323bbe8b /rv64cpu/rtl/core
parente8d3b8082110bd66c223ff053c48a8c65ab8da41 (diff)
downloadrcc-project-f29e711b76e7c6bb436111609fa0b14e5c448fb7.tar.gz
rcc-project-f29e711b76e7c6bb436111609fa0b14e5c448fb7.tar.xz
refactor(core): address WB stage architectural and naming review feedback
- Renamed `wb_reg_write_data` and `wb_reg_write_addr` to `wb_rd_wdata` and `wb_rd_addr` respectively to comply with `docs/naming_convention.md`. - Removed the 64-bit adder for `mem_wb_pc + 64'd4` from the WB stage to improve timing. Introduced a new `mem_wb_pc_plus_4` pipeline input instead. - Added a `has_trap` signal to gate architectural state updates (`wb_reg_write_en` and `csr_req`) upon exceptions, ensuring precise exceptions without corrupting the register file or CSRs. Co-authored-by: Richard-Qin-001 <69390919+Richard-Qin-001@users.noreply.github.com>
Diffstat (limited to 'rv64cpu/rtl/core')
-rw-r--r--rv64cpu/rtl/core/wb_stage.sv29
1 files changed, 17 insertions, 12 deletions
diff --git a/rv64cpu/rtl/core/wb_stage.sv b/rv64cpu/rtl/core/wb_stage.sv
index 13dd417..26c9c7b 100644
--- a/rv64cpu/rtl/core/wb_stage.sv
+++ b/rv64cpu/rtl/core/wb_stage.sv
@@ -25,6 +25,7 @@ module wb_stage
input logic [XLEN-1:0] mem_wb_alu_result,
input logic [XLEN-1:0] mem_wb_mem_rdata,
input logic [XLEN-1:0] mem_wb_pc,
+ input logic [XLEN-1:0] mem_wb_pc_plus_4,
input logic mem_wb_reg_write_en,
input logic [4:0] mem_wb_rd_addr,
@@ -46,8 +47,8 @@ module wb_stage
input logic [XLEN-1:0] csr_rdata, // Data read from CSR unit
// Outputs to Register File
- output logic [XLEN-1:0] wb_reg_write_data,
- output logic [4:0] wb_reg_write_addr,
+ output logic [XLEN-1:0] wb_rd_wdata,
+ output logic [4:0] wb_rd_addr,
output logic wb_reg_write_en,
// Outputs to CSR Unit
@@ -66,9 +67,15 @@ module wb_stage
);
// --------------------------
+ // Exception/Trap Detection
+ // --------------------------
+ logic has_trap;
+ assign has_trap = mem_wb_illegal_instr | mem_wb_is_ecall | mem_wb_is_ebreak;
+
+ // --------------------------
// CSR Signal Routing
// --------------------------
- assign csr_req = mem_wb_is_csr;
+ assign csr_req = mem_wb_is_csr & ~has_trap;
assign csr_op = mem_wb_csr_op;
assign csr_addr = mem_wb_imm[11:0];
@@ -83,13 +90,13 @@ module wb_stage
always_comb begin
if (mem_wb_is_csr) begin
// CSR reads write the previous CSR value to the destination register
- wb_reg_write_data = csr_rdata;
+ wb_rd_wdata = csr_rdata;
end else begin
case (mem_wb_wb_sel)
- 2'b00: wb_reg_write_data = mem_wb_alu_result;
- 2'b01: wb_reg_write_data = mem_wb_mem_rdata;
- 2'b10: wb_reg_write_data = mem_wb_pc + 64'd4;
- default: wb_reg_write_data = '0;
+ 2'b00: wb_rd_wdata = mem_wb_alu_result;
+ 2'b01: wb_rd_wdata = mem_wb_mem_rdata;
+ 2'b10: wb_rd_wdata = mem_wb_pc_plus_4;
+ default: wb_rd_wdata = '0;
endcase
end
end
@@ -98,10 +105,8 @@ module wb_stage
// Register File Write Control
// --------------------------
// We only write back if the instruction didn't trap.
- // For now, assume pure write-enable propagation.
- // A future trap controller might kill wb_reg_write_en if taking a trap.
- assign wb_reg_write_addr = mem_wb_rd_addr;
- assign wb_reg_write_en = mem_wb_reg_write_en;
+ assign wb_rd_addr = mem_wb_rd_addr;
+ assign wb_reg_write_en = mem_wb_reg_write_en & ~has_trap;
// --------------------------
// Trap / Exception Signals