source: rtems/cpukit/sapi/src/exinit.c @ f26145b

4.104.114.84.95
Last change on this file since f26145b was 16351f7a, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/28/05 at 02:04:21

2005-01-28 Ralf Corsepius <ralf.corsepius@…>

  • sapi/src/debug.c, sapi/src/exinit.c, sapi/src/extension.c, sapi/src/extensioncreate.c, sapi/src/extensiondelete.c, sapi/src/extensionident.c, sapi/src/fatal.c, sapi/src/io.c, sapi/src/itronapi.c, sapi/src/posixapi.c, sapi/src/rtemsapi.c: Include config.h.
  • Property mode set to 100644
File size: 7.9 KB
Line 
1/*
2 *  Initialization Manager
3 *
4 *  COPYRIGHT (c) 1989-1999.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18/*
19 *  SCORE_INIT and SAPI_INIT are defined so all of the super core and
20 *  super API data will be included in this object file.
21 */
22
23#define SAPI_INIT
24#define SCORE_INIT
25
26#include <rtems/system.h>
27#include <rtems/config.h>
28#include <rtems/debug.h>
29#include <rtems/extension.h>
30#include <rtems/fatal.h>
31#include <rtems/init.h>
32#include <rtems/io.h>
33#include <rtems/score/sysstate.h>
34
35#include <rtems/score/apiext.h>
36#include <rtems/score/apimutex.h>
37#include <rtems/score/copyrt.h>
38#include <rtems/score/heap.h>
39#include <rtems/score/interr.h>
40#include <rtems/score/isr.h>
41#if defined(RTEMS_MULTIPROCESSING)
42#include <rtems/score/mpci.h>
43#endif
44#include <rtems/score/priority.h>
45#include <rtems/score/thread.h>
46#include <rtems/score/tod.h>
47#include <rtems/score/userext.h>
48#include <rtems/score/watchdog.h>
49#include <rtems/score/wkspace.h>
50
51#include <rtems/sptables.h>
52
53
54#include <rtems/rtems/rtemsapi.h>
55#ifdef RTEMS_POSIX_API
56#include <rtems/posix/posixapi.h>
57#endif
58#ifdef RTEMS_ITRON_API
59#include <rtems/itron/itronapi.h>
60#endif
61
62Objects_Information *_Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ];
63
64/*PAGE
65 *
66 *  rtems_initialize_executive
67 *
68 *  This directive initializes all the kernels data structures
69 *  to the states necessary for the kernel to begin execution.  All
70 *  include files that contain global variable definitions should be
71 *  included in this file.  The system threads and initialization threads
72 *  are created and started by this routine.  This routine then
73 *  initiates multithreading.
74 *
75 *  Input parameters:
76 *    configuration_table - pointer to the user's configuration table
77 *    cpu_table           - pointer to the user's CPU configuration table
78 *
79 *  Output parameters:  NONE
80 */
81
82void rtems_initialize_executive(
83  rtems_configuration_table *configuration_table,
84  rtems_cpu_table           *cpu_table
85)
86{
87  rtems_interrupt_level bsp_level;
88
89  bsp_level = rtems_initialize_executive_early(configuration_table, cpu_table);
90  rtems_initialize_executive_late( bsp_level );
91}
92
93rtems_interrupt_level rtems_initialize_executive_early(
94  rtems_configuration_table *configuration_table,
95  rtems_cpu_table           *cpu_table
96)
97{
98  rtems_interrupt_level        bsp_level;
99  rtems_multiprocessing_table *multiprocessing_table;
100
101  /*
102   *  Dispatching and interrupts are disabled until the end of the
103   *  initialization sequence.  This prevents an inadvertent context
104   *  switch before the executive is initialized.
105   */
106
107  _ISR_Disable( bsp_level );
108
109  if ( configuration_table == NULL )
110    _Internal_error_Occurred(
111      INTERNAL_ERROR_CORE,
112      TRUE,
113      INTERNAL_ERROR_NO_CONFIGURATION_TABLE
114    );
115
116  /*
117   *  Initialize the system state based on whether this is an MP system.
118   */
119
120#if defined(RTEMS_MULTIPROCESSING)
121  multiprocessing_table = configuration_table->User_multiprocessing_table;
122
123  _System_state_Handler_initialization(
124    (multiprocessing_table) ? TRUE : FALSE
125  );
126#else
127  multiprocessing_table = NULL;
128
129  _System_state_Handler_initialization( FALSE );
130#endif
131
132  /*
133   *  Provided just for user convenience.
134   */
135
136  _Configuration_Table    = configuration_table;
137  _Configuration_MP_table = multiprocessing_table;
138
139  /*
140   *  Internally we view single processor systems as a very restricted
141   *  multiprocessor system.
142   */
143
144  if ( multiprocessing_table == NULL )
145    multiprocessing_table =
146      (void *)&_Initialization_Default_multiprocessing_table;
147
148  if ( cpu_table == NULL )
149    _Internal_error_Occurred(
150      INTERNAL_ERROR_CORE,
151      TRUE,
152      INTERNAL_ERROR_NO_CPU_TABLE
153    );
154
155  _CPU_Initialize( cpu_table, _Thread_Dispatch );
156
157  /*
158   *  Do this as early as possible to insure no debugging output
159   *  is even attempted to be printed.
160   */
161
162  _Debug_Manager_initialization();
163
164  _API_extensions_Initialization();
165
166  _Thread_Dispatch_initialization();
167
168  _Workspace_Handler_initialization(
169     (void *)configuration_table->work_space_start,
170     configuration_table->work_space_size
171  );
172
173  _User_extensions_Handler_initialization(
174    configuration_table->number_of_initial_extensions,
175    configuration_table->User_extension_table
176  );
177
178  _ISR_Handler_initialization();
179
180  _Objects_Handler_initialization(
181    multiprocessing_table->node,
182    multiprocessing_table->maximum_nodes,
183    multiprocessing_table->maximum_global_objects
184  );
185
186  _Objects_Information_table[OBJECTS_INTERNAL_API] = _Internal_Objects;
187
188  _Priority_Handler_initialization();
189
190  _Watchdog_Handler_initialization();
191
192  _TOD_Handler_initialization( configuration_table->microseconds_per_tick );
193
194  _Thread_Handler_initialization(
195    configuration_table->ticks_per_timeslice,
196    configuration_table->maximum_extensions,
197    multiprocessing_table->maximum_proxies
198  );
199
200#if defined(RTEMS_MULTIPROCESSING)
201  _MPCI_Handler_initialization(
202    multiprocessing_table->User_mpci_table,
203    RTEMS_TIMEOUT
204  );
205#endif
206
207/* MANAGERS */
208
209  _RTEMS_API_Initialize( configuration_table );
210
211  _Extension_Manager_initialization( configuration_table->maximum_extensions );
212
213  _IO_Manager_initialization(
214    configuration_table->Device_driver_table,
215    configuration_table->number_of_device_drivers,
216    configuration_table->maximum_drivers,
217    configuration_table->maximum_devices
218  );
219
220#ifdef RTEMS_POSIX_API
221  _POSIX_API_Initialize( configuration_table );
222#endif
223
224#ifdef RTEMS_ITRON_API
225  _ITRON_API_Initialize( configuration_table );
226#endif
227
228  _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING );
229
230  /*
231   *  No threads should be created before this point!!!
232   *  _Thread_Executing and _Thread_Heir are not set.
233   *
234   *  At this point all API extensions are in place.  After the call to
235   *  _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set.
236   */
237
238  _Thread_Create_idle();
239
240
241  /*
242   *  Scheduling can properly occur now as long as we avoid dispatching.
243   */
244
245  if ( cpu_table->pretasking_hook )
246    (*cpu_table->pretasking_hook)();
247
248#if defined(RTEMS_MULTIPROCESSING)
249  _MPCI_Create_server();
250#endif
251
252  /*
253   *  Run the API and BSPs predriver hook.
254   */
255
256  _API_extensions_Run_predriver();
257
258  if ( _CPU_Table.predriver_hook )
259    (*_CPU_Table.predriver_hook)();
260
261  /*
262   *  Initialize all the device drivers and initialize the MPCI layer.
263   *
264   *  NOTE:  The MPCI may be build upon a device driver.
265   */
266
267  _IO_Initialize_all_drivers();
268
269#if defined(RTEMS_MULTIPROCESSING)
270  if ( _System_state_Is_multiprocessing ) {
271    _MPCI_Initialization();
272    _MPCI_Internal_packets_Send_process_packet(
273      MPCI_PACKETS_SYSTEM_VERIFY
274    );
275  }
276#endif
277
278  /*
279   *  Run the APIs and BSPs postdriver hooks.
280   *
281   *  The API extensions are supposed to create user initialization tasks.
282   */
283
284  _API_extensions_Run_postdriver();
285
286  if ( _CPU_Table.postdriver_hook )
287    (*_CPU_Table.postdriver_hook)();
288
289  return bsp_level;
290}
291
292void rtems_initialize_executive_late(
293  rtems_interrupt_level bsp_level
294)
295{
296
297  _System_state_Set( SYSTEM_STATE_BEGIN_MULTITASKING );
298
299  _Thread_Start_multitasking();
300
301  /*
302   *  Restore the interrupt level to what the BSP had.  Technically,
303   *  this is unnecessary since the BSP should have all interrupts
304   *  disabled when rtems_initialize_executive is invoked.  But this keeps
305   *  the ISR Disable/Enable calls paired.
306   */
307
308  _ISR_Enable( bsp_level );
309}
310
311/*PAGE
312 *
313 *  rtems_shutdown_executive
314 *
315 *  This kernel routine shutdowns the executive.  It halts multitasking
316 *  and returns control to the application execution "thread" which
317 *  initialially invoked the rtems_initialize_executive directive.
318 *
319 *  Input parameters:   NONE
320 *
321 *  Output parameters:  NONE
322 */
323
324void rtems_shutdown_executive(
325   uint32_t   result
326)
327{
328  if ( _System_state_Current != SYSTEM_STATE_SHUTDOWN ) {
329    _System_state_Set( SYSTEM_STATE_SHUTDOWN );
330    _Thread_Stop_multitasking();
331  }
332}
Note: See TracBrowser for help on using the repository browser.