[d4886a06] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * |
---|
[8634637] | 4 | * @ingroup bsp_bootcard |
---|
[d4886a06] | 5 | * |
---|
[8634637] | 6 | * @brief Standard system startup. |
---|
[d4886a06] | 7 | */ |
---|
| 8 | |
---|
| 9 | /* |
---|
[47a3cd8] | 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> |
---|
[d4886a06] | 17 | * |
---|
[0e27119] | 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. |
---|
[d4886a06] | 21 | */ |
---|
| 22 | |
---|
| 23 | /** |
---|
[8634637] | 24 | * @defgroup bsp_kit Board Support Package |
---|
| 25 | * |
---|
| 26 | * @brief Board support package dependent code. |
---|
| 27 | */ |
---|
| 28 | |
---|
[d4886a06] | 29 | #ifndef LIBBSP_SHARED_BOOTCARD_H |
---|
| 30 | #define LIBBSP_SHARED_BOOTCARD_H |
---|
| 31 | |
---|
[47a3cd8] | 32 | #include <unistd.h> |
---|
| 33 | |
---|
| 34 | #include <rtems/malloc.h> |
---|
| 35 | #include <rtems/bspIo.h> |
---|
[d4886a06] | 36 | |
---|
[0de9fdf] | 37 | #include <bspopts.h> |
---|
[d4886a06] | 38 | |
---|
| 39 | #ifdef __cplusplus |
---|
| 40 | extern "C" { |
---|
| 41 | #endif /* __cplusplus */ |
---|
| 42 | |
---|
[47a3cd8] | 43 | /** |
---|
| 44 | * @defgroup bsp_bootcard Bootcard |
---|
| 45 | * |
---|
| 46 | * @ingroup bsp_kit |
---|
| 47 | * |
---|
| 48 | * @brief Standard system startup. |
---|
| 49 | * |
---|
| 50 | * @{ |
---|
| 51 | */ |
---|
| 52 | |
---|
[dd8df59] | 53 | /** |
---|
| 54 | * @brief Generic BSP fatal error codes. |
---|
| 55 | */ |
---|
| 56 | typedef enum { |
---|
[b1e8a58] | 57 | BSP_GENERIC_FATAL_EXCEPTION_INITIALIZATION, |
---|
[facf8362] | 58 | BSP_GENERIC_FATAL_INTERRUPT_INITIALIZATION, |
---|
| 59 | BSP_GENERIC_FATAL_SPURIOUS_INTERRUPT |
---|
[dd8df59] | 60 | } bsp_generic_fatal_code; |
---|
| 61 | |
---|
[8634637] | 62 | /** |
---|
| 63 | * @brief Global pointer to the command line of boot_card(). |
---|
| 64 | */ |
---|
| 65 | extern const char *bsp_boot_cmdline; |
---|
| 66 | |
---|
[f3eaba9a] | 67 | void bsp_start(void); |
---|
[d4886a06] | 68 | |
---|
[f3eaba9a] | 69 | void bsp_pretasking_hook(void); |
---|
[d4886a06] | 70 | |
---|
[f3eaba9a] | 71 | void bsp_predriver_hook(void); |
---|
[d4886a06] | 72 | |
---|
[f3eaba9a] | 73 | void bsp_postdriver_hook(void); |
---|
[d4886a06] | 74 | |
---|
[54cf1198] | 75 | void bsp_reset(void); |
---|
| 76 | |
---|
[8634637] | 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 | * |
---|
[1e1ee0c] | 90 | * - disable interrupts, interrupts will be enabled during the first context |
---|
| 91 | * switch |
---|
[8634637] | 92 | * - bsp_start() - more advanced initialization |
---|
[47a3cd8] | 93 | * - bsp_work_area_initialize() - initialize the RTEMS Workspace and the C |
---|
| 94 | * Program Heap |
---|
[8634637] | 95 | * - rtems_initialize_data_structures() |
---|
[47a3cd8] | 96 | * - initialize C Library |
---|
[8634637] | 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 |
---|
[2984b7c1] | 107 | * - .... application runs ... |
---|
[8634637] | 108 | * - exit |
---|
[48bff53b] | 109 | * - will not return to here |
---|
[8634637] | 110 | * |
---|
| 111 | * This style of initialization ensures that the C++ global constructors are |
---|
| 112 | * executed after RTEMS is initialized. |
---|
| 113 | */ |
---|
[48bff53b] | 114 | void boot_card(const char *cmdline) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE; |
---|
[8634637] | 115 | |
---|
[47a3cd8] | 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 |
---|
[d4886a06] | 130 | |
---|
[47a3cd8] | 131 | static 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 | |
---|
[c118a6e5] | 199 | static 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 | |
---|
[47a3cd8] | 208 | void bsp_work_area_initialize(void); |
---|
| 209 | |
---|
| 210 | void bsp_libc_init(void); |
---|
| 211 | |
---|
| 212 | /** @} */ |
---|
[d4886a06] | 213 | |
---|
| 214 | #ifdef __cplusplus |
---|
| 215 | } |
---|
| 216 | #endif /* __cplusplus */ |
---|
| 217 | |
---|
| 218 | #endif /* LIBBSP_SHARED_BOOTCARD_H */ |
---|