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