This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
pub mod vcpu;
|
pub mod vcpu;
|
||||||
|
mod vmcb;
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
14
nel_os_kernel/src/vmm/x86_64/amd/vmcb.rs
Normal file
14
nel_os_kernel/src/vmm/x86_64/amd/vmcb.rs
Normal 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 })
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user