diff --git a/src/arch/aarch64/kernel/interrupts.rs b/src/arch/aarch64/kernel/interrupts.rs index 492e7a0d91..ede0f8d8be 100644 --- a/src/arch/aarch64/kernel/interrupts.rs +++ b/src/arch/aarch64/kernel/interrupts.rs @@ -14,18 +14,18 @@ use hashbrown::HashMap; use hermit_sync::{InterruptSpinMutex, InterruptTicketMutex, OnceCell, SpinMutex}; use memory_addresses::{PhysAddr, VirtAddr}; -use crate::arch::aarch64::kernel::core_local::increment_irq_counter; +use crate::arch::aarch64::kernel::core_local::{core_id, core_scheduler, increment_irq_counter}; use crate::arch::aarch64::kernel::scheduler::State; +use crate::arch::aarch64::kernel::serial::handle_uart_interrupt; use crate::arch::aarch64::mm::paging::{self, BasePageSize, PageSize, PageTableEntryFlags}; #[cfg(not(feature = "pci"))] use crate::drivers::mmio::get_interrupt_handlers; #[cfg(feature = "pci")] use crate::drivers::pci::get_interrupt_handlers; use crate::drivers::{InterruptHandlerQueue, InterruptLine}; -use crate::kernel::serial::handle_uart_interrupt; +use crate::env; use crate::mm::{PageAlloc, PageRangeAllocator}; use crate::scheduler::{self, CoreId, timer_interrupts}; -use crate::{core_id, core_scheduler, env}; /// The ID of the first Private Peripheral Interrupt. const PPI_START: u8 = 16; diff --git a/src/arch/aarch64/kernel/mod.rs b/src/arch/aarch64/kernel/mod.rs index 28859b7734..954d12e441 100644 --- a/src/arch/aarch64/kernel/mod.rs +++ b/src/arch/aarch64/kernel/mod.rs @@ -21,6 +21,8 @@ use core::{ptr, str}; use memory_addresses::PhysAddr; +pub(crate) use self::interrupts::wakeup_core; +pub(crate) use self::processor::set_oneshot_timer; use crate::arch::aarch64::kernel::core_local::*; use crate::arch::aarch64::mm::paging::{BasePageSize, PageSize}; use crate::config::*; @@ -124,7 +126,7 @@ pub fn boot_next_processor() { use memory_addresses::VirtAddr; - use crate::kernel::start::{TTBR0, smp_start}; + use crate::arch::aarch64::kernel::start::{TTBR0, smp_start}; use crate::mm::virtual_to_physical; if cpu_online == 0 { diff --git a/src/arch/aarch64/kernel/pci.rs b/src/arch/aarch64/kernel/pci.rs index f53995ca52..18b579526f 100644 --- a/src/arch/aarch64/kernel/pci.rs +++ b/src/arch/aarch64/kernel/pci.rs @@ -11,11 +11,12 @@ use pci_types::{ PciHeader, }; +use crate::arch::aarch64::kernel::core_local::core_id; use crate::arch::aarch64::kernel::interrupts::GIC; use crate::arch::aarch64::mm::paging::{self, BasePageSize, PageSize, PageTableEntryFlags}; use crate::drivers::pci::{PCI_DEVICES, PciDevice}; +use crate::env; use crate::mm::{PageAlloc, PageRangeAllocator}; -use crate::{core_id, env}; const PCI_MAX_DEVICE_NUMBER: u8 = 32; const PCI_MAX_FUNCTION_NUMBER: u8 = 8; diff --git a/src/arch/aarch64/kernel/scheduler.rs b/src/arch/aarch64/kernel/scheduler.rs index ca264c0426..3676c3e6b5 100644 --- a/src/arch/aarch64/kernel/scheduler.rs +++ b/src/arch/aarch64/kernel/scheduler.rs @@ -15,7 +15,7 @@ use crate::arch::aarch64::mm::paging::{BasePageSize, PageSize, PageTableEntryFla use crate::mm::{FrameAlloc, PageAlloc, PageRangeAllocator}; use crate::scheduler::PerCoreSchedulerExt; use crate::scheduler::task::{Task, TaskFrame}; -use crate::{DEFAULT_STACK_SIZE, KERNEL_STACK_SIZE}; +use crate::config::{DEFAULT_STACK_SIZE, KERNEL_STACK_SIZE}; #[derive(Debug)] #[repr(C, packed)] diff --git a/src/arch/aarch64/kernel/start.rs b/src/arch/aarch64/kernel/start.rs index 6e5bb21f0a..7b6f0590f9 100644 --- a/src/arch/aarch64/kernel/start.rs +++ b/src/arch/aarch64/kernel/start.rs @@ -11,7 +11,8 @@ use hermit_entry::Entry; use hermit_entry::boot_info::RawBootInfo; use crate::arch::aarch64::kernel::scheduler::TaskStacks; -use crate::{KERNEL_STACK_SIZE, env}; +use crate::config::KERNEL_STACK_SIZE; +use crate::env; /* * Memory types available. @@ -277,7 +278,7 @@ unsafe extern "C" fn pre_init(boot_info: Option<&'static RawBootInfo>, cpu_id: u "{preamble} Secondary core booted, but Hermit was not built with SMP support!" ); loop { - crate::arch::processor::halt(); + crate::arch::kernel::processor::halt(); } } #[cfg(feature = "smp")] diff --git a/src/arch/aarch64/mm/paging.rs b/src/arch/aarch64/mm/paging.rs index 3911c42c66..74533689aa 100644 --- a/src/arch/aarch64/mm/paging.rs +++ b/src/arch/aarch64/mm/paging.rs @@ -80,6 +80,7 @@ bitflags! { } impl PageTableEntryFlags { + #[expect(dead_code)] pub fn present(&mut self) -> &mut Self { self.insert(PageTableEntryFlags::PRESENT); self @@ -102,6 +103,7 @@ impl PageTableEntryFlags { self } + #[expect(dead_code)] pub fn read_only(&mut self) -> &mut Self { self.insert(PageTableEntryFlags::READ_ONLY); self diff --git a/src/arch/mod.rs b/src/arch/mod.rs index ea98a256cc..b83730a4fe 100644 --- a/src/arch/mod.rs +++ b/src/arch/mod.rs @@ -2,75 +2,15 @@ cfg_select! { target_arch = "aarch64" => { - pub(crate) mod aarch64; + mod aarch64; pub(crate) use self::aarch64::*; - - #[cfg(target_os = "none")] - pub(crate) use self::aarch64::kernel::boot_processor_init; - pub(crate) use self::aarch64::kernel::core_local; - pub(crate) use self::aarch64::kernel::interrupts; - pub(crate) use self::aarch64::kernel::interrupts::wakeup_core; - #[cfg(feature = "pci")] - pub(crate) use self::aarch64::kernel::pci; - pub(crate) use self::aarch64::kernel::processor; - pub(crate) use self::aarch64::kernel::serial::SerialDevice; - pub(crate) use self::aarch64::kernel::processor::set_oneshot_timer; - pub(crate) use self::aarch64::kernel::scheduler; - #[cfg(feature = "smp")] - pub(crate) use self::aarch64::kernel::application_processor_init; - pub(crate) use self::aarch64::kernel::{ - get_processor_count, - }; - pub use self::aarch64::mm::paging::{BasePageSize, PageSize}; - } - target_arch = "x86_64" => { - pub(crate) mod x86_64; - pub(crate) use self::x86_64::*; - - pub(crate) use self::x86_64::kernel::apic::{ - set_oneshot_timer, - wakeup_core, - }; - #[cfg(all(target_os = "none", feature = "smp"))] - pub(crate) use self::x86_64::kernel::application_processor_init; - pub(crate) use self::x86_64::kernel::core_local; - pub(crate) use self::x86_64::kernel::gdt::set_current_kernel_stack; - pub(crate) use self::x86_64::kernel::interrupts; - #[cfg(feature = "pci")] - pub(crate) use self::x86_64::kernel::pci; - pub(crate) use self::x86_64::kernel::processor; - pub(crate) use self::x86_64::kernel::serial::SerialDevice; - pub(crate) use self::x86_64::kernel::scheduler; - pub(crate) use self::x86_64::kernel::switch; - #[cfg(target_os = "none")] - pub(crate) use self::x86_64::kernel::boot_processor_init; - pub(crate) use self::x86_64::kernel::{ - get_processor_count, - }; - pub use self::x86_64::mm::paging::{BasePageSize, PageSize}; - #[cfg(feature = "common-os")] - pub use self::x86_64::mm::create_new_root_page_table; - #[cfg(feature = "common-os")] - pub use self::x86_64::kernel::{load_application, jump_to_user_land}; } target_arch = "riscv64" => { - pub(crate) mod riscv64; + mod riscv64; pub(crate) use self::riscv64::*; - - #[cfg(feature = "smp")] - pub(crate) use self::riscv64::kernel::application_processor_init; - #[cfg(feature = "pci")] - pub(crate) use self::riscv64::kernel::pci; - pub(crate) use self::riscv64::kernel::processor::{self, set_oneshot_timer, wakeup_core}; - pub(crate) use self::riscv64::kernel::serial::SerialDevice; - pub(crate) use self::riscv64::kernel::{ - boot_processor_init, - core_local, - get_processor_count, - interrupts, - scheduler, - switch, - }; - pub use self::riscv64::mm::paging::{BasePageSize, PageSize}; + } + target_arch = "x86_64" => { + mod x86_64; + pub(crate) use self::x86_64::*; } } diff --git a/src/arch/riscv64/kernel/mod.rs b/src/arch/riscv64/kernel/mod.rs index 891e11eaea..7a4077857c 100644 --- a/src/arch/riscv64/kernel/mod.rs +++ b/src/arch/riscv64/kernel/mod.rs @@ -19,6 +19,7 @@ use free_list::PageLayout; use memory_addresses::PhysAddr; use riscv::register::sstatus; +pub(crate) use self::processor::{set_oneshot_timer, wakeup_core}; use crate::arch::riscv64::kernel::core_local::core_id; pub use crate::arch::riscv64::kernel::devicetree::init_drivers; use crate::arch::riscv64::kernel::processor::lsb; @@ -107,10 +108,12 @@ pub fn boot_processor_init() { /// Application Processor initialization #[cfg(feature = "smp")] pub fn application_processor_init() { + use crate::arch::kernel::core_local::CoreLocal; + unsafe { super::mm::paging::enable_page_table(); } - crate::CoreLocal::install(); + CoreLocal::install(); interrupts::install(); finish_processor_init(); } diff --git a/src/arch/riscv64/kernel/scheduler.rs b/src/arch/riscv64/kernel/scheduler.rs index dac25973a8..e518276a43 100644 --- a/src/arch/riscv64/kernel/scheduler.rs +++ b/src/arch/riscv64/kernel/scheduler.rs @@ -7,7 +7,7 @@ use crate::arch::riscv64::mm::paging::{BasePageSize, PageSize, PageTableEntryFla use crate::mm::{FrameAlloc, PageAlloc, PageRangeAllocator}; use crate::scheduler::task::{Task, TaskFrame}; use crate::scheduler::{PerCoreSchedulerExt, timer_interrupts}; -use crate::{DEFAULT_STACK_SIZE, KERNEL_STACK_SIZE}; +use crate::config::{DEFAULT_STACK_SIZE, KERNEL_STACK_SIZE}; /// For details, see [RISC-V Calling Conventions]. /// diff --git a/src/arch/riscv64/kernel/start.rs b/src/arch/riscv64/kernel/start.rs index 137578efc4..0a80240462 100644 --- a/src/arch/riscv64/kernel/start.rs +++ b/src/arch/riscv64/kernel/start.rs @@ -8,7 +8,8 @@ use super::{CPU_ONLINE, CURRENT_BOOT_ID, HART_MASK, NUM_CPUS}; use crate::arch::riscv64::kernel::CURRENT_STACK_ADDRESS; #[cfg(not(feature = "smp"))] use crate::arch::riscv64::kernel::processor; -use crate::{KERNEL_STACK_SIZE, env}; +use crate::config::KERNEL_STACK_SIZE; +use crate::env; //static mut BOOT_STACK: [u8; KERNEL_STACK_SIZE] = [0; KERNEL_STACK_SIZE]; diff --git a/src/arch/x86_64/kernel/apic.rs b/src/arch/x86_64/kernel/apic.rs index b8d1b0bf4a..b0b07fa9f2 100644 --- a/src/arch/x86_64/kernel/apic.rs +++ b/src/arch/x86_64/kernel/apic.rs @@ -815,7 +815,7 @@ pub fn boot_application_processors() { init_next_processor_variables(); // Save the current number of initialized CPUs. - let current_processor_count = arch::get_processor_count(); + let current_processor_count = arch::kernel::get_processor_count(); // Send an INIT IPI. local_apic_write( @@ -844,7 +844,7 @@ pub fn boot_application_processors() { // Wait until the application processor has finished initializing. // It will indicate this by counting up cpu_online. - while current_processor_count == arch::get_processor_count() { + while current_processor_count == arch::kernel::get_processor_count() { spin_loop(); } } @@ -855,7 +855,7 @@ pub fn boot_application_processors() { #[cfg(feature = "smp")] pub fn ipi_tlb_flush() { - if arch::get_processor_count() > 1 { + if arch::kernel::get_processor_count() > 1 { let apic_ids = CPU_LOCAL_APIC_IDS.lock(); let core_id = core_id(); @@ -998,7 +998,7 @@ pub fn print_information() { "xAPIC" }; infoentry!("APIC in use", "{apic}"); - let processor_count = arch::get_processor_count(); + let processor_count = arch::kernel::get_processor_count(); infoentry!("Initialized CPUs", "{processor_count}"); infofooter!(); } diff --git a/src/arch/x86_64/kernel/kernel_stack.rs b/src/arch/x86_64/kernel/kernel_stack.rs index eb5f80e428..b1ac81b59c 100644 --- a/src/arch/x86_64/kernel/kernel_stack.rs +++ b/src/arch/x86_64/kernel/kernel_stack.rs @@ -1,6 +1,6 @@ use core::mem; -use crate::core_local::CoreLocal; +use crate::arch::kernel::core_local::CoreLocal; type Reg = mem::MaybeUninit; diff --git a/src/arch/x86_64/kernel/mod.rs b/src/arch/x86_64/kernel/mod.rs index b7adf3cda7..5f4b0ed625 100644 --- a/src/arch/x86_64/kernel/mod.rs +++ b/src/arch/x86_64/kernel/mod.rs @@ -9,6 +9,7 @@ use hermit_entry::boot_info::{PlatformInfo, RawBootInfo}; use memory_addresses::PhysAddr; use x86_64::registers::control::{Cr0, Cr4}; +pub(crate) use self::apic::{set_oneshot_timer, wakeup_core}; use crate::arch::x86_64::kernel::core_local::*; use crate::env::{self, is_uhyve}; diff --git a/src/arch/x86_64/kernel/pci.rs b/src/arch/x86_64/kernel/pci.rs index d17a1aad15..3dd1c0fc7f 100644 --- a/src/arch/x86_64/kernel/pci.rs +++ b/src/arch/x86_64/kernel/pci.rs @@ -130,10 +130,10 @@ mod pcie { use pci_types::{ConfigRegionAccess, PciAddress}; use super::PciConfigRegion; + use crate::arch::kernel::acpi; use crate::arch::mm::paging::{ self, LargePageSize, PageTableEntryFlags, PageTableEntryFlagsExt, }; - use crate::kernel::acpi; use crate::mm::device_alloc::DeviceAlloc; pub fn init_pcie() -> bool { diff --git a/src/arch/x86_64/kernel/start.rs b/src/arch/x86_64/kernel/start.rs index 269725e53f..c838638607 100644 --- a/src/arch/x86_64/kernel/start.rs +++ b/src/arch/x86_64/kernel/start.rs @@ -3,9 +3,9 @@ use core::arch::naked_asm; use hermit_entry::Entry; use hermit_entry::boot_info::RawBootInfo; -use crate::KERNEL_STACK_SIZE; -use crate::kernel::pre_init; -use crate::kernel::scheduler::TaskStacks; +use crate::config::KERNEL_STACK_SIZE; +use crate::arch::kernel::pre_init; +use crate::arch::kernel::scheduler::TaskStacks; #[unsafe(no_mangle)] #[unsafe(naked)] diff --git a/src/arch/x86_64/kernel/switch.rs b/src/arch/x86_64/kernel/switch.rs index 734d56a9ec..dc1675f03c 100644 --- a/src/arch/x86_64/kernel/switch.rs +++ b/src/arch/x86_64/kernel/switch.rs @@ -2,7 +2,7 @@ use core::arch::naked_asm; use x86_64::registers::control::Cr0Flags; -use crate::set_current_kernel_stack; +use crate::arch::kernel::gdt::set_current_kernel_stack; #[cfg(not(feature = "common-os"))] macro_rules! push_gs { diff --git a/src/common_os.rs b/src/common_os.rs new file mode 100644 index 0000000000..46e46274c1 --- /dev/null +++ b/src/common_os.rs @@ -0,0 +1 @@ +pub use crate::arch::kernel::{jump_to_user_land, load_application}; diff --git a/src/console/mod.rs b/src/console/mod.rs index b927d0d283..4b974d8d50 100644 --- a/src/console/mod.rs +++ b/src/console/mod.rs @@ -7,7 +7,7 @@ use embedded_io::{ErrorType, Read, ReadReady, Write}; use heapless::Vec; use hermit_sync::{InterruptTicketMutex, Lazy}; -use crate::arch::SerialDevice; +use crate::arch::kernel::serial::SerialDevice; #[cfg(feature = "virtio-console")] use crate::drivers::console::VirtioUART; use crate::errno::Errno; @@ -152,7 +152,9 @@ impl Write for Console { pub(crate) static CONSOLE_WAKER: InterruptTicketMutex = InterruptTicketMutex::new(WakerRegistration::new()); pub(crate) static CONSOLE: Lazy> = Lazy::new(|| { - crate::CoreLocal::install(); + use crate::arch::kernel::core_local::CoreLocal; + + CoreLocal::install(); #[cfg(feature = "uhyve")] if crate::env::is_uhyve() { diff --git a/src/drivers/console/mod.rs b/src/drivers/console/mod.rs index e94f592e72..d88cf8b391 100644 --- a/src/drivers/console/mod.rs +++ b/src/drivers/console/mod.rs @@ -24,7 +24,7 @@ use virtio::console::Config; use volatile::VolatileRef; use volatile::access::ReadOnly; -use crate::VIRTIO_MAX_QUEUE_SIZE; +use crate::config::{CONSOLE_PACKET_SIZE, VIRTIO_MAX_QUEUE_SIZE}; use crate::drivers::error::DriverError; #[cfg(not(feature = "pci"))] use crate::drivers::mmio::get_console_driver; @@ -124,7 +124,7 @@ impl RxQueue { Self { vq: None, - packet_size: crate::CONSOLE_PACKET_SIZE, + packet_size: CONSOLE_PACKET_SIZE, } } @@ -189,7 +189,7 @@ impl TxQueue { pub fn new() -> Self { Self { vq: None, - packet_length: crate::CONSOLE_PACKET_SIZE, + packet_length: CONSOLE_PACKET_SIZE, } } diff --git a/src/drivers/console/pci.rs b/src/drivers/console/pci.rs index c0422d77b3..640c474502 100644 --- a/src/drivers/console/pci.rs +++ b/src/drivers/console/pci.rs @@ -2,11 +2,11 @@ use pci_types::CommandRegister; use virtio::console::Config; use volatile::VolatileRef; +use crate::arch::kernel::pci::PciConfigRegion; use crate::drivers::console::{ConsoleDevCfg, RxQueue, TxQueue, VirtioConsoleDriver}; use crate::drivers::pci::PciDevice; use crate::drivers::virtio::error::{self, VirtioError}; use crate::drivers::virtio::transport::pci::{self, PciCap, UniCapsColl}; -use crate::pci::PciConfigRegion; // Backend-dependent interface for Virtio console driver impl VirtioConsoleDriver { diff --git a/src/drivers/fs/pci.rs b/src/drivers/fs/pci.rs index 63843609c2..98c5046644 100644 --- a/src/drivers/fs/pci.rs +++ b/src/drivers/fs/pci.rs @@ -2,7 +2,7 @@ use alloc::vec::Vec; use volatile::VolatileRef; -use crate::arch::pci::PciConfigRegion; +use crate::arch::kernel::pci::PciConfigRegion; use crate::drivers::fs::{FsDevCfg, VirtioFsDriver}; use crate::drivers::pci::PciDevice; use crate::drivers::virtio::error::{self, VirtioError}; diff --git a/src/drivers/mod.rs b/src/drivers/mod.rs index 90e925faae..ee74b0c634 100644 --- a/src/drivers/mod.rs +++ b/src/drivers/mod.rs @@ -78,12 +78,12 @@ pub(crate) fn init() { #[cfg(feature = "pci")] pci::init(); #[cfg(all(not(feature = "pci"), feature = "virtio", target_arch = "x86_64"))] - crate::arch::x86_64::kernel::mmio::init_drivers(); + crate::arch::kernel::mmio::init_drivers(); #[cfg(all(not(feature = "pci"), feature = "virtio", target_arch = "aarch64"))] - crate::arch::aarch64::kernel::mmio::init_drivers(); + crate::arch::kernel::mmio::init_drivers(); #[cfg(target_arch = "riscv64")] - crate::arch::riscv64::kernel::init_drivers(); + crate::arch::kernel::init_drivers(); - crate::arch::interrupts::install_handlers(); + crate::arch::kernel::interrupts::install_handlers(); } diff --git a/src/drivers/net/rtl8139.rs b/src/drivers/net/rtl8139.rs index f5976d8991..b8b483d13d 100644 --- a/src/drivers/net/rtl8139.rs +++ b/src/drivers/net/rtl8139.rs @@ -16,7 +16,7 @@ use volatile::access::{NoAccess, ReadOnly, ReadWrite}; use volatile::{VolatileFieldAccess, VolatilePtr, VolatileRef, map_field}; use crate::arch::kernel::interrupts::*; -use crate::arch::pci::PciConfigRegion; +use crate::arch::kernel::pci::PciConfigRegion; use crate::drivers::Driver; use crate::drivers::error::DriverError; use crate::drivers::net::{NetworkDriver, mtu}; diff --git a/src/drivers/net/virtio/pci.rs b/src/drivers/net/virtio/pci.rs index 104ab84060..83cf8a0094 100644 --- a/src/drivers/net/virtio/pci.rs +++ b/src/drivers/net/virtio/pci.rs @@ -3,7 +3,7 @@ use smoltcp::phy::ChecksumCapabilities; use volatile::VolatileRef; use super::{Init, Uninit}; -use crate::arch::pci::PciConfigRegion; +use crate::arch::kernel::pci::PciConfigRegion; use crate::drivers::net::virtio::{NetDevCfg, VirtioNetDriver}; use crate::drivers::pci::PciDevice; use crate::drivers::virtio::error::{self, VirtioError}; diff --git a/src/drivers/pci.rs b/src/drivers/pci.rs index 8b4cd34621..b131965ec6 100644 --- a/src/drivers/pci.rs +++ b/src/drivers/pci.rs @@ -19,7 +19,7 @@ use pci_types::{ InterruptPin, MAX_BARS, PciAddress, PciHeader, StatusRegister, VendorId, }; -use crate::arch::pci::PciConfigRegion; +use crate::arch::kernel::pci::PciConfigRegion; #[cfg(feature = "virtio-console")] use crate::console::IoDevice; #[cfg(feature = "virtio-console")] @@ -432,7 +432,7 @@ pub(crate) fn get_interrupt_handlers() -> HashMap { info!("Virtio console driver initialized."); - crate::arch::interrupts::add_irq_name(irq_no, "virtio"); + crate::arch::kernel::interrupts::add_irq_name(irq_no, "virtio"); info!("Virtio interrupt handler at line {irq_no}"); Ok(VirtioDriver::Console(alloc::boxed::Box::new( @@ -371,7 +371,7 @@ pub(crate) fn init_device( match VirtioFsDriver::init(dev_id, registers, irq_no) { Ok(virt_fs_drv) => { info!("Virtio filesystem driver initialized."); - crate::arch::interrupts::add_irq_name(irq_no, "virtio"); + crate::arch::kernel::interrupts::add_irq_name(irq_no, "virtio"); Ok(VirtioDriver::Fs(alloc::boxed::Box::new(virt_fs_drv))) } Err(virtio_error) => { @@ -385,7 +385,7 @@ pub(crate) fn init_device( Ok(virt_net_drv) => { info!("Virtio network driver initialized."); - crate::arch::interrupts::add_irq_name(irq_no, "virtio"); + crate::arch::kernel::interrupts::add_irq_name(irq_no, "virtio"); info!("Virtio interrupt handler at line {irq_no}"); Ok(VirtioDriver::Net(alloc::boxed::Box::new(virt_net_drv))) @@ -400,7 +400,7 @@ pub(crate) fn init_device( Ok(virt_vsock_drv) => { info!("Virtio sock driver initialized."); - crate::arch::interrupts::add_irq_name(irq_no, "virtio"); + crate::arch::kernel::interrupts::add_irq_name(irq_no, "virtio"); info!("Virtio interrupt handler at line {irq_no}"); Ok(VirtioDriver::Vsock(alloc::boxed::Box::new(virt_vsock_drv))) diff --git a/src/drivers/virtio/transport/pci.rs b/src/drivers/virtio/transport/pci.rs index bebfa11d48..661a68281e 100644 --- a/src/drivers/virtio/transport/pci.rs +++ b/src/drivers/virtio/transport/pci.rs @@ -18,7 +18,7 @@ use virtio::{DeviceStatus, le16, le32}; use volatile::access::ReadOnly; use volatile::{VolatilePtr, VolatileRef}; -use crate::arch::pci::PciConfigRegion; +use crate::arch::kernel::pci::PciConfigRegion; #[cfg(feature = "virtio-console")] use crate::drivers::console::VirtioConsoleDriver; use crate::drivers::error::DriverError; @@ -654,7 +654,7 @@ pub(crate) fn init_device( info!("Virtio console driver initialized."); let irq = device.get_irq().unwrap(); - crate::arch::interrupts::add_irq_name(irq, "virtio"); + crate::arch::kernel::interrupts::add_irq_name(irq, "virtio"); info!("Virtio interrupt handler at line {irq}"); Ok(VirtioDriver::Console(alloc::boxed::Box::new( @@ -674,7 +674,7 @@ pub(crate) fn init_device( Ok(virt_fs_drv) => { info!("Virtio filesystem driver initialized."); let irq = device.get_irq().unwrap(); - crate::arch::interrupts::add_irq_name(irq, "virtio"); + crate::arch::kernel::interrupts::add_irq_name(irq, "virtio"); Ok(VirtioDriver::Fs(alloc::boxed::Box::new(virt_fs_drv))) } Err(virtio_error) => { @@ -695,7 +695,7 @@ pub(crate) fn init_device( info!("Virtio network driver initialized."); let irq = device.get_irq().unwrap(); - crate::arch::interrupts::add_irq_name(irq, "virtio"); + crate::arch::kernel::interrupts::add_irq_name(irq, "virtio"); info!("Virtio interrupt handler at line {irq}"); Ok(VirtioDriver::Net(alloc::boxed::Box::new(virt_net_drv))) @@ -713,7 +713,7 @@ pub(crate) fn init_device( info!("Virtio sock driver initialized."); let irq = device.get_irq().unwrap(); - crate::arch::interrupts::add_irq_name(irq, "virtio"); + crate::arch::kernel::interrupts::add_irq_name(irq, "virtio"); info!("Virtio interrupt handler at line {irq}"); Ok(VirtioDriver::Vsock(alloc::boxed::Box::new(virt_sock_drv))) diff --git a/src/drivers/vsock/mod.rs b/src/drivers/vsock/mod.rs index c44f75ff81..1f331ce300 100644 --- a/src/drivers/vsock/mod.rs +++ b/src/drivers/vsock/mod.rs @@ -19,7 +19,7 @@ use volatile::VolatileRef; use volatile::access::ReadOnly; use super::virtio::virtqueue::VirtQueue; -use crate::config::VIRTIO_MAX_QUEUE_SIZE; +use crate::config::{VIRTIO_MAX_QUEUE_SIZE, VSOCK_PACKET_SIZE}; use crate::drivers::Driver; use crate::drivers::virtio::ControlRegisters; use crate::drivers::virtio::error::VirtioVsockError; @@ -72,7 +72,7 @@ impl RxQueue { Self { vq: None, - packet_size: crate::VSOCK_PACKET_SIZE, + packet_size: VSOCK_PACKET_SIZE, } } @@ -138,7 +138,7 @@ impl TxQueue { pub fn new() -> Self { Self { vq: None, - packet_length: crate::VSOCK_PACKET_SIZE + size_of::() as u32, + packet_length: VSOCK_PACKET_SIZE + size_of::() as u32, } } diff --git a/src/drivers/vsock/pci.rs b/src/drivers/vsock/pci.rs index 6b3c64c9ed..7b1ad9c33f 100644 --- a/src/drivers/vsock/pci.rs +++ b/src/drivers/vsock/pci.rs @@ -1,6 +1,6 @@ use volatile::VolatileRef; -use crate::arch::pci::PciConfigRegion; +use crate::arch::kernel::pci::PciConfigRegion; use crate::drivers::pci::PciDevice; use crate::drivers::virtio::error::{self, VirtioError}; use crate::drivers::virtio::transport::pci; diff --git a/src/executor/device.rs b/src/executor/device.rs index 958a3655f6..8d166d0627 100644 --- a/src/executor/device.rs +++ b/src/executor/device.rs @@ -14,7 +14,7 @@ use smoltcp::socket::dns; use smoltcp::wire::{EthernetAddress, HardwareAddress, IpCidr, Ipv4Address, Ipv4Cidr}; use super::network::{NetworkInterface, NetworkState}; -use crate::arch; +use crate::arch::kernel::systemtime; #[cfg(feature = "write-pcap-file")] use crate::drivers::Driver; use crate::drivers::net::NetworkDriver; @@ -80,7 +80,7 @@ impl<'a> NetworkInterface<'a> { // use the current time based on the wall-clock time as seed let mut config = Config::new(hardware_addr); - config.random_seed = (arch::kernel::systemtime::now_micros()) / 1_000_000; + config.random_seed = systemtime::now_micros() / 1_000_000; if capabilities.medium == Medium::Ethernet { config.hardware_addr = hardware_addr; } diff --git a/src/executor/mod.rs b/src/executor/mod.rs index 2642ec685d..44a3e1447f 100644 --- a/src/executor/mod.rs +++ b/src/executor/mod.rs @@ -18,7 +18,7 @@ use core::time::Duration; use crossbeam_utils::Backoff; use hermit_sync::without_interrupts; -use crate::arch::core_local; +use crate::arch::kernel::core_local; use crate::errno::Errno; use crate::executor::task::AsyncTask; use crate::io; diff --git a/src/executor/network.rs b/src/executor/network.rs index 2c4babc35b..faeec88816 100644 --- a/src/executor/network.rs +++ b/src/executor/network.rs @@ -22,7 +22,7 @@ use smoltcp::wire::{DnsQueryType, IpAddress}; #[cfg(feature = "dhcpv4")] use smoltcp::wire::{IpCidr, Ipv4Address, Ipv4Cidr}; -use crate::arch; +use crate::arch::kernel::systemtime; use crate::drivers::net::{NetworkDevice, NetworkDriver}; #[cfg(feature = "dns")] use crate::errno::Errno; @@ -123,7 +123,7 @@ fn start_endpoint() -> u16 { #[inline] pub(crate) fn now() -> Instant { - Instant::from_micros_const(arch::kernel::systemtime::now_micros().try_into().unwrap()) + Instant::from_micros_const(systemtime::now_micros().try_into().unwrap()) } #[cfg(feature = "dhcpv4")] diff --git a/src/fd/socket/tcp.rs b/src/fd/socket/tcp.rs index 671ab75e19..5f8cb826ee 100644 --- a/src/fd/socket/tcp.rs +++ b/src/fd/socket/tcp.rs @@ -10,12 +10,13 @@ use smoltcp::socket::tcp; use smoltcp::time::Duration; use smoltcp::wire::{IpEndpoint, Ipv4Address, Ipv6Address}; +use crate::config::DEFAULT_KEEP_ALIVE_INTERVAL; use crate::errno::Errno; use crate::executor::block_on; use crate::executor::network::{Handle, NIC, wake_network_waker}; use crate::fd::{self, Endpoint, Fd, ListenEndpoint, ObjectInterface, PollEvent, SocketOption}; +use crate::io; use crate::syscalls::socket::Af; -use crate::{DEFAULT_KEEP_ALIVE_INTERVAL, io}; /// Further receives will be disallowed pub const SHUT_RD: i32 = 0; diff --git a/src/lib.rs b/src/lib.rs index bb4ff1880e..d977e4a5ee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -95,11 +95,9 @@ use core::hint::spin_loop; #[cfg(feature = "smp")] use core::sync::atomic::{AtomicU32, Ordering}; -use arch::core_local::*; - -pub(crate) use crate::arch::*; -pub use crate::config::DEFAULT_STACK_SIZE; -pub(crate) use crate::config::*; +use self::arch::kernel; +use self::arch::kernel::core_local::{core_id, core_scheduler}; +use self::arch::kernel::interrupts; use crate::scheduler::{PerCoreScheduler, PerCoreSchedulerExt}; #[macro_use] @@ -109,7 +107,9 @@ mod macros; mod logging; pub mod arch; -mod config; +#[cfg(all(feature = "common-os", target_arch = "x86_64"))] +pub mod common_os; +pub mod config; pub mod console; mod drivers; mod entropy; @@ -232,6 +232,8 @@ fn synch_all_cores() { /// Entry Point of Hermit for the Boot Processor #[cfg(target_os = "none")] fn boot_processor_main() -> ! { + use crate::config::USER_STACK_SIZE; + // Initialize the kernel and hardware. mm::claim_initial_heap(); hermit_sync::Lazy::force(&console::CONSOLE); @@ -267,7 +269,7 @@ fn boot_processor_main() -> ! { info!("FDT:\n{fdt:#?}"); } - boot_processor_init(); + kernel::boot_processor_init(); #[cfg(not(target_arch = "riscv64"))] scheduler::add_current_core(); @@ -293,7 +295,7 @@ fn boot_processor_main() -> ! { /// Entry Point of Hermit for an Application Processor #[cfg(all(target_os = "none", feature = "smp"))] fn application_processor_main() -> ! { - application_processor_init(); + kernel::application_processor_init(); #[cfg(not(target_arch = "riscv64"))] scheduler::add_current_core(); interrupts::enable(); diff --git a/src/logging.rs b/src/logging.rs index 0d14d7de8d..34cadc4ec8 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -5,6 +5,8 @@ use core::time::Duration; use anstyle::AnsiColor; use log::{Level, LevelFilter, Metadata, Record}; +use crate::arch::kernel::{core_local, processor}; + pub static KERNEL_LOGGER: KernelLogger = KernelLogger::new(); /// Data structure to filter kernel messages @@ -44,9 +46,9 @@ impl log::Log for KernelLogger { let time = self .time() - .then(|| Duration::from_micros(crate::processor::get_timer_ticks())); + .then(|| Duration::from_micros(processor::get_timer_ticks())); let format_time = LogTime(time); - let core_id = crate::arch::core_local::core_id(); + let core_id = core_local::core_id(); let level = ColorLevel(record.level()); let target = record.target(); diff --git a/src/mm/mod.rs b/src/mm/mod.rs index 9c5ace4ac6..ffddc2ef89 100644 --- a/src/mm/mod.rs +++ b/src/mm/mod.rs @@ -140,8 +140,8 @@ pub(crate) fn init() { * BasePageSize::SIZE as usize + 2 * LargePageSize::SIZE as usize; #[cfg(any(target_arch = "x86_64", target_arch = "riscv64"))] - let has_1gib_pages = arch::processor::supports_1gib_pages(); - let has_2mib_pages = arch::processor::supports_2mib_pages(); + let has_1gib_pages = arch::kernel::processor::supports_1gib_pages(); + let has_2mib_pages = arch::kernel::processor::supports_2mib_pages(); let min_mem = if env::is_uefi() { // On UEFI, the given memory is guaranteed free memory and the kernel is located before the given memory diff --git a/src/scheduler/mod.rs b/src/scheduler/mod.rs index e665e82cab..2fb6fd1244 100644 --- a/src/scheduler/mod.rs +++ b/src/scheduler/mod.rs @@ -18,17 +18,18 @@ use hermit_sync::*; use riscv::register::sstatus; use timer_interrupts::TimerList; -use crate::arch::core_local::*; +use crate::arch::kernel; +use crate::arch::kernel::core_local::*; +use crate::arch::kernel::scheduler::TaskStacks; #[cfg(target_arch = "riscv64")] -use crate::arch::switch::switch_to_task; +use crate::arch::kernel::switch::switch_to_task; #[cfg(target_arch = "x86_64")] -use crate::arch::switch::{switch_to_fpu_owner, switch_to_task}; -use crate::arch::{get_processor_count, interrupts}; +use crate::arch::kernel::switch::{switch_to_fpu_owner, switch_to_task}; +use crate::arch::kernel::{get_processor_count, interrupts}; use crate::errno::Errno; use crate::fd::{Fd, RawFd}; -use crate::kernel::scheduler::TaskStacks; +use crate::io; use crate::scheduler::task::*; -use crate::{arch, io}; pub mod task; pub mod timer_interrupts; @@ -136,7 +137,7 @@ impl PerCoreSchedulerExt for &mut PerCoreScheduler { use arm_gic::IntId; use arm_gic::gicv3::{GicCpuInterface, SgiTarget, SgiTargetGroup}; - use crate::interrupts::SGI_RESCHED; + use crate::arch::kernel::interrupts::SGI_RESCHED; dsb(NSH); isb(SY); @@ -288,7 +289,7 @@ impl PerCoreScheduler { debug!("Creating task {tid} with priority {prio} on core {core_id}"); if wakeup { - arch::wakeup_core(core_id); + kernel::wakeup_core(core_id); } tid @@ -363,7 +364,7 @@ impl PerCoreScheduler { // Wake up the CPU if wakeup { - arch::wakeup_core(core_id); + kernel::wakeup_core(core_id); } tid @@ -411,7 +412,7 @@ impl PerCoreScheduler { .wakeup_tasks .push_back(task); // Wake up the CPU - arch::wakeup_core(task.get_core_id()); + kernel::wakeup_core(task.get_core_id()); } } diff --git a/src/scheduler/task/mod.rs b/src/scheduler/task/mod.rs index 2c0519a0b1..e5e1fe171d 100644 --- a/src/scheduler/task/mod.rs +++ b/src/scheduler/task/mod.rs @@ -19,9 +19,9 @@ use memory_addresses::VirtAddr; #[cfg(not(feature = "common-os"))] use self::tls::Tls; use super::timer_interrupts::{Source, create_timer_abs}; -use crate::arch; -use crate::arch::core_local::*; -use crate::arch::scheduler::TaskStacks; +use crate::arch::kernel::core_local::*; +use crate::arch::kernel::processor::{self, FPUState}; +use crate::arch::kernel::scheduler::TaskStacks; use crate::fd::{Fd, RawFd, stdio}; use crate::scheduler::CoreId; @@ -373,7 +373,7 @@ pub(crate) struct Task { /// Last stack pointer on the user stack before jumping to kernel space pub user_stack_pointer: VirtAddr, /// Last FPU state before a context switch to another task using the FPU - pub last_fpu_state: arch::processor::FPUState, + pub last_fpu_state: FPUState, /// ID of the core this task is running on pub core_id: CoreId, /// Stack of the task @@ -410,14 +410,14 @@ impl Task { prio: task_prio, last_stack_pointer: VirtAddr::zero(), user_stack_pointer: VirtAddr::zero(), - last_fpu_state: arch::processor::FPUState::new(), + last_fpu_state: FPUState::new(), core_id, stacks, object_map, #[cfg(not(feature = "common-os"))] tls: None, #[cfg(all(target_arch = "x86_64", feature = "common-os"))] - root_page_table: arch::create_new_root_page_table(), + root_page_table: crate::arch::mm::create_new_root_page_table(), } } @@ -458,7 +458,7 @@ impl Task { prio: IDLE_PRIO, last_stack_pointer: VirtAddr::zero(), user_stack_pointer: VirtAddr::zero(), - last_fpu_state: arch::processor::FPUState::new(), + last_fpu_state: FPUState::new(), core_id, stacks: TaskStacks::from_boot_stacks(), object_map: OBJECT_MAP.get().unwrap().clone(), @@ -602,7 +602,7 @@ impl BlockedTaskQueue { /// at least one task has elapsed. pub fn handle_waiting_tasks(&mut self, ready_queue: &mut PriorityTaskQueue) { // Get the current time. - let time = arch::processor::get_timer_ticks(); + let time = processor::get_timer_ticks(); // Get the wakeup time of this task and check if we have reached the first task // that hasn't elapsed yet or waits indefinitely. diff --git a/src/scheduler/task/tls.rs b/src/scheduler/task/tls.rs index 1b093fe693..ccc953270b 100644 --- a/src/scheduler/task/tls.rs +++ b/src/scheduler/task/tls.rs @@ -162,7 +162,7 @@ impl Tls { } } target_arch = "x86_64" => { - use crate::arch::x86_64::kernel::processor; + use crate::arch::kernel::processor; let addr = self.thread_ptr().expose_provenance(); processor::writefs(addr); diff --git a/src/scheduler/timer_interrupts.rs b/src/scheduler/timer_interrupts.rs index e4c130a892..db1469e89c 100644 --- a/src/scheduler/timer_interrupts.rs +++ b/src/scheduler/timer_interrupts.rs @@ -1,9 +1,9 @@ use core::mem; -use crate::core_local::core_scheduler; +use crate::arch::kernel::core_local::core_scheduler; +use crate::arch::kernel::set_oneshot_timer; #[cfg(feature = "net")] use crate::executor::network::wake_network_waker; -use crate::set_oneshot_timer; /// A possible timer interrupt source (i.e. reason the timer interrupt was set /// up). @@ -93,7 +93,7 @@ pub fn create_timer(source: Source, wakeup_micros: u64) { create_timer_abs( source, // get_timer_ticks should always return a nonzero value - crate::arch::processor::get_timer_ticks() + wakeup_micros, + crate::arch::kernel::processor::get_timer_ticks() + wakeup_micros, ); } @@ -137,7 +137,7 @@ pub fn clear_active_and_set_next() { // Either way, this means that QEMU *thinks* the time has passed, so it // probably has and knows better than we do. // We can cheat a bit and adjust all timers slightly based on this - let timer_ticks = crate::arch::processor::get_timer_ticks(); + let timer_ticks = crate::arch::kernel::processor::get_timer_ticks(); if prev_wakeup_time > timer_ticks { let offset = prev_wakeup_time - timer_ticks; timers.adjust_by(offset); diff --git a/src/synch/recmutex.rs b/src/synch/recmutex.rs index 434e6eab57..b9c4cf7b28 100644 --- a/src/synch/recmutex.rs +++ b/src/synch/recmutex.rs @@ -1,6 +1,6 @@ use hermit_sync::TicketMutex; -use crate::arch::core_local::*; +use crate::arch::kernel::core_local::*; use crate::scheduler::PerCoreSchedulerExt; use crate::scheduler::task::{TaskHandlePriorityQueue, TaskId}; diff --git a/src/synch/semaphore.rs b/src/synch/semaphore.rs index 69fcab4b2c..18e07ed657 100644 --- a/src/synch/semaphore.rs +++ b/src/synch/semaphore.rs @@ -2,7 +2,7 @@ use crossbeam_utils::Backoff; use hermit_sync::InterruptTicketMutex; -use crate::arch::core_local::*; +use crate::arch::kernel::core_local::*; use crate::scheduler::PerCoreSchedulerExt; use crate::scheduler::task::TaskHandlePriorityQueue; @@ -70,7 +70,8 @@ impl Semaphore { let backoff = Backoff::new(); let core_scheduler = core_scheduler(); - let wakeup_time = time.map(|ms| crate::arch::processor::get_timer_ticks() + ms * 1000); + let wakeup_time = + time.map(|ms| crate::arch::kernel::processor::get_timer_ticks() + ms * 1000); // Loop until we have acquired the semaphore. loop { @@ -81,7 +82,7 @@ impl Semaphore { locked_state.count -= 1; return true; } else if let Some(t) = wakeup_time - && t < crate::arch::processor::get_timer_ticks() + && t < crate::arch::kernel::processor::get_timer_ticks() { // We could not acquire the semaphore and we were woken up because the wakeup time has elapsed. // Don't try again and return the failure status. diff --git a/src/syscalls/entropy.rs b/src/syscalls/entropy.rs index 4c2a06b2dc..4a9c1d9ad7 100644 --- a/src/syscalls/entropy.rs +++ b/src/syscalls/entropy.rs @@ -2,7 +2,7 @@ use core::slice; use hermit_sync::TicketMutex; -use crate::arch; +use crate::arch::kernel::processor; use crate::entropy::{self, Flags}; use crate::errno::Errno; @@ -115,7 +115,7 @@ pub extern "C" fn sys_srand(seed: u32) { } pub(crate) fn init_entropy() { - let seed: u32 = arch::processor::get_timestamp() as u32; + let seed: u32 = processor::get_timestamp() as u32; *PARK_MILLER_LEHMER_SEED.lock() = seed; } diff --git a/src/syscalls/mman.rs b/src/syscalls/mman.rs index 9c8156ab8f..6fd7d2982e 100644 --- a/src/syscalls/mman.rs +++ b/src/syscalls/mman.rs @@ -13,10 +13,9 @@ use free_list::{FreeList, PageLayout, PageRange}; use hermit_sync::SpinMutex; use memory_addresses::{PhysAddr, VirtAddr}; -use crate::arch; #[cfg(target_arch = "x86_64")] use crate::arch::mm::paging::PageTableEntryFlagsExt; -use crate::arch::mm::paging::{BasePageSize, PageSize, PageTableEntryFlags}; +use crate::arch::mm::paging::{self, BasePageSize, PageSize, PageTableEntryFlags}; use crate::mm::{FrameAlloc, PageAlloc, PageRangeAllocator}; bitflags! { @@ -67,7 +66,7 @@ pub extern "C" fn sys_mmap(size: usize, prot_flags: MemoryProtection, ret: &mut flags.execute_disable(); } - arch::mm::paging::map::(virtual_address, physical_address, count, flags); + paging::map::(virtual_address, physical_address, count, flags); *ret = virtual_address.as_mut_ptr(); @@ -86,11 +85,8 @@ pub extern "C" fn sys_munmap(ptr: *mut u8, size: usize) -> i32 { return 0; } - if let Some(physical_address) = arch::mm::paging::virtual_to_physical(virtual_address) { - arch::mm::paging::unmap::( - virtual_address, - size / BasePageSize::SIZE as usize, - ); + if let Some(physical_address) = paging::virtual_to_physical(virtual_address) { + paging::unmap::(virtual_address, size / BasePageSize::SIZE as usize); debug!("Unmapping {virtual_address:X} ({size}) -> {physical_address:X}"); let frame_range = @@ -127,14 +123,14 @@ pub extern "C" fn sys_mprotect(ptr: *mut u8, size: usize, prot_flags: MemoryProt let virtual_address = VirtAddr::from_ptr(ptr); debug!("Mprotect {virtual_address:X} ({size}) -> {prot_flags:?})"); - if let Some(physical_address) = arch::mm::paging::virtual_to_physical(virtual_address) { - arch::mm::paging::map::(virtual_address, physical_address, count, flags); + if let Some(physical_address) = paging::virtual_to_physical(virtual_address) { + paging::map::(virtual_address, physical_address, count, flags); 0 } else { let frame_layout = PageLayout::from_size(size).unwrap(); let frame_range = FrameAlloc::allocate(frame_layout).unwrap(); let physical_address = PhysAddr::from(frame_range.start()); - arch::mm::paging::map::(virtual_address, physical_address, count, flags); + paging::map::(virtual_address, physical_address, count, flags); 0 } } diff --git a/src/syscalls/mod.rs b/src/syscalls/mod.rs index 34decdb462..f9a5e288b9 100644 --- a/src/syscalls/mod.rs +++ b/src/syscalls/mod.rs @@ -272,7 +272,7 @@ pub(crate) fn shutdown(arg: i32) -> ! { // This is a stable message used for detecting exit codes for different hypervisors. panic_println!("exit status {arg}"); - crate::arch::processor::shutdown(arg) + crate::arch::kernel::processor::shutdown(arg) } #[hermit_macro::system(errno)] diff --git a/src/syscalls/processor.rs b/src/syscalls/processor.rs index a18b3b532d..53bc41ec60 100644 --- a/src/syscalls/processor.rs +++ b/src/syscalls/processor.rs @@ -1,4 +1,4 @@ -use crate::arch::get_processor_count; +use crate::arch::kernel::get_processor_count; /// Returns the number of processors currently online. #[hermit_macro::system] @@ -17,5 +17,5 @@ pub extern "C" fn sys_available_parallelism() -> usize { #[hermit_macro::system] #[unsafe(no_mangle)] pub extern "C" fn sys_get_processor_frequency() -> u16 { - crate::arch::processor::get_frequency() + crate::arch::kernel::processor::get_frequency() } diff --git a/src/syscalls/tasks.rs b/src/syscalls/tasks.rs index 3594781594..bd2d31e73f 100644 --- a/src/syscalls/tasks.rs +++ b/src/syscalls/tasks.rs @@ -2,8 +2,8 @@ use alloc::collections::BTreeMap; use hermit_sync::InterruptTicketMutex; -use crate::arch::core_local::*; -use crate::arch::processor::{get_frequency, get_timestamp}; +use crate::arch::kernel::core_local::*; +use crate::arch::kernel::processor::{get_frequency, get_timestamp}; use crate::config::USER_STACK_SIZE; use crate::errno::Errno; use crate::scheduler::PerCoreSchedulerExt; @@ -69,7 +69,7 @@ pub(super) fn usleep(usecs: u64) { if usecs >= 10_000 { // Enough time to set a wakeup timer and block the current task. debug!("sys_usleep blocking the task for {usecs} microseconds"); - let wakeup_time = arch::processor::get_timer_ticks() + usecs; + let wakeup_time = arch::kernel::processor::get_timer_ticks() + usecs; let core_scheduler = core_scheduler(); core_scheduler.block_current_task(Some(wakeup_time)); @@ -202,7 +202,7 @@ static BLOCKED_TASKS: InterruptTicketMutex> = InterruptTicketMutex::new(BTreeMap::new()); fn block_current_task(timeout: Option) { - let wakeup_time = timeout.map(|t| arch::processor::get_timer_ticks() + t * 1000); + let wakeup_time = timeout.map(|t| arch::kernel::processor::get_timer_ticks() + t * 1000); let core_scheduler = core_scheduler(); let handle = core_scheduler.get_current_task_handle(); let tid = core_scheduler.get_current_task_id(); diff --git a/src/syscalls/timer.rs b/src/syscalls/timer.rs index 81eab5f4f7..3cc92dc50c 100644 --- a/src/syscalls/timer.rs +++ b/src/syscalls/timer.rs @@ -1,4 +1,4 @@ -use crate::arch; +use crate::arch::kernel::{processor, systemtime}; use crate::errno::Errno; use crate::syscalls::usleep; use crate::time::{itimerval, timespec, timeval}; @@ -63,11 +63,11 @@ pub unsafe extern "C" fn sys_clock_gettime(clock_id: clockid_t, tp: *mut timespe match clock_id { CLOCK_REALTIME => { - *result = timespec::from_usec(arch::kernel::systemtime::now_micros() as i64); + *result = timespec::from_usec(systemtime::now_micros() as i64); 0 } CLOCK_MONOTONIC => { - *result = timespec::from_usec(arch::processor::get_timer_ticks() as i64); + *result = timespec::from_usec(processor::get_timer_ticks() as i64); 0 } _ => { @@ -111,9 +111,9 @@ pub unsafe extern "C" fn sys_clock_nanosleep( if flags & TIMER_ABSTIME > 0 { if clock_id == CLOCK_REALTIME { - microseconds -= arch::kernel::systemtime::now_micros(); + microseconds -= systemtime::now_micros(); } else { - microseconds -= arch::processor::get_timer_ticks(); + microseconds -= processor::get_timer_ticks(); } } @@ -144,7 +144,7 @@ pub unsafe extern "C" fn sys_gettimeofday(tp: *mut timeval, tz: usize) -> i32 { if let Some(result) = unsafe { tp.as_mut() } { // Return the current time based on the wallclock time when we were booted up // plus the current timer ticks. - let microseconds = arch::kernel::systemtime::now_micros(); + let microseconds = systemtime::now_micros(); *result = timeval::from_usec(microseconds as i64); } diff --git a/src/time.rs b/src/time.rs index 496a00ca8e..87fac6b34a 100644 --- a/src/time.rs +++ b/src/time.rs @@ -1,6 +1,6 @@ use core::time::Duration; -use crate::arch; +use crate::arch::kernel::systemtime; #[allow(non_camel_case_types)] pub type time_t = i64; @@ -80,9 +80,7 @@ impl SystemTime { /// Returns the system time corresponding to "now". pub fn now() -> Self { - Self(timespec::from_usec( - arch::kernel::systemtime::now_micros() as i64 - )) + Self(timespec::from_usec(systemtime::now_micros() as i64)) } /// Returns the amount of time elapsed from an earlier point in time. diff --git a/src/uhyve.rs b/src/uhyve.rs index ceee082b45..3504f90413 100644 --- a/src/uhyve.rs +++ b/src/uhyve.rs @@ -5,7 +5,7 @@ use uhyve_interface::GuestPhysAddr; use uhyve_interface::v2::parameters::SerialWriteBufferParams; use uhyve_interface::v2::{Hypercall, HypercallAddress}; -use crate::arch; +use crate::arch::kernel::processor; use crate::arch::mm::paging::virtual_to_physical; #[cfg(target_os = "none")] @@ -93,6 +93,6 @@ pub(crate) fn uhyve_hypercall(hypercall: Hypercall<'_>) { pub fn shutdown(error_code: i32) -> ! { uhyve_hypercall(Hypercall::Exit(error_code)); loop { - arch::processor::halt(); + processor::halt(); } }