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 is defined so all of the super core |
---|
24 | * data will be included in this object file. |
---|
25 | */ |
---|
26 | |
---|
27 | #define SCORE_INIT |
---|
28 | |
---|
29 | #include <rtems/system.h> |
---|
30 | #include <rtems/config.h> |
---|
31 | #include <rtems/extensionimpl.h> |
---|
32 | #include <rtems/init.h> |
---|
33 | #include <rtems/sysinit.h> |
---|
34 | #include <rtems/score/sysstate.h> |
---|
35 | |
---|
36 | #include <rtems/score/apiext.h> |
---|
37 | #include <rtems/score/apimutex.h> |
---|
38 | #include <rtems/score/copyrt.h> |
---|
39 | #include <rtems/score/heap.h> |
---|
40 | #include <rtems/score/interr.h> |
---|
41 | #include <rtems/score/isr.h> |
---|
42 | #include <rtems/score/priority.h> |
---|
43 | #include <rtems/score/schedulerimpl.h> |
---|
44 | #include <rtems/score/smpimpl.h> |
---|
45 | #include <rtems/score/timecounter.h> |
---|
46 | #include <rtems/score/threadimpl.h> |
---|
47 | #include <rtems/score/todimpl.h> |
---|
48 | #include <rtems/score/watchdogimpl.h> |
---|
49 | #include <rtems/score/wkspace.h> |
---|
50 | |
---|
51 | static Objects_Information * |
---|
52 | _Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ]; |
---|
53 | |
---|
54 | static Objects_Information *_RTEMS_Objects[ OBJECTS_RTEMS_CLASSES_LAST + 1 ]; |
---|
55 | |
---|
56 | static Objects_Information *_POSIX_Objects[ OBJECTS_POSIX_CLASSES_LAST + 1 ]; |
---|
57 | |
---|
58 | Objects_Information **_Objects_Information_table[ OBJECTS_APIS_LAST + 1 ] = { |
---|
59 | NULL, |
---|
60 | &_Internal_Objects[ 0 ], |
---|
61 | &_RTEMS_Objects[ 0 ], |
---|
62 | &_POSIX_Objects[ 0 ] |
---|
63 | }; |
---|
64 | |
---|
65 | static void rtems_initialize_data_structures(void) |
---|
66 | { |
---|
67 | /* |
---|
68 | * Dispatching and interrupts are disabled until the end of the |
---|
69 | * initialization sequence. This prevents an inadvertent context |
---|
70 | * switch before the executive is initialized. |
---|
71 | * |
---|
72 | * WARNING: Interrupts should have been disabled by the BSP and |
---|
73 | * are disabled by boot_card(). |
---|
74 | */ |
---|
75 | |
---|
76 | /* |
---|
77 | * Initialize any target architecture specific support as early as possible |
---|
78 | */ |
---|
79 | _CPU_Initialize(); |
---|
80 | |
---|
81 | _Thread_Dispatch_initialization(); |
---|
82 | |
---|
83 | _ISR_Handler_initialization(); |
---|
84 | |
---|
85 | _API_Mutex_Initialization( 2 ); |
---|
86 | _API_Mutex_Allocate( &_RTEMS_Allocator_Mutex ); |
---|
87 | _API_Mutex_Allocate( &_Once_Mutex ); |
---|
88 | |
---|
89 | _Watchdog_Handler_initialization(); |
---|
90 | |
---|
91 | _Thread_Handler_initialization(); |
---|
92 | |
---|
93 | _Scheduler_Handler_initialization(); |
---|
94 | |
---|
95 | _SMP_Handler_initialize(); |
---|
96 | } |
---|
97 | |
---|
98 | static void rtems_initialize_device_drivers(void) |
---|
99 | { |
---|
100 | /* |
---|
101 | * Initialize all the device drivers and initialize the MPCI layer. |
---|
102 | * |
---|
103 | * NOTE: The MPCI may be build upon a device driver. |
---|
104 | */ |
---|
105 | |
---|
106 | /* Initialize I/O drivers. |
---|
107 | * |
---|
108 | * Driver Manager note: |
---|
109 | * All drivers may not be registered yet. Drivers will dynamically |
---|
110 | * be initialized when registered in level 2,3 and 4. |
---|
111 | */ |
---|
112 | _IO_Initialize_all_drivers(); |
---|
113 | |
---|
114 | /* |
---|
115 | * Run the APIs and BSPs postdriver hooks. |
---|
116 | * |
---|
117 | * The API extensions are supposed to create user initialization tasks. |
---|
118 | */ |
---|
119 | _API_extensions_Run_postdriver(); |
---|
120 | } |
---|
121 | |
---|
122 | RTEMS_LINKER_ROSET( _Sysinit, rtems_sysinit_item ); |
---|
123 | |
---|
124 | RTEMS_SYSINIT_ITEM( |
---|
125 | rtems_initialize_data_structures, |
---|
126 | RTEMS_SYSINIT_DATA_STRUCTURES, |
---|
127 | RTEMS_SYSINIT_ORDER_MIDDLE |
---|
128 | ); |
---|
129 | |
---|
130 | /* |
---|
131 | * No threads should be created before this point!!! |
---|
132 | * _Thread_Executing and _Thread_Heir are not set. |
---|
133 | * |
---|
134 | * At this point all API extensions are in place. After the call to |
---|
135 | * _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set. |
---|
136 | * |
---|
137 | * Scheduling can properly occur afterwards as long as we avoid dispatching. |
---|
138 | */ |
---|
139 | RTEMS_SYSINIT_ITEM( |
---|
140 | _Thread_Create_idle, |
---|
141 | RTEMS_SYSINIT_IDLE_THREADS, |
---|
142 | RTEMS_SYSINIT_ORDER_MIDDLE |
---|
143 | ); |
---|
144 | |
---|
145 | RTEMS_SYSINIT_ITEM( |
---|
146 | rtems_initialize_device_drivers, |
---|
147 | RTEMS_SYSINIT_DEVICE_DRIVERS, |
---|
148 | RTEMS_SYSINIT_ORDER_MIDDLE |
---|
149 | ); |
---|
150 | |
---|
151 | void rtems_initialize_executive(void) |
---|
152 | { |
---|
153 | const volatile rtems_sysinit_item *cur = RTEMS_LINKER_SET_BEGIN(_Sysinit ); |
---|
154 | const volatile rtems_sysinit_item *end = RTEMS_LINKER_SET_END( _Sysinit ); |
---|
155 | |
---|
156 | /* Invoke the registered system initialization handlers */ |
---|
157 | while ( cur != end ) { |
---|
158 | ( *cur->handler )(); |
---|
159 | ++cur; |
---|
160 | } |
---|
161 | |
---|
162 | _System_state_Set( SYSTEM_STATE_UP ); |
---|
163 | |
---|
164 | _SMP_Request_start_multitasking(); |
---|
165 | |
---|
166 | _Thread_Start_multitasking(); |
---|
167 | |
---|
168 | /******************************************************************* |
---|
169 | ******************************************************************* |
---|
170 | ******************************************************************* |
---|
171 | ****** APPLICATION RUNS HERE ****** |
---|
172 | ****** THE FUNCTION NEVER RETURNS ****** |
---|
173 | ******************************************************************* |
---|
174 | ******************************************************************* |
---|
175 | *******************************************************************/ |
---|
176 | } |
---|