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

4.104.114.84.95
Last change on this file since 3f929757 was 3f929757, checked in by Joel Sherrill <joel.sherrill@…>, on 09/21/98 at 00:38:13

Patches from Aleksey which were not in 980911.

I am sending you patch which was lost. As far as I remember there
were minor patches on top of it, either by Eric Valette or
by Eric Norum or by both.

  • Property mode set to 100644
File size: 7.6 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-1998.
23| *  On-Line Applications Research Corporation (OAR).
24| *  Copyright assigned to U.S. Government, 1994.
25| *
26| *  The license and distribution terms for this file may be
27| *  found in found in the file LICENSE in this distribution or at
28| *  http://www.OARcorp.com/rtems/license.html.
29| **************************************************************************
30|
31|  $Id$
32+--------------------------------------------------------------------------*/
33
34
35#include <bsp.h>
36#include <libcsupport.h>
37#include <rtems/libio.h>
38#include <libcpu/cpuModel.h>
39#include <pc386uart.h>
40
41/*-------------------------------------------------------------------------+
42| Global Variables
43+--------------------------------------------------------------------------*/
44extern rtems_unsigned32 _end;         /* End of BSS. Defined in 'linkcmds'. */
45/*
46 * Size of heap if it is 0 it will be dynamically defined by memory size,
47 * otherwise the value should be changed by binary patch
48 */
49rtems_unsigned32 _heap_size = 0;
50
51/* Size of stack used during initialization. Defined in 'start.s'.  */
52extern rtems_unsigned32 _stack_size;
53
54rtems_unsigned32 rtemsFreeMemStart;
55                         /* Address of start of free memory - should be updated
56                            after creating new partitions or regions.         */
57
58/* The original BSP configuration table from the application and our copy of it
59   with some changes. */
60
61extern rtems_configuration_table  Configuration;
62       rtems_configuration_table  BSP_Configuration;
63
64rtems_cpu_table Cpu_table;                     /* CPU configuration table.    */
65char            *rtems_progname;               /* Program name - from main(). */
66
67extern void debugPollingGetChar();
68
69/*-------------------------------------------------------------------------+
70| External Prototypes
71+--------------------------------------------------------------------------*/
72extern void _exit(int);  /* define in exit.c */
73extern void _IBMPC_initVideo(void);
74extern void rtems_irq_mngt_init();
75void bsp_libc_init( void *, unsigned32, int );
76void bsp_postdriver_hook(void);
77extern void _IBMPC_initVideo(void);
78
79/*-------------------------------------------------------------------------+
80|         Function: bsp_pretasking_hook
81|      Description: BSP pretasking hook.  Called just before drivers are
82|                   initialized. Used to setup libc and install any BSP
83|                   extensions. NOTE: Must not use libc (to do io) from here,
84|                   since drivers are not yet initialized.
85| Global Variables: None.
86|        Arguments: None.
87|          Returns: Nothing.
88+--------------------------------------------------------------------------*/
89void bsp_pretasking_hook(void)
90{
91  rtems_unsigned32 topAddr, val;
92  int i;
93 
94 
95  if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1))  /* not aligned => align it */
96    rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
97
98  if(_heap_size == 0)
99    {
100      /*
101       * We have to dynamically size memory. Memory size can be anything
102       * between 2M and 2048M.
103       * let us first write
104       */
105      for(i=2048; i>=2; i--)
106        {
107          topAddr = i*1024*1024 - 4;
108          *(volatile rtems_unsigned32 *)topAddr = topAddr;
109        }
110
111      printk("\n");
112
113      for(i=2; i<=2048; i++)
114        {
115          topAddr = i*1024*1024 - 4;
116          val =  *(rtems_unsigned32 *)topAddr;
117          if(val != topAddr)
118            {
119              break;
120            }
121        }
122     
123      topAddr = (i-1)*1024*1024 - 4;
124
125      _heap_size = topAddr - rtemsFreeMemStart;
126    }
127     
128  bsp_libc_init((void *)rtemsFreeMemStart, _heap_size, 0);
129  rtemsFreeMemStart += _heap_size;           /* HEAP_SIZE  in KBytes */
130
131
132#ifdef RTEMS_DEBUG
133
134  rtems_debug_enable(RTEMS_DEBUG_ALL_MASK);
135
136#endif /* RTEMS_DEBUG */
137} /* bsp_pretasking_hook */
138 
139
140/*-------------------------------------------------------------------------+
141|         Function: bsp_start
142|      Description: Called before main is invoked.
143| Global Variables: None.
144|        Arguments: None.
145|          Returns: Nothing.
146+--------------------------------------------------------------------------*/
147void bsp_start( void )
148  /* Initialize printk channel */
149  _IBMPC_initVideo();
150{
151
152  /*
153   * Calibrate variable for 1ms-loop (see timer.c)
154   */
155  Calibrate_loop_1ms();
156  /*
157   * Initialize printk channel
158   */
159  _IBMPC_initVideo();
160
161  rtemsFreeMemStart = (rtems_unsigned32)&_end + _stack_size;
162                                    /* set the value of start of free memory. */
163
164  /* If we don't have command line arguments set default program name. */
165
166  Cpu_table.pretasking_hook         = bsp_pretasking_hook; /* init libc, etc. */
167  Cpu_table.predriver_hook          = NULL;                /* use system's    */
168  Cpu_table.postdriver_hook         = bsp_postdriver_hook;
169  Cpu_table.idle_task               = NULL;
170                                          /* do not override system IDLE task */
171  Cpu_table.do_zero_of_workspace    = TRUE;
172  Cpu_table.interrupt_table_segment = get_ds();
173  Cpu_table.interrupt_table_offset  = (void *)Interrupt_descriptor_table;
174  Cpu_table.interrupt_stack_size    = 4096;
175  Cpu_table.extra_mpci_receive_server_stack = 0;
176
177  /* Place RTEMS workspace at beginning of free memory. */
178
179  if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1))  /* not aligned => align it */
180    rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
181
182  BSP_Configuration.work_space_start = (void *)rtemsFreeMemStart;
183  rtemsFreeMemStart += BSP_Configuration.work_space_size;
184
185  console_reserve_resources(&BSP_Configuration);
186
187  /*
188   * Init rtems interrupt management
189   */
190  rtems_irq_mngt_init();
191  /*
192   * Init rtems exceptions management
193   */
194  rtems_exception_init_mngt();
195  /*
196   *  The following information is very useful when debugging.
197   */
198
199#if 0
200  printk( "work_space_size = 0x%x\n", BSP_Configuration.work_space_size );
201  printk( "maximum_extensions = 0x%x\n", BSP_Configuration.maximum_extensions );
202  printk( "microseconds_per_tick = 0x%x\n",
203     BSP_Configuration.microseconds_per_tick );
204  printk( "ticks_per_timeslice = 0x%x\n",
205     BSP_Configuration.ticks_per_timeslice );
206  printk( "maximum_devices = 0x%x\n", BSP_Configuration.maximum_devices );
207  printk( "number_of_device_drivers = 0x%x\n",
208     BSP_Configuration.number_of_device_drivers );
209  printk( "Device_driver_table = 0x%x\n",
210     BSP_Configuration.Device_driver_table );
211
212  printk( "_heap_size = 0x%x\n", _heap_size );
213  printk( "_stack_size = 0x%x\n", _stack_size );
214  printk( "rtemsFreeMemStart = 0x%x\n", rtemsFreeMemStart );
215  printk( "work_space_start = 0x%x\n", BSP_Configuration.work_space_start );
216  printk( "work_space_size = 0x%x\n", BSP_Configuration.work_space_size );
217#endif
218} /* bsp_start */
Note: See TracBrowser for help on using the repository browser.