Skip to content

Commit 18e34d9

Browse files
committed
multiboot2-header: Add getters for the tags
1 parent 6e24c7f commit 18e34d9

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

multiboot2-header/src/header.rs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::{
22
AddressHeaderTag, ConsoleHeaderTag, EfiBootServiceHeaderTag, EndHeaderTag,
33
EntryAddressHeaderTag, EntryEfi32HeaderTag, EntryEfi64HeaderTag, FramebufferHeaderTag,
4-
HeaderTag, HeaderTagISA, HeaderTagType, InformationRequestHeaderTag, RelocatableHeaderTag,
4+
HeaderTag, HeaderTagISA, HeaderTagType, InformationRequestHeaderTag, ModuleAlignHeaderTag,
5+
RelocatableHeaderTag,
56
};
67
use core::convert::TryInto;
78
use core::fmt::{Debug, Formatter};
@@ -110,6 +111,66 @@ impl<'a> Multiboot2Header<'a> {
110111
pub const fn calc_checksum(magic: u32, arch: HeaderTagISA, length: u32) -> u32 {
111112
Multiboot2BasicHeader::calc_checksum(magic, arch, length)
112113
}
114+
115+
/// Search for the address header tag.
116+
pub fn address_tag(&self) -> Option<&AddressHeaderTag> {
117+
self.get_tag(HeaderTagType::Address)
118+
.map(|tag| unsafe { &*(tag as *const HeaderTag as *const AddressHeaderTag) })
119+
}
120+
121+
/// Search for the entry address header tag.
122+
pub fn entry_address_tag(&self) -> Option<&EntryAddressHeaderTag> {
123+
self.get_tag(HeaderTagType::EntryAddress)
124+
.map(|tag| unsafe { &*(tag as *const HeaderTag as *const EntryAddressHeaderTag) })
125+
}
126+
127+
/// Search for the EFI32 entry address header tag.
128+
pub fn entry_address_efi32_tag(&self) -> Option<&EntryEfi32HeaderTag> {
129+
self.get_tag(HeaderTagType::EntryAddressEFI32)
130+
.map(|tag| unsafe { &*(tag as *const HeaderTag as *const EntryEfi32HeaderTag) })
131+
}
132+
133+
/// Search for the EFI64 entry address header tag.
134+
pub fn entry_address_efi64_tag(&self) -> Option<&EntryEfi64HeaderTag> {
135+
self.get_tag(HeaderTagType::EntryAddressEFI64)
136+
.map(|tag| unsafe { &*(tag as *const HeaderTag as *const EntryEfi64HeaderTag) })
137+
}
138+
139+
/// Search for the console flags header tag.
140+
pub fn console_flags_tag(&self) -> Option<&ConsoleHeaderTag> {
141+
self.get_tag(HeaderTagType::ConsoleFlags)
142+
.map(|tag| unsafe { &*(tag as *const HeaderTag as *const ConsoleHeaderTag) })
143+
}
144+
145+
/// Search for the framebuffer header tag.
146+
pub fn framebuffer_tag(&self) -> Option<&FramebufferHeaderTag> {
147+
self.get_tag(HeaderTagType::Framebuffer)
148+
.map(|tag| unsafe { &*(tag as *const HeaderTag as *const FramebufferHeaderTag) })
149+
}
150+
151+
/// Search for the module align header tag.
152+
pub fn module_align_tag(&self) -> Option<&ModuleAlignHeaderTag> {
153+
self.get_tag(HeaderTagType::ModuleAlign)
154+
.map(|tag| unsafe { &*(tag as *const HeaderTag as *const ModuleAlignHeaderTag) })
155+
}
156+
157+
/// Search for the EFI Boot Services header tag.
158+
pub fn efi_boot_services_tag(&self) -> Option<&EfiBootServiceHeaderTag> {
159+
self.get_tag(HeaderTagType::EfiBS)
160+
.map(|tag| unsafe { &*(tag as *const HeaderTag as *const EfiBootServiceHeaderTag) })
161+
}
162+
163+
/// Search for the EFI32 entry address header tag.
164+
pub fn relocatable_tag(&self) -> Option<&RelocatableHeaderTag> {
165+
self.get_tag(HeaderTagType::Relocatable)
166+
.map(|tag| unsafe { &*(tag as *const HeaderTag as *const RelocatableHeaderTag) })
167+
}
168+
169+
fn get_tag(&self, typ: HeaderTagType) -> Option<&HeaderTag> {
170+
self.iter()
171+
.map(|tag| unsafe { tag.as_ref() }.unwrap())
172+
.find(|tag| tag.typ() == typ)
173+
}
113174
}
114175

115176
impl<'a> Debug for Multiboot2Header<'a> {

0 commit comments

Comments
 (0)