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

4.115
Last change on this file since c118a6e5 was c118a6e5, checked in by Sebastian Huber <sebastian.huber@…>, on 08/24/12 at 13:25:45

bsps: Add bsp_work_area_initialize_with_table()

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