error
This commit is contained in:
@@ -157,7 +157,7 @@ pub extern "sysv64" fn main(boot_info: &nel_os_common::BootInfo) {
|
|||||||
|
|
||||||
info!("Interrupts enabled");
|
info!("Interrupts enabled");
|
||||||
|
|
||||||
let mut vcpu = vmm::get_vcpu();
|
let mut vcpu = vmm::get_vcpu().unwrap();
|
||||||
vcpu.run();
|
vcpu.run();
|
||||||
|
|
||||||
hlt_loop();
|
hlt_loop();
|
||||||
|
|||||||
@@ -8,18 +8,21 @@ use crate::{
|
|||||||
pub mod x86_64;
|
pub mod x86_64;
|
||||||
|
|
||||||
pub trait VCpu {
|
pub trait VCpu {
|
||||||
|
fn new() -> Result<Self, &'static str>
|
||||||
|
where
|
||||||
|
Self: Sized;
|
||||||
fn is_supported() -> bool
|
fn is_supported() -> bool
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
fn run(&mut self);
|
fn run(&mut self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_vcpu() -> Box<dyn VCpu> {
|
pub fn get_vcpu() -> Result<Box<dyn VCpu>, &'static str> {
|
||||||
if platform::is_amd() && AMDVCpu::is_supported() {
|
if platform::is_amd() && AMDVCpu::is_supported() {
|
||||||
Box::new(AMDVCpu::new())
|
Ok(Box::new(AMDVCpu::new()?))
|
||||||
} else if platform::is_intel() && IntelVCpu::is_supported() {
|
} else if platform::is_intel() && IntelVCpu::is_supported() {
|
||||||
Box::new(IntelVCpu::new())
|
Ok(Box::new(IntelVCpu::new()?))
|
||||||
} else {
|
} else {
|
||||||
panic!("Unsupported CPU architecture");
|
Err("Unsupported CPU architecture")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,19 +7,20 @@ use crate::{
|
|||||||
|
|
||||||
pub struct AMDVCpu;
|
pub struct AMDVCpu;
|
||||||
|
|
||||||
impl AMDVCpu {
|
impl VCpu for AMDVCpu {
|
||||||
pub fn new() -> Self {
|
fn run(&mut self) {
|
||||||
|
info!("VCpu on AMD");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new() -> Result<Self, &'static str>
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
let mut efer = common::read_msr(0xc000_0080);
|
let mut efer = common::read_msr(0xc000_0080);
|
||||||
efer |= 1 << 12;
|
efer |= 1 << 12;
|
||||||
common::write_msr(0xc000_0080, efer);
|
common::write_msr(0xc000_0080, efer);
|
||||||
|
|
||||||
AMDVCpu
|
Ok(AMDVCpu)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl VCpu for AMDVCpu {
|
|
||||||
fn run(&mut self) {
|
|
||||||
info!("VCpu on AMD");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_supported() -> bool
|
fn is_supported() -> bool
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
mod vmxon;
|
||||||
|
|
||||||
use raw_cpuid::cpuid;
|
use raw_cpuid::cpuid;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -7,8 +9,15 @@ use crate::{
|
|||||||
|
|
||||||
pub struct IntelVCpu;
|
pub struct IntelVCpu;
|
||||||
|
|
||||||
impl IntelVCpu {
|
impl VCpu for IntelVCpu {
|
||||||
pub fn new() -> Self {
|
fn run(&mut self) {
|
||||||
|
info!("VCpu on Intel");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new() -> Result<Self, &'static str>
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
let mut msr = common::read_msr(0x3a);
|
let mut msr = common::read_msr(0x3a);
|
||||||
if msr & (1 << 2) == 0 {
|
if msr & (1 << 2) == 0 {
|
||||||
msr |= 1 << 2;
|
msr |= 1 << 2;
|
||||||
@@ -18,16 +27,10 @@ impl IntelVCpu {
|
|||||||
|
|
||||||
let msr = common::read_msr(0x3a);
|
let msr = common::read_msr(0x3a);
|
||||||
if msr & (1 << 2) == 0 {
|
if msr & (1 << 2) == 0 {
|
||||||
panic!("VMX is not enabled in the BIOS");
|
return Err("VMX is not enabled in the BIOS");
|
||||||
}
|
}
|
||||||
|
|
||||||
IntelVCpu
|
Ok(IntelVCpu)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl VCpu for IntelVCpu {
|
|
||||||
fn run(&mut self) {
|
|
||||||
info!("VCpu on Intel");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_supported() -> bool
|
fn is_supported() -> bool
|
||||||
|
|||||||
16
nel_os_kernel/src/vmm/x86_64/intel/vmxon.rs
Normal file
16
nel_os_kernel/src/vmm/x86_64/intel/vmxon.rs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
use x86_64::structures::paging::{FrameAllocator, PhysFrame, Size4KiB};
|
||||||
|
|
||||||
|
#[repr(C, align(4096))]
|
||||||
|
pub struct Vmxon {
|
||||||
|
frame: PhysFrame,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Vmxon {
|
||||||
|
pub fn new(frame_allocator: &mut impl FrameAllocator<Size4KiB>) -> Result<Self, &'static str> {
|
||||||
|
let frame = frame_allocator
|
||||||
|
.allocate_frame()
|
||||||
|
.ok_or("Failed to allocate frame for VMXON")?;
|
||||||
|
|
||||||
|
Ok(Vmxon { frame })
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user