Skip to content

Commit 10190eb

Browse files
committed
multiboot2: Support setting the image load address
1 parent 5e7126c commit 10190eb

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

multiboot2/src/builder/information.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
BasicMemoryInfoTag, BootInformationInner, BootLoaderNameTag, CommandLineTag,
55
EFIImageHandle32, EFIImageHandle64, EFIBootServicesNotExited,
66
EFIMemoryMapTag, EFISdt32, EFISdt64, ElfSectionsTag, EndTag, FramebufferTag,
7-
MemoryMapTag, ModuleTag, RsdpV1Tag, RsdpV2Tag, SmbiosTag,
7+
ImageLoadPhysAddr, MemoryMapTag, ModuleTag, RsdpV1Tag, RsdpV2Tag, SmbiosTag,
88
};
99

1010
use alloc::boxed::Box;
@@ -25,6 +25,7 @@ pub struct Multiboot2InformationBuilder {
2525
efi_memory_map_tag: Option<Box<EFIMemoryMapTag>>,
2626
elf_sections_tag: Option<Box<ElfSectionsTag>>,
2727
framebuffer_tag: Option<Box<FramebufferTag>>,
28+
image_load_addr: Option<ImageLoadPhysAddr>,
2829
memory_map_tag: Option<Box<MemoryMapTag>>,
2930
module_tags: Vec<Box<ModuleTag>>,
3031
efisdt32: Option<EFISdt32>,
@@ -48,6 +49,7 @@ impl Multiboot2InformationBuilder {
4849
efi_memory_map_tag: None,
4950
elf_sections_tag: None,
5051
framebuffer_tag: None,
52+
image_load_addr: None,
5153
memory_map_tag: None,
5254
module_tags: Vec::new(),
5355
rsdp_v1_tag: None,
@@ -110,6 +112,9 @@ impl Multiboot2InformationBuilder {
110112
if let Some(tag) = &self.framebuffer_tag {
111113
len += Self::size_or_up_aligned(tag.byte_size())
112114
}
115+
if let Some(tag) = &self.image_load_addr {
116+
len += Self::size_or_up_aligned(tag.byte_size())
117+
}
113118
if let Some(tag) = &self.memory_map_tag {
114119
len += Self::size_or_up_aligned(tag.byte_size())
115120
}
@@ -190,6 +195,9 @@ impl Multiboot2InformationBuilder {
190195
if let Some(tag) = self.framebuffer_tag.as_ref() {
191196
Self::build_add_bytes(&mut data, &tag.struct_as_bytes(), false)
192197
}
198+
if let Some(tag) = self.image_load_addr.as_ref() {
199+
Self::build_add_bytes(&mut data, &tag.struct_as_bytes(), false)
200+
}
193201
if let Some(tag) = self.memory_map_tag.as_ref() {
194202
Self::build_add_bytes(&mut data, &tag.struct_as_bytes(), false)
195203
}
@@ -255,6 +263,10 @@ impl Multiboot2InformationBuilder {
255263
self.framebuffer_tag = Some(framebuffer_tag);
256264
}
257265

266+
pub fn image_load_addr(&mut self, image_load_addr: ImageLoadPhysAddr) {
267+
self.image_load_addr = Some(image_load_addr);
268+
}
269+
258270
pub fn memory_map_tag(&mut self, memory_map_tag: Box<MemoryMapTag>) {
259271
self.memory_map_tag = Some(memory_map_tag);
260272
}

multiboot2/src/image_load_addr.rs

+21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
use core::convert::TryInto;
2+
use core::mem::size_of;
3+
#[cfg(feature = "builder")]
4+
use crate::builder::traits::StructAsBytes;
15
use crate::TagType;
26

37
/// If the image has relocatable header tag, this tag contains the image's
@@ -11,8 +15,25 @@ pub struct ImageLoadPhysAddr {
1115
}
1216

1317
impl ImageLoadPhysAddr {
18+
#[cfg(feature = "builder")]
19+
pub fn new(load_base_addr: u32) -> Self {
20+
Self {
21+
typ: TagType::LoadBaseAddr,
22+
size: size_of::<Self>().try_into().unwrap(),
23+
load_base_addr,
24+
}
25+
}
26+
1427
/// Returns the load base address.
1528
pub fn load_base_addr(&self) -> u32 {
1629
self.load_base_addr
1730
}
1831
}
32+
33+
#[cfg(feature = "builder")]
34+
impl StructAsBytes for ImageLoadPhysAddr {
35+
fn byte_size(&self) -> usize {
36+
size_of::<Self>()
37+
}
38+
}
39+

0 commit comments

Comments
 (0)