|
1 | 1 | use crate::{
|
2 | 2 | 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, |
5 | 6 | };
|
6 | 7 | use core::convert::TryInto;
|
7 | 8 | use core::fmt::{Debug, Formatter};
|
@@ -107,6 +108,65 @@ impl<'a> Multiboot2Header<'a> {
|
107 | 108 | pub const fn calc_checksum(magic: u32, arch: HeaderTagISA, length: u32) -> u32 {
|
108 | 109 | Multiboot2BasicHeader::calc_checksum(magic, arch, length)
|
109 | 110 | }
|
| 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 | + } |
110 | 170 | }
|
111 | 171 |
|
112 | 172 | impl<'a> Debug for Multiboot2Header<'a> {
|
|
0 commit comments