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 | #include <rtems/config.h> |
---|
23 | #include <rtems/extensionimpl.h> |
---|
24 | #include <rtems/init.h> |
---|
25 | #include <rtems/ioimpl.h> |
---|
26 | #include <rtems/sysinit.h> |
---|
27 | #include <rtems/score/sysstate.h> |
---|
28 | |
---|
29 | #include <rtems/score/copyrt.h> |
---|
30 | #include <rtems/score/heap.h> |
---|
31 | #include <rtems/score/interr.h> |
---|
32 | #include <rtems/score/isr.h> |
---|
33 | #include <rtems/score/percpudata.h> |
---|
34 | #include <rtems/score/priority.h> |
---|
35 | #include <rtems/score/schedulerimpl.h> |
---|
36 | #include <rtems/score/smpimpl.h> |
---|
37 | #include <rtems/score/timecounter.h> |
---|
38 | #include <rtems/score/threadimpl.h> |
---|
39 | #include <rtems/score/todimpl.h> |
---|
40 | #include <rtems/score/wkspace.h> |
---|
41 | |
---|
42 | const char _Copyright_Notice[] = |
---|
43 | "COPYRIGHT (c) 1989-2008.\n\ |
---|
44 | On-Line Applications Research Corporation (OAR).\n"; |
---|
45 | |
---|
46 | static Objects_Information * |
---|
47 | _Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ]; |
---|
48 | |
---|
49 | static Objects_Information *_RTEMS_Objects[ OBJECTS_RTEMS_CLASSES_LAST + 1 ]; |
---|
50 | |
---|
51 | static Objects_Information *_POSIX_Objects[ OBJECTS_POSIX_CLASSES_LAST + 1 ]; |
---|
52 | |
---|
53 | Objects_Information ** const |
---|
54 | _Objects_Information_table[ OBJECTS_APIS_LAST + 1 ] = { |
---|
55 | NULL, |
---|
56 | &_Internal_Objects[ 0 ], |
---|
57 | &_RTEMS_Objects[ 0 ], |
---|
58 | &_POSIX_Objects[ 0 ] |
---|
59 | }; |
---|
60 | |
---|
61 | RTEMS_LINKER_RWSET( |
---|
62 | _Per_CPU_Data, |
---|
63 | #if defined(RTEMS_SMP) |
---|
64 | /* |
---|
65 | * In SMP configurations, prevent false cache line sharing of per-processor |
---|
66 | * data with a proper alignment. |
---|
67 | */ |
---|
68 | RTEMS_ALIGNED( CPU_CACHE_LINE_BYTES ) |
---|
69 | #endif |
---|
70 | char |
---|
71 | ); |
---|
72 | |
---|
73 | static void rtems_initialize_data_structures(void) |
---|
74 | { |
---|
75 | /* |
---|
76 | * Dispatching and interrupts are disabled until the end of the |
---|
77 | * initialization sequence. This prevents an inadvertent context |
---|
78 | * switch before the executive is initialized. |
---|
79 | * |
---|
80 | * WARNING: Interrupts should have been disabled by the BSP and |
---|
81 | * are disabled by boot_card(). |
---|
82 | */ |
---|
83 | |
---|
84 | /* |
---|
85 | * Initialize any target architecture specific support as early as possible |
---|
86 | */ |
---|
87 | _CPU_Initialize(); |
---|
88 | |
---|
89 | _Thread_Dispatch_initialization(); |
---|
90 | |
---|
91 | _ISR_Handler_initialization(); |
---|
92 | |
---|
93 | _Thread_Handler_initialization(); |
---|
94 | |
---|
95 | _Scheduler_Handler_initialization(); |
---|
96 | |
---|
97 | _SMP_Handler_initialize(); |
---|
98 | } |
---|
99 | |
---|
100 | RTEMS_LINKER_ROSET( _Sysinit, rtems_sysinit_item ); |
---|
101 | |
---|
102 | RTEMS_SYSINIT_ITEM( |
---|
103 | rtems_initialize_data_structures, |
---|
104 | RTEMS_SYSINIT_DATA_STRUCTURES, |
---|
105 | RTEMS_SYSINIT_ORDER_MIDDLE |
---|
106 | ); |
---|
107 | |
---|
108 | /* |
---|
109 | * No threads should be created before this point!!! |
---|
110 | * _Thread_Executing and _Thread_Heir are not set. |
---|
111 | * |
---|
112 | * At this point all API extensions are in place. After the call to |
---|
113 | * _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set. |
---|
114 | * |
---|
115 | * Scheduling can properly occur afterwards as long as we avoid dispatching. |
---|
116 | */ |
---|
117 | RTEMS_SYSINIT_ITEM( |
---|
118 | _Thread_Create_idle, |
---|
119 | RTEMS_SYSINIT_IDLE_THREADS, |
---|
120 | RTEMS_SYSINIT_ORDER_MIDDLE |
---|
121 | ); |
---|
122 | |
---|
123 | /* Initialize I/O drivers. |
---|
124 | * |
---|
125 | * Driver Manager note: |
---|
126 | * All drivers may not be registered yet. Drivers will dynamically |
---|
127 | * be initialized when registered in level 2,3 and 4. |
---|
128 | */ |
---|
129 | RTEMS_SYSINIT_ITEM( |
---|
130 | _IO_Initialize_all_drivers, |
---|
131 | RTEMS_SYSINIT_DEVICE_DRIVERS, |
---|
132 | RTEMS_SYSINIT_ORDER_MIDDLE |
---|
133 | ); |
---|
134 | |
---|
135 | void rtems_initialize_executive(void) |
---|
136 | { |
---|
137 | const rtems_sysinit_item *item; |
---|
138 | |
---|
139 | /* Invoke the registered system initialization handlers */ |
---|
140 | RTEMS_LINKER_SET_FOREACH( _Sysinit, item ) { |
---|
141 | ( *item->handler )(); |
---|
142 | } |
---|
143 | |
---|
144 | _System_state_Set( SYSTEM_STATE_UP ); |
---|
145 | |
---|
146 | _SMP_Request_start_multitasking(); |
---|
147 | |
---|
148 | _Thread_Start_multitasking(); |
---|
149 | |
---|
150 | /******************************************************************* |
---|
151 | ******************************************************************* |
---|
152 | ******************************************************************* |
---|
153 | ****** APPLICATION RUNS HERE ****** |
---|
154 | ****** THE FUNCTION NEVER RETURNS ****** |
---|
155 | ******************************************************************* |
---|
156 | ******************************************************************* |
---|
157 | *******************************************************************/ |
---|
158 | } |
---|