1 | /* |
---|
2 | * Copyright (c) 2011 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.com/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 | |
---|
24 | void _CPU_Context_Initialize( |
---|
25 | Context_Control *context, |
---|
26 | void *stack_area_begin, |
---|
27 | size_t stack_area_size, |
---|
28 | uint32_t new_level, |
---|
29 | void (*entry_point)( void ), |
---|
30 | bool is_fp |
---|
31 | ) |
---|
32 | { |
---|
33 | const Nios2_MPU_Configuration *mpu_config = _Nios2_MPU_Get_configuration(); |
---|
34 | uint32_t stack = (uint32_t) stack_area_begin + stack_area_size - 4; |
---|
35 | |
---|
36 | memset(context, 0, sizeof(*context)); |
---|
37 | |
---|
38 | context->fp = stack; |
---|
39 | context->status = _Nios2_ISR_Set_level( new_level, NIOS2_STATUS_PIE ); |
---|
40 | context->sp = stack; |
---|
41 | context->ra = (uint32_t) entry_point; |
---|
42 | |
---|
43 | if ( mpu_config != NULL ) { |
---|
44 | Nios2_MPU_Region_descriptor desc = { |
---|
45 | .index = mpu_config->data_index_for_stack_protection, |
---|
46 | /* FIXME: Brocken stack allocator */ |
---|
47 | .base = (void *) ((int) stack_area_begin & ~((1 << mpu_config->data_region_size_log2) - 1)), |
---|
48 | .end = (char *) stack_area_begin + stack_area_size, |
---|
49 | .perm = NIOS2_MPU_DATA_PERM_SVR_READWRITE_USER_NONE, |
---|
50 | .data = true, |
---|
51 | .cacheable = mpu_config->enable_data_cache_for_stack, |
---|
52 | .read = false, |
---|
53 | .write = true |
---|
54 | }; |
---|
55 | bool ok = _Nios2_MPU_Setup_region_registers( |
---|
56 | mpu_config, |
---|
57 | &desc, |
---|
58 | &context->stack_mpubase, |
---|
59 | &context->stack_mpuacc |
---|
60 | ); |
---|
61 | |
---|
62 | if ( !ok ) { |
---|
63 | /* The task stack allocator must ensure that the stack area is valid */ |
---|
64 | _Internal_error_Occurred( INTERNAL_ERROR_CORE, false, 0xdeadbeef ); |
---|
65 | } |
---|
66 | } |
---|
67 | } |
---|