[b6394ae] | 1 | /* |
---|
[0836603] | 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. |
---|
[0836603] | 8 | * On-Line Applications Research Corporation (OAR). |
---|
[03f2154e] | 9 | * Copyright assigned to U.S. Government, 1994. |
---|
[0836603] | 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. |
---|
[0836603] | 14 | * |
---|
| 15 | * $Id$ |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | #include <bsp.h> |
---|
| 19 | #include <rtems/libio.h> |
---|
| 20 | |
---|
| 21 | #include <libcsupport.h> |
---|
| 22 | |
---|
| 23 | #include <string.h> |
---|
| 24 | |
---|
| 25 | #ifndef lint |
---|
| 26 | static char _sccsid[] = "@(#)bspstart.c 09/11/96 1.15\n"; |
---|
| 27 | #endif |
---|
| 28 | |
---|
| 29 | /* |
---|
| 30 | * The original table from the application and our copy of it with |
---|
| 31 | * some changes. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | extern rtems_configuration_table Configuration; |
---|
| 35 | |
---|
| 36 | rtems_configuration_table BSP_Configuration; |
---|
| 37 | |
---|
| 38 | rtems_cpu_table Cpu_table; |
---|
| 39 | |
---|
| 40 | char *rtems_progname; |
---|
| 41 | |
---|
| 42 | /* Initialize whatever libc we are using |
---|
| 43 | * called from postdriver hook |
---|
| 44 | */ |
---|
| 45 | |
---|
| 46 | #define HEAP_BLOCK_SIZE (16 * 1024) |
---|
| 47 | |
---|
| 48 | rtems_unsigned32 heap_size = 0; |
---|
| 49 | rtems_unsigned32 heap_start; |
---|
| 50 | |
---|
[b6394ae] | 51 | /* |
---|
| 52 | * Use the shared implementations of the following routines |
---|
| 53 | */ |
---|
| 54 | |
---|
| 55 | void bsp_postdriver_hook(void); |
---|
| 56 | void bsp_libc_init( void *, unsigned32, int ); |
---|
[0836603] | 57 | |
---|
| 58 | /* |
---|
| 59 | * Function: bsp_pretasking_hook |
---|
| 60 | * Created: 95/03/10 |
---|
| 61 | * |
---|
| 62 | * Description: |
---|
| 63 | * BSP pretasking hook. Called just before drivers are initialized. |
---|
| 64 | * Used to setup libc and install any BSP extensions. |
---|
| 65 | * |
---|
| 66 | * NOTES: |
---|
| 67 | * Must not use libc (to do io) from here, since drivers are |
---|
| 68 | * not yet initialized. |
---|
| 69 | * |
---|
| 70 | */ |
---|
| 71 | |
---|
[b6394ae] | 72 | void bsp_pretasking_hook(void) |
---|
[0836603] | 73 | { |
---|
[b6394ae] | 74 | /* allocate a maximum of 2 megabytes for the heap */ |
---|
| 75 | heap_size = 2 * 1024 * 1024; |
---|
| 76 | |
---|
| 77 | /* allocate all remaining memory to the heap */ |
---|
| 78 | do { |
---|
| 79 | heap_size -= HEAP_BLOCK_SIZE; |
---|
| 80 | heap_start = _sysalloc( heap_size ); |
---|
| 81 | } while ( !heap_start ); |
---|
| 82 | |
---|
| 83 | if (!heap_start) |
---|
| 84 | rtems_fatal_error_occurred( heap_size ); |
---|
| 85 | |
---|
| 86 | if (heap_start & (CPU_ALIGNMENT-1)) |
---|
| 87 | heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1); |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | bsp_libc_init((void *) heap_start, heap_size, 0); |
---|
| 91 | |
---|
[0836603] | 92 | |
---|
| 93 | #ifdef RTEMS_DEBUG |
---|
| 94 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
| 95 | #endif |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | /* |
---|
[b6394ae] | 99 | * bsp_start |
---|
| 100 | * |
---|
| 101 | * This routine does the bulk of the system initialization. |
---|
[0836603] | 102 | */ |
---|
| 103 | |
---|
| 104 | int bsp_start( |
---|
| 105 | int argc, |
---|
| 106 | char **argv, |
---|
| 107 | char **environp |
---|
| 108 | ) |
---|
| 109 | { |
---|
| 110 | if ((argc > 0) && argv && argv[0]) |
---|
| 111 | rtems_progname = argv[0]; |
---|
| 112 | else |
---|
| 113 | rtems_progname = "RTEMS"; |
---|
| 114 | |
---|
| 115 | /* set the PIA0 register wait states */ |
---|
| 116 | *(volatile unsigned32 *)0x80000020 = 0x04080000; |
---|
| 117 | |
---|
| 118 | /* |
---|
| 119 | * Allocate the memory for the RTEMS Work Space. This can come from |
---|
| 120 | * a variety of places: hard coded address, malloc'ed from outside |
---|
| 121 | * RTEMS world (e.g. simulator or primitive memory manager), or (as |
---|
| 122 | * typically done by stock BSPs) by subtracting the required amount |
---|
| 123 | * of work space from the last physical address on the CPU board. |
---|
| 124 | */ |
---|
| 125 | |
---|
| 126 | /* |
---|
| 127 | * Need to "allocate" the memory for the RTEMS Workspace and |
---|
| 128 | * tell the RTEMS configuration where it is. This memory is |
---|
| 129 | * not malloc'ed. It is just "pulled from the air". |
---|
| 130 | */ |
---|
| 131 | |
---|
| 132 | BSP_Configuration.work_space_start = _sysalloc( BSP_Configuration.work_space_size + 512 ); |
---|
| 133 | if (!BSP_Configuration.work_space_start) |
---|
| 134 | rtems_fatal_error_occurred( BSP_Configuration.work_space_size ); |
---|
| 135 | |
---|
| 136 | BSP_Configuration.work_space_start = (void *) ((unsigned int)((char *)BSP_Configuration.work_space_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1)); |
---|
| 137 | |
---|
| 138 | /* |
---|
| 139 | * initialize the CPU table for this BSP |
---|
| 140 | */ |
---|
| 141 | |
---|
| 142 | Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */ |
---|
| 143 | Cpu_table.postdriver_hook = bsp_postdriver_hook; |
---|
| 144 | Cpu_table.interrupt_stack_size = 4096; |
---|
| 145 | |
---|
| 146 | _settrap( 109,&a29k_enable_sup); |
---|
| 147 | _settrap( 110,&a29k_disable_sup); |
---|
| 148 | _settrap( 111,&a29k_enable_all_sup); |
---|
| 149 | _settrap( 112,&a29k_disable_all_sup); |
---|
| 150 | _settrap( 106,&a29k_context_switch_sup); |
---|
| 151 | _settrap( 107,&a29k_context_restore_sup); |
---|
| 152 | _settrap( 108,&a29k_context_save_sup); |
---|
| 153 | _settrap( 105,&a29k_sigdfl_sup); |
---|
| 154 | |
---|
| 155 | /* |
---|
| 156 | * Start RTEMS |
---|
| 157 | */ |
---|
| 158 | |
---|
| 159 | rtems_initialize_executive( &BSP_Configuration, &Cpu_table ); |
---|
| 160 | |
---|
| 161 | bsp_cleanup(); |
---|
| 162 | |
---|
| 163 | return 0; |
---|
| 164 | } |
---|