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