1919//! [println_macro]: uefi::println!
2020
2121use crate :: prelude:: { Boot , SystemTable } ;
22- use crate :: Result ;
23- use crate :: StatusExt ;
24- use core:: ffi:: c_void;
25- use core:: ptr;
26- use core:: sync:: atomic:: { AtomicPtr , Ordering } ;
22+ use crate :: { table, Result } ;
2723#[ doc( hidden) ]
2824pub use println:: _print;
29- use uefi_raw:: Status ;
3025
3126#[ cfg( feature = "global_allocator" ) ]
3227mod global_allocator;
@@ -36,25 +31,6 @@ mod logger;
3631mod panic_handler;
3732mod println;
3833
39- /// Reference to the system table.
40- ///
41- /// This table is only fully safe to use until UEFI boot services have been exited.
42- /// After that, some fields and methods are unsafe to use, see the documentation of
43- /// UEFI's ExitBootServices entry point for more details.
44- static SYSTEM_TABLE : AtomicPtr < c_void > = AtomicPtr :: new ( core:: ptr:: null_mut ( ) ) ;
45-
46- #[ must_use]
47- fn system_table_opt ( ) -> Option < SystemTable < Boot > > {
48- let ptr = SYSTEM_TABLE . load ( Ordering :: Acquire ) ;
49- // Safety: the `SYSTEM_TABLE` pointer either be null or a valid system
50- // table.
51- //
52- // Null is the initial value, as well as the value set when exiting boot
53- // services. Otherwise, the value is set by the call to `init`, which
54- // requires a valid system table reference as input.
55- unsafe { SystemTable :: from_ptr ( ptr) }
56- }
57-
5834/// Obtains a pointer to the system table.
5935///
6036/// This is meant to be used by higher-level libraries,
@@ -66,7 +42,7 @@ fn system_table_opt() -> Option<SystemTable<Boot>> {
6642#[ must_use]
6743// TODO do we want to keep this public?
6844pub fn system_table ( ) -> SystemTable < Boot > {
69- system_table_opt ( ) . expect ( "The system table handle is not available " )
45+ table :: system_table_boot ( ) . expect ( "boot services are not active " )
7046}
7147
7248/// Initialize all helpers defined in [`uefi::helpers`] whose Cargo features
@@ -78,15 +54,8 @@ pub fn system_table() -> SystemTable<Boot> {
7854/// **PLEASE NOTE** that these helpers are meant for the pre exit boot service
7955/// epoch. Limited functionality might work after exiting them, such as logging
8056/// to the debugcon device.
57+ #[ allow( unused_variables) ] // `st` is unused if logger and allocator are disabled
8158pub fn init ( st : & mut SystemTable < Boot > ) -> Result < ( ) > {
82- if system_table_opt ( ) . is_some ( ) {
83- // Avoid double initialization.
84- return Status :: SUCCESS . to_result_with_val ( || ( ) ) ;
85- }
86-
87- // Setup the system table singleton
88- SYSTEM_TABLE . store ( st. as_ptr ( ) . cast_mut ( ) , Ordering :: Release ) ;
89-
9059 // Setup logging and memory allocation
9160
9261 #[ cfg( feature = "logger" ) ]
@@ -103,14 +72,6 @@ pub fn init(st: &mut SystemTable<Boot>) -> Result<()> {
10372}
10473
10574pub ( crate ) fn exit ( ) {
106- // DEBUG: The UEFI spec does not guarantee that this printout will work, as
107- // the services used by logging might already have been shut down.
108- // But it works on current OVMF, and can be used as a handy way to
109- // check that the callback does get called.
110- //
111- // info!("Shutting down the UEFI utility library");
112- SYSTEM_TABLE . store ( ptr:: null_mut ( ) , Ordering :: Release ) ;
113-
11475 #[ cfg( feature = "logger" ) ]
11576 logger:: disable ( ) ;
11677
0 commit comments