Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
feat: support NACL extension
Browse files Browse the repository at this point in the history
Signed-off-by: hwk2077 <[email protected]>
  • Loading branch information
Kalvin2077 committed Nov 29, 2023
1 parent e6feb02 commit 7f30d5f
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
### Added

- Support to PMU events in Chapter 11
- Support `NACL` extension in Chapter 15

### Modified

Expand Down
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub mod dbcn;
pub mod susp;
// §14
pub mod cppc;
// §15
pub mod nacl;

/// Converts SBI EID from str.
const fn eid_from_str(name: &str) -> i32 {
Expand Down Expand Up @@ -268,4 +270,20 @@ mod tests {
const_assert_eq!(2, READ_HI);
const_assert_eq!(3, WRITE);
}
// §15
#[test]
fn test_nacl() {
use crate::nacl::*;
const_assert_eq!(0x4E41434C, EID_NACL);
const_assert_eq!(0, PROBE_FEATURE);
const_assert_eq!(1, SET_SHMEM);
const_assert_eq!(2, SYNC_CSR);
const_assert_eq!(3, SYNC_HFENCE);
const_assert_eq!(4, SYNC_SRET);

const_assert_eq!(0, feature_id::SYNC_CSR);
const_assert_eq!(1, feature_id::SYNC_HFENCE);
const_assert_eq!(2, feature_id::SYNC_SRET);
const_assert_eq!(3, feature_id::AUTOSWAP_CSR);
}
}
51 changes: 51 additions & 0 deletions src/nacl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//! Chapter 15. Nested Acceleration Extension (EID #0x4E41434C "NACL")

/// Extension ID for Nested Acceleration Extension.
pub const EID_NACL: usize = crate::eid_from_str("NACL") as _;
pub use fid::*;

/// Declared in § 15.15.
mod fid {
/// Function ID to probe a nested acceleration feature.
///
/// Declared in §15.5.
pub const PROBE_FEATURE: usize = 0;
/// Function ID to set and enable the shared memory for nested acceleration on the calling hart.
///
/// Declared in §15.6.
pub const SET_SHMEM: usize = 1;
/// Function ID to synchronize CSRs in the nested acceleration shared memory.
///
/// Declared in §15.7.
pub const SYNC_CSR: usize = 2;
/// Function ID to synchronize HFENCEs in the nested acceleration shared memory.
///
/// Declared in §15.8.
pub const SYNC_HFENCE: usize = 3;
/// Function ID to synchronize CSRs and HFENCEs in the nested acceleration shared memory and emulate the SRET instruction.
///
/// Declared in §15.9.
pub const SYNC_SRET: usize = 4;
}

/// Nested Acceleration Feature ID.
///
/// Declared in §15.
pub mod feature_id {
/// Feature ID for the synchronize CSR feature.
///
/// Declared in §15.1.
pub const SYNC_CSR: usize = 0;
/// Feature ID for the synchronize HFENCE feature.
///
/// Declared in §15.2.
pub const SYNC_HFENCE: usize = 1;
/// Feature ID for the synchronize SRET feature.
///
/// Declared in §15.3.
pub const SYNC_SRET: usize = 2;
/// Feature ID for the autoswap CSR feature.
///
/// Declared in §15.4.
pub const AUTOSWAP_CSR: usize = 3;
}

0 comments on commit 7f30d5f

Please sign in to comment.