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

4.104.115
Last change on this file since e76068d was a196084, checked in by Joel Sherrill <joel.sherrill@…>, on 09/16/08 at 19:06:10

2008-09-16 Joel Sherrill <joel.sherrill@…>

  • startup/bspstart.c: Remove unnecessary includes of rtems/libcsupport.h and rtems/libio.h.
  • Property mode set to 100644
File size: 7.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/pci.h>
35#include <libcpu/cpuModel.h>
36
37/*-------------------------------------------------------------------------+
38| Global Variables
39+--------------------------------------------------------------------------*/
40extern uint32_t         _end;         /* End of BSS. Defined in 'linkcmds'. */
41
42/* rudimentary multiboot info */
43struct multiboot_info {
44        uint32_t        flags;          /* start.S only raises flags for items actually saved; this allows us to check for the size of the data structure */
45        uint32_t        mem_lower;      /* avail kB in lower memory */
46        uint32_t        mem_upper;      /* avail kB in lower memory */
47        /* ... (unimplemented) */
48};
49
50extern struct multiboot_info _boot_multiboot_info;
51/*
52 * Size of heap if it is 0 it will be dynamically defined by memory size,
53 * otherwise the value should be changed by binary patch
54 */
55uint32_t         _heap_size = 0;
56
57/* Alternative way to hardcode the board's memory size [rather than heap size].
58 * Can easily be overridden by application.
59 */
60extern uint32_t bsp_mem_size
61  __attribute__ ((weak, alias("bsp_mem_size_default")));
62uint32_t bsp_mem_size_default = 0;
63
64/* Size of stack used during initialization. Defined in 'start.s'.  */
65extern uint32_t         _stack_size;
66
67uint32_t         rtemsFreeMemStart;
68                         /* Address of start of free memory - should be updated
69                            after creating new partitions or regions.         */
70
71
72/*-------------------------------------------------------------------------+
73| External Prototypes
74+--------------------------------------------------------------------------*/
75extern void rtems_irq_mngt_init(void);
76void bsp_libc_init( void *, uint32_t, int );
77
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+--------------------------------------------------------------------------*/
88void bsp_pretasking_hook(void)
89{
90  uint32_t topAddr, val;
91  int      i, lowest;
92
93  if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1))  /* not aligned => align it */
94    rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
95
96  /* find the lowest 1M boundary to probe */
97  lowest = ((rtemsFreeMemStart + (1<<20)) >> 20) + 1;
98  if ( lowest  < 2 )
99      lowest = 2;
100
101  /* The memory detection algorithm is very crude; try
102   * to use multiboot info, if possible (set from start.S)
103   */
104  if ( bsp_mem_size == 0 &&
105       (_boot_multiboot_info.flags & 1) &&
106       _boot_multiboot_info.mem_upper ) {
107    bsp_mem_size = _boot_multiboot_info.mem_upper * 1024;
108  }
109
110  if ( _heap_size == 0 ) {
111    if ( bsp_mem_size == 0 ) {
112        /*
113         * We have to dynamically size memory. Memory size can be anything
114         * between no less than 2M and 2048M.
115         * let us first write
116         */
117        for (i=2048; i>=lowest; i--) {
118          topAddr = i*1024*1024 - 4;
119          *(volatile uint32_t*)topAddr = topAddr;
120        }
121
122        for(i=lowest; i<=2048; i++) {
123          topAddr = i*1024*1024 - 4;
124          val =  *(uint32_t*)topAddr;
125          if (val != topAddr) {
126            break;
127          }
128        }
129     
130        topAddr = (i-1)*1024*1024 - 4;
131      } else {
132        topAddr = bsp_mem_size;
133      }
134
135    if ( rtemsFreeMemStart > topAddr ) {
136      printk( "Out of memory -- unable to initialize BSP\n" );
137      rtems_fatal_error_occurred( 0x85858585 );
138    }
139 
140    _heap_size = topAddr - rtemsFreeMemStart;
141  }
142
143  bsp_libc_init((void *)rtemsFreeMemStart, _heap_size, 0);
144  rtemsFreeMemStart += _heap_size;           /* HEAP_SIZE  in KBytes */
145} /* bsp_pretasking_hook */
146
147/*
148 *  External but essentially private method
149 */
150void Calibrate_loop_1ms(void);
151
152/*-------------------------------------------------------------------------+
153|         Function: bsp_start
154|      Description: Called before main is invoked.
155| Global Variables: None.
156|        Arguments: None.
157|          Returns: Nothing.
158+--------------------------------------------------------------------------*/
159void bsp_start_default( void )
160{
161  int pci_init_retval;
162
163  /*
164   * Calibrate variable for 1ms-loop (see timer.c)
165   */
166  Calibrate_loop_1ms();
167
168  /* set the value of start of free memory. */
169  rtemsFreeMemStart = (uint32_t)&_end + _stack_size;
170
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);
175
176  Configuration.work_space_start = (void *)rtemsFreeMemStart;
177  rtemsFreeMemStart += rtems_configuration_get_work_space_size();
178
179  /*
180   * Init rtems interrupt management
181   */
182  rtems_irq_mngt_init();
183  /*
184   * Init rtems exceptions management
185   */
186  rtems_exception_init_mngt();
187
188  /*
189   * init PCI Bios interface...
190   */
191  pci_init_retval = pci_initialize();
192  if (pci_init_retval != PCIB_ERR_SUCCESS) {
193      printk("PCI bus: could not initialize PCI BIOS interface\n");
194  }
195
196
197#if 0
198  printk( "_heap_size = 0x%x\n", _heap_size );
199  printk( "_stack_size = 0x%x\n", _stack_size );
200  printk( "rtemsFreeMemStart = 0x%x\n", rtemsFreeMemStart );
201  printk( "work_space_start = 0x%x\n", rtems_configuration_get_work_space_start() );
202  printk( "work_space_size = 0x%x\n", rtems_configuration_get_work_space_size() );
203#endif
204} /* bsp_start */
205
206/*
207 *  By making this a weak alias for bsp_start_default, a brave soul
208 *  can override the actual bsp_start routine used.
209 */
210
211void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default")));
Note: See TracBrowser for help on using the repository browser.