-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated aliasing of mpp and mpie between mcause and mstatus. #738
Updated aliasing of mpp and mpie between mcause and mstatus. #738
Conversation
RVFI didn't always get the correct write values, and the aliasing was only working from mcause to mstatus and not the other way. The three bits are now duplicated in both mcause and mstatus, and are always written simultaneously. Assertions are added to check that mcause and mstatus always write at the same time, and that the *_rdata.mpp/mpie fields are always the same. SEC clean Signed-off-by: Oystein Knauserud <[email protected]>
rtl/cv32e40x_cs_registers.sv
Outdated
@@ -725,11 +735,14 @@ module cv32e40x_cs_registers import cv32e40x_pkg::*; | |||
mcause_n = '{ | |||
irq: csr_wdata_int[31], | |||
minhv: csr_wdata_int[30], | |||
mpp: mstatus_mpp_resolve(mstatus_rdata.mpp, csr_wdata_int[MCAUSE_MPP_BIT_HIGH:MCAUSE_MPP_BIT_LOW]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could create a separate mcause_mpp_resolve, or rename the existing one to just 'mpp_resolve'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, make a separate mcause_mpp_resolve
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and use mcause_rdata.mpp,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
rtl/cv32e40x_cs_registers.sv
Outdated
@@ -1459,7 +1521,7 @@ module cv32e40x_cs_registers import cv32e40x_pkg::*; | |||
// Signal when an interrupt may become enabled due to a CSR write | |||
generate | |||
if (SMCLIC) begin : smclic_irq_en | |||
assign csr_irq_enable_write_o = mstatus_we || priv_lvl_we || mintthresh_we || mintstatus_we; | |||
assign csr_irq_enable_write_o = (mstatus_we && !ctrl_fsm_i.csr_clear_minhv) || priv_lvl_we || mintthresh_we || mintstatus_we; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed to be SEC clean. Not needed functionally, as a clearing of minhv will only touch that bit and never update any interrupt enables. Could keep it as it was, or modify to not raise the signal on write to mstatus where we know that mie will not be written?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the non-SEC clean variant. The only negative effect could be an unneeded stall, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it would cause an extra stall, but I believe the scenario creating this isn't very common. I will remove the non-SEC code in my final push.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed check for clear_minhv, resulting PR is not SEC clean.
rtl/cv32e40x_cs_registers.sv
Outdated
@@ -725,11 +735,14 @@ module cv32e40x_cs_registers import cv32e40x_pkg::*; | |||
mcause_n = '{ | |||
irq: csr_wdata_int[31], | |||
minhv: csr_wdata_int[30], | |||
mpp: mstatus_mpp_resolve(mstatus_rdata.mpp, csr_wdata_int[MCAUSE_MPP_BIT_HIGH:MCAUSE_MPP_BIT_LOW]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, make a separate mcause_mpp_resolve
rtl/cv32e40x_cs_registers.sv
Outdated
@@ -725,11 +735,14 @@ module cv32e40x_cs_registers import cv32e40x_pkg::*; | |||
mcause_n = '{ | |||
irq: csr_wdata_int[31], | |||
minhv: csr_wdata_int[30], | |||
mpp: mstatus_mpp_resolve(mstatus_rdata.mpp, csr_wdata_int[MCAUSE_MPP_BIT_HIGH:MCAUSE_MPP_BIT_LOW]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and use mcause_rdata.mpp,
@@ -862,14 +882,14 @@ module cv32e40x_cs_registers import cv32e40x_pkg::*; | |||
|
|||
// Writes to mnxti also writes to mstatus | |||
mstatus_we = 1'b1; | |||
mcause_we = 1'b1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix above comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also fix comment on line 887 and explain whyit is now okay to write mcause unconditionally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
rtl/cv32e40x_cs_registers.sv
Outdated
@@ -1098,6 +1142,10 @@ module cv32e40x_cs_registers import cv32e40x_pkg::*; | |||
mstatus_n.mprv = (privlvl_t'(dcsr_rdata.prv) == PRIV_LVL_M) ? mstatus_rdata.mprv : 1'b0; | |||
mstatus_we = 1'b1; | |||
|
|||
// Not really needed, but allows for asserting mstatus_we == mcause_we to check aliasing formally |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section should only be done for SMCLIC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -1037,7 +1071,15 @@ module cv32e40x_cs_registers import cv32e40x_pkg::*; | |||
mepc_n = ctrl_fsm_i.pipe_pc; | |||
mepc_we = 1'b1; | |||
|
|||
mcause_n = ctrl_fsm_i.csr_cause; | |||
// Save relevant fields from controller to mcause |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only for SMCLIC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved relevant fields into "if (SMCLIC)"
rtl/cv32e40x_cs_registers.sv
Outdated
cv32e40x_csr | ||
#( | ||
.WIDTH (32), | ||
.RESETVALUE (32'd0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduce MCAUSE_BASIC_RESET_VAL and MCAUSE_CLIC_RESET_VAL (just like for MTVEC)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
rtl/cv32e40x_cs_registers.sv
Outdated
@@ -1459,7 +1521,7 @@ module cv32e40x_cs_registers import cv32e40x_pkg::*; | |||
// Signal when an interrupt may become enabled due to a CSR write | |||
generate | |||
if (SMCLIC) begin : smclic_irq_en | |||
assign csr_irq_enable_write_o = mstatus_we || priv_lvl_we || mintthresh_we || mintstatus_we; | |||
assign csr_irq_enable_write_o = (mstatus_we && !ctrl_fsm_i.csr_clear_minhv) || priv_lvl_we || mintthresh_we || mintstatus_we; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the non-SEC clean variant. The only negative effect could be an unneeded stall, right?
sva/cv32e40x_cs_registers_sva.sv
Outdated
); | ||
endproperty; | ||
a_mstatus_mcause_we: assert property(p_mstatus_mcause_we) | ||
else `uvm_error("cs_registers", "Mstatus.mpp and mstatus.mpie not written at the same time") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix error message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Signed-off-by: Oystein Knauserud <[email protected]>
RVFI didn't always get the correct write values, and the aliasing was only working from mcause to mstatus and not the other way.
The three bits are now duplicated in both mcause and mstatus, and are always written simultaneously. Assertions are added to check that mcause and mstatus always write at the same time, and that the *_rdata.mpp/mpie fields are always the same.
SEC clean
Signed-off-by: Oystein Knauserud [email protected]