1 | /* |
---|
2 | * Initialization Manager |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * All rights assigned to U.S. Government, 1994. |
---|
7 | * |
---|
8 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
9 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
10 | * notice must appear in all copies of this file and its derivatives. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | /* |
---|
16 | * INIT is defined so all of the data will be included in this |
---|
17 | * file. |
---|
18 | */ |
---|
19 | |
---|
20 | #define INIT |
---|
21 | |
---|
22 | #include <rtems/system.h> |
---|
23 | #include <rtems/config.h> |
---|
24 | #include <rtems/copyrt.h> |
---|
25 | #include <rtems/clock.h> |
---|
26 | #include <rtems/tasks.h> |
---|
27 | #include <rtems/debug.h> |
---|
28 | #include <rtems/dpmem.h> |
---|
29 | #include <rtems/event.h> |
---|
30 | #include <rtems/extension.h> |
---|
31 | #include <rtems/fatal.h> |
---|
32 | #include <rtems/heap.h> |
---|
33 | #include <rtems/init.h> |
---|
34 | #include <rtems/intthrd.h> |
---|
35 | #include <rtems/isr.h> |
---|
36 | #include <rtems/intr.h> |
---|
37 | #include <rtems/io.h> |
---|
38 | #include <rtems/message.h> |
---|
39 | #include <rtems/mp.h> |
---|
40 | #include <rtems/mpci.h> |
---|
41 | #include <rtems/part.h> |
---|
42 | #include <rtems/priority.h> |
---|
43 | #include <rtems/ratemon.h> |
---|
44 | #include <rtems/region.h> |
---|
45 | #include <rtems/sem.h> |
---|
46 | #include <rtems/signal.h> |
---|
47 | #include <rtems/sysstate.h> |
---|
48 | #include <rtems/thread.h> |
---|
49 | #include <rtems/timer.h> |
---|
50 | #include <rtems/tod.h> |
---|
51 | #include <rtems/userext.h> |
---|
52 | #include <rtems/watchdog.h> |
---|
53 | #include <rtems/wkspace.h> |
---|
54 | |
---|
55 | #include <rtems/sptables.h> |
---|
56 | |
---|
57 | /*PAGE |
---|
58 | * |
---|
59 | * rtems_initialize_executive |
---|
60 | * |
---|
61 | * This directive initializes all the kernels data structures |
---|
62 | * to the states necessary for the kernel to begin execution. All |
---|
63 | * include files that contain global variable definitions should be |
---|
64 | * included in this file. The system threads and initialization threads |
---|
65 | * are created and started by this routine. This routine then |
---|
66 | * initiates multithreading. |
---|
67 | * |
---|
68 | * Input parameters: |
---|
69 | * configuration_table - pointer to the user's configuration table |
---|
70 | * cpu_table - pointer to the user's CPU configuration table |
---|
71 | * |
---|
72 | * Output parameters: NONE |
---|
73 | */ |
---|
74 | |
---|
75 | struct months { |
---|
76 | unsigned32 months[2][13]; |
---|
77 | }; |
---|
78 | |
---|
79 | void rtems_initialize_executive( |
---|
80 | rtems_configuration_table *configuration_table, |
---|
81 | rtems_cpu_table *cpu_table |
---|
82 | ) |
---|
83 | { |
---|
84 | rtems_interrupt_level bsp_level; |
---|
85 | |
---|
86 | bsp_level = rtems_initialize_executive_early(configuration_table, cpu_table); |
---|
87 | rtems_initialize_executive_late( bsp_level ); |
---|
88 | } |
---|
89 | |
---|
90 | rtems_interrupt_level rtems_initialize_executive_early( |
---|
91 | rtems_configuration_table *configuration_table, |
---|
92 | rtems_cpu_table *cpu_table |
---|
93 | ) |
---|
94 | { |
---|
95 | rtems_interrupt_level bsp_level; |
---|
96 | rtems_multiprocessing_table *multiprocessing_table; |
---|
97 | |
---|
98 | /* |
---|
99 | * Dispatching and interrupts are disabled until the end of the |
---|
100 | * initialization sequence. This prevents an inadvertent context |
---|
101 | * switch before the executive is initialized. |
---|
102 | */ |
---|
103 | |
---|
104 | _ISR_Disable( bsp_level ); |
---|
105 | |
---|
106 | _System_state_Set( SYSTEM_STATE_BEFORE_INITIALIZATION ); |
---|
107 | |
---|
108 | _CPU_Initialize( cpu_table, _Thread_Dispatch ); |
---|
109 | |
---|
110 | /* |
---|
111 | * Do this as early as possible to insure no debugging output |
---|
112 | * is even attempted to be printed. |
---|
113 | */ |
---|
114 | |
---|
115 | _Debug_Manager_initialization(); |
---|
116 | |
---|
117 | multiprocessing_table = configuration_table->User_multiprocessing_table; |
---|
118 | if ( multiprocessing_table == NULL ) |
---|
119 | multiprocessing_table = |
---|
120 | (void *) &_Configuration_Default_multiprocessing_table; |
---|
121 | |
---|
122 | _Configuration_Handler_initialization( |
---|
123 | configuration_table, |
---|
124 | multiprocessing_table, |
---|
125 | multiprocessing_table->User_mpci_table |
---|
126 | ); |
---|
127 | |
---|
128 | _Attributes_Handler_initialization(); |
---|
129 | |
---|
130 | _Thread_Dispatch_initialization(); |
---|
131 | |
---|
132 | _User_extensions_Handler_initialization( |
---|
133 | configuration_table->User_extension_table |
---|
134 | ); |
---|
135 | |
---|
136 | _Workspace_Handler_initialization( |
---|
137 | (void *)configuration_table->work_space_start, |
---|
138 | configuration_table->work_space_size |
---|
139 | ); |
---|
140 | |
---|
141 | _ISR_Handler_initialization(); |
---|
142 | |
---|
143 | _Objects_Handler_initialization( |
---|
144 | multiprocessing_table->node, |
---|
145 | multiprocessing_table->maximum_global_objects |
---|
146 | ); |
---|
147 | |
---|
148 | _Priority_Handler_initialization(); |
---|
149 | |
---|
150 | _Watchdog_Handler_initialization(); |
---|
151 | |
---|
152 | _TOD_Handler_initialization( configuration_table->microseconds_per_tick ); |
---|
153 | |
---|
154 | _Thread_Handler_initialization( |
---|
155 | configuration_table->maximum_tasks, |
---|
156 | configuration_table->ticks_per_timeslice, |
---|
157 | multiprocessing_table->maximum_proxies |
---|
158 | ); |
---|
159 | |
---|
160 | _MPCI_Handler_initialization(); |
---|
161 | |
---|
162 | /* MANAGERS */ |
---|
163 | |
---|
164 | _Interrupt_Manager_initialization(); |
---|
165 | |
---|
166 | _Multiprocessing_Manager_initialization(); |
---|
167 | |
---|
168 | _Timer_Manager_initialization( configuration_table->maximum_timers ); |
---|
169 | |
---|
170 | _Extension_Manager_initialization( configuration_table->maximum_extensions ); |
---|
171 | |
---|
172 | _IO_Manager_initialization( |
---|
173 | configuration_table->Device_driver_table, |
---|
174 | configuration_table->number_of_device_drivers |
---|
175 | ); |
---|
176 | |
---|
177 | _Event_Manager_initialization(); |
---|
178 | |
---|
179 | _Message_queue_Manager_initialization( |
---|
180 | configuration_table->maximum_message_queues |
---|
181 | ); |
---|
182 | |
---|
183 | _Semaphore_Manager_initialization( |
---|
184 | configuration_table->maximum_semaphores |
---|
185 | ); |
---|
186 | |
---|
187 | _Partition_Manager_initialization( |
---|
188 | configuration_table->maximum_partitions |
---|
189 | ); |
---|
190 | |
---|
191 | _Region_Manager_initialization( configuration_table->maximum_regions ); |
---|
192 | |
---|
193 | _Dual_ported_memory_Manager_initialization( |
---|
194 | configuration_table->maximum_ports |
---|
195 | ); |
---|
196 | |
---|
197 | _Rate_monotonic_Manager_initialization( |
---|
198 | configuration_table->maximum_periods |
---|
199 | ); |
---|
200 | |
---|
201 | _Internal_threads_Initialization(); |
---|
202 | |
---|
203 | if ( cpu_table->pretasking_hook ) |
---|
204 | (*cpu_table->pretasking_hook)(); |
---|
205 | |
---|
206 | _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING ); |
---|
207 | |
---|
208 | return bsp_level; |
---|
209 | } |
---|
210 | |
---|
211 | void rtems_initialize_executive_late( |
---|
212 | rtems_interrupt_level bsp_level |
---|
213 | ) |
---|
214 | { |
---|
215 | |
---|
216 | _System_state_Set( SYSTEM_STATE_BEGIN_MULTITASKING ); |
---|
217 | |
---|
218 | _Thread_Start_multitasking( |
---|
219 | _Internal_threads_System_initialization_thread, |
---|
220 | _Internal_threads_Idle_thread |
---|
221 | ); |
---|
222 | |
---|
223 | /* |
---|
224 | * Restore the interrupt level to what the BSP had. Technically, |
---|
225 | * this is unnecessary since the BSP should have all interrupts |
---|
226 | * disabled when rtems_initialize_executive is invoked. But this keeps |
---|
227 | * the ISR Disable/Enable calls paired. |
---|
228 | */ |
---|
229 | |
---|
230 | _ISR_Enable( bsp_level ); |
---|
231 | } |
---|
232 | |
---|
233 | /*PAGE |
---|
234 | * |
---|
235 | * rtems_shutdown_executive |
---|
236 | * |
---|
237 | * This kernel routine shutdowns the executive. It halts multitasking |
---|
238 | * and returns control to the application execution "thread" which |
---|
239 | * initialially invoked the rtems_initialize_executive directive. |
---|
240 | * |
---|
241 | * Input parameters: NONE |
---|
242 | * |
---|
243 | * Output parameters: NONE |
---|
244 | */ |
---|
245 | |
---|
246 | void rtems_shutdown_executive( |
---|
247 | unsigned32 result |
---|
248 | ) |
---|
249 | { |
---|
250 | _Thread_Stop_multitasking(); |
---|
251 | } |
---|