source: rtems/cpukit/sapi/src/exinit.c @ 0451b44

4.104.114.84.9
Last change on this file since 0451b44 was 0451b44, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 15, 1998 at 12:02:10 AM

Per suggestion from Eric Norum, went from one initial extension set
to multiple. This lets the stack check extension be installed
at system initialization time and avoids the BSP having to
even know about its existence.

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