// SPDX-License-Identifier: MIT OR Apache-2.0 // // Copyright (c) 2018-2021 Andre Richter //! BSP Memory Management. use core::{cell::UnsafeCell, ops::RangeInclusive}; //-------------------------------------------------------------------------------------------------- // Private Definitions //-------------------------------------------------------------------------------------------------- // Symbols from the linker script. extern "Rust" { static __rx_start: UnsafeCell<()>; static __bss_start: UnsafeCell; static __bss_end_inclusive: UnsafeCell; } //-------------------------------------------------------------------------------------------------- // Private Code //-------------------------------------------------------------------------------------------------- /// Start address of the Read+Execute (RX) range. /// /// # Safety /// /// - Value is provided by the linker script and must be trusted as-is. #[inline(always)] fn rx_start() -> usize { unsafe { __rx_start.get() as usize } } //-------------------------------------------------------------------------------------------------- // Public Code //-------------------------------------------------------------------------------------------------- /// Exclusive end address of the boot core's stack. #[inline(always)] pub fn boot_core_stack_end() -> usize { rx_start() } /// Return the inclusive range spanning the .bss section. /// /// # Safety /// /// - Values are provided by the linker script and must be trusted as-is. /// - The linker-provided addresses must be u64 aligned. pub fn bss_range_inclusive() -> RangeInclusive<*mut u64> { let range; unsafe { range = RangeInclusive::new(__bss_start.get(), __bss_end_inclusive.get()); } assert!(!range.is_empty()); range }