diff --git a/nel_os_kernel/src/vmm/x86_64/amd/mod.rs b/nel_os_kernel/src/vmm/x86_64/amd/mod.rs index b088157..099e759 100644 --- a/nel_os_kernel/src/vmm/x86_64/amd/mod.rs +++ b/nel_os_kernel/src/vmm/x86_64/amd/mod.rs @@ -1 +1,2 @@ pub mod vcpu; +mod vmcb; diff --git a/nel_os_kernel/src/vmm/x86_64/amd/vcpu.rs b/nel_os_kernel/src/vmm/x86_64/amd/vcpu.rs index 2e0aa18..cfefaf0 100644 --- a/nel_os_kernel/src/vmm/x86_64/amd/vcpu.rs +++ b/nel_os_kernel/src/vmm/x86_64/amd/vcpu.rs @@ -3,18 +3,21 @@ use x86_64::structures::paging::{FrameAllocator, Size4KiB}; use crate::{ error, info, - vmm::{x86_64::common, VCpu}, + vmm::{ + x86_64::{amd::vmcb::Vmcb, common}, + VCpu, + }, }; -pub struct AMDVCpu; +pub struct AMDVCpu { + vmcb: Vmcb, +} impl VCpu for AMDVCpu { fn run( &mut self, _frame_allocator: &mut dyn FrameAllocator, ) -> Result<(), &'static str> { - info!("VCpu on AMD"); - Ok(()) } @@ -39,7 +42,7 @@ impl VCpu for AMDVCpu { unimplemented!("AMDVCpu::get_guest_memory_size is not implemented yet") } - fn new(_frame_allocator: &mut impl FrameAllocator) -> Result + fn new(frame_allocator: &mut impl FrameAllocator) -> Result where Self: Sized, { @@ -47,7 +50,9 @@ impl VCpu for AMDVCpu { efer |= 1 << 12; common::write_msr(0xc000_0080, efer); - Ok(AMDVCpu) + Ok(AMDVCpu { + vmcb: Vmcb::new(frame_allocator)?, + }) } fn is_supported() -> bool diff --git a/nel_os_kernel/src/vmm/x86_64/amd/vmcb.rs b/nel_os_kernel/src/vmm/x86_64/amd/vmcb.rs new file mode 100644 index 0000000..cf14a4d --- /dev/null +++ b/nel_os_kernel/src/vmm/x86_64/amd/vmcb.rs @@ -0,0 +1,14 @@ +use x86_64::structures::paging::{FrameAllocator, PhysFrame, Size4KiB}; + +pub struct Vmcb { + pub frame: PhysFrame, +} + +impl Vmcb { + pub fn new(frame_allocator: &mut impl FrameAllocator) -> Result { + let frame = frame_allocator + .allocate_frame() + .ok_or("Failed to allocate VMCB frame")?; + Ok(Vmcb { frame }) + } +}