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

4.104.114.84.95
Last change on this file since 9700578 was 9700578, checked in by Joel Sherrill <joel.sherrill@…>, on 10/30/95 at 21:54:45

SPARC port passes all tests

  • Property mode set to 100644
File size: 7.9 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 <stdio.h>
31#include <stdlib.h>
32#include <fcntl.h>
33#include <unistd.h>
34
35#include <bsp.h>
36#include <libcsupport.h>
37
38#include <rtems/libio.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    /*
116     *  Init the RTEMS libio facility to provide UNIX-like system
117     *  calls for use by newlib (ie: provide __open, __close, etc)
118     *  Uses malloc() to get area for the iops, so must be after malloc init
119     */
120
121    rtems_libio_init();
122
123    libc_init(1);
124}
125
126
127/*
128 *  Function:   bsp_pretasking_hook
129 *  Created:    95/03/10
130 *
131 *  Description:
132 *      BSP pretasking hook.  Called just before drivers are initialized.
133 *      Used to setup libc and install any BSP extensions.
134 *
135 *  Parameters:
136 *      none
137 *
138 *  Returns:
139 *      nada
140 *
141 *  Side Effects:
142 *      installs a few extensions
143 *
144 *  Notes:
145 *      Must not use libc (to do io) from here, since drivers are
146 *      not yet initialized.
147 *
148 *  Deficiencies/ToDo:
149 *
150 *
151 */
152
153void
154bsp_pretasking_hook(void)
155{
156    bsp_libc_init();
157
158#ifdef STACK_CHECKER_ON
159    /*
160     *  Initialize the stack bounds checker
161     *  We can either turn it on here or from the app.
162     */
163
164    Stack_check_Initialize();
165#endif
166
167#ifdef RTEMS_DEBUG
168    rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
169#endif
170}
171
172/*
173 * After drivers are setup, register some "filenames"
174 * and open stdin, stdout, stderr files
175 *
176 * Newlib will automatically associate the files with these
177 * (it hardcodes the numbers)
178 */
179 
180void
181bsp_postdriver_hook(void)
182{
183#if 0
184  int stdin_fd, stdout_fd, stderr_fd;
185  int error_code;
186 
187  error_code = 'S' << 24 | 'T' << 16;
188 
189  if ((stdin_fd = __open("/dev/console", O_RDONLY, 0)) == -1)
190    rtems_fatal_error_occurred( error_code | 'D' << 8 | '0' );
191 
192  if ((stdout_fd = __open("/dev/console", O_WRONLY, 0)) == -1)
193    rtems_fatal_error_occurred( error_code | 'D' << 8 | '1' );
194 
195  if ((stderr_fd = __open("/dev/console", O_WRONLY, 0)) == -1)
196    rtems_fatal_error_occurred( error_code | 'D' << 8 | '2' );
197 
198  if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2))
199    rtems_fatal_error_occurred( error_code | 'I' << 8 | 'O' );
200#endif
201
202#if defined(MALLOC_STATS)
203  atexit(malloc_dump);
204#endif
205
206}
207
208/*
209 *  Function:   bsp_start
210 *  Created:    94/12/6
211 *
212 *  Description:
213 *      called by crt0 as our "main" equivalent
214 *
215 *
216 *
217 *  Parameters:
218 *
219 *
220 *  Returns:
221 *
222 *
223 *  Side Effects:
224 *
225 *
226 *  Notes:
227 *
228 *
229 *  Deficiencies/ToDo:
230 *
231 *
232 */
233
234void
235bsp_start(void)
236{
237    unsigned32 workspace_ptr;
238
239    /*
240     *  Copy the table
241     */
242
243    BSP_Configuration = Configuration;
244 
245    /*
246     *  If the node number is -1 then the application better provide
247     *  it through environment variables RTEMS_NODE.
248     *  Ditto for RTEMS_MAXIMUM_NODES
249     */
250
251    if (BSP_Configuration.User_multiprocessing_table) {
252        char *p;
253 
254        /* make a copy for possible editing */
255        BSP_Multiprocessing = *BSP_Configuration.User_multiprocessing_table;
256        BSP_Configuration.User_multiprocessing_table = &BSP_Multiprocessing;
257 
258        if (BSP_Multiprocessing.node == -1)
259        {
260            p = getenv("RTEMS_NODE");
261            BSP_Multiprocessing.node = p ? atoi(p) : 1;
262        }
263 
264        /* If needed provide maximum_nodes also */
265        if (BSP_Multiprocessing.maximum_nodes == -1)
266        {
267            p = getenv("RTEMS_MAXIMUM_NODES");
268            BSP_Multiprocessing.maximum_nodes = p ? atoi(p) : 1;
269        }
270    }
271
272    /*
273     * Set cpu_number to accurately reflect our cpu number
274     */
275
276    if (BSP_Configuration.User_multiprocessing_table)
277        cpu_number = BSP_Configuration.User_multiprocessing_table->node - 1;
278    else
279        cpu_number = 0;
280
281    if (getenv("RTEMS_WORKSPACE_SIZE"))
282        BSP_Configuration.work_space_size =
283           strtol(getenv("RTEMS_WORKSPACE_SIZE"), 0, 0);
284    else
285        BSP_Configuration.work_space_size = DEFAULT_WORKSPACE_SIZE;
286 
287    /*
288     * Allocate workspace memory, ensuring it is properly aligned
289     */
290 
291    workspace_ptr =
292      (unsigned32) sbrk(BSP_Configuration.work_space_size + CPU_ALIGNMENT);
293    workspace_ptr += CPU_ALIGNMENT - 1;
294    workspace_ptr &= ~(CPU_ALIGNMENT - 1);
295
296    BSP_Configuration.work_space_start = (void *) workspace_ptr;
297 
298    /*
299     * Set up our hooks
300     * Make sure libc_init is done before drivers init'd so that
301     * they can use atexit()
302     */
303
304    Cpu_table.pretasking_hook = bsp_pretasking_hook;  /* init libc, etc. */
305
306    Cpu_table.predriver_hook = NULL;
307
308    Cpu_table.postdriver_hook = bsp_postdriver_hook;
309
310    Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
311
312    /*
313     *  Don't zero out the workspace since it is in the BSS under UNIX.
314     */
315
316    Cpu_table.do_zero_of_workspace = FALSE;
317
318    /*
319     * XXX; interrupt stack not currently used, so this doesn't matter
320     */
321
322    Cpu_table.interrupt_stack_size = (12 * 1024);
323
324    Cpu_table.extra_system_initialization_stack = 0;
325
326    /*
327     * Add 1 region for RTEMS Malloc
328     */
329
330    BSP_Configuration.maximum_regions++;
331
332#ifdef RTEMS_NEWLIB
333    /*
334     * Add 1 extension for newlib libc
335     */
336
337    BSP_Configuration.maximum_extensions++;
338#endif
339
340#ifdef STACK_CHECKER_ON
341  /*
342   * Add 1 extension for stack checker
343   */
344
345    BSP_Configuration.maximum_extensions++;
346#endif
347
348  /*
349   * Tell libio how many fd's we want and allow it to tweak config
350   */
351
352  rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS);
353
354  /*
355   * Add 1 extension for MPCI_fatal
356   */
357
358  if (BSP_Configuration.User_multiprocessing_table)
359      BSP_Configuration.maximum_extensions++;
360
361  CPU_CLICKS_PER_TICK = 1;
362
363  /*
364   *  Start most of RTEMS
365   *  main() will start the rest
366   */
367
368  bsp_isr_level = rtems_initialize_executive_early(
369    &BSP_Configuration,
370    &Cpu_table
371  );
372}
Note: See TracBrowser for help on using the repository browser.