1 | .. comment SPDX-License-Identifier: CC-BY-SA-4.0 |
---|
2 | |
---|
3 | .. COMMENT: COPYRIGHT (c) 1988-2008. |
---|
4 | .. COMMENT: On-Line Applications Research Corporation (OAR). |
---|
5 | .. COMMENT: All rights reserved. |
---|
6 | |
---|
7 | Initialization Manager |
---|
8 | ********************** |
---|
9 | |
---|
10 | Introduction |
---|
11 | ============ |
---|
12 | |
---|
13 | The Initialization Manager is responsible for initializing the Board Support |
---|
14 | Package, RTEMS, device drivers, the root filesystem and the application. The |
---|
15 | :ref:`Fatal Error Manager <fatal_error_manager>` is responsible for the system |
---|
16 | shutdown. |
---|
17 | |
---|
18 | The Initialization Manager provides only one directive: |
---|
19 | |
---|
20 | - rtems_initialize_executive_ - Initialize RTEMS |
---|
21 | |
---|
22 | Background |
---|
23 | ========== |
---|
24 | |
---|
25 | .. index:: initialization tasks |
---|
26 | |
---|
27 | Initialization Tasks |
---|
28 | -------------------- |
---|
29 | |
---|
30 | Initialization task(s) are the mechanism by which RTEMS transfers initial |
---|
31 | control to the user's application. Initialization tasks differ from other |
---|
32 | application tasks in that they are defined in the User Initialization Tasks |
---|
33 | Table and automatically created and started by RTEMS as part of its |
---|
34 | initialization sequence. Since the initialization tasks are scheduled using |
---|
35 | the same algorithm as all other RTEMS tasks, they must be configured at a |
---|
36 | priority and mode which will ensure that they will complete execution before |
---|
37 | other application tasks execute. Although there is no upper limit on the |
---|
38 | number of initialization tasks, an application is required to define at least |
---|
39 | one. |
---|
40 | |
---|
41 | A typical initialization task will create and start the static set of |
---|
42 | application tasks. It may also create any other objects used by the |
---|
43 | application. Initialization tasks which only perform initialization should |
---|
44 | delete themselves upon completion to free resources for other tasks. |
---|
45 | Initialization tasks may transform themselves into a "normal" application task. |
---|
46 | This transformation typically involves changing priority and execution mode. |
---|
47 | RTEMS does not automatically delete the initialization tasks. |
---|
48 | |
---|
49 | The Idle Task |
---|
50 | ------------- |
---|
51 | |
---|
52 | The Idle Task is the lowest priority task in a system and executes only when no |
---|
53 | other task is ready to execute. The default implementation of this task |
---|
54 | consists of an infinite loop. RTEMS allows the Idle Task body to be replaced by |
---|
55 | a CPU specific implementation, a BSP specific implementation or an application |
---|
56 | specific implementation. |
---|
57 | |
---|
58 | The Idle Task is preemptible and *WILL* be preempted when any other task is |
---|
59 | made ready to execute. This characteristic is critical to the overall behavior |
---|
60 | of any application. |
---|
61 | |
---|
62 | Initialization Manager Failure |
---|
63 | ------------------------------ |
---|
64 | |
---|
65 | System initialization errors are fatal. See :ref:`internal_errors`. |
---|
66 | |
---|
67 | Operations |
---|
68 | ========== |
---|
69 | |
---|
70 | Initializing RTEMS |
---|
71 | ------------------ |
---|
72 | |
---|
73 | The Initialization Manager :c:func:`rtems_initialize_executive()` directives is |
---|
74 | called by the :c:func:`boot_card()` routine which is invoked by the Board |
---|
75 | Support Package once a basic C run-time environment is set up. This consists |
---|
76 | of |
---|
77 | |
---|
78 | - a valid and accessible text section, read-only data, read-write data and |
---|
79 | zero-initialized data, |
---|
80 | |
---|
81 | - an initialization stack large enough to initialize the rest of the Board |
---|
82 | Support Package, RTEMS and the device drivers, |
---|
83 | |
---|
84 | - all registers and components mandated by Application Binary Interface, and |
---|
85 | |
---|
86 | - disabled interrupts. |
---|
87 | |
---|
88 | The :c:func:`rtems_initialize_executive()` directive uses a system |
---|
89 | initialization :ref:`linker set <linker_sets>` to initialize only those parts |
---|
90 | of the overall RTEMS feature set that is necessary for a particular |
---|
91 | application. Each RTEMS feature used the application may optionally register |
---|
92 | an initialization handler. The system initialization API is available via |
---|
93 | :samp:`#included <rtems/sysinit.h>`. |
---|
94 | |
---|
95 | A list of all initialization steps follows. Some steps are optional depending |
---|
96 | on the requested feature set of the application. The initialization steps are |
---|
97 | execute in the order presented here. |
---|
98 | |
---|
99 | RTEMS_SYSINIT_BSP_WORK_AREAS |
---|
100 | The work areas consisting of C Program Heap and the RTEMS Workspace are |
---|
101 | initialized by the Board Support Package. This step is mandatory. |
---|
102 | |
---|
103 | RTEMS_SYSINIT_BSP_START |
---|
104 | Basic initialization step provided by the Board Support Package. This step |
---|
105 | is mandatory. |
---|
106 | |
---|
107 | RTEMS_SYSINIT_INITIAL_EXTENSIONS |
---|
108 | Registers the initial extensions. This step is optional and depends on the |
---|
109 | application configuration. |
---|
110 | |
---|
111 | RTEMS_SYSINIT_MP_EARLY |
---|
112 | Early MPCI initialization. This step is mandatory on MPCI configurations. |
---|
113 | |
---|
114 | RTEMS_SYSINIT_DATA_STRUCTURES |
---|
115 | This directive is called when the Board Support Package has completed its |
---|
116 | basic initialization and allows RTEMS to initialize the application |
---|
117 | environment based upon the information in the Configuration Table, User |
---|
118 | Initialization Tasks Table, Device Driver Table, User Extension Table, |
---|
119 | Multiprocessor Configuration Table, and the Multiprocessor Communications |
---|
120 | Interface (MPCI) Table. |
---|
121 | |
---|
122 | RTEMS_SYSINIT_CPU_SET |
---|
123 | Initialization of system CPU set. This step is optional and depends on the |
---|
124 | application configuration. |
---|
125 | |
---|
126 | RTEMS_SYSINIT_MP |
---|
127 | MPCI initialization. This step is mandatory on MPCI configurations. |
---|
128 | |
---|
129 | RTEMS_SYSINIT_USER_EXTENSIONS |
---|
130 | Initialization of the User Extensions object class. This step is optional |
---|
131 | and depends on the application configuration. |
---|
132 | |
---|
133 | RTEMS_SYSINIT_CLASSIC_TASKS |
---|
134 | Initialization of the Classic Tasks object class. This step is optional |
---|
135 | and depends on the application configuration. |
---|
136 | |
---|
137 | RTEMS_SYSINIT_CLASSIC_TIMER |
---|
138 | Initialization of the Classic Timer object class. This step is optional |
---|
139 | and depends on the application configuration. |
---|
140 | |
---|
141 | RTEMS_SYSINIT_CLASSIC_SIGNAL |
---|
142 | Initialization of the Classic Signal support. This step is optional and |
---|
143 | depends on the application configuration. |
---|
144 | |
---|
145 | RTEMS_SYSINIT_CLASSIC_EVENT |
---|
146 | Initialization of the Classic Event support. This step is optional and |
---|
147 | depends on the application configuration. This step is only used on MPCI |
---|
148 | configurations. |
---|
149 | |
---|
150 | RTEMS_SYSINIT_CLASSIC_MESSAGE_QUEUE |
---|
151 | Initialization of the Classic Message Queue object class. This step is |
---|
152 | optional and depends on the application configuration. |
---|
153 | |
---|
154 | RTEMS_SYSINIT_CLASSIC_SEMAPHORE |
---|
155 | Initialization of the Classic Semaphore object class. This step is |
---|
156 | optional and depends on the application configuration. |
---|
157 | |
---|
158 | RTEMS_SYSINIT_CLASSIC_PARTITION |
---|
159 | Initialization of the Classic Partition object class. This step is |
---|
160 | optional and depends on the application configuration. |
---|
161 | |
---|
162 | RTEMS_SYSINIT_CLASSIC_REGION |
---|
163 | Initialization of the Classic Region object class. This step is optional |
---|
164 | and depends on the application configuration. |
---|
165 | |
---|
166 | RTEMS_SYSINIT_CLASSIC_DUAL_PORTED_MEMORY |
---|
167 | Initialization of the Classic Dual-Ported Memory object class. This step |
---|
168 | is optional and depends on the application configuration. |
---|
169 | |
---|
170 | RTEMS_SYSINIT_CLASSIC_RATE_MONOTONIC |
---|
171 | Initialization of the Classic Rate-Monotonic object class. This step is |
---|
172 | optional and depends on the application configuration. |
---|
173 | |
---|
174 | RTEMS_SYSINIT_CLASSIC_BARRIER |
---|
175 | Initialization of the Classic Barrier object class. This step is optional |
---|
176 | and depends on the application configuration. |
---|
177 | |
---|
178 | RTEMS_SYSINIT_POSIX_SIGNALS |
---|
179 | Initialization of the POSIX Signals support. This step is optional and |
---|
180 | depends on the application configuration. |
---|
181 | |
---|
182 | RTEMS_SYSINIT_POSIX_THREADS |
---|
183 | Initialization of the POSIX Threads object class. This step is optional |
---|
184 | and depends on the application configuration. |
---|
185 | |
---|
186 | RTEMS_SYSINIT_POSIX_MESSAGE_QUEUE |
---|
187 | Initialization of the POSIX Message Queue object class. This step is |
---|
188 | optional and depends on the application configuration. |
---|
189 | |
---|
190 | RTEMS_SYSINIT_POSIX_SEMAPHORE |
---|
191 | Initialization of the POSIX Semaphore object class. This step is optional |
---|
192 | and depends on the application configuration. |
---|
193 | |
---|
194 | RTEMS_SYSINIT_POSIX_TIMER |
---|
195 | Initialization of the POSIX Timer object class. This step is optional and |
---|
196 | depends on the application configuration. |
---|
197 | |
---|
198 | RTEMS_SYSINIT_POSIX_KEYS |
---|
199 | Initialization of the POSIX Keys object class. This step is optional |
---|
200 | and depends on the application configuration. |
---|
201 | |
---|
202 | RTEMS_SYSINIT_POSIX_CLEANUP |
---|
203 | Initialization of the POSIX Cleanup support. This step is optional and |
---|
204 | depends on the application configuration. |
---|
205 | |
---|
206 | RTEMS_SYSINIT_IDLE_THREADS |
---|
207 | Initialization of idle threads. This step is mandatory. |
---|
208 | |
---|
209 | RTEMS_SYSINIT_LIBIO |
---|
210 | Initialization of IO library. This step is optional and depends on the |
---|
211 | application configuration. |
---|
212 | |
---|
213 | RTEMS_SYSINIT_ROOT_FILESYSTEM |
---|
214 | Initialization of the root filesystem. This step is optional and depends |
---|
215 | on the application configuration. |
---|
216 | |
---|
217 | RTEMS_SYSINIT_DRVMGR |
---|
218 | Driver manager initialization. This step is optional and depends on the |
---|
219 | application configuration. Only available if the driver manager is |
---|
220 | enabled. |
---|
221 | |
---|
222 | RTEMS_SYSINIT_MP_SERVER |
---|
223 | MPCI server initialization. This step is mandatory on MPCI configurations. |
---|
224 | |
---|
225 | RTEMS_SYSINIT_BSP_PRE_DRIVERS |
---|
226 | Initialization step performed right before device drivers are initialized. |
---|
227 | This step is mandatory. |
---|
228 | |
---|
229 | RTEMS_SYSINIT_DRVMGR_LEVEL_1 |
---|
230 | Driver manager level 1 initialization. This step is optional and depends |
---|
231 | on the application configuration. Only available if the driver manager is |
---|
232 | enabled. |
---|
233 | |
---|
234 | RTEMS_SYSINIT_DEVICE_DRIVERS |
---|
235 | This step initializes all statically configured device drivers and performs |
---|
236 | all RTEMS initialization which requires device drivers to be initialized. |
---|
237 | This step is mandatory. In a multiprocessor configuration, this service |
---|
238 | will initialize the Multiprocessor Communications Interface (MPCI) and |
---|
239 | synchronize with the other nodes in the system. |
---|
240 | |
---|
241 | RTEMS_SYSINIT_DRVMGR_LEVEL_2 |
---|
242 | Driver manager level 2 initialization. This step is optional and depends |
---|
243 | on the application configuration. Only available if the driver manager is |
---|
244 | enabled. |
---|
245 | |
---|
246 | RTEMS_SYSINIT_DRVMGR_LEVEL_3 |
---|
247 | Driver manager level 3 initialization. This step is optional and depends |
---|
248 | on the application configuration. Only available if the driver manager is |
---|
249 | enabled. |
---|
250 | |
---|
251 | RTEMS_SYSINIT_DRVMGR_LEVEL_4 |
---|
252 | Driver manager level 4 initialization. This step is optional and depends |
---|
253 | on the application configuration. Only available if the driver manager is |
---|
254 | enabled. |
---|
255 | |
---|
256 | RTEMS_SYSINIT_MP_FINALIZE |
---|
257 | Finalize MPCI initialization. This step is mandatory on MPCI |
---|
258 | configurations. |
---|
259 | |
---|
260 | RTEMS_SYSINIT_CLASSIC_USER_TASKS |
---|
261 | Creates and starts the Classic initialization tasks. This step is optional |
---|
262 | and depends on the application configuration. |
---|
263 | |
---|
264 | RTEMS_SYSINIT_POSIX_USER_THREADS |
---|
265 | Creates POSIX initialization threads. This step is optional and depends on |
---|
266 | the application configuration. |
---|
267 | |
---|
268 | RTEMS_SYSINIT_STD_FILE_DESCRIPTORS |
---|
269 | Open the standard input, output and error file descriptors. This step is |
---|
270 | optional and depends on the application configuration. |
---|
271 | |
---|
272 | The final action of the :c:func:`rtems_initialize_executive()` directive is to |
---|
273 | start multitasking and switch to the highest priority ready thread. RTEMS does |
---|
274 | not return to the initialization context and the initialization stack may be |
---|
275 | re-used for interrupt processing. |
---|
276 | |
---|
277 | Many of RTEMS actions during initialization are based upon the contents of the |
---|
278 | Configuration Table. For more information regarding the format and contents of |
---|
279 | this table, please refer to the chapter :ref:`Configuring a System`. |
---|
280 | |
---|
281 | Global Construction |
---|
282 | ------------------- |
---|
283 | |
---|
284 | The global construction is carried out by the first Classic API initialization |
---|
285 | task (first is defined by index zero in the Classic API initialization task |
---|
286 | configuration table). If no Classic API initialization task exists, then it is |
---|
287 | carried out by the first POSIX API initialization thread. If no initialization |
---|
288 | task or thread exists, then no global construction is performed, see for |
---|
289 | example :ref:`Specify Idle Task Performs Application Initialization`. The |
---|
290 | Classic API task or POSIX API thread which carries out global construction is |
---|
291 | called the main thread. |
---|
292 | |
---|
293 | Global construction runs before the entry function of the main thread. The |
---|
294 | configuration of the main thread must take the global construction into |
---|
295 | account. In particular, the main thread stack size, priority, attributes and |
---|
296 | initial modes must be set accordingly. Thread-local objects and POSIX key |
---|
297 | values created during global construction are accessible by the main thread. |
---|
298 | If other initialization tasks are configured, and one of them has a higher |
---|
299 | priority than the main thread and the main thread is preemptible, this task |
---|
300 | executes before the global construction. In case the main thread blocks during |
---|
301 | global construction, then other tasks may run. In SMP configurations, other |
---|
302 | initialization tasks may run in parallel with global construction. Tasks |
---|
303 | created during global construction may preempt the main thread or run in |
---|
304 | parallel in SMP configurations. All RTEMS services allowed in task context are |
---|
305 | allowed during global construction. |
---|
306 | |
---|
307 | Global constructors are C++ global object constructors or functions with the |
---|
308 | constructor attribute. For example, the following test program |
---|
309 | |
---|
310 | .. code-block:: c |
---|
311 | |
---|
312 | #include <stdio.h> |
---|
313 | #include <assert.h> |
---|
314 | |
---|
315 | class A { |
---|
316 | public: |
---|
317 | A() |
---|
318 | { |
---|
319 | puts( "A:A()" ); |
---|
320 | } |
---|
321 | }; |
---|
322 | |
---|
323 | static A a; |
---|
324 | |
---|
325 | static thread_local int i; |
---|
326 | |
---|
327 | static thread_local int j; |
---|
328 | |
---|
329 | static __attribute__(( __constructor__ )) void b( void ) |
---|
330 | { |
---|
331 | i = 1; |
---|
332 | puts( "b()" ); |
---|
333 | } |
---|
334 | |
---|
335 | static __attribute__(( __constructor__( 1000 ) )) void c( void ) |
---|
336 | { |
---|
337 | puts( "c()" ); |
---|
338 | } |
---|
339 | |
---|
340 | int main( void ) |
---|
341 | { |
---|
342 | assert( i == 1 ); |
---|
343 | assert( j == 0 ); |
---|
344 | return 0; |
---|
345 | } |
---|
346 | |
---|
347 | should output: |
---|
348 | |
---|
349 | .. code-block:: shell |
---|
350 | |
---|
351 | c() |
---|
352 | b() |
---|
353 | A:A() |
---|
354 | |
---|
355 | Directives |
---|
356 | ========== |
---|
357 | |
---|
358 | This section details the Initialization Manager's directives. A subsection is |
---|
359 | dedicated to each of this manager's directives and describes the calling |
---|
360 | sequence, related constants, usage, and status codes. |
---|
361 | |
---|
362 | .. raw:: latex |
---|
363 | |
---|
364 | \clearpage |
---|
365 | |
---|
366 | .. index:: initialize RTEMS |
---|
367 | .. index:: start multitasking |
---|
368 | .. index:: rtems_initialize_executive |
---|
369 | |
---|
370 | .. _rtems_initialize_executive: |
---|
371 | |
---|
372 | INITIALIZE_EXECUTIVE - Initialize RTEMS |
---|
373 | --------------------------------------- |
---|
374 | |
---|
375 | CALLING SEQUENCE: |
---|
376 | .. code-block:: c |
---|
377 | |
---|
378 | void rtems_initialize_executive(void); |
---|
379 | |
---|
380 | DIRECTIVE STATUS CODES: |
---|
381 | NONE - This function will not return to the caller. |
---|
382 | |
---|
383 | DESCRIPTION: |
---|
384 | Iterates through the system initialization linker set and invokes the |
---|
385 | registered handlers. The final step is to start multitasking. |
---|
386 | |
---|
387 | NOTES: |
---|
388 | This directive should be called by :c:func:`boot_card()` only. |
---|
389 | |
---|
390 | This directive *does not return* to the caller. Errors in the |
---|
391 | initialization sequence are usually fatal and lead to a system termination. |
---|