From e2129101bd639f5c37d4217601b1ba06cd1038ed Mon Sep 17 00:00:00 2001 From: Kevin Vigor Date: Thu, 2 Nov 2023 10:24:56 -0600 Subject: [PATCH] Ignore hartid in single-hart mode. Don't bother checking hart ID on startup in single-hart mode. Allows use of cores with unusual mhartid values and saves a few instructions. --- src/lib.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3e86c49..5e5b1ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -368,12 +368,11 @@ mod asm; use core::sync::atomic::{compiler_fence, Ordering}; -#[cfg(feature = "s-mode")] +#[cfg(any(feature = "s-mode", feature = "single-hart"))] use riscv::register::{scause as xcause, stvec as xtvec, stvec::TrapMode as xTrapMode}; -#[cfg(not(feature = "s-mode"))] +#[cfg(all(not(feature = "s-mode"), not(feature = "single-hart")))] use riscv::register::{mcause as xcause, mhartid, mtvec as xtvec, mtvec::TrapMode as xTrapMode}; - pub use riscv_rt_macros::{entry, pre_init}; #[export_name = "error: riscv-rt appears more than once in the dependency graph"] @@ -405,10 +404,12 @@ pub unsafe extern "C" fn start_rust(a0: usize, a1: usize, a2: usize) -> ! { } // sbi passes hartid as first parameter (a0) - #[cfg(feature = "s-mode")] + #[cfg(all(feature = "s-mode", not(feature = "single-hart")))] let hartid = a0; - #[cfg(not(feature = "s-mode"))] + #[cfg(all(not(feature = "s-mode"), not(feature = "single-hart")))] let hartid = mhartid::read(); + #[cfg(feature = "single-hart")] + let hartid = 0; if _mp_hook(hartid) { __pre_init(); @@ -661,6 +662,7 @@ pub unsafe extern "Rust" fn default_pre_init() {} #[doc(hidden)] #[no_mangle] #[rustfmt::skip] +#[cfg(not(feature = "single-hart"))] pub extern "Rust" fn default_mp_hook(hartid: usize) -> bool { match hartid { 0 => true, @@ -670,6 +672,14 @@ pub extern "Rust" fn default_mp_hook(hartid: usize) -> bool { } } +#[doc(hidden)] +#[no_mangle] +#[rustfmt::skip] +#[cfg(feature = "single-hart")] +pub extern "Rust" fn default_mp_hook(_hartid: usize) -> bool { + true +} + /// Default implementation of `_setup_interrupts` that sets `mtvec`/`stvec` to a trap handler address. #[doc(hidden)] #[no_mangle]