Philipp Schuster 8ea06c7012 multiboot2-header: initial version of crate 3 سال پیش
..
examples 8ea06c7012 multiboot2-header: initial version of crate 3 سال پیش
src 8ea06c7012 multiboot2-header: initial version of crate 3 سال پیش
Cargo.toml 8ea06c7012 multiboot2-header: initial version of crate 3 سال پیش
Changelog.md 78b8a51c98 prepared cargo workspace, as discussed in PR #79 3 سال پیش
README.md 8ea06c7012 multiboot2-header: initial version of crate 3 سال پیش

README.md

multiboot2-header

Build crates.io docs

Rust library with type definitions and parsing functions for Multiboot2 headers. This library is no_std and can be used in bootloaders.

What this library is good for:

  • writing a small binary which writes you a valid Multiboot2 header into a file (such as header.bin)
  • understanding Multiboot2 headers better
  • analyze Multiboot2 headers at runtime

What this library is not optimal for:

  • compiling a Multiboot2 header statically into an object file using only Rust code

Example

use multiboot2_header::builder::Multiboot2HeaderBuilder;
use multiboot2_header::{ConsoleHeaderTag, HeaderTagFlag, HeaderTagISA, InformationRequestHeaderTagBuilder, MbiTagType, Multiboot2Header, RelocatableHeaderTag, RelocatableHeaderTagPreference, load_mb2_header};

/// Small example that creates a Multiboot2 header and parses it afterwards.
fn main() {
    // 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 = Multiboot2HeaderBuilder::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 { load_mb2_header(mb2_hdr_bytes.as_ptr() as usize) };
    println!("{:#?}", mb2_hdr);
}

License & Contribution

See main README file.