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

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

commit 5abf04a346fc00ed694404779f8a0fa87b4c6f84
Author: zhangyu117 <[email protected]>
AuthorDate: Wed Jun 4 10:39:21 2025 +0800

    arch/tricore: use 'ji' instead of 'call' to execute svcall function
    
    When a svcall trap is taken, the trap entry has already saved the
    context into CSAs, and then the svcall handler is executed by 'call',
    which allocates one more CSA that is not needed.
    
    Use 'ji' to jump to the svcall handler instead, so one CSA is saved
    for each svcall.
    
    Signed-off-by: zhangyu117 <[email protected]>
---
 arch/tricore/src/common/Ifx_Cfg_Trap.h   | 29 ++++++++++++++++++++++-------
 arch/tricore/src/common/tricore_svcall.c | 22 ++++++++++++----------
 tools/nxstyle.c                          |  6 ++++++
 3 files changed, 40 insertions(+), 17 deletions(-)

diff --git a/arch/tricore/src/common/Ifx_Cfg_Trap.h 
b/arch/tricore/src/common/Ifx_Cfg_Trap.h
index 87b0723bd17..15a22d3db4a 100644
--- a/arch/tricore/src/common/Ifx_Cfg_Trap.h
+++ b/arch/tricore/src/common/Ifx_Cfg_Trap.h
@@ -50,13 +50,28 @@
 #define IFX_CFG_CPU_TRAP_BE_HOOK(trapInfo)              
tricore_trapcall(&trapInfo)
 #define IFX_CFG_CPU_TRAP_ASSERT_HOOK(trapInfo)          
tricore_trapcall(&trapInfo)
 
-#define IFX_CFG_CPU_TRAP_SYSCALL_CPU0_HOOK(trapWatch)   
tricore_svcall(&trapWatch)
-#define IFX_CFG_CPU_TRAP_SYSCALL_CPU1_HOOK(trapWatch)   
tricore_svcall(&trapWatch)
-#define IFX_CFG_CPU_TRAP_SYSCALL_CPU2_HOOK(trapWatch)   
tricore_svcall(&trapWatch)
-#define IFX_CFG_CPU_TRAP_SYSCALL_CPU3_HOOK(trapWatch)   
tricore_svcall(&trapWatch)
-#define IFX_CFG_CPU_TRAP_SYSCALL_CPU4_HOOK(trapWatch)   
tricore_svcall(&trapWatch)
-#define IFX_CFG_CPU_TRAP_SYSCALL_CPU5_HOOK(trapWatch)   
tricore_svcall(&trapWatch)
-#define IFX_CFG_CPU_TRAP_SYSCALL_CPU6_HOOK(trapWatch)   
tricore_svcall(&trapWatch)
+#define IFX_CFG_CPU_TRAP_SYSCALL_HOOK(trapWatch)       \
+  do                                                   \
+    {                                                  \
+      Ifx__moveToAddrParam0((void *)&trapWatch);       \
+      Ifx__jumpToFunctionWithLink(tricore_svcall);     \
+    }                                                  \
+  while (0)
+
+#define IFX_CFG_CPU_TRAP_SYSCALL_CPU0_HOOK(trapWatch)  \
+  IFX_CFG_CPU_TRAP_SYSCALL_HOOK(trapWatch)
+#define IFX_CFG_CPU_TRAP_SYSCALL_CPU1_HOOK(trapWatch)  \
+  IFX_CFG_CPU_TRAP_SYSCALL_HOOK(trapWatch)
+#define IFX_CFG_CPU_TRAP_SYSCALL_CPU2_HOOK(trapWatch)  \
+  IFX_CFG_CPU_TRAP_SYSCALL_HOOK(trapWatch)
+#define IFX_CFG_CPU_TRAP_SYSCALL_CPU3_HOOK(trapWatch)  \
+  IFX_CFG_CPU_TRAP_SYSCALL_HOOK(trapWatch)
+#define IFX_CFG_CPU_TRAP_SYSCALL_CPU4_HOOK(trapWatch)  \
+  IFX_CFG_CPU_TRAP_SYSCALL_HOOK(trapWatch)
+#define IFX_CFG_CPU_TRAP_SYSCALL_CPU5_HOOK(trapWatch)  \
+  IFX_CFG_CPU_TRAP_SYSCALL_HOOK(trapWatch)
+#define IFX_CFG_CPU_TRAP_SYSCALL_CPU6_HOOK(trapWatch)  \
+  IFX_CFG_CPU_TRAP_SYSCALL_HOOK(trapWatch)
 
 #endif /* IFX_CFG_EXTEND_TRAP_HOOKS */
 
diff --git a/arch/tricore/src/common/tricore_svcall.c 
b/arch/tricore/src/common/tricore_svcall.c
index 5259ed7fd1e..2c712d4b66e 100644
--- a/arch/tricore/src/common/tricore_svcall.c
+++ b/arch/tricore/src/common/tricore_svcall.c
@@ -59,30 +59,30 @@ void tricore_svcall(volatile void *trap)
 {
   struct tcb_s **running_task = &g_running_tasks[this_cpu()];
   struct tcb_s *tcb = this_task();
-  uintptr_t *regs;
+  uintptr_t *plregs;
+  uintptr_t *puregs;
   uint32_t cmd;
 
-  regs = (uintptr_t *)tricore_mfcr(CPU_PCXI);
-
-  /* DSYNC instruction should be executed immediately prior to the MTCR */
+  /* DSYNC instruction should be executed immediately prior to the MFCR */
 
   UP_DSB();
 
-  regs = tricore_csa2addr((uintptr_t)regs);
+  plregs = tricore_csa2addr(tricore_mfcr(CPU_PCXI));
+  puregs = tricore_csa2addr(plregs[REG_LPCXI]);
 
   /* Set irq flag */
 
   up_set_interrupt_context(true);
 
-  cmd = regs[REG_D8];
+  cmd = puregs[REG_D8];
 
   if (cmd != SYS_restore_context)
     {
-      (*running_task)->xcp.regs = tricore_csa2addr(regs[REG_UPCXI]);
+      (*running_task)->xcp.regs = plregs;
     }
   else
     {
-      tricore_reclaim_csa(regs[REG_UPCXI]);
+      tricore_reclaim_csa(tricore_addr2csa(plregs));
     }
 
   /* Handle the SVCall according to the command in R0 */
@@ -94,16 +94,18 @@ void tricore_svcall(volatile void *trap)
 
       case SYS_restore_context:
         *running_task = tcb;
-        regs[REG_UPCXI] = tricore_addr2csa(tcb->xcp.regs);
+        tricore_mtcr(CPU_PCXI, tricore_addr2csa(tcb->xcp.regs));
         UP_ISB();
         break;
 
       default:
-        svcerr("ERROR: Bad SYS call: %d\n", (int)regs[REG_D0]);
+        svcerr("ERROR: Bad SYS call: %d\n", (int)puregs[REG_D8]);
         break;
     }
 
   /* Set irq flag */
 
   up_set_interrupt_context(false);
+
+  __jumpBackToLink();
 }
diff --git a/tools/nxstyle.c b/tools/nxstyle.c
index 9598948d3be..365663ad69a 100644
--- a/tools/nxstyle.c
+++ b/tools/nxstyle.c
@@ -772,6 +772,12 @@ static const char *g_white_content_list[] =
   "unzGoToNextFile",
   "unzGoToFirstFile",
 
+  /* Ref:
+   * arch/tricore/src/common
+   */
+
+  "__jumpBackToLink",
+
   /* Ref:
    * apps/netutils/telnetc/telnetc.c
    */

Reply via email to