Skip to content

Commit d2f43f1

Browse files
committed
multiboot2: Support passing the EFI System Table
1 parent 70d92b2 commit d2f43f1

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

multiboot2/src/builder/information.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
use crate::builder::traits::StructAsBytes;
33
use crate::{
44
BasicMemoryInfoTag, BootInformationInner, BootLoaderNameTag, CommandLineTag,
5-
ElfSectionsTag, EndTag, FramebufferTag, MemoryMapTag, ModuleTag,
5+
EFISdt32, EFISdt64, ElfSectionsTag, EndTag, FramebufferTag, MemoryMapTag,
6+
ModuleTag,
67
};
78

89
use alloc::boxed::Box;
@@ -21,6 +22,8 @@ pub struct Multiboot2InformationBuilder {
2122
framebuffer_tag: Option<Box<FramebufferTag>>,
2223
memory_map_tag: Option<Box<MemoryMapTag>>,
2324
module_tags: Vec<Box<ModuleTag>>,
25+
efisdt32: Option<EFISdt32>,
26+
efisdt64: Option<EFISdt64>,
2427
}
2528

2629
impl Multiboot2InformationBuilder {
@@ -29,6 +32,8 @@ impl Multiboot2InformationBuilder {
2932
basic_memory_info_tag: None,
3033
boot_loader_name_tag: None,
3134
command_line_tag: None,
35+
efisdt32: None,
36+
efisdt64: None,
3237
elf_sections_tag: None,
3338
framebuffer_tag: None,
3439
memory_map_tag: None,
@@ -66,6 +71,12 @@ impl Multiboot2InformationBuilder {
6671
if let Some(tag) = &self.command_line_tag {
6772
len += Self::size_or_up_aligned(tag.byte_size())
6873
}
74+
if let Some(tag) = &self.efisdt32 {
75+
len += Self::size_or_up_aligned(tag.byte_size())
76+
}
77+
if let Some(tag) = &self.efisdt64 {
78+
len += Self::size_or_up_aligned(tag.byte_size())
79+
}
6980
if let Some(tag) = &self.elf_sections_tag {
7081
len += Self::size_or_up_aligned(tag.byte_size())
7182
}
@@ -119,6 +130,12 @@ impl Multiboot2InformationBuilder {
119130
if let Some(tag) = self.command_line_tag.as_ref() {
120131
Self::build_add_bytes(&mut data, &tag.struct_as_bytes(), false)
121132
}
133+
if let Some(tag) = self.efisdt32.as_ref() {
134+
Self::build_add_bytes(&mut data, &tag.struct_as_bytes(), false)
135+
}
136+
if let Some(tag) = self.efisdt64.as_ref() {
137+
Self::build_add_bytes(&mut data, &tag.struct_as_bytes(), false)
138+
}
122139
if let Some(tag) = self.elf_sections_tag.as_ref() {
123140
Self::build_add_bytes(&mut data, &tag.struct_as_bytes(), false)
124141
}
@@ -149,6 +166,14 @@ impl Multiboot2InformationBuilder {
149166
self.command_line_tag = Some(command_line_tag);
150167
}
151168

169+
pub fn efisdt32(&mut self, efisdt32: EFISdt32) {
170+
self.efisdt32 = Some(efisdt32);
171+
}
172+
173+
pub fn efisdt64(&mut self, efisdt64: EFISdt64) {
174+
self.efisdt64 = Some(efisdt64);
175+
}
176+
152177
pub fn elf_sections_tag(&mut self, elf_sections_tag: Box<ElfSectionsTag>) {
153178
self.elf_sections_tag = Some(elf_sections_tag);
154179
}

multiboot2/src/efi.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
//! All MBI tags related to (U)EFI.
22
3+
use core::mem::size_of;
4+
use core::convert::TryInto;
5+
36
use crate::TagType;
7+
#[cfg(feature = "builder")]
8+
use crate::builder::traits::StructAsBytes;
49

510
/// EFI system table in 32 bit mode
611
#[derive(Clone, Copy, Debug)]
@@ -12,12 +17,28 @@ pub struct EFISdt32 {
1217
}
1318

1419
impl EFISdt32 {
20+
/// Create a new tag to pass the EFI32 System Table pointer.
21+
pub fn new(pointer: u32) -> Self {
22+
Self {
23+
typ: TagType::Efi32,
24+
size: size_of::<Self>().try_into().unwrap(),
25+
pointer
26+
}
27+
}
28+
1529
/// The physical address of a i386 EFI system table.
1630
pub fn sdt_address(&self) -> usize {
1731
self.pointer as usize
1832
}
1933
}
2034

35+
#[cfg(feature = "builder")]
36+
impl StructAsBytes for EFISdt32 {
37+
fn byte_size(&self) -> usize {
38+
size_of::<Self>()
39+
}
40+
}
41+
2142
/// EFI system table in 64 bit mode
2243
#[derive(Clone, Copy, Debug)]
2344
#[repr(C)]
@@ -28,12 +49,28 @@ pub struct EFISdt64 {
2849
}
2950

3051
impl EFISdt64 {
52+
/// Create a new tag to pass the EFI64 System Table pointer.
53+
pub fn new(pointer: u64) -> Self {
54+
Self {
55+
typ: TagType::Efi64,
56+
size: size_of::<Self>().try_into().unwrap(),
57+
pointer
58+
}
59+
}
60+
3161
/// The physical address of a x86_64 EFI system table.
3262
pub fn sdt_address(&self) -> usize {
3363
self.pointer as usize
3464
}
3565
}
3666

67+
#[cfg(feature = "builder")]
68+
impl StructAsBytes for EFISdt64 {
69+
fn byte_size(&self) -> usize {
70+
size_of::<Self>()
71+
}
72+
}
73+
3774
/// Contains pointer to boot loader image handle.
3875
#[derive(Debug)]
3976
#[repr(C)]

0 commit comments

Comments
 (0)