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

4.104.114.84.95
Last change on this file since c1403ef1 was c1403ef1, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 11, 1995 at 2:30:27 PM

Added flush of output on exit. On some UNIX's using the native library
resulted in no output when the output was redirected until this was done.
Redirection is important because runtest redirects test output.

Added support for numerous environment variables which make it easier
to run a multi-node system using a single executable and to tailor
the size of the workspace and heap.

  • Property mode set to 100644
File size: 6.6 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#ifdef STACK_CHECKER_ON
41#include <stackchk.h>
42#endif
43
44extern rtems_configuration_table  Configuration;
45
46/*
47 * A copy of the configuration table from the application
48 * with some changes applied to it.
49 */
50
51rtems_configuration_table    BSP_Configuration;
52rtems_multiprocessing_table  BSP_Multiprocessing;
53rtems_cpu_table              Cpu_table;
54rtems_unsigned32             bsp_isr_level;
55rtems_unsigned32             Heap_size;
56int                          rtems_argc;
57char                       **rtems_argv;
58char                       **rtems_envp;
59
60/*
61 * May be overridden by RTEMS_WORKSPACE_SIZE and RTEMS_HEAPSPACE_SIZE
62 * environment variables; see below.
63 */
64
65#define DEFAULT_WORKSPACE_SIZE (WORKSPACE_MB * (1024 * 1024))
66#define DEFAULT_HEAPSPACE_SIZE (HEAPSPACE_MB * (1024 * 1024))
67
68/*
69 * Amount to increment itimer by each pass
70 * It is a variable instead of a #define to allow the 'looptest'
71 * script to bump it without recompiling rtems
72 */
73
74rtems_unsigned32 CPU_CLICKS_PER_TICK;
75
76/*
77 *  Function:   bsp_libc_init
78 *  Created:    94/12/6
79 *
80 *  Description:
81 *      Initialize whatever libc we are using
82 *      called from bsp_postdriver_hook
83 *
84 *
85 *  Parameters:
86 *      none
87 *
88 *  Returns:
89 *      none.
90 *
91 *  Side Effects:
92 *
93 *
94 *  Notes:
95 *
96 *  Deficiencies/ToDo:
97 *
98 *
99 */
100
101void
102bsp_libc_init(void)
103{
104    void *heap_start;
105
106    if (getenv("RTEMS_HEAPSPACE_SIZE"))
107        Heap_size = strtol(getenv("RTEMS_HEAPSPACE_SIZE"), 0, 0);
108    else
109        Heap_size = DEFAULT_HEAPSPACE_SIZE;
110 
111    heap_start = 0;
112
113    RTEMS_Malloc_Initialize((void *)heap_start, Heap_size, 1024 * 1024);
114
115    libc_init(1);
116}
117
118
119/*
120 *  Function:   bsp_pretasking_hook
121 *  Created:    95/03/10
122 *
123 *  Description:
124 *      BSP pretasking hook.  Called just before drivers are initialized.
125 *      Used to setup libc and install any BSP extensions.
126 *
127 *  Parameters:
128 *      none
129 *
130 *  Returns:
131 *      nada
132 *
133 *  Side Effects:
134 *      installs a few extensions
135 *
136 *  Notes:
137 *      Must not use libc (to do io) from here, since drivers are
138 *      not yet initialized.
139 *
140 *  Deficiencies/ToDo:
141 *
142 *
143 */
144
145void
146bsp_pretasking_hook(void)
147{
148    bsp_libc_init();
149
150#ifdef STACK_CHECKER_ON
151    /*
152     *  Initialize the stack bounds checker
153     *  We can either turn it on here or from the app.
154     */
155
156    Stack_check_Initialize();
157#endif
158
159#ifdef RTEMS_DEBUG
160    rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
161#endif
162}
163
164/*
165 *  Function:   bsp_start
166 *  Created:    94/12/6
167 *
168 *  Description:
169 *      called by crt0 as our "main" equivalent
170 *
171 *
172 *
173 *  Parameters:
174 *
175 *
176 *  Returns:
177 *
178 *
179 *  Side Effects:
180 *
181 *
182 *  Notes:
183 *
184 *
185 *  Deficiencies/ToDo:
186 *
187 *
188 */
189
190void
191bsp_start(void)
192{
193    unsigned32 workspace_ptr;
194
195    /*
196     *  Copy the table
197     */
198
199    BSP_Configuration = Configuration;
200 
201    /*
202     *  If the node number is -1 then the application better provide
203     *  it through environment variables RTEMS_NODE.
204     *  Ditto for RTEMS_MAXIMUM_NODES
205     */
206
207    if (BSP_Configuration.User_multiprocessing_table) {
208        char *p;
209 
210        /* make a copy for possible editing */
211        BSP_Multiprocessing = *BSP_Configuration.User_multiprocessing_table;
212        BSP_Configuration.User_multiprocessing_table = &BSP_Multiprocessing;
213 
214        if (BSP_Multiprocessing.node == -1)
215        {
216            p = getenv("RTEMS_NODE");
217            BSP_Multiprocessing.node = p ? atoi(p) : 1;
218        }
219 
220        /* If needed provide maximum_nodes also */
221        if (BSP_Multiprocessing.maximum_nodes == -1)
222        {
223            p = getenv("RTEMS_MAXIMUM_NODES");
224            BSP_Multiprocessing.maximum_nodes = p ? atoi(p) : 1;
225        }
226    }
227
228    /*
229     * Set cpu_number to accurately reflect our cpu number
230     */
231
232    if (BSP_Configuration.User_multiprocessing_table)
233        cpu_number = BSP_Configuration.User_multiprocessing_table->node - 1;
234    else
235        cpu_number = 0;
236
237    if (getenv("RTEMS_WORKSPACE_SIZE"))
238        BSP_Configuration.work_space_size = 
239           strtol(getenv("RTEMS_WORKSPACE_SIZE"), 0, 0);
240    else
241        BSP_Configuration.work_space_size = DEFAULT_WORKSPACE_SIZE;
242 
243    /*
244     * Allocate workspace memory, ensuring it is properly aligned
245     */
246 
247    workspace_ptr = 
248      (unsigned32) sbrk(BSP_Configuration.work_space_size + CPU_ALIGNMENT);
249    workspace_ptr += CPU_ALIGNMENT - 1;
250    workspace_ptr &= ~(CPU_ALIGNMENT - 1);
251
252    BSP_Configuration.work_space_start = (void *) workspace_ptr;
253 
254    /*
255     * Set up our hooks
256     * Make sure libc_init is done before drivers init'd so that
257     * they can use atexit()
258     */
259
260    Cpu_table.pretasking_hook = bsp_pretasking_hook;  /* init libc, etc. */
261
262    Cpu_table.predriver_hook = NULL;
263
264    Cpu_table.postdriver_hook = NULL;
265
266    Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
267
268    /*
269     *  Don't zero out the workspace since it is in the BSS under UNIX.
270     */
271
272    Cpu_table.do_zero_of_workspace = FALSE;
273
274    /*
275     * XXX; interrupt stack not currently used, so this doesn't matter
276     */
277
278    Cpu_table.interrupt_stack_size = (12 * 1024);
279
280    Cpu_table.extra_system_initialization_stack = 0;
281
282    /*
283     * Add 1 region for RTEMS Malloc
284     */
285
286    BSP_Configuration.maximum_regions++;
287
288#ifdef RTEMS_NEWLIB
289    /*
290     * Add 1 extension for newlib libc
291     */
292
293    BSP_Configuration.maximum_extensions++;
294#endif
295
296#ifdef STACK_CHECKER_ON
297  /*
298   * Add 1 extension for stack checker
299   */
300
301    BSP_Configuration.maximum_extensions++;
302#endif
303
304    /*
305     * Add 1 extension for MPCI_fatal
306     */
307
308    if (BSP_Configuration.User_multiprocessing_table)
309        BSP_Configuration.maximum_extensions++;
310
311    CPU_CLICKS_PER_TICK = 1;
312
313    /*
314     *  Start most of RTEMS
315     *  main() will start the rest
316     */
317
318    bsp_isr_level = rtems_initialize_executive_early(
319      &BSP_Configuration,
320      &Cpu_table
321    );
322}
Note: See TracBrowser for help on using the repository browser.