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

4.104.114.95
Last change on this file since d34d8692 was d34d8692, checked in by Joel Sherrill <joel.sherrill@…>, on 12/04/07 at 22:22:26

2007-12-04 Joel Sherrill <joel.sherrill@…>

  • include/bsp.h, startup/bspstart.c: Move interrupt_stack_size field from CPU Table to Configuration Table. Eliminate CPU Table from all ports. Delete references to CPU Table in all forms.
  • Property mode set to 100644
File size: 8.1 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
63  __attribute__ ((weak, alias("bsp_mem_size_default")));
64uint32_t bsp_mem_size_default = 0;
65
66/* Size of stack used during initialization. Defined in 'start.s'.  */
67extern uint32_t         _stack_size;
68
69uint32_t         rtemsFreeMemStart;
70                         /* Address of start of free memory - should be updated
71                            after creating new partitions or regions.         */
72
73/* The original BSP configuration table from the application and our copy of it
74   with some changes. */
75
76extern rtems_configuration_table  Configuration;
77       rtems_configuration_table  BSP_Configuration;
78
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    if ( bsp_mem_size == 0 ) {
122        /*
123         * We have to dynamically size memory. Memory size can be anything
124         * between no less than 2M and 2048M.
125         * let us first write
126         */
127        for (i=2048; i>=lowest; i--) {
128          topAddr = i*1024*1024 - 4;
129          *(volatile uint32_t*)topAddr = topAddr;
130        }
131
132        for(i=lowest; i<=2048; i++) {
133          topAddr = i*1024*1024 - 4;
134          val =  *(uint32_t*)topAddr;
135          if (val != topAddr) {
136            break;
137          }
138        }
139     
140        topAddr = (i-1)*1024*1024 - 4;
141      } else {
142        topAddr = bsp_mem_size;
143      }
144
145    if ( rtemsFreeMemStart > topAddr ) {
146      printk( "Out of memory -- unable to initialize BSP\n" );
147      rtems_fatal_error_occurred( 0x85858585 );
148    }
149 
150    _heap_size = topAddr - rtemsFreeMemStart;
151  }
152
153  bsp_libc_init((void *)rtemsFreeMemStart, _heap_size, 0);
154  rtemsFreeMemStart += _heap_size;           /* HEAP_SIZE  in KBytes */
155
156#ifdef RTEMS_DEBUG
157  rtems_debug_enable(RTEMS_DEBUG_ALL_MASK);
158#endif /* RTEMS_DEBUG */
159
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  /* Place RTEMS workspace at beginning of free memory. */
183
184  if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1))  /* not aligned => align it */
185    rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
186
187  BSP_Configuration.work_space_start = (void *)rtemsFreeMemStart;
188  rtemsFreeMemStart += BSP_Configuration.work_space_size;
189
190  /*
191   * Init rtems interrupt management
192   */
193  rtems_irq_mngt_init();
194  /*
195   * Init rtems exceptions management
196   */
197  rtems_exception_init_mngt();
198
199  /*
200   * init PCI Bios interface...
201   */
202  pci_init_retval = pci_initialize();
203  if (pci_init_retval != PCIB_ERR_SUCCESS) {
204      printk("PCI bus: could not initialize PCI BIOS interface\n");
205  }
206
207  /*
208   *  The following information is very useful when debugging.
209   */
210
211#if 0
212  printk( "work_space_size = 0x%x\n", BSP_Configuration.work_space_size );
213  printk( "maximum_extensions = 0x%x\n", BSP_Configuration.maximum_extensions );
214  printk( "microseconds_per_tick = 0x%x\n",
215     BSP_Configuration.microseconds_per_tick );
216  printk( "ticks_per_timeslice = 0x%x\n",
217     BSP_Configuration.ticks_per_timeslice );
218  printk( "number_of_device_drivers = 0x%x\n",
219     BSP_Configuration.number_of_device_drivers );
220  printk( "Device_driver_table = 0x%x\n",
221     BSP_Configuration.Device_driver_table );
222
223  printk( "_heap_size = 0x%x\n", _heap_size );
224  printk( "_stack_size = 0x%x\n", _stack_size );
225  printk( "rtemsFreeMemStart = 0x%x\n", rtemsFreeMemStart );
226  printk( "work_space_start = 0x%x\n", BSP_Configuration.work_space_start );
227  printk( "work_space_size = 0x%x\n", BSP_Configuration.work_space_size );
228#endif
229} /* bsp_start */
230
231/*
232 *  By making this a weak alias for bsp_start_default, a brave soul
233 *  can override the actual bsp_start routine used.
234 */
235
236void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default")));
Note: See TracBrowser for help on using the repository browser.