This commit is contained in:
Masato Imai
2025-08-05 11:12:17 +00:00
parent 6365386c6f
commit 078e71279a
4 changed files with 35 additions and 4 deletions

View File

@ -15,7 +15,7 @@ pub trait VCpu {
fn is_supported() -> bool
where
Self: Sized;
fn run(&mut self);
fn run(&mut self) -> Result<(), &'static str>;
}
pub fn get_vcpu(

View File

@ -9,8 +9,10 @@ use crate::{
pub struct AMDVCpu;
impl VCpu for AMDVCpu {
fn run(&mut self) {
fn run(&mut self) -> Result<(), &'static str> {
info!("VCpu on AMD");
Ok(())
}
fn new(_frame_allocator: &mut impl FrameAllocator<Size4KiB>) -> Result<Self, &'static str>

View File

@ -0,0 +1,4 @@
pub fn setup_exec_controls() -> Result<(), &'static str> {
// TODO
Ok(())
}

View File

@ -1,3 +1,4 @@
mod controls;
mod vmcs;
mod vmxon;
@ -15,12 +16,30 @@ use crate::{
};
pub struct IntelVCpu {
activated: bool,
vmxon: vmxon::Vmxon,
vmcs: vmcs::Vmcs,
}
impl IntelVCpu {
fn activate(&mut self) -> Result<(), &'static str> {
self.vmcs.reset();
controls::setup_exec_controls()?;
Ok(())
}
}
impl VCpu for IntelVCpu {
fn run(&mut self) {
fn run(&mut self) -> Result<(), &'static str> {
info!("VCpu on Intel");
if !self.activated {
self.activate()?;
self.activated = true;
}
Ok(())
}
fn new(frame_allocator: &mut impl FrameAllocator<Size4KiB>) -> Result<Self, &'static str>
@ -43,7 +62,13 @@ impl VCpu for IntelVCpu {
vmxon.activate()?;
Ok(IntelVCpu { vmxon })
let vmcs = vmcs::Vmcs::new(frame_allocator)?;
Ok(IntelVCpu {
activated: false,
vmxon,
vmcs,
})
}
fn is_supported() -> bool