You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/06/19 11:28:18 UTC

[nuttx] 05/06: riscv/addrenv: Move addrenv_switch() to correct place after FPU change

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit da319bbd853c8f8be79318c4cecf70abd444692d
Author: Ville Juven <vi...@unikie.com>
AuthorDate: Thu Jun 1 15:41:00 2023 +0300

    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.
---
 arch/risc-v/src/common/riscv_doirq.c                   | 18 +-----------------
 arch/risc-v/src/common/riscv_internal.h                | 10 ++++++++++
 .../src/common/supervisor/riscv_perform_syscall.c      | 13 -------------
 3 files changed, 11 insertions(+), 30 deletions(-)

diff --git a/arch/risc-v/src/common/riscv_doirq.c b/arch/risc-v/src/common/riscv_doirq.c
index a1faf2aa0c..e96e9f6428 100644
--- a/arch/risc-v/src/common/riscv_doirq.c
+++ b/arch/risc-v/src/common/riscv_doirq.c
@@ -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 */
diff --git a/arch/risc-v/src/common/riscv_internal.h b/arch/risc-v/src/common/riscv_internal.h
index e890a30d8e..18a8b9bb3b 100644
--- a/arch/risc-v/src/common/riscv_internal.h
+++ b/arch/risc-v/src/common/riscv_internal.h
@@ -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 */
 
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 88d8be77ee..e2be09e798 100644
--- a/arch/risc-v/src/common/supervisor/riscv_perform_syscall.c
+++ b/arch/risc-v/src/common/supervisor/riscv_perform_syscall.c
@@ -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 */