summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArd Biesheuvel <ardb@kernel.org>2023-10-08 20:02:46 +0200
committerArd Biesheuvel <ardb@kernel.org>2023-10-08 20:02:46 +0200
commite88d20e7c94aeb7444c4571995c491368ddea77c (patch)
treefcfb863577887f5f90f98a162655fbade2c2aaee
parent5226fc85df631639558a96c87078c92eac7a3e2e (diff)
downloadefilite-e88d20e7c94aeb7444c4571995c491368ddea77c.tar.gz
WIP bootservices
-rw-r--r--src/efi/bootservices.rs143
-rw-r--r--src/efi/mod.rs7
-rw-r--r--src/efi/systemtable.rs4
3 files changed, 78 insertions, 76 deletions
diff --git a/src/efi/bootservices.rs b/src/efi/bootservices.rs
index 9e3ebb9..b321afb 100644
--- a/src/efi/bootservices.rs
+++ b/src/efi/bootservices.rs
@@ -160,7 +160,7 @@ pub struct BootServices {
reinstall_protocol_interface: ReinstallProtocolInterface,
uninstall_protocol_interface: UninstallProtocolInterface,
handle_protocol: HandleProtocol,
- reserved: *const (),
+ reserved: usize,
register_protocol_notify: RegisterProtocolNotify,
locate_handle: LocateHandle,
locate_device_path: LocateDevicePath,
@@ -195,69 +195,75 @@ pub struct BootServices {
set_mem: SetMem,
}
-static mut BS: BootServices = BootServices {
- hdr: TableHeader {
- signature: [b'B', b'O', b'O', b'T', b'S', b'E', b'R', b'V'],
- revision: UEFI_REVISION,
- header_size: core::mem::size_of::<BootServices>() as u32,
- crc32: 0,
- reserved: 0,
- },
- raise_tpl: raise_tpl,
- restore_tpl: restore_tpl,
-
- allocate_pages: allocate_pages,
- free_pages: free_pages,
- get_memory_map: get_memory_map,
- allocate_pool: allocate_pool,
- free_pool: free_pool,
-
- create_event: create_event,
- set_timer: set_timer,
- wait_for_event: wait_for_event,
- signal_event: signal_event,
- close_event: close_event,
- check_event: check_event,
-
- install_protocol_interface: install_protocol_interface,
- reinstall_protocol_interface: reinstall_protocol_interface,
- uninstall_protocol_interface: uninstall_protocol_interface,
- handle_protocol: handle_protocol,
- reserved: ptr::null(),
- register_protocol_notify: register_protocol_notify,
- locate_handle: locate_handle,
- locate_device_path: locate_device_path,
- install_configuration_table: install_configuration_table,
-
- load_image: load_image,
- start_image: start_image,
- exit: exit,
- unload_image: unload_image,
- exit_boot_services: exit_boot_services,
-
- get_next_monotonic_count: get_next_monotonic_count,
- stall: stall,
- set_watchdog_timer: set_watchdog_timer,
-
- connect_controller: connect_controller,
- disconnect_controller: disconnect_controller,
-
- open_protocol: open_protocol,
- close_protocol: close_protocol,
- open_protocol_information: open_protocol_information,
-
- protocols_per_handle: protocols_per_handle,
- locate_handle_buffer: locate_handle_buffer,
- locate_protocol: locate_protocol,
- install_multiple_protocol_interfaces: install_multiple_protocol_interfaces,
- uninstall_multiple_protocol_interfaces: uninstall_multiple_protocol_interfaces,
-
- calculate_crc32: calculate_crc32,
-
- copy_mem: copy_mem,
- set_mem: set_mem,
- //create_event_ex: create_event_ex,
-};
+impl BootServices {
+ pub fn new() -> BootServices {
+ let mut bs = BootServices {
+ hdr: TableHeader {
+ signature: [b'B', b'O', b'O', b'T', b'S', b'E', b'R', b'V'],
+ revision: UEFI_REVISION,
+ header_size: core::mem::size_of::<BootServices>() as u32,
+ crc32: 0,
+ reserved: 0,
+ },
+ raise_tpl: raise_tpl,
+ restore_tpl: restore_tpl,
+
+ allocate_pages: allocate_pages,
+ free_pages: free_pages,
+ get_memory_map: get_memory_map,
+ allocate_pool: allocate_pool,
+ free_pool: free_pool,
+
+ create_event: create_event,
+ set_timer: set_timer,
+ wait_for_event: wait_for_event,
+ signal_event: signal_event,
+ close_event: close_event,
+ check_event: check_event,
+
+ install_protocol_interface: install_protocol_interface,
+ reinstall_protocol_interface: reinstall_protocol_interface,
+ uninstall_protocol_interface: uninstall_protocol_interface,
+ handle_protocol: handle_protocol,
+ reserved: 0,
+ register_protocol_notify: register_protocol_notify,
+ locate_handle: locate_handle,
+ locate_device_path: locate_device_path,
+ install_configuration_table: install_configuration_table,
+
+ load_image: load_image,
+ start_image: start_image,
+ exit: exit,
+ unload_image: unload_image,
+ exit_boot_services: exit_boot_services,
+
+ get_next_monotonic_count: get_next_monotonic_count,
+ stall: stall,
+ set_watchdog_timer: set_watchdog_timer,
+
+ connect_controller: connect_controller,
+ disconnect_controller: disconnect_controller,
+
+ open_protocol: open_protocol,
+ close_protocol: close_protocol,
+ open_protocol_information: open_protocol_information,
+
+ protocols_per_handle: protocols_per_handle,
+ locate_handle_buffer: locate_handle_buffer,
+ locate_protocol: locate_protocol,
+ install_multiple_protocol_interfaces: install_multiple_protocol_interfaces,
+ uninstall_multiple_protocol_interfaces: uninstall_multiple_protocol_interfaces,
+
+ calculate_crc32: calculate_crc32,
+
+ copy_mem: copy_mem,
+ set_mem: set_mem,
+ //create_event_ex: create_event_ex,
+ };
+ bs.hdr.update_crc();
+ bs
+ }
+}
static CURRENT_TPL: AtomicUsize = AtomicUsize::new(TPL_APPLICATION);
@@ -695,12 +701,3 @@ extern "C" fn set_mem(buffer: *mut u8, size: usize, value: u8) -> *mut u8 {
unsafe { ptr::write_bytes(buffer, value, size) }
buffer
}
-
-impl BootServices {
- pub fn get() -> &'static Self {
- unsafe {
- BS.hdr.update_crc();
- &BS
- }
- }
-}
diff --git a/src/efi/mod.rs b/src/efi/mod.rs
index d2c7e64..800dd86 100644
--- a/src/efi/mod.rs
+++ b/src/efi/mod.rs
@@ -5,6 +5,7 @@
use crate::efi::configtable::ConfigurationTable;
use crate::efi::loadedimage::EFI_LOADED_IMAGE_PROTOCOL_GUID;
use crate::efi::memmap::*;
+use crate::efi::bootservices::BootServices;
use crate::efi::runtimeservices::RuntimeServices;
use crate::efi::MemoryType::*;
use crate::efi::{loadedimage::*, memorytype::*, systemtable::*};
@@ -194,6 +195,8 @@ pub struct EfiContext {
configtable_db: Spinlock<BTreeMap<Guid, ConfigurationTable>>,
#[allow(dead_code)]
+ bs_table: Box<BootServices>,
+ #[allow(dead_code)]
rts_table: Box<RuntimeServices>,
sys_table: Spinlock<Box<SystemTable>>,
}
@@ -222,11 +225,13 @@ pub fn init() -> Result<&'static EfiContext, ()> {
)
.ok_or(())?;
let h = unsafe { LockedHeap::new(rtspool.as_ptr() as *mut _, rtspool.len()) };
+ let bs = Box::new(BootServices::new());
let rts = alloc_table::<RuntimeServices>(&h, RuntimeServices::new())?;
- let sys = alloc_table::<SystemTable>(&h, SystemTable::new(&*rts))?;
+ let sys = alloc_table::<SystemTable>(&h, SystemTable::new(&*bs, &*rts))?;
Ok(Box::new(EfiContext {
rtsdata: h,
configtable_db: Spinlock::new(BTreeMap::new()),
+ bs_table: bs,
rts_table: rts,
sys_table: Spinlock::new(sys),
}))
diff --git a/src/efi/systemtable.rs b/src/efi/systemtable.rs
index 83970f4..3e8e1be 100644
--- a/src/efi/systemtable.rs
+++ b/src/efi/systemtable.rs
@@ -35,7 +35,7 @@ pub struct SystemTable {
unsafe impl Send for SystemTable {}
impl SystemTable {
- pub fn new(rts: *const RuntimeServices) -> SystemTable {
+ pub fn new(bs: *const BootServices, rts: *const RuntimeServices) -> SystemTable {
let handle = new_handle();
let inp = SimpleTextInput::get(handle);
let out = SimpleTextOutput::get(handle);
@@ -57,7 +57,7 @@ impl SystemTable {
standard_error_handle: handle,
stderr: &*out,
runtime_services: rts,
- boot_services: &*BootServices::get(),
+ boot_services: bs,
number_of_table_entries: 0,
configuration_table: ptr::null(),
};