Skip to content

Commit cb87672

Browse files
committed
Step 1: enable VMX
1 parent 4afc124 commit cb87672

19 files changed

Lines changed: 556 additions & 13 deletions

File tree

hypervisor/Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hypervisor/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ bitflags = "1.3"
1414
buddy_system_allocator = "0.8"
1515
lazy_static = { version = "1.4.0", features = ["spin_no_std"] }
1616
bitmap-allocator = { git = "https://github.com/rcore-os/bitmap-allocator", rev = "88e871a" }
17+
rvm = { path = "../rvm" }
1718

1819
[target.'cfg(target_arch = "x86_64")'.dependencies]
1920
x86 = "0.52"
2021
x86_64 = "0.14"
2122
x2apic = "0.4"
2223
raw-cpuid = "10.6"
24+
25+
[profile.release]
26+
lto = true

hypervisor/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ GDB := gdb-multiarch
2525
qemu := qemu-system-$(ARCH)
2626
qemu_args := -nographic -m 128M
2727

28-
qemu_args += -cpu host,+x2apic -accel kvm
28+
qemu_args += -cpu host,+x2apic,+vmx -accel kvm
2929

3030
ifeq ($(ARCH), x86_64)
3131
qemu_args += \

hypervisor/src/hv/hal.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use rvm::{HostPhysAddr, HostVirtAddr, RvmHal};
2+
3+
use crate::mm::{address, frame};
4+
5+
pub struct RvmHalImpl;
6+
7+
impl RvmHal for RvmHalImpl {
8+
fn alloc_page() -> Option<HostPhysAddr> {
9+
unsafe { frame::alloc_page() }
10+
}
11+
12+
fn dealloc_page(paddr: HostPhysAddr) {
13+
unsafe { frame::dealloc_page(paddr) }
14+
}
15+
16+
fn phys_to_virt(paddr: HostPhysAddr) -> HostVirtAddr {
17+
address::phys_to_virt(paddr)
18+
}
19+
20+
fn virt_to_phys(vaddr: HostVirtAddr) -> HostPhysAddr {
21+
address::virt_to_phys(vaddr)
22+
}
23+
}

hypervisor/src/hv/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
mod hal;
2+
3+
use rvm::RvmPerCpu;
4+
5+
use self::hal::RvmHalImpl;
6+
7+
pub fn run() {
8+
println!("Starting virtualization...");
9+
println!("Hardware support: {:?}", rvm::has_hardware_support());
10+
11+
let mut percpu = RvmPerCpu::<RvmHalImpl>::new(0);
12+
let res = percpu.hardware_enable();
13+
println!("Hardware enable: {:?}", res);
14+
}

hypervisor/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mod logging;
1111

1212
mod arch;
1313
mod config;
14+
mod hv;
1415
mod mm;
1516
mod timer;
1617

@@ -74,6 +75,9 @@ fn main() -> ! {
7475
INIT_OK.store(true, Ordering::SeqCst);
7576
println!("Initialization completed.\n");
7677

78+
hv::run();
79+
println!("Run OK!");
80+
7781
arch::instructions::enable_irqs();
7882
loop {
7983
arch::instructions::wait_for_ints();

hypervisor/src/mm/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![allow(dead_code)]
2-
31
mod heap;
42

53
pub mod address;

rvm/Cargo.lock

Lines changed: 0 additions & 7 deletions
This file was deleted.

rvm/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,17 @@ authors = ["Yuekai Jia <equation618@gmail.com>"]
66

77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

9+
[features]
10+
default = ["vmx"]
11+
vmx = []
12+
913
[dependencies]
14+
log = "0.4"
15+
cfg-if = "1.0"
16+
bitflags = "1.3"
17+
bit_field = "0.10"
18+
19+
[target.'cfg(target_arch = "x86_64")'.dependencies]
20+
x86 = "0.52"
21+
x86_64 = "0.14"
22+
raw-cpuid = "10.6"

rvm/src/arch/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//! Architecture dependent structures.
2+
3+
cfg_if::cfg_if! {
4+
if #[cfg(target_arch = "x86_64")] {
5+
mod x86_64;
6+
pub use self::x86_64::*;
7+
}
8+
}

0 commit comments

Comments
 (0)