source: rtems/cpukit/sapi/src/exinit.c @ 352c9b2

4.104.114.84.9
Last change on this file since 352c9b2 was 352c9b2, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 9, 1999 at 10:07:23 PM

This patch adds the basic framework for the ITRON 3.0 API implementation
for RTEMS.

  • Property mode set to 100644
File size: 7.7 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#if defined(RTEMS_MULTIPROCESSING)
38#include <rtems/score/mpci.h>
39#endif
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>
46
47#include <rtems/directives.h>
48#include <rtems/sptables.h>
49
50
51#include <rtems/rtems/rtemsapi.h>
52#ifdef RTEMS_POSIX_API
53#include <rtems/posix/posixapi.h>
54#endif
55#ifdef RTEMS_ITRON_API
56#include <rtems/itron/itronapi.h>
57#endif
58
59
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
105  if ( configuration_table == NULL )
106    _Internal_error_Occurred(
107      INTERNAL_ERROR_CORE,
108      TRUE,
109      INTERNAL_ERROR_NO_CONFIGURATION_TABLE
110    );
111
112  /*
113   *  Initialize the system state based on whether this is an MP system.
114   */
115
116#if defined(RTEMS_MULTIPROCESSING)
117  multiprocessing_table = configuration_table->User_multiprocessing_table;
118
119  _System_state_Handler_initialization(
120    (multiprocessing_table) ? TRUE : FALSE
121  );
122#else
123  multiprocessing_table = NULL;
124
125  _System_state_Handler_initialization( FALSE );
126
127#endif
128
129  /*
130   *  Provided just for user convenience.
131   */
132
133  _Configuration_Table    = configuration_table;
134  _Configuration_MP_table = multiprocessing_table;
135
136  /*
137   *  Internally we view single processor systems as a very restricted
138   *  multiprocessor system.
139   */
140
141  if ( multiprocessing_table == NULL )
142    multiprocessing_table = 
143      (void *)&_Initialization_Default_multiprocessing_table;
144
145  if ( cpu_table == NULL )
146    _Internal_error_Occurred(
147      INTERNAL_ERROR_CORE,
148      TRUE,
149      INTERNAL_ERROR_NO_CPU_TABLE
150    );
151
152  _CPU_Initialize( cpu_table, _Thread_Dispatch );
153
154  /*
155   *  Do this as early as possible to insure no debugging output
156   *  is even attempted to be printed.
157   */
158
159  _Debug_Manager_initialization();
160
161  _API_extensions_Initialization();
162
163  _Thread_Dispatch_initialization();
164
165  _Workspace_Handler_initialization(
166     (void *)configuration_table->work_space_start,
167     configuration_table->work_space_size
168  );
169
170  _User_extensions_Handler_initialization(
171    configuration_table->number_of_initial_extensions,
172    configuration_table->User_extension_table
173  );
174
175  _ISR_Handler_initialization();
176
177  _Objects_Handler_initialization(
178    multiprocessing_table->node,
179    multiprocessing_table->maximum_nodes,
180    multiprocessing_table->maximum_global_objects
181  );
182
183  _Priority_Handler_initialization();
184
185  _Watchdog_Handler_initialization();
186
187  _TOD_Handler_initialization( configuration_table->microseconds_per_tick );
188
189  _Thread_Handler_initialization(
190    configuration_table->ticks_per_timeslice,
191    configuration_table->maximum_extensions,
192    multiprocessing_table->maximum_proxies
193  );
194
195#if defined(RTEMS_MULTIPROCESSING)
196  _MPCI_Handler_initialization(
197    multiprocessing_table->User_mpci_table,
198    RTEMS_TIMEOUT
199  );
200#endif
201
202/* MANAGERS */
203
204  _Extension_Manager_initialization( configuration_table->maximum_extensions );
205
206  _IO_Manager_initialization(
207    configuration_table->Device_driver_table,
208    configuration_table->number_of_device_drivers,
209    configuration_table->maximum_devices
210  );
211
212  _RTEMS_API_Initialize( configuration_table );
213
214#ifdef RTEMS_POSIX_API
215  _POSIX_API_Initialize( configuration_table );
216#endif
217
218#ifdef RTEMS_ITRON_API
219  _ITRON_API_Initialize( configuration_table );
220#endif
221
222  _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING );
223
224  if ( cpu_table->pretasking_hook )
225    (*cpu_table->pretasking_hook)();
226
227  /*
228   *  No threads should be created before this point!!!
229   *
230   *  At this point all API extensions are in place.  After the call to
231   *  _Thread_Create_idle() _Thread_Executing will be set.
232   *  and _Thread_Heir are not set yet.
233   */
234
235  _Thread_Create_idle();
236
237#if defined(RTEMS_MULTIPROCESSING)
238  _MPCI_Create_server();
239#endif
240
241  /*
242   *  Run the API and BSPs predriver hook.
243   */
244 
245  _API_extensions_Run_predriver();
246 
247  if ( _CPU_Table.predriver_hook )
248    (*_CPU_Table.predriver_hook)();
249 
250  /*
251   *  Initialize all the device drivers and initialize the MPCI layer.
252   *
253   *  NOTE:  The MPCI may be build upon a device driver.
254   */
255 
256  _IO_Initialize_all_drivers();
257 
258#if defined(RTEMS_MULTIPROCESSING)
259  if ( _System_state_Is_multiprocessing ) {
260    _MPCI_Initialization();
261    _MPCI_Internal_packets_Send_process_packet(
262      MPCI_PACKETS_SYSTEM_VERIFY
263    );
264  }
265#endif
266 
267  /*
268   *  Run the APIs and BSPs postdriver hooks.
269   *
270   *  The API extensions are supposed to create user initialization tasks.
271   */
272 
273  _API_extensions_Run_postdriver();
274 
275  if ( _CPU_Table.postdriver_hook )
276    (*_CPU_Table.postdriver_hook)();
277
278  return bsp_level;
279}
280
281void rtems_initialize_executive_late(
282  rtems_interrupt_level bsp_level
283)
284{
285
286  _System_state_Set( SYSTEM_STATE_BEGIN_MULTITASKING );
287
288  _Thread_Start_multitasking();
289
290  /*
291   *  Restore the interrupt level to what the BSP had.  Technically,
292   *  this is unnecessary since the BSP should have all interrupts
293   *  disabled when rtems_initialize_executive is invoked.  But this keeps
294   *  the ISR Disable/Enable calls paired.
295   */
296
297  _ISR_Enable( bsp_level );
298}
299
300/*PAGE
301 *
302 *  rtems_shutdown_executive
303 *
304 *  This kernel routine shutdowns the executive.  It halts multitasking
305 *  and returns control to the application execution "thread" which
306 *  initialially invoked the rtems_initialize_executive directive.
307 *
308 *  Input parameters:   NONE
309 *
310 *  Output parameters:  NONE
311 */
312
313void rtems_shutdown_executive(
314   unsigned32 result
315)
316{
317  if ( _System_state_Current != SYSTEM_STATE_SHUTDOWN ) {
318    _System_state_Set( SYSTEM_STATE_SHUTDOWN );
319    _Thread_Stop_multitasking();
320  }
321}
Note: See TracBrowser for help on using the repository browser.