summaryrefslogtreecommitdiffstats
path: root/doc/user/init.t
blob: ecbfa148b8fe33fe4d4cb71629f07c0f48f0d6d5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
@c
@c  COPYRIGHT (c) 1988-2008.
@c  On-Line Applications Research Corporation (OAR).
@c  All rights reserved.

@chapter Initialization Manager

@section Introduction

The Initialization Manager is responsible for
initiating and shutting down RTEMS.  Initiating RTEMS involves
creating and starting all configured initialization tasks, and
for invoking the initialization routine for each user-supplied
device driver.  In a multiprocessor configuration, this manager
also initializes the interprocessor communications layer.  The
directives provided by the Initialization Manager are:

@itemize @bullet
@item @code{@value{DIRPREFIX}initialize_executive} - Initialize RTEMS
@item @code{@value{DIRPREFIX}shutdown_executive} - Shutdown RTEMS
@end itemize

@section Background

@subsection Initialization Tasks

@cindex initialization tasks

Initialization task(s) are the mechanism by which
RTEMS transfers initial control to the user's application.
Initialization tasks differ from other application tasks in that
they are defined in the User Initialization Tasks Table and
automatically created and started by RTEMS as part of its
initialization sequence.  Since the initialization tasks are
scheduled using the same algorithm as all other RTEMS tasks,
they must be configured at a priority and mode which will ensure
that they will complete execution before other application tasks
execute.  Although there is no upper limit on the number of
initialization tasks, an application is required to define at
least one.

A typical initialization task will create and start
the static set of application tasks.  It may also create any
other objects used by the application.  Initialization tasks
which only perform initialization should delete themselves upon
completion to free resources for other tasks.  Initialization
tasks may transform themselves into a "normal" application task.
This transformation typically involves changing priority and
execution mode.  RTEMS does not automatically delete the
initialization tasks.

@subsection System Initialization

System Initialization begins with board reset and continues
through RTEMS initialization, initialization of all device
drivers, and eventually a context switch to the first user
task.  Remember, that interrupts are disabled during
initialization and the @i{initialization context} is not
a task in any sense and the user should be very careful
during initialization.

The BSP must ensure that the there is enough stack
space reserved for the initialization context to
successfully execute the initialization routines for
all device drivers and, in multiprocessor configurations, the
Multiprocessor Communications Interface Layer initialization
routine.

@subsection The Idle Task

The Idle Task is the lowest priority task in a system
and executes only when no other task is ready to execute.  This
default implementation of this task consists of an infinite
loop. RTEMS allows the Idle Task body to be replaced by a CPU
specific implementation, a BSP specific implementation or an
application specific implementation.

The Idle Task is preemptible and @b{WILL} be preempted when
any other task is made ready to execute.  This characteristic is
critical to the overall behavior of any application.

@subsection Initialization Manager Failure

The @code{@value{DIRPREFIX}fatal_error_occurred} directive will
be invoked from @code{@value{DIRPREFIX}initialize_executive}
for any of the following reasons:

@itemize @bullet
@item If either the Configuration Table or the CPU Dependent
Information Table is not provided.

@item If the starting address of the RTEMS RAM Workspace,
supplied by the application in the Configuration Table, is NULL
or is not aligned on a four-byte boundary.

@item If the size of the RTEMS RAM Workspace is not large
enough to initialize and configure the system.

@item If the interrupt stack size specified is too small.

@item If multiprocessing is configured and the node entry in
the Multiprocessor Configuration Table is not between one and
the maximum_nodes entry.

@item If a multiprocessor system is being configured and no
Multiprocessor Communications Interface is specified.

@item If no user initialization tasks are configured.  At
least one initialization task must be configured to allow RTEMS
to pass control to the application at the end of the executive
initialization sequence.

@item If any of the user initialization tasks cannot be
created or started successfully.
@end itemize
 
A discussion of RTEMS actions when a fatal error occurs 
may be found @ref{Fatal Error Manager Announcing a Fatal Error}.


@section Operations

@subsection Initializing RTEMS

The Initialization Manager @code{@value{DIRPREFIX}initialize_executive}
directives is called by the @code{boot_card} routine.  The @code{boot_card}
routine is invoked by the Board Support Package once a basic C run-time
environment is set up.  This consists of

@itemize @bullet
@item a valid and accessible text section, read-only data, read-write data and
zero-initialized data,
@item an initialization stack large enough to initialize the rest of the Board
Support Package, RTEMS and the device drivers,
@item all registers and components mandated by Application Binary Interface, and
@item disabled interrupts.
@end itemize

The @code{@value{DIRPREFIX}initialize_executive} directive uses a system
initialization linker set to initialize only those parts of the overall RTEMS
feature set that is necessary for a particular application.  @xref{Linker
Sets}.  Each RTEMS feature used the application may optionally register an
initialization handler.  The system initialization API is available via
@code{#included <rtems/sysinit.h>}.

A list of all initialization steps follows.  Some steps are optional depending
on the requested feature set of the application.  The initialization steps are
execute in the order presented here.

@table @dfn

@item RTEMS_SYSINIT_BSP_WORK_AREAS
The work areas consisting of C Program Heap and the RTEMS Workspace are
initialized by the Board Support Package.  This step is mandatory.

@item RTEMS_SYSINIT_BSP_START
Basic initialization step provided by the Board Support Package.  This step is
mandatory.

@item RTEMS_SYSINIT_INITIAL_EXTENSIONS
Initializes the initial extensions if at least one is configured by the Board
Support Package or application.

@item RTEMS_SYSINIT_DATA_STRUCTURES
This directive is called when the Board Support Package has completed its basic
initialization and allows RTEMS to initialize the application environment based
upon the information in the Configuration Table, User Initialization Tasks
Table, Device Driver Table, Multiprocessor Configuration Table, and the
Multiprocessor Communications Interface (MPCI) Table.

@item RTEMS_SYSINIT_USER_EXTENSIONS
Initializes the @ref{User Extensions Manager} in case it is used by the
application.

@item RTEMS_SYSINIT_CPU_SET
Initializes the global CPU set on SMP configurations in case the application
uses this information.

@item RTEMS_SYSINIT_BSP_LIBC
Depending on the application configuration the IO library and root filesystem
is initialized.  This step is mandatory.

@item RTEMS_SYSINIT_BEFORE_DRIVERS
This directive performs initialization that must occur between basis RTEMS data
structure initialization and device driver initialization.  In particular, in a
multiprocessor configuration, this directive will create the MPCI Server Task.

@item RTEMS_SYSINIT_BSP_PRE_DRIVERS
Initialization step performed right before device drivers are initialized
provided by the Board Support Package.  This step is mandatory.

@item RTEMS_SYSINIT_DEVICE_DRIVERS
This step initializes all statically configured device drivers and performs all
RTEMS initialization which requires device drivers to be initialized.  This
step is mandatory.

In a multiprocessor configuration, this service will initialize the
Multiprocessor Communications Interface (MPCI) and synchronize with the other
nodes in the system. 

@item RTEMS_SYSINIT_BSP_POST_DRIVERS
Initialization step performed right after device drivers are initialized
provided by the Board Support Package.  This step is mandatory.

@end table

The final action of the @code{@value{DIRPREFIX}initialize_executive} directive
is to start multitasking.  RTEMS does not return to the initialization context
and the initialization stack may be re-used for interrupt processing.

Many of RTEMS actions during initialization are based upon
the contents of the Configuration Table.  For more information
regarding the format and contents of this table, please refer
to the chapter @ref{Configuring a System}.

The final action in the initialization sequence is the
initiation of multitasking.  When the scheduler and dispatcher
are enabled, the highest priority, ready task will be dispatched
to run.  Control will not be returned to the Board Support
Package after multitasking is enabled.  The initialization stack may be re-used
for interrupt processing.

@subsection Shutting Down RTEMS

The @code{@value{DIRPREFIX}shutdown_executive} directive is invoked by the
application to end multitasking and terminate the system.

@section Directives

This section details the Initialization Manager's
directives.  A subsection is dedicated to each of this manager's
directives and describes the calling sequence, related
constants, usage, and status codes.

@page
@subsection INITIALIZE_EXECUTIVE - Initialize RTEMS

@cindex initialize RTEMS
@cindex start multitasking

@subheading CALLING SEQUENCE:

@ifset is-C
@findex rtems_initialize_executive
@example
void rtems_initialize_executive(void);
@end example
@end ifset

@ifset is-Ada
@example
NOT SUPPORTED FROM Ada BINDING
@end example
@end ifset

@subheading DIRECTIVE STATUS CODES:

NONE

@subheading DESCRIPTION:

Iterates through the system initialization linker set and invokes the
registered handlers.  The final step is to start multitasking.

@subheading NOTES:

This directive should be called by @code{boot_card} only.

This directive @b{does not return} to the caller.  Errors in the initialization
sequence are usually fatal and lead to a system termination.

@page
@subsection SHUTDOWN_EXECUTIVE - Shutdown RTEMS

@cindex shutdown RTEMS

@subheading CALLING SEQUENCE:

@ifset is-C
@findex rtems_shutdown_executive
@example
void rtems_shutdown_executive(
  uint32_t result
);
@end example
@end ifset

@ifset is-Ada
@example
procedure Shutdown_Executive(
  Status : in     RTEMS.Unsigned32
);
@end example
@end ifset

@subheading DIRECTIVE STATUS CODES:

NONE

@subheading DESCRIPTION:

This directive is called when the application wishes to shutdown RTEMS.  The
system is terminated with a fatal source of @code{RTEMS_FATAL_SOURCE_EXIT} and
the specified @code{result} code.

@subheading NOTES:

This directive @b{must} be the last RTEMS directive
invoked by an application and it @b{does not return} to the caller.

This directive may be called any time.