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

4.115
Last change on this file since 48bff53b was 48bff53b, checked in by Sebastian Huber <sebastian.huber@…>, on Dec 6, 2012 at 4:47:30 PM

score: rtems_initialize_start_multitasking()

Do not return from rtems_initialize_start_multitasking() and call
rtems_fatal() instead with a fatal source of RTEMS_FATAL_SOURCE_EXIT and
a fatal code with the exit status.

Remove all bsp_cleanup() functions. The boot_card() is now a no return
function.

  • 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_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_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 * - will not return to here
110 *
111 * This style of initialization ensures that the C++ global constructors are
112 * executed after RTEMS is initialized.
113 */
114void boot_card(const char *cmdline) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
115
116#ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
117  /**
118   * @brief Gives the BSP a chance to reduce the work area size with sbrk()
119   * adding more later.
120   *
121   * bsp_sbrk_init() may reduce the work area size passed in. The routine
122   * returns the 'sbrk_amount' to be used when extending the heap.  Note that
123   * the return value may be zero.
124   *
125   * In case the @a area size is altered, then the remaining size of the
126   * @a area must be greater than or equal to @a min_size.
127   */
128  ptrdiff_t bsp_sbrk_init(Heap_Area *area, uintptr_t min_size);
129#endif
130
131static inline void bsp_work_area_initialize_default(
132  void *area_begin,
133  uintptr_t area_size
134)
135{
136  Heap_Area area = {
137    .begin = area_begin,
138    .size = area_size
139  };
140
141  #if BSP_DIRTY_MEMORY == 1
142    memset(area.begin, 0xCF,  area.size);
143  #endif
144
145  #ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
146    {
147      uintptr_t overhead = _Heap_Area_overhead(CPU_HEAP_ALIGNMENT);
148      uintptr_t work_space_size = rtems_configuration_get_work_space_size();
149      ptrdiff_t sbrk_amount = bsp_sbrk_init(
150        &area,
151        work_space_size
152          + overhead
153          + (rtems_configuration_get_unified_work_area() ? 0 : overhead)
154      );
155
156      rtems_heap_set_sbrk_amount(sbrk_amount);
157    }
158  #endif
159
160  /*
161   *  The following may be helpful in debugging what goes wrong when
162   *  you are allocating the Work Area in a new BSP.
163   */
164  #ifdef BSP_GET_WORK_AREA_DEBUG
165    {
166      void *sp = __builtin_frame_address(0);
167      void *end = (char *) area.begin + area.size;
168      printk(
169        "work_area_start = 0x%p\n"
170        "work_area_size = %lu 0x%08lx\n"
171        "end = 0x%p\n"
172        "current stack pointer = 0x%p%s\n",
173        area.begin,
174        (unsigned long) area.size,  /* decimal */
175        (unsigned long) area.size,  /* hexadecimal */
176        end,
177        sp,
178        (uintptr_t) sp >= (uintptr_t) area.begin
179          && (uintptr_t) sp <= (uintptr_t) end ?
180            " OVERLAPS!" : ""
181      );
182    }
183  #endif
184
185  _Workspace_Handler_initialization(&area, 1, NULL);
186
187  #ifdef BSP_GET_WORK_AREA_DEBUG
188    printk(
189      "heap_start = 0x%p\n"
190      "heap_size = %lu\n",
191      area.begin,
192      (unsigned long) area.size
193    );
194  #endif
195
196  RTEMS_Malloc_Initialize(&area, 1, NULL);
197}
198
199static inline void bsp_work_area_initialize_with_table(
200  Heap_Area *areas,
201  size_t area_count
202)
203{
204  _Workspace_Handler_initialization(areas, area_count, _Heap_Extend);
205  RTEMS_Malloc_Initialize(areas, area_count, _Heap_Extend);
206}
207
208void bsp_work_area_initialize(void);
209
210void bsp_libc_init(void);
211
212/** @} */
213
214#ifdef __cplusplus
215}
216#endif /* __cplusplus */
217
218#endif /* LIBBSP_SHARED_BOOTCARD_H */
Note: See TracBrowser for help on using the repository browser.