yggdrasil/src/main.rs

103 lines
2.1 KiB
Rust

//! osdev-x kernel crate
#![feature(
step_trait,
decl_macro,
naked_functions,
asm_const,
panic_info_message,
optimize_attribute,
const_trait_impl,
maybe_uninit_slice,
arbitrary_self_types,
const_mut_refs,
let_chains,
linked_list_cursors,
rustc_private,
allocator_api,
async_fn_in_trait,
strict_provenance
)]
#![allow(clippy::new_without_default, clippy::fn_to_numeric_cast)]
// #![warn(missing_docs)]
#![allow(missing_docs)]
#![no_std]
#![no_main]
use arch::Architecture;
use crate::{
arch::{ArchitectureImpl, ARCHITECTURE},
mem::heap,
sync::SpinFence,
task::{spawn_kernel_closure, Cpu},
};
extern crate yggdrasil_abi as abi;
extern crate alloc;
extern crate compiler_builtins;
#[macro_use]
pub mod debug;
#[macro_use]
pub mod arch;
pub mod device;
pub mod fs;
pub mod init;
pub mod mem;
pub mod panic;
pub mod proc;
pub mod sync;
pub mod syscall;
pub mod task;
pub mod util;
static CPU_INIT_FENCE: SpinFence = SpinFence::new();
/// Common kernel main function for application processors
pub fn kernel_secondary_main() -> ! {
// Synchronize the CPUs to this point
CPU_INIT_FENCE.signal();
CPU_INIT_FENCE.wait_all(ArchitectureImpl::cpu_count());
unsafe {
task::enter();
}
}
/// Common kernel main function. Must be called for BSP processor only.
///
/// # Prerequisites
///
/// Before the function can be called, the following preparations must be made:
///
/// * Virtual memory set up according to the architecture's memory map
/// * Physical memory
/// * Heap
/// * Basic debugging facilities
/// * Initrd
pub fn kernel_main() -> ! {
debugln!("Heap: {:#x?}", heap::heap_range());
unsafe {
ARCHITECTURE.start_application_processors();
}
Cpu::init_ipi_queues();
// Wait until all APs initialize
CPU_INIT_FENCE.signal();
CPU_INIT_FENCE.wait_all(ArchitectureImpl::cpu_count());
task::init().expect("Failed to initialize the scheduler");
spawn_kernel_closure("[kinit]", init::kinit).expect("Could not spawn [kinit]");
infoln!("All cpus ready");
unsafe {
task::enter();
}
}