source: rtems/c/src/lib/libbsp/shared/bootcard.c @ 71d0488b

4.104.115
Last change on this file since 71d0488b was 71d0488b, checked in by Joel Sherrill <joel.sherrill@…>, on 12/15/08 at 19:22:36

2008-12-15 Joel Sherrill <joel.sherrill@…>

  • bootcard.c: Eliminate pointers to API configuration tables in the main configuration table. Reference the main configuration table and the API configuration tables directly using the confdefs.h version rather than obtaining a pointer to it. This eliminated some variables, a potential fatal error, some unnecessary default configuration structures. Overall, about a 4.5% reduction in the code size for minimum and hello on the SPARC.
  • Property mode set to 100644
File size: 8.2 KB
Line 
1/*
2 *  This is the C entry point for ALL RTEMS BSPs.  It is invoked
3 *  from the assembly language initialization file usually called
4 *  start.S.  It provides the framework for the BSP initialization
5 *  sequence.  The basic flow of initialization is:
6 *
7 *  + start.S: basic CPU setup (stack, zero BSS)
8 *    + boot_card
9 *      + if defined(BSP_BOOTCARD_HANDLES_RAM_ALLOCATION)
10 *        - obtain information on BSP memory and allocate RTEMS Workspace
11 *      + bspstart.c: bsp_start - more advanced initialization
12 *      + rtems_initialize_data_structures
13 *      + if defined(BSP_BOOTCARD_HANDLES_RAM_ALLOCATION)
14 *        - Allocate memory to C Program Heap
15 *        - initialize C Library and C Program Heap
16 *      + bsp_pretasking_hook
17 *      + if defined(RTEMS_DEBUG)
18 *        - rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
19 *      + rtems_initialize_before_drivers
20 *      + bsp_predriver_hook
21 *      + rtems_initialize_device_drivers
22 *        - all device drivers
23 *      + bsp_postdriver_hook
24 *      + rtems_initialize_start_multitasking
25 *        - 1st task executes C++ global constructors
26 *          .... appplication runs ...
27 *          - exit
28 *     + back to here eventually
29 *     + bspclean.c: bsp_cleanup
30 *
31 *  This style of initialization ensures that the C++ global
32 *  constructors are executed after RTEMS is initialized.
33 *  Thanks to Chris Johns <cjohns@plessey.com.au> for the idea
34 *  to move C++ global constructors into the first task.
35 *
36 *  COPYRIGHT (c) 1989-2008.
37 *  On-Line Applications Research Corporation (OAR).
38 *
39 *  The license and distribution terms for this file may be
40 *  found in the file LICENSE in this distribution or at
41 *  http://www.rtems.com/license/LICENSE.
42 *
43 *  $Id$
44 */
45
46#include <rtems.h>
47
48#include <bsp/bootcard.h>
49
50/*
51 *  Since there is a forward reference
52 */
53char *rtems_progname;
54
55/*
56 * Are we using a single heap for the RTEMS Workspace and C Program Heap?
57 */
58extern bool rtems_unified_work_area;
59
60/*
61 *  These are the prototypes and helper routines which are used
62 *  when the BSP lets the framework handle RAM allocation between
63 *  the RTEMS Workspace and C Program Heap.
64 */
65static rtems_status_code bootcard_bsp_libc_helper(
66  void    *work_area_start,
67  intptr_t work_area_size,
68  void    *heap_start,
69  intptr_t heap_size
70)
71{
72  intptr_t heap_size_default = 0;
73
74  if ( !rtems_unified_work_area &&
75       heap_start == BSP_BOOTCARD_HEAP_USES_WORK_AREA) {
76    /* Use the work area start as heap start */
77    heap_start = work_area_start;
78
79    /* Ensure proper alignement */
80    if ((uintptr_t) heap_start & (CPU_ALIGNMENT - 1)) {
81      heap_start = (void *) (((uintptr_t) heap_start + CPU_ALIGNMENT)
82        & ~(CPU_ALIGNMENT - 1));
83    }
84
85    /*
86     * For the default heap size use the free space from the start of the
87     * work area up to the work space start as heap area.
88     */
89    heap_size_default = (intptr_t) ((char *) Configuration.work_space_start
90      - (char *) work_area_start);
91
92    /* Keep it as a multiple of 16 bytes */
93    heap_size_default &= ~((intptr_t) 0xf);
94
95    /* Use default heap size if requested */
96    if (heap_size == BSP_BOOTCARD_HEAP_SIZE_DEFAULT) {
97      heap_size = heap_size_default;
98    }
99             
100    /* Check heap size */
101    if (heap_size > heap_size_default) {
102      return RTEMS_INVALID_SIZE;
103    }
104  }
105
106  bsp_libc_init(heap_start, heap_size, 0);
107
108  return RTEMS_SUCCESSFUL;
109}
110
111/*
112 *  This is the initialization framework routine that weaves together
113 *  calls to RTEMS and the BSP in the proper sequence to initialize
114 *  the system while maximizing shared code and keeping BSP code in C
115 *  as much as possible.
116 */
117int boot_card(
118  int    argc,
119  char **argv,
120  char **envp
121)
122{
123  static char            *argv_pointer = NULL;
124  static char            *envp_pointer = NULL;
125  char                  **argv_p = &argv_pointer;
126  char                  **envp_p = &envp_pointer;
127  rtems_interrupt_level   bsp_isr_level;
128  rtems_status_code       sc = RTEMS_SUCCESSFUL;
129  void                   *work_area_start = NULL;
130  intptr_t                work_area_size = 0;
131  void                   *heap_start = NULL;
132  intptr_t                heap_size = 0;
133
134  /*
135   * Special case for PowerPC: The interrupt disable mask is stored in SPRG0.
136   * It must be valid before we can use rtems_interrupt_disable().
137   */
138  #ifdef PPC_INTERRUPT_DISABLE_MASK_DEFAULT
139    ppc_interrupt_set_disable_mask( PPC_INTERRUPT_DISABLE_MASK_DEFAULT );
140  #endif /* PPC_INTERRUPT_DISABLE_MASK_DEFAULT */
141
142  /*
143   *  Make sure interrupts are disabled.
144   */
145  rtems_interrupt_disable( bsp_isr_level );
146
147  /*
148   *  Set things up so we have real pointers for argv and envp.
149   *  If the BSP has passed us something useful, then pass it on.
150   *  Somehow we need to eventually make this available to
151   *  a real main() in user land. :)
152   */
153  if ( argv ) argv_p = argv;
154  if ( envp ) envp_p = envp;
155
156  /*
157   *  Set the program name in case some application cares.
158   */
159  if ((argc > 0) && argv && argv[0])
160    rtems_progname = argv[0];
161  else
162    rtems_progname = "RTEMS";
163
164  /*
165   * Invoke Board Support Package initialization routine written in C.
166   */
167  bsp_start();
168
169  /*
170   *  Find out where the block of memory the BSP will use for
171   *  the RTEMS Workspace and the C Program Heap is.
172   */
173  bsp_get_work_area(&work_area_start, &work_area_size, &heap_start, &heap_size);
174
175  if ( work_area_size <= Configuration.work_space_size ) {
176    printk( "bootcard: Work space too big for work area!\n");
177    bsp_cleanup();
178    return -1;
179  }
180
181  if ( rtems_unified_work_area ) {
182    Configuration.work_space_start = work_area_start;
183    Configuration.work_space_size  = work_area_size;
184  } else {
185    Configuration.work_space_start = (char *) work_area_start +
186      work_area_size - rtems_configuration_get_work_space_size();
187  }
188
189  #if (BSP_DIRTY_MEMORY == 1)
190    memset( work_area_start, 0xCF,  work_area_size );
191  #endif
192
193  /*
194   *  Initialize RTEMS data structures
195   */
196  rtems_initialize_data_structures();
197
198  /*
199   *  Initialize the C library for those BSPs using the shared
200   *  framework.
201   */
202  sc = bootcard_bsp_libc_helper(
203    work_area_start,
204    work_area_size,
205    heap_start,
206    heap_size
207  );
208  if ( sc != RTEMS_SUCCESSFUL ) {
209    printk( "bootcard: Cannot initialize C library!\n");
210    bsp_cleanup();
211    return -1;
212  }
213
214  /*
215   *  All BSP to do any required initialization now that RTEMS
216   *  data structures are initialized.  In older BSPs or those
217   *  which do not use the shared framework, this is the typical
218   *  time when the C Library is initialized so malloc()
219   *  can be called by device drivers.  For BSPs using the shared
220   *  framework, this routine can be empty.
221   */
222  bsp_pretasking_hook();
223
224  /*
225   *  If debug is enabled, then enable all dynamic RTEMS debug
226   *  capabilities.
227   *
228   *  NOTE: Most debug features are conditionally compiled in
229   *        or enabled via configure time plugins.
230   */
231  #ifdef RTEMS_DEBUG
232    rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
233  #endif
234
235  /*
236   *  Let RTEMS perform initialization it requires before drivers
237   *  are allowed to be initialized.
238   */
239  rtems_initialize_before_drivers();
240
241  /*
242   *  Execute BSP specific pre-driver hook. Drivers haven't gotten
243   *  to initialize yet so this is a good chance to initialize
244   *  buses, spurious interrupt handlers, etc..
245   *
246   *  NOTE: Many BSPs do not require this handler and use the
247   *        shared stub.
248   */
249  bsp_predriver_hook();
250
251  /*
252   *  Initialize all device drivers.
253   */
254  rtems_initialize_device_drivers();
255
256  /*
257   *  Invoke the postdriver hook.  This normally opens /dev/console
258   *  for use as stdin, stdout, and stderr.
259   */
260  bsp_postdriver_hook();
261
262  /*
263   *  Complete initialization of RTEMS and switch to the first task.
264   *  Global C++ constructors will be executed in the context of that task.
265   */
266  rtems_initialize_start_multitasking();
267
268  /***************************************************************
269   ***************************************************************
270   *  APPLICATION RUNS HERE!!!  When it shuts down, we return!!! *
271   ***************************************************************
272   ***************************************************************
273   */
274
275  /*
276   *  Perform any BSP specific shutdown actions which are written in C.
277   */
278  bsp_cleanup();
279
280  /*
281   *  Now return to the start code.
282   */
283  return 0;
284}
Note: See TracBrowser for help on using the repository browser.