Skip to content

Commit

Permalink
kernel: add ListRegistry and the List handle type
Browse files Browse the repository at this point in the history
  • Loading branch information
Qix- committed Sep 14, 2024
1 parent 7492f4b commit d3818c1
Show file tree
Hide file tree
Showing 13 changed files with 548 additions and 446 deletions.
17 changes: 5 additions & 12 deletions oro-arch-aarch64/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@ use oro_sync::spinlock::unfair_critical::UnfairCriticalSpinlock;

/// The global kernel state. Initialized once during boot
/// and re-used across all cores.
pub static mut KERNEL_STATE: MaybeUninit<
KernelState<
crate::Pfa,
OffsetTranslator,
crate::mem::address_space::AddressSpaceLayout,
crate::sync::InterruptController,
>,
> = MaybeUninit::uninit();
pub static mut KERNEL_STATE: MaybeUninit<KernelState<crate::Arch>> = MaybeUninit::uninit();

/// Initializes the global state of the architecture.
///
Expand All @@ -39,10 +32,10 @@ pub unsafe fn initialize_primary(pat: OffsetTranslator, pfa: crate::Pfa) {
}
}

KERNEL_STATE.write(
KernelState::new(pat, UnfairCriticalSpinlock::new(pfa))
.expect("failed to create global kernel state"),
);
// SAFETY(qix-): We know what we're doing here.
#[expect(static_mut_refs)]
KernelState::init(&mut KERNEL_STATE, pat, UnfairCriticalSpinlock::new(pfa))
.expect("failed to create global kernel state");
}

/// Main boot sequence for all cores for each bringup
Expand Down
19 changes: 12 additions & 7 deletions oro-arch-aarch64/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,19 @@ pub const ELF_MACHINE: ElfMachine = ElfMachine::Aarch64;
/// by the architecture.
pub(crate) type Pfa = FiloPageFrameAllocator<OffsetTranslator>;

/// Zero-sized type for specifying the architecture-specific types
/// used throughout the `oro-kernel` crate.
pub(crate) struct Arch;

impl oro_kernel::Arch for Arch {
type AddrSpace = crate::mem::address_space::AddressSpaceLayout;
type IntCtrl = crate::sync::InterruptController;
type Pat = OffsetTranslator;
type Pfa = Pfa;
}

/// Type alias for the Oro kernel core-local instance type.
pub(crate) type Kernel = oro_kernel::Kernel<
CoreState,
Pfa,
OffsetTranslator,
crate::mem::address_space::AddressSpaceLayout,
crate::sync::InterruptController,
>;
pub(crate) type Kernel = oro_kernel::Kernel<CoreState, Arch>;

/// Architecture-specific core-local state.
pub(crate) struct CoreState {
Expand Down
44 changes: 38 additions & 6 deletions oro-arch-aarch64/src/mem/address_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,45 @@ impl AddressSpaceLayout {
pub const BOOT_RESERVED_IDX: usize = 350;
/// The segment for the kernel core-local data.
pub const KERNEL_CORE_LOCAL_IDX: usize = 375;

/// The segment for the ring registry
pub const KERNEL_RING_REGISTRY_IDX: usize = 400;
/// The segment for the ring item registry
pub const KERNEL_RING_ITEM_REGISTRY_IDX: usize = 401;
/// The segment for the ring list registry
pub const KERNEL_RING_LIST_REGISTRY_IDX: usize = 402;

/// The segment for the module instance registry
pub const KERNEL_INSTANCE_REGISTRY_IDX: usize = 401;
pub const KERNEL_INSTANCE_REGISTRY_IDX: usize = 403;
/// The segment for the module instance item registry
pub const KERNEL_INSTANCE_ITEM_REGISTRY_IDX: usize = 402;
pub const KERNEL_INSTANCE_ITEM_REGISTRY_IDX: usize = 404;
/// The segment for the module instance list registry
pub const KERNEL_INSTANCE_LIST_REGISTRY_IDX: usize = 405;

/// The segment for the thread registry
pub const KERNEL_THREAD_REGISTRY_IDX: usize = 403;
pub const KERNEL_THREAD_REGISTRY_IDX: usize = 406;
/// The segment for the thread item registry
pub const KERNEL_THREAD_ITEM_REGISTRY_IDX: usize = 404;
pub const KERNEL_THREAD_ITEM_REGISTRY_IDX: usize = 407;
/// The segment for the thread list registry
pub const KERNEL_THREAD_LIST_REGISTRY_IDX: usize = 408;

/// The segment for the module registry
pub const KERNEL_MODULE_REGISTRY_IDX: usize = 405;
pub const KERNEL_MODULE_REGISTRY_IDX: usize = 409;
/// The segment for the module item registry
pub const KERNEL_MODULE_ITEM_REGISTRY_IDX: usize = 410;
/// The segment for the module list registry
pub const KERNEL_MODULE_LIST_REGISTRY_IDX: usize = 411;

/// The segment for the port registry
pub const KERNEL_PORT_REGISTRY_IDX: usize = 406;
pub const KERNEL_PORT_REGISTRY_IDX: usize = 412;
/// The segment for the port item registry
pub const KERNEL_PORT_ITEM_REGISTRY_IDX: usize = 413;
/// The segment for the port list registry
pub const KERNEL_PORT_LIST_REGISTRY_IDX: usize = 414;

/// The kernel executable range, shared by the RX, RO, and RW segments.
///
/// MUST BE 511.
pub const KERNEL_EXE_IDX: usize = 511;
}

Expand Down Expand Up @@ -322,12 +346,20 @@ unsafe impl AddressSpace for AddressSpaceLayout {

registries! {
kernel_ring_registry => KERNEL_RING_REGISTRY_IDX,
kernel_ring_item_registry => KERNEL_RING_ITEM_REGISTRY_IDX,
kernel_ring_list_registry => KERNEL_RING_LIST_REGISTRY_IDX,
kernel_instance_registry => KERNEL_INSTANCE_REGISTRY_IDX,
kernel_instance_item_registry => KERNEL_INSTANCE_ITEM_REGISTRY_IDX,
kernel_instance_list_registry => KERNEL_INSTANCE_LIST_REGISTRY_IDX,
kernel_port_registry => KERNEL_PORT_REGISTRY_IDX,
kernel_port_item_registry => KERNEL_PORT_ITEM_REGISTRY_IDX,
kernel_port_list_registry => KERNEL_PORT_LIST_REGISTRY_IDX,
kernel_thread_registry => KERNEL_THREAD_REGISTRY_IDX,
kernel_thread_item_registry => KERNEL_THREAD_ITEM_REGISTRY_IDX,
kernel_thread_list_registry => KERNEL_THREAD_LIST_REGISTRY_IDX,
kernel_module_registry => KERNEL_MODULE_REGISTRY_IDX,
kernel_module_item_registry => KERNEL_MODULE_ITEM_REGISTRY_IDX,
kernel_module_list_registry => KERNEL_MODULE_LIST_REGISTRY_IDX,
}

unsafe fn current_supervisor_space<P>(_translator: &P) -> Self::SupervisorHandle
Expand Down
17 changes: 5 additions & 12 deletions oro-arch-x86_64/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@ use oro_sync::spinlock::unfair_critical::UnfairCriticalSpinlock;

/// The global kernel state. Initialized once during boot
/// and re-used across all cores.
pub static mut KERNEL_STATE: MaybeUninit<
KernelState<
crate::Pfa,
OffsetTranslator,
crate::mem::address_space::AddressSpaceLayout,
crate::sync::InterruptController,
>,
> = MaybeUninit::uninit();
pub static mut KERNEL_STATE: MaybeUninit<KernelState<crate::Arch>> = MaybeUninit::uninit();

/// Initializes the global state of the architecture.
///
Expand All @@ -41,10 +34,10 @@ pub unsafe fn initialize_primary(pat: OffsetTranslator, pfa: crate::Pfa) {
}
}

KERNEL_STATE.write(
KernelState::new(pat, UnfairCriticalSpinlock::new(pfa))
.expect("failed to create global kernel state"),
);
// SAFETY(qix-): We know what we're doing here.
#[expect(static_mut_refs)]
KernelState::init(&mut KERNEL_STATE, pat, UnfairCriticalSpinlock::new(pfa))
.expect("failed to create global kernel state");
}

/// Main boot sequence for all cores for each bringup
Expand Down
19 changes: 12 additions & 7 deletions oro-arch-x86_64/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,19 @@ pub const ELF_MACHINE: ElfMachine = ElfMachine::X86_64;
/// by the architecture.
pub(crate) type Pfa = FiloPageFrameAllocator<OffsetTranslator>;

/// Zero-sized type for specifying the architecture-specific types
/// used throughout the `oro-kernel` crate.
pub(crate) struct Arch;

impl oro_kernel::Arch for Arch {
type AddrSpace = crate::mem::address_space::AddressSpaceLayout;
type IntCtrl = crate::sync::InterruptController;
type Pat = OffsetTranslator;
type Pfa = Pfa;
}

/// Type alias for the Oro kernel core-local instance type.
pub(crate) type Kernel = oro_kernel::Kernel<
CoreState,
Pfa,
OffsetTranslator,
crate::mem::address_space::AddressSpaceLayout,
crate::sync::InterruptController,
>;
pub(crate) type Kernel = oro_kernel::Kernel<CoreState, Arch>;

/// Architecture-specific core-local state.
pub(crate) struct CoreState {
Expand Down
44 changes: 38 additions & 6 deletions oro-arch-x86_64/src/mem/address_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,45 @@ impl AddressSpaceLayout {
pub const LINEAR_MAP_IDX: (usize, usize) = (259, 320);
/// The index for the kernel core-local segment.
pub const KERNEL_CORE_LOCAL_IDX: usize = 350;

/// The segment for the ring registry
pub const KERNEL_RING_REGISTRY_IDX: usize = 400;
/// The segment for the ring item registry
pub const KERNEL_RING_ITEM_REGISTRY_IDX: usize = 401;
/// The segment for the ring list registry
pub const KERNEL_RING_LIST_REGISTRY_IDX: usize = 402;

/// The segment for the module instance registry
pub const KERNEL_INSTANCE_REGISTRY_IDX: usize = 401;
pub const KERNEL_INSTANCE_REGISTRY_IDX: usize = 403;
/// The segment for the module instance item registry
pub const KERNEL_INSTANCE_ITEM_REGISTRY_IDX: usize = 402;
pub const KERNEL_INSTANCE_ITEM_REGISTRY_IDX: usize = 404;
/// The segment for the module instance list registry
pub const KERNEL_INSTANCE_LIST_REGISTRY_IDX: usize = 405;

/// The segment for the thread registry
pub const KERNEL_THREAD_REGISTRY_IDX: usize = 403;
pub const KERNEL_THREAD_REGISTRY_IDX: usize = 406;
/// The segment for the thread item registry
pub const KERNEL_THREAD_ITEM_REGISTRY_IDX: usize = 404;
pub const KERNEL_THREAD_ITEM_REGISTRY_IDX: usize = 407;
/// The segment for the thread list registry
pub const KERNEL_THREAD_LIST_REGISTRY_IDX: usize = 408;

/// The segment for the module registry
pub const KERNEL_MODULE_REGISTRY_IDX: usize = 405;
pub const KERNEL_MODULE_REGISTRY_IDX: usize = 409;
/// The segment for the module item registry
pub const KERNEL_MODULE_ITEM_REGISTRY_IDX: usize = 410;
/// The segment for the module list registry
pub const KERNEL_MODULE_LIST_REGISTRY_IDX: usize = 411;

/// The segment for the port registry
pub const KERNEL_PORT_REGISTRY_IDX: usize = 406;
pub const KERNEL_PORT_REGISTRY_IDX: usize = 412;
/// The segment for the port item registry
pub const KERNEL_PORT_ITEM_REGISTRY_IDX: usize = 413;
/// The segment for the port list registry
pub const KERNEL_PORT_LIST_REGISTRY_IDX: usize = 414;

/// The kernel executable range, shared by the RX, RO, and RW segments.
///
/// MUST BE 511.
pub const KERNEL_EXE_IDX: usize = 511;
}

Expand Down Expand Up @@ -199,12 +223,20 @@ unsafe impl AddressSpace for AddressSpaceLayout {

registries! {
kernel_ring_registry => KERNEL_RING_REGISTRY_IDX,
kernel_ring_item_registry => KERNEL_RING_ITEM_REGISTRY_IDX,
kernel_ring_list_registry => KERNEL_RING_LIST_REGISTRY_IDX,
kernel_instance_registry => KERNEL_INSTANCE_REGISTRY_IDX,
kernel_instance_item_registry => KERNEL_INSTANCE_ITEM_REGISTRY_IDX,
kernel_instance_list_registry => KERNEL_INSTANCE_LIST_REGISTRY_IDX,
kernel_port_registry => KERNEL_PORT_REGISTRY_IDX,
kernel_port_item_registry => KERNEL_PORT_ITEM_REGISTRY_IDX,
kernel_port_list_registry => KERNEL_PORT_LIST_REGISTRY_IDX,
kernel_thread_registry => KERNEL_THREAD_REGISTRY_IDX,
kernel_thread_item_registry => KERNEL_THREAD_ITEM_REGISTRY_IDX,
kernel_thread_list_registry => KERNEL_THREAD_LIST_REGISTRY_IDX,
kernel_module_registry => KERNEL_MODULE_REGISTRY_IDX,
kernel_module_item_registry => KERNEL_MODULE_ITEM_REGISTRY_IDX,
kernel_module_list_registry => KERNEL_MODULE_LIST_REGISTRY_IDX,
}

unsafe fn current_supervisor_space<P>(_translator: &P) -> Self::SupervisorHandle
Expand Down
37 changes: 21 additions & 16 deletions oro-kernel/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
use crate::{
module::Module,
registry::{Handle, Item, ItemIterEx},
port::Port,
registry::{Handle, List},
ring::Ring,
thread::Thread,
Arch,
};
use oro_mem::mapper::AddressSpace;
use oro_sync::spinlock::unfair_critical::InterruptController;

/// A singular module instance.
///
Expand Down Expand Up @@ -38,18 +38,20 @@ use oro_sync::spinlock::unfair_critical::InterruptController;
/// to interact with the kernel directly via the built-in modules, and
/// from there can spawn additional rings and instances as needed to
/// bootstrap the rest of the system as they see fit.
pub struct Instance<AddrSpace: AddressSpace> {
pub struct Instance<A: Arch> {
/// The module instance ID.
pub(crate) id: usize,
pub(crate) id: usize,
/// The module from which this instance was spawned.
pub(crate) module: Handle<Module>,
pub(crate) module: Handle<Module>,
/// The ring on which this instance resides.
pub(crate) ring: Handle<Ring<AddrSpace>>,
/// The root thread item of the instance.
pub(crate) root_thread: Option<Handle<Item<Thread<AddrSpace>>>>,
pub(crate) ring: Handle<Ring<A>>,
/// The thread list for the instance.
pub(crate) threads: Handle<List<Thread<A>, A>>,
/// The port list for the instance.
pub(crate) ports: Handle<List<Port, A>>,
}

impl<AddrSpace: AddressSpace> Instance<AddrSpace> {
impl<A: Arch> Instance<A> {
/// Returns the instance ID.
///
/// # Safety
Expand All @@ -70,14 +72,17 @@ impl<AddrSpace: AddressSpace> Instance<AddrSpace> {
}

/// The [`Handle`] to the ring on which this instance resides.
pub fn ring(&self) -> Handle<Ring<AddrSpace>> {
pub fn ring(&self) -> Handle<Ring<A>> {
self.ring.clone()
}

/// Gets an iterator over all threads in this instance.
pub fn threads<IntCtrl: InterruptController>(
&self,
) -> impl Iterator<Item = Handle<Item<Thread<AddrSpace>>>> {
self.root_thread.iter_all::<IntCtrl>()
/// Gets a handle to the list of threads for this instance.
pub fn threads(&self) -> Handle<List<Thread<A>, A>> {
self.threads.clone()
}

/// Gets a handle to the list of ports for this instance.
pub fn ports(&self) -> Handle<List<Port, A>> {
self.ports.clone()
}
}
Loading

0 comments on commit d3818c1

Please sign in to comment.