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

4.104.114.84.95
Last change on this file since c629812 was c629812, checked in by Joel Sherrill <joel.sherrill@…>, on 12/13/99 at 22:10:45

Removed warnings.

  • Property mode set to 100644
File size: 7.5 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.OARcorp.com/rtems/license.html.
28| **************************************************************************
29|
30|  $Id$
31+--------------------------------------------------------------------------*/
32
33
34#include <bsp.h>
35#include <libcsupport.h>
36#include <rtems/libio.h>
37#include <libcpu/cpuModel.h>
38
39/*-------------------------------------------------------------------------+
40| Global Variables
41+--------------------------------------------------------------------------*/
42extern rtems_unsigned32 _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 */
47rtems_unsigned32 _heap_size = 0;
48
49/* Size of stack used during initialization. Defined in 'start.s'.  */
50extern rtems_unsigned32 _stack_size;
51
52rtems_unsigned32 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 *, unsigned32, 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  rtems_unsigned32 topAddr, val;
85  int i;
86 
87 
88  if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1))  /* not aligned => align it */
89    rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
90
91  if(_heap_size == 0)
92    {
93      /*
94       * We have to dynamically size memory. Memory size can be anything
95       * between 2M and 2048M.
96       * let us first write
97       */
98      for(i=2048; i>=2; i--)
99        {
100          topAddr = i*1024*1024 - 4;
101          *(volatile rtems_unsigned32 *)topAddr = topAddr;
102        }
103
104      for(i=2; i<=2048; i++)
105        {
106          topAddr = i*1024*1024 - 4;
107          val =  *(rtems_unsigned32 *)topAddr;
108          if(val != topAddr)
109            {
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
123#ifdef RTEMS_DEBUG
124
125  rtems_debug_enable(RTEMS_DEBUG_ALL_MASK);
126
127#endif /* RTEMS_DEBUG */
128} /* bsp_pretasking_hook */
129 
130
131/*-------------------------------------------------------------------------+
132|         Function: bsp_start
133|      Description: Called before main is invoked.
134| Global Variables: None.
135|        Arguments: None.
136|          Returns: Nothing.
137+--------------------------------------------------------------------------*/
138void bsp_start_default( void )
139{
140  void Calibrate_loop_1ms(void);
141
142  /*
143   * Calibrate variable for 1ms-loop (see timer.c)
144   */
145  Calibrate_loop_1ms();
146
147  /*
148   * Initialize printk channel
149   */
150 
151  _IBMPC_initVideo();
152
153  rtemsFreeMemStart = (rtems_unsigned32)&_end + _stack_size;
154                                    /* set the value of start of free memory. */
155
156  /* If we don't have command line arguments set default program name. */
157
158  Cpu_table.pretasking_hook         = bsp_pretasking_hook; /* init libc, etc. */
159  Cpu_table.predriver_hook          = NULL;                /* use system's    */
160  Cpu_table.postdriver_hook         = bsp_postdriver_hook;
161  Cpu_table.idle_task               = NULL;
162                                          /* do not override system IDLE task */
163  Cpu_table.do_zero_of_workspace    = TRUE;
164  Cpu_table.interrupt_table_segment = get_ds();
165  Cpu_table.interrupt_table_offset  = (void *)Interrupt_descriptor_table;
166  Cpu_table.interrupt_stack_size    = 4096;
167  Cpu_table.extra_mpci_receive_server_stack = 0;
168
169  /* Place RTEMS workspace at beginning of free memory. */
170
171  if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1))  /* not aligned => align it */
172    rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
173
174  BSP_Configuration.work_space_start = (void *)rtemsFreeMemStart;
175  rtemsFreeMemStart += BSP_Configuration.work_space_size;
176
177  console_reserve_resources(&BSP_Configuration);
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   *  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.