use super::deref_aligned;
use crate::item::enarxcall::Number;
use crate::{item, Result};
use core::arch::asm;
use core::arch::x86_64::CpuidResult;
pub(super) unsafe fn execute(call: &mut item::Enarxcall, data: &mut [u8]) -> Result<()> {
#[allow(clippy::single_match)]
match call {
item::Enarxcall {
num: Number::Cpuid,
argv: [leaf, sub_leaf, result_offset, ..],
ret,
} => {
let result = deref_aligned::<CpuidResult>(data, *result_offset, 1)?;
#[cfg(target_arch = "x86_64")]
asm!(
"movq %rbx, {0:r}",
"cpuid",
"xchgq %rbx, {0:r}",
lateout(reg) (*result).ebx,
inlateout("eax") *leaf as u32 => (*result).eax,
inlateout("ecx") *sub_leaf as u32 => (*result).ecx,
lateout("edx") (*result).edx,
options(nostack, preserves_flags, att_syntax),
);
*ret = 0; }
_ => {}
}
Ok(())
}