1 | /* |
---|
2 | * BASED UPON SOURCE IN RTEMS, MODIFIED FOR SIMULATOR |
---|
3 | */ |
---|
4 | |
---|
5 | /* |
---|
6 | * COPYRIGHT (c) 1989-2014. |
---|
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 | #if HAVE_CONFIG_H |
---|
15 | #include "config.h" |
---|
16 | #endif |
---|
17 | |
---|
18 | #define SAPI_INIT |
---|
19 | #define SCORE_INIT |
---|
20 | #define RTEMS_API_INIT |
---|
21 | #define POSIX_API_INIT |
---|
22 | |
---|
23 | #include <rtems/system.h> |
---|
24 | #include <rtems/score/assert.h> |
---|
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> |
---|
32 | |
---|
33 | #include <rtems/score/apiext.h> |
---|
34 | #include <rtems/score/apimutex.h> |
---|
35 | #include <rtems/score/cpusetimpl.h> |
---|
36 | #include <rtems/score/userextimpl.h> |
---|
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> |
---|
42 | #include <rtems/score/wkspace.h> |
---|
43 | |
---|
44 | #include <rtems/rtems/tasksimpl.h> |
---|
45 | #include <rtems/rtems/semimpl.h> |
---|
46 | |
---|
47 | #include <rtems/posix/keyimpl.h> |
---|
48 | |
---|
49 | void Init__wrap__Thread_Dispatch(); |
---|
50 | |
---|
51 | /* |
---|
52 | * Declare Object Information tables directly here instead of API |
---|
53 | * specific initialization files as in cpukit/sapi/src. |
---|
54 | */ |
---|
55 | Objects_Information *_Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ]; |
---|
56 | |
---|
57 | Objects_Information *_RTEMS_Objects[ OBJECTS_RTEMS_CLASSES_LAST + 1 ]; |
---|
58 | |
---|
59 | Objects_Information *_POSIX_Objects[ OBJECTS_POSIX_CLASSES_LAST + 1 ]; |
---|
60 | |
---|
61 | extern void check_heir_and_executing(void); |
---|
62 | |
---|
63 | void rtems_initialize_data_structures(void) |
---|
64 | { |
---|
65 | _System_state_Handler_initialization( FALSE ); |
---|
66 | |
---|
67 | _CPU_Initialize(); |
---|
68 | |
---|
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(); |
---|
80 | _ISR_Handler_initialization(); |
---|
81 | |
---|
82 | /* |
---|
83 | * Initialize the internal support API and allocator Mutex |
---|
84 | */ |
---|
85 | _Objects_Information_table[OBJECTS_INTERNAL_API] = _Internal_Objects; |
---|
86 | |
---|
87 | _API_Mutex_Initialization( 2 ); |
---|
88 | _API_Mutex_Allocate( &_RTEMS_Allocator_Mutex ); |
---|
89 | _API_Mutex_Allocate( &_Once_Mutex ); |
---|
90 | |
---|
91 | _Watchdog_Handler_initialization(); |
---|
92 | _TOD_Handler_initialization(); |
---|
93 | |
---|
94 | _Thread_Handler_initialization(); |
---|
95 | |
---|
96 | _Scheduler_Handler_initialization(); |
---|
97 | |
---|
98 | _SMP_Handler_initialize(); |
---|
99 | |
---|
100 | _CPU_set_Handler_initialization(); |
---|
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 | |
---|
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 | |
---|
120 | /* |
---|
121 | * Discover and initialize the secondary cores in an SMP system. |
---|
122 | */ |
---|
123 | _SMP_Handler_initialize(); |
---|
124 | |
---|
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 | |
---|
140 | _System_state_Set( SYSTEM_STATE_UP ); |
---|
141 | |
---|
142 | _SMP_Request_start_multitasking(); |
---|
143 | |
---|
144 | _Thread_Start_multitasking(); |
---|
145 | |
---|
146 | /* Add Initialization of the Thread_Dispatch wrapper */ |
---|
147 | Init__wrap__Thread_Dispatch(); |
---|
148 | |
---|
149 | /* |
---|
150 | * Now we are back in a non-dispatching critical section |
---|
151 | */ |
---|
152 | #if defined(RTEMS_SMP) |
---|
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 | |
---|
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 ); */ |
---|
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 | } |
---|
183 | #else |
---|
184 | _Thread_Enable_dispatch(); |
---|
185 | #endif |
---|
186 | |
---|
187 | /* |
---|
188 | * Print an initial message |
---|
189 | */ |
---|
190 | check_heir_and_executing(); |
---|
191 | } |
---|