Skip to content

Commit e56daa7

Browse files
committed
multiboot2-header: Add getters for the tags
1 parent e8f3e73 commit e56daa7

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed

multiboot2-header/src/header.rs

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

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

0 commit comments

Comments
 (0)