-
Notifications
You must be signed in to change notification settings - Fork 0
/
oldland_regfile.v
53 lines (44 loc) · 1.43 KB
/
oldland_regfile.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
module oldland_regfile(input wire clk,
input wire rst,
input wire [3:0] ra_sel,
input wire [3:0] rb_sel,
input wire [3:0] rd_sel,
input wire wr_en,
input wire [31:0] wr_val,
output wire [31:0] ra,
output wire [31:0] rb,
input wire [3:0] dbg_reg_sel,
output wire [31:0] dbg_reg_val,
input wire [31:0] dbg_reg_wr_val,
input wire dbg_reg_wr_en,
input wire dbg_en);
reg [31:0] registers[15:0];
reg [4:0] regno = 5'b0;
wire [3:0] port_a_sel = dbg_en ? dbg_reg_sel : ra_sel;
reg [31:0] port_a_val = 32'b0;
wire [3:0] port_b_sel = rb_sel;
reg [31:0] port_b_val = 32'b0;
wire [31:0] wr_port_val = dbg_en ? dbg_reg_wr_val : wr_val;
wire wr_port_wr_en = dbg_en ? dbg_reg_wr_en : wr_en;
wire [3:0] wr_port_sel = dbg_en ? dbg_reg_sel : rd_sel;
assign ra = port_a_val;
assign rb = port_b_val;
assign dbg_reg_val = port_a_val;
initial begin
for (regno = 0; regno < 16; regno = regno + 5'b1)
registers[regno[3:0]] = 32'b0;
end
always @(posedge clk) begin
if (rst) begin
for (regno = 0; regno < 16; regno = regno + 5'b1)
registers[regno[3:0]] <= 32'b0;
end else begin
port_a_val <= (wr_en && port_a_sel == rd_sel) ? wr_port_val :
registers[port_a_sel];
port_b_val <= (wr_en && port_b_sel == rd_sel) ? wr_port_val :
registers[port_b_sel];
if (wr_port_wr_en)
registers[wr_port_sel] <= wr_port_val;
end
end
endmodule