[ac7d5ef0] | 1 | /* |
---|
| 2 | * Initialization Manager |
---|
| 3 | * |
---|
[d86ae06] | 4 | * COPYRIGHT (c) 1989-2008. |
---|
[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 |
---|
[aac75d3b] | 56 | #include <rtems/posix/posixapi.h> |
---|
[c627b2a3] | 57 | #endif |
---|
[352c9b2] | 58 | |
---|
[0577ec1d] | 59 | Objects_Information *_Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ]; |
---|
[3a4ae6c] | 60 | |
---|
[aac75d3b] | 61 | void rtems_initialize_data_structures(void) |
---|
[ac7d5ef0] | 62 | { |
---|
| 63 | /* |
---|
| 64 | * Dispatching and interrupts are disabled until the end of the |
---|
| 65 | * initialization sequence. This prevents an inadvertent context |
---|
| 66 | * switch before the executive is initialized. |
---|
[a0d22251] | 67 | * |
---|
| 68 | * WARNING: Interrupts should have been disabled by the BSP and |
---|
| 69 | * are disabled by boot_card(). |
---|
[ac7d5ef0] | 70 | */ |
---|
| 71 | |
---|
[aac75d3b] | 72 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 73 | /* |
---|
| 74 | * Initialize the system state based on whether this is an MP system. |
---|
| 75 | * In an MP configuration, internally we view single processor |
---|
| 76 | * systems as a very restricted multiprocessor system. |
---|
| 77 | */ |
---|
| 78 | _Configuration_MP_table = Configuration.User_multiprocessing_table; |
---|
| 79 | |
---|
| 80 | if ( _Configuration_MP_table == NULL ) { |
---|
| 81 | _Configuration_MP_table = |
---|
| 82 | (void *)&_Initialization_Default_multiprocessing_table; |
---|
| 83 | _System_state_Handler_initialization( FALSE ); |
---|
| 84 | } else { |
---|
| 85 | _System_state_Handler_initialization( TRUE ); |
---|
| 86 | } |
---|
| 87 | #else |
---|
[9221838] | 88 | _System_state_Handler_initialization( FALSE ); |
---|
[aac75d3b] | 89 | #endif |
---|
[ac7d5ef0] | 90 | |
---|
[45d107ec] | 91 | /* |
---|
| 92 | * Initialize any target architecture specific support as early as possible |
---|
| 93 | */ |
---|
| 94 | _CPU_Initialize(); |
---|
| 95 | |
---|
[562eab5c] | 96 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 97 | _Objects_MP_Handler_early_initialization(); |
---|
| 98 | #endif |
---|
| 99 | |
---|
[3a4ae6c] | 100 | /* |
---|
[aac75d3b] | 101 | * Do this as early as possible to ensure no debugging output |
---|
[3a4ae6c] | 102 | * is even attempted to be printed. |
---|
| 103 | */ |
---|
| 104 | _Debug_Manager_initialization(); |
---|
[ac7d5ef0] | 105 | |
---|
[7af35da5] | 106 | _API_extensions_Initialization(); |
---|
| 107 | |
---|
[ac7d5ef0] | 108 | _Thread_Dispatch_initialization(); |
---|
| 109 | |
---|
[f5f4566] | 110 | /* |
---|
| 111 | * Before this is called, we are not allowed to allocate memory |
---|
| 112 | * from the Workspace because it is not initialized. |
---|
| 113 | */ |
---|
[790b50b] | 114 | _Workspace_Handler_initialization(); |
---|
[0451b44] | 115 | |
---|
[790b50b] | 116 | _User_extensions_Handler_initialization(); |
---|
[ac7d5ef0] | 117 | _ISR_Handler_initialization(); |
---|
[0577ec1d] | 118 | |
---|
[70669f28] | 119 | /* |
---|
[790b50b] | 120 | * Initialize the internal support API and allocator Mutex |
---|
[70669f28] | 121 | */ |
---|
[790b50b] | 122 | _Objects_Information_table[OBJECTS_INTERNAL_API] = _Internal_Objects; |
---|
| 123 | |
---|
[70669f28] | 124 | _API_Mutex_Initialization( 1 ); |
---|
[8fd28d83] | 125 | _API_Mutex_Allocate( &_RTEMS_Allocator_Mutex ); |
---|
[70669f28] | 126 | |
---|
[ac7d5ef0] | 127 | _Priority_Handler_initialization(); |
---|
| 128 | _Watchdog_Handler_initialization(); |
---|
[790b50b] | 129 | _TOD_Handler_initialization(); |
---|
[ac7d5ef0] | 130 | |
---|
[790b50b] | 131 | _Thread_Handler_initialization(); |
---|
[ac7d5ef0] | 132 | |
---|
[aac75d3b] | 133 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[584ab9e] | 134 | _Objects_MP_Handler_initialization(); |
---|
[790b50b] | 135 | _MPCI_Handler_initialization( RTEMS_TIMEOUT ); |
---|
[aac75d3b] | 136 | #endif |
---|
[ac7d5ef0] | 137 | |
---|
[3a4ae6c] | 138 | /* MANAGERS */ |
---|
[ac7d5ef0] | 139 | |
---|
[aac75d3b] | 140 | _RTEMS_API_Initialize(); |
---|
[0577ec1d] | 141 | |
---|
[790b50b] | 142 | _Extension_Manager_initialization(); |
---|
[ac7d5ef0] | 143 | |
---|
[790b50b] | 144 | _IO_Manager_initialization(); |
---|
[ac7d5ef0] | 145 | |
---|
[aac75d3b] | 146 | #ifdef RTEMS_POSIX_API |
---|
| 147 | _POSIX_API_Initialize(); |
---|
| 148 | #endif |
---|
[d4b44877] | 149 | |
---|
[56d34e6] | 150 | _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING ); |
---|
| 151 | |
---|
| 152 | /* |
---|
[8486081] | 153 | * No threads should be created before this point!!! |
---|
[a2a8c5b] | 154 | * _Thread_Executing and _Thread_Heir are not set. |
---|
[56d34e6] | 155 | * |
---|
| 156 | * At this point all API extensions are in place. After the call to |
---|
[a2a8c5b] | 157 | * _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set. |
---|
[56d34e6] | 158 | */ |
---|
| 159 | _Thread_Create_idle(); |
---|
| 160 | |
---|
[a2a8c5b] | 161 | /* |
---|
| 162 | * Scheduling can properly occur now as long as we avoid dispatching. |
---|
| 163 | */ |
---|
[d86ae06] | 164 | } |
---|
[a2a8c5b] | 165 | |
---|
[d86ae06] | 166 | void rtems_initialize_before_drivers(void) |
---|
| 167 | { |
---|
[a2a8c5b] | 168 | |
---|
[aac75d3b] | 169 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 170 | _MPCI_Create_server(); |
---|
| 171 | #endif |
---|
[ac7d5ef0] | 172 | |
---|
[27b961a] | 173 | #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API) |
---|
| 174 | /* |
---|
| 175 | * Run the API and BSPs predriver hook. |
---|
| 176 | */ |
---|
| 177 | _API_extensions_Run_predriver(); |
---|
| 178 | #endif |
---|
[d86ae06] | 179 | } |
---|
[8486081] | 180 | |
---|
[d86ae06] | 181 | void rtems_initialize_device_drivers(void) |
---|
| 182 | { |
---|
[389fa850] | 183 | /* |
---|
| 184 | * Initialize all the device drivers and initialize the MPCI layer. |
---|
| 185 | * |
---|
| 186 | * NOTE: The MPCI may be build upon a device driver. |
---|
| 187 | */ |
---|
[8486081] | 188 | |
---|
[389fa850] | 189 | _IO_Initialize_all_drivers(); |
---|
[8486081] | 190 | |
---|
[aac75d3b] | 191 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 192 | if ( _System_state_Is_multiprocessing ) { |
---|
| 193 | _MPCI_Initialization(); |
---|
| 194 | _MPCI_Internal_packets_Send_process_packet( |
---|
| 195 | MPCI_PACKETS_SYSTEM_VERIFY |
---|
| 196 | ); |
---|
| 197 | } |
---|
| 198 | #endif |
---|
[8486081] | 199 | |
---|
[389fa850] | 200 | /* |
---|
| 201 | * Run the APIs and BSPs postdriver hooks. |
---|
| 202 | * |
---|
| 203 | * The API extensions are supposed to create user initialization tasks. |
---|
| 204 | */ |
---|
| 205 | _API_extensions_Run_postdriver(); |
---|
[ac7d5ef0] | 206 | } |
---|
| 207 | |
---|
[d86ae06] | 208 | void rtems_initialize_start_multitasking(void) |
---|
[ac7d5ef0] | 209 | { |
---|
| 210 | |
---|
| 211 | _System_state_Set( SYSTEM_STATE_BEGIN_MULTITASKING ); |
---|
| 212 | |
---|
[f972294d] | 213 | _Thread_Start_multitasking(); |
---|
[ac7d5ef0] | 214 | |
---|
[d86ae06] | 215 | /******************************************************************* |
---|
| 216 | ******************************************************************* |
---|
| 217 | ******************************************************************* |
---|
| 218 | ****** APPLICATION RUNS HERE ****** |
---|
| 219 | ****** RETURNS WHEN SYSTEM IS SHUT DOWN ****** |
---|
| 220 | ******************************************************************* |
---|
| 221 | ******************************************************************* |
---|
| 222 | *******************************************************************/ |
---|
[ac7d5ef0] | 223 | } |
---|