From 0124533cc3ac34fddc9e0742b5c133973309dac2 Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Mon, 19 Jun 2023 22:47:29 +0900 Subject: [PATCH] Revert "riscv/addrenv: Move addrenv_switch() to correct place after FPU change" This reverts commit da319bbd853c8f8be79318c4cecf70abd444692d. --- arch/risc-v/src/common/riscv_doirq.c | 18 +++++++++++++++++- arch/risc-v/src/common/riscv_internal.h | 10 ---------- .../common/supervisor/riscv_perform_syscall.c | 13 +++++++++++++ 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/arch/risc-v/src/common/riscv_doirq.c b/arch/risc-v/src/common/riscv_doirq.c index e96e9f6428..a1faf2aa0c 100644 --- a/arch/risc-v/src/common/riscv_doirq.c +++ b/arch/risc-v/src/common/riscv_doirq.c @@ -83,9 +83,25 @@ 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. + * 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. */ +#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 */ diff --git a/arch/risc-v/src/common/riscv_internal.h b/arch/risc-v/src/common/riscv_internal.h index 18a8b9bb3b..e890a30d8e 100644 --- a/arch/risc-v/src/common/riscv_internal.h +++ b/arch/risc-v/src/common/riscv_internal.h @@ -229,16 +229,6 @@ 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 */ diff --git a/arch/risc-v/src/common/supervisor/riscv_perform_syscall.c b/arch/risc-v/src/common/supervisor/riscv_perform_syscall.c index e2be09e798..88d8be77ee 100644 --- a/arch/risc-v/src/common/supervisor/riscv_perform_syscall.c +++ b/arch/risc-v/src/common/supervisor/riscv_perform_syscall.c @@ -44,6 +44,19 @@ 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 */