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>

source

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 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 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 fn total_size(&self) -> usize

Get the total size of the boot info struct.

source

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

Search for the basic memory info tag.

source

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

Search for the BootLoader name tag.

source

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

Search for the Command line tag.

source

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

Search for the EFI boot services not exited tag.

source

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.

source

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

Search for the EFI 32-bit SDT tag.

source

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

Search for the EFI 64-bit SDT tag.

source

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

Search for the EFI 32-bit image handle pointer tag.

source

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

Search for the EFI 64-bit image handle pointer tag.

source

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;
    }
}
source

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.

source

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

Search for the Image Load Base Physical Address tag.

source

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

Search for the Memory map tag.

source

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

Get an iterator of all module tags.

source

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

Search for the (ACPI 1.0) RSDP tag.

source

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

Search for the (ACPI 2.0 or later) RSDP tag.

source

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

Search for the SMBIOS tag.

source

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

Search for the VBE information tag.

source

pub fn get_tag<TagT: TagTrait + ?Sized + 'a>(&'a self) -> Option<&'a TagT>

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::str::Utf8Error;
use multiboot2::{BootInformation, BootInformationHeader, Tag, TagTrait, TagType, TagTypeId};

#[repr(C)]
#[derive(multiboot2::Pointee)] // Only needed for DSTs.
struct CustomTag {
    tag: TagTypeId,
    size: u32,
    // begin of inline string
    name: [u8],
}

// This implementation is only necessary for tags that are DSTs.
impl TagTrait for CustomTag {
    const ID: TagType = TagType::Custom(0x1337);

    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::parse_slice_as_string(&self.name)
    }
}
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"));

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

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

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

§

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>,

§

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.