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

4.104.114.84.95
Last change on this file since 7150f00f was 7150f00f, checked in by Joel Sherrill <joel.sherrill@…>, on 12/01/97 at 22:06:48

Inclusion of PC386 BSP submitted by Pedro Miguel Da Cruz Neto Romano
<pmcnr@…> and Jose Rufino <ruf@…>
of NavIST (http://pandora.ist.utl.pt/).

  • Property mode set to 100644
File size: 9.0 KB
RevLine 
[7150f00f]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, 1990, 1991, 1992, 1993, 1994.                      *
25| * On-Line Applications Research Corporation (OAR).                       *
26| * All rights assigned to U.S. Government, 1994.                          *
27| *                                                                        *
28| * This material may be reproduced by or for the U.S. Government pursuant *
29| * to the copyright license under the clause at DFARS 252.227-7013.  This *
30| * notice must appear in all copies of this file and its derivatives.     *
31| **************************************************************************
32+--------------------------------------------------------------------------*/
33
34
35#include <fcntl.h>
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|         Function: bsp_postdriver_hook
139|      Description: After drivers are setup, register some "filenames" and open
140|                   stdin, stdout, stderr files. Newlib will automatically
141|                   associate the files with these (it hardcodes the numbers).
142| Global Variables: None.
143|        Arguments: None.
144|          Returns: Nothing.
145+--------------------------------------------------------------------------*/
146void
147bsp_postdriver_hook(void)
148{
149  int stdin_fd, stdout_fd, stderr_fd;
150
151  rtems_status_code error_code;
152 
153  error_code = 'S' << 24 | 'T' << 16;
154
155  /* open standard devices: stdout, stderr and stdin */
156 
157  if ((stdin_fd =  __rtems_open("/dev/console", O_RDONLY, 0)) < 0)
158    rtems_fatal_error_occurred( error_code | 'D' << 8 | '0' );
159 
160  if ((stdout_fd = __rtems_open("/dev/console", O_WRONLY, 0)) < 0)
161    rtems_fatal_error_occurred( error_code | 'D' << 8 | '1' );
162 
163  if ((stderr_fd = __rtems_open("/dev/console", O_WRONLY, 0)) < 1)
164    rtems_fatal_error_occurred( error_code | 'D' << 8 | '2' );
165 
166  if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2))
167    rtems_fatal_error_occurred( error_code | 'I' << 8 | 'O' );
168} /* bsp_postdriver_hook */
169
170
171/*-------------------------------------------------------------------------+
172|         Function: main
173|      Description: Called from bsp's startup code ('start.s').
174| Global Variables: None.
175|        Arguments: None.
176|          Returns: Nothing.
177+--------------------------------------------------------------------------*/
178int main(int argc, char **argv, char **environp)
179{
180  /* If we don't have command line arguments set default program name. */
181
182  if ((argc > 0) && argv && argv[0])
183    rtems_progname = argv[0];
184  else
185    rtems_progname = "RTEMS";
186
187  Cpu_table.pretasking_hook         = bsp_pretasking_hook; /* init libc, etc. */
188  Cpu_table.predriver_hook          = NULL;                /* use system's    */
189  Cpu_table.postdriver_hook         = bsp_postdriver_hook;
190  Cpu_table.idle_task               = NULL;
191                                          /* do not override system IDLE task */
192  Cpu_table.do_zero_of_workspace    = TRUE;
193  Cpu_table.interrupt_table_segment = get_ds();
194  Cpu_table.interrupt_table_offset  = (void *)Interrupt_descriptor_table;
195  Cpu_table.interrupt_stack_size    = 4096;
196  Cpu_table.extra_mpci_receive_server_stack = 0;
197
198  /* Copy user's table and make necessary adjustments.              */
199
200  BSP_Configuration = Configuration;
201
202  /* Place RTEMS workspace at top of physical RAM (RAM_END defined in 'bsp.h' */
203
204  BSP_Configuration.work_space_start =
205                          (void *)(RAM_END - BSP_Configuration.work_space_size);
206
207  /* Add 1 region for Malloc in libc_low.                           */
208
209  BSP_Configuration.RTEMS_api_configuration->maximum_regions++;
210
211  /* Add 1 extension for newlib libc.                               */
212
213#ifdef RTEMS_NEWLIB
214  BSP_Configuration.maximum_extensions++;
215#endif
216
217  /* Add another extension if using the stack checker.              */
218
219#ifdef STACK_CHECKER_ON
220  BSP_Configuration.maximum_extensions++;
221#endif
222
223  /* Tell libio how many fd's we want and allow it to tweak config. */
224
225  rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS);
226
227  rtems_initialize_executive(&BSP_Configuration, &Cpu_table);
228  /* does not return */
229
230  /*-------------------------------------------------------------------------+
231  | We only return here if the executive has finished. This happens when the
232  | task has called exit(). We will then call _exit() which is part of the bsp.
233  +--------------------------------------------------------------------------*/
234
235  for (;;)
236    _exit(0);
237
238  /* no cleanup necessary for PC386 */
239
240  return 0;
241} /* main */
Note: See TracBrowser for help on using the repository browser.