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

cpu/cortexm: clear FPU state in cpu_switch_context_exit() #18697

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cpu/cortexm_common/thread_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,16 @@ void *thread_isr_stack_start(void)

void NORETURN cpu_switch_context_exit(void)
{
#ifdef MODULE_CORTEXM_FPU
/* An exiting thread won't need it's FPU state anymore, so clear it here.
* This is important, as `sched_task_exit` clears `sched_active_thread`,
* which in turn causes `isr_pendsv` to skip all FPU storing/restoring.
* That might lead to this thread's FPU lazy stacking / FPCAR to stay active.
*/
__set_FPSCR(0);
__set_CONTROL(__get_CONTROL() & (~(CONTROL_FPCA_Msk)));
#endif

/* enable IRQs to make sure the PENDSV interrupt is reachable */
irq_enable();

Expand Down