source: rtems/c/src/lib/libbsp/unix/posix/startup/bspstart.c @ 3a4ae6c

4.104.114.84.95
Last change on this file since 3a4ae6c was 3a4ae6c, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 11, 1995 at 7:35:39 PM

The word "RTEMS" almost completely removed from the core.

Configuration Table Template file added and all tests
modified to use this. All gvar.h and conftbl.h files
removed from test directories.

Configuration parameter maximum_devices added.

Core semaphore and mutex handlers added and RTEMS API Semaphore
Manager updated to reflect this.

Initialization sequence changed to invoke API specific initialization
routines. Initialization tasks table now owned by RTEMS Tasks Manager.

Added user extension for post-switch.

Utilized user extensions to implement API specific functionality
like signal dispatching.

Added extensions to the System Initialization Thread so that an
API can register a function to be invoked while the system
is being initialized. These are largely equivalent to the
pre-driver and post-driver hooks.

Added the Modules file oar-go32_p5, modified oar-go32, and modified
the file make/custom/go32.cfg to look at an environment varable which
determines what CPU model is being used.

All BSPs updated to reflect named devices and clock driver's IOCTL
used by the Shared Memory Driver. Also merged clock isr into
main file and removed ckisr.c where possible.

Updated spsize to reflect new and moved variables.

Makefiles for the executive source and include files updated to show
break down of files into Core, RTEMS API, and Neither.

Header and inline files installed into subdirectory based on whether
logically in the Core or a part of the RTEMS API.

  • Property mode set to 100644
File size: 7.7 KB
Line 
1/*
2 *      @(#)bspstart.c  1.7 - 95/04/07
3 *
4 */
5
6/*  bsp_start()
7 *
8 *  This routine starts the application.  It includes application,
9 *  board, and monitor specific initialization and configuration.
10 *  The generic CPU dependent initialization has been performed
11 *  before this routine is invoked.
12 *
13 *  Called by RTEMS::RTEMS constructor in startup-ctor.cc
14 *
15 *  INPUT:  NONE
16 *
17 *  OUTPUT: NONE
18 *
19 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
20 *  On-Line Applications Research Corporation (OAR).
21 *  All rights assigned to U.S. Government, 1994.
22 *
23 *  This material may be reproduced by or for the U.S. Government pursuant
24 *  to the copyright license under the clause at DFARS 252.227-7013.  This
25 *  notice must appear in all copies of this file and its derivatives.
26 *
27 *  $Id$
28 */
29
30#include <rtems.h>
31
32#include <stdio.h>
33#include <stdlib.h>
34#include <fcntl.h>
35#include <unistd.h>
36
37#include <bsp.h>
38#include <libcsupport.h>
39
40#include <rtems/libio.h>
41
42#ifdef STACK_CHECKER_ON
43#include <stackchk.h>
44#endif
45
46extern rtems_configuration_table  Configuration;
47
48/*
49 * A copy of the configuration table from the application
50 * with some changes applied to it.
51 */
52
53rtems_configuration_table    BSP_Configuration;
54rtems_multiprocessing_table  BSP_Multiprocessing;
55rtems_cpu_table              Cpu_table;
56rtems_unsigned32             bsp_isr_level;
57rtems_unsigned32             Heap_size;
58int                          rtems_argc;
59char                       **rtems_argv;
60char                       **rtems_envp;
61
62/*
63 * May be overridden by RTEMS_WORKSPACE_SIZE and RTEMS_HEAPSPACE_SIZE
64 * environment variables; see below.
65 */
66
67#define DEFAULT_WORKSPACE_SIZE (WORKSPACE_MB * (1024 * 1024))
68#define DEFAULT_HEAPSPACE_SIZE (HEAPSPACE_MB * (1024 * 1024))
69
70/*
71 * Amount to increment itimer by each pass
72 * It is a variable instead of a #define to allow the 'looptest'
73 * script to bump it without recompiling rtems
74 */
75
76rtems_unsigned32 CPU_CLICKS_PER_TICK;
77
78/*
79 *  Function:   bsp_libc_init
80 *  Created:    94/12/6
81 *
82 *  Description:
83 *      Initialize whatever libc we are using
84 *      called from bsp_postdriver_hook
85 *
86 *
87 *  Parameters:
88 *      none
89 *
90 *  Returns:
91 *      none.
92 *
93 *  Side Effects:
94 *
95 *
96 *  Notes:
97 *
98 *  Deficiencies/ToDo:
99 *
100 *
101 */
102
103void
104bsp_libc_init(void)
105{
106    void *heap_start;
107
108    if (getenv("RTEMS_HEAPSPACE_SIZE"))
109        Heap_size = strtol(getenv("RTEMS_HEAPSPACE_SIZE"), 0, 0);
110    else
111        Heap_size = DEFAULT_HEAPSPACE_SIZE;
112 
113    heap_start = 0;
114
115    RTEMS_Malloc_Initialize((void *)heap_start, Heap_size, 1024 * 1024);
116
117    /*
118     *  Init the RTEMS libio facility to provide UNIX-like system
119     *  calls for use by newlib (ie: provide __open, __close, etc)
120     *  Uses malloc() to get area for the iops, so must be after malloc init
121     */
122
123    rtems_libio_init();
124
125    libc_init(1);
126}
127
128
129/*
130 *  Function:   bsp_pretasking_hook
131 *  Created:    95/03/10
132 *
133 *  Description:
134 *      BSP pretasking hook.  Called just before drivers are initialized.
135 *      Used to setup libc and install any BSP extensions.
136 *
137 *  Parameters:
138 *      none
139 *
140 *  Returns:
141 *      nada
142 *
143 *  Side Effects:
144 *      installs a few extensions
145 *
146 *  Notes:
147 *      Must not use libc (to do io) from here, since drivers are
148 *      not yet initialized.
149 *
150 *  Deficiencies/ToDo:
151 *
152 *
153 */
154
155void
156bsp_pretasking_hook(void)
157{
158    bsp_libc_init();
159
160#ifdef STACK_CHECKER_ON
161    /*
162     *  Initialize the stack bounds checker
163     *  We can either turn it on here or from the app.
164     */
165
166    Stack_check_Initialize();
167#endif
168
169#ifdef RTEMS_DEBUG
170    rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
171#endif
172}
173
174/*
175 * After drivers are setup, register some "filenames"
176 * and open stdin, stdout, stderr files
177 *
178 * Newlib will automatically associate the files with these
179 * (it hardcodes the numbers)
180 */
181 
182void
183bsp_postdriver_hook(void)
184{
185#if 0
186  int stdin_fd, stdout_fd, stderr_fd;
187 
188  if ((stdin_fd = __open("/dev/console", O_RDONLY, 0)) == -1)
189    rtems_fatal_error_occurred('STD0');
190 
191  if ((stdout_fd = __open("/dev/console", O_WRONLY, 0)) == -1)
192    rtems_fatal_error_occurred('STD1');
193 
194  if ((stderr_fd = __open("/dev/console", O_WRONLY, 0)) == -1)
195    rtems_fatal_error_occurred('STD2');
196 
197  if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2))
198    rtems_fatal_error_occurred('STIO');
199#endif
200}
201
202/*
203 *  Function:   bsp_start
204 *  Created:    94/12/6
205 *
206 *  Description:
207 *      called by crt0 as our "main" equivalent
208 *
209 *
210 *
211 *  Parameters:
212 *
213 *
214 *  Returns:
215 *
216 *
217 *  Side Effects:
218 *
219 *
220 *  Notes:
221 *
222 *
223 *  Deficiencies/ToDo:
224 *
225 *
226 */
227
228void
229bsp_start(void)
230{
231    unsigned32 workspace_ptr;
232
233    /*
234     *  Copy the table
235     */
236
237    BSP_Configuration = Configuration;
238 
239    /*
240     *  If the node number is -1 then the application better provide
241     *  it through environment variables RTEMS_NODE.
242     *  Ditto for RTEMS_MAXIMUM_NODES
243     */
244
245    if (BSP_Configuration.User_multiprocessing_table) {
246        char *p;
247 
248        /* make a copy for possible editing */
249        BSP_Multiprocessing = *BSP_Configuration.User_multiprocessing_table;
250        BSP_Configuration.User_multiprocessing_table = &BSP_Multiprocessing;
251 
252        if (BSP_Multiprocessing.node == -1)
253        {
254            p = getenv("RTEMS_NODE");
255            BSP_Multiprocessing.node = p ? atoi(p) : 1;
256        }
257 
258        /* If needed provide maximum_nodes also */
259        if (BSP_Multiprocessing.maximum_nodes == -1)
260        {
261            p = getenv("RTEMS_MAXIMUM_NODES");
262            BSP_Multiprocessing.maximum_nodes = p ? atoi(p) : 1;
263        }
264    }
265
266    /*
267     * Set cpu_number to accurately reflect our cpu number
268     */
269
270    if (BSP_Configuration.User_multiprocessing_table)
271        cpu_number = BSP_Configuration.User_multiprocessing_table->node - 1;
272    else
273        cpu_number = 0;
274
275    if (getenv("RTEMS_WORKSPACE_SIZE"))
276        BSP_Configuration.work_space_size = 
277           strtol(getenv("RTEMS_WORKSPACE_SIZE"), 0, 0);
278    else
279        BSP_Configuration.work_space_size = DEFAULT_WORKSPACE_SIZE;
280 
281    /*
282     * Allocate workspace memory, ensuring it is properly aligned
283     */
284 
285    workspace_ptr = 
286      (unsigned32) sbrk(BSP_Configuration.work_space_size + CPU_ALIGNMENT);
287    workspace_ptr += CPU_ALIGNMENT - 1;
288    workspace_ptr &= ~(CPU_ALIGNMENT - 1);
289
290    BSP_Configuration.work_space_start = (void *) workspace_ptr;
291 
292    /*
293     * Set up our hooks
294     * Make sure libc_init is done before drivers init'd so that
295     * they can use atexit()
296     */
297
298    Cpu_table.pretasking_hook = bsp_pretasking_hook;  /* init libc, etc. */
299
300    Cpu_table.predriver_hook = NULL;
301
302    Cpu_table.postdriver_hook = bsp_postdriver_hook;
303
304    Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
305
306    /*
307     *  Don't zero out the workspace since it is in the BSS under UNIX.
308     */
309
310    Cpu_table.do_zero_of_workspace = FALSE;
311
312    /*
313     * XXX; interrupt stack not currently used, so this doesn't matter
314     */
315
316    Cpu_table.interrupt_stack_size = (12 * 1024);
317
318    Cpu_table.extra_system_initialization_stack = 0;
319
320    /*
321     * Add 1 region for RTEMS Malloc
322     */
323
324    BSP_Configuration.maximum_regions++;
325
326#ifdef RTEMS_NEWLIB
327    /*
328     * Add 1 extension for newlib libc
329     */
330
331    BSP_Configuration.maximum_extensions++;
332#endif
333
334#ifdef STACK_CHECKER_ON
335  /*
336   * Add 1 extension for stack checker
337   */
338
339    BSP_Configuration.maximum_extensions++;
340#endif
341
342  /*
343   * Tell libio how many fd's we want and allow it to tweak config
344   */
345
346  rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS);
347
348  /*
349   * Add 1 extension for MPCI_fatal
350   */
351
352  if (BSP_Configuration.User_multiprocessing_table)
353      BSP_Configuration.maximum_extensions++;
354
355  CPU_CLICKS_PER_TICK = 1;
356
357  /*
358   *  Start most of RTEMS
359   *  main() will start the rest
360   */
361
362  bsp_isr_level = rtems_initialize_executive_early(
363    &BSP_Configuration,
364    &Cpu_table
365  );
366}
Note: See TracBrowser for help on using the repository browser.