Trim unnecessary unsafe blocks

This commit is contained in:
gil 2024-05-18 23:22:04 -05:00
parent e7060b38bd
commit 304152dbeb
3 changed files with 22 additions and 8 deletions

View file

@ -50,12 +50,26 @@ unsafe extern "C" fn _entry() {
"li t0, (0b11 << 11) | (1 << 13)",
"csrw mstatus, t0",
"csrw mie, x0",
);
// TODO do hardware inits and wake other harts
"la t1, {kinit}",
"csrw mepc, t1",
"la ra, 2f",
"mret",
"2:",
kinit = sym kinit,
);
}
#[no_mangle]
extern "C" fn kinit() {
use crate::uart;
uart::Device::new(0x1000_0000);
}
#[no_mangle]
extern "C" fn kinit_hart() {}
#[inline]
unsafe fn write_tp(id: &usize) {
use core::arch::asm;

View file

@ -96,7 +96,7 @@ extern "C" fn start() -> ! {
// }
// println!("This should not print because the console is not initialised.");
unsafe { uart::init_console(0x1000_0000) };
uart::init_console(0x1000_0000);
println!("Hello, world!");
// print current hartid

View file

@ -14,7 +14,7 @@ impl Device {
/// Create a new UART device.
/// # Safety
/// `base` must be the base address of a UART device.
pub unsafe fn new(base: usize) -> Self {
pub fn new(base: usize) -> Self {
use core::ptr::write_volatile;
let addr = base as *mut u8;
// Set data size to 8 bits.
@ -64,9 +64,9 @@ impl core::fmt::Write for Device {
/// Initialise the UART debugging console.
/// # Safety
/// `base` must point to the base address of a UART device.
pub unsafe fn init_console(base: usize) {
let mut console = CONSOLE.lock();
*console = Some(unsafe { Device::new(base) });
pub fn init_console(base: usize) {
let mut console: spinning_top::lock_api::MutexGuard<spinning_top::RawSpinlock, Option<Device>> = CONSOLE.lock();
*console = Some(Device::new(base));
}
/// Prints a formatted string to the [CONSOLE].