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 thesize
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
frommultiboot2
-crate. Serialized form ofTagType
that matches the binary representation (u32
). The abstraction corresponds to thetyp
/type
field of a Multiboot2Tag
. This type can easily be created from or converted toTagType
. - 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 (seecrate::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 atHeaderBuilder
(requires thebuilder
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§
- Possible flags for
ConsoleHeaderTag
. - Flags for Multiboot2 header tags.
- ISA/ARCH in Multiboot2 header.
- Possible types for header tags of a Multiboot2 header. The names and values are taken from the example C code at the bottom of the Multiboot2 specification. This value stands in the
typ
property ofcrate::tags::HeaderTag
. - Errors that can occur when parsing a header from a slice. See
Multiboot2Header::find_header
. - Re-export of
multiboot2::TagType
frommultiboot2
-crate. Higher level abstraction forTagTypeId
that assigns each possible value to a specific semantic according to the specification. Additionally, it allows to use theTagType::Custom
variant. It is not binary compatible withTagTypeId
. - It contains load address placement suggestion for boot loader. Boot loader should follow it. ‘0’ means none, ‘1’ means load image at lowest possible address but not lower than min addr and ‘2’ means load image at highest possible address but not higher than max addr.
Constants§
- Magic value for a
Multiboot2Header
, as defined by the spec.