You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.8 KiB
Rust
64 lines
1.8 KiB
Rust
5 years ago
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||
5 years ago
|
//
|
||
5 years ago
|
// Copyright (c) 2018-2020 Andre Richter <andre.o.richter@gmail.com>
|
||
5 years ago
|
|
||
|
//! Rust runtime initialization code.
|
||
|
|
||
4 years ago
|
use crate::{bsp, memory};
|
||
5 years ago
|
|
||
4 years ago
|
//--------------------------------------------------------------------------------------------------
|
||
|
// Private Code
|
||
|
//--------------------------------------------------------------------------------------------------
|
||
|
|
||
5 years ago
|
/// Zero out the .bss section.
|
||
|
///
|
||
|
/// # Safety
|
||
|
///
|
||
|
/// - Must only be called pre `kernel_init()`.
|
||
|
#[inline(always)]
|
||
|
unsafe fn zero_bss() {
|
||
4 years ago
|
memory::zero_volatile(bsp::memory::bss_range());
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
//--------------------------------------------------------------------------------------------------
|
||
|
// Public Code
|
||
|
//--------------------------------------------------------------------------------------------------
|
||
|
|
||
5 years ago
|
/// Equivalent to `crt0` or `c0` code in C/C++ world. Clears the `bss` section, then jumps to kernel
|
||
|
/// init code.
|
||
|
///
|
||
|
/// # Safety
|
||
|
///
|
||
|
/// - Only a single core must be active and running this function.
|
||
5 years ago
|
pub unsafe fn runtime_init() -> ! {
|
||
4 years ago
|
extern "Rust" {
|
||
|
fn kernel_init() -> !;
|
||
|
}
|
||
|
|
||
5 years ago
|
zero_bss();
|
||
4 years ago
|
kernel_init()
|
||
|
}
|
||
|
|
||
|
//--------------------------------------------------------------------------------------------------
|
||
|
// Testing
|
||
|
//--------------------------------------------------------------------------------------------------
|
||
|
|
||
|
#[cfg(test)]
|
||
|
mod tests {
|
||
|
use super::*;
|
||
|
use test_macros::kernel_test;
|
||
|
|
||
|
/// Check `bss` section layout.
|
||
|
#[kernel_test]
|
||
|
fn bss_section_is_sane() {
|
||
|
use core::mem;
|
||
|
|
||
|
let start = bsp::memory::bss_range().start as *const _ as usize;
|
||
|
let end = bsp::memory::bss_range().end as *const _ as usize;
|
||
5 years ago
|
|
||
4 years ago
|
assert_eq!(start % mem::size_of::<usize>(), 0);
|
||
|
assert_eq!(end % mem::size_of::<usize>(), 0);
|
||
|
assert!(end >= start);
|
||
|
}
|
||
5 years ago
|
}
|