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

Commit

Permalink
Merge pull request #126 from kevin-vigor/master
Browse files Browse the repository at this point in the history
Ignore hartid in single-hart mode.
  • Loading branch information
romancardenas authored Nov 9, 2023
2 parents 28b916d + a906d89 commit 6624491
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Removed bors in favor of GitHub Merge Queue
- `start_trap_rust` is now marked as `unsafe`
- Implement `r0` as inline assembly
- mhartid CSR is no longer read in single-hart mode, assumed zero

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

Expand Down
25 changes: 18 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,10 @@ use core::sync::atomic::{compiler_fence, Ordering};
use riscv::register::{scause as xcause, stvec as xtvec, stvec::TrapMode as xTrapMode};

#[cfg(not(feature = "s-mode"))]
use riscv::register::{mcause as xcause, mhartid, mtvec as xtvec, mtvec::TrapMode as xTrapMode};
use riscv::register::{mcause as xcause, mtvec as xtvec, mtvec::TrapMode as xTrapMode};

#[cfg(all(not(feature = "single-hart"), not(feature = "s-mode")))]
use riscv::register::mhartid;

pub use riscv_rt_macros::{entry, pre_init};

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

// sbi passes hartid as first parameter (a0)
#[cfg(feature = "s-mode")]
let hartid = a0;
#[cfg(not(feature = "s-mode"))]
let hartid = mhartid::read();
#[cfg(not(feature = "single-hart"))]
let run_init = {
// sbi passes hartid as first parameter (a0)
#[cfg(feature = "s-mode")]
let hartid = a0;
#[cfg(not(feature = "s-mode"))]
let hartid = mhartid::read();

_mp_hook(hartid)
};
#[cfg(feature = "single-hart")]
let run_init = true;

if _mp_hook(hartid) {
if run_init {
__pre_init();

// Initialize RAM
Expand Down Expand Up @@ -661,6 +671,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 Down

0 comments on commit 6624491

Please sign in to comment.