[ac7d5ef0] | 1 | /* |
---|
| 2 | * Initialization Manager |
---|
| 3 | * |
---|
[9221838] | 4 | * COPYRIGHT (c) 1989-2007. |
---|
[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 | rtems_interrupt_level rtems_initialize_executive_early( |
---|
[6aa25da] | 65 | rtems_configuration_table *configuration_table |
---|
[ac7d5ef0] | 66 | ) |
---|
| 67 | { |
---|
| 68 | rtems_interrupt_level bsp_level; |
---|
| 69 | |
---|
| 70 | /* |
---|
| 71 | * Dispatching and interrupts are disabled until the end of the |
---|
| 72 | * initialization sequence. This prevents an inadvertent context |
---|
| 73 | * switch before the executive is initialized. |
---|
| 74 | */ |
---|
| 75 | _ISR_Disable( bsp_level ); |
---|
| 76 | |
---|
[9221838] | 77 | /* |
---|
| 78 | * Make sure the parameters were not NULL. |
---|
| 79 | */ |
---|
[9a11e1f] | 80 | if ( configuration_table == NULL ) |
---|
[3a4ae6c] | 81 | _Internal_error_Occurred( |
---|
| 82 | INTERNAL_ERROR_CORE, |
---|
| 83 | TRUE, |
---|
| 84 | INTERNAL_ERROR_NO_CONFIGURATION_TABLE |
---|
| 85 | ); |
---|
[ac7d5ef0] | 86 | |
---|
[976162a6] | 87 | /* |
---|
| 88 | * Provide pointers just for later convenience. |
---|
| 89 | */ |
---|
| 90 | _Configuration_Table = configuration_table; |
---|
| 91 | |
---|
| 92 | /* |
---|
| 93 | * Initialize any target architecture specific support as early as possible |
---|
| 94 | */ |
---|
[6aa25da] | 95 | _CPU_Initialize( _Thread_Dispatch ); |
---|
[976162a6] | 96 | |
---|
[9221838] | 97 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3a4ae6c] | 98 | /* |
---|
| 99 | * Initialize the system state based on whether this is an MP system. |
---|
[9221838] | 100 | * In an MP configuration, internally we view single processor |
---|
| 101 | * systems as a very restricted multiprocessor system. |
---|
[3a4ae6c] | 102 | */ |
---|
[9221838] | 103 | _Configuration_MP_table = configuration_table->User_multiprocessing_table; |
---|
[3a4ae6c] | 104 | |
---|
[9221838] | 105 | if ( _Configuration_MP_table == NULL ) { |
---|
| 106 | _Configuration_MP_table = |
---|
| 107 | (void *)&_Initialization_Default_multiprocessing_table; |
---|
| 108 | _System_state_Handler_initialization( FALSE ); |
---|
| 109 | } else { |
---|
| 110 | _System_state_Handler_initialization( TRUE ); |
---|
| 111 | } |
---|
[97e2729d] | 112 | #else |
---|
| 113 | _System_state_Handler_initialization( FALSE ); |
---|
| 114 | #endif |
---|
[ac7d5ef0] | 115 | |
---|
[3a4ae6c] | 116 | /* |
---|
| 117 | * Do this as early as possible to insure no debugging output |
---|
| 118 | * is even attempted to be printed. |
---|
| 119 | */ |
---|
| 120 | |
---|
| 121 | _Debug_Manager_initialization(); |
---|
[ac7d5ef0] | 122 | |
---|
[7af35da5] | 123 | _API_extensions_Initialization(); |
---|
| 124 | |
---|
[ac7d5ef0] | 125 | _Thread_Dispatch_initialization(); |
---|
| 126 | |
---|
| 127 | _Workspace_Handler_initialization( |
---|
| 128 | (void *)configuration_table->work_space_start, |
---|
| 129 | configuration_table->work_space_size |
---|
| 130 | ); |
---|
| 131 | |
---|
[0451b44] | 132 | _User_extensions_Handler_initialization( |
---|
| 133 | configuration_table->number_of_initial_extensions, |
---|
| 134 | configuration_table->User_extension_table |
---|
| 135 | ); |
---|
| 136 | |
---|
[ac7d5ef0] | 137 | _ISR_Handler_initialization(); |
---|
| 138 | |
---|
| 139 | _Objects_Handler_initialization( |
---|
[9221838] | 140 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 141 | _Configuration_MP_table->node, |
---|
| 142 | _Configuration_MP_table->maximum_nodes, |
---|
| 143 | _Configuration_MP_table->maximum_global_objects |
---|
| 144 | #endif |
---|
[ac7d5ef0] | 145 | ); |
---|
| 146 | |
---|
[0577ec1d] | 147 | _Objects_Information_table[OBJECTS_INTERNAL_API] = _Internal_Objects; |
---|
| 148 | |
---|
[70669f28] | 149 | /* |
---|
| 150 | * Initialize the internal allocator Mutex |
---|
| 151 | */ |
---|
| 152 | _API_Mutex_Initialization( 1 ); |
---|
[8fd28d83] | 153 | _API_Mutex_Allocate( &_RTEMS_Allocator_Mutex ); |
---|
[70669f28] | 154 | |
---|
[ac7d5ef0] | 155 | _Priority_Handler_initialization(); |
---|
| 156 | |
---|
| 157 | _Watchdog_Handler_initialization(); |
---|
| 158 | |
---|
| 159 | _TOD_Handler_initialization( configuration_table->microseconds_per_tick ); |
---|
| 160 | |
---|
| 161 | _Thread_Handler_initialization( |
---|
| 162 | configuration_table->ticks_per_timeslice, |
---|
[9221838] | 163 | configuration_table->maximum_extensions |
---|
| 164 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 165 | , |
---|
[976162a6] | 166 | _Configuration_MP_table->maximum_proxies |
---|
[9221838] | 167 | #endif |
---|
[ac7d5ef0] | 168 | ); |
---|
| 169 | |
---|
[97e2729d] | 170 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3a4ae6c] | 171 | _MPCI_Handler_initialization( |
---|
[976162a6] | 172 | _Configuration_MP_table->User_mpci_table, |
---|
[18c5378] | 173 | RTEMS_TIMEOUT |
---|
[3a4ae6c] | 174 | ); |
---|
[97e2729d] | 175 | #endif |
---|
[ac7d5ef0] | 176 | |
---|
[3a4ae6c] | 177 | /* MANAGERS */ |
---|
[ac7d5ef0] | 178 | |
---|
[0577ec1d] | 179 | _RTEMS_API_Initialize( configuration_table ); |
---|
| 180 | |
---|
[ac7d5ef0] | 181 | _Extension_Manager_initialization( configuration_table->maximum_extensions ); |
---|
| 182 | |
---|
| 183 | _IO_Manager_initialization( |
---|
| 184 | configuration_table->Device_driver_table, |
---|
[3a4ae6c] | 185 | configuration_table->number_of_device_drivers, |
---|
[ff3f8c85] | 186 | configuration_table->maximum_drivers |
---|
[ac7d5ef0] | 187 | ); |
---|
| 188 | |
---|
[d4b44877] | 189 | #ifdef RTEMS_POSIX_API |
---|
| 190 | _POSIX_API_Initialize( configuration_table ); |
---|
| 191 | #endif |
---|
| 192 | |
---|
[352c9b2] | 193 | #ifdef RTEMS_ITRON_API |
---|
| 194 | _ITRON_API_Initialize( configuration_table ); |
---|
| 195 | #endif |
---|
| 196 | |
---|
[56d34e6] | 197 | _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING ); |
---|
| 198 | |
---|
| 199 | /* |
---|
[8486081] | 200 | * No threads should be created before this point!!! |
---|
[a2a8c5b] | 201 | * _Thread_Executing and _Thread_Heir are not set. |
---|
[56d34e6] | 202 | * |
---|
| 203 | * At this point all API extensions are in place. After the call to |
---|
[a2a8c5b] | 204 | * _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set. |
---|
[56d34e6] | 205 | */ |
---|
[3a4ae6c] | 206 | |
---|
[56d34e6] | 207 | _Thread_Create_idle(); |
---|
| 208 | |
---|
[a2a8c5b] | 209 | /* |
---|
| 210 | * Scheduling can properly occur now as long as we avoid dispatching. |
---|
| 211 | */ |
---|
| 212 | |
---|
[976162a6] | 213 | { |
---|
| 214 | extern void bsp_pretasking_hook(void); |
---|
| 215 | bsp_pretasking_hook(); |
---|
| 216 | } |
---|
[a2a8c5b] | 217 | |
---|
[97e2729d] | 218 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[56d34e6] | 219 | _MPCI_Create_server(); |
---|
[97e2729d] | 220 | #endif |
---|
[ac7d5ef0] | 221 | |
---|
[389fa850] | 222 | /* |
---|
| 223 | * Run the API and BSPs predriver hook. |
---|
| 224 | */ |
---|
[8486081] | 225 | |
---|
[389fa850] | 226 | _API_extensions_Run_predriver(); |
---|
[8486081] | 227 | |
---|
[976162a6] | 228 | { |
---|
| 229 | extern void bsp_predriver_hook(void); |
---|
| 230 | bsp_predriver_hook(); |
---|
| 231 | } |
---|
[8486081] | 232 | |
---|
[389fa850] | 233 | /* |
---|
| 234 | * Initialize all the device drivers and initialize the MPCI layer. |
---|
| 235 | * |
---|
| 236 | * NOTE: The MPCI may be build upon a device driver. |
---|
| 237 | */ |
---|
[8486081] | 238 | |
---|
[389fa850] | 239 | _IO_Initialize_all_drivers(); |
---|
[8486081] | 240 | |
---|
[97e2729d] | 241 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[389fa850] | 242 | if ( _System_state_Is_multiprocessing ) { |
---|
| 243 | _MPCI_Initialization(); |
---|
[56d34e6] | 244 | _MPCI_Internal_packets_Send_process_packet( |
---|
| 245 | MPCI_PACKETS_SYSTEM_VERIFY |
---|
[389fa850] | 246 | ); |
---|
| 247 | } |
---|
[97e2729d] | 248 | #endif |
---|
[8486081] | 249 | |
---|
[389fa850] | 250 | /* |
---|
| 251 | * Run the APIs and BSPs postdriver hooks. |
---|
| 252 | * |
---|
| 253 | * The API extensions are supposed to create user initialization tasks. |
---|
| 254 | */ |
---|
[8486081] | 255 | |
---|
[389fa850] | 256 | _API_extensions_Run_postdriver(); |
---|
[8486081] | 257 | |
---|
[976162a6] | 258 | { |
---|
| 259 | extern void bsp_postdriver_hook(void); |
---|
| 260 | bsp_postdriver_hook(); |
---|
| 261 | } |
---|
[389fa850] | 262 | |
---|
[ac7d5ef0] | 263 | return bsp_level; |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | void rtems_initialize_executive_late( |
---|
| 267 | rtems_interrupt_level bsp_level |
---|
| 268 | ) |
---|
| 269 | { |
---|
| 270 | |
---|
| 271 | _System_state_Set( SYSTEM_STATE_BEGIN_MULTITASKING ); |
---|
| 272 | |
---|
[f972294d] | 273 | _Thread_Start_multitasking(); |
---|
[ac7d5ef0] | 274 | |
---|
| 275 | /* |
---|
| 276 | * Restore the interrupt level to what the BSP had. Technically, |
---|
| 277 | * this is unnecessary since the BSP should have all interrupts |
---|
| 278 | * disabled when rtems_initialize_executive is invoked. But this keeps |
---|
| 279 | * the ISR Disable/Enable calls paired. |
---|
| 280 | */ |
---|
| 281 | |
---|
| 282 | _ISR_Enable( bsp_level ); |
---|
| 283 | } |
---|