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

4.104.114.9
Last change on this file since f5f4566 was f5f4566, checked in by Joel Sherrill <joel.sherrill@…>, on May 6, 2008 at 11:17:07 PM

2008-05-06 Joel Sherrill <joel.sherrill@…>

  • sapi/src/exinit.c, score/src/threadstartmultitasking.c: Improve comments.
  • Property mode set to 100644
File size: 6.8 KB
Line 
1/*
2 *  Initialization Manager
3 *
4 *  COPYRIGHT (c) 1989-2007.
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.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18/*
19 *  SCORE_INIT and SAPI_INIT are defined so all of the super core and
20 *  super API data will be included in this object file.
21 */
22
23#define SAPI_INIT
24#define SCORE_INIT
25
26#include <rtems/system.h>
27#include <rtems/config.h>
28#include <rtems/debug.h>
29#include <rtems/extension.h>
30#include <rtems/fatal.h>
31#include <rtems/init.h>
32#include <rtems/io.h>
33#include <rtems/score/sysstate.h>
34
35#include <rtems/score/apiext.h>
36#include <rtems/score/apimutex.h>
37#include <rtems/score/copyrt.h>
38#include <rtems/score/heap.h>
39#include <rtems/score/interr.h>
40#include <rtems/score/isr.h>
41#if defined(RTEMS_MULTIPROCESSING)
42#include <rtems/score/mpci.h>
43#endif
44#include <rtems/score/priority.h>
45#include <rtems/score/thread.h>
46#include <rtems/score/tod.h>
47#include <rtems/score/userext.h>
48#include <rtems/score/watchdog.h>
49#include <rtems/score/wkspace.h>
50
51#include <rtems/sptables.h>
52
53
54#include <rtems/rtems/rtemsapi.h>
55#ifdef RTEMS_POSIX_API
56#include <rtems/posix/posixapi.h>
57#endif
58#ifdef RTEMS_ITRON_API
59#include <rtems/itron/itronapi.h>
60#endif
61
62Objects_Information *_Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ];
63
64rtems_interrupt_level rtems_initialize_executive_early(
65  rtems_configuration_table *configuration_table
66)
67{
68  rtems_interrupt_level        bsp_level;
69
70  /*
71   *  Dispatching and interrupts are disabled until the end of the
72   *  initialization sequence.  This prevents an inadvertent context
73   *  switch before the executive is initialized.
74   */
75  _ISR_Disable( bsp_level );
76
77  /*
78   *  Make sure the parameters were not NULL.
79   */
80  if ( configuration_table == NULL )
81    _Internal_error_Occurred(
82      INTERNAL_ERROR_CORE,
83      TRUE,
84      INTERNAL_ERROR_NO_CONFIGURATION_TABLE
85    );
86
87  /*
88   *  Provide pointers just for later convenience.
89   */
90  _Configuration_Table    = configuration_table;
91
92  /*
93   * Initialize any target architecture specific support as early as possible
94   */
95  _CPU_Initialize( _Thread_Dispatch );
96
97#if defined(RTEMS_MULTIPROCESSING)
98  /*
99   *  Initialize the system state based on whether this is an MP system.
100   *  In an MP configuration, internally we view single processor
101   *  systems as a very restricted multiprocessor system.
102   */
103  _Configuration_MP_table = configuration_table->User_multiprocessing_table;
104
105  if ( _Configuration_MP_table == NULL ) {
106    _Configuration_MP_table =
107      (void *)&_Initialization_Default_multiprocessing_table;
108    _System_state_Handler_initialization( FALSE );
109  } else {
110    _System_state_Handler_initialization( TRUE );
111  }
112#else
113  _System_state_Handler_initialization( FALSE );
114#endif
115
116  /*
117   *  Do this as early as possible to insure no debugging output
118   *  is even attempted to be printed.
119   */
120
121  _Debug_Manager_initialization();
122
123  _API_extensions_Initialization();
124
125  _Thread_Dispatch_initialization();
126
127  /*
128   *  Before this is called, we are not allowed to allocate memory
129   *  from the Workspace because it is not initialized.
130   */
131  _Workspace_Handler_initialization(
132     (void *)configuration_table->work_space_start,
133     configuration_table->work_space_size
134  );
135
136  _User_extensions_Handler_initialization(
137    configuration_table->number_of_initial_extensions,
138    configuration_table->User_extension_table
139  );
140
141  _ISR_Handler_initialization();
142
143  _Objects_Handler_initialization(
144#if defined(RTEMS_MULTIPROCESSING)
145    _Configuration_MP_table->node,
146    _Configuration_MP_table->maximum_nodes,
147    _Configuration_MP_table->maximum_global_objects
148#endif
149  );
150
151  _Objects_Information_table[OBJECTS_INTERNAL_API] = _Internal_Objects;
152
153  /*
154   * Initialize the internal allocator Mutex
155   */
156  _API_Mutex_Initialization( 1 );
157  _API_Mutex_Allocate( &_RTEMS_Allocator_Mutex );
158
159  _Priority_Handler_initialization();
160
161  _Watchdog_Handler_initialization();
162
163  _TOD_Handler_initialization( configuration_table->microseconds_per_tick );
164
165  _Thread_Handler_initialization(
166    configuration_table->ticks_per_timeslice,
167    configuration_table->maximum_extensions
168#if defined(RTEMS_MULTIPROCESSING)
169    ,
170    _Configuration_MP_table->maximum_proxies
171#endif
172  );
173
174#if defined(RTEMS_MULTIPROCESSING)
175  _MPCI_Handler_initialization(
176    _Configuration_MP_table->User_mpci_table,
177    RTEMS_TIMEOUT
178  );
179#endif
180
181/* MANAGERS */
182
183  _RTEMS_API_Initialize( configuration_table );
184
185  _Extension_Manager_initialization( configuration_table->maximum_extensions );
186
187  _IO_Manager_initialization(
188    configuration_table->Device_driver_table,
189    configuration_table->number_of_device_drivers,
190    configuration_table->maximum_drivers
191  );
192
193#ifdef RTEMS_POSIX_API
194  _POSIX_API_Initialize( configuration_table );
195#endif
196
197#ifdef RTEMS_ITRON_API
198  _ITRON_API_Initialize( configuration_table );
199#endif
200
201  _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING );
202
203  /*
204   *  No threads should be created before this point!!!
205   *  _Thread_Executing and _Thread_Heir are not set.
206   *
207   *  At this point all API extensions are in place.  After the call to
208   *  _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set.
209   */
210
211  _Thread_Create_idle();
212
213  /*
214   *  Scheduling can properly occur now as long as we avoid dispatching.
215   */
216
217  {
218    extern void bsp_pretasking_hook(void);
219    bsp_pretasking_hook();
220  }
221
222#if defined(RTEMS_MULTIPROCESSING)
223  _MPCI_Create_server();
224#endif
225
226  /*
227   *  Run the API and BSPs predriver hook.
228   */
229
230  _API_extensions_Run_predriver();
231
232  {
233    extern void bsp_predriver_hook(void);
234    bsp_predriver_hook();
235  }
236
237  /*
238   *  Initialize all the device drivers and initialize the MPCI layer.
239   *
240   *  NOTE:  The MPCI may be build upon a device driver.
241   */
242
243  _IO_Initialize_all_drivers();
244
245#if defined(RTEMS_MULTIPROCESSING)
246  if ( _System_state_Is_multiprocessing ) {
247    _MPCI_Initialization();
248    _MPCI_Internal_packets_Send_process_packet(
249      MPCI_PACKETS_SYSTEM_VERIFY
250    );
251  }
252#endif
253
254  /*
255   *  Run the APIs and BSPs postdriver hooks.
256   *
257   *  The API extensions are supposed to create user initialization tasks.
258   */
259
260  _API_extensions_Run_postdriver();
261
262  {
263    extern void bsp_postdriver_hook(void);
264    bsp_postdriver_hook();
265  }
266
267  return bsp_level;
268}
269
270void rtems_initialize_executive_late(
271  rtems_interrupt_level bsp_level
272)
273{
274
275  _System_state_Set( SYSTEM_STATE_BEGIN_MULTITASKING );
276
277  _Thread_Start_multitasking();
278
279  /*
280   *  Restore the interrupt level to what the BSP had.  Technically,
281   *  this is unnecessary since the BSP should have all interrupts
282   *  disabled when rtems_initialize_executive is invoked.  But this keeps
283   *  the ISR Disable/Enable calls paired.
284   */
285
286  _ISR_Enable( bsp_level );
287}
Note: See TracBrowser for help on using the repository browser.