[b6394ae] | 1 | /* |
---|
[637df35] | 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 | * |
---|
| 7 | * Called by RTEMS::RTEMS constructor in startup-ctor.cc |
---|
| 8 | * |
---|
[60b791ad] | 9 | * COPYRIGHT (c) 1989-1998. |
---|
[637df35] | 10 | * On-Line Applications Research Corporation (OAR). |
---|
[03f2154e] | 11 | * Copyright assigned to U.S. Government, 1994. |
---|
[637df35] | 12 | * |
---|
[98e4ebf5] | 13 | * The license and distribution terms for this file may be |
---|
| 14 | * found in the file LICENSE in this distribution or at |
---|
[03f2154e] | 15 | * http://www.OARcorp.com/rtems/license.html. |
---|
[637df35] | 16 | * |
---|
| 17 | * $Id$ |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | #include <stdio.h> |
---|
| 21 | #include <stdlib.h> |
---|
[ce41c5b] | 22 | |
---|
| 23 | /* for sbrk prototype in linux */ |
---|
[421dfef6] | 24 | #if defined(__linux__) |
---|
[ce41c5b] | 25 | #define __USE_MISC |
---|
| 26 | #endif |
---|
[637df35] | 27 | #include <unistd.h> |
---|
| 28 | |
---|
| 29 | #include <bsp.h> |
---|
| 30 | #include <libcsupport.h> |
---|
| 31 | |
---|
[3a4ae6c] | 32 | #include <rtems/libio.h> |
---|
| 33 | |
---|
[637df35] | 34 | extern rtems_configuration_table Configuration; |
---|
| 35 | |
---|
| 36 | /* |
---|
| 37 | * A copy of the configuration table from the application |
---|
| 38 | * with some changes applied to it. |
---|
| 39 | */ |
---|
| 40 | |
---|
| 41 | rtems_configuration_table BSP_Configuration; |
---|
| 42 | rtems_multiprocessing_table BSP_Multiprocessing; |
---|
| 43 | rtems_cpu_table Cpu_table; |
---|
| 44 | rtems_unsigned32 bsp_isr_level; |
---|
| 45 | rtems_unsigned32 Heap_size; |
---|
| 46 | int rtems_argc; |
---|
| 47 | char **rtems_argv; |
---|
| 48 | |
---|
[c1403ef1] | 49 | /* |
---|
| 50 | * May be overridden by RTEMS_WORKSPACE_SIZE and RTEMS_HEAPSPACE_SIZE |
---|
| 51 | * environment variables; see below. |
---|
| 52 | */ |
---|
[637df35] | 53 | |
---|
[c1403ef1] | 54 | #define DEFAULT_WORKSPACE_SIZE (WORKSPACE_MB * (1024 * 1024)) |
---|
| 55 | #define DEFAULT_HEAPSPACE_SIZE (HEAPSPACE_MB * (1024 * 1024)) |
---|
[637df35] | 56 | |
---|
| 57 | /* |
---|
| 58 | * Amount to increment itimer by each pass |
---|
| 59 | * It is a variable instead of a #define to allow the 'looptest' |
---|
| 60 | * script to bump it without recompiling rtems |
---|
| 61 | */ |
---|
| 62 | |
---|
| 63 | rtems_unsigned32 CPU_CLICKS_PER_TICK; |
---|
| 64 | |
---|
| 65 | /* |
---|
[b6394ae] | 66 | * Use the shared implementations of the following routines |
---|
[637df35] | 67 | */ |
---|
[c1403ef1] | 68 | |
---|
[b6394ae] | 69 | void bsp_postdriver_hook(void); |
---|
| 70 | void bsp_libc_init( void *, unsigned32, int ); |
---|
[637df35] | 71 | |
---|
| 72 | /* |
---|
| 73 | * Function: bsp_pretasking_hook |
---|
| 74 | * Created: 95/03/10 |
---|
| 75 | * |
---|
| 76 | * Description: |
---|
| 77 | * BSP pretasking hook. Called just before drivers are initialized. |
---|
| 78 | * Used to setup libc and install any BSP extensions. |
---|
| 79 | * |
---|
[b6394ae] | 80 | * NOTES: |
---|
[637df35] | 81 | * Must not use libc (to do io) from here, since drivers are |
---|
| 82 | * not yet initialized. |
---|
| 83 | */ |
---|
| 84 | |
---|
[b6394ae] | 85 | void bsp_pretasking_hook(void) |
---|
[637df35] | 86 | { |
---|
[b6394ae] | 87 | void *heap_start; |
---|
| 88 | |
---|
| 89 | if (getenv("RTEMS_HEAPSPACE_SIZE")) |
---|
| 90 | Heap_size = strtol(getenv("RTEMS_HEAPSPACE_SIZE"), 0, 0); |
---|
| 91 | else |
---|
| 92 | Heap_size = DEFAULT_HEAPSPACE_SIZE; |
---|
| 93 | |
---|
| 94 | heap_start = 0; |
---|
| 95 | |
---|
| 96 | bsp_libc_init((void *)heap_start, Heap_size, 1024 * 1024); |
---|
| 97 | |
---|
[637df35] | 98 | |
---|
| 99 | #ifdef RTEMS_DEBUG |
---|
| 100 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
| 101 | #endif |
---|
[1f94ed6b] | 102 | |
---|
| 103 | /* |
---|
| 104 | * Dump malloc stats on exit... |
---|
| 105 | */ |
---|
| 106 | #if defined(RTEMS_DEBUG) |
---|
| 107 | atexit(malloc_dump); |
---|
| 108 | #endif |
---|
[637df35] | 109 | } |
---|
| 110 | |
---|
[3a4ae6c] | 111 | /* |
---|
[8f95b5f] | 112 | * DO NOT Use the shared bsp_postdriver_hook() implementation |
---|
[3a4ae6c] | 113 | */ |
---|
| 114 | |
---|
[b6394ae] | 115 | void bsp_postdriver_hook(void) |
---|
[3a4ae6c] | 116 | { |
---|
[8f95b5f] | 117 | return; |
---|
[3a4ae6c] | 118 | } |
---|
| 119 | |
---|
[637df35] | 120 | /* |
---|
[b6394ae] | 121 | * bsp_start |
---|
[637df35] | 122 | * |
---|
[b6394ae] | 123 | * This routine does the bulk of the system initialization. |
---|
[637df35] | 124 | */ |
---|
| 125 | |
---|
[b6394ae] | 126 | void bsp_start(void) |
---|
[637df35] | 127 | { |
---|
[c1403ef1] | 128 | unsigned32 workspace_ptr; |
---|
[637df35] | 129 | |
---|
| 130 | /* |
---|
[bd9c3d1] | 131 | * Copy the table (normally done in shared main). |
---|
[637df35] | 132 | */ |
---|
| 133 | |
---|
| 134 | BSP_Configuration = Configuration; |
---|
| 135 | |
---|
| 136 | /* |
---|
[c1403ef1] | 137 | * If the node number is -1 then the application better provide |
---|
| 138 | * it through environment variables RTEMS_NODE. |
---|
| 139 | * Ditto for RTEMS_MAXIMUM_NODES |
---|
[637df35] | 140 | */ |
---|
| 141 | |
---|
| 142 | if (BSP_Configuration.User_multiprocessing_table) { |
---|
[c1403ef1] | 143 | char *p; |
---|
| 144 | |
---|
| 145 | /* make a copy for possible editing */ |
---|
| 146 | BSP_Multiprocessing = *BSP_Configuration.User_multiprocessing_table; |
---|
| 147 | BSP_Configuration.User_multiprocessing_table = &BSP_Multiprocessing; |
---|
| 148 | |
---|
| 149 | if (BSP_Multiprocessing.node == -1) |
---|
| 150 | { |
---|
| 151 | p = getenv("RTEMS_NODE"); |
---|
| 152 | BSP_Multiprocessing.node = p ? atoi(p) : 1; |
---|
[637df35] | 153 | } |
---|
[c1403ef1] | 154 | |
---|
| 155 | /* If needed provide maximum_nodes also */ |
---|
| 156 | if (BSP_Multiprocessing.maximum_nodes == -1) |
---|
| 157 | { |
---|
| 158 | p = getenv("RTEMS_MAXIMUM_NODES"); |
---|
| 159 | BSP_Multiprocessing.maximum_nodes = p ? atoi(p) : 1; |
---|
[637df35] | 160 | } |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | /* |
---|
| 164 | * Set cpu_number to accurately reflect our cpu number |
---|
| 165 | */ |
---|
| 166 | |
---|
| 167 | if (BSP_Configuration.User_multiprocessing_table) |
---|
| 168 | cpu_number = BSP_Configuration.User_multiprocessing_table->node - 1; |
---|
| 169 | else |
---|
| 170 | cpu_number = 0; |
---|
| 171 | |
---|
[c1403ef1] | 172 | if (getenv("RTEMS_WORKSPACE_SIZE")) |
---|
| 173 | BSP_Configuration.work_space_size = |
---|
| 174 | strtol(getenv("RTEMS_WORKSPACE_SIZE"), 0, 0); |
---|
| 175 | else |
---|
| 176 | BSP_Configuration.work_space_size = DEFAULT_WORKSPACE_SIZE; |
---|
| 177 | |
---|
| 178 | /* |
---|
| 179 | * Allocate workspace memory, ensuring it is properly aligned |
---|
| 180 | */ |
---|
| 181 | |
---|
| 182 | workspace_ptr = |
---|
| 183 | (unsigned32) sbrk(BSP_Configuration.work_space_size + CPU_ALIGNMENT); |
---|
| 184 | workspace_ptr += CPU_ALIGNMENT - 1; |
---|
| 185 | workspace_ptr &= ~(CPU_ALIGNMENT - 1); |
---|
[637df35] | 186 | |
---|
[c1403ef1] | 187 | BSP_Configuration.work_space_start = (void *) workspace_ptr; |
---|
| 188 | |
---|
[637df35] | 189 | /* |
---|
| 190 | * Set up our hooks |
---|
| 191 | * Make sure libc_init is done before drivers init'd so that |
---|
| 192 | * they can use atexit() |
---|
| 193 | */ |
---|
| 194 | |
---|
| 195 | Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */ |
---|
| 196 | |
---|
| 197 | Cpu_table.predriver_hook = NULL; |
---|
| 198 | |
---|
[3a4ae6c] | 199 | Cpu_table.postdriver_hook = bsp_postdriver_hook; |
---|
[637df35] | 200 | |
---|
| 201 | Cpu_table.idle_task = NULL; /* do not override system IDLE task */ |
---|
| 202 | |
---|
| 203 | /* |
---|
| 204 | * Don't zero out the workspace since it is in the BSS under UNIX. |
---|
| 205 | */ |
---|
| 206 | |
---|
| 207 | Cpu_table.do_zero_of_workspace = FALSE; |
---|
| 208 | |
---|
| 209 | /* |
---|
| 210 | * XXX; interrupt stack not currently used, so this doesn't matter |
---|
| 211 | */ |
---|
| 212 | |
---|
| 213 | Cpu_table.interrupt_stack_size = (12 * 1024); |
---|
| 214 | |
---|
[8cbbe312] | 215 | Cpu_table.extra_mpci_receive_server_stack = 0; |
---|
[637df35] | 216 | |
---|
[bd9c3d1] | 217 | /* |
---|
| 218 | * Add 1 extension for MPCI_fatal |
---|
| 219 | */ |
---|
[637df35] | 220 | |
---|
[bd9c3d1] | 221 | if (BSP_Configuration.User_multiprocessing_table) |
---|
| 222 | BSP_Configuration.maximum_extensions++; |
---|
[3a4ae6c] | 223 | |
---|
[bd9c3d1] | 224 | CPU_CLICKS_PER_TICK = 1; |
---|
[3a4ae6c] | 225 | |
---|
[bd9c3d1] | 226 | /* |
---|
| 227 | * Start most of RTEMS |
---|
| 228 | * main() will start the rest |
---|
| 229 | */ |
---|
[637df35] | 230 | |
---|
[bd9c3d1] | 231 | bsp_isr_level = rtems_initialize_executive_early( |
---|
| 232 | &BSP_Configuration, |
---|
| 233 | &Cpu_table |
---|
| 234 | ); |
---|
[637df35] | 235 | } |
---|