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

4.115
Last change on this file since bb2b825 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 8.8 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup bsp_bootcard
5 *
6 * @brief Standard system startup.
7 */
8
9/*
10 *  This is the C entry point for ALL RTEMS BSPs.  It is invoked
11 *  from the assembly language initialization file usually called
12 *  start.S.  It provides the framework for the BSP initialization
13 *  sequence.  The basic flow of initialization is:
14 *
15 *  + start.S: basic CPU setup (stack, zero BSS)
16 *    + boot_card
17 *      + bspstart.c: bsp_start - more advanced initialization
18 *      + obtain information on BSP memory and allocate RTEMS Workspace
19 *      + rtems_initialize_data_structures
20 *      + allocate memory to C Program Heap
21 *      + initialize C Library and C Program Heap
22 *      + bsp_pretasking_hook
23 *      + if defined( RTEMS_DEBUG )
24 *        - rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
25 *      + rtems_initialize_before_drivers
26 *      + bsp_predriver_hook
27 *      + rtems_initialize_device_drivers
28 *        - all device drivers
29 *      + bsp_postdriver_hook
30 *      + rtems_initialize_start_multitasking
31 *        - 1st task executes C++ global constructors
32 *          .... appplication runs ...
33 *          - exit
34 *     + back to here eventually
35 *     + bspclean.c: bsp_cleanup
36 *
37 *  This style of initialization ensures that the C++ global
38 *  constructors are executed after RTEMS is initialized.
39 *  Thanks to Chris Johns <cjohns@plessey.com.au> for the idea
40 *  to move C++ global constructors into the first task.
41 *
42 *  COPYRIGHT (c) 1989-2011.
43 *  On-Line Applications Research Corporation (OAR).
44 *
45 *  The license and distribution terms for this file may be
46 *  found in the file LICENSE in this distribution or at
47 *  http://www.rtems.com/license/LICENSE.
48 */
49
50#include <rtems.h>
51
52#include <bsp/bootcard.h>
53#include <rtems/bspIo.h>
54#include <rtems/malloc.h>
55
56#ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
57#include <unistd.h> /* for sbrk() */
58#endif
59
60/*
61 *  At most a single pointer to the cmdline for those target
62 *  short on memory and not supporting a command line.
63 */
64const char *bsp_boot_cmdline;
65
66/*
67 *  These are the prototypes and helper routines which are used
68 *  when the BSP lets the framework handle RAM allocation between
69 *  the RTEMS Workspace and C Program Heap.
70 */
71static void bootcard_bsp_libc_helper(
72  void      *work_area_start,
73  uintptr_t  work_area_size,
74  void      *heap_start,
75  uintptr_t  heap_size,
76  uintptr_t  sbrk_amount
77)
78{
79  if ( heap_start == BSP_BOOTCARD_HEAP_USES_WORK_AREA ) {
80    if ( !rtems_configuration_get_unified_work_area() ) {
81      uintptr_t work_space_size = rtems_configuration_get_work_space_size();
82
83      heap_start = (char *) work_area_start + work_space_size;
84
85      if (heap_size == BSP_BOOTCARD_HEAP_SIZE_DEFAULT) {
86        uintptr_t heap_size_default = work_area_size - work_space_size;
87
88        heap_size = heap_size_default;
89      }
90    } else {
91      heap_start = work_area_start;
92      if (heap_size == BSP_BOOTCARD_HEAP_SIZE_DEFAULT) {
93        heap_size = work_area_size;
94      }
95    }
96  }
97
98  bsp_libc_init(heap_start, heap_size, sbrk_amount);
99}
100
101/*
102 *  This is the initialization framework routine that weaves together
103 *  calls to RTEMS and the BSP in the proper sequence to initialize
104 *  the system while maximizing shared code and keeping BSP code in C
105 *  as much as possible.
106 */
107uint32_t boot_card(
108  const char *cmdline
109)
110{
111  rtems_interrupt_level  bsp_isr_level;
112  void                  *work_area_start = NULL;
113  uintptr_t              work_area_size = 0;
114  void                  *heap_start = NULL;
115  uintptr_t              heap_size = 0;
116  uintptr_t              sbrk_amount = 0;
117  uintptr_t              work_space_size = 0;
118  uint32_t               status = 0;
119
120  /*
121   * Special case for PowerPC: The interrupt disable mask is stored in SPRG0.
122   * It must be valid before we can use rtems_interrupt_disable().
123   */
124  #ifdef PPC_INTERRUPT_DISABLE_MASK_DEFAULT
125    ppc_interrupt_set_disable_mask( PPC_INTERRUPT_DISABLE_MASK_DEFAULT );
126  #endif /* PPC_INTERRUPT_DISABLE_MASK_DEFAULT */
127
128  /*
129   *  Make sure interrupts are disabled.
130   */
131  rtems_interrupt_disable( bsp_isr_level );
132
133  bsp_boot_cmdline = cmdline;
134
135  /*
136   * Invoke Board Support Package initialization routine written in C.
137   */
138  bsp_start();
139
140  /*
141   *  Find out where the block of memory the BSP will use for
142   *  the RTEMS Workspace and the C Program Heap is.
143   */
144  bsp_get_work_area(&work_area_start, &work_area_size,
145                    &heap_start, &heap_size);
146
147#ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
148  /* This routine may reduce the work area size with the
149   * option to extend it later via sbrk(). If the application
150   * was configured w/o CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK then
151   * omit this step.
152   */
153  if ( rtems_malloc_sbrk_helpers ) {
154    sbrk_amount = bsp_sbrk_init(work_area_start, &work_area_size);
155    work_space_size = rtems_configuration_get_work_space_size();
156    if ( work_area_size <  work_space_size && sbrk_amount > 0 ) {
157      /* Need to use sbrk right now */
158      uintptr_t sbrk_now;
159
160      sbrk_now = (work_space_size - work_area_size) / sbrk_amount;
161      sbrk( sbrk_now * sbrk_amount );
162    }
163  }
164#else
165  if ( rtems_malloc_sbrk_helpers ) {
166    printk("Configuration error!\n"
167           "Application was configured with CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK\n"
168           "but BSP was configured w/o sbrk support\n");
169    status = 1;
170    bsp_cleanup( status );
171    return status;
172  }
173#endif
174
175  /*
176   *  If the user has configured a set of objects which will require more
177   *  workspace than is actually available, print a message indicating
178   *  such and return to the invoking initialization code.
179   *
180   *  NOTE: Output from printk() may not work at this point on some BSPs.
181   *
182   *  NOTE: Use cast to (void *) and %p since these are uintptr_t types.
183   */
184  work_space_size = rtems_configuration_get_work_space_size();
185  if ( work_area_size <= work_space_size ) {
186    printk(
187      "bootcard: work space too big for work area: %p >= %p\n",
188      (void *) work_space_size,
189      (void *) work_area_size
190    );
191    status = 1;
192    bsp_cleanup( status );
193    return status;
194  }
195
196  if ( !rtems_configuration_get_unified_work_area() ) {
197    rtems_configuration_set_work_space_start( work_area_start );
198  } else {
199    rtems_configuration_set_work_space_start( work_area_start );
200    rtems_configuration_set_work_space_size( work_area_size );
201    if ( !rtems_configuration_get_stack_allocator_avoids_work_space() ) {
202      rtems_configuration_set_stack_space_size( 0 );
203    }
204  }
205
206  #if (BSP_DIRTY_MEMORY == 1)
207    memset( work_area_start, 0xCF,  work_area_size );
208  #endif
209
210  /*
211   *  Initialize RTEMS data structures
212   */
213  rtems_initialize_data_structures();
214
215  /*
216   *  Initialize the C library for those BSPs using the shared
217   *  framework.
218   */
219  bootcard_bsp_libc_helper(
220    work_area_start,
221    work_area_size,
222    heap_start,
223    heap_size,
224    sbrk_amount
225  );
226
227  /*
228   *  Let the BSP do any required initialization now that RTEMS
229   *  data structures are initialized.  In older BSPs or those
230   *  which do not use the shared framework, this is the typical
231   *  time when the C Library is initialized so malloc()
232   *  can be called by device drivers.  For BSPs using the shared
233   *  framework, this routine can be empty.
234   */
235  bsp_pretasking_hook();
236
237  /*
238   *  If debug is enabled, then enable all dynamic RTEMS debug
239   *  capabilities.
240   *
241   *  NOTE: Most debug features are conditionally compiled in
242   *        or enabled via configure time plugins.
243   */
244  #ifdef RTEMS_DEBUG
245    rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
246  #endif
247
248  /*
249   *  Let RTEMS perform initialization it requires before drivers
250   *  are allowed to be initialized.
251   */
252  rtems_initialize_before_drivers();
253
254  /*
255   *  Execute BSP specific pre-driver hook. Drivers haven't gotten
256   *  to initialize yet so this is a good chance to initialize
257   *  buses, spurious interrupt handlers, etc..
258   *
259   *  NOTE: Many BSPs do not require this handler and use the
260   *        shared stub.
261   */
262  bsp_predriver_hook();
263
264  /*
265   *  Initialize all device drivers.
266   */
267  rtems_initialize_device_drivers();
268
269  /*
270   *  Invoke the postdriver hook.  This normally opens /dev/console
271   *  for use as stdin, stdout, and stderr.
272   */
273  bsp_postdriver_hook();
274
275  /*
276   *  Complete initialization of RTEMS and switch to the first task.
277   *  Global C++ constructors will be executed in the context of that task.
278   */
279  status = rtems_initialize_start_multitasking();
280
281  /***************************************************************
282   ***************************************************************
283   *  APPLICATION RUNS HERE!!!  When it shuts down, we return!!! *
284   ***************************************************************
285   ***************************************************************
286   */
287
288  /*
289   *  Perform any BSP specific shutdown actions which are written in C.
290   */
291  bsp_cleanup( status );
292
293  /*
294   *  Now return to the start code.
295   */
296  return status;
297}
Note: See TracBrowser for help on using the repository browser.