ax-cpu 0.10.0

Privileged instruction and structure abstractions for various CPU architectures
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//! LoongArch CPU configuration discovery.

/// Reports the CPUCFG2 LVZ extension bit of the current CPU.
pub fn has_hypervisor_extension() -> bool {
    let config = read_cpucfg(2);
    config & (1 << 10) != 0
}

/// Reads an architectural CPUCFG word without applying operating-system policy.
pub fn read_cpucfg(index: usize) -> usize {
    let value;
    // SAFETY: CPUCFG reads immutable hardware identity and capability information.
    unsafe {
        core::arch::asm!("cpucfg {}, {}", out(reg) value, in(reg) index, options(nomem, nostack));
    }
    value
}