minimal.rs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. use multiboot2_common::MaybeDynSized;
  2. use multiboot2_header::Builder;
  3. use multiboot2_header::{
  4. HeaderTagFlag, HeaderTagISA, InformationRequestHeaderTag, MbiTagType, Multiboot2Header,
  5. RelocatableHeaderTag, RelocatableHeaderTagPreference,
  6. };
  7. /// Small example that creates a Multiboot2 header and parses it afterwards.
  8. fn main() {
  9. // We create a Multiboot2 header during runtime here. A more practical
  10. // example, however, would be that you parse the header from kernel binary
  11. // at runtime.
  12. let mb2_hdr_bytes = Builder::new(HeaderTagISA::I386)
  13. .relocatable_tag(RelocatableHeaderTag::new(
  14. HeaderTagFlag::Required,
  15. 0x1337,
  16. 0xdeadbeef,
  17. 4096,
  18. RelocatableHeaderTagPreference::None,
  19. ))
  20. .information_request_tag(InformationRequestHeaderTag::new(
  21. HeaderTagFlag::Required,
  22. &[
  23. MbiTagType::Cmdline.into(),
  24. MbiTagType::BootLoaderName.into(),
  25. ],
  26. ))
  27. .build();
  28. // Cast bytes in vector to Multiboot2 information structure
  29. let ptr = mb2_hdr_bytes.as_bytes().as_ptr();
  30. let mb2_hdr = unsafe { Multiboot2Header::load(ptr.cast()) };
  31. let mb2_hdr = mb2_hdr.unwrap();
  32. println!("{:#?}", mb2_hdr);
  33. }