|
1 | 1 | use crate::{
|
2 | 2 | AddressHeaderTag, ConsoleHeaderTag, EfiBootServiceHeaderTag, EndHeaderTag,
|
3 | 3 | EntryAddressHeaderTag, EntryEfi32HeaderTag, EntryEfi64HeaderTag, FramebufferHeaderTag,
|
4 |
| - HeaderTag, HeaderTagISA, HeaderTagType, InformationRequestHeaderTag, RelocatableHeaderTag, |
| 4 | + HeaderTag, HeaderTagISA, HeaderTagType, InformationRequestHeaderTag, ModuleAlignHeaderTag, |
| 5 | + RelocatableHeaderTag, |
5 | 6 | };
|
6 | 7 | use core::convert::TryInto;
|
7 | 8 | use core::fmt::{Debug, Formatter};
|
@@ -110,6 +111,66 @@ impl<'a> Multiboot2Header<'a> {
|
110 | 111 | pub const fn calc_checksum(magic: u32, arch: HeaderTagISA, length: u32) -> u32 {
|
111 | 112 | Multiboot2BasicHeader::calc_checksum(magic, arch, length)
|
112 | 113 | }
|
| 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 | + } |
113 | 174 | }
|
114 | 175 |
|
115 | 176 | impl<'a> Debug for Multiboot2Header<'a> {
|
|
0 commit comments