minimal.rs 1.1 KB

12345678910111213141516171819202122232425262728
  1. use multiboot2_header::builder::{HeaderBuilder, InformationRequestHeaderTagBuilder};
  2. use multiboot2_header::{
  3. HeaderTagFlag, HeaderTagISA, MbiTagType, Multiboot2Header, RelocatableHeaderTag,
  4. RelocatableHeaderTagPreference,
  5. };
  6. /// Small example that creates a Multiboot2 header and parses it afterwards.
  7. fn main() {
  8. // We create a Multiboot2 header during runtime here. A practical example is that your
  9. // program gets the header from a file and parses it afterwards.
  10. let mb2_hdr_bytes = HeaderBuilder::new(HeaderTagISA::I386)
  11. .relocatable_tag(RelocatableHeaderTag::new(
  12. HeaderTagFlag::Required,
  13. 0x1337,
  14. 0xdeadbeef,
  15. 4096,
  16. RelocatableHeaderTagPreference::None,
  17. ))
  18. .information_request_tag(
  19. InformationRequestHeaderTagBuilder::new(HeaderTagFlag::Required)
  20. .add_irs(&[MbiTagType::Cmdline, MbiTagType::BootLoaderName]),
  21. )
  22. .build();
  23. // Cast bytes in vector to Multiboot2 information structure
  24. let mb2_hdr = unsafe { Multiboot2Header::from_addr(mb2_hdr_bytes.as_ptr() as usize) };
  25. println!("{:#?}", mb2_hdr);
  26. }