source: rtems/cpukit/sapi/src/exinit.c @ 599d71f

Last change on this file since 599d71f was 599d71f, checked in by Sebastian Huber <sebastian.huber@…>, on Jan 11, 2016 at 12:02:06 PM

score: Statically initialize TOD handler

  • Property mode set to 100644
File size: 7.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief Initialization Manager
5 *
6 * @ingroup ClassicRTEMS
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2014.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22/*
23 *  SCORE_INIT and SAPI_INIT are defined so all of the super core and
24 *  super API data will be included in this object file.
25 */
26
27#define SAPI_INIT
28#define SCORE_INIT
29
30#include <rtems/system.h>
31#include <rtems/config.h>
32#include <rtems/extensionimpl.h>
33#include <rtems/init.h>
34#include <rtems/sysinit.h>
35#include <rtems/score/sysstate.h>
36
37#include <rtems/score/apiext.h>
38#include <rtems/score/apimutex.h>
39#include <rtems/score/copyrt.h>
40#include <rtems/score/cpusetimpl.h>
41#include <rtems/score/heap.h>
42#include <rtems/score/interr.h>
43#include <rtems/score/isr.h>
44#include <rtems/score/priority.h>
45#include <rtems/score/schedulerimpl.h>
46#include <rtems/score/smpimpl.h>
47#include <rtems/score/timecounter.h>
48#include <rtems/score/threadimpl.h>
49#include <rtems/score/todimpl.h>
50#include <rtems/score/userextimpl.h>
51#include <rtems/score/watchdogimpl.h>
52#include <rtems/score/wkspace.h>
53
54#include <rtems/sptables.h>
55
56
57#include <rtems/rtems/rtemsapi.h>
58#include <rtems/posix/posixapi.h>
59
60#ifdef RTEMS_DRVMGR_STARTUP
61  #include <drvmgr/drvmgr.h>
62#endif
63
64Objects_Information *_Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ];
65
66static void rtems_initialize_data_structures(void)
67{
68  /*
69   *  Dispatching and interrupts are disabled until the end of the
70   *  initialization sequence.  This prevents an inadvertent context
71   *  switch before the executive is initialized.
72   *
73   *  WARNING: Interrupts should have been disabled by the BSP and
74   *           are disabled by boot_card().
75   */
76
77  #if defined(RTEMS_MULTIPROCESSING)
78    /*
79     *  Initialize the system state based on whether this is an MP system.
80     *  In an MP configuration, internally we view single processor
81     *  systems as a very restricted multiprocessor system.
82     */
83    _Configuration_MP_table = rtems_configuration_get_user_multiprocessing_table();
84
85    if ( _Configuration_MP_table == NULL ) {
86      _Configuration_MP_table =
87        (void *)&_Initialization_Default_multiprocessing_table;
88    } else {
89      _System_state_Is_multiprocessing = true;
90    }
91  #endif
92
93  /*
94   * Initialize any target architecture specific support as early as possible
95   */
96  _CPU_Initialize();
97
98  #if defined(RTEMS_MULTIPROCESSING)
99    _Objects_MP_Handler_early_initialization();
100  #endif
101
102  _Thread_Dispatch_initialization();
103
104  _User_extensions_Handler_initialization();
105  _ISR_Handler_initialization();
106
107  /*
108   * Initialize the internal support API and allocator Mutex
109   */
110  _Objects_Information_table[OBJECTS_INTERNAL_API] = _Internal_Objects;
111
112  _API_Mutex_Initialization( 2 );
113  _API_Mutex_Allocate( &_RTEMS_Allocator_Mutex );
114  _API_Mutex_Allocate( &_Once_Mutex );
115
116  _Watchdog_Handler_initialization();
117
118  _Thread_Handler_initialization();
119
120  _Scheduler_Handler_initialization();
121
122  #if defined(RTEMS_MULTIPROCESSING)
123    _Objects_MP_Handler_initialization();
124    _MPCI_Handler_initialization( RTEMS_TIMEOUT );
125  #endif
126
127  _SMP_Handler_initialize();
128
129  _CPU_set_Handler_initialization();
130
131/* MANAGERS */
132
133  _RTEMS_API_Initialize();
134
135  _Extension_Manager_initialization();
136
137  _POSIX_API_Initialize();
138
139  _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING );
140
141  /*
142   *  No threads should be created before this point!!!
143   *  _Thread_Executing and _Thread_Heir are not set.
144   *
145   *  At this point all API extensions are in place.  After the call to
146   *  _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set.
147   */
148  _Thread_Create_idle();
149
150  /*
151   *  Scheduling can properly occur now as long as we avoid dispatching.
152   */
153}
154
155static void rtems_initialize_before_drivers(void)
156{
157  #ifdef RTEMS_DRVMGR_STARTUP
158  _DRV_Manager_initialization();
159  #endif
160
161  #if defined(RTEMS_MULTIPROCESSING)
162    _MPCI_Create_server();
163  #endif
164}
165
166static void rtems_initialize_device_drivers(void)
167{
168  /*
169   *  Initialize all the device drivers and initialize the MPCI layer.
170   *
171   *  NOTE:  The MPCI may be build upon a device driver.
172   */
173
174  #ifdef RTEMS_DRVMGR_STARTUP
175  /* BSPs has already registered their "root bus" driver in the
176   * bsp_predriver hook or so.
177   *
178   * Init Drivers to Level 1, constraints:
179   *   - Interrupts and system clock timer does not work.
180   *   - malloc() work, however other memory services may not
181   *     have been initialized yet.
182   *   - initializes most basic stuff
183   *
184   * Typical setup in Level 1:
185   *   - Find most devices in system, do PCI scan and configuration.
186   *   - Reset hardware if needed.
187   *   - Install IRQ driver
188   *   - Install Timer driver
189   *   - Install console driver and debug printk()
190   *   - Install extra memory.
191   */
192  _DRV_Manager_init_level(1);
193  bsp_driver_level_hook(1);
194  #endif
195
196  /* Initialize I/O drivers.
197   *
198   * Driver Manager note:
199   * All drivers may not be registered yet. Drivers will dynamically
200   * be initialized when registered in level 2,3 and 4.
201   */
202  _IO_Initialize_all_drivers();
203
204  #ifdef RTEMS_DRVMGR_STARTUP
205  /* Init Drivers to Level 2, constraints:
206   *  - Interrupts can be registered and enabled.
207   *  - System Clock is running
208   *  - Console may be used.
209   *
210   * This is typically where drivers are initialized
211   * for the first time.
212   */
213  _DRV_Manager_init_level(2);
214  bsp_driver_level_hook(2);
215
216  /* Init Drivers to Level 3
217   *
218   * This is typically where normal drivers are initialized
219   * for the second time, they may depend on other drivers
220   * API inited in level 2
221   */
222  _DRV_Manager_init_level(3);
223  bsp_driver_level_hook(3);
224
225  /* Init Drivers to Level 4,
226   * Init drivers that depend on services initialized in Level 3
227   */
228  _DRV_Manager_init_level(4);
229  bsp_driver_level_hook(4);
230  #endif
231
232  #if defined(RTEMS_MULTIPROCESSING)
233    if ( _System_state_Is_multiprocessing ) {
234      _MPCI_Initialization();
235      _MPCI_Internal_packets_Send_process_packet(
236        MPCI_PACKETS_SYSTEM_VERIFY
237      );
238    }
239  #endif
240
241  /*
242   *  Run the APIs and BSPs postdriver hooks.
243   *
244   *  The API extensions are supposed to create user initialization tasks.
245   */
246  _API_extensions_Run_postdriver();
247}
248
249RTEMS_LINKER_ROSET( _Sysinit, rtems_sysinit_item );
250
251RTEMS_SYSINIT_ITEM(
252  rtems_initialize_data_structures,
253  RTEMS_SYSINIT_DATA_STRUCTURES,
254  RTEMS_SYSINIT_ORDER_MIDDLE
255);
256
257RTEMS_SYSINIT_ITEM(
258  rtems_initialize_before_drivers,
259  RTEMS_SYSINIT_BEFORE_DRIVERS,
260  RTEMS_SYSINIT_ORDER_MIDDLE
261);
262
263RTEMS_SYSINIT_ITEM(
264  rtems_initialize_device_drivers,
265  RTEMS_SYSINIT_DEVICE_DRIVERS,
266  RTEMS_SYSINIT_ORDER_MIDDLE
267);
268
269void rtems_initialize_executive(void)
270{
271  const volatile rtems_sysinit_item *cur = RTEMS_LINKER_SET_BEGIN(_Sysinit );
272  const volatile rtems_sysinit_item *end = RTEMS_LINKER_SET_END( _Sysinit );
273
274  /* Invoke the registered system initialization handlers */
275  while ( cur != end ) {
276    ( *cur->handler )();
277    ++cur;
278  }
279
280  _System_state_Set( SYSTEM_STATE_UP );
281
282  _SMP_Request_start_multitasking();
283
284  _Thread_Start_multitasking();
285
286  /*******************************************************************
287   *******************************************************************
288   *******************************************************************
289   ******                 APPLICATION RUNS HERE                 ******
290   ******              THE FUNCTION NEVER RETURNS               ******
291   *******************************************************************
292   *******************************************************************
293   *******************************************************************/
294}
Note: See TracBrowser for help on using the repository browser.