diff --git a/riscv-rt/CHANGELOG.md b/riscv-rt/CHANGELOG.md index 863f2823..e7d442b6 100644 --- a/riscv-rt/CHANGELOG.md +++ b/riscv-rt/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Main function no longer needs to be close to _start. A linker script may copy all code to RAM and keep .init in flash/ROM. +- By default, the stack is now split into equal parts based on the number of + harts. ### Fixed diff --git a/riscv-rt/link.x.in b/riscv-rt/link.x.in index c1879b0e..5d798400 100644 --- a/riscv-rt/link.x.in +++ b/riscv-rt/link.x.in @@ -72,7 +72,7 @@ ${INCLUDE_LINKER_FILES} PROVIDE(_stext = ORIGIN(REGION_TEXT)); PROVIDE(_stack_start = ORIGIN(REGION_STACK) + LENGTH(REGION_STACK)); PROVIDE(_max_hart_id = 0); -PROVIDE(_hart_stack_size = 2K); +PROVIDE(_hart_stack_size = SIZEOF(.stack) / (_max_hart_id + 1)); PROVIDE(_heap_size = 0); SECTIONS @@ -218,7 +218,7 @@ ASSERT(_stext + SIZEOF(.text) < ORIGIN(REGION_TEXT) + LENGTH(REGION_TEXT), " ERROR(riscv-rt): The .text section must be placed inside the REGION_TEXT region. Set _stext to an address smaller than 'ORIGIN(REGION_TEXT) + LENGTH(REGION_TEXT)'"); -ASSERT(SIZEOF(.stack) > (_max_hart_id + 1) * _hart_stack_size, " +ASSERT(SIZEOF(.stack) >= (_max_hart_id + 1) * _hart_stack_size, " ERROR(riscv-rt): .stack section is too small for allocating stacks for all the harts. Consider changing `_max_hart_id` or `_hart_stack_size`."); diff --git a/riscv-rt/src/lib.rs b/riscv-rt/src/lib.rs index 406adda6..08c87927 100644 --- a/riscv-rt/src/lib.rs +++ b/riscv-rt/src/lib.rs @@ -90,7 +90,10 @@ //! //! This symbol defines stack area size for *one* hart. //! -//! If omitted this symbol value will default to 2K. +//! If omitted this symbol value will default to `SIZEOF(.stack) / (_max_hart_id + 1)`. +//! +//! Note that due to alignment, each individual stack may differ slightly in +//! size. //! //! ### `_stack_start` //!