interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / uefi / src / table / mod.rs

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