Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed task switching #9

Merged
merged 1 commit into from
Sep 16, 2024
Merged

Fixed task switching #9

merged 1 commit into from
Sep 16, 2024

Conversation

alexcekay
Copy link
Member

@alexcekay alexcekay commented Sep 13, 2024

Debugging NuttX reveals that it stores an incorrect SP at regs[0] during context switching.

Right before the context switch via SVC call:

0x08014410 in sys_call2 (nbr=2, parm2=537382140, parm1=537028520) at /home/alex/PX4-Autopilot/platforms/nuttx/NuttX/nuttx/arch/arm/include/syscall.h:186 186 __asm__ __volatile__ => 0x08014410 <arm_switchcontext+10>: 00 df svc 0

sp is as follows:
sp 0x20036d4c 0x20036d4c

In the exception entry (due to SVC)

After the SVC happens, NuttX calculates the previous sp (before exc) and stores it to r2
157 add r2, #HW_XCPT_SIZE /* R2=MSP/PSP before the interrupt was taken */ => 0x0800821a <exception_common+17>: 02 f1 68 02 add.w r2, r2, #104 ; 0x68

r2 is as follows:
r2 0x20036d48 537095496

Workaround

The workaround below solves the problem by adding the offset to the sp stored by NuttX. Afterwards the bt works again. A complete solution is to discuss the topic with the NuttX guys.

@alexcekay alexcekay requested a review from niklaut September 13, 2024 14:45
Copy link
Collaborator

@niklaut niklaut left a comment

Choose a reason for hiding this comment

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

Thanks!

@alexcekay alexcekay merged commit f0dc7b3 into main Sep 16, 2024
3 checks passed
@niklaut niklaut deleted the task-switch-fix branch November 4, 2024 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants