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

4.104.114.84.95
Last change on this file since a2a8c5b was a2a8c5b, checked in by Joel Sherrill <joel.sherrill@…>, on 05/09/02 at 21:41:05

2001-05-09 Joel Sherrill <joel@…>

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