From 449abb89259e211e7c2799e20bf4607ab9ba1716 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 25 Feb 2024 15:53:04 +0100 Subject: [PATCH] Share bootstrap_mem between all archs --- src/arch/aarch64/mod.rs | 9 --------- src/arch/x86/mod.rs | 8 -------- src/arch/x86_64/mod.rs | 13 ------------- src/syscall/process.rs | 12 ++++++++++-- 4 files changed, 10 insertions(+), 32 deletions(-) diff --git a/src/arch/aarch64/mod.rs b/src/arch/aarch64/mod.rs index 7bf4c04e35..4c96a984c3 100644 --- a/src/arch/aarch64/mod.rs +++ b/src/arch/aarch64/mod.rs @@ -68,15 +68,6 @@ pub unsafe extern "C" fn arch_copy_to_user(dst: usize, src: usize, len: usize) - options(noreturn) ); } -pub unsafe fn bootstrap_mem(bootstrap: &crate::Bootstrap) -> &'static [u8] { - use crate::memory::PAGE_SIZE; - use ::rmm::Arch; - - core::slice::from_raw_parts( - CurrentRmmArch::phys_to_virt(bootstrap.base.start_address()).data() as *const u8, - bootstrap.page_count * PAGE_SIZE, - ) -} pub const KFX_SIZE: usize = 1024; diff --git a/src/arch/x86/mod.rs b/src/arch/x86/mod.rs index e672f24819..3647202cc7 100644 --- a/src/arch/x86/mod.rs +++ b/src/arch/x86/mod.rs @@ -21,8 +21,6 @@ pub mod rmm; /// Initialization and start function pub mod start; -use crate::{memory::PAGE_SIZE, Bootstrap}; -use ::rmm::Arch; pub use ::rmm::X86Arch as CurrentRmmArch; // Flags @@ -56,12 +54,6 @@ pub unsafe extern "C" fn arch_copy_to_user(dst: usize, src: usize, len: usize) - } pub use arch_copy_to_user as arch_copy_from_user; -pub unsafe fn bootstrap_mem(bootstrap: &Bootstrap) -> &'static [u8] { - core::slice::from_raw_parts( - CurrentRmmArch::phys_to_virt(bootstrap.base.start_address()).data() as *const u8, - bootstrap.page_count * PAGE_SIZE, - ) -} pub const KFX_SIZE: usize = 512; // This function exists as the KFX size is dynamic on x86_64. diff --git a/src/arch/x86_64/mod.rs b/src/arch/x86_64/mod.rs index 6edd2e87d2..ee5fa059c7 100644 --- a/src/arch/x86_64/mod.rs +++ b/src/arch/x86_64/mod.rs @@ -1,7 +1,3 @@ -use crate::Bootstrap; - -use self::paging::PAGE_SIZE; - pub use crate::arch::x86_shared::*; pub mod alternative; @@ -33,7 +29,6 @@ pub mod rmm; /// Initialization and start function pub mod start; -use ::rmm::Arch; pub use ::rmm::X8664Arch as CurrentRmmArch; // Flags @@ -73,12 +68,4 @@ pub unsafe extern "C" fn arch_copy_to_user(dst: usize, src: usize, len: usize) - } pub use arch_copy_to_user as arch_copy_from_user; -// TODO: This doesn't need to be arch-specific, right? -pub unsafe fn bootstrap_mem(bootstrap: &Bootstrap) -> &'static [u8] { - core::slice::from_raw_parts( - CurrentRmmArch::phys_to_virt(bootstrap.base.start_address()).data() as *const u8, - bootstrap.page_count * PAGE_SIZE, - ) -} - pub use alternative::kfx_size; diff --git a/src/syscall/process.rs b/src/syscall/process.rs index 35b9576b84..db700f728e 100644 --- a/src/syscall/process.rs +++ b/src/syscall/process.rs @@ -2,6 +2,7 @@ use alloc::{sync::Arc, vec::Vec}; use core::mem; use spin::RwLock; +use rmm::Arch; use crate::context::{ memory::{AddrSpace, PageSpan}, @@ -22,7 +23,7 @@ use crate::{ }, ptrace_event, }, - Bootstrap, + Bootstrap, CurrentRmmArch, }; use super::usercopy::{UserSliceRo, UserSliceWo}; @@ -606,9 +607,16 @@ pub unsafe fn usermode_bootstrap(bootstrap: &Bootstrap) -> ! { // TODO: Not all arches do linear mapping UserSliceWo::new(0, bootstrap.page_count * PAGE_SIZE) .expect("failed to create bootstrap user slice") - .copy_from_slice(unsafe { crate::arch::bootstrap_mem(bootstrap) }) + .copy_from_slice(unsafe { bootstrap_mem(bootstrap) }) .expect("failed to copy memory to bootstrap"); // Start in a minimal environment without any stack. usermode(bootstrap.entry, 0, 0, 0); } + +pub unsafe fn bootstrap_mem(bootstrap: &crate::Bootstrap) -> &'static [u8] { + core::slice::from_raw_parts( + CurrentRmmArch::phys_to_virt(bootstrap.base.start_address()).data() as *const u8, + bootstrap.page_count * PAGE_SIZE, + ) +}