Skip to content

Commit

Permalink
cpu/cortexm: clear FPU state in cpu_switch_context_exit()
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspar030 committed Oct 5, 2022
1 parent 6257e32 commit 5cc43e5
Showing 1 changed file with 10 additions and 0 deletions.
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

0 comments on commit 5cc43e5

Please sign in to comment.