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

4.115
Last change on this file since dd8df59 was dd8df59, checked in by Sebastian Huber <sebastian.huber@…>, on 11/14/12 at 12:59:27

bsps: Interrupt initialization error is fatal

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