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 077b5a9ae271d292fe3fcee647d91a06928b9198
Author: buxiasen <[email protected]>
AuthorDate: Fri Nov 27 21:17:31 2026 +0800

    arch/tricore: select idle and interrupt stacks by CPU
    
    Use per-core linker-provided stack tops in multi-core builds. Route idle 
stack setup through up_cpu_idlestack() and use the selected interrupt stack for 
coloration and usage checks.
    
    Signed-off-by: buxiasen <[email protected]>
---
 arch/tricore/src/common/tricore_checkstack.c   |  2 +-
 arch/tricore/src/common/tricore_getintstack.c  | 84 ++++++++++++++++++++++++++
 arch/tricore/src/common/tricore_initialstate.c |  6 +-
 arch/tricore/src/common/tricore_internal.h     |  3 -
 arch/tricore/src/common/tricore_irq.c          |  2 +-
 5 files changed, 88 insertions(+), 9 deletions(-)

diff --git a/arch/tricore/src/common/tricore_checkstack.c 
b/arch/tricore/src/common/tricore_checkstack.c
index 77a4653e032..10d588ed718 100644
--- a/arch/tricore/src/common/tricore_checkstack.c
+++ b/arch/tricore/src/common/tricore_checkstack.c
@@ -150,7 +150,7 @@ size_t up_check_intstack(int cpu, size_t check_size)
       check_size = CONFIG_ARCH_INTERRUPTSTACK & ~15;
     }
 
-  return tricore_stack_check((uintptr_t)g_intstackalloc, check_size);
+  return tricore_stack_check(up_get_intstackbase(cpu), check_size);
 }
 #endif
 
diff --git a/arch/tricore/src/common/tricore_getintstack.c 
b/arch/tricore/src/common/tricore_getintstack.c
index 5647e8380ca..8411d91caa2 100644
--- a/arch/tricore/src/common/tricore_getintstack.c
+++ b/arch/tricore/src/common/tricore_getintstack.c
@@ -28,6 +28,8 @@
 
 #include <stdint.h>
 
+#include <nuttx/sched.h>
+
 #include "tricore_internal.h"
 
 /****************************************************************************
@@ -38,9 +40,91 @@
  * Name: up_get_intstackbase
  ****************************************************************************/
 
+#ifndef CONFIG_UP
+extern uintptr_t __ustack0[];
+extern uintptr_t __ustack1[];
+extern uintptr_t __ustack2[];
+extern uintptr_t __ustack3[];
+extern uintptr_t __ustack4[];
+extern uintptr_t __ustack5[];
+extern uintptr_t __istack0[];
+extern uintptr_t __istack1[];
+extern uintptr_t __istack2[];
+extern uintptr_t __istack3[];
+extern uintptr_t __istack4[];
+extern uintptr_t __istack5[];
+
+static uintptr_t g_idle_topstack[CONFIG_NCPUS] =
+{
+  [0] = (uintptr_t)__ustack0,
+#if CONFIG_NCPUS > 1
+  [1] = (uintptr_t)__ustack1,
+#if CONFIG_NCPUS > 2
+  [2] = (uintptr_t)__ustack2,
+#if CONFIG_NCPUS > 3
+  [3] = (uintptr_t)__ustack3,
+#if CONFIG_NCPUS > 4
+  [4] = (uintptr_t)__ustack4,
+#if CONFIG_NCPUS > 5
+  [5] = (uintptr_t)__ustack5,
+#endif
+#endif
+#endif
+#endif
+#endif
+};
+
+#if CONFIG_ARCH_INTERRUPTSTACK > 3
+static uintptr_t g_int_topstack[CONFIG_NCPUS] =
+{
+  [0] = (uintptr_t)__istack0,
+#if CONFIG_NCPUS > 1
+  [1] = (uintptr_t)__istack1,
+#if CONFIG_NCPUS > 2
+  [2] = (uintptr_t)__istack2,
+#if CONFIG_NCPUS > 3
+  [3] = (uintptr_t)__istack3,
+#if CONFIG_NCPUS > 4
+  [4] = (uintptr_t)__istack4,
+#if CONFIG_NCPUS > 5
+  [5] = (uintptr_t)__istack5,
+#endif
+#endif
+#endif
+#endif
+#endif
+};
+
+uintptr_t up_get_intstackbase(int cpu)
+{
+  return (uintptr_t)g_int_topstack[cpu] - CONFIG_ARCH_INTERRUPTSTACK;
+}
+#endif
+
+int up_cpu_idlestack(int cpu, struct tcb_s *tcb, size_t stack_size)
+{
+  tcb->stack_alloc_ptr = (void *)(g_idle_topstack[cpu] - stack_size);
+  tcb->stack_base_ptr  = tcb->stack_alloc_ptr;
+  tcb->adj_stack_size  = stack_size;
+  return 0;
+}
+#else
+
+#define g_idle_topstack ((uintptr_t)__ustack)
+#define g_intstackalloc ((uintptr_t)__istack - CONFIG_ARCH_INTERRUPTSTACK)
+
 #if CONFIG_ARCH_INTERRUPTSTACK > 3
 uintptr_t up_get_intstackbase(int cpu)
 {
   return (uintptr_t)g_intstackalloc;
 }
 #endif
+
+int up_cpu_idlestack(int cpu, struct tcb_s *tcb, size_t stack_size)
+{
+  tcb->stack_alloc_ptr = (void *)(g_idle_topstack - stack_size);
+  tcb->stack_base_ptr  = tcb->stack_alloc_ptr;
+  tcb->adj_stack_size  = stack_size;
+  return 0;
+}
+#endif
diff --git a/arch/tricore/src/common/tricore_initialstate.c 
b/arch/tricore/src/common/tricore_initialstate.c
index 07190b36021..95bf1efb34d 100644
--- a/arch/tricore/src/common/tricore_initialstate.c
+++ b/arch/tricore/src/common/tricore_initialstate.c
@@ -75,10 +75,8 @@ void up_initial_state(struct tcb_s *tcb)
 
   if (tcb->pid == IDLE_PROCESS_ID)
     {
-      tcb->stack_alloc_ptr = (void *)((uintptr_t)g_idle_topstack -
-                                      CONFIG_IDLETHREAD_STACKSIZE);
-      tcb->stack_base_ptr  = tcb->stack_alloc_ptr;
-      tcb->adj_stack_size  = CONFIG_IDLETHREAD_STACKSIZE;
+      up_cpu_idlestack(up_cpu_index(), tcb,
+                       CONFIG_IDLETHREAD_STACKSIZE);
       tricore_set_tls_info((uintptr_t)tcb->stack_alloc_ptr +
                            sizeof(struct tls_info_s));
 
diff --git a/arch/tricore/src/common/tricore_internal.h 
b/arch/tricore/src/common/tricore_internal.h
index 985c0d336d0..27e3fd5f8f9 100644
--- a/arch/tricore/src/common/tricore_internal.h
+++ b/arch/tricore/src/common/tricore_internal.h
@@ -149,14 +149,11 @@ typedef void (*up_vector_t)(void);
  */
 
 extern uintptr_t        __ustack[];
-#define g_idle_topstack __ustack
 
 /* Address of the saved user stack pointer */
 
 #if CONFIG_ARCH_INTERRUPTSTACK > 3
 extern uintptr_t        __istack[];
-#define g_intstackalloc ((uintptr_t)__istack - CONFIG_ARCH_INTERRUPTSTACK)
-#define g_intstacktop   __istack
 #endif
 
 /* These symbols are setup by the linker script. */
diff --git a/arch/tricore/src/common/tricore_irq.c 
b/arch/tricore/src/common/tricore_irq.c
index ccafe9ab074..a28dd30608a 100644
--- a/arch/tricore/src/common/tricore_irq.c
+++ b/arch/tricore/src/common/tricore_irq.c
@@ -53,7 +53,7 @@
 #if defined(CONFIG_STACK_COLORATION) && CONFIG_ARCH_INTERRUPTSTACK > 15
 static inline void tricore_color_intstack(void)
 {
-  uint32_t *ptr = (uint32_t *)g_intstackalloc;
+  uint32_t *ptr = (uint32_t *)up_get_intstackbase(up_cpu_index());
   ssize_t size;
 
   for (size = (CONFIG_ARCH_INTERRUPTSTACK & ~15);

Reply via email to