/** * @file * * @brief Initialization Manager * * @ingroup ClassicRTEMS */ /* * COPYRIGHT (c) 1989-2014. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at * http://www.rtems.org/license/LICENSE. */ #if HAVE_CONFIG_H #include "config.h" #endif /* * SCORE_INIT and SAPI_INIT are defined so all of the super core and * super API data will be included in this object file. */ #define SAPI_INIT #define SCORE_INIT #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef RTEMS_DRVMGR_STARTUP #include #endif static Objects_Information * _Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ]; static Objects_Information *_RTEMS_Objects[ OBJECTS_RTEMS_CLASSES_LAST + 1 ]; static Objects_Information *_POSIX_Objects[ OBJECTS_POSIX_CLASSES_LAST + 1 ]; Objects_Information **_Objects_Information_table[ OBJECTS_APIS_LAST + 1 ] = { NULL, &_Internal_Objects[ 0 ], &_RTEMS_Objects[ 0 ], &_POSIX_Objects[ 0 ] }; static void rtems_initialize_data_structures(void) { /* * Dispatching and interrupts are disabled until the end of the * initialization sequence. This prevents an inadvertent context * switch before the executive is initialized. * * WARNING: Interrupts should have been disabled by the BSP and * are disabled by boot_card(). */ #if defined(RTEMS_MULTIPROCESSING) /* * Initialize the system state based on whether this is an MP system. * In an MP configuration, internally we view single processor * systems as a very restricted multiprocessor system. */ _Configuration_MP_table = rtems_configuration_get_user_multiprocessing_table(); if ( _Configuration_MP_table == NULL ) { _Configuration_MP_table = (void *)&_Initialization_Default_multiprocessing_table; } else { _System_state_Is_multiprocessing = true; } #endif /* * Initialize any target architecture specific support as early as possible */ _CPU_Initialize(); #if defined(RTEMS_MULTIPROCESSING) _Objects_MP_Handler_early_initialization(); #endif _Thread_Dispatch_initialization(); _User_extensions_Handler_initialization(); _ISR_Handler_initialization(); _API_Mutex_Initialization( 2 ); _API_Mutex_Allocate( &_RTEMS_Allocator_Mutex ); _API_Mutex_Allocate( &_Once_Mutex ); _Watchdog_Handler_initialization(); _Thread_Handler_initialization(); _Scheduler_Handler_initialization(); #if defined(RTEMS_MULTIPROCESSING) _Objects_MP_Handler_initialization(); _MPCI_Handler_initialization( RTEMS_TIMEOUT ); #endif _SMP_Handler_initialize(); _CPU_set_Handler_initialization(); /* MANAGERS */ _RTEMS_API_Initialize(); _Extension_Manager_initialization(); _POSIX_API_Initialize(); } static void rtems_initialize_before_drivers(void) { #ifdef RTEMS_DRVMGR_STARTUP _DRV_Manager_initialization(); #endif #if defined(RTEMS_MULTIPROCESSING) _MPCI_Create_server(); #endif } static void rtems_initialize_device_drivers(void) { /* * Initialize all the device drivers and initialize the MPCI layer. * * NOTE: The MPCI may be build upon a device driver. */ #ifdef RTEMS_DRVMGR_STARTUP /* BSPs has already registered their "root bus" driver in the * bsp_predriver hook or so. * * Init Drivers to Level 1, constraints: * - Interrupts and system clock timer does not work. * - malloc() work, however other memory services may not * have been initialized yet. * - initializes most basic stuff * * Typical setup in Level 1: * - Find most devices in system, do PCI scan and configuration. * - Reset hardware if needed. * - Install IRQ driver * - Install Timer driver * - Install console driver and debug printk() * - Install extra memory. */ _DRV_Manager_init_level(1); bsp_driver_level_hook(1); #endif /* Initialize I/O drivers. * * Driver Manager note: * All drivers may not be registered yet. Drivers will dynamically * be initialized when registered in level 2,3 and 4. */ _IO_Initialize_all_drivers(); #ifdef RTEMS_DRVMGR_STARTUP /* Init Drivers to Level 2, constraints: * - Interrupts can be registered and enabled. * - System Clock is running * - Console may be used. * * This is typically where drivers are initialized * for the first time. */ _DRV_Manager_init_level(2); bsp_driver_level_hook(2); /* Init Drivers to Level 3 * * This is typically where normal drivers are initialized * for the second time, they may depend on other drivers * API inited in level 2 */ _DRV_Manager_init_level(3); bsp_driver_level_hook(3); /* Init Drivers to Level 4, * Init drivers that depend on services initialized in Level 3 */ _DRV_Manager_init_level(4); bsp_driver_level_hook(4); #endif #if defined(RTEMS_MULTIPROCESSING) if ( _System_state_Is_multiprocessing ) { _MPCI_Initialization(); _MPCI_Internal_packets_Send_process_packet( MPCI_PACKETS_SYSTEM_VERIFY ); } #endif /* * Run the APIs and BSPs postdriver hooks. * * The API extensions are supposed to create user initialization tasks. */ _API_extensions_Run_postdriver(); } RTEMS_LINKER_ROSET( _Sysinit, rtems_sysinit_item ); RTEMS_SYSINIT_ITEM( rtems_initialize_data_structures, RTEMS_SYSINIT_DATA_STRUCTURES, RTEMS_SYSINIT_ORDER_MIDDLE ); /* * No threads should be created before this point!!! * _Thread_Executing and _Thread_Heir are not set. * * At this point all API extensions are in place. After the call to * _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set. * * Scheduling can properly occur afterwards as long as we avoid dispatching. */ RTEMS_SYSINIT_ITEM( _Thread_Create_idle, RTEMS_SYSINIT_IDLE_THREADS, RTEMS_SYSINIT_ORDER_MIDDLE ); RTEMS_SYSINIT_ITEM( rtems_initialize_before_drivers, RTEMS_SYSINIT_BEFORE_DRIVERS, RTEMS_SYSINIT_ORDER_MIDDLE ); RTEMS_SYSINIT_ITEM( rtems_initialize_device_drivers, RTEMS_SYSINIT_DEVICE_DRIVERS, RTEMS_SYSINIT_ORDER_MIDDLE ); void rtems_initialize_executive(void) { const volatile rtems_sysinit_item *cur = RTEMS_LINKER_SET_BEGIN(_Sysinit ); const volatile rtems_sysinit_item *end = RTEMS_LINKER_SET_END( _Sysinit ); /* Invoke the registered system initialization handlers */ while ( cur != end ) { ( *cur->handler )(); ++cur; } _System_state_Set( SYSTEM_STATE_UP ); _SMP_Request_start_multitasking(); _Thread_Start_multitasking(); /******************************************************************* ******************************************************************* ******************************************************************* ****** APPLICATION RUNS HERE ****** ****** THE FUNCTION NEVER RETURNS ****** ******************************************************************* ******************************************************************* *******************************************************************/ }