Skip to content

Commit 7a73715

Browse files
committed
register: add scontext register
Adds the definition for the `scontext` Supervisor debug context CSR.
1 parent d7fd706 commit 7a73715

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

riscv/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212
- CSR helper macro `write_composite_csr` for writing 64-bit CSRs on 32-bit targets.
1313
- Write utilities for `mcycle`, `minstret`
1414
- Add `senvcfg` CSR
15+
- Add `scontext` CSR
1516

1617
### Changed
1718

riscv/src/register.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub mod stvec;
5757

5858
// Supervisor Trap Handling
5959
pub mod scause;
60+
pub mod scontext;
6061
pub mod senvcfg;
6162
pub mod sepc;
6263
pub mod sip;

riscv/src/register/scontext.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//! `scontext` register.
2+
3+
#[cfg(target_arch = "riscv32")]
4+
const MASK: usize = 0xffff;
5+
#[cfg(not(target_arch = "riscv32"))]
6+
const MASK: usize = 0xffff_ffff;
7+
8+
read_write_csr! {
9+
/// `scontext` register.
10+
Scontext: 0x5a8,
11+
mask: MASK,
12+
}
13+
14+
set!(0x5a8);
15+
clear!(0x5a8);
16+
17+
#[cfg(target_arch = "riscv32")]
18+
read_write_csr_field! {
19+
Scontext,
20+
/// Represents the `data` context number of the `scontext` CSR.
21+
data: [0:15],
22+
}
23+
24+
#[cfg(not(target_arch = "riscv32"))]
25+
read_write_csr_field! {
26+
Scontext,
27+
/// Represents the `data` context number of the `scontext` CSR.
28+
data: [0:31],
29+
}

0 commit comments

Comments
 (0)