Struct multiboot2::BootInformation
source · pub struct BootInformation<'a>(/* private fields */);
Expand description
A Multiboot 2 Boot Information (MBI) accessor.
Implementations§
source§impl<'a> BootInformation<'a>
impl<'a> BootInformation<'a>
sourcepub unsafe fn load(
ptr: *const BootInformationHeader
) -> Result<Self, MbiLoadError>
pub unsafe fn load( ptr: *const BootInformationHeader ) -> Result<Self, MbiLoadError>
Loads the BootInformation
from a pointer. The pointer must be valid
and aligned to an 8-byte boundary, as defined by the spec.
Example
use multiboot2::{BootInformation, BootInformationHeader};
fn kernel_entry(mb_magic: u32, mbi_ptr: u32) {
if mb_magic == multiboot2::MAGIC {
let boot_info = unsafe { BootInformation::load(mbi_ptr as *const BootInformationHeader).unwrap() };
let _cmd = boot_info.command_line_tag();
} else { /* Panic or use multiboot1 flow. */ }
}
Safety
ptr
must be valid for reading. Otherwise this function might cause invalid machine state or crash your binary (kernel). This can be the case in environments with standard environment (segfault), but also in boot environments, such as UEFI.- The memory at
ptr
must not be modified after callingload
or the program may observe unsynchronized mutation.
sourcepub fn start_address(&self) -> usize
pub fn start_address(&self) -> usize
Get the start address of the boot info.
sourcepub fn end_address(&self) -> usize
pub fn end_address(&self) -> usize
Get the end address of the boot info.
This is the same as doing:
let end_addr = boot_info.start_address() + boot_info.total_size();
sourcepub fn total_size(&self) -> usize
pub fn total_size(&self) -> usize
Get the total size of the boot info struct.
sourcepub fn basic_memory_info_tag(&self) -> Option<&BasicMemoryInfoTag>
pub fn basic_memory_info_tag(&self) -> Option<&BasicMemoryInfoTag>
Search for the basic memory info tag.
sourcepub fn elf_sections(&self) -> Option<ElfSectionIter>
pub fn elf_sections(&self) -> Option<ElfSectionIter>
Returns an ElfSectionIter
iterator over the ELF Sections, if the
ElfSectionsTag
is present.
Examples
if let Some(sections) = boot_info.elf_sections() {
let mut total = 0;
for section in sections {
println!("Section: {:?}", section);
total += 1;
}
}
sourcepub fn memory_map_tag(&self) -> Option<&MemoryMapTag>
pub fn memory_map_tag(&self) -> Option<&MemoryMapTag>
Search for the Memory map tag.
Get an iterator of all module tags.
sourcepub fn boot_loader_name_tag(&self) -> Option<&BootLoaderNameTag>
pub fn boot_loader_name_tag(&self) -> Option<&BootLoaderNameTag>
Search for the BootLoader name tag.
sourcepub fn command_line_tag(&self) -> Option<&CommandLineTag>
pub fn command_line_tag(&self) -> Option<&CommandLineTag>
Search for the Command line tag.
sourcepub fn framebuffer_tag(
&self
) -> Option<Result<&FramebufferTag, UnknownFramebufferType>>
pub fn framebuffer_tag( &self ) -> Option<Result<&FramebufferTag, UnknownFramebufferType>>
Search for the VBE framebuffer tag. The result is Some(Err(e))
, if the
framebuffer type is unknown, while the framebuffer tag is present.
sourcepub fn efi_sdt_32_tag(&self) -> Option<&EFISdt32Tag>
pub fn efi_sdt_32_tag(&self) -> Option<&EFISdt32Tag>
Search for the EFI 32-bit SDT tag.
sourcepub fn efi_sdt_64_tag(&self) -> Option<&EFISdt64Tag>
pub fn efi_sdt_64_tag(&self) -> Option<&EFISdt64Tag>
Search for the EFI 64-bit SDT tag.
sourcepub fn rsdp_v1_tag(&self) -> Option<&RsdpV1Tag>
pub fn rsdp_v1_tag(&self) -> Option<&RsdpV1Tag>
Search for the (ACPI 1.0) RSDP tag.
sourcepub fn rsdp_v2_tag(&self) -> Option<&RsdpV2Tag>
pub fn rsdp_v2_tag(&self) -> Option<&RsdpV2Tag>
Search for the (ACPI 2.0 or later) RSDP tag.
sourcepub fn efi_memory_map_tag(&self) -> Option<&EFIMemoryMapTag>
pub fn efi_memory_map_tag(&self) -> Option<&EFIMemoryMapTag>
Search for the EFI Memory map tag, if the boot services were exited.
Otherwise, if the TagType::EfiBs
tag is present, this returns None
as it is strictly recommended to get the memory map from the uefi
services.
sourcepub fn efi_32_ih_tag(&self) -> Option<&EFIImageHandle32Tag>
pub fn efi_32_ih_tag(&self) -> Option<&EFIImageHandle32Tag>
Search for the EFI 32-bit image handle pointer tag.
sourcepub fn efi_64_ih_tag(&self) -> Option<&EFIImageHandle64Tag>
pub fn efi_64_ih_tag(&self) -> Option<&EFIImageHandle64Tag>
Search for the EFI 64-bit image handle pointer tag.
sourcepub fn efi_bs_not_exited_tag(&self) -> Option<&EFIBootServicesNotExitedTag>
pub fn efi_bs_not_exited_tag(&self) -> Option<&EFIBootServicesNotExitedTag>
Search for the EFI boot services not exited tag.
sourcepub fn load_base_addr_tag(&self) -> Option<&ImageLoadPhysAddrTag>
pub fn load_base_addr_tag(&self) -> Option<&ImageLoadPhysAddrTag>
Search for the Image Load Base Physical Address tag.
sourcepub fn vbe_info_tag(&self) -> Option<&VBEInfoTag>
pub fn vbe_info_tag(&self) -> Option<&VBEInfoTag>
Search for the VBE information tag.
sourcepub fn smbios_tag(&self) -> Option<&SmbiosTag>
pub fn smbios_tag(&self) -> Option<&SmbiosTag>
Search for the SMBIOS tag.
sourcepub fn get_tag<TagT: TagTrait + ?Sized + 'a, TagType: Into<TagTypeId>>(
&'a self,
typ: TagType
) -> Option<&'a TagT>
pub fn get_tag<TagT: TagTrait + ?Sized + 'a, TagType: Into<TagTypeId>>( &'a self, typ: TagType ) -> Option<&'a TagT>
Public getter to find any Multiboot tag by its type, including specified and custom ones.
The parameter can be of type u32
, TagType
, or TagTypeId
.
Specified or Custom Tags
The Multiboot2 specification specifies a list of tags, see TagType
.
However, it doesn’t forbid to use custom tags. Because of this, there
exists the TagType
abstraction. It is recommended to use this
getter only for custom tags. For specified tags, use getters, such as
Self::efi_64_ih_tag
.
Use Custom Tags
The following example shows how you may use this interface to parse custom tags from the MBI. If they are dynamically sized (DST), a few more special handling is required. This is reflected by code-comments.
use std::str::Utf8Error;
use multiboot2::{Tag, TagTrait, TagTypeId};
#[repr(C)]
#[derive(multiboot2::Pointee)] // Only needed for DSTs.
struct CustomTag {
// new type from the lib: has repr(u32)
tag: TagTypeId,
size: u32,
// begin of inline string
name: [u8],
}
// This implementation is only necessary for tags that are DSTs.
impl TagTrait for CustomTag {
fn dst_size(base_tag: &Tag) -> usize {
// The size of the sized portion of the custom tag.
let tag_base_size = 8; // id + size is 8 byte in size
assert!(base_tag.size >= 8);
base_tag.size as usize - tag_base_size
}
}
impl CustomTag {
fn name(&self) -> Result<&str, Utf8Error> {
Tag::get_dst_str_slice(&self.name)
}
}
let mbi = unsafe { multiboot2::load(0xdeadbeef).unwrap() };
let tag = mbi
.get_tag::<CustomTag, _>(0x1337)
.unwrap();
assert_eq!(tag.name(), Ok("name"));
Trait Implementations§
source§impl Debug for BootInformation<'_>
impl Debug for BootInformation<'_>
impl Send for BootInformation<'_>
Auto Trait Implementations§
impl<'a> RefUnwindSafe for BootInformation<'a>
impl<'a> Sync for BootInformation<'a>
impl<'a> Unpin for BootInformation<'a>
impl<'a> UnwindSafe for BootInformation<'a>
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T, U> Into<U> for Twhere
U: From<T>,
impl<T, U> Into<U> for Twhere
U: From<T>,
source§impl<T> TagTrait for Twhere
T: Pointee<Metadata = ()>,
impl<T> TagTrait for Twhere
T: Pointee<Metadata = ()>,
source§fn dst_size(_: &Tag) -> <T as Pointee>::Metadata
fn dst_size(_: &Tag) -> <T as Pointee>::Metadata
source§unsafe fn from_base_tag<'a>(tag: &Tag) -> &'a Self
unsafe fn from_base_tag<'a>(tag: &Tag) -> &'a Self
Self::dst_size
implementation. Read more