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.

83 lines
2.4 KiB
Rust

4 years ago
// SPDX-License-Identifier: MIT OR Apache-2.0
//
2 years ago
// Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com>
4 years ago
// Rust embedded logo for `make doc`.
#![doc(
html_logo_url = "https://raw.githubusercontent.com/rust-embedded/wg/master/assets/logo/ewg-logo-blue-white-on-transparent.png"
)]
4 years ago
//! The `kernel` binary.
#![feature(format_args_nl)]
#![no_main]
#![no_std]
use libkernel::{bsp, console, driver, exception, info, memory, time};
4 years ago
/// Early init code.
///
/// # Safety
///
/// - Only a single core must be active and running this function.
/// - The init calls in this function must appear in the correct order:
3 years ago
/// - MMU + Data caching must be activated at the earliest. Without it, any atomic operations,
/// e.g. the yet-to-be-introduced spinlocks in the device drivers (which currently employ
/// NullLocks instead of spinlocks), will fail to work (properly) on the RPi SoCs.
4 years ago
#[no_mangle]
unsafe fn kernel_init() -> ! {
use memory::mmu::interface::MMU;
4 years ago
exception::handling_init();
4 years ago
if let Err(string) = memory::mmu::mmu().enable_mmu_and_caching() {
4 years ago
panic!("MMU: {}", string);
}
// Initialize the BSP driver subsystem.
if let Err(x) = bsp::driver::init() {
panic!("Error initializing BSP driver subsystem: {}", x);
4 years ago
}
// Initialize all device drivers.
driver::driver_manager().init_drivers();
4 years ago
// println! is usable from here on.
// Transition from unsafe to safe.
kernel_main()
}
/// The main function running after the early init.
fn kernel_main() -> ! {
use console::console;
4 years ago
info!("{}", libkernel::version());
4 years ago
info!("Booting on: {}", bsp::board_name());
info!("MMU online. Special regions:");
bsp::memory::mmu::virt_mem_layout().print_layout();
4 years ago
let (_, privilege_level) = exception::current_privilege_level();
4 years ago
info!("Current privilege level: {}", privilege_level);
info!("Exception handling state:");
exception::asynchronous::print_state();
4 years ago
info!(
"Architectural timer resolution: {} ns",
time::time_manager().resolution().as_nanos()
4 years ago
);
info!("Drivers loaded:");
driver::driver_manager().enumerate();
4 years ago
info!("Echoing input now");
// Discard any spurious received characters before going into echo mode.
console().clear_rx();
4 years ago
loop {
let c = console().read_char();
console().write_char(c);
4 years ago
}
}