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

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

commit 7952a1d0fe13ed6d50918a3eaad3791c904b1ac4
Author: zhangyu117 <[email protected]>
AuthorDate: Thu Nov 26 11:38:35 2026 +0800

    arch/tricore: fix up_tls_info() to match the a8 TP layout
    
    Use the ARM/ARM64/RISC-V thread-pointer layout: A8 points past the
    tls_info_s metadata and up_tls_info() subtracts one to recover its address.
    Initialize A8 for the idle thread and apply the same offset on context
    switches so __thread accesses and TLS metadata lookups stay consistent.
    
    Signed-off-by: zhangyu117 <[email protected]>
---
 arch/tricore/include/irq.h                     | 2 +-
 arch/tricore/src/common/tricore_doirq.c        | 4 +++-
 arch/tricore/src/common/tricore_initialstate.c | 2 ++
 arch/tricore/src/common/tricore_svcall.c       | 4 +++-
 4 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/tricore/include/irq.h b/arch/tricore/include/irq.h
index ee56131bdc1..80070aed5ef 100644
--- a/arch/tricore/include/irq.h
+++ b/arch/tricore/include/irq.h
@@ -195,7 +195,7 @@
 #define FPU_TRAP_FZE_SHIFT    20
 #define FPU_TRAP_TCL_SHIFT    1
 
-#define up_tls_info() ((struct tls_info_s *)read_sysreg(a8))
+#define up_tls_info() ((struct tls_info_s *)read_sysreg(a8) - 1)
 
 #ifndef __ASSEMBLY__
 
diff --git a/arch/tricore/src/common/tricore_doirq.c 
b/arch/tricore/src/common/tricore_doirq.c
index 3d8579d1c6f..62540242160 100644
--- a/arch/tricore/src/common/tricore_doirq.c
+++ b/arch/tricore/src/common/tricore_doirq.c
@@ -33,6 +33,7 @@
 #include <nuttx/arch.h>
 #include <nuttx/addrenv.h>
 #include <nuttx/board.h>
+#include <nuttx/tls.h>
 
 #include <arch/barriers.h>
 #include <arch/board/board.h>
@@ -156,7 +157,8 @@ void tricore_irq_sched(void)
 
       /* Update the TLS pointer */
 
-      tricore_set_tls_info(tcb->stack_alloc_ptr);
+      tricore_set_tls_info((uintptr_t)tcb->stack_alloc_ptr +
+                           sizeof(struct tls_info_s));
 
       /* Record the new "running" task when context switch occurred.
        * g_running_tasks[] is only used by assertion logic for reporting
diff --git a/arch/tricore/src/common/tricore_initialstate.c 
b/arch/tricore/src/common/tricore_initialstate.c
index 3c0baf997f2..29a68bb232f 100644
--- a/arch/tricore/src/common/tricore_initialstate.c
+++ b/arch/tricore/src/common/tricore_initialstate.c
@@ -79,6 +79,8 @@ void up_initial_state(struct tcb_s *tcb)
                                       CONFIG_IDLETHREAD_STACKSIZE);
       tcb->stack_base_ptr  = tcb->stack_alloc_ptr;
       tcb->adj_stack_size  = CONFIG_IDLETHREAD_STACKSIZE;
+      tricore_set_tls_info((uintptr_t)tcb->stack_alloc_ptr +
+                           sizeof(struct tls_info_s));
 
 #ifdef CONFIG_STACK_COLORATION
       /* If stack debug is enabled, then fill the stack with a
diff --git a/arch/tricore/src/common/tricore_svcall.c 
b/arch/tricore/src/common/tricore_svcall.c
index 6757a207b75..3dc5afa7a81 100644
--- a/arch/tricore/src/common/tricore_svcall.c
+++ b/arch/tricore/src/common/tricore_svcall.c
@@ -31,6 +31,7 @@
 #include <assert.h>
 #include <nuttx/debug.h>
 #include <nuttx/userspace.h>
+#include <nuttx/tls.h>
 #include <syscall.h>
 
 #include <arch/barriers.h>
@@ -125,7 +126,8 @@ void tricore_svcall(volatile void *trap)
         nxsched_switch_context(*running_task, tcb);
 
       case SYS_restore_context:
-        tricore_set_tls_info(tcb->stack_alloc_ptr);
+        tricore_set_tls_info((uintptr_t)tcb->stack_alloc_ptr +
+                             sizeof(struct tls_info_s));
         *running_task = tcb;
         tricore_mtcr(TRICORE_CPU_PCXI, tricore_addr2csa(tcb->xcp.regs));
         UP_ISB();

Reply via email to