add VMCB
Some checks failed
Check / Build ISO (nightly-2025-04-27) (push) Failing after 1m29s

This commit is contained in:
mii443
2025-08-28 13:57:21 +09:00
parent 53a31749b4
commit 33c511dcb0
3 changed files with 26 additions and 6 deletions

View File

@@ -1 +1,2 @@
pub mod vcpu; pub mod vcpu;
mod vmcb;

View File

@@ -3,18 +3,21 @@ use x86_64::structures::paging::{FrameAllocator, Size4KiB};
use crate::{ use crate::{
error, info, 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 { impl VCpu for AMDVCpu {
fn run( fn run(
&mut self, &mut self,
_frame_allocator: &mut dyn FrameAllocator<Size4KiB>, _frame_allocator: &mut dyn FrameAllocator<Size4KiB>,
) -> Result<(), &'static str> { ) -> Result<(), &'static str> {
info!("VCpu on AMD");
Ok(()) Ok(())
} }
@@ -39,7 +42,7 @@ impl VCpu for AMDVCpu {
unimplemented!("AMDVCpu::get_guest_memory_size is not implemented yet") unimplemented!("AMDVCpu::get_guest_memory_size is not implemented yet")
} }
fn new(_frame_allocator: &mut impl FrameAllocator<Size4KiB>) -> Result<Self, &'static str> fn new(frame_allocator: &mut impl FrameAllocator<Size4KiB>) -> Result<Self, &'static str>
where where
Self: Sized, Self: Sized,
{ {
@@ -47,7 +50,9 @@ impl VCpu for AMDVCpu {
efer |= 1 << 12; efer |= 1 << 12;
common::write_msr(0xc000_0080, efer); common::write_msr(0xc000_0080, efer);
Ok(AMDVCpu) Ok(AMDVCpu {
vmcb: Vmcb::new(frame_allocator)?,
})
} }
fn is_supported() -> bool fn is_supported() -> bool

View File

@@ -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<Size4KiB>) -> Result<Self, &'static str> {
let frame = frame_allocator
.allocate_frame()
.ok_or("Failed to allocate VMCB frame")?;
Ok(Vmcb { frame })
}
}