Crate multiboot2_header

source ·
Expand description

Rust library with type definitions and parsing functions for Multiboot2 headers, as well as a builder to build them at runtime. This library is no_std and can be used in bootloaders.

§Example

use multiboot2_header::builder::{InformationRequestHeaderTagBuilder, HeaderBuilder};
use multiboot2_header::{HeaderTagFlag, HeaderTagISA, MbiTagType, RelocatableHeaderTag, RelocatableHeaderTagPreference, Multiboot2Header};

// Small example that creates a Multiboot2 header and parses it afterwards.

// We create a Multiboot2 header during runtime here. A practical example is that your
// program gets the header from a file and parses it afterwards.
let mb2_hdr_bytes = HeaderBuilder::new(HeaderTagISA::I386)
    .relocatable_tag(RelocatableHeaderTag::new(
        HeaderTagFlag::Required,
        0x1337,
        0xdeadbeef,
        4096,
        RelocatableHeaderTagPreference::None,
    ))
    .information_request_tag(
        InformationRequestHeaderTagBuilder::new(HeaderTagFlag::Required)
            .add_irs(&[MbiTagType::Cmdline, MbiTagType::BootLoaderName]),
    )
    .build();

// Cast bytes in vector to Multiboot2 information structure
let mb2_hdr = unsafe { Multiboot2Header::load(mb2_hdr_bytes.as_ptr().cast()) };
println!("{:#?}", mb2_hdr);

§MSRV

The MSRV is 1.70.0 stable.

Modules§

  • Module for the builder-feature.

Structs§

  • This information does not need to be provided if the kernel image is in ELF format, but it must be provided if the image is in a.out format or in some other format. Required for legacy boot (BIOS). Determines load addresses.
  • Tells that a console must be available in MBI. Only relevant for legacy BIOS.
  • This tag indicates that payload supports starting without terminating UEFI boot services. Or in other words: The payload wants to use UEFI boot services.
  • Terminates a list of optional tags in a Multiboot2 header.
  • Specifies the physical address to which the boot loader should jump in order to start running the operating system. Not needed for ELF files.
  • This tag is taken into account only on EFI i386 platforms when Multiboot2 image header contains EFI boot services tag. Then entry point specified in ELF header and the entry address tag of Multiboot2 header are ignored.
  • This tag is taken into account only on EFI amd64 platforms when Multiboot2 image header contains EFI boot services tag. Then entry point specified in ELF header and the entry address tag of Multiboot2 header are ignored.
  • Specifies the preferred graphics mode. If this tag is present the bootloader assumes that the payload has framebuffer support. Note: This is only a recommended mode. Only relevant on legacy BIOS.
  • Common properties for all header tags. Other tags may have additional fields that depend on the typ and the size field. All tags share the same beginning of the struct.
  • Specifies what specific tag types the bootloader should provide inside the mbi.
  • Iterates the dynamically sized information request structure and finds all MBI tags that are requested.
  • Re-export of multiboot2::TagType from multiboot2-crate. Serialized form of TagType that matches the binary representation (u32). The abstraction corresponds to the typ/type field of a Multiboot2 Tag. This type can easily be created from or converted to TagType.
  • If this tag is present, provided boot modules must be page aligned.
  • The “basic” Multiboot2 header. This means only the properties, that are known during compile time. All other information are derived during runtime from the size property.
  • Wrapper type around a pointer to the Multiboot2 header. The Multiboot2 header is the Multiboot2BasicHeader followed by all tags (see crate::tags::HeaderTagType). Use this if you get a pointer to the header and just want to parse it. If you want to construct the type by yourself, please look at HeaderBuilder (requires the builder feature).
  • Iterator over all tags of a Multiboot2 header. The number of items is derived by the size/length of the header.
  • This tag indicates that the image is relocatable.

Enums§

Constants§