sparreal_kernel/
kernel.rsuse core::ptr::NonNull;
use driver_interface::Register;
use log::*;
use page_table_generic::{AccessSetting, CacheSetting};
use spin_on::spin_on;
use crate::{
driver::{self, device_tree::set_dtb_addr},
logger::KLogger,
mem::{self, *},
platform::{self, app_main},
println,
stdout::{self, EarlyDebugWrite},
};
pub unsafe fn init_log_and_memory(kconfig: &KernelConfig) {
set_dtb_addr(kconfig.dtb_addr);
let _ = log::set_logger(&KLogger);
log::set_max_level(LevelFilter::Trace);
stdout::set_stdout(EarlyDebugWrite {});
info!("Logger initialized.");
mem::init(kconfig);
let version = env!("CARGO_PKG_VERSION");
println!("Welcome to sparreal\nVersion: {version}");
platform::print_system_info();
}
pub fn driver_register_append(registers: impl IntoIterator<Item = Register>) {
driver::register_append(registers);
}
pub unsafe fn run() -> ! {
spin_on(async {
driver::init().await;
});
platform::irqs_enable();
app_main();
println!("Waiting for interrupt...");
loop {
platform::wait_for_interrupt();
}
}
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct MemoryRange {
pub start: Phys<u8>,
pub size: usize,
}
impl MemoryRange {
pub const fn new() -> Self {
Self {
start: Phys::new(),
size: 0,
}
}
}
#[repr(C)]
#[derive(Clone)]
pub struct KernelConfig {
pub boot_info: BootConfig,
pub stack_top: Phys<u8>,
pub dtb_addr: Option<NonNull<u8>>,
}
#[derive(Clone)]
pub struct BootConfig {
pub main_memory: MemoryRange,
pub main_memory_heap_offset: usize,
pub hart_stack_size: usize,
pub reserved_memory: [Option<MemoryReservedRange>; 24],
pub va_offset: usize,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct MemoryReservedRange {
pub name: &'static str,
pub start: Phys<u8>,
pub size: usize,
pub access: AccessSetting,
pub cache: CacheSetting,
}