[457b6ae] | 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 | * INPUT: NONE |
---|
| 9 | * |
---|
| 10 | * OUTPUT: NONE |
---|
| 11 | * |
---|
| 12 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
| 13 | * On-Line Applications Research Corporation (OAR). |
---|
| 14 | * All rights assigned to U.S. Government, 1994. |
---|
| 15 | * |
---|
| 16 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
| 17 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
| 18 | * notice must appear in all copies of this file and its derivatives. |
---|
| 19 | * |
---|
| 20 | * $Id$ |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | #include <bsp.h> |
---|
| 24 | #include <rtems/libio.h> |
---|
| 25 | |
---|
| 26 | #include <libcsupport.h> |
---|
| 27 | |
---|
| 28 | #include <string.h> |
---|
| 29 | #include <fcntl.h> |
---|
| 30 | |
---|
| 31 | #ifdef STACK_CHECKER_ON |
---|
| 32 | #include <stackchk.h> |
---|
| 33 | #endif |
---|
| 34 | |
---|
| 35 | /* |
---|
| 36 | * The original table from the application and our copy of it with |
---|
| 37 | * some changes. |
---|
| 38 | */ |
---|
| 39 | |
---|
| 40 | extern rtems_configuration_table Configuration; |
---|
| 41 | rtems_configuration_table BSP_Configuration; |
---|
| 42 | |
---|
| 43 | rtems_cpu_table Cpu_table; |
---|
| 44 | |
---|
| 45 | char *rtems_progname; |
---|
| 46 | |
---|
| 47 | /* Initialize whatever libc we are using |
---|
| 48 | * called from postdriver hook |
---|
| 49 | */ |
---|
| 50 | |
---|
| 51 | void bsp_libc_init() |
---|
| 52 | { |
---|
| 53 | extern void *_HeapStart; |
---|
| 54 | extern rtems_unsigned32 _HeapSize; |
---|
| 55 | |
---|
| 56 | /* |
---|
| 57 | * The last parameter to RTEMS_Malloc_Initialize is the "chunk" |
---|
| 58 | * size which a multiple of will be requested on each sbrk() |
---|
| 59 | * call by malloc(). A value of 0 indicates that sbrk() should |
---|
| 60 | * not be called to extend the heap. |
---|
| 61 | */ |
---|
| 62 | |
---|
| 63 | RTEMS_Malloc_Initialize(&_HeapStart, _HeapSize, 0); |
---|
| 64 | |
---|
| 65 | /* |
---|
| 66 | * Init the RTEMS libio facility to provide UNIX-like system |
---|
[634e746] | 67 | * calls for use by newlib (ie: provide __rtems_open, __rtems_close, etc) |
---|
[457b6ae] | 68 | * Uses malloc() to get area for the iops, so must be after malloc init |
---|
| 69 | */ |
---|
| 70 | |
---|
| 71 | rtems_libio_init(); |
---|
| 72 | |
---|
| 73 | /* |
---|
| 74 | * Set up for the libc handling. |
---|
| 75 | */ |
---|
| 76 | |
---|
| 77 | if (BSP_Configuration.ticks_per_timeslice > 0) |
---|
| 78 | libc_init(1); /* reentrant if possible */ |
---|
| 79 | else |
---|
| 80 | libc_init(0); /* non-reentrant */ |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | /* |
---|
| 84 | * Function: bsp_pretasking_hook |
---|
| 85 | * Created: 95/03/10 |
---|
| 86 | * |
---|
| 87 | * Description: |
---|
| 88 | * BSP pretasking hook. Called just before drivers are initialized. |
---|
| 89 | * Used to setup libc and install any BSP extensions. |
---|
| 90 | * |
---|
| 91 | * NOTES: |
---|
| 92 | * Must not use libc (to do io) from here, since drivers are |
---|
| 93 | * not yet initialized. |
---|
| 94 | * |
---|
| 95 | */ |
---|
| 96 | |
---|
| 97 | void |
---|
| 98 | bsp_pretasking_hook(void) |
---|
| 99 | { |
---|
| 100 | bsp_libc_init(); |
---|
| 101 | |
---|
| 102 | #ifdef STACK_CHECKER_ON |
---|
| 103 | /* |
---|
| 104 | * Initialize the stack bounds checker |
---|
| 105 | * We can either turn it on here or from the app. |
---|
| 106 | */ |
---|
| 107 | |
---|
| 108 | Stack_check_Initialize(); |
---|
| 109 | #endif |
---|
| 110 | |
---|
| 111 | #ifdef RTEMS_DEBUG |
---|
| 112 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
| 113 | #endif |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | /* |
---|
| 118 | * After drivers are setup, register some "filenames" |
---|
| 119 | * and open stdin, stdout, stderr files |
---|
| 120 | * |
---|
| 121 | * Newlib will automatically associate the files with these |
---|
| 122 | * (it hardcodes the numbers) |
---|
| 123 | */ |
---|
| 124 | |
---|
| 125 | void |
---|
| 126 | bsp_postdriver_hook(void) |
---|
| 127 | { |
---|
| 128 | int stdin_fd, stdout_fd, stderr_fd; |
---|
| 129 | int error_code; |
---|
| 130 | |
---|
| 131 | error_code = 'S' << 24 | 'T' << 16; |
---|
| 132 | |
---|
[634e746] | 133 | if ((stdin_fd = __rtems_open("/dev/console", O_RDONLY, 0)) == -1) |
---|
[457b6ae] | 134 | rtems_fatal_error_occurred( error_code | 'D' << 8 | '0' ); |
---|
| 135 | |
---|
[634e746] | 136 | if ((stdout_fd = __rtems_open("/dev/console", O_WRONLY, 0)) == -1) |
---|
[457b6ae] | 137 | rtems_fatal_error_occurred( error_code | 'D' << 8 | '1' ); |
---|
| 138 | |
---|
[634e746] | 139 | if ((stderr_fd = __rtems_open("/dev/console", O_WRONLY, 0)) == -1) |
---|
[457b6ae] | 140 | rtems_fatal_error_occurred( error_code | 'D' << 8 | '2' ); |
---|
| 141 | |
---|
| 142 | if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2)) |
---|
| 143 | rtems_fatal_error_occurred( error_code | 'I' << 8 | 'O' ); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | int main( |
---|
| 147 | int argc, |
---|
| 148 | char **argv, |
---|
| 149 | char **environp |
---|
| 150 | ) |
---|
| 151 | { |
---|
| 152 | extern void *_WorkspaceBase; |
---|
| 153 | if ((argc > 0) && argv && argv[0]) |
---|
| 154 | rtems_progname = argv[0]; |
---|
| 155 | else |
---|
| 156 | rtems_progname = "RTEMS"; |
---|
| 157 | |
---|
| 158 | /* |
---|
| 159 | * Allocate the memory for the RTEMS Work Space. This can come from |
---|
| 160 | * a variety of places: hard coded address, malloc'ed from outside |
---|
| 161 | * RTEMS world (e.g. simulator or primitive memory manager), or (as |
---|
| 162 | * typically done by stock BSPs) by subtracting the required amount |
---|
| 163 | * of work space from the last physical address on the CPU board. |
---|
| 164 | */ |
---|
| 165 | #if 0 |
---|
| 166 | Cpu_table.interrupt_vector_table = (mc68000_isr *) 0/*&M68Kvec*/; |
---|
| 167 | #endif |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | /* |
---|
| 171 | * Copy the Configuration Table .. so we can change it |
---|
| 172 | */ |
---|
| 173 | |
---|
| 174 | BSP_Configuration = Configuration; |
---|
| 175 | |
---|
| 176 | /* |
---|
| 177 | * Add 1 region for the RTEMS Malloc |
---|
| 178 | */ |
---|
| 179 | |
---|
[e6d4b1d] | 180 | BSP_Configuration.RTEMS_api_configuration->maximum_regions++; |
---|
[457b6ae] | 181 | |
---|
| 182 | /* |
---|
| 183 | * Add 1 extension for newlib libc |
---|
| 184 | */ |
---|
| 185 | |
---|
| 186 | #ifdef RTEMS_NEWLIB |
---|
| 187 | BSP_Configuration.maximum_extensions++; |
---|
| 188 | #endif |
---|
| 189 | |
---|
| 190 | /* |
---|
| 191 | * Add another extension if using the stack checker |
---|
| 192 | */ |
---|
| 193 | |
---|
| 194 | #ifdef STACK_CHECKER_ON |
---|
| 195 | BSP_Configuration.maximum_extensions++; |
---|
| 196 | #endif |
---|
| 197 | |
---|
| 198 | /* |
---|
| 199 | * Tell libio how many fd's we want and allow it to tweak config |
---|
| 200 | */ |
---|
| 201 | |
---|
| 202 | rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS); |
---|
| 203 | |
---|
| 204 | /* |
---|
| 205 | * Need to "allocate" the memory for the RTEMS Workspace and |
---|
| 206 | * tell the RTEMS configuration where it is. This memory is |
---|
| 207 | * not malloc'ed. It is just "pulled from the air". |
---|
| 208 | */ |
---|
| 209 | |
---|
| 210 | BSP_Configuration.work_space_start = (void *)&_WorkspaceBase; |
---|
| 211 | |
---|
| 212 | /* |
---|
| 213 | * initialize the CPU table for this BSP |
---|
| 214 | */ |
---|
| 215 | |
---|
| 216 | /* |
---|
| 217 | * we do not use the pretasking_hook |
---|
| 218 | */ |
---|
| 219 | |
---|
| 220 | Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */ |
---|
| 221 | |
---|
| 222 | Cpu_table.predriver_hook = NULL; |
---|
| 223 | |
---|
| 224 | Cpu_table.postdriver_hook = bsp_postdriver_hook; |
---|
| 225 | |
---|
| 226 | Cpu_table.idle_task = NULL; /* do not override system IDLE task */ |
---|
| 227 | |
---|
| 228 | Cpu_table.do_zero_of_workspace = TRUE; |
---|
| 229 | |
---|
| 230 | Cpu_table.interrupt_stack_size = 4096; |
---|
| 231 | |
---|
[8cf88427] | 232 | Cpu_table.extra_mpci_receive_server_stack = 0; |
---|
[457b6ae] | 233 | |
---|
| 234 | /* |
---|
| 235 | * Don't forget the other CPU Table entries. |
---|
| 236 | */ |
---|
| 237 | |
---|
| 238 | /* |
---|
| 239 | * Start RTEMS |
---|
| 240 | */ |
---|
| 241 | |
---|
| 242 | rtems_initialize_executive( &BSP_Configuration, &Cpu_table ); |
---|
| 243 | |
---|
| 244 | bsp_cleanup(); |
---|
| 245 | |
---|
| 246 | return 0; |
---|
| 247 | } |
---|