Skip to content
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

Merged

Conversation

silabs-oysteink
Copy link
Contributor

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]

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]>
@silabs-oysteink silabs-oysteink marked this pull request as draft December 20, 2022 05:43
@@ -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]),
Copy link
Contributor Author

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'.

Copy link
Contributor

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

Copy link
Contributor

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,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -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;
Copy link
Contributor Author

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@@ -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]),
Copy link
Contributor

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

@@ -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]),
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix above comment

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -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
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only for SMCLIC

Copy link
Contributor Author

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)"

cv32e40x_csr
#(
.WIDTH (32),
.RESETVALUE (32'd0)
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -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;
Copy link
Contributor

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?

);
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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix error message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@Silabs-ArjanB Silabs-ArjanB added the Component:RTL For issues in the RTL (e.g. for files in the rtl directory) label Dec 20, 2022
Signed-off-by: Oystein Knauserud <[email protected]>
@silabs-oysteink silabs-oysteink marked this pull request as ready for review December 20, 2022 09:27
@Silabs-ArjanB Silabs-ArjanB merged commit 1af01ad into openhwgroup:master Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component:RTL For issues in the RTL (e.g. for files in the rtl directory)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants