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

4.104.114.95
Last change on this file since ec3007c was ec3007c, checked in by Joel Sherrill <joel.sherrill@…>, on 05/15/08 at 15:55:46

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

  • bootcard.c: Add capability for bootcard.c BSP Initialization Framework to ask the BSP where it has memory for the RTEMS Workspace and C Program Heap. These collectively are referred to as work area. If the BSP supports this, then it does not have to include code to split the available memory between the two areas. This reduces the amount of code in the BSP specific bspstart.c file. Additionally, the shared framework can initialize the C Library, call rtems_debug_enable(), and dirty the work area memory. Until most/all BSPs support this new capability, if the BSP supports this, it should call RTEMS_BSP_BOOTCARD_HANDLES_RAM_ALLOCATION from its configure.ac. When the transition is complete, this autoconf macro can be removed.
  • bsppretaskinghook.c: New file.
  • Property mode set to 100644
File size: 7.7 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 <bsp.h>
47
48/*
49 *  Since there is a forward reference
50 */
51char *rtems_progname;
52
53
54/*
55 *  Prototypes of external routines
56 */
57extern void bsp_start( void );
58extern void bsp_cleanup( void );
59extern void bsp_pretasking_hook(void);
60extern void bsp_libc_init( void *, uint32_t, int );
61extern void bsp_predriver_hook(void);
62extern void bsp_postdriver_hook(void);
63
64/*
65 *  These are the prototypes and helper routines which are used
66 *  when the BSP lets the framework handle RAM allocation between
67 *  the RTEMS Workspace and C Program Heap.
68 */
69#if defined(BSP_BOOTCARD_HANDLES_RAM_ALLOCATION)
70  extern void bsp_get_workarea( void **, size_t *, size_t *);
71
72  void bootcard_bsp_libc_helper(
73    void   *workarea_base,
74    size_t  workarea_size,
75    size_t  requested_heap_size
76  )
77  {
78    uint32_t     heap_start;
79    uint32_t     heap_size;
80
81    heap_start = (uint32_t) workarea_base;
82    if (heap_start & (CPU_ALIGNMENT-1))
83      heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
84
85    if ( requested_heap_size == 0 ) {
86      heap_size = Configuration.work_space_start - workarea_base;
87      heap_size &= 0xfffffff0;  /* keep it as a multiple of 16 bytes */
88    } else {
89      heap_size = requested_heap_size;
90    }
91
92    bsp_libc_init((void *) heap_start, heap_size, 0);
93  }
94#endif
95
96/*
97 *  This is the initialization framework routine that weaves together
98 *  calls to RTEMS and the BSP in the proper sequence to initialize
99 *  the system while maximizing shared code and keeping BSP code in C
100 *  as much as possible.
101 */
102int boot_card(
103  int    argc,
104  char **argv,
105  char **envp
106)
107{
108  static char  *argv_pointer = NULL;
109  static char  *envp_pointer = NULL;
110  char **argv_p = &argv_pointer;
111  char **envp_p = &envp_pointer;
112  rtems_interrupt_level bsp_isr_level;
113  #if defined(BSP_BOOTCARD_HANDLES_RAM_ALLOCATION)
114    void   *workarea_base;
115    size_t  workarea_size;
116    size_t  heap_size;
117  #endif
118
119  /*
120   *  Make sure interrupts are disabled.
121   */
122  rtems_interrupt_disable( bsp_isr_level );
123
124  /*
125   *  Set things up so we have real pointers for argv and envp.
126   *  If the BSP has passed us something useful, then pass it on.
127   *  Somehow we need to eventually make this available to
128   *  a real main() in user land. :)
129   */
130  if ( argv ) argv_p = argv;
131  if ( envp ) envp_p = envp;
132
133  /*
134   *  Set the program name in case some application cares.
135   */
136  if ((argc > 0) && argv && argv[0])
137    rtems_progname = argv[0];
138  else
139    rtems_progname = "RTEMS";
140
141  /*
142   *  Find out where the block of memory the BSP will use for
143   *  the RTEMS Workspace and the C Program Heap is.
144   */
145  #if defined(BSP_BOOTCARD_HANDLES_RAM_ALLOCATION)
146  {
147    unsigned char     *work_space_start;
148
149    bsp_get_workarea( &workarea_base, &workarea_size, &heap_size );
150
151    work_space_start = workarea_base + workarea_size
152      - rtems_configuration_get_work_space_size();
153
154    if ( work_space_start <= (unsigned char *)workarea_base ) {
155      printk( "bootcard: Not enough RAM!!!\n" );
156      bsp_cleanup();
157      return -1;
158    }
159
160    Configuration.work_space_start = work_space_start;
161
162    #if (BSP_DIRTY_MEMORY == 1)
163      memset(workarea_base, 0xCF,  workarea_size);
164    #endif
165  }
166
167  #endif
168
169  /*
170   * Invoke Board Support Package initialization routine written in C.
171   */
172  bsp_start();
173
174  /*
175   *  Initialize RTEMS data structures
176   */
177  rtems_initialize_data_structures( &Configuration );
178
179  /*
180   *  Initialize the C library for those BSPs using the shared
181   *  framework.
182   */
183  #if defined(BSP_BOOTCARD_HANDLES_RAM_ALLOCATION)
184    bootcard_bsp_libc_helper( workarea_base, workarea_size, heap_size );
185  #endif
186
187  /*
188   *  All BSP to do any required initialization now that RTEMS
189   *  data structures are initialized.  In older BSPs or those
190   *  which do not use the shared framework, this is the typical
191   *  time when the C Library is initialized so malloc()
192   *  can be called by device drivers.  For BSPs using the shared
193   *  framework, this routine can be empty.
194   */
195  bsp_pretasking_hook();
196
197  /*
198   *  If debug is enabled, then enable all dynamic RTEMS debug
199   *  capabilities.
200   *
201   *  NOTE: Most debug features are conditionally compiled in
202   *        or enabled via configure time plugins.
203   */
204  #ifdef RTEMS_DEBUG
205    rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
206  #endif
207
208  /*
209   *  Let RTEMS perform initialization it requires before drivers
210   *  are allowed to be initialized.
211   */
212  rtems_initialize_before_drivers();
213
214  /*
215   *  Execute BSP specific pre-driver hook. Drivers haven't gotten
216   *  to initialize yet so this is a good chance to initialize
217   *  buses, spurious interrupt handlers, etc..
218   *
219   *  NOTE: Many BSPs do not require this handler and use the
220   *        shared stub.
221   */
222  bsp_predriver_hook();
223
224  /*
225   *  Let RTEMS perform initialization it requires before drivers
226   *  are allowed to be initialized.
227   */
228  rtems_initialize_before_drivers();
229
230  /*
231   *  Execute BSP specific pre-driver hook. Drivers haven't gotten
232   *  to initialize yet so this is a good chance to initialize
233   *  buses, spurious interrupt handlers, etc..
234   *
235   *  NOTE: Many BSPs do not require this handler and use the
236   *        shared stub.
237   */
238  bsp_predriver_hook();
239
240  /*
241   *  Initialize all device drivers.
242   */
243  rtems_initialize_device_drivers();
244
245  /*
246   *  Invoke the postdriver hook.  This normally opens /dev/console
247   *  for use as stdin, stdout, and stderr.
248   */
249  bsp_postdriver_hook();
250
251  /*
252   *  Complete initialization of RTEMS and switch to the first task.
253   *  Global C++ constructors will be executed in the context of that task.
254   */
255  rtems_initialize_start_multitasking();
256
257  /***************************************************************
258   ***************************************************************
259   *  APPLICATION RUNS HERE!!!  When it shuts down, we return!!! *
260   ***************************************************************
261   ***************************************************************
262   */
263
264  /*
265   *  Perform any BSP specific shutdown actions which are written in C.
266   */
267  bsp_cleanup();
268
269  /*
270   *  Now return to the start code.
271   */
272
273  return 0;
274}
Note: See TracBrowser for help on using the repository browser.