Verified Commit 59221659 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Add system table function

parent 13d58c3c
use core::fmt::{self, Write};
use crate::UEFI;
pub struct Stdout;
impl Write for Stdout {
fn write_str(&mut self, string: &str) -> Result<(), fmt::Error> {
let uefi = unsafe { &mut *UEFI };
let st = crate::system_table();
for c in string.chars() {
let _ = (uefi.ConsoleOut.OutputString)(uefi.ConsoleOut, [c as u16, 0].as_ptr());
let _ = (st.ConsoleOut.OutputString)(st.ConsoleOut, [c as u16, 0].as_ptr());
if c == '\n' {
let _ = (uefi.ConsoleOut.OutputString)(uefi.ConsoleOut, ['\r' as u16, 0].as_ptr());
let _ = (st.ConsoleOut.OutputString)(st.ConsoleOut, ['\r' as u16, 0].as_ptr());
}
}
......
......@@ -87,4 +87,12 @@ pub mod rt;
static ALLOCATOR: uefi_alloc::Allocator = uefi_alloc::Allocator;
pub static mut HANDLE: uefi::Handle = uefi::Handle(0);
pub static mut UEFI: *mut uefi::system::SystemTable = 0 as *mut uefi::system::SystemTable;
pub static mut SYSTEM_TABLE: *mut uefi::system::SystemTable = 0 as *mut uefi::system::SystemTable;
pub fn system_table() -> &'static uefi::system::SystemTable {
unsafe { & *SYSTEM_TABLE }
}
pub unsafe fn system_table_mut() -> &'static mut uefi::system::SystemTable {
&mut *SYSTEM_TABLE
}
......@@ -2,18 +2,16 @@ use uefi::Handle;
use uefi::status::Status;
use uefi::system::SystemTable;
use crate::{HANDLE, UEFI};
#[no_mangle]
pub unsafe extern "win64" fn _start(handle: Handle, uefi: &'static mut SystemTable) -> Status {
pub unsafe extern "win64" fn _start(handle: Handle, system_table: &'static mut SystemTable) -> Status {
extern "C" {
fn main() -> Status;
}
HANDLE = handle;
UEFI = uefi;
crate::HANDLE = handle;
crate::SYSTEM_TABLE = system_table;
uefi_alloc::init(::core::mem::transmute(&mut *UEFI));
uefi_alloc::init(::core::mem::transmute(system_table));
main()
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment