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

4.104.114.84.95
Last change on this file since 0451b44 was c244a9ee, checked in by Joel Sherrill <joel.sherrill@…>, on 04/14/98 at 21:32:12

Stack checker extension now accounted for in confdefs.h

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