From 3a10757921f375a03e2a35a07307218d983a7242 Mon Sep 17 00:00:00 2001 From: gjz010 Date: Mon, 17 May 2021 11:04:31 +0800 Subject: [PATCH] bump rvm version and modify ffi --- kernel/Cargo.lock | 4 ++-- kernel/Cargo.toml | 2 +- kernel/src/rvm/mod.rs | 48 ++++++++++++++++--------------------------- 3 files changed, 21 insertions(+), 33 deletions(-) diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index dcafa37a..f63e1dd0 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -681,7 +681,7 @@ dependencies = [ [[package]] name = "rvm" version = "1.2.0" -source = "git+https://github.com/rcore-riscv-hypervisor-dev/RVM?rev=5ccac8b#5ccac8ba6529cf06d5dabb8c137227c36f5ad2eb" +source = "git+https://github.com/rcore-riscv-hypervisor-dev/RVM?rev=2867e78#2867e782463fe81e572d7c3cd68abaf79252f50c" dependencies = [ "bit-set", "bit_field 0.10.1", @@ -701,7 +701,7 @@ dependencies = [ [[package]] name = "rvm_macros" version = "0.1.0" -source = "git+https://github.com/rcore-riscv-hypervisor-dev/RVM?rev=5ccac8b#5ccac8ba6529cf06d5dabb8c137227c36f5ad2eb" +source = "git+https://github.com/rcore-riscv-hypervisor-dev/RVM?rev=2867e78#2867e782463fe81e572d7c3cd68abaf79252f50c" dependencies = [ "quote", "syn", diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 3268076d..2cc0e74c 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -77,7 +77,7 @@ virtio-drivers = { git = "https://github.com/rcore-riscv-hypervisor-dev/virtio-d volatile = "0.2" woke = "0.0.2" xmas-elf = "0.7" -rvm = { git = "https://github.com/rcore-riscv-hypervisor-dev/RVM", rev = "5ccac8b", optional = true } +rvm = { git = "https://github.com/rcore-riscv-hypervisor-dev/RVM", rev = "2867e78", optional = true } [target.'cfg(target_arch = "x86_64")'.dependencies] apic = { git = "https://github.com/rcore-os/apic-rs", rev = "fb86bd7" } diff --git a/kernel/src/rvm/mod.rs b/kernel/src/rvm/mod.rs index 26116240..666fd6c7 100644 --- a/kernel/src/rvm/mod.rs +++ b/kernel/src/rvm/mod.rs @@ -28,25 +28,20 @@ fn into_fs_error(e: RvmError) -> FsError { } mod rvm_extern_fn { - use crate::memory::{alloc_frame, dealloc_frame, phys_to_virt}; - #[rvm::extern_fn(alloc_frame)] - fn rvm_alloc_frame() -> Option { - alloc_frame() + use crate::memory::{alloc_frame_contiguous, dealloc_frame, phys_to_virt}; + use rvm::PAGE_SIZE; + #[rvm::extern_fn(alloc_frames)] + fn rvm_alloc_frames(n: usize, align_log2: usize) -> Option { + alloc_frame_contiguous(n, align_log2) } - #[rvm::extern_fn(dealloc_frame)] - fn rvm_dealloc_frame(paddr: usize) { - dealloc_frame(paddr) - } - #[rvm::extern_fn(alloc_frame_x4)] - fn rvm_alloc_frame_x4() -> Option { - use crate::memory::alloc_frame_contiguous; - alloc_frame_contiguous(4, 2) - } - - #[rvm::extern_fn(dealloc_frame_x4)] - fn rvm_dealloc_frame_x4(paddr: usize) { - dealloc_frame(paddr) + #[rvm::extern_fn(dealloc_frames)] + fn rvm_dealloc_frames(paddr: usize, n: usize, _align_log2: usize) { + for i in 0..n { + dealloc_frame(paddr + i * PAGE_SIZE) + } + //use crate::memory::dealloc_frame_contiguous; + //dealloc_frame_contiguous(paddr, n, align_log2) } #[rvm::extern_fn(phys_to_virt)] @@ -73,20 +68,13 @@ mod rvm_extern_fn { crate::arch::interrupt::trap_handler_no_frame(sepc); } - #[cfg(all( - any(target_arch = "riscv64", target_arch = "riscv32"), - feature = "hypervisor" - ))] + #[cfg(any(target_arch = "riscv64", target_arch = "riscv32"))] #[rvm::extern_fn(riscv_check_hypervisor_extension)] fn rvm_riscv_check_hypervisor_extension() -> bool { - return true; - } - #[cfg(all( - any(target_arch = "riscv64", target_arch = "riscv32"), - not(feature = "hypervisor") - ))] - #[rvm::extern_fn(riscv_check_hypervisor_extension)] - fn rvm_riscv_check_hypervisor_extension() -> bool { - return false; + if cfg!(feature = "hypervisor") { + true + } else { + false + } } }