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

4.104.114.95
Last change on this file since a70ec6cb was a70ec6cb, checked in by Joel Sherrill <joel.sherrill@…>, on 12/12/07 at 17:08:20

2007-12-12 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, startup/bspstart.c: Links and runs again.
  • console/console-io.c: New file.
  • Property mode set to 100644
File size: 3.9 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-1999.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 *
16 *  $Id$
17 */
18
19#include <stdio.h>
20#include <stdlib.h>
21#include <unistd.h>
22
23#include <bsp.h>
24#include <rtems/libcsupport.h>
25#include <rtems/libio.h>
26
27uint32_t                     Heap_size;
28int                          rtems_argc;
29char                       **rtems_argv;
30
31/*
32 * May be overridden by RTEMS_WORKSPACE_SIZE and RTEMS_HEAPSPACE_SIZE
33 * environment variables; see below.
34 */
35
36#define DEFAULT_WORKSPACE_SIZE (WORKSPACE_MB * (1024 * 1024))
37#define DEFAULT_HEAPSPACE_SIZE (HEAPSPACE_MB * (1024 * 1024))
38
39/*
40 * Amount to increment itimer by each pass
41 * It is a variable instead of a #define to allow the 'looptest'
42 * script to bump it without recompiling rtems
43 */
44
45uint32_t         CPU_CLICKS_PER_TICK;
46
47/*
48 *  Use the shared implementations of the following routines
49 */
50
51void bsp_postdriver_hook(void);
52void bsp_libc_init( void *, uint32_t, int );
53
54/*
55 *  Function:   bsp_pretasking_hook
56 *  Created:    95/03/10
57 *
58 *  Description:
59 *      BSP pretasking hook.  Called just before drivers are initialized.
60 *      Used to setup libc and install any BSP extensions.
61 *
62 *  NOTES:
63 *      Must not use libc (to do io) from here, since drivers are
64 *      not yet initialized.
65 */
66
67void bsp_pretasking_hook(void)
68{
69    void *heap_start;
70
71    if (getenv("RTEMS_HEAPSPACE_SIZE"))
72        Heap_size = strtol(getenv("RTEMS_HEAPSPACE_SIZE"), 0, 0);
73    else
74        Heap_size = DEFAULT_HEAPSPACE_SIZE;
75
76    heap_start = 0;
77
78    bsp_libc_init((void *)heap_start, Heap_size, 1024 * 1024);
79
80#ifdef RTEMS_DEBUG
81    rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
82#endif
83
84    /*
85     * Dump malloc stats on exit...
86     */
87#if defined(RTEMS_DEBUG)
88  atexit(malloc_dump);
89#endif
90}
91
92/*
93 *  DO NOT Use the shared bsp_postdriver_hook() implementation
94 */
95
96void bsp_postdriver_hook(void)
97{
98  return;
99}
100
101/*
102 *  bsp_start
103 *
104 *  This routine does the bulk of the system initialization.
105 */
106
107void bsp_start(void)
108{
109  uintptr_t   workspace_ptr;
110
111  cpu_number = 0;
112
113  #if defined(RTEMS_MULTIPROCESSING)
114    /*
115     *  If the node number is -1 then the application better provide
116     *  it through environment variables RTEMS_NODE.
117     *  Ditto for RTEMS_MAXIMUM_NODES
118     */
119    if (Configuration.User_multiprocessing_table) {
120      char *p;
121
122      if (Configuration.User_multiprocessing_table->node == -1) {
123        p = getenv("RTEMS_NODE");
124        Configuration.User_multiprocessing_table->node = p ? atoi(p) : 1;
125      }
126
127      /* If needed provide maximum_nodes also */
128      if (Configuration.User_multiprocessing_table->maximum_nodes == -1) {
129        p = getenv("RTEMS_MAXIMUM_NODES");
130       Configuration.User_multiprocessing_table->maximum_nodes = p ? atoi(p) : 1;
131      }
132    }
133
134    /*
135     * Set cpu_number to accurately reflect our cpu number
136     */
137      if (Configuration.User_multiprocessing_table)
138        cpu_number = Configuration.User_multiprocessing_table->node - 1;
139   #endif
140
141    if (getenv("RTEMS_WORKSPACE_SIZE"))
142        rtems_configuration_get_work_space_size() =
143           strtol(getenv("RTEMS_WORKSPACE_SIZE"), 0, 0);
144    else
145        rtems_configuration_get_work_space_size() = DEFAULT_WORKSPACE_SIZE;
146
147    /*
148     * Allocate workspace memory, ensuring it is properly aligned
149     */
150
151    workspace_ptr =
152      (uintptr_t) sbrk(rtems_configuration_get_work_space_size() + CPU_ALIGNMENT);
153    workspace_ptr += CPU_ALIGNMENT - 1;
154    workspace_ptr &= ~(CPU_ALIGNMENT - 1);
155
156    Configuration.work_space_start = (void *) workspace_ptr;
157
158    CPU_CLICKS_PER_TICK = 1;
159
160}
Note: See TracBrowser for help on using the repository browser.