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

Ignore hartid in single-hart mode. #126

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")]
kevin-vigor marked this conversation as resolved.
Show resolved Hide resolved
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