yggdrasil/src/main.rs

98 lines
2.0 KiB
Rust
Raw Normal View History

2023-07-18 18:03:45 +03:00
//! osdev-x kernel crate
#![feature(
naked_functions,
asm_const,
panic_info_message,
optimize_attribute,
const_trait_impl,
maybe_uninit_slice,
2023-07-25 16:47:00 +03:00
arbitrary_self_types,
2023-07-28 14:26:39 +03:00
const_mut_refs,
let_chains,
linked_list_cursors,
2023-08-31 13:40:17 +03:00
rustc_private,
allocator_api
2023-07-18 18:03:45 +03:00
)]
2023-08-01 18:05:10 +03:00
#![allow(clippy::new_without_default, clippy::fn_to_numeric_cast)]
2023-07-18 18:03:45 +03:00
#![warn(missing_docs)]
#![no_std]
#![no_main]
use sync::SpinFence;
use task::spawn_kernel_closure;
use crate::{
arch::{Architecture, ArchitectureImpl, ARCHITECTURE},
mem::heap,
2023-08-31 13:40:17 +03:00
task::Cpu,
};
2023-07-29 19:31:56 +03:00
extern crate yggdrasil_abi as abi;
2023-08-02 20:43:21 +03:00
2023-07-30 16:40:30 +03:00
extern crate alloc;
extern crate compiler_builtins;
2023-07-29 19:31:56 +03:00
#[macro_use]
pub mod debug;
2023-07-18 18:03:45 +03:00
#[macro_use]
pub mod arch;
2023-07-29 21:11:15 +03:00
pub mod device;
pub mod fs;
pub mod init;
2023-07-29 19:31:56 +03:00
pub mod mem;
pub mod panic;
pub mod proc;
2023-07-29 19:31:56 +03:00
pub mod sync;
pub mod syscall;
2023-08-01 18:05:10 +03:00
pub mod task;
2023-08-31 19:54:09 +03:00
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();
}
2023-08-31 13:40:17 +03:00
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();
}
}