Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Fix setting incorrect sp if single-hart #128

Merged
merged 3 commits into from
Nov 10, 2023

Conversation

ivq
Copy link
Contributor

@ivq ivq commented Nov 10, 2023

The PR #119 introduced a bug that if feature single-hart is enabled, stack pointer is
not set properly. That is:

# near _abs_start
# ...
20000042:	4e81                	li	t4,0
20000044:	4f01                	li	t5,0
20000046:	4f81                	li	t6,0

20000048 <.Lpcrel_hi0>:
20000048:	60000197          	auipc	gp,0x60000
2000004c:	7b818193          	addi	gp,gp,1976 # 80000800 <__global_pointer$>

20000050 <.Lpcrel_hi1>:
20000050:	60008117          	auipc	sp,0x60008
20000054:	fb010113          	addi	sp,sp,-80 # 80008000 <_sstack>
20000058:	000012b7          	lui	t0,0x1
2000005c:	80028293          	addi	t0,t0,-2048 # 800 <_hart_stack_size>
20000060:	40510133          	sub	sp,sp,t0 # BUG here: sp is set to _sstack(equals to _stack_start) - _hart_stack_size
20000064:	840a                	mv	s0,sp
20000066:	0040006f          	j	2000006a <_start_rust>

The stack pointer should be set to _stack_start in this case. Also, the operations on _hart_stack_size should be removed.

After the fix:

# near _abs_start
# ...
20000042:	4e81                	li	t4,0
20000044:	4f01                	li	t5,0
20000046:	4f81                	li	t6,0

20000048 <.Lpcrel_hi0>:
20000048:	60000197          	auipc	gp,0x60000
2000004c:	7b818193          	addi	gp,gp,1976 # 80000800 <__global_pointer$>

20000050 <.Lpcrel_hi1>:
20000050:	60008117          	auipc	sp,0x60008
20000054:	fb010113          	addi	sp,sp,-80 # 80008000 <_sstack>
20000058:	840a                	mv	s0,sp
2000005a:	0040006f          	j	2000005e <_start_rust>

Relevant document is also updated.

ivq added 3 commits November 10, 2023 19:16
If single-hart is enabled, the sp is set to _stack_start - _hart_stack_size,
rather than _stack_start. Fix this.

Fixes: 9a02223 ("Add feature single-hart")
Signed-off-by: Chien Wong <[email protected]>
Signed-off-by: Chien Wong <[email protected]>
@ivq ivq requested a review from a team as a code owner November 10, 2023 11:39
Copy link
Contributor

@romancardenas romancardenas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@romancardenas romancardenas added this pull request to the merge queue Nov 10, 2023
Merged via the queue into rust-embedded:master with commit 7fe4dc3 Nov 10, 2023
69 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants