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

4.11
Last change on this file since d56f76a was d56f76a, checked in by Sebastian Huber <sebastian.huber@…>, on Aug 26, 2013 at 11:00:53 AM

bsps: Fix header includes

  • Property mode set to 100644
File size: 5.2 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup bsp_bootcard
5 *
6 * @brief Standard system startup.
7 */
8
9/*
10 * Copyright (c) 2008-2013 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.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 <string.h>
33
34#include <rtems/config.h>
35#include <rtems/bspIo.h>
36#include <rtems/malloc.h>
37#include <rtems/score/wkspace.h>
38
39#include <bspopts.h>
40
41#ifdef __cplusplus
42extern "C" {
43#endif /* __cplusplus */
44
45/**
46 * @defgroup bsp_bootcard Bootcard
47 *
48 * @ingroup bsp_kit
49 *
50 * @brief Standard system startup.
51 *
52 * @{
53 */
54
55/**
56 * @brief Global pointer to the command line of boot_card().
57 */
58extern const char *bsp_boot_cmdline;
59
60void bsp_start(void);
61
62void bsp_pretasking_hook(void);
63
64void bsp_predriver_hook(void);
65
66void bsp_postdriver_hook(void);
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 * - will not return to here
103 *
104 * This style of initialization ensures that the C++ global constructors are
105 * executed after RTEMS is initialized.
106 */
107void boot_card(const char *cmdline) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
108
109#ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
110  /**
111   * @brief Gives the BSP a chance to reduce the work area size with sbrk()
112   * adding more later.
113   *
114   * bsp_sbrk_init() may reduce the work area size passed in. The routine
115   * returns the 'sbrk_amount' to be used when extending the heap.  Note that
116   * the return value may be zero.
117   *
118   * In case the @a area size is altered, then the remaining size of the
119   * @a area must be greater than or equal to @a min_size.
120   */
121  ptrdiff_t bsp_sbrk_init(Heap_Area *area, uintptr_t min_size);
122#endif
123
124static inline void bsp_work_area_initialize_default(
125  void *area_begin,
126  uintptr_t area_size
127)
128{
129  Heap_Area area = {
130    .begin = area_begin,
131    .size = area_size
132  };
133
134  #if BSP_DIRTY_MEMORY == 1
135    memset(area.begin, 0xCF,  area.size);
136  #endif
137
138  #ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
139    {
140      uintptr_t overhead = _Heap_Area_overhead(CPU_HEAP_ALIGNMENT);
141      uintptr_t work_space_size = rtems_configuration_get_work_space_size();
142      ptrdiff_t sbrk_amount = bsp_sbrk_init(
143        &area,
144        work_space_size
145          + overhead
146          + (rtems_configuration_get_unified_work_area() ? 0 : overhead)
147      );
148
149      rtems_heap_set_sbrk_amount(sbrk_amount);
150    }
151  #endif
152
153  /*
154   *  The following may be helpful in debugging what goes wrong when
155   *  you are allocating the Work Area in a new BSP.
156   */
157  #ifdef BSP_GET_WORK_AREA_DEBUG
158    {
159      void *sp = __builtin_frame_address(0);
160      void *end = (char *) area.begin + area.size;
161      printk(
162        "work_area_start = 0x%p\n"
163        "work_area_size = %lu 0x%08lx\n"
164        "end = 0x%p\n"
165        "current stack pointer = 0x%p%s\n",
166        area.begin,
167        (unsigned long) area.size,  /* decimal */
168        (unsigned long) area.size,  /* hexadecimal */
169        end,
170        sp,
171        (uintptr_t) sp >= (uintptr_t) area.begin
172          && (uintptr_t) sp <= (uintptr_t) end ?
173            " OVERLAPS!" : ""
174      );
175    }
176  #endif
177
178  _Workspace_Handler_initialization(&area, 1, NULL);
179
180  #ifdef BSP_GET_WORK_AREA_DEBUG
181    printk(
182      "heap_start = 0x%p\n"
183      "heap_size = %lu\n",
184      area.begin,
185      (unsigned long) area.size
186    );
187  #endif
188
189  RTEMS_Malloc_Initialize(&area, 1, NULL);
190}
191
192static inline void bsp_work_area_initialize_with_table(
193  Heap_Area *areas,
194  size_t area_count
195)
196{
197  _Workspace_Handler_initialization(areas, area_count, _Heap_Extend);
198  RTEMS_Malloc_Initialize(areas, area_count, _Heap_Extend);
199}
200
201void bsp_work_area_initialize(void);
202
203void bsp_libc_init(void);
204
205/** @} */
206
207#ifdef __cplusplus
208}
209#endif /* __cplusplus */
210
211#endif /* LIBBSP_SHARED_BOOTCARD_H */
Note: See TracBrowser for help on using the repository browser.