124 lines
3.6 KiB
Rust
124 lines
3.6 KiB
Rust
pub use logging::log;
|
|
use {
|
|
crate::{allocator, bootmodules::BootModule, kmain::kmain},
|
|
alloc::vec::Vec,
|
|
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 = 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,
|
|
);
|
|
|
|
let file_path = file.path.to_str().unwrap().to_str();
|
|
if file_path.is_err() {
|
|
panic!("invalid file path: {:?}", file_path);
|
|
}
|
|
let file_cmd = file.cmdline.to_str().unwrap().to_str();
|
|
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);
|
|
}
|
|
|
|
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,
|
|
);
|
|
}
|
|
|
|
pub fn spin_loop() -> ! {
|
|
loop {
|
|
unsafe { asm!("wfi") }
|
|
}
|
|
}
|
|
|
|
/// I am sorry.
|
|
static mut A_REAL_RANDOM_U64_I_PROMISE: u64 = 0;
|
|
|
|
pub fn hardware_random_u64() -> u64 {
|
|
if let Some(rng) = aarch64_cpu::asm::random::ArmRng::new() {
|
|
if let Some(rnd) = rng.rndr() {
|
|
return rnd;
|
|
}
|
|
}
|
|
unsafe {
|
|
A_REAL_RANDOM_U64_I_PROMISE += 1;
|
|
A_REAL_RANDOM_U64_I_PROMISE
|
|
}
|
|
}
|
|
|
|
pub fn register_dump() {}
|
|
#[no_mangle]
|
|
pub fn fmod() {}
|