dbs_arch/lib.rs
1// Copyright 2021-2022 Alibaba Cloud. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4#![deny(missing_docs)]
5
6//! CPU architecture specific constants, structures and utilities.
7//!
8//! This crate provides CPU architecture specific constants, structures and utilities to abstract
9//! away CPU architecture specific details from the Dragonball Secure Sandbox or other VMMs.
10//!
11//! # Supported CPU Architectures
12//! - **x86_64**: x86_64 (also known as x64, x86-64, AMD64, and Intel 64) is a 64-bit
13//! version of the x86 instruction set.
14//! - **ARM64**: AArch64 or ARM64 is the 64-bit extension of the ARM architecture.
15
16#[cfg(target_arch = "x86_64")]
17mod x86_64;
18#[cfg(target_arch = "x86_64")]
19pub use x86_64::*;
20
21#[cfg(target_arch = "aarch64")]
22mod aarch64;
23#[cfg(target_arch = "aarch64")]
24pub use aarch64::*;
25
26/// Enum indicating vpmu feature level
27#[derive(Debug, Eq, PartialEq, Copy, Clone)]
28pub enum VpmuFeatureLevel {
29 /// Disabled means vpmu feature is off (by default)
30 Disabled,
31 /// LimitedlyEnabled means minimal vpmu counters are supported( only cycles and instructions )
32 /// For aarch64, LimitedlyEnabled isn't supported currently. The ability will be implemented in the future.
33 LimitedlyEnabled,
34 /// FullyEnabled means all vpmu counters are supported
35 FullyEnabled,
36}
37
38#[cfg(test)]
39mod tests {
40 use super::*;
41
42 #[test]
43 fn test_debug_trait() {
44 let level = VpmuFeatureLevel::Disabled;
45 assert_eq!(format!("{level:#?}"), "Disabled");
46
47 let level = VpmuFeatureLevel::LimitedlyEnabled;
48 assert_eq!(format!("{level:#?}"), "LimitedlyEnabled");
49
50 let level = VpmuFeatureLevel::FullyEnabled;
51 assert_eq!(format!("{level:#?}"), "FullyEnabled");
52 }
53
54 #[test]
55 fn test_eq_trait() {
56 let level = VpmuFeatureLevel::Disabled;
57 assert!(level == VpmuFeatureLevel::Disabled);
58 assert!(level != VpmuFeatureLevel::LimitedlyEnabled);
59 }
60
61 #[test]
62 fn test_copy_trait() {
63 let level1 = VpmuFeatureLevel::Disabled;
64 let level2 = level1;
65 assert_eq!(level1, level2);
66 }
67}