This commit is contained in:
Masato Imai
2025-08-04 07:58:59 +00:00
parent 4a1cecdb40
commit 646d7d581d
2 changed files with 29 additions and 1 deletions

View File

@@ -8,6 +8,7 @@ EFI_BINARY="$1"
qemu-system-x86_64 -enable-kvm \
-m 4G \
-serial mon:stdio \
-nographic \
-no-reboot \
-drive if=pflash,format=raw,readonly=on,file=OVMF_CODE.fd \
-drive if=pflash,format=raw,readonly=on,file=OVMF_VARS.fd \

View File

@@ -1,9 +1,26 @@
use crate::{info, vmm::VCpu};
use raw_cpuid::cpuid;
use crate::{
info,
vmm::{x86_64::common, VCpu},
};
pub struct IntelVCpu;
impl IntelVCpu {
pub fn new() -> Self {
let mut msr = common::read_msr(0x3a);
if msr & (1 << 2) == 0 {
msr |= 1 << 2;
msr |= 1;
common::write_msr(0x3a, msr);
}
let msr = common::read_msr(0x3a);
if msr & (1 << 2) == 0 {
panic!("VMX is not enabled in the BIOS");
}
IntelVCpu
}
}
@@ -17,6 +34,16 @@ impl VCpu for IntelVCpu {
where
Self: Sized,
{
if cpuid!(0x1).ecx & (1 << 5) == 0 {
info!("Intel CPU does not support VMX");
return false;
}
let msr = common::read_msr(0x3a);
if msr & (1 << 2) == 0 && msr & 1 != 0 {
info!("VMX is not enabled in the BIOS");
return false;
}
true
}
}