2020-03-28 12:25:18 +00:00
|
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
//
|
2021-01-01 10:28:32 +00:00
|
|
|
// Copyright (c) 2018-2021 Andre Richter <andre.o.richter@gmail.com>
|
2020-03-28 12:25:18 +00:00
|
|
|
|
|
|
|
//! BSP Memory Management.
|
|
|
|
|
2020-10-05 21:47:18 +00:00
|
|
|
use core::{cell::UnsafeCell, ops::RangeInclusive};
|
2020-09-28 19:40:59 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
// Private Definitions
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Symbols from the linker script.
|
2020-10-05 21:47:18 +00:00
|
|
|
extern "Rust" {
|
2021-03-16 21:36:06 +00:00
|
|
|
static __rx_start: UnsafeCell<()>;
|
|
|
|
|
2020-10-05 21:47:18 +00:00
|
|
|
static __bss_start: UnsafeCell<u64>;
|
|
|
|
static __bss_end_inclusive: UnsafeCell<u64>;
|
2020-09-28 19:40:59 +00:00
|
|
|
}
|
|
|
|
|
2020-03-28 12:25:18 +00:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
// Public Definitions
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2021-03-16 21:36:06 +00:00
|
|
|
/// The board's physical memory map.
|
2020-03-28 12:25:18 +00:00
|
|
|
#[rustfmt::skip]
|
|
|
|
pub(super) mod map {
|
2020-09-29 19:43:31 +00:00
|
|
|
|
2020-09-30 19:51:31 +00:00
|
|
|
pub const GPIO_OFFSET: usize = 0x0020_0000;
|
|
|
|
pub const UART_OFFSET: usize = 0x0020_1000;
|
2020-03-28 12:25:18 +00:00
|
|
|
|
|
|
|
/// Physical devices.
|
|
|
|
#[cfg(feature = "bsp_rpi3")]
|
|
|
|
pub mod mmio {
|
|
|
|
use super::*;
|
|
|
|
|
2020-09-30 19:51:31 +00:00
|
|
|
pub const START: usize = 0x3F00_0000;
|
|
|
|
pub const GPIO_START: usize = START + GPIO_OFFSET;
|
|
|
|
pub const PL011_UART_START: usize = START + UART_OFFSET;
|
2020-03-28 12:25:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Physical devices.
|
|
|
|
#[cfg(feature = "bsp_rpi4")]
|
|
|
|
pub mod mmio {
|
|
|
|
use super::*;
|
|
|
|
|
2020-09-30 19:51:31 +00:00
|
|
|
pub const START: usize = 0xFE00_0000;
|
|
|
|
pub const GPIO_START: usize = START + GPIO_OFFSET;
|
|
|
|
pub const PL011_UART_START: usize = START + UART_OFFSET;
|
2020-03-28 12:25:18 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-28 19:40:59 +00:00
|
|
|
|
2021-03-16 21:36:06 +00:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
// 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 }
|
|
|
|
}
|
|
|
|
|
2020-09-28 19:40:59 +00:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
// Public Code
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2020-09-29 19:43:31 +00:00
|
|
|
/// Exclusive end address of the boot core's stack.
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn boot_core_stack_end() -> usize {
|
2021-03-16 21:36:06 +00:00
|
|
|
rx_start()
|
2020-09-29 19:43:31 +00:00
|
|
|
}
|
|
|
|
|
2020-10-05 21:47:18 +00:00
|
|
|
/// Return the inclusive range spanning the .bss section.
|
2020-09-28 19:40:59 +00:00
|
|
|
///
|
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// - Values are provided by the linker script and must be trusted as-is.
|
|
|
|
/// - The linker-provided addresses must be u64 aligned.
|
2020-10-05 21:47:18 +00:00
|
|
|
pub fn bss_range_inclusive() -> RangeInclusive<*mut u64> {
|
2020-11-01 20:32:53 +00:00
|
|
|
let range;
|
|
|
|
unsafe {
|
|
|
|
range = RangeInclusive::new(__bss_start.get(), __bss_end_inclusive.get());
|
|
|
|
}
|
|
|
|
assert!(!range.is_empty());
|
|
|
|
|
|
|
|
range
|
2020-09-28 19:40:59 +00:00
|
|
|
}
|