[7150f00f] | 1 | /*-------------------------------------------------------------------------+ |
---|
| 2 | | This file contains the PC386 BSP startup package. It includes application, |
---|
| 3 | | board, and monitor specific initialization and configuration. The generic CPU |
---|
[6128a4a] | 4 | | dependent initialization has been performed before this routine is invoked. |
---|
[7150f00f] | 5 | +--------------------------------------------------------------------------+ |
---|
| 6 | | (C) Copyright 1997 - |
---|
| 7 | | - NavIST Group - Real-Time Distributed Systems and Industrial Automation |
---|
| 8 | | |
---|
| 9 | | http://pandora.ist.utl.pt |
---|
| 10 | | |
---|
| 11 | | Instituto Superior Tecnico * Lisboa * PORTUGAL |
---|
| 12 | +--------------------------------------------------------------------------+ |
---|
| 13 | | Disclaimer: |
---|
| 14 | | |
---|
| 15 | | This file is provided "AS IS" without warranty of any kind, either |
---|
| 16 | | expressed or implied. |
---|
| 17 | +--------------------------------------------------------------------------+ |
---|
| 18 | | This code is based on: |
---|
| 19 | | bspstart.c,v 1.8 1996/05/28 13:12:40 joel Exp - go32 BSP |
---|
| 20 | | With the following copyright notice: |
---|
| 21 | | ************************************************************************** |
---|
[08311cc3] | 22 | | * COPYRIGHT (c) 1989-1999. |
---|
[6f9c75c3] | 23 | | * On-Line Applications Research Corporation (OAR). |
---|
| 24 | | * |
---|
| 25 | | * The license and distribution terms for this file may be |
---|
| 26 | | * found in found in the file LICENSE in this distribution or at |
---|
[af2abc9e] | 27 | | * http://www.rtems.com/license/LICENSE. |
---|
[7150f00f] | 28 | | ************************************************************************** |
---|
[6f9c75c3] | 29 | | |
---|
| 30 | | $Id$ |
---|
[7150f00f] | 31 | +--------------------------------------------------------------------------*/ |
---|
| 32 | |
---|
| 33 | #include <bsp.h> |
---|
| 34 | #include <rtems/libio.h> |
---|
[eba2e4f] | 35 | #include <rtems/libcsupport.h> |
---|
[71319f77] | 36 | #include <rtems/pci.h> |
---|
[ab0df696] | 37 | #include <libcpu/cpuModel.h> |
---|
| 38 | |
---|
[7150f00f] | 39 | /*-------------------------------------------------------------------------+ |
---|
| 40 | | Global Variables |
---|
| 41 | +--------------------------------------------------------------------------*/ |
---|
[6fda59f] | 42 | extern uint32_t _end; /* End of BSS. Defined in 'linkcmds'. */ |
---|
[6128a4a] | 43 | /* |
---|
| 44 | * Size of heap if it is 0 it will be dynamically defined by memory size, |
---|
| 45 | * otherwise the value should be changed by binary patch |
---|
[0375c72] | 46 | */ |
---|
[6128a4a] | 47 | uint32_t _heap_size = 0; |
---|
[0375c72] | 48 | |
---|
| 49 | /* Size of stack used during initialization. Defined in 'start.s'. */ |
---|
[6fda59f] | 50 | extern uint32_t _stack_size; |
---|
[7150f00f] | 51 | |
---|
[6fda59f] | 52 | uint32_t rtemsFreeMemStart; |
---|
[7150f00f] | 53 | /* Address of start of free memory - should be updated |
---|
| 54 | after creating new partitions or regions. */ |
---|
| 55 | |
---|
| 56 | /* The original BSP configuration table from the application and our copy of it |
---|
| 57 | with some changes. */ |
---|
| 58 | |
---|
| 59 | extern rtems_configuration_table Configuration; |
---|
| 60 | rtems_configuration_table BSP_Configuration; |
---|
| 61 | |
---|
| 62 | rtems_cpu_table Cpu_table; /* CPU configuration table. */ |
---|
| 63 | char *rtems_progname; /* Program name - from main(). */ |
---|
| 64 | |
---|
| 65 | /*-------------------------------------------------------------------------+ |
---|
| 66 | | External Prototypes |
---|
| 67 | +--------------------------------------------------------------------------*/ |
---|
[8a496e46] | 68 | extern void rtems_irq_mngt_init(void); |
---|
[6fda59f] | 69 | void bsp_libc_init( void *, uint32_t, int ); |
---|
[b6394ae] | 70 | void bsp_postdriver_hook(void); |
---|
[67a2288] | 71 | |
---|
[7150f00f] | 72 | /*-------------------------------------------------------------------------+ |
---|
| 73 | | Function: bsp_pretasking_hook |
---|
| 74 | | Description: BSP pretasking hook. Called just before drivers are |
---|
| 75 | | initialized. Used to setup libc and install any BSP |
---|
| 76 | | extensions. NOTE: Must not use libc (to do io) from here, |
---|
| 77 | | since drivers are not yet initialized. |
---|
| 78 | | Global Variables: None. |
---|
| 79 | | Arguments: None. |
---|
[6128a4a] | 80 | | Returns: Nothing. |
---|
[7150f00f] | 81 | +--------------------------------------------------------------------------*/ |
---|
[b6394ae] | 82 | void bsp_pretasking_hook(void) |
---|
[7150f00f] | 83 | { |
---|
[6fda59f] | 84 | uint32_t topAddr, val; |
---|
[fdcfca01] | 85 | int i, lowest; |
---|
[6128a4a] | 86 | |
---|
[b6394ae] | 87 | if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1)) /* not aligned => align it */ |
---|
| 88 | rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1); |
---|
| 89 | |
---|
[fdcfca01] | 90 | /* find the lowest 1M boundary to probe */ |
---|
| 91 | lowest = ((rtemsFreeMemStart + (1<<20)) >> 20) + 1; |
---|
| 92 | if ( lowest < 2 ) |
---|
| 93 | lowest = 2; |
---|
| 94 | |
---|
| 95 | if (_heap_size == 0) { |
---|
| 96 | /* |
---|
| 97 | * We have to dynamically size memory. Memory size can be anything |
---|
| 98 | * between no less than 2M and 2048M. |
---|
| 99 | * let us first write |
---|
| 100 | */ |
---|
| 101 | for (i=2048; i>=lowest; i--) { |
---|
| 102 | topAddr = i*1024*1024 - 4; |
---|
| 103 | *(volatile uint32_t*)topAddr = topAddr; |
---|
[0375c72] | 104 | } |
---|
[6128a4a] | 105 | |
---|
[fdcfca01] | 106 | for(i=lowest; i<=2048; i++) { |
---|
| 107 | topAddr = i*1024*1024 - 4; |
---|
| 108 | val = *(uint32_t*)topAddr; |
---|
| 109 | if (val != topAddr) { |
---|
| 110 | break; |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | topAddr = (i-1)*1024*1024 - 4; |
---|
| 115 | |
---|
| 116 | _heap_size = topAddr - rtemsFreeMemStart; |
---|
| 117 | } |
---|
| 118 | |
---|
[4050a7f] | 119 | bsp_libc_init((void *)rtemsFreeMemStart, _heap_size, 0); |
---|
| 120 | rtemsFreeMemStart += _heap_size; /* HEAP_SIZE in KBytes */ |
---|
[b6394ae] | 121 | |
---|
[7150f00f] | 122 | #ifdef RTEMS_DEBUG |
---|
| 123 | |
---|
| 124 | rtems_debug_enable(RTEMS_DEBUG_ALL_MASK); |
---|
| 125 | |
---|
| 126 | #endif /* RTEMS_DEBUG */ |
---|
| 127 | } /* bsp_pretasking_hook */ |
---|
[6128a4a] | 128 | |
---|
[7150f00f] | 129 | /*-------------------------------------------------------------------------+ |
---|
[e2a2ec60] | 130 | | Function: bsp_start |
---|
| 131 | | Description: Called before main is invoked. |
---|
[7150f00f] | 132 | | Global Variables: None. |
---|
| 133 | | Arguments: None. |
---|
[6128a4a] | 134 | | Returns: Nothing. |
---|
[7150f00f] | 135 | +--------------------------------------------------------------------------*/ |
---|
[45544f0] | 136 | void bsp_start_default( void ) |
---|
[7150f00f] | 137 | { |
---|
[71319f77] | 138 | int pci_init_retval; |
---|
[c629812] | 139 | void Calibrate_loop_1ms(void); |
---|
[6128a4a] | 140 | |
---|
[eff217e] | 141 | /* |
---|
| 142 | * Calibrate variable for 1ms-loop (see timer.c) |
---|
| 143 | */ |
---|
| 144 | Calibrate_loop_1ms(); |
---|
[8a496e46] | 145 | |
---|
[6fda59f] | 146 | rtemsFreeMemStart = (uint32_t)&_end + _stack_size; |
---|
[96d56b3] | 147 | /* set the value of start of free memory. */ |
---|
| 148 | |
---|
[7150f00f] | 149 | /* If we don't have command line arguments set default program name. */ |
---|
| 150 | |
---|
| 151 | Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */ |
---|
| 152 | Cpu_table.predriver_hook = NULL; /* use system's */ |
---|
| 153 | Cpu_table.postdriver_hook = bsp_postdriver_hook; |
---|
| 154 | Cpu_table.idle_task = NULL; |
---|
| 155 | /* do not override system IDLE task */ |
---|
| 156 | Cpu_table.do_zero_of_workspace = TRUE; |
---|
| 157 | Cpu_table.interrupt_table_segment = get_ds(); |
---|
| 158 | Cpu_table.interrupt_table_offset = (void *)Interrupt_descriptor_table; |
---|
[df49c60] | 159 | Cpu_table.interrupt_stack_size = CONFIGURE_INTERRUPT_STACK_MEMORY; |
---|
[7150f00f] | 160 | Cpu_table.extra_mpci_receive_server_stack = 0; |
---|
| 161 | |
---|
[96d56b3] | 162 | /* Place RTEMS workspace at beginning of free memory. */ |
---|
| 163 | |
---|
| 164 | if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1)) /* not aligned => align it */ |
---|
| 165 | rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1); |
---|
[7150f00f] | 166 | |
---|
[96d56b3] | 167 | BSP_Configuration.work_space_start = (void *)rtemsFreeMemStart; |
---|
| 168 | rtemsFreeMemStart += BSP_Configuration.work_space_size; |
---|
[4050a7f] | 169 | |
---|
[67a2288] | 170 | /* |
---|
[eb562f2] | 171 | * Init rtems interrupt management |
---|
[67a2288] | 172 | */ |
---|
| 173 | rtems_irq_mngt_init(); |
---|
[eb562f2] | 174 | /* |
---|
| 175 | * Init rtems exceptions management |
---|
| 176 | */ |
---|
| 177 | rtems_exception_init_mngt(); |
---|
[71319f77] | 178 | |
---|
| 179 | /* |
---|
| 180 | * init PCI Bios interface... |
---|
| 181 | */ |
---|
| 182 | pci_init_retval = pci_initialize(); |
---|
| 183 | if (pci_init_retval != PCIB_ERR_SUCCESS) { |
---|
| 184 | printk("PCI bus: could not initialize PCI BIOS interface\n"); |
---|
| 185 | } |
---|
| 186 | |
---|
[4050a7f] | 187 | /* |
---|
| 188 | * The following information is very useful when debugging. |
---|
| 189 | */ |
---|
| 190 | |
---|
| 191 | #if 0 |
---|
| 192 | printk( "work_space_size = 0x%x\n", BSP_Configuration.work_space_size ); |
---|
| 193 | printk( "maximum_extensions = 0x%x\n", BSP_Configuration.maximum_extensions ); |
---|
| 194 | printk( "microseconds_per_tick = 0x%x\n", |
---|
| 195 | BSP_Configuration.microseconds_per_tick ); |
---|
| 196 | printk( "ticks_per_timeslice = 0x%x\n", |
---|
| 197 | BSP_Configuration.ticks_per_timeslice ); |
---|
| 198 | printk( "maximum_devices = 0x%x\n", BSP_Configuration.maximum_devices ); |
---|
| 199 | printk( "number_of_device_drivers = 0x%x\n", |
---|
| 200 | BSP_Configuration.number_of_device_drivers ); |
---|
| 201 | printk( "Device_driver_table = 0x%x\n", |
---|
| 202 | BSP_Configuration.Device_driver_table ); |
---|
| 203 | |
---|
| 204 | printk( "_heap_size = 0x%x\n", _heap_size ); |
---|
| 205 | printk( "_stack_size = 0x%x\n", _stack_size ); |
---|
| 206 | printk( "rtemsFreeMemStart = 0x%x\n", rtemsFreeMemStart ); |
---|
| 207 | printk( "work_space_start = 0x%x\n", BSP_Configuration.work_space_start ); |
---|
| 208 | printk( "work_space_size = 0x%x\n", BSP_Configuration.work_space_size ); |
---|
| 209 | #endif |
---|
[e2a2ec60] | 210 | } /* bsp_start */ |
---|
[45544f0] | 211 | |
---|
| 212 | /* |
---|
| 213 | * By making this a weak alias for bsp_start_default, a brave soul |
---|
| 214 | * can override the actual bsp_start routine used. |
---|
| 215 | */ |
---|
| 216 | |
---|
| 217 | void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default"))); |
---|