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

4.104.114.84.95
Last change on this file since e7d06758 was 71319f77, checked in by Joel Sherrill <joel.sherrill@…>, on 08/18/05 at 22:24:46

2005-08-18 Karel Gardas <kgardas@…>

  • startup/bspstart.c: Initialize PCI bus in bsp_start function.
  • Property mode set to 100644
File size: 7.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 * Size of heap if it is 0 it will be dynamically defined by memory size,
45 * otherwise the value should be changed by binary patch
46 */
47uint32_t         _heap_size = 0;
48
49/* Size of stack used during initialization. Defined in 'start.s'.  */
50extern uint32_t         _stack_size;
51
52uint32_t         rtemsFreeMemStart;
53                         /* Address of start of free memory - should be updated
54                            after creating new partitions or regions.         */
55
56/* The original BSP configuration table from the application and our copy of it
57   with some changes. */
58
59extern rtems_configuration_table  Configuration;
60       rtems_configuration_table  BSP_Configuration;
61
62rtems_cpu_table Cpu_table;                     /* CPU configuration table.    */
63char            *rtems_progname;               /* Program name - from main(). */
64
65/*-------------------------------------------------------------------------+
66| External Prototypes
67+--------------------------------------------------------------------------*/
68extern void rtems_irq_mngt_init(void);
69void bsp_libc_init( void *, uint32_t, int );
70void bsp_postdriver_hook(void);
71
72/*-------------------------------------------------------------------------+
73|         Function: bsp_pretasking_hook
74|      Description: BSP pretasking hook.  Called just before drivers are
75|                   initialized. Used to setup libc and install any BSP
76|                   extensions. NOTE: Must not use libc (to do io) from here,
77|                   since drivers are not yet initialized.
78| Global Variables: None.
79|        Arguments: None.
80|          Returns: Nothing.
81+--------------------------------------------------------------------------*/
82void bsp_pretasking_hook(void)
83{
84  uint32_t         topAddr, val;
85  int i, lowest;
86
87  if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1))  /* not aligned => align it */
88    rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
89
90  /* find the lowest 1M boundary to probe */
91  lowest = ((rtemsFreeMemStart + (1<<20)) >> 20) + 1;
92  if ( lowest  < 2 )
93      lowest = 2;
94
95  if (_heap_size == 0) {
96    /*
97     * We have to dynamically size memory. Memory size can be anything
98     * between no less than 2M and 2048M.
99     * let us first write
100     */
101    for (i=2048; i>=lowest; i--) {
102      topAddr = i*1024*1024 - 4;
103      *(volatile uint32_t*)topAddr = topAddr;
104    }
105
106   for(i=lowest; i<=2048; i++) {
107     topAddr = i*1024*1024 - 4;
108     val =  *(uint32_t*)topAddr;
109     if (val != topAddr) {
110       break;
111     }
112   }
113
114    topAddr = (i-1)*1024*1024 - 4;
115
116    _heap_size = topAddr - rtemsFreeMemStart;
117  }
118
119  bsp_libc_init((void *)rtemsFreeMemStart, _heap_size, 0);
120  rtemsFreeMemStart += _heap_size;           /* HEAP_SIZE  in KBytes */
121
122#ifdef RTEMS_DEBUG
123
124  rtems_debug_enable(RTEMS_DEBUG_ALL_MASK);
125
126#endif /* RTEMS_DEBUG */
127} /* bsp_pretasking_hook */
128
129/*-------------------------------------------------------------------------+
130|         Function: bsp_start
131|      Description: Called before main is invoked.
132| Global Variables: None.
133|        Arguments: None.
134|          Returns: Nothing.
135+--------------------------------------------------------------------------*/
136void bsp_start_default( void )
137{
138  int pci_init_retval;
139  void Calibrate_loop_1ms(void);
140
141  /*
142   * Calibrate variable for 1ms-loop (see timer.c)
143   */
144  Calibrate_loop_1ms();
145
146  rtemsFreeMemStart = (uint32_t)&_end + _stack_size;
147                                    /* set the value of start of free memory. */
148
149  /* If we don't have command line arguments set default program name. */
150
151  Cpu_table.pretasking_hook         = bsp_pretasking_hook; /* init libc, etc. */
152  Cpu_table.predriver_hook          = NULL;                /* use system's    */
153  Cpu_table.postdriver_hook         = bsp_postdriver_hook;
154  Cpu_table.idle_task               = NULL;
155                                          /* do not override system IDLE task */
156  Cpu_table.do_zero_of_workspace    = TRUE;
157  Cpu_table.interrupt_table_segment = get_ds();
158  Cpu_table.interrupt_table_offset  = (void *)Interrupt_descriptor_table;
159  Cpu_table.interrupt_stack_size    = CONFIGURE_INTERRUPT_STACK_MEMORY;
160  Cpu_table.extra_mpci_receive_server_stack = 0;
161
162  /* Place RTEMS workspace at beginning of free memory. */
163
164  if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1))  /* not aligned => align it */
165    rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
166
167  BSP_Configuration.work_space_start = (void *)rtemsFreeMemStart;
168  rtemsFreeMemStart += BSP_Configuration.work_space_size;
169
170  /*
171   * Init rtems interrupt management
172   */
173  rtems_irq_mngt_init();
174  /*
175   * Init rtems exceptions management
176   */
177  rtems_exception_init_mngt();
178
179  /*
180   * init PCI Bios interface...
181   */
182  pci_init_retval = pci_initialize();
183  if (pci_init_retval != PCIB_ERR_SUCCESS) {
184      printk("PCI bus: could not initialize PCI BIOS interface\n");
185  }
186
187  /*
188   *  The following information is very useful when debugging.
189   */
190
191#if 0
192  printk( "work_space_size = 0x%x\n", BSP_Configuration.work_space_size );
193  printk( "maximum_extensions = 0x%x\n", BSP_Configuration.maximum_extensions );
194  printk( "microseconds_per_tick = 0x%x\n",
195     BSP_Configuration.microseconds_per_tick );
196  printk( "ticks_per_timeslice = 0x%x\n",
197     BSP_Configuration.ticks_per_timeslice );
198  printk( "maximum_devices = 0x%x\n", BSP_Configuration.maximum_devices );
199  printk( "number_of_device_drivers = 0x%x\n",
200     BSP_Configuration.number_of_device_drivers );
201  printk( "Device_driver_table = 0x%x\n",
202     BSP_Configuration.Device_driver_table );
203
204  printk( "_heap_size = 0x%x\n", _heap_size );
205  printk( "_stack_size = 0x%x\n", _stack_size );
206  printk( "rtemsFreeMemStart = 0x%x\n", rtemsFreeMemStart );
207  printk( "work_space_start = 0x%x\n", BSP_Configuration.work_space_start );
208  printk( "work_space_size = 0x%x\n", BSP_Configuration.work_space_size );
209#endif
210} /* bsp_start */
211
212/*
213 *  By making this a weak alias for bsp_start_default, a brave soul
214 *  can override the actual bsp_start routine used.
215 */
216
217void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default")));
Note: See TracBrowser for help on using the repository browser.