[ac7d5ef0] | 1 | /* |
---|
| 2 | * Initialization Manager |
---|
| 3 | * |
---|
[08311cc3] | 4 | * COPYRIGHT (c) 1989-1999. |
---|
[ac7d5ef0] | 5 | * On-Line Applications Research Corporation (OAR). |
---|
| 6 | * |
---|
[98e4ebf5] | 7 | * The license and distribution terms for this file may be |
---|
| 8 | * found in the file LICENSE in this distribution or at |
---|
[2ba508b] | 9 | * http://www.rtems.com/license/LICENSE. |
---|
[ac7d5ef0] | 10 | * |
---|
| 11 | * $Id$ |
---|
| 12 | */ |
---|
| 13 | |
---|
[16351f7a] | 14 | #if HAVE_CONFIG_H |
---|
| 15 | #include "config.h" |
---|
| 16 | #endif |
---|
| 17 | |
---|
[ac7d5ef0] | 18 | /* |
---|
[8486081] | 19 | * SCORE_INIT and SAPI_INIT are defined so all of the super core and |
---|
[c627b2a3] | 20 | * super API data will be included in this object file. |
---|
[ac7d5ef0] | 21 | */ |
---|
| 22 | |
---|
[c627b2a3] | 23 | #define SAPI_INIT |
---|
| 24 | #define SCORE_INIT |
---|
[ac7d5ef0] | 25 | |
---|
| 26 | #include <rtems/system.h> |
---|
| 27 | #include <rtems/config.h> |
---|
| 28 | #include <rtems/debug.h> |
---|
| 29 | #include <rtems/extension.h> |
---|
| 30 | #include <rtems/fatal.h> |
---|
| 31 | #include <rtems/init.h> |
---|
| 32 | #include <rtems/io.h> |
---|
[5e9b32b] | 33 | #include <rtems/score/sysstate.h> |
---|
[ac7d5ef0] | 34 | |
---|
[5e9b32b] | 35 | #include <rtems/score/apiext.h> |
---|
[a2a8c5b] | 36 | #include <rtems/score/apimutex.h> |
---|
[5e9b32b] | 37 | #include <rtems/score/copyrt.h> |
---|
| 38 | #include <rtems/score/heap.h> |
---|
| 39 | #include <rtems/score/interr.h> |
---|
| 40 | #include <rtems/score/isr.h> |
---|
[97e2729d] | 41 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[5e9b32b] | 42 | #include <rtems/score/mpci.h> |
---|
[97e2729d] | 43 | #endif |
---|
[5e9b32b] | 44 | #include <rtems/score/priority.h> |
---|
| 45 | #include <rtems/score/thread.h> |
---|
| 46 | #include <rtems/score/tod.h> |
---|
| 47 | #include <rtems/score/userext.h> |
---|
| 48 | #include <rtems/score/watchdog.h> |
---|
| 49 | #include <rtems/score/wkspace.h> |
---|
[3a4ae6c] | 50 | |
---|
[ac7d5ef0] | 51 | #include <rtems/sptables.h> |
---|
| 52 | |
---|
[c627b2a3] | 53 | |
---|
[3a4ae6c] | 54 | #include <rtems/rtems/rtemsapi.h> |
---|
[c627b2a3] | 55 | #ifdef RTEMS_POSIX_API |
---|
| 56 | #include <rtems/posix/posixapi.h> |
---|
| 57 | #endif |
---|
[352c9b2] | 58 | #ifdef RTEMS_ITRON_API |
---|
| 59 | #include <rtems/itron/itronapi.h> |
---|
| 60 | #endif |
---|
| 61 | |
---|
[0577ec1d] | 62 | Objects_Information *_Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ]; |
---|
[3a4ae6c] | 63 | |
---|
[ac7d5ef0] | 64 | /*PAGE |
---|
| 65 | * |
---|
| 66 | * rtems_initialize_executive |
---|
| 67 | * |
---|
| 68 | * This directive initializes all the kernels data structures |
---|
| 69 | * to the states necessary for the kernel to begin execution. All |
---|
| 70 | * include files that contain global variable definitions should be |
---|
| 71 | * included in this file. The system threads and initialization threads |
---|
| 72 | * are created and started by this routine. This routine then |
---|
| 73 | * initiates multithreading. |
---|
| 74 | * |
---|
| 75 | * Input parameters: |
---|
| 76 | * configuration_table - pointer to the user's configuration table |
---|
| 77 | * cpu_table - pointer to the user's CPU configuration table |
---|
| 78 | * |
---|
| 79 | * Output parameters: NONE |
---|
| 80 | */ |
---|
| 81 | |
---|
| 82 | void rtems_initialize_executive( |
---|
| 83 | rtems_configuration_table *configuration_table, |
---|
| 84 | rtems_cpu_table *cpu_table |
---|
| 85 | ) |
---|
| 86 | { |
---|
| 87 | rtems_interrupt_level bsp_level; |
---|
| 88 | |
---|
| 89 | bsp_level = rtems_initialize_executive_early(configuration_table, cpu_table); |
---|
| 90 | rtems_initialize_executive_late( bsp_level ); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | rtems_interrupt_level rtems_initialize_executive_early( |
---|
| 94 | rtems_configuration_table *configuration_table, |
---|
| 95 | rtems_cpu_table *cpu_table |
---|
| 96 | ) |
---|
| 97 | { |
---|
| 98 | rtems_interrupt_level bsp_level; |
---|
| 99 | rtems_multiprocessing_table *multiprocessing_table; |
---|
| 100 | |
---|
| 101 | /* |
---|
| 102 | * Dispatching and interrupts are disabled until the end of the |
---|
| 103 | * initialization sequence. This prevents an inadvertent context |
---|
| 104 | * switch before the executive is initialized. |
---|
| 105 | */ |
---|
| 106 | |
---|
| 107 | _ISR_Disable( bsp_level ); |
---|
| 108 | |
---|
[9a11e1f] | 109 | if ( configuration_table == NULL ) |
---|
[3a4ae6c] | 110 | _Internal_error_Occurred( |
---|
| 111 | INTERNAL_ERROR_CORE, |
---|
| 112 | TRUE, |
---|
| 113 | INTERNAL_ERROR_NO_CONFIGURATION_TABLE |
---|
| 114 | ); |
---|
[ac7d5ef0] | 115 | |
---|
[3a4ae6c] | 116 | /* |
---|
| 117 | * Initialize the system state based on whether this is an MP system. |
---|
| 118 | */ |
---|
| 119 | |
---|
[97e2729d] | 120 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3a4ae6c] | 121 | multiprocessing_table = configuration_table->User_multiprocessing_table; |
---|
| 122 | |
---|
| 123 | _System_state_Handler_initialization( |
---|
| 124 | (multiprocessing_table) ? TRUE : FALSE |
---|
| 125 | ); |
---|
[97e2729d] | 126 | #else |
---|
| 127 | multiprocessing_table = NULL; |
---|
| 128 | |
---|
| 129 | _System_state_Handler_initialization( FALSE ); |
---|
| 130 | #endif |
---|
[ac7d5ef0] | 131 | |
---|
[88d594a] | 132 | /* |
---|
[3a4ae6c] | 133 | * Provided just for user convenience. |
---|
[88d594a] | 134 | */ |
---|
| 135 | |
---|
[3a4ae6c] | 136 | _Configuration_Table = configuration_table; |
---|
| 137 | _Configuration_MP_table = multiprocessing_table; |
---|
| 138 | |
---|
| 139 | /* |
---|
| 140 | * Internally we view single processor systems as a very restricted |
---|
| 141 | * multiprocessor system. |
---|
| 142 | */ |
---|
[88d594a] | 143 | |
---|
[ac7d5ef0] | 144 | if ( multiprocessing_table == NULL ) |
---|
[8486081] | 145 | multiprocessing_table = |
---|
[3a4ae6c] | 146 | (void *)&_Initialization_Default_multiprocessing_table; |
---|
[ac7d5ef0] | 147 | |
---|
[3a4ae6c] | 148 | if ( cpu_table == NULL ) |
---|
| 149 | _Internal_error_Occurred( |
---|
| 150 | INTERNAL_ERROR_CORE, |
---|
| 151 | TRUE, |
---|
| 152 | INTERNAL_ERROR_NO_CPU_TABLE |
---|
| 153 | ); |
---|
| 154 | |
---|
| 155 | _CPU_Initialize( cpu_table, _Thread_Dispatch ); |
---|
[ac7d5ef0] | 156 | |
---|
[3a4ae6c] | 157 | /* |
---|
| 158 | * Do this as early as possible to insure no debugging output |
---|
| 159 | * is even attempted to be printed. |
---|
| 160 | */ |
---|
| 161 | |
---|
| 162 | _Debug_Manager_initialization(); |
---|
[ac7d5ef0] | 163 | |
---|
[7af35da5] | 164 | _API_extensions_Initialization(); |
---|
| 165 | |
---|
[ac7d5ef0] | 166 | _Thread_Dispatch_initialization(); |
---|
| 167 | |
---|
| 168 | _Workspace_Handler_initialization( |
---|
| 169 | (void *)configuration_table->work_space_start, |
---|
| 170 | configuration_table->work_space_size |
---|
| 171 | ); |
---|
| 172 | |
---|
[0451b44] | 173 | _User_extensions_Handler_initialization( |
---|
| 174 | configuration_table->number_of_initial_extensions, |
---|
| 175 | configuration_table->User_extension_table |
---|
| 176 | ); |
---|
| 177 | |
---|
[ac7d5ef0] | 178 | _ISR_Handler_initialization(); |
---|
| 179 | |
---|
| 180 | _Objects_Handler_initialization( |
---|
| 181 | multiprocessing_table->node, |
---|
[3a4ae6c] | 182 | multiprocessing_table->maximum_nodes, |
---|
[ac7d5ef0] | 183 | multiprocessing_table->maximum_global_objects |
---|
| 184 | ); |
---|
| 185 | |
---|
[0577ec1d] | 186 | _Objects_Information_table[OBJECTS_INTERNAL_API] = _Internal_Objects; |
---|
| 187 | |
---|
[ac7d5ef0] | 188 | _Priority_Handler_initialization(); |
---|
| 189 | |
---|
| 190 | _Watchdog_Handler_initialization(); |
---|
| 191 | |
---|
| 192 | _TOD_Handler_initialization( configuration_table->microseconds_per_tick ); |
---|
| 193 | |
---|
| 194 | _Thread_Handler_initialization( |
---|
| 195 | configuration_table->ticks_per_timeslice, |
---|
[3a4ae6c] | 196 | configuration_table->maximum_extensions, |
---|
[ac7d5ef0] | 197 | multiprocessing_table->maximum_proxies |
---|
| 198 | ); |
---|
| 199 | |
---|
[97e2729d] | 200 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3a4ae6c] | 201 | _MPCI_Handler_initialization( |
---|
[18c5378] | 202 | multiprocessing_table->User_mpci_table, |
---|
| 203 | RTEMS_TIMEOUT |
---|
[3a4ae6c] | 204 | ); |
---|
[97e2729d] | 205 | #endif |
---|
[ac7d5ef0] | 206 | |
---|
[3a4ae6c] | 207 | /* MANAGERS */ |
---|
[ac7d5ef0] | 208 | |
---|
[0577ec1d] | 209 | _RTEMS_API_Initialize( configuration_table ); |
---|
| 210 | |
---|
[ac7d5ef0] | 211 | _Extension_Manager_initialization( configuration_table->maximum_extensions ); |
---|
| 212 | |
---|
| 213 | _IO_Manager_initialization( |
---|
| 214 | configuration_table->Device_driver_table, |
---|
[3a4ae6c] | 215 | configuration_table->number_of_device_drivers, |
---|
[059a3714] | 216 | configuration_table->maximum_drivers, |
---|
[3a4ae6c] | 217 | configuration_table->maximum_devices |
---|
[ac7d5ef0] | 218 | ); |
---|
| 219 | |
---|
[d4b44877] | 220 | #ifdef RTEMS_POSIX_API |
---|
| 221 | _POSIX_API_Initialize( configuration_table ); |
---|
| 222 | #endif |
---|
| 223 | |
---|
[352c9b2] | 224 | #ifdef RTEMS_ITRON_API |
---|
| 225 | _ITRON_API_Initialize( configuration_table ); |
---|
| 226 | #endif |
---|
| 227 | |
---|
[56d34e6] | 228 | _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING ); |
---|
| 229 | |
---|
| 230 | /* |
---|
[8486081] | 231 | * No threads should be created before this point!!! |
---|
[a2a8c5b] | 232 | * _Thread_Executing and _Thread_Heir are not set. |
---|
[56d34e6] | 233 | * |
---|
| 234 | * At this point all API extensions are in place. After the call to |
---|
[a2a8c5b] | 235 | * _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set. |
---|
[56d34e6] | 236 | */ |
---|
[3a4ae6c] | 237 | |
---|
[56d34e6] | 238 | _Thread_Create_idle(); |
---|
| 239 | |
---|
[a2a8c5b] | 240 | |
---|
| 241 | /* |
---|
| 242 | * Scheduling can properly occur now as long as we avoid dispatching. |
---|
| 243 | */ |
---|
| 244 | |
---|
| 245 | if ( cpu_table->pretasking_hook ) |
---|
| 246 | (*cpu_table->pretasking_hook)(); |
---|
| 247 | |
---|
[97e2729d] | 248 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[56d34e6] | 249 | _MPCI_Create_server(); |
---|
[97e2729d] | 250 | #endif |
---|
[ac7d5ef0] | 251 | |
---|
[389fa850] | 252 | /* |
---|
| 253 | * Run the API and BSPs predriver hook. |
---|
| 254 | */ |
---|
[8486081] | 255 | |
---|
[389fa850] | 256 | _API_extensions_Run_predriver(); |
---|
[8486081] | 257 | |
---|
[389fa850] | 258 | if ( _CPU_Table.predriver_hook ) |
---|
| 259 | (*_CPU_Table.predriver_hook)(); |
---|
[8486081] | 260 | |
---|
[389fa850] | 261 | /* |
---|
| 262 | * Initialize all the device drivers and initialize the MPCI layer. |
---|
| 263 | * |
---|
| 264 | * NOTE: The MPCI may be build upon a device driver. |
---|
| 265 | */ |
---|
[8486081] | 266 | |
---|
[389fa850] | 267 | _IO_Initialize_all_drivers(); |
---|
[8486081] | 268 | |
---|
[97e2729d] | 269 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[389fa850] | 270 | if ( _System_state_Is_multiprocessing ) { |
---|
| 271 | _MPCI_Initialization(); |
---|
[56d34e6] | 272 | _MPCI_Internal_packets_Send_process_packet( |
---|
| 273 | MPCI_PACKETS_SYSTEM_VERIFY |
---|
[389fa850] | 274 | ); |
---|
| 275 | } |
---|
[97e2729d] | 276 | #endif |
---|
[8486081] | 277 | |
---|
[389fa850] | 278 | /* |
---|
| 279 | * Run the APIs and BSPs postdriver hooks. |
---|
| 280 | * |
---|
| 281 | * The API extensions are supposed to create user initialization tasks. |
---|
| 282 | */ |
---|
[8486081] | 283 | |
---|
[389fa850] | 284 | _API_extensions_Run_postdriver(); |
---|
[8486081] | 285 | |
---|
[389fa850] | 286 | if ( _CPU_Table.postdriver_hook ) |
---|
| 287 | (*_CPU_Table.postdriver_hook)(); |
---|
| 288 | |
---|
[ac7d5ef0] | 289 | return bsp_level; |
---|
| 290 | } |
---|
| 291 | |
---|
| 292 | void rtems_initialize_executive_late( |
---|
| 293 | rtems_interrupt_level bsp_level |
---|
| 294 | ) |
---|
| 295 | { |
---|
| 296 | |
---|
| 297 | _System_state_Set( SYSTEM_STATE_BEGIN_MULTITASKING ); |
---|
| 298 | |
---|
[f972294d] | 299 | _Thread_Start_multitasking(); |
---|
[ac7d5ef0] | 300 | |
---|
| 301 | /* |
---|
| 302 | * Restore the interrupt level to what the BSP had. Technically, |
---|
| 303 | * this is unnecessary since the BSP should have all interrupts |
---|
| 304 | * disabled when rtems_initialize_executive is invoked. But this keeps |
---|
| 305 | * the ISR Disable/Enable calls paired. |
---|
| 306 | */ |
---|
| 307 | |
---|
| 308 | _ISR_Enable( bsp_level ); |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | /*PAGE |
---|
| 312 | * |
---|
| 313 | * rtems_shutdown_executive |
---|
| 314 | * |
---|
| 315 | * This kernel routine shutdowns the executive. It halts multitasking |
---|
| 316 | * and returns control to the application execution "thread" which |
---|
| 317 | * initialially invoked the rtems_initialize_executive directive. |
---|
| 318 | * |
---|
| 319 | * Input parameters: NONE |
---|
| 320 | * |
---|
| 321 | * Output parameters: NONE |
---|
| 322 | */ |
---|
| 323 | |
---|
| 324 | void rtems_shutdown_executive( |
---|
[8bd41178] | 325 | uint32_t result |
---|
[ac7d5ef0] | 326 | ) |
---|
| 327 | { |
---|
[eafd698] | 328 | if ( _System_state_Current != SYSTEM_STATE_SHUTDOWN ) { |
---|
| 329 | _System_state_Set( SYSTEM_STATE_SHUTDOWN ); |
---|
| 330 | _Thread_Stop_multitasking(); |
---|
| 331 | } |
---|
[ac7d5ef0] | 332 | } |
---|