rtl: core: fix data related for csr regs

Signed-off-by: liangkangnan <liangkangnan@163.com>
pull/1/head
liangkangnan 2020-06-05 22:22:49 +08:00
parent 0256674146
commit 5b888bd483
2 changed files with 75 additions and 52 deletions

View File

@ -54,6 +54,7 @@ module csr_reg(
reg[`RegBus] mepc; reg[`RegBus] mepc;
reg[`RegBus] mie; reg[`RegBus] mie;
reg[`RegBus] mstatus; reg[`RegBus] mstatus;
reg[`RegBus] mscratch;
assign global_int_en_o = (mstatus[3] == 1'b1)? `True: `False; assign global_int_en_o = (mstatus[3] == 1'b1)? `True: `False;
@ -82,6 +83,7 @@ module csr_reg(
mepc <= `ZeroWord; mepc <= `ZeroWord;
mie <= `ZeroWord; mie <= `ZeroWord;
mstatus <= `ZeroWord; mstatus <= `ZeroWord;
mscratch <= `ZeroWord;
end else begin end else begin
// ex // ex
if (we_i == `WriteEnable) begin if (we_i == `WriteEnable) begin
@ -101,6 +103,9 @@ module csr_reg(
`CSR_MSTATUS: begin `CSR_MSTATUS: begin
mstatus <= data_i; mstatus <= data_i;
end end
`CSR_MSCRATCH: begin
mscratch <= data_i;
end
default: begin default: begin
end end
@ -123,6 +128,9 @@ module csr_reg(
`CSR_MSTATUS: begin `CSR_MSTATUS: begin
mstatus <= clint_data_i; mstatus <= clint_data_i;
end end
`CSR_MSCRATCH: begin
mscratch <= clint_data_i;
end
default: begin default: begin
end end
@ -137,32 +145,39 @@ module csr_reg(
if (rst == `RstEnable) begin if (rst == `RstEnable) begin
data_o = `ZeroWord; data_o = `ZeroWord;
end else begin end else begin
case (raddr_i[11:0]) if ((waddr_i[11:0] == raddr_i[11:0]) && (we_i == `WriteEnable)) begin
`CSR_CYCLE: begin data_o = data_i;
data_o = cycle[31:0]; end else begin
end case (raddr_i[11:0])
`CSR_CYCLEH: begin `CSR_CYCLE: begin
data_o = cycle[63:32]; data_o = cycle[31:0];
end end
`CSR_MTVEC: begin `CSR_CYCLEH: begin
data_o = mtvec; data_o = cycle[63:32];
end end
`CSR_MCAUSE: begin `CSR_MTVEC: begin
data_o = mcause; data_o = mtvec;
end end
`CSR_MEPC: begin `CSR_MCAUSE: begin
data_o = mepc; data_o = mcause;
end end
`CSR_MIE: begin `CSR_MEPC: begin
data_o = mie; data_o = mepc;
end end
`CSR_MSTATUS: begin `CSR_MIE: begin
data_o = mstatus; data_o = mie;
end end
default: begin `CSR_MSTATUS: begin
data_o = `ZeroWord; data_o = mstatus;
end end
endcase `CSR_MSCRATCH: begin
data_o = mscratch;
end
default: begin
data_o = `ZeroWord;
end
endcase
end
end end
end end
@ -172,32 +187,39 @@ module csr_reg(
if (rst == `RstEnable) begin if (rst == `RstEnable) begin
clint_data_o = `ZeroWord; clint_data_o = `ZeroWord;
end else begin end else begin
case (clint_raddr_i[11:0]) if ((clint_waddr_i[11:0] == clint_raddr_i[11:0]) && (clint_we_i == `WriteEnable)) begin
`CSR_CYCLE: begin clint_data_o = clint_data_i;
clint_data_o = cycle[31:0]; end else begin
end case (clint_raddr_i[11:0])
`CSR_CYCLEH: begin `CSR_CYCLE: begin
clint_data_o = cycle[63:32]; clint_data_o = cycle[31:0];
end end
`CSR_MTVEC: begin `CSR_CYCLEH: begin
clint_data_o = mtvec; clint_data_o = cycle[63:32];
end end
`CSR_MCAUSE: begin `CSR_MTVEC: begin
clint_data_o = mcause; clint_data_o = mtvec;
end end
`CSR_MEPC: begin `CSR_MCAUSE: begin
clint_data_o = mepc; clint_data_o = mcause;
end end
`CSR_MIE: begin `CSR_MEPC: begin
clint_data_o = mie; clint_data_o = mepc;
end end
`CSR_MSTATUS: begin `CSR_MIE: begin
clint_data_o = mstatus; clint_data_o = mie;
end end
default: begin `CSR_MSTATUS: begin
clint_data_o = `ZeroWord; clint_data_o = mstatus;
end end
endcase `CSR_MSCRATCH: begin
clint_data_o = mscratch;
end
default: begin
clint_data_o = `ZeroWord;
end
endcase
end
end end
end end

View File

@ -143,6 +143,7 @@
`define CSR_MEPC 12'h341 `define CSR_MEPC 12'h341
`define CSR_MIE 12'h304 `define CSR_MIE 12'h304
`define CSR_MSTATUS 12'h300 `define CSR_MSTATUS 12'h300
`define CSR_MSCRATCH 12'h340
`define RomNum 4096 // rom depth(how many words) `define RomNum 4096 // rom depth(how many words)