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

4.104.114.95
Last change on this file since 6ea100c1 was 6ea100c1, checked in by Joel Sherrill <joel.sherrill@…>, on 05/12/08 at 18:43:55

2008-05-12 Joel Sherrill <joel.sherrill@…>

  • startup/bspstart.c: Refactored and renamed initialization routines to rtems_initialize_data_structures, rtems_initialize_before_drivers, rtems_initialize_device_drivers, and rtems_initialize_start_multitasking. This opened the sequence up so that bootcard() could provide a more robust and flexible framework which is easier to explain and understand. This also lays the groundwork for sharing the division of available memory between the RTEMS workspace and heap and the C library initialization across all BSPs.
  • 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
148#ifdef RTEMS_DEBUG
149  rtems_debug_enable(RTEMS_DEBUG_ALL_MASK);
150#endif /* RTEMS_DEBUG */
151
152} /* bsp_pretasking_hook */
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  void Calibrate_loop_1ms(void);
165
166  /*
167   * Calibrate variable for 1ms-loop (see timer.c)
168   */
169  Calibrate_loop_1ms();
170
171  /* set the value of start of free memory. */
172  rtemsFreeMemStart = (uint32_t)&_end + _stack_size;
173
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);
178
179  Configuration.work_space_start = (void *)rtemsFreeMemStart;
180  rtemsFreeMemStart += rtems_configuration_get_work_space_size();
181
182  /*
183   * Init rtems interrupt management
184   */
185  rtems_irq_mngt_init();
186  /*
187   * Init rtems exceptions management
188   */
189  rtems_exception_init_mngt();
190
191  /*
192   * init PCI Bios interface...
193   */
194  pci_init_retval = pci_initialize();
195  if (pci_init_retval != PCIB_ERR_SUCCESS) {
196      printk("PCI bus: could not initialize PCI BIOS interface\n");
197  }
198
199
200#if 0
201  printk( "_heap_size = 0x%x\n", _heap_size );
202  printk( "_stack_size = 0x%x\n", _stack_size );
203  printk( "rtemsFreeMemStart = 0x%x\n", rtemsFreeMemStart );
204  printk( "work_space_start = 0x%x\n", rtems_configuration_get_work_space_start() );
205  printk( "work_space_size = 0x%x\n", rtems_configuration_get_work_space_size() );
206#endif
207} /* bsp_start */
208
209/*
210 *  By making this a weak alias for bsp_start_default, a brave soul
211 *  can override the actual bsp_start routine used.
212 */
213
214void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default")));
Note: See TracBrowser for help on using the repository browser.