source: rtems/cpukit/score/cpu/nios2/nios2-context-initialize.c @ c968b27

Last change on this file since c968b27 was c968b27, checked in by Sebastian Huber <sebastian.huber@…>, on 01/08/21 at 08:04:22

nios2: Add TLS support

Update #4214.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 * Copyright (c) 2011, 2021 embedded brains GmbH
3 *
4 * Copyright (c) 2006 Kolja Waschk (rtemsdev/ixo.de)
5 *
6 * COPYRIGHT (c) 1989-2006
7 * On-Line Applications Research Corporation (OAR).
8 *
9 * The license and distribution terms for this file may be
10 * found in the file LICENSE in this distribution or at
11 * http://www.rtems.org/license/LICENSE.
12 */
13
14#ifdef HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <string.h>
19
20#include <rtems/score/cpu.h>
21#include <rtems/score/nios2-utility.h>
22#include <rtems/score/interr.h>
23#include <rtems/score/tls.h>
24
25void _CPU_Context_Initialize(
26  Context_Control *context,
27  void *stack_area_begin,
28  size_t stack_area_size,
29  uint32_t new_level,
30  void (*entry_point)( void ),
31  bool is_fp,
32  void *tls_area
33)
34{
35  const Nios2_MPU_Configuration *mpu_config = _Nios2_MPU_Get_configuration();
36  uint32_t stack = (uint32_t) stack_area_begin + stack_area_size - 4;
37
38  memset(context, 0, sizeof(*context));
39
40  context->fp = stack;
41  context->status = _Nios2_ISR_Set_level( new_level, NIOS2_STATUS_PIE );
42  context->sp = stack;
43  context->ra = (uint32_t) entry_point;
44
45  if ( mpu_config != NULL ) {
46    Nios2_MPU_Region_descriptor desc = {
47      .index = mpu_config->data_index_for_stack_protection,
48      .base = stack_area_begin,
49      .end = (const void *) RTEMS_ALIGN_UP(
50        (uintptr_t) stack_area_begin + stack_area_size +
51          _TLS_Get_allocation_size(),
52        1U << mpu_config->data_region_size_log2
53      ),
54      .perm = NIOS2_MPU_DATA_PERM_SVR_READWRITE_USER_NONE,
55      .data = true,
56      .cacheable = mpu_config->enable_data_cache_for_stack,
57      .read = false,
58      .write = true
59    };
60    bool ok = _Nios2_MPU_Setup_region_registers(
61      mpu_config,
62      &desc,
63      &context->stack_mpubase,
64      &context->stack_mpuacc
65    );
66
67    if ( !ok ) {
68      /* The task stack allocator must ensure that the stack area is valid */
69      _Terminate( INTERNAL_ERROR_CORE, 0xdeadbeef );
70    }
71  }
72
73  if ( tls_area != NULL ) {
74    context->r23 = (uintptr_t) tls_area +
75      _TLS_Get_thread_control_block_area_size( (uintptr_t) _TLS_Alignment ) +
76       0x7000;
77    _TLS_TCB_before_TLS_block_initialize( tls_area );
78  }
79}
Note: See TracBrowser for help on using the repository browser.