Skip to content

Commit 3c1359b

Browse files
committed
Set _hart_stack_size to size of stack for single-hart
Single core devices have no reason to split the stack in multiples, so just set it to use the entire available stack.
1 parent 6e161a4 commit 3c1359b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

riscv-rt/build.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ fn add_linker_script(arch_width: u32) -> io::Result<()> {
1111
let mut content = fs::read_to_string("link.x.in")?;
1212
content = content.replace("${ARCH_WIDTH}", &arch_width.to_string());
1313

14+
// Single core devices can use the entire stack, no need to limit it.
15+
let hart_stack_size = if env::var_os("CARGO_FEATURE_SINGLE_HART").is_some() {
16+
"SIZEOF(.stack)"
17+
} else {
18+
"2K"
19+
};
20+
21+
content = content.replace("${HART_STACK_SIZE}", hart_stack_size);
22+
1423
// Get target-dependent linker configuration and replace ${INCLUDE_LINKER_FILES} with it
1524
let mut include_content = String::new();
1625

riscv-rt/link.x.in

Lines changed: 1 addition & 1 deletion
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 = ${HART_STACK_SIZE});
7676
PROVIDE(_heap_size = 0);
7777

7878
SECTIONS

0 commit comments

Comments
 (0)