use crate::proto::console::text::{Input, Output};
use crate::table::cfg::ConfigTableEntry;
use crate::table::{self, Revision};
use crate::{CStr16, Char16};
use core::slice;
#[must_use]
pub fn firmware_vendor() -> &'static CStr16 {
let st = table::system_table_raw_panicking();
let st = unsafe { st.as_ref() };
let vendor: *const Char16 = st.firmware_vendor.cast();
unsafe { CStr16::from_ptr(vendor) }
}
#[must_use]
pub fn firmware_revision() -> u32 {
let st = table::system_table_raw_panicking();
let st = unsafe { st.as_ref() };
st.firmware_revision
}
#[must_use]
pub fn uefi_revision() -> Revision {
let st = table::system_table_raw_panicking();
let st = unsafe { st.as_ref() };
st.header.revision
}
pub fn with_config_table<F, R>(mut f: F) -> R
where
F: FnMut(&[ConfigTableEntry]) -> R,
{
let st = table::system_table_raw_panicking();
let st = unsafe { st.as_ref() };
let ptr: *const ConfigTableEntry = st.configuration_table.cast();
let len = st.number_of_configuration_table_entries;
let slice = if ptr.is_null() {
&[]
} else {
unsafe { slice::from_raw_parts(ptr, len) }
};
f(slice)
}
pub fn with_stdin<F, R>(mut f: F) -> R
where
F: FnMut(&mut Input) -> R,
{
let st = table::system_table_raw_panicking();
let st = unsafe { st.as_ref() };
assert!(!st.boot_services.is_null(), "boot services are not active");
assert!(!st.stdin.is_null(), "stdin is not available");
let stdin: *mut Input = st.stdin.cast();
let stdin = unsafe { &mut *stdin };
f(stdin)
}
pub fn with_stdout<F, R>(mut f: F) -> R
where
F: FnMut(&mut Output) -> R,
{
let st = table::system_table_raw_panicking();
let st = unsafe { st.as_ref() };
assert!(!st.boot_services.is_null(), "boot services are not active");
assert!(!st.stdout.is_null(), "stdout is not available");
let stdout: *mut Output = st.stdout.cast();
let stdout = unsafe { &mut *stdout };
f(stdout)
}
pub fn with_stderr<F, R>(mut f: F) -> R
where
F: FnMut(&mut Output) -> R,
{
let st = table::system_table_raw_panicking();
let st = unsafe { st.as_ref() };
assert!(!st.boot_services.is_null(), "boot services are not active");
assert!(!st.stderr.is_null(), "stderr is not available");
let stderr: *mut Output = st.stderr.cast();
let stderr = unsafe { &mut *stderr };
f(stderr)
}
#[cfg(test)]
mod tests {
use super::*;
#[allow(dead_code)]
#[allow(clippy::assertions_on_constants)]
fn with_config_table_compile_test() {
assert!(false, "compile test only");
let mut acpi2_address = None;
with_config_table(|slice| {
for i in slice {
if i.guid == ConfigTableEntry::ACPI2_GUID {
acpi2_address = Some(i.address);
break;
}
}
});
}
}