-
Notifications
You must be signed in to change notification settings - Fork 746
Add mcounteren register
#2403
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
base: master
Are you sure you want to change the base?
Add mcounteren register
#2403
Changes from 4 commits
6355f79
72eaebf
216c77c
bacacea
497d1ec
ed45547
791beb6
6c1539e
c27c013
e0d9935
37ddcd4
49bffac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,6 +103,7 @@ module top import ibex_pkg::*; #( | |
|
|
||
| // CPU Control Signals | ||
| input ibex_mubi_t fetch_enable_i, | ||
| input ibex_mubi_t mcounteren_writable_i, | ||
|
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. What's the point of making this an input as opposed to a parameter? Is there a use-case to be able to switch this dynamically during runtime?
Contributor
Author
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. Yes. This allows locking the |
||
| output logic core_sleep_o, | ||
| output logic alert_minor_o, | ||
| output logic alert_major_internal_o, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,6 +98,7 @@ module ibex_cs_registers import ibex_pkg::*; #( | |
| output logic icache_enable_o, | ||
| output logic csr_shadow_err_o, | ||
| input logic ic_scr_key_valid_i, | ||
| input ibex_mubi_t mcounteren_writable_i, | ||
|
|
||
| // Exception save/restore | ||
| input logic csr_save_if_i, | ||
|
|
@@ -258,6 +259,11 @@ module ibex_cs_registers import ibex_pkg::*; #( | |
| logic [MHPMCounterNum+3-1:0] mcountinhibit_d, mcountinhibit_q; | ||
| logic mcountinhibit_we; | ||
|
|
||
| // mcounteren: machine counter enable (controls U-mode counter access) | ||
| logic [31:0] mcounteren; | ||
| logic [MHPMCounterNum+3-1:0] mcounteren_d, mcounteren_q; | ||
|
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. It probably makes sense to have at least a local parameter with the 3 offset since this is shared with the mcountinhibit above. |
||
| logic mcounteren_we; | ||
|
|
||
| // mhpmcounter flops are elaborated below providing only the precise number that is required based | ||
| // on MHPMCounterNum/MHPMCounterWidth. This signal connects to the Q output of these flops | ||
| // where they exist and is otherwise 0. | ||
|
|
@@ -374,9 +380,7 @@ module ibex_cs_registers import ibex_pkg::*; #( | |
| end | ||
|
|
||
| // mcounteren: machine counter enable | ||
| CSR_MCOUNTEREN: begin | ||
| csr_rdata_int = '0; | ||
| end | ||
| CSR_MCOUNTEREN: csr_rdata_int = mcounteren; | ||
|
|
||
| CSR_MSCRATCH: csr_rdata_int = mscratch_q; | ||
|
|
||
|
|
@@ -504,6 +508,35 @@ module ibex_cs_registers import ibex_pkg::*; #( | |
| csr_rdata_int = mhpmcounter[mhpmcounter_idx][63:32]; | ||
| end | ||
|
|
||
| // Unprivileged Counter/Timers (readable from U-mode subject to mcounteren) | ||
| CSR_CYCLE, | ||
| CSR_INSTRET, | ||
| CSR_HPMCOUNTER3, | ||
| CSR_HPMCOUNTER4, CSR_HPMCOUNTER5, CSR_HPMCOUNTER6, CSR_HPMCOUNTER7, | ||
| CSR_HPMCOUNTER8, CSR_HPMCOUNTER9, CSR_HPMCOUNTER10, CSR_HPMCOUNTER11, | ||
| CSR_HPMCOUNTER12, CSR_HPMCOUNTER13, CSR_HPMCOUNTER14, CSR_HPMCOUNTER15, | ||
| CSR_HPMCOUNTER16, CSR_HPMCOUNTER17, CSR_HPMCOUNTER18, CSR_HPMCOUNTER19, | ||
| CSR_HPMCOUNTER20, CSR_HPMCOUNTER21, CSR_HPMCOUNTER22, CSR_HPMCOUNTER23, | ||
| CSR_HPMCOUNTER24, CSR_HPMCOUNTER25, CSR_HPMCOUNTER26, CSR_HPMCOUNTER27, | ||
| CSR_HPMCOUNTER28, CSR_HPMCOUNTER29, CSR_HPMCOUNTER30, CSR_HPMCOUNTER31: begin | ||
| csr_rdata_int = mhpmcounter[mhpmcounter_idx][31:0]; | ||
|
gautschimi marked this conversation as resolved.
|
||
| illegal_csr = (priv_lvl_q == PRIV_LVL_U) && !mcounteren[mhpmcounter_idx]; | ||
| end | ||
|
|
||
| CSR_CYCLEH, | ||
| CSR_INSTRETH, | ||
| CSR_HPMCOUNTER3H, | ||
| CSR_HPMCOUNTER4H, CSR_HPMCOUNTER5H, CSR_HPMCOUNTER6H, CSR_HPMCOUNTER7H, | ||
| CSR_HPMCOUNTER8H, CSR_HPMCOUNTER9H, CSR_HPMCOUNTER10H, CSR_HPMCOUNTER11H, | ||
| CSR_HPMCOUNTER12H, CSR_HPMCOUNTER13H, CSR_HPMCOUNTER14H, CSR_HPMCOUNTER15H, | ||
| CSR_HPMCOUNTER16H, CSR_HPMCOUNTER17H, CSR_HPMCOUNTER18H, CSR_HPMCOUNTER19H, | ||
| CSR_HPMCOUNTER20H, CSR_HPMCOUNTER21H, CSR_HPMCOUNTER22H, CSR_HPMCOUNTER23H, | ||
| CSR_HPMCOUNTER24H, CSR_HPMCOUNTER25H, CSR_HPMCOUNTER26H, CSR_HPMCOUNTER27H, | ||
| CSR_HPMCOUNTER28H, CSR_HPMCOUNTER29H, CSR_HPMCOUNTER30H, CSR_HPMCOUNTER31H: begin | ||
| csr_rdata_int = mhpmcounter[mhpmcounter_idx][63:32]; | ||
| illegal_csr = (priv_lvl_q == PRIV_LVL_U) && !mcounteren[mhpmcounter_idx]; | ||
| end | ||
|
|
||
| // Debug triggers | ||
| CSR_TSELECT: begin | ||
| csr_rdata_int = tselect_rdata; | ||
|
|
@@ -598,6 +631,7 @@ module ibex_cs_registers import ibex_pkg::*; #( | |
| mstack_cause_d = mcause_q; | ||
|
|
||
| mcountinhibit_we = 1'b0; | ||
| mcounteren_we = 1'b0; | ||
| mhpmcounter_we = '0; | ||
| mhpmcounterh_we = '0; | ||
|
|
||
|
|
@@ -675,6 +709,7 @@ module ibex_cs_registers import ibex_pkg::*; #( | |
| CSR_DSCRATCH1: dscratch1_en = 1'b1; | ||
|
|
||
| // machine counter/timers | ||
| CSR_MCOUNTEREN: mcounteren_we = mcounteren_writable_i == IbexMuBiOn; | ||
| CSR_MCOUNTINHIBIT: mcountinhibit_we = 1'b1; | ||
|
|
||
| CSR_MCYCLE, | ||
|
|
@@ -1277,6 +1312,15 @@ module ibex_cs_registers import ibex_pkg::*; #( | |
| end | ||
| end | ||
|
|
||
| always_comb begin : mcounteren_update | ||
| if (mcounteren_we == 1'b1) begin | ||
| // bit 1 must always be 0 (no time CSR implemented) | ||
| mcounteren_d = {csr_wdata_int[MHPMCounterNum+2:2], 1'b0, csr_wdata_int[0]}; | ||
| end else begin | ||
| mcounteren_d = mcounteren_q; | ||
| end | ||
| end | ||
|
|
||
| // event selection (hardwired) & control | ||
| always_comb begin : gen_mhpmcounter_incr | ||
|
|
||
|
|
@@ -1434,6 +1478,25 @@ module ibex_cs_registers import ibex_pkg::*; #( | |
| end | ||
| end | ||
|
|
||
| if (MHPMCounterNum < 29) begin : g_mcounteren_reduced | ||
| assign mcounteren = {{29 - MHPMCounterNum{1'b0}}, mcounteren_q}; | ||
| end else begin : g_mcounteren_full | ||
| assign mcounteren = mcounteren_q; | ||
| end | ||
|
|
||
| ibex_csr #( | ||
| .Width (MHPMCounterNum+3), | ||
| .ShadowCopy(1'b0), | ||
| .ResetValue('0) | ||
| ) u_mcounteren_csr ( | ||
| .clk_i (clk_i), | ||
| .rst_ni (rst_ni), | ||
| .wr_data_i (mcounteren_d), | ||
| .wr_en_i (mcounteren_we), | ||
| .rd_data_o (mcounteren_q), | ||
| .rd_error_o() | ||
| ); | ||
|
|
||
| ///////////////////////////// | ||
| // Debug trigger registers // | ||
| ///////////////////////////// | ||
|
|
||
|
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. I double checked this mapping and I think they are 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.
This bump adds ZIHPM extension to Spike but it also pulls in the Zc* extensions. Is there any risk in that inclusion?
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.
You're right. But that will be fine, because we anyway already have the Zc* extension in the RTL. Only the DV is not fully merged yet, but already having Spike support those extensions will not hurt.