Skip to content

Commit 2d4db6b

Browse files
nicholasbishopphip1611
authored andcommitted
uefi: Use uefi_raw's SystemTable to implement SystemTable
1 parent 74e63cc commit 2d4db6b

File tree

1 file changed

+16
-60
lines changed

1 file changed

+16
-60
lines changed

uefi/src/table/system.rs

Lines changed: 16 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ use core::ffi::c_void;
22
use core::fmt::{Debug, Formatter};
33
use core::marker::PhantomData;
44
use core::ptr::NonNull;
5-
use core::{ptr, slice};
5+
use core::slice;
66

77
use crate::proto::console::text;
8-
use crate::{CStr16, Char16, Handle, Result, Status, StatusExt};
8+
use crate::{CStr16, Result, Status, StatusExt};
99

1010
use super::boot::{BootServices, MemoryDescriptor, MemoryMap, MemoryType};
1111
use super::runtime::{ResetType, RuntimeServices};
12-
use super::{cfg, Header, Revision};
12+
use super::{cfg, Revision};
1313

1414
/// Marker trait used to provide different views of the UEFI System Table.
1515
pub trait SystemTableView {}
@@ -47,7 +47,7 @@ impl SystemTableView for Runtime {}
4747
/// will be provided to replace it.
4848
#[repr(transparent)]
4949
pub struct SystemTable<View: SystemTableView> {
50-
table: *const SystemTableImpl,
50+
table: *const uefi_raw::table::system::SystemTable,
5151
_marker: PhantomData<View>,
5252
}
5353

@@ -56,13 +56,13 @@ impl<View: SystemTableView> SystemTable<View> {
5656
/// Return the firmware vendor string
5757
#[must_use]
5858
pub fn firmware_vendor(&self) -> &CStr16 {
59-
unsafe { CStr16::from_ptr((*self.table).fw_vendor) }
59+
unsafe { CStr16::from_ptr((*self.table).firmware_vendor.cast()) }
6060
}
6161

6262
/// Return the firmware revision
6363
#[must_use]
6464
pub const fn firmware_revision(&self) -> u32 {
65-
unsafe { (*self.table).fw_revision }
65+
unsafe { (*self.table).firmware_revision }
6666
}
6767

6868
/// Returns the revision of this table, which is defined to be
@@ -80,9 +80,10 @@ impl<View: SystemTableView> SystemTable<View> {
8080
unsafe {
8181
let table = &*self.table;
8282
table
83-
.cfg_table
83+
.configuration_table
84+
.cast::<cfg::ConfigTableEntry>()
8485
.as_ref()
85-
.map(|ptr| slice::from_raw_parts(ptr, table.nr_cfg))
86+
.map(|ptr| slice::from_raw_parts(ptr, table.number_of_configuration_table_entries))
8687
.unwrap_or(&[])
8788
}
8889
}
@@ -119,7 +120,7 @@ impl<View: SystemTableView> SystemTable<View> {
119120
impl SystemTable<Boot> {
120121
/// Returns the standard input protocol.
121122
pub fn stdin(&mut self) -> &mut text::Input {
122-
unsafe { &mut *(*self.table).stdin }
123+
unsafe { &mut *(*self.table).stdin.cast() }
123124
}
124125

125126
/// Returns the standard output protocol.
@@ -135,13 +136,13 @@ impl SystemTable<Boot> {
135136
/// Access runtime services
136137
#[must_use]
137138
pub const fn runtime_services(&self) -> &RuntimeServices {
138-
unsafe { &*(*self.table).runtime }
139+
unsafe { &*(*self.table).runtime_services.cast_const().cast() }
139140
}
140141

141142
/// Access boot services
142143
#[must_use]
143144
pub const fn boot_services(&self) -> &BootServices {
144-
unsafe { &*(*self.table).boot }
145+
unsafe { &*(*self.table).boot_services.cast_const().cast() }
145146
}
146147

147148
/// Get the size in bytes of the buffer to allocate for storing the memory
@@ -299,7 +300,7 @@ impl SystemTable<Runtime> {
299300
/// "Calling Conventions" chapter of the UEFI specification for details.
300301
#[must_use]
301302
pub const unsafe fn runtime_services(&self) -> &RuntimeServices {
302-
&*(*self.table).runtime
303+
&*(*self.table).runtime_services.cast_const().cast()
303304
}
304305

305306
/// Changes the runtime addressing mode of EFI firmware from physical to virtual.
@@ -325,11 +326,11 @@ impl SystemTable<Runtime> {
325326
let entry_size = core::mem::size_of::<MemoryDescriptor>();
326327
let entry_version = MemoryDescriptor::VERSION;
327328
let map_ptr = map.as_mut_ptr();
328-
(*(*self.table).runtime)
329+
self.runtime_services()
329330
.set_virtual_address_map(map_size, entry_size, entry_version, map_ptr)
330331
.to_result_with_val(|| {
331-
let new_table_ref =
332-
&mut *(new_system_table_virtual_addr as usize as *mut SystemTableImpl);
332+
let new_table_ref = &mut *(new_system_table_virtual_addr as usize
333+
as *mut uefi_raw::table::system::SystemTable);
333334
Self {
334335
table: new_table_ref,
335336
_marker: PhantomData,
@@ -345,51 +346,6 @@ impl SystemTable<Runtime> {
345346
}
346347
}
347348

348-
/// The actual UEFI system table
349-
#[repr(C)]
350-
struct SystemTableImpl {
351-
header: Header,
352-
/// Null-terminated string representing the firmware's vendor.
353-
fw_vendor: *const Char16,
354-
fw_revision: u32,
355-
stdin_handle: Handle,
356-
stdin: *mut text::Input,
357-
stdout_handle: Handle,
358-
stdout: *mut text::Output,
359-
stderr_handle: Handle,
360-
stderr: *mut text::Output,
361-
/// Runtime services table.
362-
runtime: *const RuntimeServices,
363-
/// Boot services table.
364-
boot: *const BootServices,
365-
/// Number of entries in the configuration table.
366-
nr_cfg: usize,
367-
/// Pointer to beginning of the array.
368-
cfg_table: *const cfg::ConfigTableEntry,
369-
}
370-
371349
impl<View: SystemTableView> super::Table for SystemTable<View> {
372350
const SIGNATURE: u64 = 0x5453_5953_2049_4249;
373351
}
374-
375-
impl Debug for SystemTableImpl {
376-
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
377-
f.debug_struct("UefiSystemTable")
378-
.field("header", &self.header)
379-
.field("fw_vendor", &(unsafe { CStr16::from_ptr(self.fw_vendor) }))
380-
.field("fw_revision", &self.fw_revision)
381-
.field("stdin_handle", &self.stdin_handle)
382-
.field("stdin", &self.stdin)
383-
.field("stdout_handle", &self.stdout_handle)
384-
.field("stdout", &self.stdout)
385-
.field("stderr_handle", &self.stderr_handle)
386-
.field("stderr", &self.stderr)
387-
.field("runtime", &self.runtime)
388-
// a little bit of extra work needed to call debug-fmt on the BootServices
389-
// instead of printing the raw pointer
390-
.field("boot", &(unsafe { ptr::read(self.boot) }))
391-
.field("nf_cfg", &self.nr_cfg)
392-
.field("cfg_table", &self.cfg_table)
393-
.finish()
394-
}
395-
}

0 commit comments

Comments
 (0)