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

4.115
Last change on this file since ade27c6 was ade27c6, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 20, 2013 at 9:44:04 AM

bsps: Move bsp_generic_fatal_code to new file

Add bsp_generic_fatal().

  • 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 <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_reset(void);
67
68/**
69 * @brief Standard system initialization procedure.
70 *
71 * You may pass a command line in @a cmdline.  It is later available via the
72 * global @ref bsp_boot_cmdline variable.
73 *
74 * This is the C entry point for ALL RTEMS BSPs.  It is invoked from the
75 * assembly language initialization file usually called @c start.S which does
76 * the basic CPU setup (stack, C runtime environment, zero BSS, load other
77 * sections) and calls afterwards boot_card().  The boot card function provides
78 * the framework for the BSP initialization sequence.  The basic flow of
79 * initialization is:
80 *
81 * - disable interrupts, interrupts will be enabled during the first context
82 *   switch
83 * - bsp_start() - more advanced initialization
84 * - bsp_work_area_initialize() - initialize the RTEMS Workspace and the C
85 *   Program Heap
86 * - rtems_initialize_data_structures()
87 * - initialize C Library
88 * - bsp_pretasking_hook()
89 * - if defined( RTEMS_DEBUG )
90 *   - rtems_debug_enable( RTEMS_DEBUG_ALL_MASK )
91 * - rtems_initialize_before_drivers()
92 * - bsp_predriver_hook()
93 * - rtems_initialize_device_drivers()
94 *   - initialization of all device drivers
95 * - bsp_postdriver_hook()
96 * - rtems_initialize_start_multitasking()
97 *   - 1st task executes C++ global constructors
98 *   - .... application runs ...
99 *   - exit
100 * - will not return to here
101 *
102 * This style of initialization ensures that the C++ global constructors are
103 * executed after RTEMS is initialized.
104 */
105void boot_card(const char *cmdline) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
106
107#ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
108  /**
109   * @brief Gives the BSP a chance to reduce the work area size with sbrk()
110   * adding more later.
111   *
112   * bsp_sbrk_init() may reduce the work area size passed in. The routine
113   * returns the 'sbrk_amount' to be used when extending the heap.  Note that
114   * the return value may be zero.
115   *
116   * In case the @a area size is altered, then the remaining size of the
117   * @a area must be greater than or equal to @a min_size.
118   */
119  ptrdiff_t bsp_sbrk_init(Heap_Area *area, uintptr_t min_size);
120#endif
121
122static inline void bsp_work_area_initialize_default(
123  void *area_begin,
124  uintptr_t area_size
125)
126{
127  Heap_Area area = {
128    .begin = area_begin,
129    .size = area_size
130  };
131
132  #if BSP_DIRTY_MEMORY == 1
133    memset(area.begin, 0xCF,  area.size);
134  #endif
135
136  #ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
137    {
138      uintptr_t overhead = _Heap_Area_overhead(CPU_HEAP_ALIGNMENT);
139      uintptr_t work_space_size = rtems_configuration_get_work_space_size();
140      ptrdiff_t sbrk_amount = bsp_sbrk_init(
141        &area,
142        work_space_size
143          + overhead
144          + (rtems_configuration_get_unified_work_area() ? 0 : overhead)
145      );
146
147      rtems_heap_set_sbrk_amount(sbrk_amount);
148    }
149  #endif
150
151  /*
152   *  The following may be helpful in debugging what goes wrong when
153   *  you are allocating the Work Area in a new BSP.
154   */
155  #ifdef BSP_GET_WORK_AREA_DEBUG
156    {
157      void *sp = __builtin_frame_address(0);
158      void *end = (char *) area.begin + area.size;
159      printk(
160        "work_area_start = 0x%p\n"
161        "work_area_size = %lu 0x%08lx\n"
162        "end = 0x%p\n"
163        "current stack pointer = 0x%p%s\n",
164        area.begin,
165        (unsigned long) area.size,  /* decimal */
166        (unsigned long) area.size,  /* hexadecimal */
167        end,
168        sp,
169        (uintptr_t) sp >= (uintptr_t) area.begin
170          && (uintptr_t) sp <= (uintptr_t) end ?
171            " OVERLAPS!" : ""
172      );
173    }
174  #endif
175
176  _Workspace_Handler_initialization(&area, 1, NULL);
177
178  #ifdef BSP_GET_WORK_AREA_DEBUG
179    printk(
180      "heap_start = 0x%p\n"
181      "heap_size = %lu\n",
182      area.begin,
183      (unsigned long) area.size
184    );
185  #endif
186
187  RTEMS_Malloc_Initialize(&area, 1, NULL);
188}
189
190static inline void bsp_work_area_initialize_with_table(
191  Heap_Area *areas,
192  size_t area_count
193)
194{
195  _Workspace_Handler_initialization(areas, area_count, _Heap_Extend);
196  RTEMS_Malloc_Initialize(areas, area_count, _Heap_Extend);
197}
198
199void bsp_work_area_initialize(void);
200
201void bsp_libc_init(void);
202
203/** @} */
204
205#ifdef __cplusplus
206}
207#endif /* __cplusplus */
208
209#endif /* LIBBSP_SHARED_BOOTCARD_H */
Note: See TracBrowser for help on using the repository browser.