File indexing completed on 2025-05-11 08:24:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 #ifdef HAVE_CONFIG_H
0034 #include "config.h"
0035 #endif
0036
0037 #include <string.h>
0038
0039 #include <rtems/score/cpu.h>
0040 #include <rtems/score/nios2-utility.h>
0041 #include <rtems/score/interr.h>
0042 #include <rtems/score/tls.h>
0043
0044 void _CPU_Context_Initialize(
0045 Context_Control *context,
0046 void *stack_area_begin,
0047 size_t stack_area_size,
0048 uint32_t new_level,
0049 void (*entry_point)( void ),
0050 bool is_fp,
0051 void *tls_area
0052 )
0053 {
0054 const Nios2_MPU_Configuration *mpu_config = _Nios2_MPU_Get_configuration();
0055 uint32_t stack = (uint32_t) stack_area_begin + stack_area_size - 4;
0056
0057 memset(context, 0, sizeof(*context));
0058
0059 context->fp = stack;
0060 context->status = _Nios2_ISR_Set_level( new_level, NIOS2_STATUS_PIE );
0061 context->sp = stack;
0062 context->ra = (uint32_t) entry_point;
0063
0064 if ( mpu_config != NULL ) {
0065 Nios2_MPU_Region_descriptor desc = {
0066 .index = mpu_config->data_index_for_stack_protection,
0067 .base = stack_area_begin,
0068 .end = (const void *) RTEMS_ALIGN_UP(
0069 (uintptr_t) stack_area_begin + stack_area_size +
0070 _TLS_Get_allocation_size(),
0071 1U << mpu_config->data_region_size_log2
0072 ),
0073 .perm = NIOS2_MPU_DATA_PERM_SVR_READWRITE_USER_NONE,
0074 .data = true,
0075 .cacheable = mpu_config->enable_data_cache_for_stack,
0076 .read = false,
0077 .write = true
0078 };
0079 bool ok = _Nios2_MPU_Setup_region_registers(
0080 mpu_config,
0081 &desc,
0082 &context->stack_mpubase,
0083 &context->stack_mpuacc
0084 );
0085
0086 if ( !ok ) {
0087
0088 _Terminate( INTERNAL_ERROR_CORE, 0xdeadbeef );
0089 }
0090 }
0091
0092 if ( tls_area != NULL ) {
0093 context->r23 = (uintptr_t) _TLS_Initialize_area( tls_area ) + 0x7000;
0094 }
0095 }