From f3d518c1b7835593ac691c0824a056721f1df7d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 17 Sep 2024 11:30:25 +0200 Subject: [PATCH] refactor(uefi): migrate away from tables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/os/uefi/allocator.rs | 2 -- src/os/uefi/console.rs | 22 ++++++++-------------- src/os/uefi/mod.rs | 17 ++++++----------- 3 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/os/uefi/allocator.rs b/src/os/uefi/allocator.rs index f9e40f62..30d85eb3 100644 --- a/src/os/uefi/allocator.rs +++ b/src/os/uefi/allocator.rs @@ -54,6 +54,4 @@ pub fn exit_boot_services() { let bump = BumpAllocator::from(mem); *ALLOCATOR.0.lock() = GlobalAllocator::Bump(bump); - - uefi::allocator::exit_boot_services(); } diff --git a/src/os/uefi/console.rs b/src/os/uefi/console.rs index 94142a27..fd7006d9 100644 --- a/src/os/uefi/console.rs +++ b/src/os/uefi/console.rs @@ -29,16 +29,13 @@ impl Console { fn init(&mut self) { assert!(matches!(self, Console::None)); unsafe { - uefi::table::system_table_boot() - .unwrap() - .boot_services() - .create_event( - EventType::SIGNAL_EXIT_BOOT_SERVICES, - Tpl::NOTIFY, - Some(exit_boot_services), - None, - ) - .unwrap(); + uefi::boot::create_event( + EventType::SIGNAL_EXIT_BOOT_SERVICES, + Tpl::NOTIFY, + Some(exit_boot_services), + None, + ) + .unwrap(); } *self = Console::BootServices; } @@ -51,10 +48,7 @@ impl fmt::Write for Console { self.init(); self.write_str(s)?; } - Console::BootServices => uefi::table::system_table_boot() - .unwrap() - .stdout() - .write_str(s)?, + Console::BootServices => uefi::system::with_stdout(|stdout| stdout.write_str(s))?, Console::Native { console } => console.write_bytes(s.as_bytes()), } Ok(()) diff --git a/src/os/uefi/mod.rs b/src/os/uefi/mod.rs index 45986a75..cbc487f4 100644 --- a/src/os/uefi/mod.rs +++ b/src/os/uefi/mod.rs @@ -14,21 +14,17 @@ pub use self::console::CONSOLE; // Entry Point of the Uefi Loader #[entry] -fn loader_main(_handle: Handle, mut system_table: SystemTable) -> Status { +fn main() -> Status { uefi::helpers::init().unwrap(); - unsafe { - uefi::allocator::init(&mut system_table); - } crate::log::init(); - let app = read_app(system_table.boot_services()); + let app = read_app(); let string = String::from_utf8(app).unwrap(); println!("{string}"); allocator::exit_boot_services(); - let (_runtime_system_table, _memory_map) = - unsafe { system_table.exit_boot_services(MemoryType::LOADER_DATA) }; + let _memory_map = unsafe { boot::exit_boot_services(MemoryType::LOADER_DATA) }; println!("Exited boot services!"); println!("Allocations still {}!", String::from("work")); @@ -38,10 +34,9 @@ fn loader_main(_handle: Handle, mut system_table: SystemTable) -> Status { qemu_exit_handle.exit_success() } -fn read_app(bt: &BootServices) -> Vec { - let fs = bt - .get_image_file_system(bt.image_handle()) - .expect("should open file system"); +fn read_app() -> Vec { + let image_handle = boot::image_handle(); + let fs = boot::get_image_file_system(image_handle).expect("should open file system"); let path = Path::new(cstr16!(r"\efi\boot\hermit-app"));