Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions riscv/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

- Add `dpc` CSR support for RISC-V
- Add Mtopi
- Added DCSR (Debug Control and Status Register) CSR support for the RISC-V
- Add `miselect` CSR
Expand Down
1 change: 1 addition & 0 deletions riscv/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,4 @@ mod tests;

// TODO: Debug Mode Registers
pub mod dcsr;
pub mod dpc;
25 changes: 25 additions & 0 deletions riscv/src/register/dpc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! dpc register — Debug PC (0x7b1)

read_write_csr! {
/// Debug PC Register
Dpc: 0x7b1,
mask: !1usize,
Copy link
Contributor

Choose a reason for hiding this comment

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

What are you basing this alignment on?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Debug Spec defines dpc as holding the address of the next instruction, and according to the base ISA alignment rules (for the C extension), instruction addresses are always 2-byte aligned.
So, bit 0 of dpc is always 0, which is why the mask !1usize is applied. Hope this clears out what you were concerned about :)

}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_dpc_alignment_mask() {
let dpc = Dpc::from_bits(0x1);
assert_eq!(dpc.bits() & 1, 0);
}

#[test]
fn test_dpc_bits_roundtrip() {
let dpc = Dpc::from_bits(0x12345);
assert_eq!(dpc.bits(), 0x12344);
assert_eq!(Dpc::from_bits(dpc.bits()).bits(), dpc.bits());
}
}
Loading