Skip to content

Commit

Permalink
refactor(uefi): migrate away from tables
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Sep 17, 2024
1 parent 2a2d3ff commit f3d518c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 27 deletions.
2 changes: 0 additions & 2 deletions src/os/uefi/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
22 changes: 8 additions & 14 deletions src/os/uefi/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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(())
Expand Down
17 changes: 6 additions & 11 deletions src/os/uefi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boot>) -> 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"));
Expand All @@ -38,10 +34,9 @@ fn loader_main(_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
qemu_exit_handle.exit_success()
}

fn read_app(bt: &BootServices) -> Vec<u8> {
let fs = bt
.get_image_file_system(bt.image_handle())
.expect("should open file system");
fn read_app() -> Vec<u8> {
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"));

Expand Down

0 comments on commit f3d518c

Please sign in to comment.