[a800d09c] | 1 | /* bspstart.c |
---|
| 2 | * |
---|
| 3 | * This set of routines 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 | * COPYRIGHT (c) 1989-1998. |
---|
| 9 | * On-Line Applications Research Corporation (OAR). |
---|
| 10 | * |
---|
| 11 | * The license and distribution terms for this file may be |
---|
| 12 | * found in the file LICENSE in this distribution or at |
---|
| 13 | * http://www.rtems.com/license/LICENSE. |
---|
| 14 | * |
---|
| 15 | * SS555 port sponsored by Defence Research and Development Canada - Suffield |
---|
| 16 | * Copyright (C) 2004, Real-Time Systems Inc. (querbach@realtime.bc.ca) |
---|
| 17 | * |
---|
| 18 | * Derived from c/src/lib/libbsp/powerpc/mbx8xx/startup/bspstart.c: |
---|
| 19 | * |
---|
| 20 | * Modifications for MBX860: |
---|
| 21 | * Copyright (c) 1999, National Research Council of Canada |
---|
| 22 | * |
---|
| 23 | * $Id$ |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include <string.h> |
---|
| 27 | |
---|
| 28 | #include <rtems/libio.h> |
---|
| 29 | #include <rtems/libcsupport.h> |
---|
| 30 | #include <rtems/bspIo.h> |
---|
[1899fe4] | 31 | #include <rtems/powerpc/powerpc.h> |
---|
[a800d09c] | 32 | |
---|
| 33 | #include <libcpu/cpuIdent.h> |
---|
| 34 | #include <libcpu/spr.h> |
---|
| 35 | |
---|
| 36 | #include <bsp/irq.h> |
---|
| 37 | #include <bsp.h> |
---|
| 38 | |
---|
| 39 | SPR_RW(SPRG0) |
---|
| 40 | SPR_RW(SPRG1) |
---|
| 41 | |
---|
| 42 | /* |
---|
| 43 | * The original table from the application (in ROM) and our copy of it with |
---|
| 44 | * some changes. Configuration is defined in <confdefs.h>. Make sure that |
---|
| 45 | * our configuration tables are uninitialized so that they get allocated in |
---|
| 46 | * the .bss section (RAM). |
---|
| 47 | */ |
---|
| 48 | extern rtems_configuration_table Configuration; |
---|
| 49 | extern unsigned long intrStackPtr; |
---|
| 50 | rtems_configuration_table BSP_Configuration; |
---|
| 51 | |
---|
| 52 | rtems_cpu_table Cpu_table; |
---|
| 53 | |
---|
| 54 | char *rtems_progname; |
---|
| 55 | |
---|
| 56 | /* |
---|
| 57 | * Use the shared implementations of the following routines. |
---|
| 58 | * Look in rtems/c/src/lib/libbsp/shared/bsppost.c and |
---|
| 59 | * rtems/c/src/lib/libbsp/shared/bsplibc.c. |
---|
| 60 | */ |
---|
| 61 | void bsp_postdriver_hook(void); |
---|
[76f9c44] | 62 | void bsp_libc_init( void *, uint32_t, int ); |
---|
[a800d09c] | 63 | |
---|
| 64 | void BSP_panic(char *s) |
---|
| 65 | { |
---|
| 66 | printk("%s PANIC %s\n",_RTEMS_version, s); |
---|
[6128a4a] | 67 | __asm__ __volatile ("sc"); |
---|
[a800d09c] | 68 | } |
---|
| 69 | |
---|
| 70 | void _BSP_Fatal_error(unsigned int v) |
---|
| 71 | { |
---|
| 72 | printk("%s PANIC ERROR %x\n",_RTEMS_version, v); |
---|
[6128a4a] | 73 | __asm__ __volatile ("sc"); |
---|
[a800d09c] | 74 | } |
---|
| 75 | |
---|
| 76 | /* |
---|
| 77 | * bsp_pretasking_hook |
---|
| 78 | * |
---|
| 79 | * Called when RTEMS initialization is complete but before interrupts and |
---|
| 80 | * tasking are enabled. Used to setup libc and install any BSP extensions. |
---|
| 81 | * |
---|
| 82 | * Must not use libc (to do io) from here, since drivers are not yet |
---|
| 83 | * initialized. |
---|
| 84 | * |
---|
| 85 | * Installed in the rtems_cpu_table defined in |
---|
| 86 | * rtems/c/src/exec/score/cpu/powerpc/rtems/new-exceptions/cpu.h by main() |
---|
| 87 | * below. Called from rtems_initialize_executive() defined in |
---|
| 88 | * rtems/c/src/exec/sapi/src/init.c |
---|
| 89 | * |
---|
| 90 | * Input parameters: NONE |
---|
| 91 | * |
---|
| 92 | * Output parameters: NONE |
---|
| 93 | * |
---|
| 94 | * Return values: NONE |
---|
| 95 | */ |
---|
| 96 | void bsp_pretasking_hook(void) |
---|
| 97 | { |
---|
[6128a4a] | 98 | /* |
---|
[a800d09c] | 99 | * These are assigned addresses in the linkcmds file for the BSP. This |
---|
| 100 | * approach is better than having these defined as manifest constants and |
---|
| 101 | * compiled into the kernel, but it is still not ideal when dealing with |
---|
| 102 | * multiprocessor configuration in which each board as a different memory |
---|
| 103 | * map. A better place for defining these symbols might be the makefiles. |
---|
| 104 | * Consideration should also be given to developing an approach in which |
---|
| 105 | * the kernel and the application can be linked and burned into ROM |
---|
| 106 | * independently of each other. |
---|
| 107 | */ |
---|
[106e048] | 108 | uint8_t *_HeapStart = |
---|
| 109 | (uint8_t *)BSP_Configuration.work_space_start |
---|
[a800d09c] | 110 | + BSP_Configuration.work_space_size; |
---|
[106e048] | 111 | extern uint8_t _HeapEnd[]; |
---|
[a800d09c] | 112 | |
---|
| 113 | bsp_libc_init( _HeapStart, _HeapEnd - _HeapStart, 0 ); |
---|
[6128a4a] | 114 | |
---|
[a800d09c] | 115 | #ifdef RTEMS_DEBUG |
---|
| 116 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
| 117 | #endif |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | /* |
---|
| 121 | * bsp_start() |
---|
| 122 | * |
---|
| 123 | * Board-specific initialization code. Called from the generic boot_card() |
---|
| 124 | * function defined in rtems/c/src/lib/libbsp/shared/main.c. That function |
---|
| 125 | * does some of the board independent initialization. It is called from the |
---|
| 126 | * SS555 entry point _start() defined in |
---|
| 127 | * rtems/c/src/lib/libbsp/powerpc/ss555/startup/start.S |
---|
| 128 | * |
---|
| 129 | * _start() has set up a stack, has zeroed the .bss section, has set up the |
---|
| 130 | * .data section from contents stored in ROM, has turned off interrupts, |
---|
| 131 | * and placed the processor in the supervisor mode. boot_card() has left |
---|
| 132 | * the processor in that state when bsp_start() was called. |
---|
| 133 | * |
---|
| 134 | * Input parameters: NONE |
---|
| 135 | * |
---|
| 136 | * Output parameters: NONE |
---|
| 137 | * |
---|
| 138 | * Return values: NONE |
---|
| 139 | */ |
---|
| 140 | void bsp_start(void) |
---|
| 141 | { |
---|
| 142 | extern char _WorkspaceBase[]; |
---|
[6128a4a] | 143 | |
---|
[a800d09c] | 144 | ppc_cpu_id_t myCpu; |
---|
| 145 | ppc_cpu_revision_t myCpuRevision; |
---|
| 146 | register unsigned char* intrStack; |
---|
[6128a4a] | 147 | |
---|
[a800d09c] | 148 | /* |
---|
| 149 | * Get CPU identification dynamically. Note that the get_ppc_cpu_type() |
---|
| 150 | * function stores the result in global variables so that it can be used |
---|
| 151 | * later. |
---|
| 152 | */ |
---|
| 153 | myCpu = get_ppc_cpu_type(); |
---|
| 154 | myCpuRevision = get_ppc_cpu_revision(); |
---|
| 155 | |
---|
| 156 | /* |
---|
| 157 | * Initialize some SPRG registers related to irq handling |
---|
| 158 | */ |
---|
[1899fe4] | 159 | intrStack = (((unsigned char*)&intrStackPtr) - PPC_MINIMUM_STACK_FRAME_SIZE); |
---|
[a800d09c] | 160 | _write_SPRG1((unsigned int)intrStack); |
---|
| 161 | /* signal them that we have fixed PR288 - eventually, this should go away */ |
---|
| 162 | _write_SPRG0(PPC_BSP_HAS_FIXED_PR288); |
---|
| 163 | |
---|
| 164 | /* |
---|
| 165 | * Install our own set of exception vectors |
---|
| 166 | */ |
---|
| 167 | initialize_exceptions(); |
---|
| 168 | |
---|
| 169 | /* |
---|
| 170 | * Allocate the memory for the RTEMS Work Space. This can come from |
---|
| 171 | * a variety of places: hard coded address, malloc'ed from outside |
---|
| 172 | * RTEMS world (e.g. simulator or primitive memory manager), or (as |
---|
| 173 | * typically done by stock BSPs) by subtracting the required amount |
---|
| 174 | * of work space from the last physical address on the CPU board. |
---|
| 175 | * |
---|
| 176 | * In this case, the memory is not malloc'ed. It is just |
---|
| 177 | * "pulled from the air". |
---|
| 178 | */ |
---|
| 179 | BSP_Configuration.work_space_start = _WorkspaceBase; |
---|
| 180 | |
---|
| 181 | /* |
---|
| 182 | * initialize the CPU table for this BSP |
---|
| 183 | */ |
---|
| 184 | Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */ |
---|
| 185 | Cpu_table.postdriver_hook = bsp_postdriver_hook; |
---|
| 186 | if( Cpu_table.interrupt_stack_size < 4 * 1024 ) |
---|
| 187 | Cpu_table.interrupt_stack_size = 4 * 1024; |
---|
| 188 | |
---|
| 189 | Cpu_table.clicks_per_usec = BSP_CRYSTAL_HZ / 4 / 1000000; |
---|
| 190 | Cpu_table.clock_speed = BSP_CLOCK_HZ; /* for SCI baud rate generator */ |
---|
| 191 | |
---|
[6128a4a] | 192 | /* |
---|
[a800d09c] | 193 | * Call this in case we use TERMIOS for console I/O |
---|
| 194 | */ |
---|
| 195 | m5xx_uart_reserve_resources( &BSP_Configuration ); |
---|
| 196 | |
---|
| 197 | /* |
---|
| 198 | * Initalize RTEMS IRQ system |
---|
| 199 | */ |
---|
| 200 | BSP_rtems_irq_mng_init(0); |
---|
| 201 | } |
---|