diff --git a/src/arch/aarch64/kernel/mod.rs b/src/arch/aarch64/kernel/mod.rs index c73b017b00..dddf1cad06 100644 --- a/src/arch/aarch64/kernel/mod.rs +++ b/src/arch/aarch64/kernel/mod.rs @@ -21,7 +21,7 @@ use hermit_entry::boot_info::{BootInfo, RawBootInfo}; use crate::arch::aarch64::kernel::core_local::*; use crate::arch::aarch64::kernel::serial::SerialPort; use crate::arch::aarch64::mm::{PhysAddr, VirtAddr}; -use crate::env; +use crate::runtime_params; const SERIAL_PORT_BAUDRATE: u32 = 115200; @@ -144,7 +144,7 @@ pub fn boot_processor_init() { crate::mm::init(); crate::mm::print_information(); CoreLocal::get().add_irq_counter(); - env::init(); + runtime_params::init(); interrupts::init(); interrupts::enable(); processor::detect_frequency(); diff --git a/src/arch/aarch64/kernel/processor.rs b/src/arch/aarch64/kernel/processor.rs index af7a3ac98a..974a0cab9f 100644 --- a/src/arch/aarch64/kernel/processor.rs +++ b/src/arch/aarch64/kernel/processor.rs @@ -6,7 +6,7 @@ use hermit_dtb::Dtb; use hermit_sync::{without_interrupts, Lazy}; use crate::arch::aarch64::kernel::boot_info; -use crate::env; +use crate::runtime_params; // System counter frequency in Hz static CPU_FREQUENCY: Lazy = Lazy::new(|| { @@ -63,7 +63,7 @@ impl CpuFrequency { } unsafe fn detect_from_cmdline(&mut self) -> Result<(), ()> { - let mhz = env::freq().ok_or(())?; + let mhz = runtime_params::freq().ok_or(())?; self.set_detected_cpu_frequency(u32::from(mhz) * 1000000, CpuFrequencySources::CommandLine) } diff --git a/src/arch/aarch64/mm/paging.rs b/src/arch/aarch64/mm/paging.rs index 5e03396a35..95618a9b76 100644 --- a/src/arch/aarch64/mm/paging.rs +++ b/src/arch/aarch64/mm/paging.rs @@ -10,7 +10,7 @@ use crate::arch::aarch64::kernel::{ get_base_address, get_boot_info_address, get_image_size, get_ram_address, processor, }; use crate::arch::aarch64::mm::{physicalmem, virtualmem, PhysAddr, VirtAddr}; -use crate::env::is_uhyve; +use crate::runtime_params::is_uhyve; use crate::{mm, scheduler, KERNEL_STACK_SIZE}; /// Pointer to the root page table (called "Level 0" in ARM terminology). diff --git a/src/arch/riscv64/kernel/mod.rs b/src/arch/riscv64/kernel/mod.rs index 68bf45f02a..c2c2974886 100644 --- a/src/arch/riscv64/kernel/mod.rs +++ b/src/arch/riscv64/kernel/mod.rs @@ -25,7 +25,7 @@ pub use crate::arch::riscv64::kernel::devicetree::init_drivers; use crate::arch::riscv64::kernel::processor::lsb; use crate::arch::riscv64::mm::{physicalmem, PhysAddr, VirtAddr}; use crate::config::KERNEL_STACK_SIZE; -use crate::env; +use crate::runtime_params; // Used to store information about available harts. The index of the hart in the vector // represents its CpuId and does not need to match its hart_id @@ -134,7 +134,7 @@ pub fn boot_processor_init() { devicetree::init(); crate::mm::init(); crate::mm::print_information(); - env::init(); + runtime_params::init(); interrupts::install(); finish_processor_init(); @@ -199,7 +199,7 @@ fn finish_processor_init() { CPU_ONLINE.fetch_add(1, Ordering::Release); //When running bare-metal/QEMU we use the firmware to start the next hart - if !env::is_uhyve() { + if !runtime_params::is_uhyve() { sbi_rt::hart_start( next_hart_id as usize, start::_start as usize, diff --git a/src/arch/x86_64/kernel/apic.rs b/src/arch/x86_64/kernel/apic.rs index 983d55df90..e2579f0a64 100644 --- a/src/arch/x86_64/kernel/apic.rs +++ b/src/arch/x86_64/kernel/apic.rs @@ -29,7 +29,7 @@ use crate::arch::x86_64::mm::{paging, virtualmem, PhysAddr, VirtAddr}; use crate::arch::x86_64::swapgs; use crate::config::*; use crate::scheduler::CoreId; -use crate::{arch, env, scheduler}; +use crate::{arch, runtime_params, scheduler}; const MP_FLT_SIGNATURE: u32 = 0x5f504d5f; const MP_CONFIG_SIGNATURE: u32 = 0x504d4350; @@ -448,7 +448,7 @@ fn default_apic() -> PhysAddr { let default_address = PhysAddr(0xFEE0_0000); // currently, uhyve doesn't support an IO-APIC - if !env::is_uhyve() { + if !runtime_params::is_uhyve() { init_ioapic_address(default_address); } @@ -515,7 +515,7 @@ pub fn init() { } // currently, IO-APIC isn't supported by uhyve - if !env::is_uhyve() { + if !runtime_params::is_uhyve() { // initialize IO-APIC init_ioapic(); } diff --git a/src/arch/x86_64/kernel/mmio.rs b/src/arch/x86_64/kernel/mmio.rs index 510e9d44f0..cacde7b222 100644 --- a/src/arch/x86_64/kernel/mmio.rs +++ b/src/arch/x86_64/kernel/mmio.rs @@ -15,7 +15,7 @@ use crate::arch::x86_64::mm::{paging, PhysAddr}; use crate::drivers::net::virtio::VirtioNetDriver; use crate::drivers::virtio::transport::mmio as mmio_virtio; use crate::drivers::virtio::transport::mmio::VirtioDriver; -use crate::env; +use crate::runtime_params; pub const MAGIC_VALUE: u32 = 0x74726976; @@ -179,7 +179,7 @@ fn guess_device() -> Result<(VolatileRef<'static, DeviceRegisters>, u8), &'stati /// Tries to find the network device within the specified address range. /// Returns a reference to it within the Ok() if successful or an Err() on failure. fn detect_network() -> Result<(VolatileRef<'static, DeviceRegisters>, u8), &'static str> { - let linux_mmio = env::mmio(); + let linux_mmio = runtime_params::mmio(); if !linux_mmio.is_empty() { check_linux_args(linux_mmio) diff --git a/src/arch/x86_64/kernel/mod.rs b/src/arch/x86_64/kernel/mod.rs index e6243eea57..fc85d043f5 100644 --- a/src/arch/x86_64/kernel/mod.rs +++ b/src/arch/x86_64/kernel/mod.rs @@ -12,7 +12,7 @@ use x86::controlregs::{cr0, cr0_write, cr4, Cr0}; use self::serial::SerialPort; use crate::arch::mm::{PhysAddr, VirtAddr}; use crate::arch::x86_64::kernel::core_local::*; -use crate::env::{self, is_uhyve}; +use crate::runtime_params::{self, is_uhyve}; #[cfg(feature = "acpi")] pub mod acpi; @@ -157,7 +157,7 @@ pub fn boot_processor_init() { processor::detect_features(); processor::configure(); - if cfg!(feature = "vga") && !env::is_uhyve() { + if cfg!(feature = "vga") && !runtime_params::is_uhyve() { #[cfg(feature = "vga")] vga::init(); } @@ -165,7 +165,7 @@ pub fn boot_processor_init() { crate::mm::init(); crate::mm::print_information(); CoreLocal::get().add_irq_counter(); - env::init(); + runtime_params::init(); gdt::add_current_core(); interrupts::load_idt(); pic::init(); @@ -182,7 +182,7 @@ pub fn boot_processor_init() { #[cfg(feature = "pci")] pci::init(); } - if !env::is_uhyve() { + if !runtime_params::is_uhyve() { #[cfg(feature = "acpi")] acpi::init(); } @@ -220,7 +220,7 @@ pub fn application_processor_init() { } fn finish_processor_init() { - if env::is_uhyve() { + if runtime_params::is_uhyve() { // uhyve does not use apic::detect_from_acpi and therefore does not know the number of processors and // their APIC IDs in advance. // Therefore, we have to add each booted processor into the CPU_LOCAL_APIC_IDS vector ourselves. diff --git a/src/arch/x86_64/kernel/processor.rs b/src/arch/x86_64/kernel/processor.rs index 4f640dbb53..476c368992 100644 --- a/src/arch/x86_64/kernel/processor.rs +++ b/src/arch/x86_64/kernel/processor.rs @@ -24,7 +24,7 @@ use x86_64::VirtAddr; #[cfg(feature = "acpi")] use crate::arch::x86_64::kernel::acpi; use crate::arch::x86_64::kernel::{boot_info, interrupts, pic, pit}; -use crate::env; +use crate::runtime_params; const IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP: u64 = 1 << 16; const IA32_MISC_ENABLE_SPEEDSTEP_LOCK: u64 = 1 << 20; @@ -313,7 +313,7 @@ impl CpuFrequency { } unsafe fn detect_from_cmdline(&mut self) -> Result<(), ()> { - let mhz = env::freq().ok_or(())?; + let mhz = runtime_params::freq().ok_or(())?; self.set_detected_cpu_frequency(mhz, CpuFrequencySources::CommandLine) } @@ -406,7 +406,7 @@ impl CpuFrequency { use crate::arch::x86_64::kernel::interrupts::IDT; // The PIC is not initialized for uhyve, so we cannot measure anything. - if env::is_uhyve() { + if runtime_params::is_uhyve() { return Err(()); } @@ -672,7 +672,7 @@ impl fmt::Display for CpuFeaturePrinter { } pub(crate) fn run_on_hypervisor() -> bool { - env::is_uhyve() || FEATURES.run_on_hypervisor + runtime_params::is_uhyve() || FEATURES.run_on_hypervisor } #[derive(Debug)] diff --git a/src/arch/x86_64/kernel/serial.rs b/src/arch/x86_64/kernel/serial.rs index 5db44653ca..f9b99c9c05 100644 --- a/src/arch/x86_64/kernel/serial.rs +++ b/src/arch/x86_64/kernel/serial.rs @@ -22,7 +22,7 @@ pub struct SerialPort { impl SerialPort { pub unsafe fn new(base: u16) -> Self { - if crate::env::is_uhyve() { + if crate::runtime_params::is_uhyve() { let serial = Port::new(base); Self { inner: SerialInner::Uhyve(serial), diff --git a/src/arch/x86_64/mm/paging.rs b/src/arch/x86_64/mm/paging.rs index 6607671d64..ad384384ab 100644 --- a/src/arch/x86_64/mm/paging.rs +++ b/src/arch/x86_64/mm/paging.rs @@ -15,7 +15,7 @@ use x86_64::structures::paging::{ use crate::arch::x86_64::kernel::processor; use crate::arch::x86_64::mm::{physicalmem, PhysAddr, VirtAddr}; -use crate::{env, mm, scheduler}; +use crate::{mm, runtime_params, scheduler}; pub trait PageTableEntryFlagsExt { fn device(&mut self) -> &mut Self; @@ -303,7 +303,7 @@ pub(crate) extern "x86-interrupt" fn page_fault_handler( pub fn init() {} pub fn init_page_tables() { - if env::is_uhyve() { + if runtime_params::is_uhyve() { // Uhyve identity-maps the first Gibibyte of memory (512 page table entries * 2MiB pages) // We now unmap all memory after the kernel image, so that we can remap it ourselves later for the heap. // Ideally, uhyve would only map as much memory as necessary, but this requires a hermit-entry ABI jump. diff --git a/src/arch/x86_64/mm/physicalmem.rs b/src/arch/x86_64/mm/physicalmem.rs index cb25c5c4c7..7403cd73d9 100644 --- a/src/arch/x86_64/mm/physicalmem.rs +++ b/src/arch/x86_64/mm/physicalmem.rs @@ -7,7 +7,7 @@ use multiboot::information::{MemoryType, Multiboot}; use crate::arch::x86_64::kernel::{get_fdt, get_limit, get_mbinfo}; use crate::arch::x86_64::mm::paging::{BasePageSize, PageSize}; use crate::arch::x86_64::mm::{MultibootMemory, PhysAddr, VirtAddr}; -use crate::{env, mm}; +use crate::{mm, runtime_params}; pub static PHYSICAL_FREE_LIST: InterruptTicketMutex> = InterruptTicketMutex::new(FreeList::new()); @@ -106,7 +106,7 @@ fn detect_from_multiboot_info() -> Result<(), ()> { } fn detect_from_uhyve() -> Result<(), ()> { - if !env::is_uhyve() { + if !runtime_params::is_uhyve() { return Err(()); } diff --git a/src/fs/uhyve.rs b/src/fs/uhyve.rs index 0c88394b77..38d4a57ba4 100644 --- a/src/fs/uhyve.rs +++ b/src/fs/uhyve.rs @@ -12,12 +12,12 @@ use async_trait::async_trait; use x86::io::outl; use crate::arch::mm::{paging, PhysAddr, VirtAddr}; -use crate::env::is_uhyve; use crate::executor::block_on; use crate::fd::IoError; use crate::fs::{ self, AccessPermission, FileAttr, NodeKind, ObjectInterface, OpenOption, SeekWhence, VfsNode, }; +use crate::runtime_params::is_uhyve; /// forward a request to the hypervisor uhyve #[inline] diff --git a/src/lib.rs b/src/lib.rs index 2ac8ad8b50..62b5d2f97a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,7 +60,7 @@ use core::sync::atomic::{AtomicU32, Ordering}; use arch::core_local::*; // Used for integration test status. #[doc(hidden)] -pub use env::is_uhyve as _is_uhyve; +pub use runtime_params::is_uhyve as _is_uhyve; pub(crate) use crate::arch::*; pub use crate::config::DEFAULT_STACK_SIZE; @@ -80,13 +80,13 @@ mod config; pub mod console; mod drivers; mod entropy; -mod env; pub mod errno; mod executor; pub mod fd; pub mod fs; pub mod io; mod mm; +mod runtime_params; pub mod scheduler; #[cfg(all(feature = "shell", target_arch = "x86_64"))] mod shell; @@ -133,7 +133,7 @@ extern "C" fn initd(_arg: usize) { fn main(argc: i32, argv: *const *const u8, env: *const *const u8); } - if !env::is_uhyve() { + if !runtime_params::is_uhyve() { info!("Hermit is running on common system!"); } else { info!("Hermit is running on uhyve!"); @@ -192,7 +192,7 @@ fn boot_processor_main() -> ! { } info!("Welcome to Hermit {}", env!("CARGO_PKG_VERSION")); - info!("Kernel starts at {:p}", env::get_base_address()); + info!("Kernel starts at {:p}", runtime_params::get_base_address()); #[cfg(target_arch = "x86_64")] if let Some(fdt) = kernel::get_fdt() { @@ -211,7 +211,7 @@ fn boot_processor_main() -> ! { #[cfg(not(target_arch = "riscv64"))] scheduler::add_current_core(); - if !env::is_uhyve() { + if !runtime_params::is_uhyve() { arch::boot_application_processors(); } @@ -227,7 +227,7 @@ fn boot_processor_main() -> ! { #[cfg(feature = "smp")] info!("Compiled with SMP support"); - if is_uhyve_with_pci() || !env::is_uhyve() { + if is_uhyve_with_pci() || !runtime_params::is_uhyve() { #[cfg(feature = "pci")] crate::drivers::pci::print_information(); } diff --git a/src/macros.rs b/src/macros.rs index b63426156d..2cac96eef6 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -212,7 +212,7 @@ macro_rules! hermit_var { ($name:expr) => {{ use alloc::borrow::Cow; - match crate::env::var($name) { + match crate::runtime_params::var($name) { Some(val) => Some(Cow::from(val)), None => option_env!($name).map(Cow::Borrowed), } diff --git a/src/mm/mod.rs b/src/mm/mod.rs index 38ffadf7d9..10bef4296a 100644 --- a/src/mm/mod.rs +++ b/src/mm/mod.rs @@ -21,7 +21,7 @@ use crate::arch::mm::virtualmem::kernel_heap_end; #[cfg(feature = "pci")] use crate::arch::mm::PhysAddr; use crate::arch::mm::VirtAddr; -use crate::{arch, env}; +use crate::{arch, runtime_params}; #[cfg(target_os = "none")] #[global_allocator] @@ -31,8 +31,9 @@ pub static ALLOCATOR: LockedAllocator = LockedAllocator::new(); static KERNEL_ADDR_RANGE: Lazy> = Lazy::new(|| { if cfg!(target_os = "none") { // Calculate the start and end addresses of the 2 MiB page(s) that map the kernel. - env::get_base_address().align_down_to_large_page() - ..(env::get_base_address() + env::get_image_size()).align_up_to_large_page() + runtime_params::get_base_address().align_down_to_large_page() + ..(runtime_params::get_base_address() + runtime_params::get_image_size()) + .align_up_to_large_page() } else { VirtAddr::zero()..VirtAddr::zero() } @@ -94,7 +95,7 @@ pub(crate) fn init() { //info!("reserved space {} KB", reserved_space >> 10); if total_memory_size() - < kernel_end_address().as_usize() - env::get_ram_address().as_usize() + < kernel_end_address().as_usize() - runtime_params::get_ram_address().as_usize() + reserved_space + LargePageSize::SIZE as usize { @@ -105,7 +106,7 @@ pub(crate) fn init() { let mut map_size: usize; let available_memory = (total_memory_size() - - (kernel_end_address().as_usize() - env::get_ram_address().as_usize()) + - (kernel_end_address().as_usize() - runtime_params::get_ram_address().as_usize()) - reserved_space) .align_down(LargePageSize::SIZE as usize); diff --git a/src/env.rs b/src/runtime_params.rs similarity index 82% rename from src/env.rs rename to src/runtime_params.rs index 0987352b71..ca48dad2c4 100644 --- a/src/env.rs +++ b/src/runtime_params.rs @@ -1,4 +1,4 @@ -//! Central parsing of the command-line parameters. +//! Kernel Runtime parameters (e.g., command line arguments) use alloc::string::{String, ToString}; use alloc::vec::Vec; @@ -19,29 +19,27 @@ pub fn init() { CLI.set(Cli::default()).unwrap(); } +/// Parameters retrieved from the command line arguments of the kernel. #[derive(Debug)] struct Cli { #[allow(dead_code)] image_path: Option, #[cfg(not(target_arch = "riscv64"))] freq: Option, - env_vars: HashMap, + // Other Kernel parameters + parameters: HashMap, + // Application arguments args: Vec, #[allow(dead_code)] mmio: Vec, } -/// Whether Hermit is running under the "uhyve" hypervisor. -pub fn is_uhyve() -> bool { - matches!(boot_info().platform_info, PlatformInfo::Uhyve { .. }) -} - impl Default for Cli { fn default() -> Self { let mut image_path = None; #[cfg(not(target_arch = "riscv64"))] let mut freq = None; - let mut env_vars = HashMap::::with_hasher( + let mut variables = HashMap::::with_hasher( RandomState::with_seeds(0, 0, 0, 0), ); let mut args = Vec::new(); @@ -71,25 +69,25 @@ impl Default for Cli { } "-ip" => { let ip = expect_arg(words.next(), word.as_str()); - env_vars.insert(String::from("HERMIT_IP"), ip); + variables.insert(String::from("HERMIT_IP"), ip); } "-mask" => { let mask = expect_arg(words.next(), word.as_str()); - env_vars.insert(String::from("HERMIT_MASK"), mask); + variables.insert(String::from("HERMIT_MASK"), mask); } "-gateway" => { let gateway = expect_arg(words.next(), word.as_str()); - env_vars.insert(String::from("HERMIT_GATEWAY"), gateway); + variables.insert(String::from("HERMIT_GATEWAY"), gateway); } "-mount" => { let gateway = expect_arg(words.next(), word.as_str()); - env_vars.insert(String::from("UHYVE_MOUNT"), gateway); + variables.insert(String::from("UHYVE_MOUNT"), gateway); } "--" => args.extend(&mut words), _ if image_path.is_none() => image_path = Some(word), word => warn!( "Found argument '{word}' which wasn't expected, or isn't valid in this context - + If you tried to supply `{word}` as a value rather than a flag, use `-- {word}`" ), }; @@ -99,7 +97,7 @@ impl Default for Cli { image_path, #[cfg(not(target_arch = "riscv64"))] freq, - env_vars, + parameters: variables, args, #[allow(dead_code)] mmio, @@ -115,11 +113,11 @@ pub fn freq() -> Option { #[allow(dead_code)] pub fn var(key: &str) -> Option<&String> { - CLI.get().unwrap().env_vars.get(key) + CLI.get().unwrap().parameters.get(key) } pub fn vars() -> Iter<'static, String, String> { - CLI.get().unwrap().env_vars.iter() + CLI.get().unwrap().parameters.iter() } /// Returns the cmdline argument passed in after "--" @@ -132,3 +130,8 @@ pub fn args() -> &'static [String] { pub fn mmio() -> &'static [String] { CLI.get().unwrap().mmio.as_slice() } + +/// Whether Hermit is running under the "uhyve" hypervisor. +pub fn is_uhyve() -> bool { + matches!(boot_info().platform_info, PlatformInfo::Uhyve { .. }) +} diff --git a/src/scheduler/task.rs b/src/scheduler/task.rs index 60f8491c9f..1c939c6623 100644 --- a/src/scheduler/task.rs +++ b/src/scheduler/task.rs @@ -28,7 +28,7 @@ use crate::fd::{ FileDescriptor, IoError, ObjectInterface, STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO, }; use crate::scheduler::CoreId; -use crate::{arch, env}; +use crate::{arch, runtime_params}; /// Returns the most significant bit. /// @@ -467,7 +467,7 @@ impl Task { let _ = poll_on( async { let mut guard = objmap.write().await; - if env::is_uhyve() { + if runtime_params::is_uhyve() { guard .try_insert(STDIN_FILENO, Arc::new(UhyveStdin::new())) .map_err(|_| IoError::EIO)?; diff --git a/src/syscalls/interfaces/mod.rs b/src/syscalls/interfaces/mod.rs index 332a9360b9..a4162bc958 100644 --- a/src/syscalls/interfaces/mod.rs +++ b/src/syscalls/interfaces/mod.rs @@ -3,7 +3,7 @@ use alloc::vec::Vec; pub use self::generic::*; pub use self::uhyve::*; -use crate::{arch, env}; +use crate::{arch, runtime_params}; mod generic; pub(crate) mod uhyve; @@ -19,7 +19,7 @@ pub trait SyscallInterface: Send + Sync { let name = Box::leak(Box::new("{name}\0")).as_ptr(); argv.push(name); - let args = env::args(); + let args = runtime_params::args(); debug!("Setting argv as: {:?}", args); for arg in args { let ptr = Box::leak(format!("{arg}\0").into_boxed_str()).as_ptr(); @@ -28,7 +28,7 @@ pub trait SyscallInterface: Send + Sync { let mut envv = Vec::new(); - let envs = env::vars(); + let envs = runtime_params::vars(); debug!("Setting envv as: {:?}", envs); for (key, value) in envs { let ptr = Box::leak(format!("{key}={value}\0").into_boxed_str()).as_ptr(); diff --git a/src/syscalls/mod.rs b/src/syscalls/mod.rs index 93dcd0e395..3d15521193 100644 --- a/src/syscalls/mod.rs +++ b/src/syscalls/mod.rs @@ -20,7 +20,6 @@ pub use self::spinlock::*; pub use self::system::*; pub use self::tasks::*; pub use self::timer::*; -use crate::env; use crate::fd::{ dup_object, get_object, remove_object, AccessPermission, EventFlags, FileDescriptor, IoCtl, IoError, OpenOption, PollFd, @@ -28,6 +27,7 @@ use crate::fd::{ use crate::fs::{self, FileAttr}; #[cfg(all(target_os = "none", not(feature = "common-os")))] use crate::mm::ALLOCATOR; +use crate::runtime_params; use crate::syscalls::interfaces::SyscallInterface; mod condvar; @@ -48,7 +48,7 @@ mod tasks; mod timer; pub(crate) static SYS: Lazy<&'static dyn SyscallInterface> = Lazy::new(|| { - if env::is_uhyve() { + if runtime_params::is_uhyve() { &self::interfaces::Uhyve } else { &self::interfaces::Generic