diff --git a/ableos/.cargo/config.toml b/ableos/.cargo/config.toml index d1fcae5..3d2b992 100644 --- a/ableos/.cargo/config.toml +++ b/ableos/.cargo/config.toml @@ -2,8 +2,8 @@ [build] -# target = "./json_targets/x86_64-ableos.json" -target = "x86_64-unknown-uefi" +target = "./json_targets/x86_64-ableos.json" +# target = "x86_64-unknown-uefi" [unstable] build-std = ["core", "compiler_builtins", "alloc"] diff --git a/ableos/Cargo.lock b/ableos/Cargo.lock index 8b8dfe0..c0fbc11 100644 --- a/ableos/Cargo.lock +++ b/ableos/Cargo.lock @@ -48,6 +48,7 @@ dependencies = [ "spin", "uart_16550", "uefi", + "uefi-services", "unicode-width", "vga", "volatile 0.2.7", @@ -653,6 +654,17 @@ dependencies = [ "syn", ] +[[package]] +name = "uefi-services" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7840bddc6477dc443cc5652ca9683de9f10bd173691151c3160d734521bef3bd" +dependencies = [ + "cfg-if", + "log", + "uefi", +] + [[package]] name = "unicode-width" version = "0.1.9" diff --git a/ableos/Cargo.toml b/ableos/Cargo.toml index e339a5b..1f3cc35 100644 --- a/ableos/Cargo.toml +++ b/ableos/Cargo.toml @@ -51,8 +51,8 @@ pretty-hex = "0.2.1" unicode-width = "0.1.7" picorand = "*" # watson = "0.4" -uefi = { version="*", features = ["exts"] } - +uefi = { version="*",default-features = false, features = ["exts"] } +uefi-services = "0.11.0" [dependencies.rdrand] version = "0.8.1" diff --git a/ableos/src/allocator/mod.rs b/ableos/src/allocator/mod.rs index 45a1f21..2228222 100644 --- a/ableos/src/allocator/mod.rs +++ b/ableos/src/allocator/mod.rs @@ -17,10 +17,10 @@ static ALLOCATOR: Dummy = Dummy; */ use linked_list_allocator::LockedHeap; -#[global_allocator] +// #[global_allocator] pub static ALLOCATOR: LockedHeap = LockedHeap::empty(); -#[alloc_error_handler] +// #[alloc_error_handler] fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! { panic!("allocation error: {:?}", layout) } diff --git a/ableos/src/arch/uefi_86/firmware/OVMF-pure-efi.fd b/ableos/src/arch/uefi_86/firmware/OVMF-pure-efi.fd new file mode 100644 index 0000000..a42726c Binary files /dev/null and b/ableos/src/arch/uefi_86/firmware/OVMF-pure-efi.fd differ diff --git a/ableos/src/kmain.rs b/ableos/src/kmain.rs index 802d54f..1ffe9ec 100644 --- a/ableos/src/kmain.rs +++ b/ableos/src/kmain.rs @@ -1,5 +1,7 @@ #![allow(clippy::empty_loop)] +use x86_64::instructions::random::RdRand; + use { crate::{ arch::{init, sloop}, @@ -36,45 +38,45 @@ lazy_static! { /// The main entry point of the kernel #[no_mangle] pub fn kernel_main() -> ! { - init::init(); - log::set_max_level(BOOT_CONF.log_level()); - - { - { - let mut scheduler = SCHEDULER.lock(); - - use crate::scheduler::Priority::*; - let mut process_1 = scheduler.new_process(High); - process_1.capabilities.files = FileAccess::Some(vec![PathRep { - location: FileLocations::Home, - file_name: "test".to_string(), - }]); - scheduler.add_process(process_1); - for ref_process in &scheduler.list { - trace!("{:?}", ref_process); - } - drop(scheduler); - } - - use crate::proto_filetable::file::FileLocations; + /* init::init(); + log::set_max_level(BOOT_CONF.log_level()); { - let mut sock_print_id = SimpleSock::new(); - sock_print_id.register_protocol("Screen Printer".to_string()); - sock_print_id.write(format!("🐑").into()); + { + let mut scheduler = SCHEDULER.lock(); - let mut mode = SCREEN_BUFFER.lock(); - - mode.force_redraw(); - for current in (*String::from_utf8_lossy(&sock_print_id.peek().unwrap())).chars() { - mode.draw_char(0, 0, current, from_vga_16(Color16::Red)); + use crate::scheduler::Priority::*; + let mut process_1 = scheduler.new_process(High); + process_1.capabilities.files = FileAccess::Some(vec![PathRep { + location: FileLocations::Home, + file_name: "test".to_string(), + }]); + scheduler.add_process(process_1); + for ref_process in &scheduler.list { + trace!("{:?}", ref_process); + } + drop(scheduler); + } + + use crate::proto_filetable::file::FileLocations; + + { + let mut sock_print_id = SimpleSock::new(); + sock_print_id.register_protocol("Screen Printer".to_string()); + sock_print_id.write(format!("🐑").into()); + + let mut mode = SCREEN_BUFFER.lock(); + + mode.force_redraw(); + for current in (*String::from_utf8_lossy(&sock_print_id.peek().unwrap())).chars() { + mode.draw_char(0, 0, current, from_vga_16(Color16::Red)); + } + mode.copy_to_buffer(); } - mode.copy_to_buffer(); } - } - - start_facepalm(); + start_facepalm(); + */ sloop() } @@ -105,3 +107,27 @@ pub fn log_version_data() { master().unwrap().brand_string().unwrap() ); } + +pub fn generate_process_pass() -> u128 { + use rdrand::RdRand; + let gen = RdRand::new().unwrap(); + let ret = (gen.try_next_u64().unwrap() as u128) << 64 | (gen.try_next_u64().unwrap() as u128); + ret +} + +// #![no_main] +// #![no_std] + +use uefi::prelude::*; +use uefi::ResultExt; + +#[entry] +fn main(_handle: Handle, mut system_table: SystemTable) -> Status { + uefi_services::init(&mut system_table).unwrap_success(); + log_version_data(); + + kernel_main(); + + loop {} + // Status::SUCCESS +} diff --git a/ableos/src/lib.rs b/ableos/src/lib.rs index 5e759d1..264385d 100644 --- a/ableos/src/lib.rs +++ b/ableos/src/lib.rs @@ -14,6 +14,7 @@ naked_functions, slice_pattern )] +#![feature(abi_efiapi)] /// Contains architecture specific code for aarch64. #[cfg(target_arch = "aarch64")] diff --git a/ableos/src/panic.rs b/ableos/src/panic.rs index 9ae4d7c..0de0754 100644 --- a/ableos/src/panic.rs +++ b/ableos/src/panic.rs @@ -9,7 +9,7 @@ use {crate::arch::sloop, core::panic::PanicInfo}; /// /// # Safety /// This function is unsafe because it does not guarantee that the panic is handled. -#[panic_handler] +// #[panic_handler] fn panic(info: &PanicInfo) -> ! { error!("{}", info); // help me use facepalm::start_facepalm; diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 51a01e6..3b97ab1 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -4,46 +4,47 @@ use clap::Parser; #[clap(version = clap::crate_version!(), author = clap::crate_authors!("\n"))] /// Hello Remember this is a feature enum Command { - Run { - #[clap(long, short)] - debug: bool, + Run { + #[clap(long, short)] + debug: bool, - #[clap(long, short, arg_enum)] - machine: Option, - }, + #[clap(long, short, arg_enum)] + machine: Option, + }, - Doc { - #[clap(long, short, arg_enum)] - machine: Option, - }, + Doc { + #[clap(long, short, arg_enum)] + machine: Option, + }, } #[derive(clap::ArgEnum, Debug, Clone)] enum MachineType { - X86, - RISCV, - ARM, + X86, + RISCV, + ARM, + Uefi86, } fn main() -> anyhow::Result<()> { - let args = Command::parse(); + let args = Command::parse(); - match args { - Command::Run { debug, machine } => { - let _dir = xshell::pushd("./ableos"); + match args { + Command::Run { debug, machine } => { + let _dir = xshell::pushd("./ableos"); - let _debug_log: &[&str] = match debug { - true => &["-D", "debug.log"], - false => &[], - }; - match machine.unwrap_or(MachineType::X86) { - MachineType::X86 => { - xshell::cmd!("cargo run --release").run()?; - } - MachineType::ARM => { - xshell::cmd!("cargo build --release --target=json_targets/aarch64-ableos.json") - .run()?; - #[rustfmt::skip] + let _debug_log: &[&str] = match debug { + true => &["-D", "debug.log"], + false => &[], + }; + match machine.unwrap_or(MachineType::X86) { + MachineType::X86 => { + xshell::cmd!("cargo run --release").run()?; + } + MachineType::ARM => { + xshell::cmd!("cargo build --release --target=json_targets/aarch64-ableos.json") + .run()?; + #[rustfmt::skip] xshell::cmd!( "qemu-system-aarch64 -machine virt @@ -53,10 +54,11 @@ fn main() -> anyhow::Result<()> { -device virtio-keyboard " ).run()?; - } - MachineType::RISCV => { - xshell::cmd!("cargo build --release --target=riscv64gc-unknown-none-elf").run()?; - #[rustfmt::skip] + } + MachineType::RISCV => { + xshell::cmd!("cargo build --release --target=riscv64gc-unknown-none-elf") + .run()?; + #[rustfmt::skip] xshell::cmd!( "qemu-system-riscv64 -machine virt @@ -66,26 +68,35 @@ fn main() -> anyhow::Result<()> { -bios src/arch/riscv/firmwear/opensbi-riscv64-generic-fw_jump.bin -kernel target/riscv64gc-unknown-none-elf/release/ableos" ).run()?; - } - } - } + } + MachineType::Uefi86 => { + xshell::cmd!("cargo build --release --target=x86_64-unknown-uefi").run()?; - Command::Doc { machine } => { - let _dir = xshell::pushd("./ableos"); + xshell::cmd!("uefi-run -b src/arch/uefi_86/firmware/OVMF-pure-efi.fd target/x86_64-unknown-uefi/release/ableos.efi").run()?; + } + } + } - match machine.unwrap_or(MachineType::X86) { - MachineType::X86 => { - xshell::cmd!("cargo doc --open").run()?; - } - MachineType::ARM => { - xshell::cmd!("cargo doc --open --target=json_targets/aarch64-ableos.json").run()?; - } - MachineType::RISCV => { - xshell::cmd!("cargo doc --open --target=riscv64gc-unknown-none-elf").run()?; - } - } - } - } + Command::Doc { machine } => { + let _dir = xshell::pushd("./ableos"); - Ok(()) + match machine.unwrap_or(MachineType::X86) { + MachineType::X86 => { + xshell::cmd!("cargo doc --open").run()?; + } + MachineType::ARM => { + xshell::cmd!("cargo doc --open --target=json_targets/aarch64-ableos.json") + .run()?; + } + MachineType::RISCV => { + xshell::cmd!("cargo doc --open --target=riscv64gc-unknown-none-elf").run()?; + } + MachineType::Uefi86 => { + xshell::cmd!("cargo doc --open --target=x86_64-unknown-uefi").run()?; + } + } + } + } + + Ok(()) }