|
327 | 327 | //! |
328 | 328 | //! ## `single-hart` |
329 | 329 | //! |
330 | | -//! This feature saves a little code size by removing unnecessary stack space calculation if there is only one hart on the target. |
| 330 | +//! This feature saves a little code size if there is only one hart on the target. |
331 | 331 | //! |
332 | 332 | //! ## `s-mode` |
333 | 333 | //! |
@@ -372,7 +372,10 @@ use core::sync::atomic::{compiler_fence, Ordering}; |
372 | 372 | use riscv::register::{scause as xcause, stvec as xtvec, stvec::TrapMode as xTrapMode}; |
373 | 373 |
|
374 | 374 | #[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; |
376 | 379 |
|
377 | 380 | pub use riscv_rt_macros::{entry, pre_init}; |
378 | 381 |
|
@@ -404,13 +407,20 @@ pub unsafe extern "C" fn start_rust(a0: usize, a1: usize, a2: usize) -> ! { |
404 | 407 | fn _mp_hook(hartid: usize) -> bool; |
405 | 408 | } |
406 | 409 |
|
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; |
412 | 422 |
|
413 | | - if _mp_hook(hartid) { |
| 423 | + if run_init { |
414 | 424 | __pre_init(); |
415 | 425 |
|
416 | 426 | // Initialize RAM |
@@ -661,6 +671,7 @@ pub unsafe extern "Rust" fn default_pre_init() {} |
661 | 671 | #[doc(hidden)] |
662 | 672 | #[no_mangle] |
663 | 673 | #[rustfmt::skip] |
| 674 | +#[cfg(not(feature = "single-hart"))] |
664 | 675 | pub extern "Rust" fn default_mp_hook(hartid: usize) -> bool { |
665 | 676 | match hartid { |
666 | 677 | 0 => true, |
|
0 commit comments