ableos/kernel/src/arch/aarch64/mod.rs

119 lines
3.5 KiB
Rust

pub use logging::log;
use {
crate::{allocator, bootmodules::BootModule, kmain::kmain},
core::arch::asm,
limine::FramebufferRequest,
};
mod device_info_collector;
use device_info_collector::collect_device_info;
pub mod logging;
use limine::HhdmRequest;
extern "C" {
fn _initial_kernel_heap_start();
fn _initial_kernel_heap_size();
}
const INITIAL_KERNEL_HEAP_START: *mut u8 = _initial_kernel_heap_start as _;
const INITIAL_KERNEL_HEAP_SIZE: *const () = _initial_kernel_heap_size as _;
pub const PAGE_SIZE: usize = 4096;
static FB_REQ: FramebufferRequest = FramebufferRequest::new(0);
#[no_mangle]
unsafe extern "C" fn _kernel_start() -> ! {
crate::logger::init().expect("failed to set logger");
log::info!("Initialising AKern {}", crate::VERSION);
static HDHM_REQ: HhdmRequest = HhdmRequest::new(0);
// memory::init_pt(VirtAddr::new(
// HDHM_REQ
// .get_response()
// .get()
// .expect("tried to get physical memory mapping offset from Limine")
// .offset,
// ));
allocator::init(INITIAL_KERNEL_HEAP_START, INITIAL_KERNEL_HEAP_SIZE as _);
collect_device_info();
let bm = MOD_REQ.get_response().get();
use limine::{KernelFileRequest, ModuleRequest};
static KFILE_REQ: KernelFileRequest = KernelFileRequest::new(0);
static MOD_REQ: ModuleRequest = ModuleRequest::new(0);
let mut bootmodules = alloc::vec::Vec::new();
if bm.is_some() {
let bm = bm.unwrap();
for x in 0..bm.module_count {
let file = bm.modules().get(x as usize);
if file.is_some() {
let file = file.unwrap();
let raw_bytes = core::slice::from_raw_parts(
file.base.as_ptr().expect("invalid initrd"),
file.length as usize,
)
.to_vec();
let file_path = alloc::string::String::from_utf8(
file.path.to_str().unwrap().to_bytes().to_vec(),
);
if file_path.is_err() {
panic!("invalid file path: {:?}", file_path);
}
let file_cmd = alloc::string::String::from_utf8(
file.cmdline.to_str().unwrap().to_bytes().to_vec(),
);
if file_cmd.is_err() {
panic!("invalid module cmd: {:?}", file_cmd);
}
log::trace!("module path: {:?}", file_path);
log::trace!("module cmd: {:?}", file_cmd);
bootmodules.push(BootModule::new(
file_path.unwrap(),
raw_bytes,
file_cmd.unwrap(),
));
} else {
log::error!("You should not be here");
break;
}
}
log::info!("Boot module count: {:?}", bootmodules.len());
assert_eq!(bm.module_count, bootmodules.len() as u64);
}
crate::kmain::kmain(
KFILE_REQ
.get_response()
.get()
.and_then(|r| r.kernel_file.get())
.expect("failed to get kernel file from Limine")
.cmdline
.to_str()
.map(core::ffi::CStr::to_str)
.transpose()
.expect("expected valid cmdline string")
.unwrap_or_default(),
bootmodules,
);
spin_loop();
}
pub fn spin_loop() -> ! {
loop {
unsafe { asm!("wfi") }
}
}
pub fn hardware_random_u64() -> u64 {
0
}
pub fn register_dump() {}
#[no_mangle]
pub fn fmod() {}