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

4.104.114.84.95
Last change on this file since 8f95b5f was 8f95b5f, checked in by Joel Sherrill <joel.sherrill@…>, on 03/30/98 at 14:01:19

Moved bsp_postdriver_hook() to a shared file and made it a common
component.

  • Property mode set to 100644
File size: 7.5 KB
Line 
1/*-------------------------------------------------------------------------+
2| bspstart.c v1.1 - PC386 BSP - 1997/08/07
3+--------------------------------------------------------------------------+
4| This file contains the PC386 BSP startup package. It includes application,
5| board, and monitor specific initialization and configuration. The generic CPU
6| dependent initialization has been performed before this routine is invoked.
7+--------------------------------------------------------------------------+
8| (C) Copyright 1997 -
9| - NavIST Group - Real-Time Distributed Systems and Industrial Automation
10|
11| http://pandora.ist.utl.pt
12|
13| Instituto Superior Tecnico * Lisboa * PORTUGAL
14+--------------------------------------------------------------------------+
15| Disclaimer:
16|
17| This file is provided "AS IS" without warranty of any kind, either
18| expressed or implied.
19+--------------------------------------------------------------------------+
20| This code is based on:
21|   bspstart.c,v 1.8 1996/05/28 13:12:40 joel Exp - go32 BSP
22| With the following copyright notice:
23| **************************************************************************
24| *  COPYRIGHT (c) 1989-1998.
25| *  On-Line Applications Research Corporation (OAR).
26| *  Copyright assigned to U.S. Government, 1994.
27| *
28| *  The license and distribution terms for this file may be
29| *  found in found in the file LICENSE in this distribution or at
30| *  http://www.OARcorp.com/rtems/license.html.
31| **************************************************************************
32|
33|  $Id$
34+--------------------------------------------------------------------------*/
35
36
37#include <bsp.h>
38#include <libcsupport.h>
39#include <rtems/libio.h>
40 
41#ifdef STACK_CHECKER_ON
42#include <stackchk.h>
43#endif
44
45/*-------------------------------------------------------------------------+
46| Global Variables
47+--------------------------------------------------------------------------*/
48#ifdef RTEMS_SMALL_MEMORY
49extern rtems_unsigned32 _end;           /* End of BSS. Defined in 'linkcmds'. */
50
51rtems_unsigned32 rtemsFreeMemStart = (rtems_unsigned32)&_end;
52                         /* Address of start of free memory - should be updated
53                            after creating new partitions or regions.         */
54#else
55rtems_unsigned32 rtemsFreeMemStart = RAM_START;
56                                             /* RAM_START defined in 'bsp.h'. */
57#endif /* RTEMS_SMALL_MEMORY */
58
59/* The original BSP configuration table from the application and our copy of it
60   with some changes. */
61
62extern rtems_configuration_table  Configuration;
63       rtems_configuration_table  BSP_Configuration;
64
65rtems_cpu_table Cpu_table;                     /* CPU configuration table.    */
66char            *rtems_progname;               /* Program name - from main(). */
67
68
69/*-------------------------------------------------------------------------+
70| External Prototypes
71+--------------------------------------------------------------------------*/
72extern void _exit(int);  /* define in exit.c */
73
74/*-------------------------------------------------------------------------+
75|         Function: bsp_libc_init
76|      Description: Initialize whatever libc we are using. Called from
77|                   pretasking hook.
78| Global Variables: rtemsFreeMemStart.
79|        Arguments: None.
80|          Returns: Nothing.
81+--------------------------------------------------------------------------*/
82static void
83bsp_libc_init(void)
84{
85  if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1))  /* not aligned => align it */
86    rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
87
88  RTEMS_Malloc_Initialize((void *)rtemsFreeMemStart, HEAP_SIZE << 10, 0);
89  rtemsFreeMemStart += HEAP_SIZE << 10;           /* HEAP_SIZE is in KBytes */
90
91  /* Init the RTEMS libio facility to provide UNIX-like system calls for use by
92     newlib (ie: provide __rtems_open, __rtems_close, etc). Uses malloc()
93     to get area for the iops, so must be after malloc initialization. */
94
95  rtems_libio_init();
96
97  /* Set up for the libc handling. */
98
99  if (BSP_Configuration.ticks_per_timeslice > 0)
100    libc_init(1); /* reentrant if possible */
101  else
102    libc_init(0); /* non-reentrant         */
103} /* bsp_libc_init */
104
105 
106/*-------------------------------------------------------------------------+
107|         Function: bsp_pretasking_hook
108|      Description: BSP pretasking hook.  Called just before drivers are
109|                   initialized. Used to setup libc and install any BSP
110|                   extensions. NOTE: Must not use libc (to do io) from here,
111|                   since drivers are not yet initialized.
112| Global Variables: None.
113|        Arguments: None.
114|          Returns: Nothing.
115+--------------------------------------------------------------------------*/
116void
117bsp_pretasking_hook(void)
118{
119  bsp_libc_init();
120
121#ifdef STACK_CHECKER_ON
122  /* Initialize the stack bounds checker. We can either turn it on here or from
123     the app. */
124   
125  Stack_check_Initialize();
126
127#endif /* STACK_CHECKER_ON */
128 
129#ifdef RTEMS_DEBUG
130
131  rtems_debug_enable(RTEMS_DEBUG_ALL_MASK);
132
133#endif /* RTEMS_DEBUG */
134} /* bsp_pretasking_hook */
135 
136
137/*
138 *  Use the shared bsp_postdriver_hook() implementation
139 */
140 
141void bsp_postdriver_hook(void);
142
143
144/*-------------------------------------------------------------------------+
145|         Function: bsp_start
146|      Description: Called before main is invoked.
147| Global Variables: None.
148|        Arguments: None.
149|          Returns: Nothing.
150+--------------------------------------------------------------------------*/
151void bsp_start( void )
152{
153  /* If we don't have command line arguments set default program name. */
154
155  Cpu_table.pretasking_hook         = bsp_pretasking_hook; /* init libc, etc. */
156  Cpu_table.predriver_hook          = NULL;                /* use system's    */
157  Cpu_table.postdriver_hook         = bsp_postdriver_hook;
158  Cpu_table.idle_task               = NULL;
159                                          /* do not override system IDLE task */
160  Cpu_table.do_zero_of_workspace    = TRUE;
161  Cpu_table.interrupt_table_segment = get_ds();
162  Cpu_table.interrupt_table_offset  = (void *)Interrupt_descriptor_table;
163  Cpu_table.interrupt_stack_size    = 4096;
164  Cpu_table.extra_mpci_receive_server_stack = 0;
165
166  /* Copy user's table and make necessary adjustments.              */
167
168  BSP_Configuration = Configuration;
169
170  /* Place RTEMS workspace at top of physical RAM (RAM_END defined in 'bsp.h' */
171
172  BSP_Configuration.work_space_start =
173                          (void *)(RAM_END - BSP_Configuration.work_space_size);
174
175  /* Add 1 region for Malloc in libc_low.                           */
176
177  BSP_Configuration.RTEMS_api_configuration->maximum_regions++;
178
179  /* Add 1 extension for newlib libc.                               */
180
181#ifdef RTEMS_NEWLIB
182  BSP_Configuration.maximum_extensions++;
183#endif
184
185  /* Add another extension if using the stack checker.              */
186
187#ifdef STACK_CHECKER_ON
188  BSP_Configuration.maximum_extensions++;
189#endif
190
191  /* Tell libio how many fd's we want and allow it to tweak config. */
192
193  rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS);
194
195#if 0
196  rtems_initialize_executive(&BSP_Configuration, &Cpu_table);
197  /* does not return */
198
199  /*-------------------------------------------------------------------------+
200  | We only return here if the executive has finished. This happens when the
201  | task has called exit(). We will then call _exit() which is part of the bsp.
202  +--------------------------------------------------------------------------*/
203
204  for (;;)
205    _exit(0);
206
207  /* no cleanup necessary for PC386 */
208
209  return 0;
210#endif
211} /* bsp_start */
Note: See TracBrowser for help on using the repository browser.