Struct BootInformation

Source
pub struct BootInformation<'a>(/* private fields */);
Expand description

A Multiboot 2 Boot Information (MBI) accessor.

Implementations§

Source§

impl<'a> BootInformation<'a>

Source

pub unsafe fn load(ptr: *const BootInformationHeader) -> Result<Self, LoadError>

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 calling load or the program may observe unsynchronized mutation.
Source

pub fn start_address(&self) -> usize

Get the start address of the boot info.

Source

pub const fn as_ptr(&self) -> *const ()

Get the start address of the boot info as pointer.

Source

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();
Source

pub const fn total_size(&self) -> usize

Get the total size of the boot info struct.

Source

pub fn apm_tag(&self) -> Option<&ApmTag>

Search for the ApmTag.

Source

pub fn basic_memory_info_tag(&self) -> Option<&BasicMemoryInfoTag>

Search for the BasicMemoryInfoTag.

Source

pub fn boot_loader_name_tag(&self) -> Option<&BootLoaderNameTag>

Search for the BootLoaderNameTag.

Source

pub fn bootdev_tag(&self) -> Option<&BootdevTag>

Search for the BootdevTag.

Source

pub fn command_line_tag(&self) -> Option<&CommandLineTag>

Search for the CommandLineTag.

Source

pub fn efi_bs_not_exited_tag(&self) -> Option<&EFIBootServicesNotExitedTag>

Source

pub fn efi_memory_map_tag(&self) -> Option<&EFIMemoryMapTag>

Search for the EFIMemoryMapTag, 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 uefi instead.

Source

pub fn efi_sdt32_tag(&self) -> Option<&EFISdt32Tag>

Search for the EFISdt32Tag.

Source

pub fn efi_sdt64_tag(&self) -> Option<&EFISdt64Tag>

Search for the EFISdt64Tag.

Source

pub fn efi_ih32_tag(&self) -> Option<&EFIImageHandle32Tag>

Search for the EFIImageHandle32Tag.

Source

pub fn efi_ih64_tag(&self) -> Option<&EFIImageHandle64Tag>

Search for the EFIImageHandle64Tag.

Source

pub fn elf_sections(&self) -> Option<ElfSectionIter<'_>>

👎Deprecated: Use elf_sections_tag() instead and corresponding getters

Returns an ElfSectionIter iterator over the ELF Sections, if the ElfSectionsTag is present.

§Examples
if let Some(sections) = boot_info.elf_sections_tag().map(|tag| tag.sections()) {
    let mut total = 0;
    for section in sections {
        println!("Section: {:?}", section);
        total += 1;
    }
}
Source

pub fn elf_sections_tag(&self) -> Option<&ElfSectionsTag>

Search for the ElfSectionsTag.

Source

pub fn framebuffer_tag( &self, ) -> Option<Result<&FramebufferTag, UnknownFramebufferType>>

Search for the FramebufferTag. The result is Some(Err(e)), if the framebuffer type is unknown, while the framebuffer tag is present.

Source

pub fn load_base_addr_tag(&self) -> Option<&ImageLoadPhysAddrTag>

Search for the ImageLoadPhysAddrTag.

Source

pub fn memory_map_tag(&self) -> Option<&MemoryMapTag>

Search for the MemoryMapTag.

Source

pub fn module_tags(&self) -> ModuleIter<'_>

Get an iterator of all ModuleTags.

Source

pub fn network_tag(&self) -> Option<&NetworkTag>

Search for the NetworkTag.

Source

pub fn rsdp_v1_tag(&self) -> Option<&RsdpV1Tag>

Search for the RsdpV1Tag.

Source

pub fn rsdp_v2_tag(&self) -> Option<&RsdpV2Tag>

Search for the RsdpV2Tag.

Source

pub fn smbios_tag(&self) -> Option<&SmbiosTag>

Search for the SmbiosTag.

Source

pub fn vbe_info_tag(&self) -> Option<&VBEInfoTag>

Search for the VBEInfoTag.

Source

pub fn get_tag<T: Tag<IDType = TagType, Header = TagHeader> + ?Sized + 'a>( &'a self, ) -> Option<&'a T>

Public getter to find any Multiboot tag by its type, including specified and custom ones.

§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_ih64_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::mem;
use multiboot2::{BootInformation, BootInformationHeader, parse_slice_as_string, StringError, TagHeader, TagType, TagTypeId};    ///
use multiboot2_common::{MaybeDynSized, Tag};

#[repr(C)]
#[derive(multiboot2::Pointee)] // Only needed for DSTs.
struct CustomTag {
    header: TagHeader,
    some_other_prop: u32,
    // Begin of C string, for example.
    name: [u8],
}

impl CustomTag {
    fn name(&self) -> Result<&str, StringError> {
        parse_slice_as_string(&self.name)
    }
}

// Give the library hints how big this tag is.
impl MaybeDynSized for CustomTag {
    type Header = TagHeader;
    const BASE_SIZE: usize = mem::size_of::<TagHeader>() + mem::size_of::<u32>();

    // This differs for DSTs and normal structs. See function
    // documentation.
    fn dst_len(header: &TagHeader) -> usize {
        assert!(header.size >= Self::BASE_SIZE as u32);
        header.size as usize - Self::BASE_SIZE
    }
}

// Make the Tag identifiable.
impl Tag for CustomTag {
    type IDType = TagType;
    const ID: TagType = TagType::Custom(0x1337);
}

let mbi_ptr = 0xdeadbeef as *const BootInformationHeader;
let mbi = unsafe { BootInformation::load(mbi_ptr).unwrap() };

let tag = mbi
    .get_tag::<CustomTag>()
    .unwrap();
assert_eq!(tag.name(), Ok("name"));
Source

pub fn tags(&self) -> TagIter<'_>

Returns an iterator over all tags.

This is public to enable users to iterate over tags that appear multiple times, even tho this is unusual. However, it is recommended to use the tag getters as normal bootloaders provide most tags only once.

Trait Implementations§

Source§

impl Debug for BootInformation<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for BootInformation<'a>

§

impl<'a> RefUnwindSafe for BootInformation<'a>

§

impl<'a> Send for BootInformation<'a>

§

impl<'a> Sync for BootInformation<'a>

§

impl<'a> Unpin for BootInformation<'a>

§

impl<'a> UnwindSafe for BootInformation<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.