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

4.115
Last change on this file since 7bb33391 was 296c74e6, checked in by Daniel Ramirez <javamonn@…>, on 12/09/13 at 19:37:48

doxygen: refactored doxygen in libbsp to illustrate new rule set

  • Property mode set to 100644
File size: 5.1 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#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_postdriver_hook(void);
61
62void bsp_reset(void);
63
64/**
65 * @brief Standard system initialization procedure.
66 *
67 * You may pass a command line in @a cmdline.  It is later available via the
68 * global @ref bsp_boot_cmdline variable.
69 *
70 * This is the C entry point for ALL RTEMS BSPs.  It is invoked from the
71 * assembly language initialization file usually called @c start.S which does
72 * the basic CPU setup (stack, C runtime environment, zero BSS, load other
73 * sections) and calls afterwards boot_card().  The boot card function provides
74 * the framework for the BSP initialization sequence.  The basic flow of
75 * initialization is:
76 *
77 * - disable interrupts, interrupts will be enabled during the first context
78 *   switch
79 * - bsp_start() - more advanced initialization
80 * - bsp_work_area_initialize() - initialize the RTEMS Workspace and the C
81 *   Program Heap
82 * - rtems_initialize_data_structures()
83 * - initialize C Library
84 * - bsp_pretasking_hook()
85 * - if defined( RTEMS_DEBUG )
86 *   - rtems_debug_enable( RTEMS_DEBUG_ALL_MASK )
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_COMPILER_NO_RETURN_ATTRIBUTE;
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
201#ifdef __cplusplus
202}
203#endif /* __cplusplus */
204
205#endif /* LIBBSP_SHARED_BOOTCARD_H */
Note: See TracBrowser for help on using the repository browser.