Skip to content

Commit 448eec9

Browse files
Merge pull request #126 from kevin-vigor/master
Ignore hartid in single-hart mode.
2 parents ea1deea + 0631b3a commit 448eec9

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

riscv-rt/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1919
- Removed bors in favor of GitHub Merge Queue
2020
- `start_trap_rust` is now marked as `unsafe`
2121
- Implement `r0` as inline assembly
22+
- mhartid CSR is no longer read in single-hart mode, assumed zero
2223

2324
## [v0.11.0] - 2023-01-18
2425

riscv-rt/src/lib.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,10 @@ use core::sync::atomic::{compiler_fence, Ordering};
372372
use riscv::register::{scause as xcause, stvec as xtvec, stvec::TrapMode as xTrapMode};
373373

374374
#[cfg(not(feature = "s-mode"))]
375-
use riscv::register::{mcause as xcause, mhartid, mtvec as xtvec, mtvec::TrapMode as xTrapMode};
375+
use riscv::register::{mcause as xcause, mtvec as xtvec, mtvec::TrapMode as xTrapMode};
376+
377+
#[cfg(all(not(feature = "single-hart"), not(feature = "s-mode")))]
378+
use riscv::register::mhartid;
376379

377380
pub use riscv_rt_macros::{entry, pre_init};
378381

@@ -404,13 +407,20 @@ pub unsafe extern "C" fn start_rust(a0: usize, a1: usize, a2: usize) -> ! {
404407
fn _mp_hook(hartid: usize) -> bool;
405408
}
406409

407-
// sbi passes hartid as first parameter (a0)
408-
#[cfg(feature = "s-mode")]
409-
let hartid = a0;
410-
#[cfg(not(feature = "s-mode"))]
411-
let hartid = mhartid::read();
410+
#[cfg(not(feature = "single-hart"))]
411+
let run_init = {
412+
// sbi passes hartid as first parameter (a0)
413+
#[cfg(feature = "s-mode")]
414+
let hartid = a0;
415+
#[cfg(not(feature = "s-mode"))]
416+
let hartid = mhartid::read();
417+
418+
_mp_hook(hartid)
419+
};
420+
#[cfg(feature = "single-hart")]
421+
let run_init = true;
412422

413-
if _mp_hook(hartid) {
423+
if run_init {
414424
__pre_init();
415425

416426
// Initialize RAM
@@ -661,6 +671,7 @@ pub unsafe extern "Rust" fn default_pre_init() {}
661671
#[doc(hidden)]
662672
#[no_mangle]
663673
#[rustfmt::skip]
674+
#[cfg(not(feature = "single-hart"))]
664675
pub extern "Rust" fn default_mp_hook(hartid: usize) -> bool {
665676
match hartid {
666677
0 => true,

0 commit comments

Comments
 (0)