[abb18dc] | 1 | /* |
---|
| 2 | * BASED UPON SOURCE IN RTEMS, MODIFIED FOR SIMULATOR |
---|
[726b27c] | 3 | */ |
---|
| 4 | |
---|
| 5 | /* |
---|
| 6 | * COPYRIGHT (c) 1989-2014. |
---|
[abb18dc] | 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 | |
---|
[8703c13] | 14 | #if HAVE_CONFIG_H |
---|
| 15 | #include "config.h" |
---|
| 16 | #endif |
---|
| 17 | |
---|
[abb18dc] | 18 | #define SAPI_INIT |
---|
| 19 | #define SCORE_INIT |
---|
| 20 | #define RTEMS_API_INIT |
---|
[726b27c] | 21 | #define POSIX_API_INIT |
---|
| 22 | |
---|
| 23 | #include <rtems/system.h> |
---|
[8703c13] | 24 | #include <rtems/score/assert.h> |
---|
[726b27c] | 25 | #include <rtems/config.h> |
---|
| 26 | #include <rtems/debug.h> |
---|
| 27 | #include <rtems/extensionimpl.h> |
---|
| 28 | #include <rtems/fatal.h> |
---|
| 29 | #include <rtems/init.h> |
---|
| 30 | #include <rtems/io.h> |
---|
| 31 | #include <rtems/score/sysstate.h> |
---|
[abb18dc] | 32 | |
---|
| 33 | #include <rtems/score/apiext.h> |
---|
| 34 | #include <rtems/score/apimutex.h> |
---|
[726b27c] | 35 | #include <rtems/score/cpusetimpl.h> |
---|
[783fbfe] | 36 | #include <rtems/score/userextimpl.h> |
---|
[726b27c] | 37 | #include <rtems/score/schedulerimpl.h> |
---|
| 38 | #include <rtems/score/smpimpl.h> |
---|
| 39 | #include <rtems/score/threadimpl.h> |
---|
| 40 | #include <rtems/score/todimpl.h> |
---|
| 41 | #include <rtems/score/watchdogimpl.h> |
---|
[abb18dc] | 42 | #include <rtems/score/wkspace.h> |
---|
| 43 | |
---|
[726b27c] | 44 | #include <rtems/rtems/tasksimpl.h> |
---|
| 45 | #include <rtems/rtems/semimpl.h> |
---|
| 46 | |
---|
| 47 | #include <rtems/posix/keyimpl.h> |
---|
| 48 | |
---|
[2d51251] | 49 | void Init__wrap__Thread_Dispatch(); |
---|
| 50 | |
---|
[726b27c] | 51 | /* |
---|
| 52 | * Declare Object Information tables directly here instead of API |
---|
| 53 | * specific initialization files as in cpukit/sapi/src. |
---|
| 54 | */ |
---|
[abb18dc] | 55 | Objects_Information *_Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ]; |
---|
| 56 | |
---|
| 57 | Objects_Information *_RTEMS_Objects[ OBJECTS_RTEMS_CLASSES_LAST + 1 ]; |
---|
| 58 | |
---|
[726b27c] | 59 | Objects_Information *_POSIX_Objects[ OBJECTS_POSIX_CLASSES_LAST + 1 ]; |
---|
| 60 | |
---|
[abb18dc] | 61 | extern void check_heir_and_executing(void); |
---|
| 62 | |
---|
| 63 | void rtems_initialize_data_structures(void) |
---|
| 64 | { |
---|
| 65 | _System_state_Handler_initialization( FALSE ); |
---|
| 66 | |
---|
[30aa792] | 67 | _CPU_Initialize(); |
---|
| 68 | |
---|
[abb18dc] | 69 | /* |
---|
| 70 | * Do this as early as possible to ensure no debugging output |
---|
| 71 | * is even attempted to be printed. |
---|
| 72 | */ |
---|
| 73 | _Debug_Manager_initialization(); |
---|
| 74 | |
---|
| 75 | _API_extensions_Initialization(); |
---|
| 76 | |
---|
| 77 | _Thread_Dispatch_initialization(); |
---|
| 78 | |
---|
| 79 | _User_extensions_Handler_initialization(); |
---|
[aebb1ca] | 80 | _ISR_Handler_initialization(); |
---|
[abb18dc] | 81 | |
---|
| 82 | /* |
---|
| 83 | * Initialize the internal support API and allocator Mutex |
---|
| 84 | */ |
---|
| 85 | _Objects_Information_table[OBJECTS_INTERNAL_API] = _Internal_Objects; |
---|
| 86 | |
---|
[726b27c] | 87 | _API_Mutex_Initialization( 2 ); |
---|
[abb18dc] | 88 | _API_Mutex_Allocate( &_RTEMS_Allocator_Mutex ); |
---|
[726b27c] | 89 | _API_Mutex_Allocate( &_Once_Mutex ); |
---|
[abb18dc] | 90 | |
---|
| 91 | _Watchdog_Handler_initialization(); |
---|
| 92 | _TOD_Handler_initialization(); |
---|
| 93 | |
---|
| 94 | _Thread_Handler_initialization(); |
---|
| 95 | |
---|
| 96 | _Scheduler_Handler_initialization(); |
---|
| 97 | |
---|
[726b27c] | 98 | _SMP_Handler_initialize(); |
---|
| 99 | |
---|
| 100 | _CPU_set_Handler_initialization(); |
---|
[abb18dc] | 101 | |
---|
| 102 | /* MANAGERS */ |
---|
| 103 | /* |
---|
| 104 | * Install our API Object Management Table and initialize the |
---|
| 105 | * various managers. |
---|
| 106 | */ |
---|
| 107 | _Objects_Information_table[OBJECTS_CLASSIC_API] = _RTEMS_Objects; |
---|
| 108 | |
---|
| 109 | _RTEMS_tasks_Manager_initialization(); |
---|
| 110 | _Semaphore_Manager_initialization(); |
---|
| 111 | |
---|
[726b27c] | 112 | /* |
---|
| 113 | * Install our API Object Management Table and initialize the |
---|
| 114 | * various managers. |
---|
| 115 | */ |
---|
| 116 | _Objects_Information_table[OBJECTS_POSIX_API] = _POSIX_Objects; |
---|
| 117 | |
---|
| 118 | _POSIX_Key_Manager_initialization(); |
---|
| 119 | |
---|
[aebb1ca] | 120 | /* |
---|
| 121 | * Discover and initialize the secondary cores in an SMP system. |
---|
| 122 | */ |
---|
[726b27c] | 123 | _SMP_Handler_initialize(); |
---|
[aebb1ca] | 124 | |
---|
[abb18dc] | 125 | _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING ); |
---|
| 126 | |
---|
| 127 | /* |
---|
| 128 | * No threads should be created before this point!!! |
---|
| 129 | * _Thread_Executing and _Thread_Heir are not set. |
---|
| 130 | * |
---|
| 131 | * At this point all API extensions are in place. After the call to |
---|
| 132 | * _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set. |
---|
| 133 | */ |
---|
| 134 | _Thread_Create_idle(); |
---|
| 135 | |
---|
| 136 | /* |
---|
| 137 | * Scheduling can properly occur now as long as we avoid dispatching. |
---|
| 138 | */ |
---|
| 139 | |
---|
[726b27c] | 140 | _System_state_Set( SYSTEM_STATE_UP ); |
---|
| 141 | |
---|
[2d51251] | 142 | _SMP_Request_start_multitasking(); |
---|
[abb18dc] | 143 | |
---|
| 144 | _Thread_Start_multitasking(); |
---|
| 145 | |
---|
[2d51251] | 146 | /* Add Initialization of the Thread_Dispatch wrapper */ |
---|
| 147 | Init__wrap__Thread_Dispatch(); |
---|
| 148 | |
---|
[abb18dc] | 149 | /* |
---|
| 150 | * Now we are back in a non-dispatching critical section |
---|
| 151 | */ |
---|
[726b27c] | 152 | #if defined(RTEMS_SMP) |
---|
[2d51251] | 153 | { |
---|
| 154 | ISR_Level level; |
---|
| 155 | |
---|
| 156 | /* |
---|
| 157 | * On SMP we enter _Thread_Handler() with interrupts disabled and |
---|
| 158 | * _Thread_Dispatch() obtained the per-CPU lock for us. We have to |
---|
| 159 | * release it here and set the desired interrupt level of the thread. |
---|
| 160 | */ |
---|
| 161 | Per_CPU_Control *cpu_self = _Per_CPU_Get(); |
---|
| 162 | |
---|
| 163 | _Assert( cpu_self->thread_dispatch_disable_level == 1 ); |
---|
| 164 | _Assert( _ISR_Get_level() != 0 ); |
---|
| 165 | |
---|
| 166 | cpu_self->thread_dispatch_disable_level = 0; |
---|
| 167 | _Profiling_Thread_dispatch_enable( cpu_self, 0 ); |
---|
| 168 | |
---|
[30aa792] | 169 | /* For whatever reason, we haven't locked our per cpu yet in the |
---|
| 170 | * Scheduler Simulator. Until this is done, this release is not needed. |
---|
| 171 | */ |
---|
| 172 | /* _Per_CPU_Release( cpu_self ); */ |
---|
[2d51251] | 173 | |
---|
| 174 | level = _Thread_Executing->Start.isr_level; |
---|
| 175 | _ISR_Set_level( level); |
---|
| 176 | |
---|
| 177 | /* |
---|
| 178 | * The thread dispatch level changed from one to zero. Make sure we lose |
---|
| 179 | * no thread dispatch necessary update. |
---|
| 180 | */ |
---|
| 181 | _Thread_Dispatch(); |
---|
| 182 | } |
---|
[726b27c] | 183 | #else |
---|
| 184 | _Thread_Enable_dispatch(); |
---|
| 185 | #endif |
---|
[abb18dc] | 186 | |
---|
| 187 | /* |
---|
| 188 | * Print an initial message |
---|
| 189 | */ |
---|
| 190 | check_heir_and_executing(); |
---|
| 191 | } |
---|