1 //! Standard UEFI tables. 2 3 pub mod cfg; 4 5 mod header; 6 7 pub use header::Header; 8 pub use uefi_raw::table::Revision; 9 10 use core::ptr::{self, NonNull}; 11 use core::sync::atomic::{AtomicPtr, Ordering}; 12 13 /// Global system table pointer. This is only modified by [`set_system_table`]. 14 static SYSTEM_TABLE: AtomicPtr<uefi_raw::table::system::SystemTable> = 15 AtomicPtr::new(ptr::null_mut()); 16 17 /// Get the raw system table pointer. 18 /// 19 /// If called before `set_system_table` has been called, this will return `None`. system_table_raw() -> Option<NonNull<uefi_raw::table::system::SystemTable>>20pub fn system_table_raw() -> Option<NonNull<uefi_raw::table::system::SystemTable>> { 21 let ptr = SYSTEM_TABLE.load(Ordering::Acquire); 22 NonNull::new(ptr) 23 } 24 25 /// Get the raw system table pointer. This may only be called after 26 /// `set_system_table` has been used to set the global pointer. 27 /// 28 /// # Panics 29 /// 30 /// Panics if the global system table pointer is null. 31 #[track_caller] system_table_raw_panicking() -> NonNull<uefi_raw::table::system::SystemTable>32pub(crate) fn system_table_raw_panicking() -> NonNull<uefi_raw::table::system::SystemTable> { 33 system_table_raw().expect("global system table pointer is not set") 34 } 35 36 /// Update the global system table pointer. 37 /// 38 /// This is called automatically in the `main` entry point as part of 39 /// [`uefi::entry`]. 40 /// 41 /// It is also called by [`set_virtual_address_map`] to transition from a 42 /// physical address to a virtual address. 43 /// 44 /// This function should not be called at any other point in time, unless the 45 /// executable does not use [`uefi::entry`], in which case it should be called 46 /// once before calling any other API in this crate. 47 /// 48 /// # Safety 49 /// 50 /// This function should only be called as described above, and the 51 /// `ptr` must be a valid [`SystemTable`]. 52 /// 53 /// [`SystemTable`]: uefi_raw::table::system::SystemTable 54 /// [`set_virtual_address_map`]: uefi::runtime::set_virtual_address_map set_system_table(ptr: *const uefi_raw::table::system::SystemTable)55pub unsafe fn set_system_table(ptr: *const uefi_raw::table::system::SystemTable) { 56 SYSTEM_TABLE.store(ptr.cast_mut(), Ordering::Release); 57 } 58 59 /// Common trait implemented by all standard UEFI tables. 60 pub trait Table { 61 /// A unique number assigned by the UEFI specification 62 /// to the standard tables. 63 const SIGNATURE: u64; 64 } 65