1
0
Fork 0
forked from AbleOS/ableos
ableos/kernel/src/kmain.rs

130 lines
3.7 KiB
Rust
Raw Normal View History

2023-03-30 16:43:04 -05:00
//! AbleOS Kernel Entrypoint
2023-05-06 06:50:24 -05:00
use {
2023-07-08 23:22:44 -05:00
crate::{
2024-03-22 03:58:59 -05:00
arch::{hardware_random_u64, logging::SERIAL_CONSOLE},
2023-07-08 23:22:44 -05:00
bootmodules::{build_cmd, BootModules},
capabilities,
2023-07-08 23:22:44 -05:00
device_tree::DeviceTree,
holeybytes::ExecThread,
ipc::buffer::{self, IpcBuffer},
2023-07-08 23:22:44 -05:00
},
alloc::format,
hashbrown::HashMap,
hbvm::mem::Address,
limine::{Framebuffer, FramebufferRequest, NonNullPtr},
2023-07-08 23:22:44 -05:00
log::{debug, info, trace},
2023-05-06 06:50:24 -05:00
spin::{Lazy, Mutex},
2023-06-16 05:20:37 -05:00
xml::XMLElement,
2023-05-06 06:50:24 -05:00
};
2023-04-05 12:29:20 -05:00
2023-07-08 23:22:44 -05:00
pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! {
2023-05-25 07:04:19 -05:00
debug!("Entered kmain");
2023-03-30 16:43:04 -05:00
2023-08-22 08:52:30 -05:00
let kcmd = build_cmd("Kernel Command Line", cmdline);
trace!("Cmdline: {kcmd:?}");
2023-03-30 16:43:04 -05:00
2023-11-18 01:32:09 -06:00
// for (i, bm) in boot_modules.iter().enumerate() {
// let name = format!("module-{}", i);
// let _bmcmd: XMLElement;
// if bm.cmd.len() >= 2 {
// // TODO: pass into the program
// // Pass CMDLine into an IPCBuffer and put the ptr to the IPCBuffer in r200
// _bmcmd = build_cmd(name, bm.cmd.clone());
// log::info!("{:?}", _bmcmd);
// }
// }
2023-07-08 23:22:44 -05:00
2023-05-23 05:16:14 -05:00
let dt = DEVICE_TREE.lock();
2023-04-05 12:29:20 -05:00
2023-09-13 02:19:37 -05:00
// TODO(Able): This line causes a deadlock
2023-09-17 17:13:23 -05:00
info!("Device Tree: {}", dt);
2023-09-13 02:19:37 -05:00
2023-07-08 23:22:44 -05:00
info!("Boot complete. Moving to init_system");
2023-06-25 22:34:24 -05:00
// TODO: schedule the disk driver from the initramfs
// TODO: schedule the filesystem driver from the initramfs
// TODO: Schedule the VFS from initramfs
2023-06-25 22:34:24 -05:00
// TODO: schedule the init system from the initramfs
2023-05-15 02:19:34 -05:00
drop(dt);
let fb1: &NonNullPtr<Framebuffer> = &FB_REQ.get_response().get().unwrap().framebuffers()[0];
{
use crate::alloc::string::ToString;
let mut dt = DEVICE_TREE.lock();
let mut disp = xml::XMLElement::new("display_0");
disp.set_attribute("width", fb1.width);
disp.set_attribute("height", fb1.height);
disp.set_attribute("bits per pixel", fb1.bpp);
disp.set_attribute("pitch", fb1.pitch);
dt.devices.insert("Displays".to_string(), alloc::vec![disp]);
}
log::info!("Graphics initialised");
log::info!(
"Graphics front ptr {:?}",
fb1.address.as_ptr().unwrap() as *const u8
);
2023-08-22 08:52:30 -05:00
let mut executor = crate::task::Executor::default();
let bm_take = boot_modules.len();
2023-08-22 08:52:30 -05:00
unsafe {
for module in boot_modules.into_iter().take(bm_take) {
let mut cmd = module.cmd;
if cmd.len() > 2 {
// Remove the quotes
cmd.remove(0);
cmd.pop();
}
let cmd_len = cmd.as_bytes().len() as u64;
log::info!("Spawning {} with arguments \"{}\"", module.path, cmd);
2023-08-22 08:52:30 -05:00
executor.spawn(async move {
let mut thr = ExecThread::new(&module.bytes, Address::new(0));
if cmd_len > 0 {
thr.set_arguments(cmd.as_bytes().as_ptr() as u64, cmd_len);
}
2023-11-14 15:02:50 -06:00
if let Err(e) = thr.await {
2023-08-22 08:52:30 -05:00
log::error!("{e:?}");
}
});
}
2024-02-15 14:21:00 -06:00
info!("{}", hardware_random_u64());
2023-08-22 08:52:30 -05:00
executor.run();
};
2023-07-08 23:22:44 -05:00
2023-08-22 08:52:30 -05:00
crate::arch::spin_loop()
2023-03-30 16:43:04 -05:00
}
2023-04-10 01:16:30 -05:00
2023-05-06 06:50:24 -05:00
pub static DEVICE_TREE: Lazy<Mutex<DeviceTree>> = Lazy::new(|| {
2023-05-23 05:16:14 -05:00
let dt = DeviceTree::new();
2023-05-06 06:50:24 -05:00
Mutex::new(dt)
});
pub static FB_REQ: FramebufferRequest = FramebufferRequest::new(0);
2023-05-15 02:19:34 -05:00
2023-09-09 02:35:16 -05:00
use alloc::vec::Vec;
2023-10-23 09:12:43 -05:00
pub type IpcBuffers = HashMap<u64, IpcBuffer>;
pub static IPC_BUFFERS: Lazy<Mutex<IpcBuffers>> = Lazy::new(|| {
let mut bufs = HashMap::new();
let log_buffer = IpcBuffer::new(false, 0);
let file_buffer = IpcBuffer::new(false, 0);
bufs.insert(1, log_buffer);
bufs.insert(2, file_buffer);
Mutex::new(bufs)
});
2023-05-15 02:19:34 -05:00
#[test_case]
fn trivial_assertion() {
trace!("trivial assertion... ");
assert_eq!(1, 1);
info!("[ok]");
}