This commit is contained in:
Masato Imai
2025-08-09 14:06:29 +00:00
parent e30749eb63
commit 6e34ecdc89
5 changed files with 21 additions and 3 deletions

View File

@ -159,7 +159,11 @@ pub extern "sysv64" fn main(boot_info: &nel_os_common::BootInfo) {
let mut vcpu = vmm::get_vcpu(&mut bitmap_table).unwrap(); let mut vcpu = vmm::get_vcpu(&mut bitmap_table).unwrap();
loop { loop {
info!("{:?}", vcpu.run(&mut bitmap_table)); let result = vcpu.run(&mut bitmap_table);
if let Err(e) = result {
error!("VCPU run failed: {}", e);
break;
}
} }
hlt_loop(); hlt_loop();

View File

@ -1,6 +1,6 @@
use modular_bitfield::{ use modular_bitfield::{
bitfield, bitfield,
prelude::{B3, B4, B52, B53}, prelude::{B1, B3, B4, B52, B53},
}; };
use x86_64::{ use x86_64::{
structures::paging::{FrameAllocator, PhysFrame, Size4KiB}, structures::paging::{FrameAllocator, PhysFrame, Size4KiB},
@ -325,7 +325,8 @@ pub struct EntryBase {
pub accessed: bool, pub accessed: bool,
pub dirty: bool, pub dirty: bool,
pub exec_user: bool, pub exec_user: bool,
pub phys: B53, reserved: B1,
pub phys: B52,
} }
impl EntryBase { impl EntryBase {

View File

@ -4,6 +4,7 @@ mod ept;
mod register; mod register;
pub mod vcpu; pub mod vcpu;
mod vmcs; mod vmcs;
mod vmexit;
mod vmxon; mod vmxon;
use core::arch::asm; use core::arch::asm;

View File

@ -76,6 +76,11 @@ impl IntelVCpu {
VmxExitReason::HLT => { VmxExitReason::HLT => {
info!("VM hlt"); info!("VM hlt");
} }
VmxExitReason::EPT_VIOLATION => {
let guest_address = vmread(vmcs::ro::GUEST_PHYSICAL_ADDR_FULL)?;
info!("EPT Violation at guest address: {:#x}", guest_address);
return Err("EPT Violation");
}
_ => { _ => {
info!("VM exit reason: {:?}", exit_reason); info!("VM exit reason: {:?}", exit_reason);
} }
@ -153,6 +158,13 @@ impl IntelVCpu {
let eptp = ept::EPTP::init(&self.ept.root_table); let eptp = ept::EPTP::init(&self.ept.root_table);
vmwrite(x86::vmx::vmcs::control::EPTP_FULL, u64::from(eptp))?; vmwrite(x86::vmx::vmcs::control::EPTP_FULL, u64::from(eptp))?;
info!(
"GPA 0x0 -> HPA {:#x}",
self.ept
.get_phys_addr(0)
.ok_or("Failed to get physical address")?
);
Ok(()) Ok(())
} }