Skip to main content

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 error;
8mod faults;
9mod idle;
10mod irq;
11mod mem;
12
13#[macro_use]
14mod print;
15mod types;
16mod uspace;
17
18mod sched;
19mod sync;
20mod syscalls;
21mod time;
22
23#[cfg(any(feature = "metrics", metrics))]
24pub mod metrics;
25
26// Public, for now.
27pub mod drivers;
28pub mod uapi;
29
30pub use hal_cortex_m::*;
31// Add new hals here. No cfg needed.
32
33pub use hal::Machinelike;
34pub use hal_api::error::*;
35pub use proc_macros::app_main;
36
37/// The kernel initialization function.
38///
39/// # Safety
40///
41/// This function must be called only once during the kernel startup.
42#[unsafe(no_mangle)]
43pub unsafe extern "C" fn kernel_init() -> ! {
44    // Initialize basic hardware and the logging system.
45    hal::Machine::init();
46    hal::Machine::init_irqs(irq::register_irq_safe);
47    hal::Machine::bench_start();
48
49    print::print_header();
50
51    // Initialize the memory allocator.
52    let kaddr_space = mem::init_memory();
53    kprint!("Memory initialized.\n");
54
55    drivers::init();
56    kprint!("Drivers initialized.\n");
57
58    sched::init(kaddr_space);
59    kprint!("Scheduler initialized.\n");
60
61    idle::init();
62    kprint!("Idle thread initialized.\n");
63
64    let (cyc, _ns) = hal::Machine::bench_end();
65    kprint!("Kernel init took {} cycles.\n", cyc);
66
67    // Start the init application.
68    uspace::init_app();
69
70    sched::enable();
71
72    loop {}
73}
74
75pub fn panic(info: &core::panic::PanicInfo) -> ! {
76    kprint!("**************************** PANIC ****************************\n");
77    kprint!("\n");
78    kprint!("Message: {}\n", info.message());
79
80    if let Some(location) = info.location() {
81        kprint!("Location: {}:{}\n", location.file(), location.line());
82    }
83
84    kprint!("**************************** PANIC ****************************\n");
85
86    hal::Machine::panic_handler(info);
87}