[b6394ae] | 1 | /* |
---|
[8961188] | 2 | * This set of routines 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 any of these are invoked. |
---|
| 6 | * |
---|
[08311cc3] | 7 | * COPYRIGHT (c) 1989-1999. |
---|
[8961188] | 8 | * On-Line Applications Research Corporation (OAR). |
---|
| 9 | * |
---|
[b6394ae] | 10 | * The license and distribution terms for this file may be |
---|
| 11 | * found in the file LICENSE in this distribution or at |
---|
[9d2bdb5] | 12 | * http://www.rtems.com/license/LICENSE. |
---|
[8961188] | 13 | * |
---|
| 14 | * $Id$ |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | #include <string.h> |
---|
| 18 | #include <fcntl.h> |
---|
[eba2e4f] | 19 | #include <bsp.h> |
---|
[270ce1ff] | 20 | #include <bsp/irq.h> |
---|
[eba2e4f] | 21 | #include <rtems/libio.h> |
---|
| 22 | #include <rtems/libcsupport.h> |
---|
[f844cfcc] | 23 | #include <rtems/bspIo.h> |
---|
[1899fe4] | 24 | #include <rtems/powerpc/powerpc.h> |
---|
| 25 | |
---|
[270ce1ff] | 26 | #include <libcpu/cpuIdent.h> |
---|
| 27 | #include <libcpu/spr.h> |
---|
| 28 | |
---|
| 29 | SPR_RW(SPRG0) |
---|
| 30 | SPR_RW(SPRG1) |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | extern unsigned long __rtems_end[]; |
---|
| 34 | |
---|
| 35 | void initialize_exceptions(void); |
---|
| 36 | |
---|
| 37 | /* On psim, each click of the decrementer register corresponds |
---|
| 38 | * to 1 instruction. By setting this to 100, we are indicating |
---|
| 39 | * that we are assuming it can execute 100 instructions per |
---|
| 40 | * microsecond. This corresponds to sustaining 1 instruction |
---|
| 41 | * per cycle at 100 Mhz. Whether this is a good guess or not |
---|
| 42 | * is anyone's guess. |
---|
| 43 | */ |
---|
| 44 | |
---|
| 45 | extern int PSIM_INSTRUCTIONS_PER_MICROSECOND; |
---|
[eba2e4f] | 46 | |
---|
[8961188] | 47 | /* |
---|
| 48 | * The original table from the application and our copy of it with |
---|
| 49 | * some changes. |
---|
| 50 | */ |
---|
[6128a4a] | 51 | |
---|
[8961188] | 52 | extern rtems_configuration_table Configuration; |
---|
| 53 | rtems_configuration_table BSP_Configuration; |
---|
| 54 | rtems_cpu_table Cpu_table; |
---|
| 55 | |
---|
| 56 | /* |
---|
| 57 | * Tells us where to put the workspace in case remote debugger is present. |
---|
| 58 | */ |
---|
| 59 | |
---|
| 60 | #if 0 |
---|
[3f71ac1] | 61 | extern uint32_t rdb_start; |
---|
[8961188] | 62 | #endif |
---|
| 63 | |
---|
[270ce1ff] | 64 | /* |
---|
| 65 | * PCI Bus Frequency |
---|
| 66 | */ |
---|
| 67 | unsigned int BSP_bus_frequency; |
---|
| 68 | /* |
---|
| 69 | * * Time base divisior (how many tick for 1 second). |
---|
| 70 | * */ |
---|
| 71 | unsigned int BSP_time_base_divisor; |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | |
---|
[8961188] | 75 | /* |
---|
[b6394ae] | 76 | * Use the shared implementations of the following routines |
---|
| 77 | */ |
---|
[6128a4a] | 78 | |
---|
[b6394ae] | 79 | void bsp_postdriver_hook(void); |
---|
[3f71ac1] | 80 | void bsp_libc_init( void *, uint32_t, int ); |
---|
[b6394ae] | 81 | |
---|
[270ce1ff] | 82 | /* |
---|
| 83 | * system init stack and soft ir stack size |
---|
| 84 | */ |
---|
| 85 | #define INIT_STACK_SIZE 0x1000 |
---|
| 86 | #define INTR_STACK_SIZE CONFIGURE_INTERRUPT_STACK_MEMORY |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | void BSP_panic(char *s) |
---|
| 90 | { |
---|
| 91 | printk("%s PANIC %s\n",_RTEMS_version, s); |
---|
| 92 | __asm__ __volatile ("sc"); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | void _BSP_Fatal_error(unsigned int v) |
---|
| 96 | { |
---|
| 97 | printk("%s PANIC ERROR %x\n",_RTEMS_version, v); |
---|
| 98 | __asm__ __volatile ("sc"); |
---|
| 99 | } |
---|
| 100 | |
---|
[b6394ae] | 101 | /* |
---|
| 102 | * bsp_pretasking_hook |
---|
[8961188] | 103 | * |
---|
[b6394ae] | 104 | * BSP pretasking hook. Called just before drivers are initialized. |
---|
| 105 | * Used to setup libc and install any BSP extensions. |
---|
[8961188] | 106 | */ |
---|
| 107 | |
---|
[b6394ae] | 108 | void bsp_pretasking_hook(void) |
---|
[8961188] | 109 | { |
---|
| 110 | extern int end; |
---|
[3f71ac1] | 111 | uint32_t heap_start; |
---|
| 112 | uint32_t heap_size; |
---|
[8961188] | 113 | |
---|
[3f71ac1] | 114 | heap_start = (uint32_t) &end; |
---|
[8961188] | 115 | if (heap_start & (CPU_ALIGNMENT-1)) |
---|
| 116 | heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1); |
---|
| 117 | |
---|
| 118 | heap_size = BSP_Configuration.work_space_start - (void *)&end; |
---|
| 119 | heap_size &= 0xfffffff0; /* keep it as a multiple of 16 bytes */ |
---|
| 120 | |
---|
[b6394ae] | 121 | bsp_libc_init((void *) heap_start, heap_size, 0); |
---|
[8961188] | 122 | |
---|
| 123 | #ifdef RTEMS_DEBUG |
---|
| 124 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
| 125 | #endif |
---|
| 126 | |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | /* |
---|
| 130 | * bsp_start |
---|
| 131 | * |
---|
| 132 | * This routine does the bulk of the system initialization. |
---|
| 133 | */ |
---|
| 134 | |
---|
| 135 | void bsp_start( void ) |
---|
| 136 | { |
---|
[270ce1ff] | 137 | unsigned char *work_space_start; |
---|
| 138 | register uint32_t intrStack; |
---|
| 139 | register uint32_t *intrStackPtr; |
---|
[8961188] | 140 | |
---|
[6128a4a] | 141 | /* |
---|
[270ce1ff] | 142 | * Note we can not get CPU identification dynamically, so force current_ppc_cpu. |
---|
[8961188] | 143 | */ |
---|
[270ce1ff] | 144 | current_ppc_cpu = PPC_PSIM; |
---|
[8961188] | 145 | |
---|
| 146 | /* |
---|
| 147 | * Set up our hooks |
---|
| 148 | * Make sure libc_init is done before drivers initialized so that |
---|
| 149 | * they can use atexit() |
---|
| 150 | */ |
---|
| 151 | |
---|
| 152 | Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */ |
---|
| 153 | Cpu_table.postdriver_hook = bsp_postdriver_hook; |
---|
| 154 | |
---|
| 155 | /* |
---|
[bd9c3d1] | 156 | * Is this true? |
---|
| 157 | * |
---|
[8961188] | 158 | * PSIM does zero out memory BUT only when IT begins execution. Thus |
---|
| 159 | * if we want to have a clean slate in the workspace each time we |
---|
| 160 | * begin execution of OUR application, then we must zero the workspace. |
---|
[bd9c3d1] | 161 | * |
---|
| 162 | * It is true that it takes simulated time to clear the memory. |
---|
[8961188] | 163 | */ |
---|
| 164 | |
---|
| 165 | Cpu_table.do_zero_of_workspace = FALSE; |
---|
| 166 | |
---|
[df49c60] | 167 | Cpu_table.interrupt_stack_size = CONFIGURE_INTERRUPT_STACK_MEMORY; |
---|
[8961188] | 168 | |
---|
[270ce1ff] | 169 | BSP_bus_frequency = (unsigned int)&PSIM_INSTRUCTIONS_PER_MICROSECOND; |
---|
| 170 | BSP_time_base_divisor = 1; |
---|
| 171 | |
---|
[8961188] | 172 | /* |
---|
[270ce1ff] | 173 | * The simulator likes the exception table to be at 0xfff00000. |
---|
[8961188] | 174 | */ |
---|
| 175 | |
---|
[270ce1ff] | 176 | Cpu_table.exceptions_in_RAM = FALSE; |
---|
[8961188] | 177 | |
---|
[2e34f4ad] | 178 | BSP_Configuration.work_space_size += 1024; |
---|
[8961188] | 179 | |
---|
[6128a4a] | 180 | work_space_start = |
---|
[8961188] | 181 | (unsigned char *)&RAM_END - BSP_Configuration.work_space_size; |
---|
| 182 | |
---|
| 183 | if ( work_space_start <= (unsigned char *)&end ) { |
---|
[e177810d] | 184 | printk( "bspstart: Not enough RAM!!!\n" ); |
---|
[8961188] | 185 | bsp_cleanup(); |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | BSP_Configuration.work_space_start = work_space_start; |
---|
[21ca2199] | 189 | #if defined(BSP_DIRTY_MEMORY) |
---|
| 190 | { |
---|
| 191 | memset(&end, 0xCF, (unsigned char *)&RAM_END - (unsigned char *)&end ); |
---|
| 192 | } |
---|
| 193 | #endif |
---|
[8961188] | 194 | |
---|
[270ce1ff] | 195 | /* |
---|
| 196 | * Initialize the interrupt related settings |
---|
| 197 | * SPRG1 = software managed IRQ stack |
---|
| 198 | * |
---|
| 199 | * This could be done latter (e.g in IRQ_INIT) but it helps to understand |
---|
| 200 | * some settings below... |
---|
| 201 | */ |
---|
| 202 | intrStack = ((uint32_t) __rtems_end) + |
---|
[1899fe4] | 203 | INIT_STACK_SIZE + INTR_STACK_SIZE - PPC_MINIMUM_STACK_FRAME_SIZE; |
---|
[270ce1ff] | 204 | |
---|
| 205 | /* make sure it's properly aligned */ |
---|
| 206 | intrStack &= ~(CPU_STACK_ALIGNMENT-1); |
---|
| 207 | |
---|
| 208 | /* tag the bottom (T. Straumann 6/36/2001 <strauman@slac.stanford.edu>) */ |
---|
| 209 | intrStackPtr = (uint32_t*) intrStack; |
---|
| 210 | *intrStackPtr = 0; |
---|
| 211 | |
---|
| 212 | _write_SPRG1(intrStack); |
---|
| 213 | |
---|
| 214 | /* signal them that we have fixed PR288 - eventually, this should go away */ |
---|
| 215 | _write_SPRG0(PPC_BSP_HAS_FIXED_PR288); |
---|
| 216 | |
---|
| 217 | /* |
---|
[28d241b] | 218 | * Initialize default raw exception handlers. See vectors/vectors_init.c |
---|
[270ce1ff] | 219 | */ |
---|
| 220 | initialize_exceptions(); |
---|
| 221 | |
---|
| 222 | /* |
---|
| 223 | * Initalize RTEMS IRQ system |
---|
| 224 | */ |
---|
| 225 | BSP_rtems_irq_mng_init(0); |
---|
| 226 | |
---|
[8961188] | 227 | } |
---|