[33442772] | 1 | /* |
---|
[752cd8f] | 2 | * This routine starts the application. It includes application, |
---|
| 3 | * board, and monitor specific initialization and configuration. |
---|
| 4 | * The generic CPU dependent initialization has been performed |
---|
| 5 | * before this routine is invoked. |
---|
| 6 | * |
---|
[60b791ad] | 7 | * COPYRIGHT (c) 1989-1998. |
---|
[752cd8f] | 8 | * On-Line Applications Research Corporation (OAR). |
---|
[03f2154e] | 9 | * Copyright assigned to U.S. Government, 1994. |
---|
[752cd8f] | 10 | * |
---|
[98e4ebf5] | 11 | * The license and distribution terms for this file may be |
---|
| 12 | * found in the file LICENSE in this distribution or at |
---|
[03f2154e] | 13 | * http://www.OARcorp.com/rtems/license.html. |
---|
[752cd8f] | 14 | * |
---|
[33442772] | 15 | * Ported to the i386ex and submitted by: |
---|
| 16 | * |
---|
| 17 | * Erik Ivanenko |
---|
| 18 | * University of Toronto |
---|
| 19 | * erik.ivanenko@utoronto.ca |
---|
| 20 | * |
---|
[752cd8f] | 21 | * $Id$ |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | #include <bsp.h> |
---|
[fe6ef776] | 25 | #include <rtems/libio.h> |
---|
| 26 | |
---|
[752cd8f] | 27 | #include <libcsupport.h> |
---|
| 28 | |
---|
[33442772] | 29 | #ifdef STACK_CHECKER_ON |
---|
| 30 | #include <stackchk.h> |
---|
[fe6ef776] | 31 | #endif |
---|
[752cd8f] | 32 | |
---|
| 33 | /* |
---|
| 34 | * The original table from the application and our copy of it with |
---|
| 35 | * some changes. |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | extern rtems_configuration_table Configuration; |
---|
| 39 | rtems_configuration_table BSP_Configuration; |
---|
| 40 | |
---|
| 41 | rtems_cpu_table Cpu_table; |
---|
| 42 | |
---|
[33442772] | 43 | /* |
---|
| 44 | * Tells us where to put the workspace in case remote debugger is present. |
---|
| 45 | */ |
---|
| 46 | |
---|
| 47 | extern rtems_unsigned32 rdb_start; |
---|
[fe6ef776] | 48 | |
---|
[33442772] | 49 | /* |
---|
| 50 | * bsp_libc_init |
---|
| 51 | * |
---|
| 52 | * Initialize whatever libc we are using called from bsp_postdriver_hook. |
---|
[752cd8f] | 53 | */ |
---|
[33442772] | 54 | |
---|
[fe6ef776] | 55 | |
---|
[752cd8f] | 56 | void bsp_libc_init() |
---|
| 57 | { |
---|
[33442772] | 58 | extern int heap_bottom; |
---|
| 59 | rtems_unsigned32 heap_start; |
---|
| 60 | rtems_unsigned32 heap_size; |
---|
| 61 | |
---|
| 62 | heap_start = (rtems_unsigned32) &heap_bottom; |
---|
[752cd8f] | 63 | if (heap_start & (CPU_ALIGNMENT-1)) |
---|
[33442772] | 64 | heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1); |
---|
| 65 | |
---|
| 66 | heap_size = BSP_Configuration.work_space_start -(void *) heap_start ; |
---|
| 67 | heap_size &= 0xfffffff0; /* keep it as a multiple of 16 bytes */ |
---|
| 68 | |
---|
| 69 | heap_size &= 0xfffffff0; /* keep it as a multiple of 16 bytes */ |
---|
| 70 | RTEMS_Malloc_Initialize((void *) heap_start, heap_size, 0); |
---|
| 71 | |
---|
[fe6ef776] | 72 | /* |
---|
| 73 | * Init the RTEMS libio facility to provide UNIX-like system |
---|
[634e746] | 74 | * calls for use by newlib (ie: provide __rtems_open, __rtems_close, etc) |
---|
[fe6ef776] | 75 | * Uses malloc() to get area for the iops, so must be after malloc init |
---|
| 76 | */ |
---|
| 77 | |
---|
| 78 | rtems_libio_init(); |
---|
| 79 | |
---|
[752cd8f] | 80 | /* |
---|
| 81 | * Set up for the libc handling. |
---|
| 82 | */ |
---|
[fe6ef776] | 83 | |
---|
[752cd8f] | 84 | if (BSP_Configuration.ticks_per_timeslice > 0) |
---|
| 85 | libc_init(1); /* reentrant if possible */ |
---|
| 86 | else |
---|
| 87 | libc_init(0); /* non-reentrant */ |
---|
[fe6ef776] | 88 | } |
---|
[752cd8f] | 89 | |
---|
[fe6ef776] | 90 | /* |
---|
| 91 | * Function: bsp_pretasking_hook |
---|
| 92 | * Created: 95/03/10 |
---|
| 93 | * |
---|
| 94 | * Description: |
---|
| 95 | * BSP pretasking hook. Called just before drivers are initialized. |
---|
| 96 | * Used to setup libc and install any BSP extensions. |
---|
| 97 | * |
---|
| 98 | * NOTES: |
---|
| 99 | * Must not use libc (to do io) from here, since drivers are |
---|
| 100 | * not yet initialized. |
---|
| 101 | * |
---|
| 102 | */ |
---|
| 103 | |
---|
| 104 | void |
---|
| 105 | bsp_pretasking_hook(void) |
---|
| 106 | { |
---|
| 107 | bsp_libc_init(); |
---|
| 108 | |
---|
| 109 | #ifdef STACK_CHECKER_ON |
---|
[752cd8f] | 110 | /* |
---|
| 111 | * Initialize the stack bounds checker |
---|
[fe6ef776] | 112 | * We can either turn it on here or from the app. |
---|
[752cd8f] | 113 | */ |
---|
[fe6ef776] | 114 | |
---|
[752cd8f] | 115 | Stack_check_Initialize(); |
---|
| 116 | #endif |
---|
[33442772] | 117 | |
---|
[fe6ef776] | 118 | #ifdef RTEMS_DEBUG |
---|
| 119 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
| 120 | #endif |
---|
| 121 | } |
---|
| 122 | |
---|
[752cd8f] | 123 | |
---|
[fe6ef776] | 124 | /* |
---|
[33442772] | 125 | * Use the shared bsp_postdriver_hook() implementation |
---|
[fe6ef776] | 126 | */ |
---|
| 127 | |
---|
[33442772] | 128 | void bsp_postdriver_hook(void); |
---|
[fe6ef776] | 129 | |
---|
[e2a2ec60] | 130 | void bsp_start( void ) |
---|
[752cd8f] | 131 | { |
---|
| 132 | /* |
---|
| 133 | * we do not use the pretasking_hook. |
---|
| 134 | */ |
---|
| 135 | |
---|
[fe6ef776] | 136 | Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */ |
---|
| 137 | |
---|
| 138 | Cpu_table.predriver_hook = NULL; |
---|
| 139 | |
---|
| 140 | Cpu_table.postdriver_hook = bsp_postdriver_hook; |
---|
| 141 | |
---|
[752cd8f] | 142 | Cpu_table.idle_task = NULL; /* do not override system IDLE task */ |
---|
[fe6ef776] | 143 | |
---|
[752cd8f] | 144 | Cpu_table.do_zero_of_workspace = TRUE; |
---|
[fe6ef776] | 145 | |
---|
[752cd8f] | 146 | Cpu_table.interrupt_table_segment = get_ds(); |
---|
[fe6ef776] | 147 | |
---|
[752cd8f] | 148 | Cpu_table.interrupt_table_offset = (void *)Interrupt_descriptor_table; |
---|
[fe6ef776] | 149 | |
---|
[33442772] | 150 | Cpu_table.interrupt_stack_size = 4096; /* STACK_MINIMUM_SIZE */ |
---|
[fe6ef776] | 151 | |
---|
| 152 | Cpu_table.extra_mpci_receive_server_stack = 0; |
---|
[752cd8f] | 153 | |
---|
| 154 | /* |
---|
| 155 | * Copy the table |
---|
| 156 | */ |
---|
| 157 | |
---|
| 158 | BSP_Configuration = Configuration; |
---|
| 159 | |
---|
[33442772] | 160 | #if defined(RTEMS_POSIX_API) |
---|
| 161 | BSP_Configuration.work_space_size *= 3; |
---|
| 162 | #endif |
---|
| 163 | |
---|
[752cd8f] | 164 | BSP_Configuration.work_space_start = (void *) |
---|
| 165 | RAM_END - BSP_Configuration.work_space_size; |
---|
| 166 | |
---|
[33442772] | 167 | /* |
---|
| 168 | * Account for the console's resources |
---|
| 169 | */ |
---|
| 170 | |
---|
| 171 | /* console_reserve_resources( &BSP_Configuration ); */ |
---|
| 172 | |
---|
| 173 | |
---|
[752cd8f] | 174 | /* |
---|
[c244a9ee] | 175 | * Tell libio how many fd's we want and allow it to tweak config |
---|
[752cd8f] | 176 | */ |
---|
| 177 | |
---|
[c244a9ee] | 178 | rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS); |
---|
[752cd8f] | 179 | |
---|
| 180 | } |
---|