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

4.104.114.95
Last change on this file since e3a1d425 was e3a1d425, checked in by Joel Sherrill <joel.sherrill@…>, on 08/19/08 at 19:34:08

2008-08-19 Joel Sherrill <joel.sherrill@…>

  • clock/ckinit.c, console/serial_mouse.c, ne2000/ne2000.c, startup/bspstart.c: Fix warnings for prototypes, types, etc.
  • Property mode set to 100644
File size: 7.2 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
74/*-------------------------------------------------------------------------+
75| External Prototypes
76+--------------------------------------------------------------------------*/
77extern void rtems_irq_mngt_init(void);
78void bsp_libc_init( void *, uint32_t, int );
79
80/*-------------------------------------------------------------------------+
81|         Function: bsp_pretasking_hook
82|      Description: BSP pretasking hook.  Called just before drivers are
83|                   initialized. Used to setup libc and install any BSP
84|                   extensions. NOTE: Must not use libc (to do io) from here,
85|                   since drivers are not yet initialized.
86| Global Variables: None.
87|        Arguments: None.
88|          Returns: Nothing.
89+--------------------------------------------------------------------------*/
90void bsp_pretasking_hook(void)
91{
92  uint32_t topAddr, val;
93  int      i, lowest;
94
95  if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1))  /* not aligned => align it */
96    rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
97
98  /* find the lowest 1M boundary to probe */
99  lowest = ((rtemsFreeMemStart + (1<<20)) >> 20) + 1;
100  if ( lowest  < 2 )
101      lowest = 2;
102
103  /* The memory detection algorithm is very crude; try
104   * to use multiboot info, if possible (set from start.S)
105   */
106  if ( bsp_mem_size == 0 &&
107       (_boot_multiboot_info.flags & 1) &&
108       _boot_multiboot_info.mem_upper ) {
109    bsp_mem_size = _boot_multiboot_info.mem_upper * 1024;
110  }
111
112  if ( _heap_size == 0 ) {
113    if ( bsp_mem_size == 0 ) {
114        /*
115         * We have to dynamically size memory. Memory size can be anything
116         * between no less than 2M and 2048M.
117         * let us first write
118         */
119        for (i=2048; i>=lowest; i--) {
120          topAddr = i*1024*1024 - 4;
121          *(volatile uint32_t*)topAddr = topAddr;
122        }
123
124        for(i=lowest; i<=2048; i++) {
125          topAddr = i*1024*1024 - 4;
126          val =  *(uint32_t*)topAddr;
127          if (val != topAddr) {
128            break;
129          }
130        }
131     
132        topAddr = (i-1)*1024*1024 - 4;
133      } else {
134        topAddr = bsp_mem_size;
135      }
136
137    if ( rtemsFreeMemStart > topAddr ) {
138      printk( "Out of memory -- unable to initialize BSP\n" );
139      rtems_fatal_error_occurred( 0x85858585 );
140    }
141 
142    _heap_size = topAddr - rtemsFreeMemStart;
143  }
144
145  bsp_libc_init((void *)rtemsFreeMemStart, _heap_size, 0);
146  rtemsFreeMemStart += _heap_size;           /* HEAP_SIZE  in KBytes */
147} /* bsp_pretasking_hook */
148
149/*
150 *  External but essentially private method
151 */
152void Calibrate_loop_1ms(void);
153
154/*-------------------------------------------------------------------------+
155|         Function: bsp_start
156|      Description: Called before main is invoked.
157| Global Variables: None.
158|        Arguments: None.
159|          Returns: Nothing.
160+--------------------------------------------------------------------------*/
161void bsp_start_default( void )
162{
163  int pci_init_retval;
164
165  /*
166   * Calibrate variable for 1ms-loop (see timer.c)
167   */
168  Calibrate_loop_1ms();
169
170  /* set the value of start of free memory. */
171  rtemsFreeMemStart = (uint32_t)&_end + _stack_size;
172
173  /* Place RTEMS workspace at beginning of free memory. */
174
175  if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1))  /* not aligned => align it */
176    rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
177
178  Configuration.work_space_start = (void *)rtemsFreeMemStart;
179  rtemsFreeMemStart += rtems_configuration_get_work_space_size();
180
181  /*
182   * Init rtems interrupt management
183   */
184  rtems_irq_mngt_init();
185  /*
186   * Init rtems exceptions management
187   */
188  rtems_exception_init_mngt();
189
190  /*
191   * init PCI Bios interface...
192   */
193  pci_init_retval = pci_initialize();
194  if (pci_init_retval != PCIB_ERR_SUCCESS) {
195      printk("PCI bus: could not initialize PCI BIOS interface\n");
196  }
197
198
199#if 0
200  printk( "_heap_size = 0x%x\n", _heap_size );
201  printk( "_stack_size = 0x%x\n", _stack_size );
202  printk( "rtemsFreeMemStart = 0x%x\n", rtemsFreeMemStart );
203  printk( "work_space_start = 0x%x\n", rtems_configuration_get_work_space_start() );
204  printk( "work_space_size = 0x%x\n", rtems_configuration_get_work_space_size() );
205#endif
206} /* bsp_start */
207
208/*
209 *  By making this a weak alias for bsp_start_default, a brave soul
210 *  can override the actual bsp_start routine used.
211 */
212
213void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default")));
Note: See TracBrowser for help on using the repository browser.