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

4.104.114.84.95
Last change on this file since 634e746 was 634e746, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 29, 1997 at 12:28:47 AM

All RTEMS system call implementation renamed to be rtems_*.

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