File tree Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
12
12
- CSR helper macro ` write_composite_csr ` for writing 64-bit CSRs on 32-bit targets.
13
13
- Write utilities for ` mcycle ` , ` minstret `
14
14
- Add ` senvcfg ` CSR
15
+ - Add ` scontext ` CSR
15
16
16
17
### Changed
17
18
Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ pub mod stvec;
57
57
58
58
// Supervisor Trap Handling
59
59
pub mod scause;
60
+ pub mod scontext;
60
61
pub mod senvcfg;
61
62
pub mod sepc;
62
63
pub mod sip;
Original file line number Diff line number Diff line change
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
+ }
30
+
31
+ #[ cfg( test) ]
32
+ mod tests {
33
+ use super :: * ;
34
+
35
+ #[ test]
36
+ fn test_scontext ( ) {
37
+ #[ cfg( target_arch = "riscv32" ) ]
38
+ const DATA_BITS : usize = 16 ;
39
+ #[ cfg( not( target_arch = "riscv32" ) ) ]
40
+ const DATA_BITS : usize = 32 ;
41
+
42
+ let mut scontext = Scontext :: from_bits ( 0 ) ;
43
+
44
+ ( 1 ..=DATA_BITS )
45
+ . map ( |b| ( ( 1u64 << b) - 1 ) as usize )
46
+ . for_each ( |data| {
47
+ scontext. set_data ( data) ;
48
+ assert_eq ! ( scontext. data( ) , data) ;
49
+ assert_eq ! ( scontext. bits( ) , data) ;
50
+ } ) ;
51
+ }
52
+ }
You can’t perform that action at this time.
0 commit comments