-
Notifications
You must be signed in to change notification settings - Fork 200
riscv: add Sdtrig CSRs as raw usize accessors #413
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
JurajSadel
wants to merge
1
commit into
rust-embedded:master
Choose a base branch
from
JurajSadel:upstream/sdtrig-stubs
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 all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| //! tcontrol register — Trigger Control (0x7a5) | ||
| //! | ||
| //! Global control for machine-mode triggers (Sdtrig). | ||
|
|
||
| read_write_csr! { | ||
| /// Trigger Control Register | ||
| Tcontrol: 0x7a5, | ||
| mask: 0x88, | ||
| } | ||
|
|
||
| read_write_csr_field! { | ||
| Tcontrol, | ||
| /// M-mode trigger enable (bit 3). | ||
| /// | ||
| /// When a trap into M-mode is taken, `mte` is set to 0. `mret` restores it | ||
| /// from `mpte`. | ||
| mte: 3, | ||
| } | ||
|
|
||
| read_write_csr_field! { | ||
| Tcontrol, | ||
| /// M-mode previous trigger enable (bit 7). | ||
| mpte: 7, | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_tcontrol() { | ||
| let mut tcontrol = Tcontrol::from_bits(0); | ||
|
|
||
| test_csr_field!(tcontrol, mte); | ||
| test_csr_field!(tcontrol, mpte); | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| //! tdata1 register — Trigger Data 1 (0x7a1) | ||
| //! | ||
| //! First data register of the trigger selected by [`tselect`](crate::register::tselect). | ||
| //! Layout of the lower bits depends on the trigger type. | ||
|
|
||
| read_write_csr! { | ||
| /// Trigger Data 1 Register | ||
| Tdata1: 0x7a1, | ||
| mask: usize::MAX, | ||
| } | ||
|
|
||
| csr_field_enum! { | ||
| /// Trigger type encoded in `tdata1.type` (Sdtrig). | ||
| TriggerType { | ||
| default: None, | ||
| /// No trigger at this `tselect`. | ||
| None = 0, | ||
| /// Legacy SiFive address match trigger. | ||
| Legacy = 1, | ||
| /// Address/data match trigger (`mcontrol`). | ||
| Mcontrol = 2, | ||
| /// Instruction count trigger (`icount`). | ||
| Icount = 3, | ||
| /// Interrupt trigger (`itrigger`). | ||
| Itrigger = 4, | ||
| /// Exception trigger (`etrigger`). | ||
| Etrigger = 5, | ||
| /// Address/data match trigger (`mcontrol6`). | ||
| Mcontrol6 = 6, | ||
| /// Trigger source external to the trigger module (`tmexttrigger`). | ||
| Tmexttrigger = 7, | ||
| /// Custom trigger type 12. | ||
| Custom12 = 12, | ||
| /// Custom trigger type 13. | ||
| Custom13 = 13, | ||
| /// Custom trigger type 14. | ||
| Custom14 = 14, | ||
| /// Trigger disabled. | ||
| Disabled = 15, | ||
| } | ||
| } | ||
|
|
||
| #[cfg(target_arch = "riscv32")] | ||
| read_write_csr_field! { | ||
| Tdata1, | ||
| /// Trigger type (spec field `type`, bits XLEN-1:XLEN-4). | ||
| trigger_type, | ||
| TriggerType: [28:31], | ||
| } | ||
|
|
||
| #[cfg(not(target_arch = "riscv32"))] | ||
| read_write_csr_field! { | ||
| Tdata1, | ||
| /// Trigger type (spec field `type`, bits XLEN-1:XLEN-4). | ||
| trigger_type, | ||
| TriggerType: [60:63], | ||
| } | ||
|
|
||
| #[cfg(target_arch = "riscv32")] | ||
| read_write_csr_field! { | ||
| Tdata1, | ||
| /// Debug-mode-only write enable (bit XLEN-5). | ||
| dmode: 27, | ||
| } | ||
|
|
||
| #[cfg(not(target_arch = "riscv32"))] | ||
| read_write_csr_field! { | ||
| Tdata1, | ||
| /// Debug-mode-only write enable (bit XLEN-5). | ||
| dmode: 59, | ||
| } | ||
|
|
||
| #[cfg(target_arch = "riscv32")] | ||
| read_write_csr_field! { | ||
| Tdata1, | ||
| /// Trigger-specific data (bits XLEN-6:0). | ||
| data: [0:26], | ||
| } | ||
|
|
||
| #[cfg(not(target_arch = "riscv32"))] | ||
| read_write_csr_field! { | ||
| Tdata1, | ||
| /// Trigger-specific data (bits XLEN-6:0). | ||
| data: [0:58], | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use crate::result::Error; | ||
|
|
||
| #[test] | ||
| fn test_tdata1() { | ||
| let mut tdata1 = Tdata1::from_bits(0); | ||
|
|
||
| test_csr_field!(tdata1, dmode); | ||
| test_csr_field!( | ||
| tdata1, | ||
| data: [Tdata1::DATA_SHIFT, Tdata1::DATA_SHIFT + Tdata1::DATA_WIDTH - 1], | ||
| 0 | ||
| ); | ||
|
|
||
| [ | ||
| TriggerType::None, | ||
| TriggerType::Legacy, | ||
| TriggerType::Mcontrol, | ||
| TriggerType::Icount, | ||
| TriggerType::Itrigger, | ||
| TriggerType::Etrigger, | ||
| TriggerType::Mcontrol6, | ||
| TriggerType::Tmexttrigger, | ||
| TriggerType::Custom12, | ||
| TriggerType::Custom13, | ||
| TriggerType::Custom14, | ||
| TriggerType::Disabled, | ||
| ] | ||
| .into_iter() | ||
| .for_each(|variant| { | ||
| test_csr_field!(tdata1, trigger_type: variant); | ||
| }); | ||
|
|
||
| tdata1 = Tdata1::from_bits(8 << Tdata1::TRIGGER_TYPE_SHIFT); | ||
| assert_eq!(tdata1.try_trigger_type(), Err(Error::InvalidVariant(8))); | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| //! tdata2 register — Trigger Data 2 (0x7a2) | ||
| //! | ||
| //! Second data register of the trigger selected by [`tselect`](crate::register::tselect). For address/data | ||
| //! match triggers this typically holds the compare value. | ||
|
|
||
| read_write_csr_as_usize!(0x7a2); | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use crate::result::Error; | ||
|
|
||
| #[test] | ||
| fn test_tdata2_read_write() { | ||
| for i in 0..usize::BITS { | ||
| let val = 1usize << i; | ||
| assert_eq!(unsafe { try_write(val) }, Err(Error::Unimplemented)); | ||
| assert_eq!(try_read(), Err(Error::Unimplemented)); | ||
| } | ||
| } | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //! tdata3 register — Trigger Data 3 (0x7a3) | ||
| //! | ||
| //! Third data register of the trigger selected by [`tselect`](crate::register::tselect). | ||
| //! Holds trigger-specific data. When [`tdata1`](crate::register::tdata1) `type` is 2, 3, 4, 5, or 6, | ||
| //! this register is interpreted as `textra32` (RV32) or `textra64` (RV64). | ||
|
|
||
| read_write_csr_as_usize!(0x7a3); | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use crate::result::Error; | ||
|
|
||
| #[test] | ||
| fn test_tdata3_read_write() { | ||
| for i in 0..usize::BITS { | ||
| let val = 1usize << i; | ||
| assert_eq!(unsafe { try_write(val) }, Err(Error::Unimplemented)); | ||
| assert_eq!(try_read(), Err(Error::Unimplemented)); | ||
| } | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //! tselect register — Trigger Select (0x7a0) | ||
| //! | ||
| //! Selects which trigger the `tdata1`, `tdata2` and `tdata3` registers access. | ||
| //! The register is WARL, so writing an unsupported index and reading the value | ||
| //! back is the way to discover how many triggers the hart implements. | ||
|
|
||
| read_write_csr_as_usize!(0x7a0); | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use crate::result::Error; | ||
|
|
||
| #[test] | ||
| fn test_tselect_read_write() { | ||
| for i in 0..usize::BITS { | ||
| let val = 1usize << i; | ||
| assert_eq!(unsafe { try_write(val) }, Err(Error::Unimplemented)); | ||
| assert_eq!(try_read(), Err(Error::Unimplemented)); | ||
| } | ||
| } | ||
| } |
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.
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.
Can you add tdata3 as well?
https://github.com/riscv/riscv-debug-spec/releases/download/1.0/riscv-debug-specification.pdf
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.
Added and hopefully addressed your other comments