-
Notifications
You must be signed in to change notification settings - Fork 705
[rtl] Add common security features of regfiles to separate module #2266
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
Open
aklsh
wants to merge
2
commits into
lowRISC:master
Choose a base branch
from
aklsh:refactor-regfile-impls
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,82 +48,38 @@ module ibex_register_file_fpga #( | |
| logic [DataWidth-1:0] mem[NUM_WORDS]; | ||
| logic we; // write enable if writing to any register other than R0 | ||
|
|
||
| logic [DataWidth-1:0] mem_o_a, mem_o_b; | ||
| // Encode we_a/raddr_a/raddr_b into one-hot encoded signals | ||
| logic [NUM_WORDS-1:0] raddr_onehot_a, raddr_onehot_b, we_onehot_a; | ||
|
|
||
| // WE strobe and one-hot encoded raddr alert. | ||
| logic oh_raddr_a_err, oh_raddr_b_err, oh_we_err; | ||
| assign err_o = oh_raddr_a_err || oh_raddr_b_err || oh_we_err; | ||
|
|
||
| if (RdataMuxCheck) begin : gen_rdata_mux_check | ||
| // Encode raddr_a/b into one-hot encoded signals. | ||
| logic [NUM_WORDS-1:0] raddr_onehot_a, raddr_onehot_b; | ||
| logic [NUM_WORDS-1:0] raddr_onehot_a_buf, raddr_onehot_b_buf; | ||
| prim_onehot_enc #( | ||
| .OneHotWidth(NUM_WORDS) | ||
| ) u_prim_onehot_enc_raddr_a ( | ||
| .in_i (raddr_a_i), | ||
| .en_i (1'b1), | ||
| .out_o (raddr_onehot_a) | ||
| ); | ||
|
|
||
| prim_onehot_enc #( | ||
| .OneHotWidth(NUM_WORDS) | ||
| ) u_prim_onehot_enc_raddr_b ( | ||
| .in_i (raddr_b_i), | ||
| .en_i (1'b1), | ||
| .out_o (raddr_onehot_b) | ||
| ); | ||
|
|
||
| // Buffer the one-hot encoded signals so that the checkers | ||
| // are not optimized. | ||
| prim_buf #( | ||
| .Width(NUM_WORDS) | ||
| ) u_prim_buf_raddr_a ( | ||
| .in_i (raddr_onehot_a), | ||
| .out_o(raddr_onehot_a_buf) | ||
| ); | ||
|
|
||
| prim_buf #( | ||
| .Width(NUM_WORDS) | ||
| ) u_prim_buf_raddr_b ( | ||
| .in_i (raddr_onehot_b), | ||
| .out_o(raddr_onehot_b_buf) | ||
| ); | ||
|
|
||
| // SEC_CM: DATA_REG_SW.GLITCH_DETECT | ||
| // Check the one-hot encoded signals for glitches. | ||
| prim_onehot_check #( | ||
| .AddrWidth(ADDR_WIDTH), | ||
| .OneHotWidth(NUM_WORDS), | ||
| .AddrCheck(1), | ||
| // When AddrCheck=1 also EnableCheck needs to be 1. | ||
| .EnableCheck(1) | ||
| ) u_prim_onehot_check_raddr_a ( | ||
| .clk_i, | ||
| .rst_ni, | ||
| .oh_i (raddr_onehot_a_buf), | ||
| .addr_i (raddr_a_i), | ||
| // Set enable=1 as address is always valid. | ||
| .en_i (1'b1), | ||
| .err_o (oh_raddr_a_err) | ||
| ); | ||
| logic [DataWidth-1:0] mem_o_a, mem_o_b; | ||
|
|
||
| prim_onehot_check #( | ||
| .AddrWidth(ADDR_WIDTH), | ||
| .OneHotWidth(NUM_WORDS), | ||
| .AddrCheck(1), | ||
| // When AddrCheck=1 also EnableCheck needs to be 1. | ||
| .EnableCheck(1) | ||
| ) u_prim_onehot_check_raddr_b ( | ||
| .clk_i, | ||
| .rst_ni, | ||
| .oh_i (raddr_onehot_b_buf), | ||
| .addr_i (raddr_b_i), | ||
| // Set enable=1 as address is always valid. | ||
| .en_i (1'b1), | ||
| .err_o (oh_raddr_b_err) | ||
| ); | ||
| // Common security functionality | ||
| ibex_register_file_common #( | ||
| .FPGA(1), | ||
| .AddrWidth(ADDR_WIDTH), | ||
| .NumWords(NUM_WORDS), | ||
| .WrenCheck(WrenCheck), | ||
| .RdataMuxCheck(RdataMuxCheck) | ||
| ) security_module ( | ||
| .clk_i, | ||
| .rst_ni, | ||
| .raddr_a_i, | ||
| .raddr_onehot_a, | ||
| .oh_raddr_a_err, | ||
| .raddr_b_i, | ||
| .raddr_onehot_b, | ||
| .oh_raddr_b_err, | ||
| .waddr_a_i, | ||
| .we_a_i, | ||
| .we_onehot_a, | ||
| .oh_we_err, | ||
| .err_o | ||
| ); | ||
|
|
||
| if (RdataMuxCheck) begin : gen_rdata_mux_check | ||
| // MUX register to rdata_a/b_o according to raddr_a/b_onehot. | ||
| prim_onehot_mux #( | ||
| .Width(DataWidth), | ||
|
|
@@ -153,21 +109,13 @@ module ibex_register_file_fpga #( | |
| assign rdata_a_o = (raddr_a_i == '0) ? WordZeroVal : mem[raddr_a_i]; | ||
| assign rdata_b_o = (raddr_b_i == '0) ? WordZeroVal : mem[raddr_b_i]; | ||
|
|
||
| assign oh_raddr_a_err = 1'b0; | ||
| assign oh_raddr_b_err = 1'b0; | ||
| logic unused_raddr_onehot, unused_oh_raddr_err; | ||
| assign unused_raddr_onehot = ^{raddr_onehot_a, raddr_onehot_b}; | ||
| assign unused_oh_raddr_err = ^{oh_raddr_a_err, oh_raddr_b_err}; | ||
| end | ||
|
|
||
| // we select | ||
| assign we = (waddr_a_i == '0) ? 1'b0 : we_a_i; | ||
|
|
||
| // SEC_CM: DATA_REG_SW.GLITCH_DETECT | ||
| // This checks for spurious WE strobes on the regfile. | ||
| if (WrenCheck) begin : gen_wren_check | ||
| // Since the FPGA uses a memory macro, there is only one write-enable strobe to check. | ||
| assign oh_we_err = we && !we_a_i; | ||
| end else begin : gen_no_wren_check | ||
| assign oh_we_err = 1'b0; | ||
| end | ||
| assign we = (waddr_a_i == '0) ? 1'b0 : we_onehot_a[0]; | ||
|
|
||
| // Note that the SystemVerilog LRM requires variables on the LHS of assignments within | ||
| // "always_ff" to not be written to by any other process. However, to enable the initialization | ||
|
|
@@ -198,4 +146,10 @@ module ibex_register_file_fpga #( | |
| logic unused_test_en; | ||
| assign unused_test_en = test_en_i; | ||
|
|
||
| if (WrenCheck) begin : gen_wren_check | ||
| end else begin : gen_no_wren_check | ||
| logic unused_oh_we_err; | ||
| assign unused_oh_we_err = oh_we_err; // this is never read from in this case | ||
| end | ||
|
Comment on lines
+149
to
+153
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe change this to |
||
|
|
||
| endmodule | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.