-
Notifications
You must be signed in to change notification settings - Fork 0
/
CSR_RegisterFile.sv
48 lines (41 loc) · 1009 Bytes
/
CSR_RegisterFile.sv
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
module CSR_RegisterFile(input logic clk, reset, reg_wr, reg_rd, is_mret, input logic [11:0] addr, input logic [31:0] wdata, PC, input logic [1:0] interrupt,
output logic epc_taken, output logic [31:0] rdata, exc_pc);
logic [31:0] mstatus, mie, mepc, mip, mtvec, mcause;
always_ff @(posedge clk) begin
if (reset) begin
mstatus <= 0;
mie <= 0;
mip <= 2176;
mtvec <= 0;
mcause <= 0;
end
else if (reg_wr) begin
case (addr)
768: mstatus <= wdata;
772: mie <= wdata;
773: mtvec <= wdata;
endcase
end
end
always_comb begin
rdata <= 0;
if (reg_rd) begin
case (addr)
768: rdata <= mstatus;
772: rdata <= mie;
773: rdata <= mtvec;
endcase
end
end
always_comb begin
if (interrupt == 1) begin
mepc <= PC;
epc_taken <= 1;
exc_pc <= 4;
end else if (is_mret) begin
epc_taken <= 1;
exc_pc <= mepc;
end
else epc_taken <= 0;
end
endmodule