source: rtems/c/src/exec/sapi/src/exinit.c @ 5f57730

4.104.114.84.95
Last change on this file since 5f57730 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

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