From 6b21624ac03ed9a7503793a35f398a5ab5acc1de Mon Sep 17 00:00:00 2001 From: John Hodge <tpg@mutabah.net> Date: Sun, 7 Apr 2019 10:14:52 +0800 Subject: [PATCH] UEFI Bootloader - Upgrade --- Bootloaders/libuefi/src/con.rs | 4 ++-- Bootloaders/libuefi/src/lib.rs | 4 +++- Bootloaders/uefi/Makefile | 2 +- Bootloaders/uefi/main.rs | 12 ++++++------ Bootloaders/uefi/target-uefi.json | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Bootloaders/libuefi/src/con.rs b/Bootloaders/libuefi/src/con.rs index 84d308e9..8aeec015 100644 --- a/Bootloaders/libuefi/src/con.rs +++ b/Bootloaders/libuefi/src/con.rs @@ -85,8 +85,8 @@ impl SimpleTextOutputInterface #[derive(Default)] pub struct InputKey { - scan_code: u16, - unicode_char: u16, + pub scan_code: u16, + pub unicode_char: u16, } #[repr(C)] diff --git a/Bootloaders/libuefi/src/lib.rs b/Bootloaders/libuefi/src/lib.rs index 0f599c55..03a5a9b1 100644 --- a/Bootloaders/libuefi/src/lib.rs +++ b/Bootloaders/libuefi/src/lib.rs @@ -13,7 +13,6 @@ #![no_std] #![crate_name="uefi"] #![crate_type="lib"] -#![feature(unique)] #![feature(try_trait)] // Makes Status a little easier to use #![feature(ptr_internals)] // rawptr as_ref @@ -94,6 +93,9 @@ impl<T> ::core::ops::Deref for SizePtr<T> } } +// TODO: Have a SystemTablePtr structure that exposes the various boot services as borrows only +// - BUT: The only way to call ExitBootServices is to consume it + #[repr(C)] /// System Table (top-level EFI structure) /// diff --git a/Bootloaders/uefi/Makefile b/Bootloaders/uefi/Makefile index d47bdd09..268cd4c5 100644 --- a/Bootloaders/uefi/Makefile +++ b/Bootloaders/uefi/Makefile @@ -21,7 +21,7 @@ clean: @echo [LD] -o $@ $Vx86_64-efi-pe-ld -g -r -o $@ -e efi_main $(OBJS) --strip-discarded --gc-sections --allow-multiple-definition -$(TARGET_DIR)libbootloader_uefi.a: .obj/libstubs.a $(TARGET_FILE) +$(TARGET_DIR)libbootloader_uefi.a: .obj/libstubs.a $(TARGET_FILE) .PHONY @echo [XARGO] build $VRUSTFLAGS="$(RUSTFLAGS)" RUST_TARGET_PATH=$(abspath .) $(XARGO) build --target=$(TARGET_NAME) --release diff --git a/Bootloaders/uefi/main.rs b/Bootloaders/uefi/main.rs index 37ef600c..147509dc 100644 --- a/Bootloaders/uefi/main.rs +++ b/Bootloaders/uefi/main.rs @@ -2,8 +2,8 @@ // // #![feature(asm)] -#![feature(proc_macro, proc_macro_non_items)] // utf16_literal -#![feature(panic_implementation,panic_info_message)] +#![feature(proc_macro_hygiene)] // utf16_literal +#![feature(panic_info_message)] #![no_std] use uefi::boot_services::protocols; @@ -91,6 +91,7 @@ pub extern "win64" fn efi_main(image_handle: ::uefi::Handle, system_table: &::ue let system_volume_fs: &protocols::SimpleFileSystem = boot_services.handle_protocol(&image_proto.device_handle).expect("image_proto - FileProtocol"); // - Get the root of this volume and load the bootloader configuration file from it let system_volume_root = system_volume_fs.open_volume().expect("system_volume_fs - File"); + // NOTE: This function will return Ok(Default::default()) if the file can't be found let config = match Configuration::from_file(boot_services, &system_volume_root, PATH_CONFIG.into()) { Ok(c) => c, @@ -133,6 +134,7 @@ pub extern "win64" fn efi_main(image_handle: ::uefi::Handle, system_table: &::ue (map_key, map) }; loge!(conout, "- Exiting boot services"); + //let runtime_services = system_table_ptr.exit_boot_services().ok().expect("exit_boot_services"); // SAFE: Weeelll... unsafe { (boot_services.exit_boot_services)(image_handle, map_key).expect("exit_boot_services"); @@ -211,10 +213,8 @@ fn load_kernel_file(boot_services: &::uefi::boot_services::BootServices, sys_vol } -#[panic_implementation] -// NOTE: Needs to be public and no_mangle (rust#51342) -#[no_mangle] -pub fn handle_panic(info: &::core::panic::PanicInfo) -> ! { +#[panic_handler] +fn handle_panic(info: &::core::panic::PanicInfo) -> ! { static mut NESTED: bool = false; unsafe { if NESTED { diff --git a/Bootloaders/uefi/target-uefi.json b/Bootloaders/uefi/target-uefi.json index 4450d425..046c8c60 100644 --- a/Bootloaders/uefi/target-uefi.json +++ b/Bootloaders/uefi/target-uefi.json @@ -8,7 +8,7 @@ "target-c-int-width": "32", "os": "tifflin", "arch": "x86_64", - "pre-link-args": [], + "pre-link-args": {}, "no-compiler-rt": true, "disable-redzone": true, "eliminate-frame-pointer": false, -- GitLab