Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
6456b78
feat: export load_application, jump_to_user_land from common_os instead
mkroening Jun 17, 2026
5ab109d
feat: export DEFAULT_STACK_SIZE from config instead of from crate root
mkroening Jun 17, 2026
2ed8e68
refactor: don't import core-locals from crate root
mkroening Jun 17, 2026
ad5e586
refactor: don't import arch items from crate root
mkroening Jun 17, 2026
e2bc75b
refactor: don't import config items from crate root
mkroening Jun 17, 2026
5c3706c
refactor: don't import arch module
mkroening Jun 17, 2026
f90257e
refactor: don't import pci from arch
mkroening Jun 17, 2026
46fa48d
refactor: don't import SerialDevice from arch
mkroening Jun 17, 2026
fcc0632
refactor: don't import core_local from arch
mkroening Jun 17, 2026
fe7814c
refactor: don't import processor from arch
mkroening Jun 17, 2026
450a701
refactor: don't import interrupts from arch
mkroening Jun 17, 2026
a07aa7f
refactor: don't import processor_init from arch
mkroening Jun 17, 2026
e1e4ab9
refactor: don't import scheduler from arch
mkroening Jun 17, 2026
82353b7
refactor: don't import get_processor_count from arch
mkroening Jun 17, 2026
a90cb70
refactor: don't export page size from arch
mkroening Jun 17, 2026
c49e3f8
refactor: don't export switch from arch
mkroening Jun 17, 2026
4d0a699
refactor: don't export create_new_root_page_table from arch
mkroening Jun 17, 2026
c08a486
refactor: don't export wakeup_core, set_oneshot_timer from arch
mkroening Jun 17, 2026
34a94ad
refactor: don't export arch modules
mkroening Jun 17, 2026
f88d984
style(arch): sort cfgs
mkroening Jun 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/arch/aarch64/kernel/interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/arch/aarch64/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/arch/aarch64/kernel/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/arch/aarch64/kernel/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
5 changes: 3 additions & 2 deletions src/arch/aarch64/kernel/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")]
Expand Down
2 changes: 2 additions & 0 deletions src/arch/aarch64/mm/paging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ bitflags! {
}

impl PageTableEntryFlags {
#[expect(dead_code)]
pub fn present(&mut self) -> &mut Self {
self.insert(PageTableEntryFlags::PRESENT);
self
Expand All @@ -102,6 +103,7 @@ impl PageTableEntryFlags {
self
}

#[expect(dead_code)]
pub fn read_only(&mut self) -> &mut Self {
self.insert(PageTableEntryFlags::READ_ONLY);
self
Expand Down
72 changes: 6 additions & 66 deletions src/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
}
}
5 changes: 4 additions & 1 deletion src/arch/riscv64/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/arch/riscv64/kernel/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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].
///
Expand Down
3 changes: 2 additions & 1 deletion src/arch/riscv64/kernel/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
8 changes: 4 additions & 4 deletions src/arch/x86_64/kernel/apic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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();

Expand Down Expand Up @@ -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!();
}
2 changes: 1 addition & 1 deletion src/arch/x86_64/kernel/kernel_stack.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::mem;

use crate::core_local::CoreLocal;
use crate::arch::kernel::core_local::CoreLocal;

type Reg = mem::MaybeUninit<usize>;

Expand Down
1 change: 1 addition & 0 deletions src/arch/x86_64/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
2 changes: 1 addition & 1 deletion src/arch/x86_64/kernel/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/arch/x86_64/kernel/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/arch/x86_64/kernel/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/common_os.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use crate::arch::kernel::{jump_to_user_land, load_application};
6 changes: 4 additions & 2 deletions src/console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -152,7 +152,9 @@ impl Write for Console {
pub(crate) static CONSOLE_WAKER: InterruptTicketMutex<WakerRegistration> =
InterruptTicketMutex::new(WakerRegistration::new());
pub(crate) static CONSOLE: Lazy<InterruptTicketMutex<Console>> = Lazy::new(|| {
crate::CoreLocal::install();
use crate::arch::kernel::core_local::CoreLocal;

CoreLocal::install();

#[cfg(feature = "uhyve")]
if crate::env::is_uhyve() {
Expand Down
6 changes: 3 additions & 3 deletions src/drivers/console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -124,7 +124,7 @@ impl RxQueue {
Self {
vq: None,

packet_size: crate::CONSOLE_PACKET_SIZE,
packet_size: CONSOLE_PACKET_SIZE,
}
}

Expand Down Expand Up @@ -189,7 +189,7 @@ impl TxQueue {
pub fn new() -> Self {
Self {
vq: None,
packet_length: crate::CONSOLE_PACKET_SIZE,
packet_length: CONSOLE_PACKET_SIZE,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/drivers/console/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/fs/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
8 changes: 4 additions & 4 deletions src/drivers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Loading
Loading