Skip to content

Commit 5922165

Browse files
committed
Add system table function
1 parent 13d58c3 commit 5922165

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/io.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
use core::fmt::{self, Write};
22

3-
use crate::UEFI;
4-
53
pub struct Stdout;
64

75
impl Write for Stdout {
86
fn write_str(&mut self, string: &str) -> Result<(), fmt::Error> {
9-
let uefi = unsafe { &mut *UEFI };
7+
let st = crate::system_table();
108

119
for c in string.chars() {
12-
let _ = (uefi.ConsoleOut.OutputString)(uefi.ConsoleOut, [c as u16, 0].as_ptr());
10+
let _ = (st.ConsoleOut.OutputString)(st.ConsoleOut, [c as u16, 0].as_ptr());
1311
if c == '\n' {
14-
let _ = (uefi.ConsoleOut.OutputString)(uefi.ConsoleOut, ['\r' as u16, 0].as_ptr());
12+
let _ = (st.ConsoleOut.OutputString)(st.ConsoleOut, ['\r' as u16, 0].as_ptr());
1513
}
1614
}
1715

src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,12 @@ pub mod rt;
8787
static ALLOCATOR: uefi_alloc::Allocator = uefi_alloc::Allocator;
8888

8989
pub static mut HANDLE: uefi::Handle = uefi::Handle(0);
90-
pub static mut UEFI: *mut uefi::system::SystemTable = 0 as *mut uefi::system::SystemTable;
90+
pub static mut SYSTEM_TABLE: *mut uefi::system::SystemTable = 0 as *mut uefi::system::SystemTable;
91+
92+
pub fn system_table() -> &'static uefi::system::SystemTable {
93+
unsafe { & *SYSTEM_TABLE }
94+
}
95+
96+
pub unsafe fn system_table_mut() -> &'static mut uefi::system::SystemTable {
97+
&mut *SYSTEM_TABLE
98+
}

src/rt.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ use uefi::Handle;
22
use uefi::status::Status;
33
use uefi::system::SystemTable;
44

5-
use crate::{HANDLE, UEFI};
6-
75
#[no_mangle]
8-
pub unsafe extern "win64" fn _start(handle: Handle, uefi: &'static mut SystemTable) -> Status {
6+
pub unsafe extern "win64" fn _start(handle: Handle, system_table: &'static mut SystemTable) -> Status {
97
extern "C" {
108
fn main() -> Status;
119
}
1210

13-
HANDLE = handle;
14-
UEFI = uefi;
11+
crate::HANDLE = handle;
12+
crate::SYSTEM_TABLE = system_table;
1513

16-
uefi_alloc::init(::core::mem::transmute(&mut *UEFI));
14+
uefi_alloc::init(::core::mem::transmute(system_table));
1715

1816
main()
1917
}

0 commit comments

Comments
 (0)