Skip to content

Commit 5852eed

Browse files
Implement dscratch0 and dscratch1 CSRs for RISC-V
1 parent 8eed873 commit 5852eed

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

riscv/src/register.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,9 @@ mod tests;
131131

132132
// TODO: Debug Mode Registers
133133
pub mod dcsr;
134+
<<<<<<< HEAD
134135
pub mod dpc;
136+
=======
137+
pub mod dscratch0;
138+
pub mod dscratch1;
139+
>>>>>>> d078ccf (Implement dscratch0 and dscratch1 CSRs for RISC-V)

riscv/src/register/dscratch0.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//! dscratch0
2+
3+
read_write_csr! {
4+
/// Debug scratch register 0
5+
Dscratch0: 0x7b2,
6+
mask: usize::MAX,
7+
}
8+
9+
#[cfg(test)]
10+
mod tests {
11+
use super::*;
12+
13+
#[test]
14+
fn test_dscratch0_mask() {
15+
let reg = Dscratch0::from_bits(usize::MAX);
16+
assert_eq!(reg.bits(), usize::MAX);
17+
assert_eq!(Dscratch0::BITMASK, usize::MAX);
18+
}
19+
20+
#[test]
21+
fn test_dscratch0_roundtrip() {
22+
let reg = Dscratch0::from_bits(0xDEAD_BEEFusize);
23+
assert_eq!(reg.bits(), 0xDEAD_BEEFusize);
24+
}
25+
}

riscv/src/register/dscratch1.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//! dscratch1
2+
3+
read_write_csr! {
4+
/// Debug scratch register 1
5+
Dscratch1: 0x7b3,
6+
mask: usize::MAX,
7+
}
8+
9+
#[cfg(test)]
10+
mod tests {
11+
use super::*;
12+
13+
#[test]
14+
fn test_dscratch1_mask() {
15+
let reg = Dscratch1::from_bits(usize::MAX);
16+
assert_eq!(reg.bits(), usize::MAX);
17+
assert_eq!(Dscratch1::BITMASK, usize::MAX);
18+
}
19+
20+
#[test]
21+
fn test_dscratch1_roundtrip() {
22+
let reg = Dscratch1::from_bits(0xDEAD_BEEFusize);
23+
assert_eq!(reg.bits(), 0xDEAD_BEEFusize);
24+
}
25+
}

0 commit comments

Comments
 (0)