Skip to content

Commit ed316cb

Browse files
committed
multiboot2: Support setting the image handle pointer
1 parent 12f4642 commit ed316cb

File tree

2 files changed

+72
-3
lines changed

2 files changed

+72
-3
lines changed

multiboot2/src/builder/information.rs

+27-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
use crate::builder::traits::StructAsBytes;
33
use crate::{
44
BasicMemoryInfoTag, BootInformationInner, BootLoaderNameTag, CommandLineTag,
5-
EFIBootServicesNotExited, EFIMemoryMapTag, EFISdt32, EFISdt64, ElfSectionsTag, EndTag,
6-
FramebufferTag, MemoryMapTag, ModuleTag, RsdpV1Tag, RsdpV2Tag, SmbiosTag,
5+
EFIBootServicesNotExited, EFIImageHandle32, EFIImageHandle64, EFIMemoryMapTag, EFISdt32,
6+
EFISdt64, ElfSectionsTag, EndTag, FramebufferTag, MemoryMapTag, ModuleTag, RsdpV1Tag,
7+
RsdpV2Tag, SmbiosTag,
78
};
89

910
use alloc::boxed::Box;
@@ -19,6 +20,8 @@ pub struct Multiboot2InformationBuilder {
1920
boot_loader_name_tag: Option<Box<BootLoaderNameTag>>,
2021
command_line_tag: Option<Box<CommandLineTag>>,
2122
efi_boot_services_not_exited: Option<EFIBootServicesNotExited>,
23+
efi_image_handle32: Option<EFIImageHandle32>,
24+
efi_image_handle64: Option<EFIImageHandle64>,
2225
efi_memory_map_tag: Option<Box<EFIMemoryMapTag>>,
2326
elf_sections_tag: Option<Box<ElfSectionsTag>>,
2427
framebuffer_tag: Option<Box<FramebufferTag>>,
@@ -40,6 +43,8 @@ impl Multiboot2InformationBuilder {
4043
efisdt32: None,
4144
efisdt64: None,
4245
efi_boot_services_not_exited: None,
46+
efi_image_handle32: None,
47+
efi_image_handle64: None,
4348
efi_memory_map_tag: None,
4449
elf_sections_tag: None,
4550
framebuffer_tag: None,
@@ -90,6 +95,12 @@ impl Multiboot2InformationBuilder {
9095
if let Some(tag) = &self.efi_boot_services_not_exited {
9196
len += Self::size_or_up_aligned(tag.byte_size())
9297
}
98+
if let Some(tag) = &self.efi_image_handle32 {
99+
len += Self::size_or_up_aligned(tag.byte_size())
100+
}
101+
if let Some(tag) = &self.efi_image_handle64 {
102+
len += Self::size_or_up_aligned(tag.byte_size())
103+
}
93104
if let Some(tag) = &self.efi_memory_map_tag {
94105
len += Self::size_or_up_aligned(tag.byte_size())
95106
}
@@ -162,6 +173,12 @@ impl Multiboot2InformationBuilder {
162173
if let Some(tag) = self.efi_boot_services_not_exited.as_ref() {
163174
Self::build_add_bytes(&mut data, &tag.struct_as_bytes(), false)
164175
}
176+
if let Some(tag) = self.efi_image_handle32.as_ref() {
177+
Self::build_add_bytes(&mut data, &tag.struct_as_bytes(), false)
178+
}
179+
if let Some(tag) = self.efi_image_handle64.as_ref() {
180+
Self::build_add_bytes(&mut data, &tag.struct_as_bytes(), false)
181+
}
165182
if let Some(tag) = self.efi_memory_map_tag.as_ref() {
166183
Self::build_add_bytes(&mut data, &tag.struct_as_bytes(), false)
167184
}
@@ -216,6 +233,14 @@ impl Multiboot2InformationBuilder {
216233
self.efi_boot_services_not_exited = Some(EFIBootServicesNotExited::new());
217234
}
218235

236+
pub fn efi_image_handle32(&mut self, efi_image_handle32: EFIImageHandle32) {
237+
self.efi_image_handle32 = Some(efi_image_handle32);
238+
}
239+
240+
pub fn efi_image_handle64(&mut self, efi_image_handle64: EFIImageHandle64) {
241+
self.efi_image_handle64 = Some(efi_image_handle64);
242+
}
243+
219244
pub fn efi_memory_map_tag(&mut self, efi_memory_map_tag: Box<EFIMemoryMapTag>) {
220245
self.efi_memory_map_tag = Some(efi_memory_map_tag);
221246
}

multiboot2/src/efi.rs

+45-1
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,28 @@ pub struct EFIImageHandle32 {
8282
}
8383

8484
impl EFIImageHandle32 {
85+
#[cfg(feature = "builder")]
86+
pub fn new(pointer: u32) -> Self {
87+
Self {
88+
typ: TagType::Efi32Ih.into(),
89+
size: size_of::<Self>().try_into().unwrap(),
90+
pointer,
91+
}
92+
}
93+
8594
/// Returns the physical address of the EFI image handle.
8695
pub fn image_handle(&self) -> usize {
8796
self.pointer as usize
8897
}
8998
}
9099

100+
#[cfg(feature = "builder")]
101+
impl StructAsBytes for EFIImageHandle32 {
102+
fn byte_size(&self) -> usize {
103+
size_of::<Self>()
104+
}
105+
}
106+
91107
/// Contains pointer to boot loader image handle.
92108
#[derive(Debug)]
93109
#[repr(C)]
@@ -98,15 +114,31 @@ pub struct EFIImageHandle64 {
98114
}
99115

100116
impl EFIImageHandle64 {
117+
#[cfg(feature = "builder")]
118+
pub fn new(pointer: u64) -> Self {
119+
Self {
120+
typ: TagType::Efi64Ih.into(),
121+
size: size_of::<Self>().try_into().unwrap(),
122+
pointer,
123+
}
124+
}
125+
101126
/// Returns the physical address of the EFI image handle.
102127
pub fn image_handle(&self) -> usize {
103128
self.pointer as usize
104129
}
105130
}
106131

132+
#[cfg(feature = "builder")]
133+
impl StructAsBytes for EFIImageHandle64 {
134+
fn byte_size(&self) -> usize {
135+
size_of::<Self>()
136+
}
137+
}
138+
107139
#[cfg(test)]
108140
mod tests {
109-
use super::{EFISdt32, EFISdt64};
141+
use super::{EFIImageHandle32, EFIImageHandle64, EFISdt32, EFISdt64};
110142

111143
const ADDR: usize = 0xABCDEF;
112144

@@ -121,4 +153,16 @@ mod tests {
121153
let tag = EFISdt64::new(ADDR.try_into().unwrap());
122154
assert_eq!(tag.sdt_address(), ADDR);
123155
}
156+
157+
#[test]
158+
fn test_build_eftih32() {
159+
let tag = EFIImageHandle32::new(ADDR.try_into().unwrap());
160+
assert_eq!(tag.image_handle(), ADDR);
161+
}
162+
163+
#[test]
164+
fn test_build_eftih64() {
165+
let tag = EFIImageHandle32::new(ADDR.try_into().unwrap());
166+
assert_eq!(tag.image_handle(), ADDR);
167+
}
124168
}

0 commit comments

Comments
 (0)