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

5
Last change on this file since 143696a was 143696a, checked in by Sebastian Huber <sebastian.huber@…>, on 10/16/15 at 06:15:03

basedefs.h: Add and use RTEMS_NO_RETURN

  • Property mode set to 100644
File size: 5.5 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_start() - more advanced initialization
82 * - bsp_work_area_initialize() - initialize the RTEMS Workspace and the C
83 *   Program Heap
84 * - rtems_initialize_data_structures()
85 * - initialize C Library
86 * - bsp_pretasking_hook()
87 * - if defined( RTEMS_DEBUG )
88 *   - rtems_debug_enable( RTEMS_DEBUG_ALL_MASK )
89 * - rtems_initialize_before_drivers()
90 * - bsp_predriver_hook()
91 * - rtems_initialize_device_drivers()
92 *   - initialization of all device drivers
93 * - bsp_postdriver_hook()
94 * - rtems_initialize_start_multitasking()
95 *   - 1st task executes C++ global constructors
96 *   - .... application runs ...
97 *   - exit
98 * - will not return to here
99 *
100 * This style of initialization ensures that the C++ global constructors are
101 * executed after RTEMS is initialized.
102 */
103void boot_card(const char *cmdline) RTEMS_NO_RETURN;
104
105#ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
106  /**
107   * @brief Gives the BSP a chance to reduce the work area size with sbrk()
108   * adding more later.
109   *
110   * bsp_sbrk_init() may reduce the work area size passed in. The routine
111   * returns the 'sbrk_amount' to be used when extending the heap.  Note that
112   * the return value may be zero.
113   *
114   * In case the @a area size is altered, then the remaining size of the
115   * @a area must be greater than or equal to @a min_size.
116   */
117  ptrdiff_t bsp_sbrk_init(Heap_Area *area, uintptr_t min_size);
118#endif
119
120static inline void bsp_work_area_initialize_default(
121  void *area_begin,
122  uintptr_t area_size
123)
124{
125  Heap_Area area = {
126    .begin = area_begin,
127    .size = area_size
128  };
129
130  #if BSP_DIRTY_MEMORY == 1
131    memset(area.begin, 0xCF,  area.size);
132  #endif
133
134  #ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
135    {
136      uintptr_t overhead = _Heap_Area_overhead(CPU_HEAP_ALIGNMENT);
137      uintptr_t work_space_size = rtems_configuration_get_work_space_size();
138      ptrdiff_t sbrk_amount = bsp_sbrk_init(
139        &area,
140        work_space_size
141          + overhead
142          + (rtems_configuration_get_unified_work_area() ? 0 : overhead)
143      );
144
145      rtems_heap_set_sbrk_amount(sbrk_amount);
146    }
147  #endif
148
149  /*
150   *  The following may be helpful in debugging what goes wrong when
151   *  you are allocating the Work Area in a new BSP.
152   */
153  #ifdef BSP_GET_WORK_AREA_DEBUG
154    {
155      void *sp = __builtin_frame_address(0);
156      void *end = (char *) area.begin + area.size;
157      printk(
158        "work_area_start = 0x%p\n"
159        "work_area_size = %lu 0x%08lx\n"
160        "end = 0x%p\n"
161        "current stack pointer = 0x%p%s\n",
162        area.begin,
163        (unsigned long) area.size,  /* decimal */
164        (unsigned long) area.size,  /* hexadecimal */
165        end,
166        sp,
167        (uintptr_t) sp >= (uintptr_t) area.begin
168          && (uintptr_t) sp <= (uintptr_t) end ?
169            " OVERLAPS!" : ""
170      );
171    }
172  #endif
173
174  _Workspace_Handler_initialization(&area, 1, NULL);
175
176  #ifdef BSP_GET_WORK_AREA_DEBUG
177    printk(
178      "heap_start = 0x%p\n"
179      "heap_size = %lu\n",
180      area.begin,
181      (unsigned long) area.size
182    );
183  #endif
184
185  RTEMS_Malloc_Initialize(&area, 1, NULL);
186}
187
188static inline void bsp_work_area_initialize_with_table(
189  Heap_Area *areas,
190  size_t area_count
191)
192{
193  _Workspace_Handler_initialization(areas, area_count, _Heap_Extend);
194  RTEMS_Malloc_Initialize(areas, area_count, _Heap_Extend);
195}
196
197void bsp_work_area_initialize(void);
198
199void bsp_libc_init(void);
200
201/**
202 * @brief Standard start routine for secondary processors.
203 *
204 * This function is usually called by low-level startup code of secondary
205 * processors or boot loaders starting a secondary processor.  The final step
206 * of this function is a call to
207 * _SMP_Start_multitasking_on_secondary_processor().
208 */
209void bsp_start_on_secondary_processor(void);
210
211/** @} */
212
213#ifdef __cplusplus
214}
215#endif /* __cplusplus */
216
217#endif /* LIBBSP_SHARED_BOOTCARD_H */
Note: See TracBrowser for help on using the repository browser.