81 lines
1.8 KiB
Rust
81 lines
1.8 KiB
Rust
//! osdev-x kernel crate
|
|
#![feature(
|
|
naked_functions,
|
|
asm_const,
|
|
panic_info_message,
|
|
optimize_attribute,
|
|
const_trait_impl,
|
|
maybe_uninit_slice,
|
|
arbitrary_self_types,
|
|
linked_list_cursors
|
|
)]
|
|
#![allow(clippy::new_without_default)]
|
|
#![warn(missing_docs)]
|
|
#![no_std]
|
|
#![no_main]
|
|
|
|
extern crate yggdrasil_abi as abi;
|
|
|
|
use abi::{
|
|
error::Error,
|
|
io::{FileMode, OpenOptions},
|
|
process::ExitCode,
|
|
};
|
|
use fs::{FileBlockAllocator, INITRD_DATA};
|
|
use memfs::MemoryFilesystem;
|
|
use task::process::Process;
|
|
use vfs::{Filesystem, IoContext, VnodeRef};
|
|
|
|
extern crate alloc;
|
|
|
|
#[macro_use]
|
|
pub mod debug;
|
|
#[macro_use]
|
|
pub mod arch;
|
|
|
|
pub mod device;
|
|
pub mod fs;
|
|
pub mod mem;
|
|
pub mod panic;
|
|
pub mod proc;
|
|
pub mod sync;
|
|
pub mod syscall;
|
|
pub mod task;
|
|
pub mod util;
|
|
|
|
fn setup_root() -> Result<VnodeRef, Error> {
|
|
let initrd_data = INITRD_DATA.get();
|
|
let fs = MemoryFilesystem::<FileBlockAllocator>::from_slice(initrd_data.data).unwrap();
|
|
fs.root()
|
|
}
|
|
|
|
/// Entry point for common kernel code.
|
|
///
|
|
/// # Note
|
|
///
|
|
/// This function is meant to be used as a kernel-space process after all the platform-specific
|
|
/// initialization has finished.
|
|
pub fn kernel_main() {
|
|
let root = match setup_root() {
|
|
Ok(root) => root,
|
|
Err(err) => {
|
|
warnln!("Could not setup root from initrd: {:?}", err);
|
|
return;
|
|
}
|
|
};
|
|
|
|
let ioctx = IoContext::new(root);
|
|
let node = ioctx.find(None, "/init", true, true).unwrap();
|
|
let file = node.open(OpenOptions::READ, FileMode::empty()).unwrap();
|
|
|
|
{
|
|
let user_init = proc::exec::load_elf(file, &["/init", "xxx"]).unwrap();
|
|
let mut io = user_init.io.lock();
|
|
io.set_ioctx(ioctx);
|
|
drop(io);
|
|
user_init.enqueue_somewhere();
|
|
}
|
|
|
|
Process::current().exit(ExitCode::SUCCESS);
|
|
}
|