[ac7d5ef0] | 1 | /* bsp_start() |
---|
| 2 | * |
---|
| 3 | * This routine starts the application. It includes application, |
---|
| 4 | * board, and monitor specific initialization and configuration. |
---|
| 5 | * The generic CPU dependent initialization has been performed |
---|
| 6 | * before this routine is invoked. |
---|
| 7 | * |
---|
| 8 | * Called by RTEMS::RTEMS constructor in startup-ctor.cc |
---|
| 9 | * |
---|
| 10 | * INPUT: NONE |
---|
| 11 | * |
---|
| 12 | * OUTPUT: NONE |
---|
| 13 | * |
---|
[03f2154e] | 14 | * COPYRIGHT (c) 1989-1997. |
---|
[ac7d5ef0] | 15 | * On-Line Applications Research Corporation (OAR). |
---|
[03f2154e] | 16 | * Copyright assigned to U.S. Government, 1994. |
---|
[ac7d5ef0] | 17 | * |
---|
[98e4ebf5] | 18 | * The license and distribution terms for this file may be |
---|
| 19 | * found in the file LICENSE in this distribution or at |
---|
[03f2154e] | 20 | * http://www.OARcorp.com/rtems/license.html. |
---|
[ac7d5ef0] | 21 | * |
---|
[b06e68ef] | 22 | * $Id$ |
---|
[ac7d5ef0] | 23 | */ |
---|
| 24 | |
---|
[b06e68ef] | 25 | #include <rtems.h> |
---|
[ac7d5ef0] | 26 | #include <bsp.h> |
---|
[b06e68ef] | 27 | #include <rtems/libio.h> |
---|
| 28 | |
---|
[ac7d5ef0] | 29 | #include <libcsupport.h> |
---|
| 30 | |
---|
| 31 | #include <string.h> |
---|
[b06e68ef] | 32 | #include <fcntl.h> |
---|
[ac7d5ef0] | 33 | |
---|
| 34 | #ifdef STACK_CHECKER_ON |
---|
| 35 | #include <stackchk.h> |
---|
| 36 | #endif |
---|
| 37 | |
---|
| 38 | extern rtems_configuration_table Configuration; |
---|
| 39 | |
---|
| 40 | rtems_configuration_table BSP_Configuration; |
---|
| 41 | rtems_cpu_table Cpu_table; |
---|
| 42 | rtems_unsigned32 bsp_isr_level; |
---|
| 43 | |
---|
[64f311f7] | 44 | int cpu_number; |
---|
| 45 | |
---|
[ac7d5ef0] | 46 | #define WORKSPACE_SIZE (1024 * 1024) |
---|
| 47 | rtems_unsigned8 MY_WORK_SPACE[ WORKSPACE_SIZE ]; |
---|
| 48 | |
---|
| 49 | /* |
---|
| 50 | * Amount to increment itimer by each pass |
---|
| 51 | * It is a variable instead of a #define to allow the 'looptest' |
---|
| 52 | * script to bump it without recompiling rtems |
---|
| 53 | */ |
---|
| 54 | |
---|
| 55 | rtems_unsigned32 CPU_HPPA_CLICKS_PER_TICK; |
---|
| 56 | |
---|
| 57 | #if SIMHPPA_FAST_IDLE |
---|
| 58 | |
---|
| 59 | /* |
---|
| 60 | * Many of the tests are very slow on the simulator because they have |
---|
| 61 | * have 5 second delays hardwired in. |
---|
| 62 | * Try to speed those tests up by speeding up the clock when in idle |
---|
| 63 | */ |
---|
| 64 | |
---|
| 65 | rtems_extension |
---|
| 66 | fast_idle_switch_hook(rtems_tcb *current_task, |
---|
| 67 | rtems_tcb *heir_task) |
---|
| 68 | { |
---|
| 69 | static rtems_unsigned32 normal_clock = ~0; |
---|
| 70 | static rtems_unsigned32 fast_clock; |
---|
| 71 | |
---|
| 72 | /* init our params on first call */ |
---|
[588c9ed] | 73 | if (normal_clock == (rtems_unsigned32) ~0) |
---|
[ac7d5ef0] | 74 | { |
---|
| 75 | normal_clock = CPU_HPPA_CLICKS_PER_TICK; |
---|
| 76 | fast_clock = CPU_HPPA_CLICKS_PER_TICK / 0x100; |
---|
| 77 | if (fast_clock == 0) /* who? me? pathological? never! */ |
---|
| 78 | fast_clock++; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | /* |
---|
| 82 | * Checking for 'name' field of 'IDLE' is not the best/safest, |
---|
| 83 | * but its the best we could think of at the moment. |
---|
| 84 | */ |
---|
| 85 | |
---|
[8cbbe312] | 86 | if (heir_task == _Thread_Idle) |
---|
[ac7d5ef0] | 87 | CPU_HPPA_CLICKS_PER_TICK = fast_clock; |
---|
[8cbbe312] | 88 | else if (current_task == _Thread_Idle) |
---|
[ac7d5ef0] | 89 | CPU_HPPA_CLICKS_PER_TICK = normal_clock; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | #endif |
---|
| 93 | |
---|
| 94 | /* |
---|
| 95 | * Function: bsp_libc_init |
---|
| 96 | * Created: 94/12/6 |
---|
| 97 | * |
---|
| 98 | * Description: |
---|
| 99 | * Initialize whatever libc we are using |
---|
| 100 | * called from bsp_postdriver_hook |
---|
| 101 | * |
---|
| 102 | * |
---|
| 103 | * Parameters: |
---|
| 104 | * none |
---|
| 105 | * |
---|
| 106 | * Returns: |
---|
| 107 | * none. |
---|
| 108 | * |
---|
| 109 | * Side Effects: |
---|
| 110 | * |
---|
| 111 | * |
---|
| 112 | * Notes: |
---|
| 113 | * |
---|
| 114 | * Deficiencies/ToDo: |
---|
| 115 | * |
---|
| 116 | * |
---|
| 117 | */ |
---|
| 118 | |
---|
| 119 | void |
---|
| 120 | bsp_libc_init(void) |
---|
| 121 | { |
---|
| 122 | extern int end; |
---|
| 123 | rtems_unsigned32 heap_start; |
---|
| 124 | |
---|
| 125 | heap_start = (rtems_unsigned32) &end; |
---|
| 126 | if (heap_start & (CPU_ALIGNMENT-1)) |
---|
| 127 | heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1); |
---|
| 128 | |
---|
| 129 | RTEMS_Malloc_Initialize((void *) heap_start, 64 * 1024, 0); |
---|
| 130 | |
---|
[b06e68ef] | 131 | /* |
---|
[3a4ae6c] | 132 | * Init the RTEMS libio facility to provide UNIX-like system |
---|
[634e746] | 133 | * calls for use by newlib (ie: provide __rtems_open, __rtems_close, etc) |
---|
[b06e68ef] | 134 | * Uses malloc() to get area for the iops, so must be after malloc init |
---|
| 135 | */ |
---|
| 136 | |
---|
| 137 | rtems_libio_init(); |
---|
| 138 | |
---|
[ac7d5ef0] | 139 | /* |
---|
| 140 | * Set up for the libc handling. |
---|
[b06e68ef] | 141 | * XXX; this should allow for case of some other non-clock interrupts |
---|
[ac7d5ef0] | 142 | */ |
---|
| 143 | |
---|
| 144 | if (BSP_Configuration.ticks_per_timeslice > 0) |
---|
| 145 | libc_init(1); /* reentrant if possible */ |
---|
| 146 | else |
---|
| 147 | libc_init(0); /* non-reentrant */ |
---|
| 148 | |
---|
| 149 | /* |
---|
| 150 | * on MP systems, always use the print buffer |
---|
| 151 | * instead of the (broken) system calls |
---|
| 152 | */ |
---|
| 153 | |
---|
| 154 | if (BSP_Configuration.User_multiprocessing_table) |
---|
| 155 | use_print_buffer = 1; |
---|
| 156 | |
---|
| 157 | #ifdef SIMHPPA_ROM |
---|
| 158 | use_print_buffer = 1; |
---|
| 159 | #endif |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | /* |
---|
| 164 | * Function: bsp_pretasking_hook |
---|
| 165 | * Created: 95/03/10 |
---|
| 166 | * |
---|
| 167 | * Description: |
---|
| 168 | * BSP pretasking hook. Called just before drivers are initialized. |
---|
| 169 | * Used to setup libc and install any BSP extensions. |
---|
| 170 | * |
---|
| 171 | * Parameters: |
---|
| 172 | * none |
---|
| 173 | * |
---|
| 174 | * Returns: |
---|
| 175 | * nada |
---|
| 176 | * |
---|
| 177 | * Side Effects: |
---|
| 178 | * installs a few extensions |
---|
| 179 | * |
---|
| 180 | * Notes: |
---|
| 181 | * Must not use libc (to do io) from here, since drivers are |
---|
| 182 | * not yet initialized. |
---|
| 183 | * |
---|
| 184 | * Deficiencies/ToDo: |
---|
| 185 | * |
---|
| 186 | * |
---|
| 187 | */ |
---|
| 188 | |
---|
| 189 | void |
---|
| 190 | bsp_pretasking_hook(void) |
---|
| 191 | { |
---|
| 192 | bsp_libc_init(); |
---|
| 193 | |
---|
| 194 | #if SIMHPPA_FAST_IDLE |
---|
| 195 | /* |
---|
| 196 | * Install the fast idle task switch extension |
---|
| 197 | * |
---|
| 198 | * on MP systems, might now want to do this; it confuses at least |
---|
| 199 | * one test (mp06) |
---|
| 200 | */ |
---|
| 201 | |
---|
| 202 | #if 0 |
---|
| 203 | if (BSP_Configuration.User_multiprocessing_table == 0) |
---|
| 204 | #endif |
---|
| 205 | { |
---|
| 206 | rtems_extensions_table fast_idle_extension; |
---|
| 207 | rtems_id extension_id; |
---|
| 208 | rtems_status_code rc; |
---|
| 209 | |
---|
| 210 | memset(&fast_idle_extension, 0, sizeof(fast_idle_extension)); |
---|
| 211 | |
---|
[3652ad35] | 212 | fast_idle_extension.thread_switch = fast_idle_switch_hook; |
---|
[ac7d5ef0] | 213 | |
---|
| 214 | rc = rtems_extension_create(rtems_build_name('F', 'D', 'L', 'E'), |
---|
| 215 | &fast_idle_extension, &extension_id); |
---|
| 216 | if (rc != RTEMS_SUCCESSFUL) |
---|
| 217 | rtems_fatal_error_occurred(rc); |
---|
| 218 | } |
---|
| 219 | #endif |
---|
| 220 | |
---|
| 221 | |
---|
| 222 | #ifdef STACK_CHECKER_ON |
---|
| 223 | /* |
---|
| 224 | * Initialize the stack bounds checker |
---|
| 225 | * We can either turn it on here or from the app. |
---|
| 226 | */ |
---|
| 227 | |
---|
| 228 | Stack_check_Initialize(); |
---|
| 229 | #endif |
---|
| 230 | } |
---|
| 231 | |
---|
[b06e68ef] | 232 | /* |
---|
| 233 | * After drivers are setup, register some "filenames" |
---|
| 234 | * and open stdin, stdout, stderr files |
---|
| 235 | * |
---|
| 236 | * Newlib will automatically associate the files with these |
---|
| 237 | * (it hardcodes the numbers) |
---|
| 238 | */ |
---|
| 239 | |
---|
| 240 | void |
---|
| 241 | bsp_postdriver_hook(void) |
---|
| 242 | { |
---|
[9700578] | 243 | int stdin_fd, stdout_fd, stderr_fd; |
---|
| 244 | int error_code; |
---|
| 245 | |
---|
| 246 | error_code = 'S' << 24 | 'T' << 16; |
---|
| 247 | |
---|
[634e746] | 248 | if ((stdin_fd = __rtems_open("/dev/console", O_RDONLY, 0)) == -1) |
---|
[9700578] | 249 | rtems_fatal_error_occurred( error_code | 'D' << 8 | '0' ); |
---|
| 250 | |
---|
[634e746] | 251 | if ((stdout_fd = __rtems_open("/dev/console", O_WRONLY, 0)) == -1) |
---|
[9700578] | 252 | rtems_fatal_error_occurred( error_code | 'D' << 8 | '1' ); |
---|
| 253 | |
---|
[634e746] | 254 | if ((stderr_fd = __rtems_open("/dev/console", O_WRONLY, 0)) == -1) |
---|
[9700578] | 255 | rtems_fatal_error_occurred( error_code | 'D' << 8 | '2' ); |
---|
| 256 | |
---|
| 257 | if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2)) |
---|
| 258 | rtems_fatal_error_occurred( error_code | 'I' << 8 | 'O' ); |
---|
[b06e68ef] | 259 | } |
---|
| 260 | |
---|
[ac7d5ef0] | 261 | /* |
---|
| 262 | * Function: bsp_start |
---|
| 263 | * Created: 94/12/6 |
---|
| 264 | * |
---|
| 265 | * Description: |
---|
| 266 | * called by crt0 as our "main" equivalent |
---|
| 267 | * |
---|
| 268 | * |
---|
| 269 | * |
---|
| 270 | * Parameters: |
---|
| 271 | * |
---|
| 272 | * |
---|
| 273 | * Returns: |
---|
| 274 | * |
---|
| 275 | * |
---|
| 276 | * Side Effects: |
---|
| 277 | * |
---|
| 278 | * |
---|
| 279 | * Notes: |
---|
| 280 | * |
---|
| 281 | * |
---|
| 282 | * Deficiencies/ToDo: |
---|
| 283 | * |
---|
| 284 | * |
---|
| 285 | */ |
---|
| 286 | |
---|
| 287 | |
---|
| 288 | void |
---|
| 289 | bsp_start(void) |
---|
| 290 | { |
---|
| 291 | /* |
---|
| 292 | * Set cpu_number to accurately reflect our cpu number |
---|
| 293 | */ |
---|
| 294 | |
---|
| 295 | #ifdef hppa7200 |
---|
| 296 | /* |
---|
[88d594a] | 297 | * Use HPPA_DR0 if supported |
---|
[ac7d5ef0] | 298 | */ |
---|
| 299 | { |
---|
| 300 | int dr0; |
---|
[88d594a] | 301 | HPPA_ASM_MFCPU(HPPA_DR0, dr0); |
---|
[ac7d5ef0] | 302 | cpu_number = (dr0 >> 4) & 0x7; |
---|
| 303 | } |
---|
| 304 | #else |
---|
| 305 | if (Configuration.User_multiprocessing_table) |
---|
| 306 | cpu_number = Configuration.User_multiprocessing_table->node - 1; |
---|
| 307 | else |
---|
| 308 | cpu_number = 0; |
---|
| 309 | #endif |
---|
| 310 | |
---|
| 311 | /* |
---|
| 312 | * Copy the table |
---|
| 313 | */ |
---|
| 314 | |
---|
| 315 | BSP_Configuration = Configuration; |
---|
| 316 | |
---|
| 317 | BSP_Configuration.work_space_start = (void *)MY_WORK_SPACE; |
---|
| 318 | if (BSP_Configuration.work_space_size) |
---|
| 319 | BSP_Configuration.work_space_size = WORKSPACE_SIZE; |
---|
| 320 | |
---|
| 321 | /* |
---|
| 322 | * Set up our hooks |
---|
| 323 | * Make sure libc_init is done before drivers init'd so that |
---|
| 324 | * they can use atexit() |
---|
| 325 | */ |
---|
| 326 | |
---|
| 327 | Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */ |
---|
| 328 | |
---|
| 329 | Cpu_table.predriver_hook = NULL; |
---|
| 330 | |
---|
[b06e68ef] | 331 | Cpu_table.postdriver_hook = bsp_postdriver_hook; /* register drivers */ |
---|
[ac7d5ef0] | 332 | |
---|
| 333 | Cpu_table.idle_task = NULL; /* do not override system IDLE task */ |
---|
| 334 | |
---|
| 335 | /* |
---|
| 336 | * Don't zero out the workspace. The simulator did it for us. |
---|
| 337 | */ |
---|
| 338 | |
---|
| 339 | Cpu_table.do_zero_of_workspace = FALSE; |
---|
| 340 | |
---|
| 341 | Cpu_table.interrupt_stack_size = (12 * 1024); |
---|
| 342 | |
---|
[8cbbe312] | 343 | Cpu_table.extra_mpci_receive_server_stack = 0; |
---|
[ac7d5ef0] | 344 | |
---|
| 345 | /* |
---|
| 346 | * Set this artificially low for the simulator |
---|
| 347 | */ |
---|
| 348 | |
---|
| 349 | Cpu_table.itimer_clicks_per_microsecond = 1; |
---|
| 350 | |
---|
[254b4450] | 351 | #if 0 |
---|
[8389628] | 352 | /* |
---|
| 353 | * Commented by DIVISION INC. External interrupt |
---|
| 354 | * processing is now divorced from RTEMS for HPPA. |
---|
| 355 | */ |
---|
| 356 | |
---|
[ac7d5ef0] | 357 | /* |
---|
| 358 | * Determine the external interrupt processing order |
---|
| 359 | * the external interrupt handler walks thru this table, in |
---|
| 360 | * order checking for posted interrupts. |
---|
| 361 | */ |
---|
| 362 | |
---|
| 363 | Cpu_table.external_interrupts = 0; |
---|
| 364 | |
---|
| 365 | Cpu_table.external_interrupt[ Cpu_table.external_interrupts ] = |
---|
[a6aded4f] | 366 | HPPA_INTERRUPT_EXTERNAL_INTERVAL_TIMER; |
---|
[ac7d5ef0] | 367 | Cpu_table.external_interrupts++; |
---|
| 368 | |
---|
| 369 | if ( Configuration.User_multiprocessing_table ) { |
---|
| 370 | Cpu_table.external_interrupt[ Cpu_table.external_interrupts ] = |
---|
[a6aded4f] | 371 | HPPA_INTERRUPT_EXTERNAL_10; |
---|
[ac7d5ef0] | 372 | Cpu_table.external_interrupts++; |
---|
| 373 | } |
---|
[8389628] | 374 | #endif |
---|
[ac7d5ef0] | 375 | |
---|
| 376 | /* |
---|
| 377 | * Add 1 region for RTEMS Malloc |
---|
| 378 | */ |
---|
| 379 | |
---|
[e6d4b1d] | 380 | BSP_Configuration.RTEMS_api_configuration->maximum_regions++; |
---|
[ac7d5ef0] | 381 | |
---|
| 382 | #ifdef RTEMS_NEWLIB |
---|
| 383 | /* |
---|
| 384 | * Add 1 extension for newlib libc |
---|
| 385 | */ |
---|
| 386 | |
---|
| 387 | BSP_Configuration.maximum_extensions++; |
---|
| 388 | #endif |
---|
| 389 | |
---|
| 390 | #ifdef STACK_CHECKER_ON |
---|
[b06e68ef] | 391 | /* |
---|
| 392 | * Add 1 extension for stack checker |
---|
| 393 | */ |
---|
[ac7d5ef0] | 394 | |
---|
| 395 | BSP_Configuration.maximum_extensions++; |
---|
| 396 | #endif |
---|
| 397 | |
---|
| 398 | #if SIMHPPA_FAST_IDLE |
---|
[b06e68ef] | 399 | /* |
---|
| 400 | * Add 1 extension for fast idle |
---|
| 401 | */ |
---|
[ac7d5ef0] | 402 | |
---|
| 403 | BSP_Configuration.maximum_extensions++; |
---|
| 404 | #endif |
---|
| 405 | |
---|
[b06e68ef] | 406 | /* |
---|
| 407 | * Tell libio how many fd's we want and allow it to tweak config |
---|
| 408 | */ |
---|
| 409 | |
---|
| 410 | rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS); |
---|
| 411 | |
---|
[ac7d5ef0] | 412 | /* |
---|
| 413 | * Add 1 extension for MPCI_fatal |
---|
| 414 | */ |
---|
| 415 | |
---|
| 416 | if (BSP_Configuration.User_multiprocessing_table) |
---|
| 417 | BSP_Configuration.maximum_extensions++; |
---|
| 418 | |
---|
| 419 | /* |
---|
| 420 | * Set the "clicks per tick" for the simulator |
---|
| 421 | * used by libcpu/hppa/clock/clock.c to schedule interrupts |
---|
| 422 | * |
---|
| 423 | * Set it only if 0 to allow for simulator setting it via script |
---|
| 424 | * on test startup. |
---|
| 425 | */ |
---|
| 426 | |
---|
| 427 | if (CPU_HPPA_CLICKS_PER_TICK == 0) |
---|
| 428 | CPU_HPPA_CLICKS_PER_TICK = 0x4000; |
---|
| 429 | |
---|
| 430 | /* |
---|
| 431 | * Start most of RTEMS |
---|
| 432 | * main() will start the rest |
---|
| 433 | */ |
---|
| 434 | |
---|
| 435 | bsp_isr_level = rtems_initialize_executive_early( |
---|
| 436 | &BSP_Configuration, |
---|
| 437 | &Cpu_table |
---|
| 438 | ); |
---|
| 439 | } |
---|