summaryrefslogtreecommitdiff
path: root/rtl/core/core_reg_file.sv
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2024-01-21 06:23:46 -0600
committerAlejandro Soto <alejandro@34project.org>2024-02-20 11:11:17 -0600
commitf3b18ead59ae02f95dabbf0a1dea40873a816975 (patch)
tree8979e50f2a37f66a4cd27e937b480efe60d72cf7 /rtl/core/core_reg_file.sv
parenta8bc5a353ea997f73209b39377ee15a73e471237 (diff)
rtl: refactor filenames and directory hierarchy
Diffstat (limited to 'rtl/core/core_reg_file.sv')
-rw-r--r--rtl/core/core_reg_file.sv51
1 files changed, 51 insertions, 0 deletions
diff --git a/rtl/core/core_reg_file.sv b/rtl/core/core_reg_file.sv
new file mode 100644
index 0000000..2ba95e8
--- /dev/null
+++ b/rtl/core/core_reg_file.sv
@@ -0,0 +1,51 @@
+`include "core/uarch.sv"
+
+module core_reg_file
+(
+ input logic clk,
+ rst_n,
+
+ input psr_mode rd_mode,
+ input reg_num rd_r,
+ input reg_index wr_index,
+ input logic wr_enable,
+ wr_enable_file,
+ input word wr_value,
+ wr_current,
+ pc_word,
+
+ output word rd_value
+);
+
+ // Ver comentario en uarch.sv
+ word file[`NUM_GPREGS] /*verilator public*/;
+ word rd_actual;
+ logic rd_pc, hold_rd_pc, forward;
+ reg_index rd_index;
+
+ core_reg_map map_rd
+ (
+ .r(rd_r),
+ .mode(rd_mode),
+ .is_pc(rd_pc),
+ .index(rd_index)
+ );
+
+ assign rd_value = hold_rd_pc ? pc_word : forward ? wr_current : rd_actual;
+
+ always_ff @(posedge clk or negedge rst_n)
+ if(!rst_n) begin
+ forward <= 0;
+ rd_actual <= 0;
+ hold_rd_pc <= 0;
+ end else begin
+ forward <= wr_enable && rd_index == wr_index;
+ hold_rd_pc <= rd_pc;
+
+ if(wr_enable_file)
+ file[wr_index] <= wr_value;
+
+ rd_actual <= file[rd_index];
+ end
+
+endmodule