#![expect(unused)]
use core::arch::x86_64::__cpuid;
use spin::Lazy;
use x86_64::registers::model_specific::Msr;

const CPUID_FLAG_MSR: u32 = 1 << 5;
static EDX: Lazy<u32> = Lazy::new(|| unsafe { __cpuid(1).edx });

pub fn cpu_has_msr() -> bool {
    *EDX & CPUID_FLAG_MSR != 0
}

pub fn cpu_get_msr(msr: u32, value: &mut u64) {
    let msr = Msr::new(msr);
    unsafe {
        *value = msr.read();
    }
}

pub fn cpu_set_msr(msr: u32, value: u64) {
    let mut msr = Msr::new(msr);
    unsafe {
        msr.write(value);
    }
}
