kernel/
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]
7pub mod macros;
8#[macro_use]
9pub mod utils;
10pub mod faults;
11pub mod mem;
12pub mod print;
13pub mod sched;
14pub mod services;
15pub mod sync;
16pub mod syscalls;
17pub mod time;
18pub mod uspace;
19
20use core::ffi::c_char;
21
22use hal::Machinelike;
23
24/// The memory map entry type.
25///
26/// This structure shall be compatible with the multiboot_memory_map_t struct at
27/// Link: [https://www.gnu.org/software/grub/manual/multiboot/multiboot.html]()
28#[repr(packed, C)]
29pub struct MemMapEntry {
30    /// The size of the entry.
31    size: u32,
32    /// The base address of the memory region.
33    addr: u64,
34    /// The length of the memory region.
35    length: u64,
36    /// The type of the memory region.
37    ty: u32,
38}
39
40/// The boot information structure.
41#[repr(C)]
42pub struct BootInfo {
43    /// The implementer of the processor.
44    pub implementer: *const c_char,
45    /// The variant of the processor.
46    pub variant: *const c_char,
47    /// The memory map.
48    pub mmap: [MemMapEntry; 8],
49    /// The length of the memory map.
50    pub mmap_len: usize,
51}
52
53/// The kernel initialization function.
54///
55/// `boot_info` - The boot information.
56#[unsafe(no_mangle)]
57pub unsafe extern "C" fn kernel_init(boot_info: *const BootInfo) -> ! {
58    // Initialize basic hardware and the logging system.
59    hal::Machine::init();
60
61    //hal::asm::disable_interrupts();
62
63    hal::Machine::bench_start();
64
65    let boot_info = unsafe { &*boot_info };
66
67    print::print_header();
68    print::print_boot_info(boot_info);
69
70    // Initialize the memory allocator.
71    if let Err(e) = mem::init_memory(boot_info) {
72        panic!(
73            "[Kernel] Error: failed to initialize memory allocator. Error: {:?}",
74            e
75        );
76    }
77
78    // Initialize the services.
79    if let Err(e) = services::init_services() {
80        panic!(
81            "[Kernel] Error: failed to initialize services. Error: {:?}",
82            e
83        );
84    }
85
86    sched::enable_scheduler(false);
87
88    let (cyc, ns) = hal::Machine::bench_end();
89    kprintln!(
90        "[Osiris] Init took {} cycles taking {} ms",
91        cyc,
92        ns / 1e6f32
93    );
94
95    sched::enable_scheduler(true);
96
97    loop {
98        hal::asm::nop!();
99    }
100}