add InstructionError

This commit is contained in:
Masato Imai
2025-04-21 08:41:44 +00:00
parent 96f5c9e7d7
commit a3e8288013
2 changed files with 56 additions and 4 deletions

View File

@@ -8,7 +8,6 @@
extern crate alloc;
use bootloader::{entry_point, BootInfo};
use core::arch::asm;
use core::panic::PanicInfo;
use nel_os::{
allocator, info,
@@ -17,8 +16,10 @@ use nel_os::{
vmm::{
support::{has_intel_cpu, has_vmx_support},
vcpu::VCpu,
vmcs::InstructionError,
},
};
use x86::bits64::vmx;
use x86_64::VirtAddr;
#[cfg(not(test))]
@@ -60,10 +61,16 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! {
info!("vmlaunch...");
unsafe {
asm!("vmlaunch");
}
let vmlaunch = vmx::vmlaunch();
info!("vmlaunch succeeded");
if vmlaunch.is_err() {
let error = InstructionError::read();
let error = error.as_str();
info!("error: {}", error);
} else {
info!("vmlaunch success");
}
}
#[cfg(test)]
test_main();

View File

@@ -29,3 +29,48 @@ impl Vmcs {
}
}
}
pub struct InstructionError(pub u32);
impl InstructionError {
pub fn as_str(&self) -> &str {
match self.0 {
0 => "error_not_available",
1 => "vmcall_in_vmxroot",
2 => "vmclear_invalid_phys",
3 => "vmclear_vmxonptr",
4 => "vmlaunch_nonclear_vmcs",
5 => "vmresume_nonlaunched_vmcs",
6 => "vmresume_after_vmxoff",
7 => "vmentry_invalid_ctrl",
8 => "vmentry_invalid_host_state",
9 => "vmptrld_invalid_phys",
10 => "vmptrld_vmxonp",
11 => "vmptrld_incorrect_rev",
12 => "vmrw_unsupported_component",
13 => "vmw_ro_component",
15 => "vmxon_in_vmxroot",
16 => "vmentry_invalid_exec_ctrl",
17 => "vmentry_nonlaunched_exec_ctrl",
18 => "vmentry_exec_vmcsptr",
19 => "vmcall_nonclear_vmcs",
20 => "vmcall_invalid_exitctl",
22 => "vmcall_incorrect_msgrev",
23 => "vmxoff_dualmonitor",
24 => "vmcall_invalid_smm",
25 => "vmentry_invalid_execctrl",
26 => "vmentry_events_blocked",
28 => "invalid_invept",
_ => "unknown",
}
}
pub fn read() -> Self {
let err = unsafe { vmx::vmread(0x4400) };
if err.is_err() {
panic!("Failed to read VM instruction error");
}
let err = err.unwrap();
InstructionError(err as u32)
}
}