[rtems commit] nios2: Add TLS support

Sebastian Huber sebh at rtems.org
Mon Feb 1 06:20:12 UTC 2021


Module:    rtems
Branch:    master
Commit:    c968b27fbd8d8b4f012b638826d35446b4f4e0c0
Changeset: http://git.rtems.org/rtems/commit/?id=c968b27fbd8d8b4f012b638826d35446b4f4e0c0

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Jan  8 09:04:22 2021 +0100

nios2: Add TLS support

Update #4214.

---

 cpukit/score/cpu/nios2/nios2-context-initialize.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/cpukit/score/cpu/nios2/nios2-context-initialize.c b/cpukit/score/cpu/nios2/nios2-context-initialize.c
index 1b7d1bb..6950ce4 100644
--- a/cpukit/score/cpu/nios2/nios2-context-initialize.c
+++ b/cpukit/score/cpu/nios2/nios2-context-initialize.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011 embedded brains GmbH
+ * Copyright (c) 2011, 2021 embedded brains GmbH
  *
  * Copyright (c) 2006 Kolja Waschk (rtemsdev/ixo.de)
  *
@@ -20,6 +20,7 @@
 #include <rtems/score/cpu.h>
 #include <rtems/score/nios2-utility.h>
 #include <rtems/score/interr.h>
+#include <rtems/score/tls.h>
 
 void _CPU_Context_Initialize(
   Context_Control *context,
@@ -44,9 +45,12 @@ void _CPU_Context_Initialize(
   if ( mpu_config != NULL ) {
     Nios2_MPU_Region_descriptor desc = {
       .index = mpu_config->data_index_for_stack_protection,
-      /* FIXME: Brocken stack allocator */
-      .base = (void *) ((int) stack_area_begin & ~((1 << mpu_config->data_region_size_log2) - 1)),
-      .end = (char *) stack_area_begin + stack_area_size,
+      .base = stack_area_begin,
+      .end = (const void *) RTEMS_ALIGN_UP(
+        (uintptr_t) stack_area_begin + stack_area_size +
+          _TLS_Get_allocation_size(),
+        1U << mpu_config->data_region_size_log2
+      ),
       .perm = NIOS2_MPU_DATA_PERM_SVR_READWRITE_USER_NONE,
       .data = true,
       .cacheable = mpu_config->enable_data_cache_for_stack,
@@ -65,4 +69,11 @@ void _CPU_Context_Initialize(
       _Terminate( INTERNAL_ERROR_CORE, 0xdeadbeef );
     }
   }
+
+  if ( tls_area != NULL ) {
+    context->r23 = (uintptr_t) tls_area +
+      _TLS_Get_thread_control_block_area_size( (uintptr_t) _TLS_Alignment ) +
+       0x7000;
+    _TLS_TCB_before_TLS_block_initialize( tls_area );
+  }
 }



More information about the vc mailing list