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

4.115
Last change on this file since a0c7aa55 was b1e8a58, checked in by Sebastian Huber <sebastian.huber@…>, on 11/14/12 at 08:57:55

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