Skip to content

Commit 4235ddb

Browse files
Merge pull request #296 from janderholm/master
Correct hart_stack_size assertion
2 parents c044fe8 + 467fbfc commit 4235ddb

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

riscv-rt/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
- Main function no longer needs to be close to _start. A linker script may copy
1313
all code to RAM and keep .init in flash/ROM.
14+
- By default, the stack is now split into equal parts based on the number of
15+
harts.
1416

1517
### Fixed
1618

riscv-rt/link.x.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ ${INCLUDE_LINKER_FILES}
7272
PROVIDE(_stext = ORIGIN(REGION_TEXT));
7373
PROVIDE(_stack_start = ORIGIN(REGION_STACK) + LENGTH(REGION_STACK));
7474
PROVIDE(_max_hart_id = 0);
75-
PROVIDE(_hart_stack_size = 2K);
75+
PROVIDE(_hart_stack_size = SIZEOF(.stack) / (_max_hart_id + 1));
7676
PROVIDE(_heap_size = 0);
7777

7878
SECTIONS
@@ -218,7 +218,7 @@ ASSERT(_stext + SIZEOF(.text) < ORIGIN(REGION_TEXT) + LENGTH(REGION_TEXT), "
218218
ERROR(riscv-rt): The .text section must be placed inside the REGION_TEXT region.
219219
Set _stext to an address smaller than 'ORIGIN(REGION_TEXT) + LENGTH(REGION_TEXT)'");
220220

221-
ASSERT(SIZEOF(.stack) > (_max_hart_id + 1) * _hart_stack_size, "
221+
ASSERT(SIZEOF(.stack) >= (_max_hart_id + 1) * _hart_stack_size, "
222222
ERROR(riscv-rt): .stack section is too small for allocating stacks for all the harts.
223223
Consider changing `_max_hart_id` or `_hart_stack_size`.");
224224

riscv-rt/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@
9090
//!
9191
//! This symbol defines stack area size for *one* hart.
9292
//!
93-
//! If omitted this symbol value will default to 2K.
93+
//! If omitted this symbol value will default to `SIZEOF(.stack) / (_max_hart_id + 1)`.
94+
//!
95+
//! Note that due to alignment, each individual stack may differ slightly in
96+
//! size.
9497
//!
9598
//! ### `_stack_start`
9699
//!

0 commit comments

Comments
 (0)