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 2026/01/15 03:37:19 UTC
(nuttx) branch master updated (68a5732d9ad -> 8786c814f00)
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
from 68a5732d9ad stdio.h: Update TMP_MAX definition to match Linux.
new 8da6b45939d arch/tricore: Regs for context switching save the memory address of the CSA.
new 8a15aebfeae arch/tricore: Resolving gcc compilation warning
new 6b755dea45a arch/tricore: optimize task switching process
new 69ed5f54f30 tricore: remove up_set_current_regs/up_current_regs
new b8fd06cf0eb arch/tricore: Inline up_switch_context
new 8786c814f00 arch/tricore: syscall SYS_switch_context and SYS_restore_context use 0 para
The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
arch/tricore/include/inttypes.h | 4 +-
arch/tricore/include/irq.h | 73 +++++++++++---------
arch/tricore/src/common/CMakeLists.txt | 1 -
arch/tricore/src/common/Make.defs | 1 -
arch/tricore/src/common/tricore_csa.c | 2 +-
arch/tricore/src/common/tricore_doirq.c | 44 +++++-------
arch/tricore/src/common/tricore_exit.c | 10 +--
arch/tricore/src/common/tricore_initialize.c | 4 +-
arch/tricore/src/common/tricore_internal.h | 22 +-----
.../tricore/src/common/tricore_schedulesigaction.c | 19 +++---
arch/tricore/src/common/tricore_sigdeliver.c | 3 +-
arch/tricore/src/common/tricore_svcall.c | 78 ++++++----------------
arch/tricore/src/common/tricore_switchcontext.c | 27 +-------
arch/tricore/src/common/tricore_trapcall.c | 4 +-
tools/nxstyle.c | 2 +
15 files changed, 106 insertions(+), 188 deletions(-)
(nuttx) 05/06: arch/tricore: Inline up_switch_context
Posted by xi...@apache.org.
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 b8fd06cf0eb329f883eec6e62ef7a533d2077269
Author: zhangyu117 <zh...@xiaomi.com>
AuthorDate: Thu Dec 12 11:18:57 2024 +0800
arch/tricore: Inline up_switch_context
inline up_switch_context, avoid function call burden.
Signed-off-by: zhangyu117 <zh...@xiaomi.com>
---
arch/tricore/include/irq.h | 15 +++++++++++++++
arch/tricore/src/common/CMakeLists.txt | 1 -
arch/tricore/src/common/Make.defs | 1 -
arch/tricore/src/common/tricore_internal.h | 16 ++--------------
4 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/arch/tricore/include/irq.h b/arch/tricore/include/irq.h
index e472dddd863..0c1178673d6 100644
--- a/arch/tricore/include/irq.h
+++ b/arch/tricore/include/irq.h
@@ -34,6 +34,7 @@
#include <sys/types.h>
#ifndef __ASSEMBLY__
# include <stdbool.h>
+# include <syscall.h>
#endif
/* Include NuttX-specific IRQ definitions */
@@ -211,6 +212,20 @@ static inline_function uintptr_t up_getusrsp(void *regs)
#endif /* __ASSEMBLY__ */
+/****************************************************************************
+ * Name: up_switch_context
+ ****************************************************************************/
+
+#define up_switch_context(tcb, rtcb) \
+ do { \
+ if (!up_interrupt_context()) \
+ { \
+ nxsched_switch_context(rtcb, tcb); \
+ sys_call2(SYS_switch_context, (uintptr_t)&rtcb->xcp.regs, \
+ (uintptr_t)tcb->xcp.regs); \
+ } \
+ } while (0)
+
/****************************************************************************
* Name: up_getusrpc
****************************************************************************/
diff --git a/arch/tricore/src/common/CMakeLists.txt b/arch/tricore/src/common/CMakeLists.txt
index 1183ed621e9..c0f55332edb 100644
--- a/arch/tricore/src/common/CMakeLists.txt
+++ b/arch/tricore/src/common/CMakeLists.txt
@@ -40,7 +40,6 @@ set(SRCS
tricore_sigdeliver.c
tricore_stackframe.c
tricore_svcall.c
- tricore_switchcontext.c
tricore_tcbinfo.c
tricore_trapcall.c
tricore_systimer.c
diff --git a/arch/tricore/src/common/Make.defs b/arch/tricore/src/common/Make.defs
index c3e9c77dd30..8dbfbffd427 100644
--- a/arch/tricore/src/common/Make.defs
+++ b/arch/tricore/src/common/Make.defs
@@ -41,7 +41,6 @@ CMN_CSRCS += tricore_schedulesigaction.c
CMN_CSRCS += tricore_sigdeliver.c
CMN_CSRCS += tricore_stackframe.c
CMN_CSRCS += tricore_svcall.c
-CMN_CSRCS += tricore_switchcontext.c
CMN_CSRCS += tricore_tcbinfo.c
CMN_CSRCS += tricore_trapcall.c
CMN_CSRCS += tricore_systimer.c
diff --git a/arch/tricore/src/common/tricore_internal.h b/arch/tricore/src/common/tricore_internal.h
index ca1cf3a1512..e75faf4d551 100644
--- a/arch/tricore/src/common/tricore_internal.h
+++ b/arch/tricore/src/common/tricore_internal.h
@@ -131,20 +131,8 @@
/* Context switching */
-#ifndef tricore_fullcontextrestore
-# define tricore_fullcontextrestore(restoreregs) \
- sys_call1(SYS_restore_context, (uintptr_t)restoreregs);
-#else
-extern void tricore_fullcontextrestore(uintptr_t *restoreregs);
-#endif
-
-#ifndef tricore_switchcontext
-# define tricore_switchcontext(saveregs, restoreregs) \
- sys_call2(SYS_switch_context, (uintptr_t)saveregs, (uintptr_t)restoreregs);
-#else
-extern void tricore_switchcontext(uintptr_t **saveregs,
- uintptr_t *restoreregs);
-#endif
+#define tricore_fullcontextrestore(restoreregs) \
+ sys_call1(SYS_restore_context, (uintptr_t)restoreregs);
/****************************************************************************
* Public Types
(nuttx) 03/06: arch/tricore: optimize task switching process
Posted by xi...@apache.org.
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 6b755dea45a2edb97d76a18b3a21e4df8c042096
Author: zhangyu117 <zh...@xiaomi.com>
AuthorDate: Tue Dec 10 15:45:41 2024 +0800
arch/tricore: optimize task switching process
g_current_regs is only used to determine if we are in irq, with other functionalities removed.
Signed-off-by: zhangyu117 <zh...@xiaomi.com>
---
arch/tricore/src/common/tricore_doirq.c | 8 +++----
arch/tricore/src/common/tricore_internal.h | 5 ----
.../tricore/src/common/tricore_schedulesigaction.c | 17 +++++++-------
arch/tricore/src/common/tricore_svcall.c | 14 +++++------
arch/tricore/src/common/tricore_switchcontext.c | 27 +---------------------
5 files changed, 20 insertions(+), 51 deletions(-)
diff --git a/arch/tricore/src/common/tricore_doirq.c b/arch/tricore/src/common/tricore_doirq.c
index 614b697a4f0..7d5a7278cc6 100644
--- a/arch/tricore/src/common/tricore_doirq.c
+++ b/arch/tricore/src/common/tricore_doirq.c
@@ -79,6 +79,8 @@ IFX_INTERRUPT_INTERNAL(tricore_doirq, 0, 255)
irq_dispatch(icr.B.CCPN, regs);
+ tcb = this_task();
+
/* Check for a context switch. If a context switch occurred, then
* g_current_regs will have a different value than it did on entry. If an
* interrupt level context switch has occurred, then restore the floating
@@ -86,10 +88,8 @@ IFX_INTERRUPT_INTERNAL(tricore_doirq, 0, 255)
* returning from the interrupt.
*/
- if (regs != up_current_regs())
+ if (regs != tcb->xcp.regs)
{
- tcb = this_task();
-
#ifdef CONFIG_ARCH_ADDRENV
/* Make sure that the address environment for the previously
* running task is closed down gracefully (data caches dump,
@@ -112,7 +112,7 @@ IFX_INTERRUPT_INTERNAL(tricore_doirq, 0, 255)
running_task = tcb;
g_running_tasks[this_cpu()] = running_task;
- __mtcr(CPU_PCXI, tricore_addr2csa(up_current_regs()));
+ __mtcr(CPU_PCXI, tricore_addr2csa(tcb->xcp.regs));
__isync();
}
diff --git a/arch/tricore/src/common/tricore_internal.h b/arch/tricore/src/common/tricore_internal.h
index b6df70c1ace..ca1cf3a1512 100644
--- a/arch/tricore/src/common/tricore_internal.h
+++ b/arch/tricore/src/common/tricore_internal.h
@@ -204,11 +204,6 @@ extern uintptr_t __A0_MEM[]; /* End+1 of .data */
* Inline Functions
****************************************************************************/
-/* Macros to handle saving and restoring interrupt state. */
-
-#define tricore_savestate(regs) (regs = up_current_regs())
-#define tricore_restorestate(regs) (up_set_current_regs(regs))
-
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
diff --git a/arch/tricore/src/common/tricore_schedulesigaction.c b/arch/tricore/src/common/tricore_schedulesigaction.c
index ffac299f1ac..4eb548b284d 100644
--- a/arch/tricore/src/common/tricore_schedulesigaction.c
+++ b/arch/tricore/src/common/tricore_schedulesigaction.c
@@ -117,16 +117,16 @@ void up_schedule_sigaction(struct tcb_s *tcb)
* been delivered.
*/
- tricore_savestate(tcb->xcp.saved_regs);
+ tcb->xcp.saved_regs = tcb->xcp.regs;
/* Create a new CSA for signal delivery. The new context
* will borrow the process stack of the current tcb.
*/
- up_set_current_regs(tricore_alloc_csa((uintptr_t)
- tricore_sigdeliver,
- STACK_ALIGN_DOWN(up_getusrsp(tcb->xcp.regs)),
- PSW_IO_SUPERVISOR | PSW_CDE, true));
+ tcb->xcp.regs =
+ tricore_alloc_csa((uintptr_t)tricore_sigdeliver,
+ STACK_ALIGN_DOWN(up_getusrsp(tcb->xcp.regs)),
+ PSW_IO_SUPERVISOR | PSW_CDE, true);
}
}
@@ -151,8 +151,9 @@ void up_schedule_sigaction(struct tcb_s *tcb)
* will borrow the process stack of the current tcb.
*/
- tcb->xcp.regs = tricore_alloc_csa((uintptr_t)tricore_sigdeliver,
- STACK_ALIGN_DOWN(up_getusrsp(tcb->xcp.regs)),
- PSW_IO_SUPERVISOR | PSW_CDE, true);
+ tcb->xcp.regs =
+ tricore_alloc_csa((uintptr_t)tricore_sigdeliver,
+ STACK_ALIGN_DOWN(up_getusrsp(tcb->xcp.regs)),
+ PSW_IO_SUPERVISOR | PSW_CDE, true);
}
}
diff --git a/arch/tricore/src/common/tricore_svcall.c b/arch/tricore/src/common/tricore_svcall.c
index 4e89f8475c1..67164a08882 100644
--- a/arch/tricore/src/common/tricore_svcall.c
+++ b/arch/tricore/src/common/tricore_svcall.c
@@ -58,14 +58,12 @@ void tricore_svcall(volatile void *trap)
{
struct tcb_s *running_task;
struct tcb_s *tcb;
- int cpu = this_cpu();
-
uintptr_t *regs;
uint32_t cmd;
regs = (uintptr_t *)__mfcr(CPU_PCXI);
- running_task = g_running_tasks[cpu];
+ running_task = g_running_tasks[this_cpu()];
tcb = this_task();
/* DSYNC instruction should be executed immediately prior to the MTCR */
@@ -102,14 +100,14 @@ void tricore_svcall(volatile void *trap)
case SYS_restore_context:
{
tricore_reclaim_csa(regs[REG_UPCXI]);
- up_set_current_regs((uintptr_t *)regs[REG_D9]);
+ tcb->xcp.regs = (uintptr_t *)regs[REG_D9];
}
break;
case SYS_switch_context:
{
*(uintptr_t **)regs[REG_D9] = tricore_csa2addr(regs[REG_UPCXI]);
- up_set_current_regs((uintptr_t *)regs[REG_D10]);
+ tcb->xcp.regs = (uintptr_t *)regs[REG_D10];
}
break;
@@ -120,7 +118,7 @@ void tricore_svcall(volatile void *trap)
break;
}
- if (regs != up_current_regs())
+ if (regs != tcb->xcp.regs)
{
/* Update scheduler parameters */
@@ -131,9 +129,9 @@ void tricore_svcall(volatile void *trap)
* crashes.
*/
- g_running_tasks[cpu] = this_task();
+ g_running_tasks[this_cpu()] = this_task();
- regs[REG_UPCXI] = tricore_addr2csa(up_current_regs());
+ regs[REG_UPCXI] = tricore_addr2csa(tcb->xcp.regs);
__isync();
}
diff --git a/arch/tricore/src/common/tricore_switchcontext.c b/arch/tricore/src/common/tricore_switchcontext.c
index 7d08421a8ff..9e399cd1028 100644
--- a/arch/tricore/src/common/tricore_switchcontext.c
+++ b/arch/tricore/src/common/tricore_switchcontext.c
@@ -59,35 +59,10 @@
void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb)
{
- /* Are we in an interrupt handler? */
-
- if (up_current_regs())
- {
- /* Yes, then we have to do things differently.
- * Just copy the g_current_regs into the OLD rtcb.
- */
-
- tricore_savestate(rtcb->xcp.regs);
-
- /* Then switch contexts. Any necessary address environment
- * changes will be made when the interrupt returns.
- */
-
- tricore_restorestate(tcb->xcp.regs);
- }
-
- /* No, then we will need to perform the user context switch */
-
- else
+ if (!up_current_regs())
{
/* Then switch contexts */
tricore_switchcontext(&rtcb->xcp.regs, tcb->xcp.regs);
-
- /* tricore_switchcontext forces a context switch to the task at the
- * head of the ready-to-run list. It does not 'return' in the
- * normal sense. When it does return, it is because the blocked
- * task is again ready to run and has execution priority.
- */
}
}
(nuttx) 04/06: tricore: remove up_set_current_regs/up_current_regs
Posted by xi...@apache.org.
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 69ed5f54f304cc0323c21aa576f858bfdab37c12
Author: zhangyu117 <zh...@xiaomi.com>
AuthorDate: Tue Dec 10 16:59:10 2024 +0800
tricore: remove up_set_current_regs/up_current_regs
add g_interrupt_context to to identify interruption context
Signed-off-by: zhangyu117 <zh...@xiaomi.com>
---
arch/tricore/include/irq.h | 45 +++++++++-------------
arch/tricore/src/common/tricore_doirq.c | 21 +++-------
arch/tricore/src/common/tricore_initialize.c | 4 +-
.../tricore/src/common/tricore_schedulesigaction.c | 2 +-
arch/tricore/src/common/tricore_svcall.c | 8 +++-
arch/tricore/src/common/tricore_switchcontext.c | 2 +-
arch/tricore/src/common/tricore_trapcall.c | 4 +-
tools/nxstyle.c | 2 +
8 files changed, 39 insertions(+), 49 deletions(-)
diff --git a/arch/tricore/include/irq.h b/arch/tricore/include/irq.h
index 592ba712561..e472dddd863 100644
--- a/arch/tricore/include/irq.h
+++ b/arch/tricore/include/irq.h
@@ -73,17 +73,9 @@ extern "C"
* Public Data
****************************************************************************/
-/* g_current_regs[] holds a references to the current interrupt level
- * register storage structure. If is non-NULL only during interrupt
- * processing. Access to g_current_regs[] must be through the macro
- * g_current_regs for portability.
- */
-
-/* For the case of architectures with multiple CPUs, then there must be one
- * such value for each processor that can receive an interrupt.
- */
+/* g_interrupt_context store irq status */
-EXTERN volatile uintptr_t *g_current_regs[CONFIG_SMP_NCPUS];
+EXTERN volatile bool g_interrupt_context[CONFIG_SMP_NCPUS];
/****************************************************************************
* Public Function Prototypes
@@ -155,21 +147,21 @@ void up_irq_restore(irqstate_t flags)
* Inline Functions
****************************************************************************/
-static inline_function uintptr_t *up_current_regs(void)
-{
-#ifdef CONFIG_SMP
- return (uintptr_t *)g_current_regs[up_cpu_index()];
-#else
- return (uintptr_t *)g_current_regs[0];
-#endif
-}
+/****************************************************************************
+ * Name: up_set_interrupt_context
+ *
+ * Description:
+ * Set the interrupt handler context.
+ *
+ ****************************************************************************/
-static inline_function void up_set_current_regs(uintptr_t *regs)
+noinstrument_function
+static inline_function void up_set_interrupt_context(bool flag)
{
#ifdef CONFIG_SMP
- g_current_regs[up_cpu_index()] = regs;
+ g_interrupt_context[up_this_cpu()] = flag;
#else
- g_current_regs[0] = regs;
+ g_interrupt_context[0] = flag;
#endif
}
@@ -187,15 +179,14 @@ static inline_function bool up_interrupt_context(void)
{
#ifdef CONFIG_SMP
irqstate_t flags = up_irq_save();
-#endif
+ bool ret = g_interrupt_context[up_this_cpu()];
- bool ret = up_current_regs() != NULL;
-
-#ifdef CONFIG_SMP
up_irq_restore(flags);
-#endif
return ret;
+#else
+ return g_interrupt_context[0];
+#endif
}
/****************************************************************************
@@ -225,7 +216,7 @@ static inline_function uintptr_t up_getusrsp(void *regs)
****************************************************************************/
#define up_getusrpc(regs) \
- (((uint32_t *)((regs) ? (regs) : up_current_regs()))[REG_UPC])
+ (((uint32_t *)((regs) ? (regs) : running_regs()))[REG_UPC])
#undef EXTERN
#ifdef __cplusplus
diff --git a/arch/tricore/src/common/tricore_doirq.c b/arch/tricore/src/common/tricore_doirq.c
index 7d5a7278cc6..228cb2de744 100644
--- a/arch/tricore/src/common/tricore_doirq.c
+++ b/arch/tricore/src/common/tricore_doirq.c
@@ -67,13 +67,11 @@ IFX_INTERRUPT_INTERNAL(tricore_doirq, 0, 255)
/* Nested interrupts are not supported */
- DEBUGASSERT(up_current_regs() == NULL);
+ DEBUGASSERT(!up_interrupt_context());
- /* Current regs non-zero indicates that we are processing an interrupt;
- * current_regs is also used to manage interrupt level context switches.
- */
+ /* Set irq flag */
- up_set_current_regs(regs);
+ up_set_interrupt_context(true);
/* Deliver the IRQ */
@@ -81,12 +79,7 @@ IFX_INTERRUPT_INTERNAL(tricore_doirq, 0, 255)
tcb = this_task();
- /* Check for a context switch. If a context switch occurred, then
- * g_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.
- */
+ /* Check for a context switch. */
if (regs != tcb->xcp.regs)
{
@@ -116,11 +109,9 @@ IFX_INTERRUPT_INTERNAL(tricore_doirq, 0, 255)
__isync();
}
- /* Set current_regs to NULL to indicate that we are no longer in an
- * interrupt handler.
- */
+ /* Set irq flag */
- up_set_current_regs(NULL);
+ up_set_interrupt_context(false);
/* running_task->xcp.regs is about to become invalid
* and will be marked as NULL to avoid misusage.
diff --git a/arch/tricore/src/common/tricore_initialize.c b/arch/tricore/src/common/tricore_initialize.c
index 9fa6ac84468..ec8377cbcb5 100644
--- a/arch/tricore/src/common/tricore_initialize.c
+++ b/arch/tricore/src/common/tricore_initialize.c
@@ -34,7 +34,9 @@
* Public Data
****************************************************************************/
-volatile uintptr_t *g_current_regs[CONFIG_SMP_NCPUS];
+/* g_interrupt_context store irq status */
+
+volatile bool g_interrupt_context[CONFIG_SMP_NCPUS];
/****************************************************************************
* Public Functions
diff --git a/arch/tricore/src/common/tricore_schedulesigaction.c b/arch/tricore/src/common/tricore_schedulesigaction.c
index 4eb548b284d..3f4662077cb 100644
--- a/arch/tricore/src/common/tricore_schedulesigaction.c
+++ b/arch/tricore/src/common/tricore_schedulesigaction.c
@@ -90,7 +90,7 @@ void up_schedule_sigaction(struct tcb_s *tcb)
* a task is signalling itself for some reason.
*/
- if (up_current_regs() == NULL)
+ if (!up_interrupt_context())
{
/* In this case just deliver the signal now. */
diff --git a/arch/tricore/src/common/tricore_svcall.c b/arch/tricore/src/common/tricore_svcall.c
index 67164a08882..601f754da15 100644
--- a/arch/tricore/src/common/tricore_svcall.c
+++ b/arch/tricore/src/common/tricore_svcall.c
@@ -72,7 +72,9 @@ void tricore_svcall(volatile void *trap)
regs = tricore_csa2addr((uintptr_t)regs);
- up_set_current_regs(regs);
+ /* Set irq flag */
+
+ up_set_interrupt_context(true);
cmd = regs[REG_D8];
@@ -136,5 +138,7 @@ void tricore_svcall(volatile void *trap)
__isync();
}
- up_set_current_regs(NULL);
+ /* Set irq flag */
+
+ up_set_interrupt_context(false);
}
diff --git a/arch/tricore/src/common/tricore_switchcontext.c b/arch/tricore/src/common/tricore_switchcontext.c
index 9e399cd1028..532fe248a3a 100644
--- a/arch/tricore/src/common/tricore_switchcontext.c
+++ b/arch/tricore/src/common/tricore_switchcontext.c
@@ -59,7 +59,7 @@
void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb)
{
- if (!up_current_regs())
+ if (!up_interrupt_context())
{
/* Then switch contexts */
diff --git a/arch/tricore/src/common/tricore_trapcall.c b/arch/tricore/src/common/tricore_trapcall.c
index a83bcb21a4a..0f3b6ff0f13 100644
--- a/arch/tricore/src/common/tricore_trapcall.c
+++ b/arch/tricore/src/common/tricore_trapcall.c
@@ -62,8 +62,8 @@ void tricore_trapcall(volatile void *trap)
regs = tricore_csa2addr(__mfcr(CPU_PCXI));
- up_set_current_regs(regs);
+ up_set_interrupt_context(true);
up_irq_save();
- PANIC_WITH_REGS("Trap", up_current_regs());
+ PANIC_WITH_REGS("Trap", regs);
}
diff --git a/tools/nxstyle.c b/tools/nxstyle.c
index 58094557a1e..4b58da91cf9 100644
--- a/tools/nxstyle.c
+++ b/tools/nxstyle.c
@@ -223,6 +223,8 @@ static const char *g_white_prefix[] =
"Http", /* Ref: apps/netutils/xedge/BAS/examples/xedge/src/xedge.h */
"Disk", /* Ref: apps/netutils/xedge/BAS/examples/xedge/src/xedge.h */
"Xedge", /* Ref: apps/netutils/xedge/BAS/examples/xedge/src/xedge.h */
+ "tClass", /* Ref: arch/tricore/src */
+ "tId", /* Ref: arch/tricore/src */
NULL
};
(nuttx) 01/06: arch/tricore: Regs for context switching save the memory address of the CSA.
Posted by xi...@apache.org.
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 8da6b45939d18bebd556f7d6d1dff7b67b2909ac
Author: liwenxiang1 <li...@xiaomi.com>
AuthorDate: Fri Nov 22 14:53:43 2024 +0800
arch/tricore: Regs for context switching save the memory address of the CSA.
In the exception panic process, regs needs to use a memory address, which defaults to PCXI. Here, it is uniformly saved as the actual memory address.
Signed-off-by: liwenxiang1 <li...@xiaomi.com>
---
arch/tricore/include/irq.h | 9 +++++----
arch/tricore/src/common/tricore_csa.c | 2 +-
arch/tricore/src/common/tricore_doirq.c | 4 ++--
arch/tricore/src/common/tricore_svcall.c | 4 ++--
4 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/arch/tricore/include/irq.h b/arch/tricore/include/irq.h
index cedddc410be..ae3e09c5312 100644
--- a/arch/tricore/include/irq.h
+++ b/arch/tricore/include/irq.h
@@ -205,14 +205,15 @@ static inline_function bool up_interrupt_context(void)
static inline_function uintptr_t up_getusrsp(void *regs)
{
uintptr_t *csa = regs;
+ uintptr_t pcxi = tricore_addr2csa(csa);
- while (((uintptr_t)csa & PCXI_UL) == 0)
+ while ((pcxi & PCXI_UL) == 0)
{
- csa = tricore_csa2addr((uintptr_t)csa);
- csa = (uintptr_t *)csa[0];
+ csa = tricore_csa2addr(csa[REG_UPCXI]);
+ pcxi = csa[REG_UPCXI];
}
- csa = tricore_csa2addr((uintptr_t)csa);
+ csa = tricore_csa2addr(pcxi);
return csa[REG_SP];
}
diff --git a/arch/tricore/src/common/tricore_csa.c b/arch/tricore/src/common/tricore_csa.c
index 74dd8931ac8..d1c782ec2ed 100644
--- a/arch/tricore/src/common/tricore_csa.c
+++ b/arch/tricore/src/common/tricore_csa.c
@@ -82,7 +82,7 @@ uintptr_t *tricore_alloc_csa(uintptr_t pc, uintptr_t sp,
plcsa[REG_LPCXI] |= PCXI_PIE;
}
- return (uintptr_t *)tricore_addr2csa(plcsa);
+ return plcsa;
}
/****************************************************************************
diff --git a/arch/tricore/src/common/tricore_doirq.c b/arch/tricore/src/common/tricore_doirq.c
index f5d686c3532..614b697a4f0 100644
--- a/arch/tricore/src/common/tricore_doirq.c
+++ b/arch/tricore/src/common/tricore_doirq.c
@@ -56,7 +56,7 @@ IFX_INTERRUPT_INTERNAL(tricore_doirq, 0, 255)
uintptr_t *regs;
icr.U = __mfcr(CPU_ICR);
- regs = (uintptr_t *)__mfcr(CPU_PCXI);
+ regs = tricore_csa2addr(__mfcr(CPU_PCXI));
if (running_task != NULL)
{
@@ -112,7 +112,7 @@ IFX_INTERRUPT_INTERNAL(tricore_doirq, 0, 255)
running_task = tcb;
g_running_tasks[this_cpu()] = running_task;
- __mtcr(CPU_PCXI, (uintptr_t)up_current_regs());
+ __mtcr(CPU_PCXI, tricore_addr2csa(up_current_regs()));
__isync();
}
diff --git a/arch/tricore/src/common/tricore_svcall.c b/arch/tricore/src/common/tricore_svcall.c
index 575a43eebf5..4e89f8475c1 100644
--- a/arch/tricore/src/common/tricore_svcall.c
+++ b/arch/tricore/src/common/tricore_svcall.c
@@ -108,7 +108,7 @@ void tricore_svcall(volatile void *trap)
case SYS_switch_context:
{
- *(uintptr_t **)regs[REG_D9] = (uintptr_t *)regs[REG_UPCXI];
+ *(uintptr_t **)regs[REG_D9] = tricore_csa2addr(regs[REG_UPCXI]);
up_set_current_regs((uintptr_t *)regs[REG_D10]);
}
break;
@@ -133,7 +133,7 @@ void tricore_svcall(volatile void *trap)
g_running_tasks[cpu] = this_task();
- regs[REG_UPCXI] = (uintptr_t)up_current_regs();
+ regs[REG_UPCXI] = tricore_addr2csa(up_current_regs());
__isync();
}
(nuttx) 02/06: arch/tricore: Resolving gcc compilation warning
Posted by xi...@apache.org.
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 8a15aebfeae73872eee16692772873bec6226195
Author: liwenxiang1 <li...@xiaomi.com>
AuthorDate: Thu Nov 7 20:19:56 2024 +0800
arch/tricore: Resolving gcc compilation warning
fix type error and add up_getusrpc()
Signed-off-by: liwenxiang1 <li...@xiaomi.com>
---
arch/tricore/include/inttypes.h | 4 ++--
arch/tricore/include/irq.h | 7 +++++++
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/arch/tricore/include/inttypes.h b/arch/tricore/include/inttypes.h
index d5b5ba723ab..5e762312f1f 100644
--- a/arch/tricore/include/inttypes.h
+++ b/arch/tricore/include/inttypes.h
@@ -69,14 +69,14 @@
#define PRIx32 "lx"
#define PRIx64 "llx"
-#define PRIxPTR "x"
+#define PRIxPTR "lx"
#define PRIX8 "X"
#define PRIX16 "X"
#define PRIX32 "lX"
#define PRIX64 "llX"
-#define PRIXPTR "X"
+#define PRIXPTR "lX"
#define SCNd8 "hhd"
#define SCNd16 "hd"
diff --git a/arch/tricore/include/irq.h b/arch/tricore/include/irq.h
index ae3e09c5312..592ba712561 100644
--- a/arch/tricore/include/irq.h
+++ b/arch/tricore/include/irq.h
@@ -220,6 +220,13 @@ static inline_function uintptr_t up_getusrsp(void *regs)
#endif /* __ASSEMBLY__ */
+/****************************************************************************
+ * Name: up_getusrpc
+ ****************************************************************************/
+
+#define up_getusrpc(regs) \
+ (((uint32_t *)((regs) ? (regs) : up_current_regs()))[REG_UPC])
+
#undef EXTERN
#ifdef __cplusplus
}
(nuttx) 06/06: arch/tricore: syscall SYS_switch_context and SYS_restore_context use 0 para
Posted by xi...@apache.org.
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 8786c814f0022b5f67f24ba3dc107ab6e991f88c
Author: zhangyu117 <zh...@xiaomi.com>
AuthorDate: Mon Dec 16 15:50:01 2024 +0800
arch/tricore: syscall SYS_switch_context and SYS_restore_context use 0 para
after task switch optimization, we can just use g_running_tasks and this_task() without pass params
Signed-off-by: zhangyu117 <zh...@xiaomi.com>
---
arch/tricore/include/irq.h | 5 +-
arch/tricore/src/common/tricore_doirq.c | 19 ++++----
arch/tricore/src/common/tricore_exit.c | 10 +---
arch/tricore/src/common/tricore_internal.h | 5 +-
arch/tricore/src/common/tricore_sigdeliver.c | 3 +-
arch/tricore/src/common/tricore_svcall.c | 70 +++++++---------------------
6 files changed, 31 insertions(+), 81 deletions(-)
diff --git a/arch/tricore/include/irq.h b/arch/tricore/include/irq.h
index 0c1178673d6..f1018dcb667 100644
--- a/arch/tricore/include/irq.h
+++ b/arch/tricore/include/irq.h
@@ -220,10 +220,9 @@ static inline_function uintptr_t up_getusrsp(void *regs)
do { \
if (!up_interrupt_context()) \
{ \
- nxsched_switch_context(rtcb, tcb); \
- sys_call2(SYS_switch_context, (uintptr_t)&rtcb->xcp.regs, \
- (uintptr_t)tcb->xcp.regs); \
+ sys_call0(SYS_switch_context); \
} \
+ UNUSED(rtcb); \
} while (0)
/****************************************************************************
diff --git a/arch/tricore/src/common/tricore_doirq.c b/arch/tricore/src/common/tricore_doirq.c
index 228cb2de744..02da6543d69 100644
--- a/arch/tricore/src/common/tricore_doirq.c
+++ b/arch/tricore/src/common/tricore_doirq.c
@@ -46,8 +46,8 @@
IFX_INTERRUPT_INTERNAL(tricore_doirq, 0, 255)
{
- struct tcb_s *running_task = g_running_tasks[this_cpu()];
- struct tcb_s *tcb;
+ struct tcb_s **running_task = &g_running_tasks[this_cpu()];
+ struct tcb_s *tcb = this_task();
#ifdef CONFIG_SUPPRESS_INTERRUPTS
PANIC();
@@ -58,9 +58,9 @@ IFX_INTERRUPT_INTERNAL(tricore_doirq, 0, 255)
icr.U = __mfcr(CPU_ICR);
regs = tricore_csa2addr(__mfcr(CPU_PCXI));
- if (running_task != NULL)
+ if (*running_task != NULL)
{
- running_task->xcp.regs = regs;
+ (*running_task)->xcp.regs = regs;
}
board_autoled_on(LED_INIRQ);
@@ -77,11 +77,9 @@ IFX_INTERRUPT_INTERNAL(tricore_doirq, 0, 255)
irq_dispatch(icr.B.CCPN, regs);
- tcb = this_task();
-
/* Check for a context switch. */
- if (regs != tcb->xcp.regs)
+ if (*running_task != tcb)
{
#ifdef CONFIG_ARCH_ADDRENV
/* Make sure that the address environment for the previously
@@ -95,15 +93,14 @@ IFX_INTERRUPT_INTERNAL(tricore_doirq, 0, 255)
/* Update scheduler parameters */
- nxsched_switch_context(running_task, tcb);
+ nxsched_switch_context(*running_task, tcb);
/* Record the new "running" task when context switch occurred.
* g_running_tasks[] is only used by assertion logic for reporting
* crashes.
*/
- running_task = tcb;
- g_running_tasks[this_cpu()] = running_task;
+ *running_task = tcb;
__mtcr(CPU_PCXI, tricore_addr2csa(tcb->xcp.regs));
__isync();
@@ -117,7 +114,7 @@ IFX_INTERRUPT_INTERNAL(tricore_doirq, 0, 255)
* and will be marked as NULL to avoid misusage.
*/
- running_task->xcp.regs = NULL;
+ (*running_task)->xcp.regs = NULL;
board_autoled_off(LED_INIRQ);
#endif
}
diff --git a/arch/tricore/src/common/tricore_exit.c b/arch/tricore/src/common/tricore_exit.c
index ffa58ddc381..71201c3b3ec 100644
--- a/arch/tricore/src/common/tricore_exit.c
+++ b/arch/tricore/src/common/tricore_exit.c
@@ -56,25 +56,17 @@
void up_exit(int status)
{
- struct tcb_s *tcb = this_task();
-
/* Destroy the task at the head of the ready to run list. */
nxtask_exit();
- /* Now, perform the context switch to the new ready-to-run task at the
- * head of the list.
- */
-
- tcb = this_task();
-
/* Scheduler parameters will update inside syscall */
g_running_tasks[this_cpu()] = NULL;
/* Then switch contexts */
- tricore_fullcontextrestore(tcb->xcp.regs);
+ tricore_fullcontextrestore();
/* tricore_fullcontextrestore() should not return but could if the software
* interrupts are disabled.
diff --git a/arch/tricore/src/common/tricore_internal.h b/arch/tricore/src/common/tricore_internal.h
index e75faf4d551..4cbc9b1e4b7 100644
--- a/arch/tricore/src/common/tricore_internal.h
+++ b/arch/tricore/src/common/tricore_internal.h
@@ -129,10 +129,7 @@
#define modreg32(v,m,a) putreg32((getreg32(a) & ~(m)) | ((v) & (m)), (a))
#define modreg64(v,m,a) putreg64((getreg64(a) & ~(m)) | ((v) & (m)), (a))
-/* Context switching */
-
-#define tricore_fullcontextrestore(restoreregs) \
- sys_call1(SYS_restore_context, (uintptr_t)restoreregs);
+#define tricore_fullcontextrestore() sys_call0(SYS_restore_context)
/****************************************************************************
* Public Types
diff --git a/arch/tricore/src/common/tricore_sigdeliver.c b/arch/tricore/src/common/tricore_sigdeliver.c
index 5149dec75ba..bddb4892985 100644
--- a/arch/tricore/src/common/tricore_sigdeliver.c
+++ b/arch/tricore/src/common/tricore_sigdeliver.c
@@ -116,5 +116,6 @@ retry:
board_autoled_off(LED_SIGNAL);
- tricore_fullcontextrestore(regs);
+ rtcb->xcp.regs = regs;
+ tricore_fullcontextrestore();
}
diff --git a/arch/tricore/src/common/tricore_svcall.c b/arch/tricore/src/common/tricore_svcall.c
index 601f754da15..fb1f35c686b 100644
--- a/arch/tricore/src/common/tricore_svcall.c
+++ b/arch/tricore/src/common/tricore_svcall.c
@@ -56,16 +56,13 @@
void tricore_svcall(volatile void *trap)
{
- struct tcb_s *running_task;
- struct tcb_s *tcb;
+ struct tcb_s **running_task = &g_running_tasks[this_cpu()];
+ struct tcb_s *tcb = this_task();
uintptr_t *regs;
uint32_t cmd;
regs = (uintptr_t *)__mfcr(CPU_PCXI);
- running_task = g_running_tasks[this_cpu()];
- tcb = this_task();
-
/* DSYNC instruction should be executed immediately prior to the MTCR */
__dsync();
@@ -78,66 +75,33 @@ void tricore_svcall(volatile void *trap)
cmd = regs[REG_D8];
+ if (cmd != SYS_restore_context)
+ {
+ (*running_task)->xcp.regs = tricore_csa2addr(regs[REG_UPCXI]);
+ }
+ else
+ {
+ tricore_reclaim_csa(regs[REG_UPCXI]);
+ }
+
/* Handle the SVCall according to the command in R0 */
switch (cmd)
{
- /* R0=SYS_restore_context: This a restore context command:
- *
- * void tricore_fullcontextrestore(uint32_t *restoreregs)
- * noreturn_function;
- *
- * At this point, the following values are saved in context:
- *
- * R0 = SYS_restore_context
- * R1 = restoreregs
- *
- * In this case, we simply need to set g_current_regs to restore
- * register area referenced in the saved R1. context == g_current_regs
- * is the normal exception return. By setting g_current_regs =
- * context[R1], we force the return to the saved context referenced
- * in R1.
- */
+ case SYS_switch_context:
+ nxsched_switch_context(*running_task, tcb);
case SYS_restore_context:
- {
- tricore_reclaim_csa(regs[REG_UPCXI]);
- tcb->xcp.regs = (uintptr_t *)regs[REG_D9];
- }
- break;
-
- case SYS_switch_context:
- {
- *(uintptr_t **)regs[REG_D9] = tricore_csa2addr(regs[REG_UPCXI]);
- tcb->xcp.regs = (uintptr_t *)regs[REG_D10];
- }
+ *running_task = tcb;
+ regs[REG_UPCXI] = tricore_addr2csa(tcb->xcp.regs);
+ __isync();
break;
default:
- {
- svcerr("ERROR: Bad SYS call: %d\n", (int)regs[REG_D0]);
- }
+ svcerr("ERROR: Bad SYS call: %d\n", (int)regs[REG_D0]);
break;
}
- if (regs != tcb->xcp.regs)
- {
- /* Update scheduler parameters */
-
- nxsched_switch_context(running_task, tcb);
-
- /* Record the new "running" task when context switch occurred.
- * g_running_tasks[] is only used by assertion logic for reporting
- * crashes.
- */
-
- g_running_tasks[this_cpu()] = this_task();
-
- regs[REG_UPCXI] = tricore_addr2csa(tcb->xcp.regs);
-
- __isync();
- }
-
/* Set irq flag */
up_set_interrupt_context(false);