source: rtems/c/src/lib/libbsp/i386/pc386/startup/bspstart.c @ 662c157

4.104.114.84.95
Last change on this file since 662c157 was 662c157, checked in by Till Straumann <strauman@…>, on Sep 4, 2006 at 11:29:29 PM
  • startup/bspstart.c, start/start.S: Since the crude memory autodetection code can easily fail (boards with 'reserved' regions - I experienced a hard lockup on a dell precision 490 when writing past the bios-reported memory size) I added code that a) tries to save and use multiboot info, if present b) allows applications to override/set memory size via a weak alias.
  • Property mode set to 100644
File size: 8.8 KB
Line 
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| **************************************************************************
22| *  COPYRIGHT (c) 1989-1999.
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
27| *  http://www.rtems.com/license/LICENSE.
28| **************************************************************************
29|
30|  $Id$
31+--------------------------------------------------------------------------*/
32
33#include <bsp.h>
34#include <rtems/libio.h>
35#include <rtems/libcsupport.h>
36#include <rtems/pci.h>
37#include <libcpu/cpuModel.h>
38
39/*-------------------------------------------------------------------------+
40| Global Variables
41+--------------------------------------------------------------------------*/
42extern uint32_t         _end;         /* End of BSS. Defined in 'linkcmds'. */
43
44/* rudimentary multiboot info */
45struct multiboot_info {
46        uint32_t        flags;          /* start.S only raises flags for items actually saved; this allows us to check for the size of the data structure */
47        uint32_t        mem_lower;      /* avail kB in lower memory */
48        uint32_t        mem_upper;      /* avail kB in lower memory */
49        /* ... (unimplemented) */
50};
51
52extern struct multiboot_info _boot_multiboot_info;
53/*
54 * Size of heap if it is 0 it will be dynamically defined by memory size,
55 * otherwise the value should be changed by binary patch
56 */
57uint32_t         _heap_size = 0;
58
59/* Alternative way to hardcode the board's memory size [rather than heap size].
60 * Can easily be overridden by application.
61 */
62extern uint32_t bsp_mem_size __attribute__ ((weak, alias("bsp_mem_size_default")));
63uint32_t bsp_mem_size_default = 0;
64
65/* Size of stack used during initialization. Defined in 'start.s'.  */
66extern uint32_t         _stack_size;
67
68uint32_t         rtemsFreeMemStart;
69                         /* Address of start of free memory - should be updated
70                            after creating new partitions or regions.         */
71
72/* The original BSP configuration table from the application and our copy of it
73   with some changes. */
74
75extern rtems_configuration_table  Configuration;
76       rtems_configuration_table  BSP_Configuration;
77
78rtems_cpu_table Cpu_table;                     /* CPU configuration table.    */
79char            *rtems_progname;               /* Program name - from main(). */
80
81/*-------------------------------------------------------------------------+
82| External Prototypes
83+--------------------------------------------------------------------------*/
84extern void rtems_irq_mngt_init(void);
85void bsp_libc_init( void *, uint32_t, int );
86void bsp_postdriver_hook(void);
87
88/*-------------------------------------------------------------------------+
89|         Function: bsp_pretasking_hook
90|      Description: BSP pretasking hook.  Called just before drivers are
91|                   initialized. Used to setup libc and install any BSP
92|                   extensions. NOTE: Must not use libc (to do io) from here,
93|                   since drivers are not yet initialized.
94| Global Variables: None.
95|        Arguments: None.
96|          Returns: Nothing.
97+--------------------------------------------------------------------------*/
98void bsp_pretasking_hook(void)
99{
100  uint32_t         topAddr, val;
101  int i, lowest;
102
103  if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1))  /* not aligned => align it */
104    rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
105
106  /* find the lowest 1M boundary to probe */
107  lowest = ((rtemsFreeMemStart + (1<<20)) >> 20) + 1;
108  if ( lowest  < 2 )
109      lowest = 2;
110
111  /* The memory detection algorithm is very crude; try
112   * to use multiboot info, if possible (set from start.S)
113   */
114  if (   bsp_mem_size == 0
115      && (_boot_multiboot_info.flags & 1)
116      && _boot_multiboot_info.mem_upper ) {
117    bsp_mem_size = _boot_multiboot_info.mem_upper * 1024;
118  }
119
120  if (_heap_size == 0) {
121
122    if ( bsp_mem_size == 0 ) {
123        /*
124         * We have to dynamically size memory. Memory size can be anything
125         * between no less than 2M and 2048M.
126         * let us first write
127         */
128        for (i=2048; i>=lowest; i--) {
129          topAddr = i*1024*1024 - 4;
130          *(volatile uint32_t*)topAddr = topAddr;
131        }
132
133        for(i=lowest; i<=2048; i++) {
134          topAddr = i*1024*1024 - 4;
135          val =  *(uint32_t*)topAddr;
136          if (val != topAddr) {
137            break;
138          }
139        }
140     
141        topAddr = (i-1)*1024*1024 - 4;
142
143      } else {
144
145        topAddr = bsp_mem_size;
146
147      }
148
149    _heap_size = topAddr - rtemsFreeMemStart;
150  }
151
152  bsp_libc_init((void *)rtemsFreeMemStart, _heap_size, 0);
153  rtemsFreeMemStart += _heap_size;           /* HEAP_SIZE  in KBytes */
154
155#ifdef RTEMS_DEBUG
156
157  rtems_debug_enable(RTEMS_DEBUG_ALL_MASK);
158
159#endif /* RTEMS_DEBUG */
160} /* bsp_pretasking_hook */
161
162/*-------------------------------------------------------------------------+
163|         Function: bsp_start
164|      Description: Called before main is invoked.
165| Global Variables: None.
166|        Arguments: None.
167|          Returns: Nothing.
168+--------------------------------------------------------------------------*/
169void bsp_start_default( void )
170{
171  int pci_init_retval;
172  void Calibrate_loop_1ms(void);
173
174  /*
175   * Calibrate variable for 1ms-loop (see timer.c)
176   */
177  Calibrate_loop_1ms();
178
179  /* set the value of start of free memory. */
180  rtemsFreeMemStart = (uint32_t)&_end + _stack_size;
181
182  /* If we don't have command line arguments set default program name. */
183
184  Cpu_table.pretasking_hook         = bsp_pretasking_hook; /* init libc, etc. */
185  Cpu_table.predriver_hook          = NULL;                /* use system's    */
186  Cpu_table.postdriver_hook         = bsp_postdriver_hook;
187  Cpu_table.idle_task               = NULL;
188                                          /* do not override system IDLE task */
189  Cpu_table.do_zero_of_workspace    = TRUE;
190  Cpu_table.interrupt_table_segment = get_ds();
191  Cpu_table.interrupt_table_offset  = (void *)Interrupt_descriptor_table;
192  Cpu_table.interrupt_stack_size    = CONFIGURE_INTERRUPT_STACK_MEMORY;
193  Cpu_table.extra_mpci_receive_server_stack = 0;
194
195  /* Place RTEMS workspace at beginning of free memory. */
196
197  if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1))  /* not aligned => align it */
198    rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
199
200  BSP_Configuration.work_space_start = (void *)rtemsFreeMemStart;
201  rtemsFreeMemStart += BSP_Configuration.work_space_size;
202
203  /*
204   * Init rtems interrupt management
205   */
206  rtems_irq_mngt_init();
207  /*
208   * Init rtems exceptions management
209   */
210  rtems_exception_init_mngt();
211
212  /*
213   * init PCI Bios interface...
214   */
215  pci_init_retval = pci_initialize();
216  if (pci_init_retval != PCIB_ERR_SUCCESS) {
217      printk("PCI bus: could not initialize PCI BIOS interface\n");
218  }
219
220  /*
221   *  The following information is very useful when debugging.
222   */
223
224#if 0
225  printk( "work_space_size = 0x%x\n", BSP_Configuration.work_space_size );
226  printk( "maximum_extensions = 0x%x\n", BSP_Configuration.maximum_extensions );
227  printk( "microseconds_per_tick = 0x%x\n",
228     BSP_Configuration.microseconds_per_tick );
229  printk( "ticks_per_timeslice = 0x%x\n",
230     BSP_Configuration.ticks_per_timeslice );
231  printk( "maximum_devices = 0x%x\n", BSP_Configuration.maximum_devices );
232  printk( "number_of_device_drivers = 0x%x\n",
233     BSP_Configuration.number_of_device_drivers );
234  printk( "Device_driver_table = 0x%x\n",
235     BSP_Configuration.Device_driver_table );
236
237  printk( "_heap_size = 0x%x\n", _heap_size );
238  printk( "_stack_size = 0x%x\n", _stack_size );
239  printk( "rtemsFreeMemStart = 0x%x\n", rtemsFreeMemStart );
240  printk( "work_space_start = 0x%x\n", BSP_Configuration.work_space_start );
241  printk( "work_space_size = 0x%x\n", BSP_Configuration.work_space_size );
242#endif
243} /* bsp_start */
244
245/*
246 *  By making this a weak alias for bsp_start_default, a brave soul
247 *  can override the actual bsp_start routine used.
248 */
249
250void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default")));
Note: See TracBrowser for help on using the repository browser.