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

4.104.114.84.9
Last change on this file since a2a8c5b was a2a8c5b, checked in by Joel Sherrill <joel.sherrill@…>, on May 9, 2002 at 9:41:05 PM

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
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.OARcorp.com/rtems/license.html.
10 *
11 *  $Id$
12 */
13
14/*
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.
17 */
18
19#define SAPI_INIT
20#define SCORE_INIT
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>
29#include <rtems/score/sysstate.h>
30
31#include <rtems/score/apiext.h>
32#if 0
33#include <rtems/score/apimutex.h>
34#endif
35#include <rtems/score/copyrt.h>
36#include <rtems/score/heap.h>
37#include <rtems/score/interr.h>
38#include <rtems/score/isr.h>
39#if defined(RTEMS_MULTIPROCESSING)
40#include <rtems/score/mpci.h>
41#endif
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>
48
49#include <rtems/directives.h>
50#include <rtems/sptables.h>
51
52
53#include <rtems/rtems/rtemsapi.h>
54#ifdef RTEMS_POSIX_API
55#include <rtems/posix/posixapi.h>
56#endif
57#ifdef RTEMS_ITRON_API
58#include <rtems/itron/itronapi.h>
59#endif
60
61
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
107  if ( configuration_table == NULL )
108    _Internal_error_Occurred(
109      INTERNAL_ERROR_CORE,
110      TRUE,
111      INTERNAL_ERROR_NO_CONFIGURATION_TABLE
112    );
113
114  /*
115   *  Initialize the system state based on whether this is an MP system.
116   */
117
118#if defined(RTEMS_MULTIPROCESSING)
119  multiprocessing_table = configuration_table->User_multiprocessing_table;
120
121  _System_state_Handler_initialization(
122    (multiprocessing_table) ? TRUE : FALSE
123  );
124#else
125  multiprocessing_table = NULL;
126
127  _System_state_Handler_initialization( FALSE );
128
129#endif
130
131  /*
132   *  Provided just for user convenience.
133   */
134
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   */
142
143  if ( multiprocessing_table == NULL )
144    multiprocessing_table = 
145      (void *)&_Initialization_Default_multiprocessing_table;
146
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 );
155
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();
162
163  _API_extensions_Initialization();
164
165  _Thread_Dispatch_initialization();
166
167  _Workspace_Handler_initialization(
168     (void *)configuration_table->work_space_start,
169     configuration_table->work_space_size
170  );
171
172  _User_extensions_Handler_initialization(
173    configuration_table->number_of_initial_extensions,
174    configuration_table->User_extension_table
175  );
176
177  _ISR_Handler_initialization();
178
179  _Objects_Handler_initialization(
180    multiprocessing_table->node,
181    multiprocessing_table->maximum_nodes,
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,
193    configuration_table->maximum_extensions,
194    multiprocessing_table->maximum_proxies
195  );
196
197#if defined(RTEMS_MULTIPROCESSING)
198  _MPCI_Handler_initialization(
199    multiprocessing_table->User_mpci_table,
200    RTEMS_TIMEOUT
201  );
202#endif
203
204/* MANAGERS */
205
206  _Extension_Manager_initialization( configuration_table->maximum_extensions );
207
208  _IO_Manager_initialization(
209    configuration_table->Device_driver_table,
210    configuration_table->number_of_device_drivers,
211    configuration_table->maximum_drivers,
212    configuration_table->maximum_devices
213  );
214
215  _RTEMS_API_Initialize( configuration_table );
216
217#ifdef RTEMS_POSIX_API
218  _POSIX_API_Initialize( configuration_table );
219#endif
220
221#ifdef RTEMS_ITRON_API
222  _ITRON_API_Initialize( configuration_table );
223#endif
224
225  _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING );
226
227  /*
228   *  No threads should be created before this point!!!
229   *  _Thread_Executing and _Thread_Heir are not set.
230   *
231   *  At this point all API extensions are in place.  After the call to
232   *  _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set.
233   */
234
235  _Thread_Create_idle();
236
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
245#if defined(RTEMS_MULTIPROCESSING)
246  _MPCI_Create_server();
247#endif
248
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 
266#if defined(RTEMS_MULTIPROCESSING)
267  if ( _System_state_Is_multiprocessing ) {
268    _MPCI_Initialization();
269    _MPCI_Internal_packets_Send_process_packet(
270      MPCI_PACKETS_SYSTEM_VERIFY
271    );
272  }
273#endif
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
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
296  _Thread_Start_multitasking();
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{
325  if ( _System_state_Current != SYSTEM_STATE_SHUTDOWN ) {
326    _System_state_Set( SYSTEM_STATE_SHUTDOWN );
327    _Thread_Stop_multitasking();
328  }
329}
Note: See TracBrowser for help on using the repository browser.