riscv/addrenv: Move addrenv_switch() to correct place after FPU change

The new address environment must be instantiated prior to restoring FPU
state as the CPU status register is in tcb->regs, which is user stack.
This commit is contained in:
Ville Juven 2023-06-01 15:41:00 +03:00 committed by Xiang Xiao
parent 5ce169f047
commit da319bbd85
3 changed files with 11 additions and 30 deletions

View File

@ -83,25 +83,9 @@ uintptr_t *riscv_doirq(int irq, uintptr_t *regs)
irq_dispatch(irq, regs);
/* Check for a context switch. If a context switch occurred, then
* CURRENT_REGS will have a different value than it did on entry. If an
* interrupt level context switch has occurred, then restore the floating
* point state and the establish the correct address environment before
* returning from the interrupt.
* CURRENT_REGS will have a different value than it did on entry.
*/
#ifdef CONFIG_ARCH_ADDRENV
if (regs != CURRENT_REGS)
{
/* Make sure that the address environment for the previously
* running task is closed down gracefully (data caches dump,
* MMU flushed) and set up the address environment for the new
* thread at the head of the ready-to-run list.
*/
addrenv_switch(NULL);
}
#endif
if (regs != CURRENT_REGS)
{
/* Restore the cpu lock */

View File

@ -229,6 +229,16 @@ static inline void riscv_restorecontext(struct tcb_s *tcb)
{
CURRENT_REGS = (uintptr_t *)tcb->xcp.regs;
#ifdef CONFIG_ARCH_ADDRENV
/* Make sure that the address environment for the previously
* running task is closed down gracefully (data caches dump,
* MMU flushed) and set up the address environment for the new
* thread at the head of the ready-to-run list.
*/
addrenv_switch(tcb);
#endif
#ifdef CONFIG_ARCH_FPU
/* Restore FPU after the new address environment is instantiated */

View File

@ -44,19 +44,6 @@ void *riscv_perform_syscall(uintptr_t *regs)
riscv_swint(0, regs, NULL);
#ifdef CONFIG_ARCH_ADDRENV
if (regs != CURRENT_REGS)
{
/* Make sure that the address environment for the previously
* running task is closed down gracefully (data caches dump,
* MMU flushed) and set up the address environment for the new
* thread at the head of the ready-to-run list.
*/
addrenv_switch(NULL);
}
#endif
if (regs != CURRENT_REGS)
{
/* Restore the cpu lock */