Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Ignore hartid in single-hart mode.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kevin-vigor committed Nov 2, 2023
1 parent 28b916d commit e212910
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand All @@ -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]
Expand Down

0 comments on commit e212910

Please sign in to comment.