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

4.104.114.84.9
Last change on this file since bd9c3d1 was bd9c3d1, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 15, 1998 at 8:50:31 PM

Numerous changes which in total greatly reduced the amount of source
code in each BSP's bspstart.c. These changes were:

+ confdefs.h now knows libio's semaphore requirements
+ shared/main.c now copies Configuration to BSP_Configuration
+ shared/main.c fills in the Cpu_table with default values

This removed the need for rtems_libio_config() and the constant
BSP_LIBIO_MAX_FDS in every BSP. Plus now the maximum number of open
files can now be set on the gcc command line.

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/*
2 *  This routine starts the application.  It includes application,
3 *  board, and monitor specific initialization and configuration.
4 *  The generic CPU dependent initialization has been performed
5 *  before this routine is invoked.
6 *
7 *  Called by RTEMS::RTEMS constructor in startup-ctor.cc
8 *
9 *  COPYRIGHT (c) 1989-1998.
10 *  On-Line Applications Research Corporation (OAR).
11 *  Copyright assigned to U.S. Government, 1994.
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.OARcorp.com/rtems/license.html.
16 *
17 *  $Id$
18 */
19
20#include <stdio.h>
21#include <stdlib.h>
22
23/* for sbrk prototype in linux */
24#if defined(__linux__)
25#define __USE_MISC
26#endif
27#include <unistd.h>
28
29#include <bsp.h>
30#include <libcsupport.h>
31
32#include <rtems/libio.h>
33
34extern rtems_configuration_table  Configuration;
35
36/*
37 * A copy of the configuration table from the application
38 * with some changes applied to it.
39 */
40
41rtems_configuration_table    BSP_Configuration;
42rtems_multiprocessing_table  BSP_Multiprocessing;
43rtems_cpu_table              Cpu_table;
44rtems_unsigned32             bsp_isr_level;
45rtems_unsigned32             Heap_size;
46int                          rtems_argc;
47char                       **rtems_argv;
48
49/*
50 * May be overridden by RTEMS_WORKSPACE_SIZE and RTEMS_HEAPSPACE_SIZE
51 * environment variables; see below.
52 */
53
54#define DEFAULT_WORKSPACE_SIZE (WORKSPACE_MB * (1024 * 1024))
55#define DEFAULT_HEAPSPACE_SIZE (HEAPSPACE_MB * (1024 * 1024))
56
57/*
58 * Amount to increment itimer by each pass
59 * It is a variable instead of a #define to allow the 'looptest'
60 * script to bump it without recompiling rtems
61 */
62
63rtems_unsigned32 CPU_CLICKS_PER_TICK;
64
65/*
66 *  Use the shared implementations of the following routines
67 */
68 
69void bsp_postdriver_hook(void);
70void bsp_libc_init( void *, unsigned32, int );
71
72/*
73 *  Function:   bsp_pretasking_hook
74 *  Created:    95/03/10
75 *
76 *  Description:
77 *      BSP pretasking hook.  Called just before drivers are initialized.
78 *      Used to setup libc and install any BSP extensions.
79 *
80 *  NOTES:
81 *      Must not use libc (to do io) from here, since drivers are
82 *      not yet initialized.
83 */
84
85void bsp_pretasking_hook(void)
86{
87    void *heap_start;
88
89    if (getenv("RTEMS_HEAPSPACE_SIZE"))
90        Heap_size = strtol(getenv("RTEMS_HEAPSPACE_SIZE"), 0, 0);
91    else
92        Heap_size = DEFAULT_HEAPSPACE_SIZE;
93 
94    heap_start = 0;
95
96    bsp_libc_init((void *)heap_start, Heap_size, 1024 * 1024);
97
98
99#ifdef RTEMS_DEBUG
100    rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
101#endif
102
103    /*
104     * Dump malloc stats on exit...
105     */
106#if defined(RTEMS_DEBUG)
107  atexit(malloc_dump);
108#endif
109}
110
111/*
112 *  DO NOT Use the shared bsp_postdriver_hook() implementation
113 */
114 
115void bsp_postdriver_hook(void)
116{
117  return;
118}
119
120/*
121 *  bsp_start
122 *
123 *  This routine does the bulk of the system initialization.
124 */
125
126void bsp_start(void)
127{
128    unsigned32 workspace_ptr;
129
130    /*
131     *  Copy the table (normally done in shared main).
132     */
133
134    BSP_Configuration = Configuration;
135 
136    /*
137     *  If the node number is -1 then the application better provide
138     *  it through environment variables RTEMS_NODE.
139     *  Ditto for RTEMS_MAXIMUM_NODES
140     */
141
142    if (BSP_Configuration.User_multiprocessing_table) {
143        char *p;
144 
145        /* make a copy for possible editing */
146        BSP_Multiprocessing = *BSP_Configuration.User_multiprocessing_table;
147        BSP_Configuration.User_multiprocessing_table = &BSP_Multiprocessing;
148 
149        if (BSP_Multiprocessing.node == -1)
150        {
151            p = getenv("RTEMS_NODE");
152            BSP_Multiprocessing.node = p ? atoi(p) : 1;
153        }
154 
155        /* If needed provide maximum_nodes also */
156        if (BSP_Multiprocessing.maximum_nodes == -1)
157        {
158            p = getenv("RTEMS_MAXIMUM_NODES");
159            BSP_Multiprocessing.maximum_nodes = p ? atoi(p) : 1;
160        }
161    }
162
163    /*
164     * Set cpu_number to accurately reflect our cpu number
165     */
166
167    if (BSP_Configuration.User_multiprocessing_table)
168        cpu_number = BSP_Configuration.User_multiprocessing_table->node - 1;
169    else
170        cpu_number = 0;
171
172    if (getenv("RTEMS_WORKSPACE_SIZE"))
173        BSP_Configuration.work_space_size = 
174           strtol(getenv("RTEMS_WORKSPACE_SIZE"), 0, 0);
175    else
176        BSP_Configuration.work_space_size = DEFAULT_WORKSPACE_SIZE;
177 
178    /*
179     * Allocate workspace memory, ensuring it is properly aligned
180     */
181 
182    workspace_ptr = 
183      (unsigned32) sbrk(BSP_Configuration.work_space_size + CPU_ALIGNMENT);
184    workspace_ptr += CPU_ALIGNMENT - 1;
185    workspace_ptr &= ~(CPU_ALIGNMENT - 1);
186
187    BSP_Configuration.work_space_start = (void *) workspace_ptr;
188 
189    /*
190     * Set up our hooks
191     * Make sure libc_init is done before drivers init'd so that
192     * they can use atexit()
193     */
194
195    Cpu_table.pretasking_hook = bsp_pretasking_hook;  /* init libc, etc. */
196
197    Cpu_table.predriver_hook = NULL;
198
199    Cpu_table.postdriver_hook = bsp_postdriver_hook;
200
201    Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
202
203    /*
204     *  Don't zero out the workspace since it is in the BSS under UNIX.
205     */
206
207    Cpu_table.do_zero_of_workspace = FALSE;
208
209    /*
210     * XXX; interrupt stack not currently used, so this doesn't matter
211     */
212
213    Cpu_table.interrupt_stack_size = (12 * 1024);
214
215    Cpu_table.extra_mpci_receive_server_stack = 0;
216
217    /*
218     * Add 1 extension for MPCI_fatal
219     */
220
221    if (BSP_Configuration.User_multiprocessing_table)
222        BSP_Configuration.maximum_extensions++;
223
224    CPU_CLICKS_PER_TICK = 1;
225
226    /*
227     *  Start most of RTEMS
228     *  main() will start the rest
229     */
230
231    bsp_isr_level = rtems_initialize_executive_early(
232      &BSP_Configuration,
233      &Cpu_table
234    );
235}
Note: See TracBrowser for help on using the repository browser.