Skip to content

Commit 78c9298

Browse files
Merge pull request #368 from KushalMeghani1644/add-dpc
Implement DPC CSR for RISC-V
2 parents 617840c + f41190e commit 78c9298

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

riscv/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Added
1111

12+
- Add `dpc` CSR support for RISC-V
1213
- Add Mtopi
1314
- Added DCSR (Debug Control and Status Register) CSR support for the RISC-V
1415
- Add `miselect` CSR

riscv/src/register.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,4 @@ mod tests;
131131

132132
// TODO: Debug Mode Registers
133133
pub mod dcsr;
134+
pub mod dpc;

riscv/src/register/dpc.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//! dpc register — Debug PC (0x7b1)
2+
3+
read_write_csr! {
4+
/// Debug PC Register
5+
Dpc: 0x7b1,
6+
mask: !1usize,
7+
}
8+
9+
#[cfg(test)]
10+
mod tests {
11+
use super::*;
12+
13+
#[test]
14+
fn test_dpc_alignment_mask() {
15+
let dpc = Dpc::from_bits(0x1);
16+
assert_eq!(dpc.bits() & 1, 0);
17+
}
18+
19+
#[test]
20+
fn test_dpc_bits_roundtrip() {
21+
(0..=usize::BITS)
22+
.map(|r| ((1u128 << r) - 1) as usize)
23+
.for_each(|pc| {
24+
// ensure lowest bit is cleared
25+
let exp_pc = pc & !1usize;
26+
let dpc = Dpc::from_bits(pc);
27+
assert_eq!(dpc.bits(), exp_pc);
28+
assert_eq!(Dpc::from_bits(dpc.bits()).bits(), dpc.bits());
29+
});
30+
}
31+
}

0 commit comments

Comments
 (0)