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

4.104.114.84.95
Last change on this file since e2a2ec60 was e2a2ec60, checked in by Joel Sherrill <joel.sherrill@…>, on Mar 21, 1998 at 3:37:18 PM

Switch to using a shared main() for all of the embedded BSPs
based on the GNU tools. This usually involved correcting the
type of bsp_start(), bsp_cleanup(), adjusting the start code to
call the right start routine (the shared boot_card()), and then
removing code from bsp_start() which was performed in the new
boot_card()/main() path.

  • Property mode set to 100644
File size: 8.6 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 <fcntl.h>
38
39#include <bsp.h>
40#include <libcsupport.h>
41#include <rtems/libio.h>
42 
43#ifdef STACK_CHECKER_ON
44#include <stackchk.h>
45#endif
46
47/*-------------------------------------------------------------------------+
48| Global Variables
49+--------------------------------------------------------------------------*/
50#ifdef RTEMS_SMALL_MEMORY
51extern rtems_unsigned32 _end;           /* End of BSS. Defined in 'linkcmds'. */
52
53rtems_unsigned32 rtemsFreeMemStart = (rtems_unsigned32)&_end;
54                         /* Address of start of free memory - should be updated
55                            after creating new partitions or regions.         */
56#else
57rtems_unsigned32 rtemsFreeMemStart = RAM_START;
58                                             /* RAM_START defined in 'bsp.h'. */
59#endif /* RTEMS_SMALL_MEMORY */
60
61/* The original BSP configuration table from the application and our copy of it
62   with some changes. */
63
64extern rtems_configuration_table  Configuration;
65       rtems_configuration_table  BSP_Configuration;
66
67rtems_cpu_table Cpu_table;                     /* CPU configuration table.    */
68char            *rtems_progname;               /* Program name - from main(). */
69
70
71/*-------------------------------------------------------------------------+
72| External Prototypes
73+--------------------------------------------------------------------------*/
74extern void _exit(int);  /* define in exit.c */
75
76/*-------------------------------------------------------------------------+
77|         Function: bsp_libc_init
78|      Description: Initialize whatever libc we are using. Called from
79|                   pretasking hook.
80| Global Variables: rtemsFreeMemStart.
81|        Arguments: None.
82|          Returns: Nothing.
83+--------------------------------------------------------------------------*/
84static void
85bsp_libc_init(void)
86{
87  if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1))  /* not aligned => align it */
88    rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
89
90  RTEMS_Malloc_Initialize((void *)rtemsFreeMemStart, HEAP_SIZE << 10, 0);
91  rtemsFreeMemStart += HEAP_SIZE << 10;           /* HEAP_SIZE is in KBytes */
92
93  /* Init the RTEMS libio facility to provide UNIX-like system calls for use by
94     newlib (ie: provide __rtems_open, __rtems_close, etc). Uses malloc()
95     to get area for the iops, so must be after malloc initialization. */
96
97  rtems_libio_init();
98
99  /* Set up for the libc handling. */
100
101  if (BSP_Configuration.ticks_per_timeslice > 0)
102    libc_init(1); /* reentrant if possible */
103  else
104    libc_init(0); /* non-reentrant         */
105} /* bsp_libc_init */
106
107 
108/*-------------------------------------------------------------------------+
109|         Function: bsp_pretasking_hook
110|      Description: BSP pretasking hook.  Called just before drivers are
111|                   initialized. Used to setup libc and install any BSP
112|                   extensions. NOTE: Must not use libc (to do io) from here,
113|                   since drivers are not yet initialized.
114| Global Variables: None.
115|        Arguments: None.
116|          Returns: Nothing.
117+--------------------------------------------------------------------------*/
118void
119bsp_pretasking_hook(void)
120{
121  bsp_libc_init();
122
123#ifdef STACK_CHECKER_ON
124  /* Initialize the stack bounds checker. We can either turn it on here or from
125     the app. */
126   
127  Stack_check_Initialize();
128
129#endif /* STACK_CHECKER_ON */
130 
131#ifdef RTEMS_DEBUG
132
133  rtems_debug_enable(RTEMS_DEBUG_ALL_MASK);
134
135#endif /* RTEMS_DEBUG */
136} /* bsp_pretasking_hook */
137 
138
139/*-------------------------------------------------------------------------+
140|         Function: bsp_postdriver_hook
141|      Description: After drivers are setup, register some "filenames" and open
142|                   stdin, stdout, stderr files. Newlib will automatically
143|                   associate the files with these (it hardcodes the numbers).
144| Global Variables: None.
145|        Arguments: None.
146|          Returns: Nothing.
147+--------------------------------------------------------------------------*/
148void
149bsp_postdriver_hook(void)
150{
151  int stdin_fd, stdout_fd, stderr_fd;
152
153  rtems_status_code error_code;
154 
155  error_code = 'S' << 24 | 'T' << 16;
156
157  /* open standard devices: stdout, stderr and stdin */
158 
159  if ((stdin_fd =  __rtems_open("/dev/console", O_RDONLY, 0)) < 0)
160    rtems_fatal_error_occurred( error_code | 'D' << 8 | '0' );
161 
162  if ((stdout_fd = __rtems_open("/dev/console", O_WRONLY, 0)) < 0)
163    rtems_fatal_error_occurred( error_code | 'D' << 8 | '1' );
164 
165  if ((stderr_fd = __rtems_open("/dev/console", O_WRONLY, 0)) < 1)
166    rtems_fatal_error_occurred( error_code | 'D' << 8 | '2' );
167 
168  if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2))
169    rtems_fatal_error_occurred( error_code | 'I' << 8 | 'O' );
170} /* bsp_postdriver_hook */ 
171
172
173/*-------------------------------------------------------------------------+
174|         Function: bsp_start
175|      Description: Called before main is invoked.
176| Global Variables: None.
177|        Arguments: None.
178|          Returns: Nothing.
179+--------------------------------------------------------------------------*/
180void bsp_start( void )
181{
182  /* If we don't have command line arguments set default program name. */
183
184  Cpu_table.pretasking_hook         = bsp_pretasking_hook; /* init libc, etc. */
185  Cpu_table.predriver_hook          = NULL;                /* use system's    */
186  Cpu_table.postdriver_hook         = bsp_postdriver_hook;
187  Cpu_table.idle_task               = NULL;
188                                          /* do not override system IDLE task */
189  Cpu_table.do_zero_of_workspace    = TRUE;
190  Cpu_table.interrupt_table_segment = get_ds();
191  Cpu_table.interrupt_table_offset  = (void *)Interrupt_descriptor_table;
192  Cpu_table.interrupt_stack_size    = 4096;
193  Cpu_table.extra_mpci_receive_server_stack = 0;
194
195  /* Copy user's table and make necessary adjustments.              */
196
197  BSP_Configuration = Configuration;
198
199  /* Place RTEMS workspace at top of physical RAM (RAM_END defined in 'bsp.h' */
200
201  BSP_Configuration.work_space_start =
202                          (void *)(RAM_END - BSP_Configuration.work_space_size);
203
204  /* Add 1 region for Malloc in libc_low.                           */
205
206  BSP_Configuration.RTEMS_api_configuration->maximum_regions++;
207
208  /* Add 1 extension for newlib libc.                               */
209
210#ifdef RTEMS_NEWLIB
211  BSP_Configuration.maximum_extensions++;
212#endif
213
214  /* Add another extension if using the stack checker.              */
215
216#ifdef STACK_CHECKER_ON
217  BSP_Configuration.maximum_extensions++;
218#endif
219
220  /* Tell libio how many fd's we want and allow it to tweak config. */
221
222  rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS);
223
224#if 0
225  rtems_initialize_executive(&BSP_Configuration, &Cpu_table);
226  /* does not return */
227
228  /*-------------------------------------------------------------------------+
229  | We only return here if the executive has finished. This happens when the
230  | task has called exit(). We will then call _exit() which is part of the bsp.
231  +--------------------------------------------------------------------------*/
232
233  for (;;)
234    _exit(0);
235
236  /* no cleanup necessary for PC386 */
237
238  return 0;
239#endif
240} /* bsp_start */
Note: See TracBrowser for help on using the repository browser.