Skip to content

Commit e540f1e

Browse files
committed
Add feature single-hart
Signed-off-by: Chien Wong <[email protected]>
1 parent 15939f4 commit e540f1e

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

riscv-rt/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ edition = "2018"
1212

1313
[features]
1414
s-mode = []
15+
single-hart = []
1516

1617
[dependencies]
1718
r0 = "1.0.0"

riscv-rt/src/asm.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,21 @@ _abs_start:
8686
.option norelax
8787
la gp, __global_pointer$
8888
.option pop",
89-
#[cfg(feature = "s-mode")]
89+
#[cfg(all(not(feature = "single-hart"), feature = "s-mode"))]
9090
"mv t2, a0 // the hartid is passed as parameter by SMODE",
91-
#[cfg(not(feature = "s-mode"))]
91+
#[cfg(all(not(feature = "single-hart"), not(feature = "s-mode")))]
9292
"csrr t2, mhartid",
93+
#[cfg(not(feature = "single-hart"))]
9394
"lui t0, %hi(_max_hart_id)
9495
add t0, t0, %lo(_max_hart_id)
95-
bgtu t2, t0, abort
96-
97-
// Allocate stacks
96+
bgtu t2, t0, abort",
97+
"// Allocate stacks
9898
la sp, _stack_start
9999
lui t0, %hi(_hart_stack_size)
100100
add t0, t0, %lo(_hart_stack_size)",
101-
#[cfg(riscvm)]
101+
#[cfg(all(not(feature = "single-hart"), riscvm))]
102102
"mul t0, t2, t0",
103-
#[cfg(not(riscvm))]
103+
#[cfg(all(not(feature = "single-hart"), not(riscvm)))]
104104
"beqz t2, 2f // Jump if single-hart
105105
mv t1, t2
106106
mv t3, t0
@@ -110,8 +110,8 @@ _abs_start:
110110
bnez t1, 1b
111111
2: ",
112112
"sub sp, sp, t0
113-
114-
// Set frame pointer
113+
114+
// Set frame pointer
115115
add s0, sp, zero
116116
117117
jal zero, _start_rust
@@ -121,9 +121,9 @@ _abs_start:
121121

122122
/// Trap entry point (_start_trap). It saves caller saved registers, calls
123123
/// _start_trap_rust, restores caller saved registers and then returns.
124-
///
124+
///
125125
/// # Usage
126-
///
126+
///
127127
/// The macro takes 5 arguments:
128128
/// - `$STORE`: the instruction used to store a register in the stack (e.g. `sd` for riscv64)
129129
/// - `$LOAD`: the instruction used to load a register from the stack (e.g. `ld` for riscv64)

riscv-rt/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@
325325
//!
326326
//! # Features
327327
//!
328+
//! ## `single-hart`
329+
//!
330+
//! This feature saves a little code size by removing unnecessary stack space calculation if there is only one hart on the target.
331+
//!
328332
//! ## `s-mode`
329333
//!
330334
//! The supervisor mode feature (`s-mode`) can be activated via [Cargo features](https://doc.rust-lang.org/cargo/reference/features.html).

0 commit comments

Comments
 (0)