source: rtems/cpukit/sapi/src/exinit.c @ 6bf44a5

5
Last change on this file since 6bf44a5 was 6bf44a5, checked in by Sebastian Huber <sebastian.huber@…>, on 01/26/16 at 08:28:11

Use linker set for driver manager initialization

Update #2408.

  • Property mode set to 100644
File size: 5.9 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/heap.h>
41#include <rtems/score/interr.h>
42#include <rtems/score/isr.h>
43#include <rtems/score/priority.h>
44#include <rtems/score/schedulerimpl.h>
45#include <rtems/score/smpimpl.h>
46#include <rtems/score/timecounter.h>
47#include <rtems/score/threadimpl.h>
48#include <rtems/score/todimpl.h>
49#include <rtems/score/watchdogimpl.h>
50#include <rtems/score/wkspace.h>
51
52#include <rtems/sptables.h>
53
54static Objects_Information *
55_Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ];
56
57static Objects_Information *_RTEMS_Objects[ OBJECTS_RTEMS_CLASSES_LAST + 1 ];
58
59static Objects_Information *_POSIX_Objects[ OBJECTS_POSIX_CLASSES_LAST + 1 ];
60
61Objects_Information **_Objects_Information_table[ OBJECTS_APIS_LAST + 1 ] = {
62  NULL,
63  &_Internal_Objects[ 0 ],
64  &_RTEMS_Objects[ 0 ],
65  &_POSIX_Objects[ 0 ]
66};
67
68static void rtems_initialize_data_structures(void)
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   *  WARNING: Interrupts should have been disabled by the BSP and
76   *           are disabled by boot_card().
77   */
78
79  #if defined(RTEMS_MULTIPROCESSING)
80    /*
81     *  Initialize the system state based on whether this is an MP system.
82     *  In an MP configuration, internally we view single processor
83     *  systems as a very restricted multiprocessor system.
84     */
85    _Configuration_MP_table = rtems_configuration_get_user_multiprocessing_table();
86
87    if ( _Configuration_MP_table == NULL ) {
88      _Configuration_MP_table =
89        (void *)&_Initialization_Default_multiprocessing_table;
90    } else {
91      _System_state_Is_multiprocessing = true;
92    }
93  #endif
94
95  /*
96   * Initialize any target architecture specific support as early as possible
97   */
98  _CPU_Initialize();
99
100  #if defined(RTEMS_MULTIPROCESSING)
101    _Objects_MP_Handler_early_initialization();
102  #endif
103
104  _Thread_Dispatch_initialization();
105
106  _ISR_Handler_initialization();
107
108  _API_Mutex_Initialization( 2 );
109  _API_Mutex_Allocate( &_RTEMS_Allocator_Mutex );
110  _API_Mutex_Allocate( &_Once_Mutex );
111
112  _Watchdog_Handler_initialization();
113
114  _Thread_Handler_initialization();
115
116  _Scheduler_Handler_initialization();
117
118  #if defined(RTEMS_MULTIPROCESSING)
119    _Objects_MP_Handler_initialization();
120    _MPCI_Handler_initialization( RTEMS_TIMEOUT );
121  #endif
122
123  _SMP_Handler_initialize();
124}
125
126static void rtems_initialize_before_drivers(void)
127{
128  #if defined(RTEMS_MULTIPROCESSING)
129    _MPCI_Create_server();
130  #endif
131}
132
133static void rtems_initialize_device_drivers(void)
134{
135  /*
136   *  Initialize all the device drivers and initialize the MPCI layer.
137   *
138   *  NOTE:  The MPCI may be build upon a device driver.
139   */
140
141  /* Initialize I/O drivers.
142   *
143   * Driver Manager note:
144   * All drivers may not be registered yet. Drivers will dynamically
145   * be initialized when registered in level 2,3 and 4.
146   */
147  _IO_Initialize_all_drivers();
148
149  #if defined(RTEMS_MULTIPROCESSING)
150    if ( _System_state_Is_multiprocessing ) {
151      _MPCI_Initialization();
152      _MPCI_Internal_packets_Send_process_packet(
153        MPCI_PACKETS_SYSTEM_VERIFY
154      );
155    }
156  #endif
157
158  /*
159   *  Run the APIs and BSPs postdriver hooks.
160   *
161   *  The API extensions are supposed to create user initialization tasks.
162   */
163  _API_extensions_Run_postdriver();
164}
165
166RTEMS_LINKER_ROSET( _Sysinit, rtems_sysinit_item );
167
168RTEMS_SYSINIT_ITEM(
169  rtems_initialize_data_structures,
170  RTEMS_SYSINIT_DATA_STRUCTURES,
171  RTEMS_SYSINIT_ORDER_MIDDLE
172);
173
174/*
175 *  No threads should be created before this point!!!
176 *  _Thread_Executing and _Thread_Heir are not set.
177 *
178 *  At this point all API extensions are in place.  After the call to
179 *  _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set.
180 *
181 *  Scheduling can properly occur afterwards as long as we avoid dispatching.
182 */
183RTEMS_SYSINIT_ITEM(
184  _Thread_Create_idle,
185  RTEMS_SYSINIT_IDLE_THREADS,
186  RTEMS_SYSINIT_ORDER_MIDDLE
187);
188
189RTEMS_SYSINIT_ITEM(
190  rtems_initialize_before_drivers,
191  RTEMS_SYSINIT_BEFORE_DRIVERS,
192  RTEMS_SYSINIT_ORDER_MIDDLE
193);
194
195RTEMS_SYSINIT_ITEM(
196  rtems_initialize_device_drivers,
197  RTEMS_SYSINIT_DEVICE_DRIVERS,
198  RTEMS_SYSINIT_ORDER_MIDDLE
199);
200
201void rtems_initialize_executive(void)
202{
203  const volatile rtems_sysinit_item *cur = RTEMS_LINKER_SET_BEGIN(_Sysinit );
204  const volatile rtems_sysinit_item *end = RTEMS_LINKER_SET_END( _Sysinit );
205
206  /* Invoke the registered system initialization handlers */
207  while ( cur != end ) {
208    ( *cur->handler )();
209    ++cur;
210  }
211
212  _System_state_Set( SYSTEM_STATE_UP );
213
214  _SMP_Request_start_multitasking();
215
216  _Thread_Start_multitasking();
217
218  /*******************************************************************
219   *******************************************************************
220   *******************************************************************
221   ******                 APPLICATION RUNS HERE                 ******
222   ******              THE FUNCTION NEVER RETURNS               ******
223   *******************************************************************
224   *******************************************************************
225   *******************************************************************/
226}
Note: See TracBrowser for help on using the repository browser.