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

4.115
Last change on this file since 1bb8782 was facf8362, checked in by Sebastian Huber <sebastian.huber@…>, on 12/06/12 at 16:42:41

bsps: Add BSP_GENERIC_FATAL_SPURIOUS_INTERRUPT

Use rtems_fatal() instead of bsp_cleanup().

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