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

Last change on this file since d0c39838 was d0c39838, checked in by Sebastian Huber <sebastian.huber@…>, on Sep 22, 2015 at 2:21:12 PM

Use linker set for system initialization

Make rtems_initialize_data_structures(),
rtems_initialize_before_drivers() and rtems_initialize_device_drivers()
static. Rename rtems_initialize_start_multitasking() to
rtems_initialize_executive() and call the registered system
initialization handlers in this function. Add system initialization API
available via #include <rtems/sysinit.h>. Update the documentation
accordingly.

This is no functional change, only the method to call the existing
initialization routines changes. Instead of direct function calls a
table of function pointers contained in the new RTEMS system
initialization linker set is used. This table looks like this (the
actual addresses depend on the target).

nm *.exe | grep _Linker | sort
0201a2d0 D _Linker_setSysinit_begin
0201a2d0 D _Linker_set
Sysinit_bsp_work_area_initialize
0201a2d4 D _Linker_setSysinit_bsp_start
0201a2d8 D _Linker_set
Sysinit_rtems_initialize_data_structures
0201a2dc D _Linker_setSysinit_bsp_libc_init
0201a2e0 D _Linker_set
Sysinit_rtems_initialize_before_drivers
0201a2e4 D _Linker_setSysinit_bsp_predriver_hook
0201a2e8 D _Linker_set
Sysinit_rtems_initialize_device_drivers
0201a2ec D _Linker_setSysinit_bsp_postdriver_hook
0201a2f0 D _Linker_set
Sysinit_end

Add test sptests/spsysinit01.

Update #2408.

  • Property mode set to 100644
File size: 7.7 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  _TOD_Handler_initialization();
118
119  _Thread_Handler_initialization();
120
121  _Scheduler_Handler_initialization();
122
123  #if defined(RTEMS_MULTIPROCESSING)
124    _Objects_MP_Handler_initialization();
125    _MPCI_Handler_initialization( RTEMS_TIMEOUT );
126  #endif
127
128  _SMP_Handler_initialize();
129
130  _CPU_set_Handler_initialization();
131
132/* MANAGERS */
133
134  _RTEMS_API_Initialize();
135
136  _Extension_Manager_initialization();
137
138  _POSIX_API_Initialize();
139
140  _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING );
141
142  /*
143   *  No threads should be created before this point!!!
144   *  _Thread_Executing and _Thread_Heir are not set.
145   *
146   *  At this point all API extensions are in place.  After the call to
147   *  _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set.
148   */
149  _Thread_Create_idle();
150
151  /*
152   *  Scheduling can properly occur now as long as we avoid dispatching.
153   */
154}
155
156static void rtems_initialize_before_drivers(void)
157{
158  #ifdef RTEMS_DRVMGR_STARTUP
159  _DRV_Manager_initialization();
160  #endif
161
162  #if defined(RTEMS_MULTIPROCESSING)
163    _MPCI_Create_server();
164  #endif
165}
166
167static void rtems_initialize_device_drivers(void)
168{
169  /*
170   *  Initialize all the device drivers and initialize the MPCI layer.
171   *
172   *  NOTE:  The MPCI may be build upon a device driver.
173   */
174
175  #ifdef RTEMS_DRVMGR_STARTUP
176  /* BSPs has already registered their "root bus" driver in the
177   * bsp_predriver hook or so.
178   *
179   * Init Drivers to Level 1, constraints:
180   *   - Interrupts and system clock timer does not work.
181   *   - malloc() work, however other memory services may not
182   *     have been initialized yet.
183   *   - initializes most basic stuff
184   *
185   * Typical setup in Level 1:
186   *   - Find most devices in system, do PCI scan and configuration.
187   *   - Reset hardware if needed.
188   *   - Install IRQ driver
189   *   - Install Timer driver
190   *   - Install console driver and debug printk()
191   *   - Install extra memory.
192   */
193  _DRV_Manager_init_level(1);
194  bsp_driver_level_hook(1);
195  #endif
196
197  /* Initialize I/O drivers.
198   *
199   * Driver Manager note:
200   * All drivers may not be registered yet. Drivers will dynamically
201   * be initialized when registered in level 2,3 and 4.
202   */
203  _IO_Initialize_all_drivers();
204
205  #ifdef RTEMS_DRVMGR_STARTUP
206  /* Init Drivers to Level 2, constraints:
207   *  - Interrupts can be registered and enabled.
208   *  - System Clock is running
209   *  - Console may be used.
210   *
211   * This is typically where drivers are initialized
212   * for the first time.
213   */
214  _DRV_Manager_init_level(2);
215  bsp_driver_level_hook(2);
216
217  /* Init Drivers to Level 3
218   *
219   * This is typically where normal drivers are initialized
220   * for the second time, they may depend on other drivers
221   * API inited in level 2
222   */
223  _DRV_Manager_init_level(3);
224  bsp_driver_level_hook(3);
225
226  /* Init Drivers to Level 4,
227   * Init drivers that depend on services initialized in Level 3
228   */
229  _DRV_Manager_init_level(4);
230  bsp_driver_level_hook(4);
231  #endif
232
233  #if defined(RTEMS_MULTIPROCESSING)
234    if ( _System_state_Is_multiprocessing ) {
235      _MPCI_Initialization();
236      _MPCI_Internal_packets_Send_process_packet(
237        MPCI_PACKETS_SYSTEM_VERIFY
238      );
239    }
240  #endif
241
242  /*
243   *  Run the APIs and BSPs postdriver hooks.
244   *
245   *  The API extensions are supposed to create user initialization tasks.
246   */
247  _API_extensions_Run_postdriver();
248}
249
250RTEMS_LINKER_ROSET( _Sysinit, rtems_sysinit_item );
251
252RTEMS_SYSINIT_ITEM(
253  rtems_initialize_data_structures,
254  RTEMS_SYSINIT_DATA_STRUCTURES,
255  RTEMS_SYSINIT_ORDER_MIDDLE
256);
257
258RTEMS_SYSINIT_ITEM(
259  rtems_initialize_before_drivers,
260  RTEMS_SYSINIT_BEFORE_DRIVERS,
261  RTEMS_SYSINIT_ORDER_MIDDLE
262);
263
264RTEMS_SYSINIT_ITEM(
265  rtems_initialize_device_drivers,
266  RTEMS_SYSINIT_DEVICE_DRIVERS,
267  RTEMS_SYSINIT_ORDER_MIDDLE
268);
269
270void rtems_initialize_executive(void)
271{
272  const volatile rtems_sysinit_item *cur = RTEMS_LINKER_SET_BEGIN(_Sysinit );
273  const volatile rtems_sysinit_item *end = RTEMS_LINKER_SET_END( _Sysinit );
274
275  /* Invoke the registered system initialization handlers */
276  while ( cur != end ) {
277    ( *cur->handler )();
278    ++cur;
279  }
280
281  _System_state_Set( SYSTEM_STATE_UP );
282
283  _SMP_Request_start_multitasking();
284
285  _Thread_Start_multitasking();
286
287  /*******************************************************************
288   *******************************************************************
289   *******************************************************************
290   ******                 APPLICATION RUNS HERE                 ******
291   ******              THE FUNCTION NEVER RETURNS               ******
292   *******************************************************************
293   *******************************************************************
294   *******************************************************************/
295}
Note: See TracBrowser for help on using the repository browser.