osiris/
lib.rs

1//! This is the default kernel of the osiris operating system.
2//! The kernel is organized as a microkernel.
3
4#![cfg_attr(freestanding, no_std)]
5
6#[macro_use]
7mod macros;
8#[macro_use]
9mod error;
10mod faults;
11mod idle;
12mod mem;
13mod print;
14mod types;
15mod uspace;
16
17mod sched;
18mod sync;
19mod syscalls;
20mod time;
21
22pub mod uapi;
23
24use hal::Machinelike;
25
26pub use hal;
27pub use proc_macros::app_main;
28
29/// The kernel initialization function.
30///
31/// # Safety
32///
33/// This function must be called only once during the kernel startup.
34#[unsafe(no_mangle)]
35pub unsafe extern "C" fn kernel_init() -> ! {
36    // Initialize basic hardware and the logging system.
37    hal::Machine::init();
38    hal::Machine::bench_start();
39
40    print::print_header();
41
42    error!("Hello World!");
43
44    // Initialize the memory allocator.
45    let kaddr_space = mem::init_memory();
46    kprintln!("Memory initialized.");
47
48    sched::init(kaddr_space);
49    kprintln!("Scheduler initialized.");
50
51    idle::init();
52    kprintln!("Idle thread initialized.");
53
54    let (cyc, _ns) = hal::Machine::bench_end();
55    kprintln!("Kernel init took {} cycles.", cyc);
56
57    // Start the init application.
58    uspace::init_app();
59
60    sched::enable();
61
62    loop {}
63}
64
65pub fn panic(info: &core::panic::PanicInfo) -> ! {
66    kprintln!("**************************** PANIC ****************************");
67    kprintln!("");
68    kprintln!("Message: {}", info.message());
69
70    if let Some(location) = info.location() {
71        kprintln!("Location: {}:{}", location.file(), location.line());
72    }
73
74    kprintln!("**************************** PANIC ****************************");
75
76    hal::Machine::panic_handler(info);
77}