From 93f2bba6e2373a551649db8979c1cf7b6adb5134 Mon Sep 17 00:00:00 2001 From: Chien Wong Date: Fri, 10 Nov 2023 19:16:42 +0800 Subject: [PATCH 1/3] Fix setting incorrect sp if single-hart If single-hart is enabled, the sp is set to _stack_start - _hart_stack_size, rather than _stack_start. Fix this. Fixes: 9a02223ac3b6 ("Add feature single-hart") Signed-off-by: Chien Wong --- src/asm.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/asm.rs b/src/asm.rs index c29d918..a0af873 100644 --- a/src/asm.rs +++ b/src/asm.rs @@ -85,7 +85,8 @@ _abs_start: .option push .option norelax la gp, __global_pointer$ - .option pop", + .option pop + // Allocate stacks", #[cfg(all(not(feature = "single-hart"), feature = "s-mode"))] "mv t2, a0 // the hartid is passed as parameter by SMODE", #[cfg(all(not(feature = "single-hart"), not(feature = "s-mode")))] @@ -93,9 +94,7 @@ _abs_start: #[cfg(not(feature = "single-hart"))] "lui t0, %hi(_max_hart_id) add t0, t0, %lo(_max_hart_id) - bgtu t2, t0, abort", - "// Allocate stacks - la sp, _stack_start + bgtu t2, t0, abort lui t0, %hi(_hart_stack_size) add t0, t0, %lo(_hart_stack_size)", #[cfg(all(not(feature = "single-hart"), riscvm))] @@ -109,9 +108,10 @@ _abs_start: addi t1, t1, -1 bnez t1, 1b 2: ", - "sub sp, sp, t0 - - // Set frame pointer + "la sp, _stack_start", + #[cfg(not(feature = "single-hart"))] + "sub sp, sp, t0", + "// Set frame pointer add s0, sp, zero jal zero, _start_rust From 13364069ace221c01991f2b2bc8a2337ab1b74ba Mon Sep 17 00:00:00 2001 From: Chien Wong Date: Fri, 10 Nov 2023 19:20:40 +0800 Subject: [PATCH 2/3] Add 'single-hart' changelog entry Signed-off-by: Chien Wong --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3557b3..5e022be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - New GitHub workflow for checking invalid labels in PRs - New GitHub workflow for checking modifications on CHANGELOG.md - New GitHub workflow for checking clippy lints in PRs +- Optional cargo feature `single-hart` for single CPU targets ### Changed From 97f9b6a3c5c2542f1eb01713898e9bd05034faf9 Mon Sep 17 00:00:00 2001 From: Chien Wong Date: Fri, 10 Nov 2023 19:23:53 +0800 Subject: [PATCH 3/3] Update doc on single-hart Signed-off-by: Chien Wong --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 422f3f2..54e5c01 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -327,7 +327,7 @@ //! //! ## `single-hart` //! -//! This feature saves a little code size by removing unnecessary stack space calculation if there is only one hart on the target. +//! This feature saves a little code size if there is only one hart on the target. //! //! ## `s-mode` //!