payload.rs 802 B

12345678910111213141516171819202122232425262728293031
  1. use core::arch::naked_asm;
  2. use core::sync::atomic::{AtomicBool, Ordering};
  3. use riscv::register::mstatus;
  4. use super::BootInfo;
  5. /// Determine whether the current hart is boot hart.
  6. ///
  7. /// Return true if the current hart is boot hart.
  8. pub fn is_boot_hart(_nonstandard_a2: usize) -> bool {
  9. static GENESIS: AtomicBool = AtomicBool::new(true);
  10. GENESIS.swap(false, Ordering::AcqRel)
  11. }
  12. pub fn get_boot_info(_nonstandard_a2: usize) -> BootInfo {
  13. BootInfo {
  14. next_address: get_image_address(),
  15. mpp: mstatus::MPP::Supervisor,
  16. }
  17. }
  18. #[naked]
  19. #[unsafe(link_section = ".payload")]
  20. pub extern "C" fn payload_image() {
  21. unsafe { naked_asm!(concat!(".incbin \"", env!("PROTOTYPER_PAYLOAD_PATH"), "\""),) }
  22. }
  23. #[inline]
  24. fn get_image_address() -> usize {
  25. payload_image as usize
  26. }