source: rtems/cpukit/sapi/src/exinit.c @ 36b86d7

5
Last change on this file since 36b86d7 was 36b86d7, checked in by Sebastian Huber <sebastian.huber@…>, on 01/25/16 at 19:55:52

score: Create idle threads via linker set

This allows a more fine grained rtems_initialize_data_structures().

Update #2408.

  • Property mode set to 100644
File size: 7.8 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
64static Objects_Information *
65_Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ];
66
67static Objects_Information *_RTEMS_Objects[ OBJECTS_RTEMS_CLASSES_LAST + 1 ];
68
69static Objects_Information *_POSIX_Objects[ OBJECTS_POSIX_CLASSES_LAST + 1 ];
70
71Objects_Information **_Objects_Information_table[ OBJECTS_APIS_LAST + 1 ] = {
72  NULL,
73  &_Internal_Objects[ 0 ],
74  &_RTEMS_Objects[ 0 ],
75  &_POSIX_Objects[ 0 ]
76};
77
78static void rtems_initialize_data_structures(void)
79{
80  /*
81   *  Dispatching and interrupts are disabled until the end of the
82   *  initialization sequence.  This prevents an inadvertent context
83   *  switch before the executive is initialized.
84   *
85   *  WARNING: Interrupts should have been disabled by the BSP and
86   *           are disabled by boot_card().
87   */
88
89  #if defined(RTEMS_MULTIPROCESSING)
90    /*
91     *  Initialize the system state based on whether this is an MP system.
92     *  In an MP configuration, internally we view single processor
93     *  systems as a very restricted multiprocessor system.
94     */
95    _Configuration_MP_table = rtems_configuration_get_user_multiprocessing_table();
96
97    if ( _Configuration_MP_table == NULL ) {
98      _Configuration_MP_table =
99        (void *)&_Initialization_Default_multiprocessing_table;
100    } else {
101      _System_state_Is_multiprocessing = true;
102    }
103  #endif
104
105  /*
106   * Initialize any target architecture specific support as early as possible
107   */
108  _CPU_Initialize();
109
110  #if defined(RTEMS_MULTIPROCESSING)
111    _Objects_MP_Handler_early_initialization();
112  #endif
113
114  _Thread_Dispatch_initialization();
115
116  _User_extensions_Handler_initialization();
117  _ISR_Handler_initialization();
118
119  _API_Mutex_Initialization( 2 );
120  _API_Mutex_Allocate( &_RTEMS_Allocator_Mutex );
121  _API_Mutex_Allocate( &_Once_Mutex );
122
123  _Watchdog_Handler_initialization();
124
125  _Thread_Handler_initialization();
126
127  _Scheduler_Handler_initialization();
128
129  #if defined(RTEMS_MULTIPROCESSING)
130    _Objects_MP_Handler_initialization();
131    _MPCI_Handler_initialization( RTEMS_TIMEOUT );
132  #endif
133
134  _SMP_Handler_initialize();
135
136  _CPU_set_Handler_initialization();
137
138/* MANAGERS */
139
140  _RTEMS_API_Initialize();
141
142  _Extension_Manager_initialization();
143
144  _POSIX_API_Initialize();
145}
146
147static void rtems_initialize_before_drivers(void)
148{
149  #ifdef RTEMS_DRVMGR_STARTUP
150  _DRV_Manager_initialization();
151  #endif
152
153  #if defined(RTEMS_MULTIPROCESSING)
154    _MPCI_Create_server();
155  #endif
156}
157
158static void rtems_initialize_device_drivers(void)
159{
160  /*
161   *  Initialize all the device drivers and initialize the MPCI layer.
162   *
163   *  NOTE:  The MPCI may be build upon a device driver.
164   */
165
166  #ifdef RTEMS_DRVMGR_STARTUP
167  /* BSPs has already registered their "root bus" driver in the
168   * bsp_predriver hook or so.
169   *
170   * Init Drivers to Level 1, constraints:
171   *   - Interrupts and system clock timer does not work.
172   *   - malloc() work, however other memory services may not
173   *     have been initialized yet.
174   *   - initializes most basic stuff
175   *
176   * Typical setup in Level 1:
177   *   - Find most devices in system, do PCI scan and configuration.
178   *   - Reset hardware if needed.
179   *   - Install IRQ driver
180   *   - Install Timer driver
181   *   - Install console driver and debug printk()
182   *   - Install extra memory.
183   */
184  _DRV_Manager_init_level(1);
185  bsp_driver_level_hook(1);
186  #endif
187
188  /* Initialize I/O drivers.
189   *
190   * Driver Manager note:
191   * All drivers may not be registered yet. Drivers will dynamically
192   * be initialized when registered in level 2,3 and 4.
193   */
194  _IO_Initialize_all_drivers();
195
196  #ifdef RTEMS_DRVMGR_STARTUP
197  /* Init Drivers to Level 2, constraints:
198   *  - Interrupts can be registered and enabled.
199   *  - System Clock is running
200   *  - Console may be used.
201   *
202   * This is typically where drivers are initialized
203   * for the first time.
204   */
205  _DRV_Manager_init_level(2);
206  bsp_driver_level_hook(2);
207
208  /* Init Drivers to Level 3
209   *
210   * This is typically where normal drivers are initialized
211   * for the second time, they may depend on other drivers
212   * API inited in level 2
213   */
214  _DRV_Manager_init_level(3);
215  bsp_driver_level_hook(3);
216
217  /* Init Drivers to Level 4,
218   * Init drivers that depend on services initialized in Level 3
219   */
220  _DRV_Manager_init_level(4);
221  bsp_driver_level_hook(4);
222  #endif
223
224  #if defined(RTEMS_MULTIPROCESSING)
225    if ( _System_state_Is_multiprocessing ) {
226      _MPCI_Initialization();
227      _MPCI_Internal_packets_Send_process_packet(
228        MPCI_PACKETS_SYSTEM_VERIFY
229      );
230    }
231  #endif
232
233  /*
234   *  Run the APIs and BSPs postdriver hooks.
235   *
236   *  The API extensions are supposed to create user initialization tasks.
237   */
238  _API_extensions_Run_postdriver();
239}
240
241RTEMS_LINKER_ROSET( _Sysinit, rtems_sysinit_item );
242
243RTEMS_SYSINIT_ITEM(
244  rtems_initialize_data_structures,
245  RTEMS_SYSINIT_DATA_STRUCTURES,
246  RTEMS_SYSINIT_ORDER_MIDDLE
247);
248
249/*
250 *  No threads should be created before this point!!!
251 *  _Thread_Executing and _Thread_Heir are not set.
252 *
253 *  At this point all API extensions are in place.  After the call to
254 *  _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set.
255 *
256 *  Scheduling can properly occur afterwards as long as we avoid dispatching.
257 */
258RTEMS_SYSINIT_ITEM(
259  _Thread_Create_idle,
260  RTEMS_SYSINIT_IDLE_THREADS,
261  RTEMS_SYSINIT_ORDER_MIDDLE
262);
263
264RTEMS_SYSINIT_ITEM(
265  rtems_initialize_before_drivers,
266  RTEMS_SYSINIT_BEFORE_DRIVERS,
267  RTEMS_SYSINIT_ORDER_MIDDLE
268);
269
270RTEMS_SYSINIT_ITEM(
271  rtems_initialize_device_drivers,
272  RTEMS_SYSINIT_DEVICE_DRIVERS,
273  RTEMS_SYSINIT_ORDER_MIDDLE
274);
275
276void rtems_initialize_executive(void)
277{
278  const volatile rtems_sysinit_item *cur = RTEMS_LINKER_SET_BEGIN(_Sysinit );
279  const volatile rtems_sysinit_item *end = RTEMS_LINKER_SET_END( _Sysinit );
280
281  /* Invoke the registered system initialization handlers */
282  while ( cur != end ) {
283    ( *cur->handler )();
284    ++cur;
285  }
286
287  _System_state_Set( SYSTEM_STATE_UP );
288
289  _SMP_Request_start_multitasking();
290
291  _Thread_Start_multitasking();
292
293  /*******************************************************************
294   *******************************************************************
295   *******************************************************************
296   ******                 APPLICATION RUNS HERE                 ******
297   ******              THE FUNCTION NEVER RETURNS               ******
298   *******************************************************************
299   *******************************************************************
300   *******************************************************************/
301}
Note: See TracBrowser for help on using the repository browser.