source: rtems/cpukit/sapi/src/exinit.c @ 8bd41178

4.104.114.84.95
Last change on this file since 8bd41178 was 8bd41178, checked in by Ralf Corsepius <ralf.corsepius@…>, on 03/29/04 at 16:20:10

2004-03-29 Ralf Corsepius <ralf_corsepius@…>

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