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