source: rtems/c/src/lib/libbsp/shared/include/bootcard.h @ 37030e3

5
Last change on this file since 37030e3 was 37030e3, checked in by Sebastian Huber <sebastian.huber@…>, on 12/09/15 at 07:05:57

bsps: Call bsp_work_area_initialize() early

Call bsp_work_area_initialize() before bsp_start(). This allows
bsp_start() to use malloc() etc. which is beneficial for systems with a
plug-and-play hardware enumeration.

Update #2408.

  • Property mode set to 100644
File size: 5.4 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup bsp_bootcard
5 *
6 * @brief Standard system startup.
7 */
8
9/*
10 * Copyright (c) 2008-2014 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Dornierstr. 4
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
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.rtems.org/license/LICENSE.
21 */
22
23#ifndef LIBBSP_SHARED_BOOTCARD_H
24#define LIBBSP_SHARED_BOOTCARD_H
25
26#include <string.h>
27
28#include <rtems/config.h>
29#include <rtems/bspIo.h>
30#include <rtems/malloc.h>
31#include <rtems/score/wkspace.h>
32
33#include <bspopts.h>
34
35#ifdef __cplusplus
36extern "C" {
37#endif /* __cplusplus */
38
39/**
40 * @defgroup shared_bootcard Bootcard
41 *
42 * @ingroup bsp_shared
43 *
44 * @brief Standard system startup.
45 *
46 * @{
47 */
48
49/**
50 * @brief Global pointer to the command line of boot_card().
51 */
52extern const char *bsp_boot_cmdline;
53
54void bsp_start(void);
55
56void bsp_pretasking_hook(void);
57
58void bsp_predriver_hook(void);
59
60void bsp_driver_level_hook( int level );
61
62void bsp_postdriver_hook(void);
63
64void bsp_reset(void);
65
66/**
67 * @brief Standard system initialization procedure.
68 *
69 * You may pass a command line in @a cmdline.  It is later available via the
70 * global @ref bsp_boot_cmdline variable.
71 *
72 * This is the C entry point for ALL RTEMS BSPs.  It is invoked from the
73 * assembly language initialization file usually called @c start.S which does
74 * the basic CPU setup (stack, C runtime environment, zero BSS, load other
75 * sections) and calls afterwards boot_card().  The boot card function provides
76 * the framework for the BSP initialization sequence.  The basic flow of
77 * initialization is:
78 *
79 * - disable interrupts, interrupts will be enabled during the first context
80 *   switch
81 * - bsp_work_area_initialize() - initialize the RTEMS Workspace and the C
82 *   Program Heap
83 * - bsp_start() - more advanced initialization
84 * - rtems_initialize_data_structures()
85 * - initialize C Library
86 * - bsp_pretasking_hook()
87 * - rtems_initialize_before_drivers()
88 * - bsp_predriver_hook()
89 * - rtems_initialize_device_drivers()
90 *   - initialization of all device drivers
91 * - bsp_postdriver_hook()
92 * - rtems_initialize_start_multitasking()
93 *   - 1st task executes C++ global constructors
94 *   - .... application runs ...
95 *   - exit
96 * - will not return to here
97 *
98 * This style of initialization ensures that the C++ global constructors are
99 * executed after RTEMS is initialized.
100 */
101void boot_card(const char *cmdline) RTEMS_NO_RETURN;
102
103#ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
104  /**
105   * @brief Gives the BSP a chance to reduce the work area size with sbrk()
106   * adding more later.
107   *
108   * bsp_sbrk_init() may reduce the work area size passed in. The routine
109   * returns the 'sbrk_amount' to be used when extending the heap.  Note that
110   * the return value may be zero.
111   *
112   * In case the @a area size is altered, then the remaining size of the
113   * @a area must be greater than or equal to @a min_size.
114   */
115  ptrdiff_t bsp_sbrk_init(Heap_Area *area, uintptr_t min_size);
116#endif
117
118static inline void bsp_work_area_initialize_default(
119  void *area_begin,
120  uintptr_t area_size
121)
122{
123  Heap_Area area = {
124    .begin = area_begin,
125    .size = area_size
126  };
127
128  #if BSP_DIRTY_MEMORY == 1
129    memset(area.begin, 0xCF,  area.size);
130  #endif
131
132  #ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
133    {
134      uintptr_t overhead = _Heap_Area_overhead(CPU_HEAP_ALIGNMENT);
135      uintptr_t work_space_size = rtems_configuration_get_work_space_size();
136      ptrdiff_t sbrk_amount = bsp_sbrk_init(
137        &area,
138        work_space_size
139          + overhead
140          + (rtems_configuration_get_unified_work_area() ? 0 : overhead)
141      );
142
143      rtems_heap_set_sbrk_amount(sbrk_amount);
144    }
145  #endif
146
147  /*
148   *  The following may be helpful in debugging what goes wrong when
149   *  you are allocating the Work Area in a new BSP.
150   */
151  #ifdef BSP_GET_WORK_AREA_DEBUG
152    {
153      void *sp = __builtin_frame_address(0);
154      void *end = (char *) area.begin + area.size;
155      printk(
156        "work_area_start = 0x%p\n"
157        "work_area_size = %lu 0x%08lx\n"
158        "end = 0x%p\n"
159        "current stack pointer = 0x%p%s\n",
160        area.begin,
161        (unsigned long) area.size,  /* decimal */
162        (unsigned long) area.size,  /* hexadecimal */
163        end,
164        sp,
165        (uintptr_t) sp >= (uintptr_t) area.begin
166          && (uintptr_t) sp <= (uintptr_t) end ?
167            " OVERLAPS!" : ""
168      );
169    }
170  #endif
171
172  _Workspace_Handler_initialization(&area, 1, NULL);
173
174  #ifdef BSP_GET_WORK_AREA_DEBUG
175    printk(
176      "heap_start = 0x%p\n"
177      "heap_size = %lu\n",
178      area.begin,
179      (unsigned long) area.size
180    );
181  #endif
182
183  RTEMS_Malloc_Initialize(&area, 1, NULL);
184}
185
186static inline void bsp_work_area_initialize_with_table(
187  Heap_Area *areas,
188  size_t area_count
189)
190{
191  _Workspace_Handler_initialization(areas, area_count, _Heap_Extend);
192  RTEMS_Malloc_Initialize(areas, area_count, _Heap_Extend);
193}
194
195void bsp_work_area_initialize(void);
196
197void bsp_libc_init(void);
198
199/**
200 * @brief Standard start routine for secondary processors.
201 *
202 * This function is usually called by low-level startup code of secondary
203 * processors or boot loaders starting a secondary processor.  The final step
204 * of this function is a call to
205 * _SMP_Start_multitasking_on_secondary_processor().
206 */
207void bsp_start_on_secondary_processor(void);
208
209/** @} */
210
211#ifdef __cplusplus
212}
213#endif /* __cplusplus */
214
215#endif /* LIBBSP_SHARED_BOOTCARD_H */
Note: See TracBrowser for help on using the repository browser.