-
-
Notifications
You must be signed in to change notification settings - Fork 169
Add basic API for a global system table #1156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
phip1611
merged 4 commits into
rust-osdev:main
from
nicholasbishop:bishop-global-tables-simple
May 23, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6cff6c5
uefi: Sort the code in table/mod.rs
nicholasbishop a42ddc5
uefi: Add global system table pointer and API
nicholasbishop ec956eb
uefi-macros: Call set_image_handle from the entry macro
nicholasbishop c04e423
uefi: Make exit_boot_services unsafe
nicholasbishop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,84 @@ | ||
//! Standard UEFI tables. | ||
|
||
/// Common trait implemented by all standard UEFI tables. | ||
pub trait Table { | ||
/// A unique number assigned by the UEFI specification | ||
/// to the standard tables. | ||
const SIGNATURE: u64; | ||
} | ||
pub mod boot; | ||
pub mod cfg; | ||
pub mod runtime; | ||
|
||
mod header; | ||
pub use header::Header; | ||
|
||
mod system; | ||
|
||
pub use header::Header; | ||
pub use system::{Boot, Runtime, SystemTable}; | ||
pub use uefi_raw::table::Revision; | ||
|
||
pub mod boot; | ||
pub mod runtime; | ||
use core::ptr; | ||
use core::sync::atomic::{AtomicPtr, Ordering}; | ||
|
||
pub mod cfg; | ||
/// Global system table pointer. This is only modified by [`set_system_table`]. | ||
static SYSTEM_TABLE: AtomicPtr<uefi_raw::table::system::SystemTable> = | ||
AtomicPtr::new(ptr::null_mut()); | ||
|
||
pub use uefi_raw::table::Revision; | ||
/// Update the global system table pointer. | ||
/// | ||
/// This is called automatically in the `main` entry point as part of | ||
/// [`uefi::entry`]. It should not be called at any other point in time, unless | ||
/// the executable does not use [`uefi::entry`], in which case it should be | ||
/// called once before calling any other API in this crate. | ||
/// | ||
/// # Safety | ||
/// | ||
/// This function should only be called as described above, and the | ||
/// `ptr` must be a valid [`SystemTable`]. | ||
pub unsafe fn set_system_table(ptr: *const uefi_raw::table::system::SystemTable) { | ||
SYSTEM_TABLE.store(ptr.cast_mut(), Ordering::Release); | ||
} | ||
|
||
/// Get the system table while boot services are active. | ||
/// | ||
/// # Panics | ||
/// | ||
/// Panics if the system table has not been set with `set_system_table`, or if | ||
/// boot services are not available (e.g. if [`exit_boot_services`] has been | ||
/// called). | ||
/// | ||
/// [`exit_boot_services`]: SystemTable::exit_boot_services | ||
pub fn system_table_boot() -> SystemTable<Boot> { | ||
let st = SYSTEM_TABLE.load(Ordering::Acquire); | ||
assert!(!st.is_null()); | ||
|
||
// SAFETY: the system table is valid per the requirements of `set_system_table`. | ||
unsafe { | ||
if (*st).boot_services.is_null() { | ||
panic!("boot services are not active"); | ||
} | ||
|
||
SystemTable::<Boot>::from_ptr(st.cast()).unwrap() | ||
} | ||
} | ||
|
||
/// Get the system table while runtime services are active. | ||
/// | ||
/// # Panics | ||
/// | ||
/// Panics if the system table has not been set with `set_system_table`, or if | ||
/// runtime services are not available. | ||
pub fn system_table_runtime() -> SystemTable<Runtime> { | ||
let st = SYSTEM_TABLE.load(Ordering::Acquire); | ||
assert!(!st.is_null()); | ||
|
||
// SAFETY: the system table is valid per the requirements of `set_system_table`. | ||
unsafe { | ||
if (*st).runtime_services.is_null() { | ||
panic!("runtime services are not active"); | ||
} | ||
|
||
SystemTable::<Runtime>::from_ptr(st.cast()).unwrap() | ||
} | ||
} | ||
|
||
/// Common trait implemented by all standard UEFI tables. | ||
pub trait Table { | ||
/// A unique number assigned by the UEFI specification | ||
/// to the standard tables. | ||
const SIGNATURE: u64; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strictly speaking, they are also active, but not exclusively, right?