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 2022/04/20 17:59:41 UTC
[incubator-nuttx] 01/03: arch/xtensa: Use syscall interface for xtensa_save/restore_context.
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/incubator-nuttx.git
commit 6db910a1aa824f11b55004beee4f8e1d9ecea335
Author: Abdelatif Guettouche <ab...@espressif.com>
AuthorDate: Wed Apr 20 04:30:00 2022 +0200
arch/xtensa: Use syscall interface for xtensa_save/restore_context.
Signed-off-by: Abdelatif Guettouche <ab...@espressif.com>
---
arch/xtensa/src/common/xtensa.h | 18 ++++--
arch/xtensa/src/common/xtensa_context.S | 88 ---------------------------
arch/xtensa/src/common/xtensa_exit.c | 2 +-
arch/xtensa/src/common/xtensa_switchcontext.c | 47 --------------
arch/xtensa/src/esp32/Make.defs | 2 +-
arch/xtensa/src/esp32s2/Make.defs | 1 -
arch/xtensa/src/esp32s3/Make.defs | 1 -
7 files changed, 14 insertions(+), 145 deletions(-)
diff --git a/arch/xtensa/src/common/xtensa.h b/arch/xtensa/src/common/xtensa.h
index a984976ef0..0af851cc05 100644
--- a/arch/xtensa/src/common/xtensa.h
+++ b/arch/xtensa/src/common/xtensa.h
@@ -32,6 +32,7 @@
# include <stdint.h>
# include <sys/types.h>
# include <stdbool.h>
+# include <syscall.h>
#endif
#include <arch/chip/core-isa.h>
@@ -112,6 +113,17 @@
#define xtensa_savestate(regs) xtensa_copystate(regs, (uint32_t*)CURRENT_REGS)
#define xtensa_restorestate(regs) do { CURRENT_REGS = regs; } while (0)
+/* Context switching via system calls ***************************************/
+
+#define xtensa_context_save(regs)\
+ sys_call1(SYS_save_context, (uintptr_t)regs)
+
+#define xtensa_context_restore(regs)\
+ sys_call1(SYS_restore_context, (uintptr_t)regs)
+
+#define xtensa_switchcontext(saveregs, restoreregs)\
+ sys_call2(SYS_switch_context, (uintptr_t)saveregs, (uintptr_t)restoreregs)
+
/* Interrupt codes from other CPUs: */
#define CPU_INTCODE_NONE 0
@@ -279,12 +291,6 @@ int xtensa_intercpu_interrupt(int tocpu, int intcode);
void xtensa_pause_handler(void);
#endif
-/* Synchronous context switching */
-
-int xtensa_context_save(uint32_t *regs);
-void xtensa_context_restore(uint32_t *regs) noreturn_function;
-void xtensa_switchcontext(uint32_t *saveregs, uint32_t *restoreregs);
-
#if XCHAL_CP_NUM > 0
void xtensa_coproc_savestate(struct xtensa_cpstate_s *cpstate);
void xtensa_coproc_restorestate(struct xtensa_cpstate_s *cpstate);
diff --git a/arch/xtensa/src/common/xtensa_context.S b/arch/xtensa/src/common/xtensa_context.S
index 539518394a..1521b53b24 100644
--- a/arch/xtensa/src/common/xtensa_context.S
+++ b/arch/xtensa/src/common/xtensa_context.S
@@ -204,47 +204,6 @@ _xtensa_context_save:
.size _xtensa_context_save, . - _xtensa_context_save
-/****************************************************************************
- * Name: xtensa_context_save
- *
- * Description:
- *
- * This function implements the moral equivalent of setjmp(). It is
- * called from user code (with interrupts disabled) to save the current
- * state of the running thread. This function always returns zero.
- *
- * The counterpart to this function is xtensa_context_restore().
- *
- * Input State:
- * a0 = The true return value to the caller.
- * a2 = The address of the register state structure
- *
- * Return state:
- * a0, a2, and a3 modified.
- * Returned value is in a2
- *
- ****************************************************************************/
-
- .global xtensa_context_save
- .type xtensa_context_save, @function
-
- .align 4
- .literal_position
- .align 4
-
-xtensa_context_save:
- ENTRY(16)
-
- mov a3, a2
- movi a2, SYS_save_context
- movi a4, XCHAL_SWINT_CALL
- wsr a4, intset
- rsync
-
- RET(16)
-
- .size xtensa_context_save, . - xtensa_context_save
-
/****************************************************************************
* Name: _xtensa_context_restore
*
@@ -331,50 +290,3 @@ _xtensa_context_restore:
.size _xtensa_context_restore, . - _xtensa_context_restore
-/****************************************************************************
- * Name: xtensa_context_restore
- *
- * Description:
- *
- * This functions implements the moral equivalent of longjmp(). It is
- * called from user code (with interrupts disabled) to restore the current
- * state of the running thread. This function always appears to be a
- * second return from xtensa_context_save except that that it returns the
- * value 1 (because the saved value of A2 was set to 1
- * inxtensa_context_save()).
- *
- * The counterpart to this function is xtensa_context_save().
- *
- * Entry Conditions:
- * - A0 = Return address to caller.
- * - A2 = Pointer to the processor state save area
- *
- * Exit conditions:
- * NOTE: That this function does NOT return to the caller but rather
- * to a new threading context. It is not necessary to save any of the
- * caller's registers.
- *
- * Assumptions:
- * - Interrupts are disabled.
- *
- ****************************************************************************/
-
- .global xtensa_context_restore
- .type xtensa_context_restore, @function
-
- .align 4
- .literal_position
- .align 4
-
-xtensa_context_restore:
- ENTRY(16)
-
- mov a3, a2
- movi a2, SYS_restore_context
- movi a4, XCHAL_SWINT_CALL
- wsr a4, intset
- rsync
-
- RET(16)
-
- .size xtensa_context_restore, . - xtensa_context_restore
diff --git a/arch/xtensa/src/common/xtensa_exit.c b/arch/xtensa/src/common/xtensa_exit.c
index bbd050afa1..66f529ff8c 100644
--- a/arch/xtensa/src/common/xtensa_exit.c
+++ b/arch/xtensa/src/common/xtensa_exit.c
@@ -151,5 +151,5 @@ void up_exit(int status)
* software interrupts are disabled.
*/
- DEBUGPANIC();
+ PANIC();
}
diff --git a/arch/xtensa/src/common/xtensa_switchcontext.c b/arch/xtensa/src/common/xtensa_switchcontext.c
deleted file mode 100644
index 3aecda2a99..0000000000
--- a/arch/xtensa/src/common/xtensa_switchcontext.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/****************************************************************************
- * arch/xtensa/src/common/xtensa_switchcontext.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership. The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include "syscall.h"
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: xtensa_switchcontext
- *
- * Description:
- * Save the current thread context and restore the specified context.
- *
- * Returned Value:
- * None
- *
- ****************************************************************************/
-
-void xtensa_switchcontext(uint32_t *saveregs, uint32_t *restoreregs)
-{
- sys_call2(SYS_switch_context, (uintptr_t)saveregs, (uintptr_t)restoreregs);
-}
diff --git a/arch/xtensa/src/esp32/Make.defs b/arch/xtensa/src/esp32/Make.defs
index 77fd05d0f4..9a2c846565 100644
--- a/arch/xtensa/src/esp32/Make.defs
+++ b/arch/xtensa/src/esp32/Make.defs
@@ -39,7 +39,7 @@ CMN_CSRCS += xtensa_modifyreg8.c xtensa_modifyreg16.c xtensa_modifyreg32.c
CMN_CSRCS += xtensa_puts.c xtensa_releasepending.c xtensa_releasestack.c
CMN_CSRCS += xtensa_reprioritizertr.c xtensa_schedsigaction.c
CMN_CSRCS += xtensa_sigdeliver.c xtensa_stackframe.c xtensa_udelay.c
-CMN_CSRCS += xtensa_unblocktask.c xtensa_usestack.c xtensa_swint.c xtensa_switchcontext.c
+CMN_CSRCS += xtensa_unblocktask.c xtensa_usestack.c xtensa_swint.c
# Configuration-dependent common XTENSA files
diff --git a/arch/xtensa/src/esp32s2/Make.defs b/arch/xtensa/src/esp32s2/Make.defs
index 74ddefa0af..59eaad7755 100644
--- a/arch/xtensa/src/esp32s2/Make.defs
+++ b/arch/xtensa/src/esp32s2/Make.defs
@@ -40,7 +40,6 @@ CMN_CSRCS += xtensa_puts.c xtensa_releasepending.c xtensa_releasestack.c
CMN_CSRCS += xtensa_reprioritizertr.c xtensa_schedsigaction.c
CMN_CSRCS += xtensa_sigdeliver.c xtensa_stackframe.c xtensa_udelay.c
CMN_CSRCS += xtensa_unblocktask.c xtensa_usestack.c xtensa_swint.c
-CMN_CSRCS += xtensa_switchcontext.c
# Configuration-dependent common XTENSA files
diff --git a/arch/xtensa/src/esp32s3/Make.defs b/arch/xtensa/src/esp32s3/Make.defs
index 2ffe1d149a..fe04717293 100644
--- a/arch/xtensa/src/esp32s3/Make.defs
+++ b/arch/xtensa/src/esp32s3/Make.defs
@@ -40,7 +40,6 @@ CMN_CSRCS += xtensa_puts.c xtensa_releasepending.c xtensa_releasestack.c
CMN_CSRCS += xtensa_reprioritizertr.c xtensa_schedsigaction.c
CMN_CSRCS += xtensa_sigdeliver.c xtensa_stackframe.c xtensa_udelay.c
CMN_CSRCS += xtensa_unblocktask.c xtensa_usestack.c xtensa_swint.c
-CMN_CSRCS += xtensa_switchcontext.c
# Configuration-dependent common XTENSA files