main.rs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #![no_main]
  2. #![no_std]
  3. #![feature(error_in_core)]
  4. extern crate alloc;
  5. #[macro_use]
  6. extern crate util;
  7. core::arch::global_asm!(include_str!("start.S"), options(att_syntax));
  8. core::arch::global_asm!(include_str!("multiboot2_header.S"));
  9. use multiboot2::BootInformation;
  10. use util::{init_environment, qemu_exit_success};
  11. mod verify;
  12. /// Entry into the Rust code from assembly.
  13. #[no_mangle]
  14. fn rust_entry(multiboot2_magic: u32, multiboot2_hdr: u32) -> ! {
  15. main(multiboot2_magic, multiboot2_hdr).expect("Should run multiboot2 integration test");
  16. log::info!("Integration test finished successfully");
  17. qemu_exit_success()
  18. }
  19. /// Executes the main logic.
  20. fn main(multiboot2_magic: u32, multiboot2_hdr: u32) -> anyhow::Result<()> {
  21. init_environment();
  22. if multiboot2_magic != multiboot2::MAGIC {
  23. Err(anyhow::Error::msg("Invalid bootloader magic"))?
  24. }
  25. log::debug!("multiboot2_hdr={multiboot2_hdr:x?}, multiboot2_magic=0x{multiboot2_magic:x?}");
  26. let mbi_ptr = (multiboot2_hdr as *const u8).cast();
  27. let mbi = unsafe { BootInformation::load(mbi_ptr) }.map_err(anyhow::Error::msg)?;
  28. verify::run(&mbi)
  29. }