File tree Expand file tree Collapse file tree 3 files changed +58
-1
lines changed Expand file tree Collapse file tree 3 files changed +58
-1
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1313- Write utilities for ` mcycle ` , ` minstret `
1414- Add ` senvcfg ` CSR
1515- Add ` scontext ` CSR
16- - Add ` mtinst ` CSR
16+ - Add ` mconfigptr ` CSR
1717
1818### Changed
1919
Original file line number Diff line number Diff line change @@ -110,6 +110,9 @@ pub mod minstreth;
110110mod mhpmeventx;
111111pub use self :: mhpmeventx:: * ;
112112
113+ // Machine configuration
114+ pub mod mconfigptr;
115+
113116#[ cfg( test) ]
114117mod tests;
115118
Original file line number Diff line number Diff line change 1+ //! `mconfigptr` register.
2+
3+ use crate :: result:: { Error , Result } ;
4+
5+ const MASK : usize = usize:: MAX ;
6+
7+ read_only_csr ! {
8+ /// `mconfigptr` register.
9+ Mconfigptr : 0xf15 ,
10+ mask: MASK ,
11+ sentinel: 0 ,
12+ }
13+
14+ impl Mconfigptr {
15+ /// Represents the bitshift for a properly aligned configuration pointer.
16+ pub const ALIGN_SHIFT : usize = ( usize:: BITS / 8 ) . ilog2 ( ) as usize ;
17+ /// Represents the bitmask for a properly aligned configuration pointer.
18+ pub const ALIGN_MASK : usize = ( 1usize << Self :: ALIGN_SHIFT ) - 1 ;
19+
20+ /// Gets the pointer to the machine configuration structure.
21+ ///
22+ /// # Panics
23+ ///
24+ /// Panics if:
25+ ///
26+ /// - the value is `0`, indicating no configuration structure
27+ /// - the pointer is not aligned to an MXLEN byte value
28+ pub fn as_ptr ( & self ) -> * const u8 {
29+ self . try_as_ptr ( ) . unwrap ( )
30+ }
31+
32+ /// Attempts to get the pointer to the machine configuration structure.
33+ ///
34+ /// # Note
35+ ///
36+ /// Returns an error if:
37+ ///
38+ /// - the value is `0`, indicating no configuration structure
39+ /// - the pointer is not aligned to an MXLEN byte value
40+ pub const fn try_as_ptr ( & self ) -> Result < * const u8 > {
41+ match self . bits ( ) {
42+ 0 => Err ( Error :: InvalidFieldVariant {
43+ field : "mconfigptr" ,
44+ value : 0 ,
45+ } ) ,
46+ p if p & Self :: ALIGN_MASK != 0 => Err ( Error :: InvalidFieldValue {
47+ field : "mconfigptr" ,
48+ value : p,
49+ bitmask : !Self :: ALIGN_MASK ,
50+ } ) ,
51+ p => Ok ( p as * const _ ) ,
52+ }
53+ }
54+ }
You can’t perform that action at this time.
0 commit comments