aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios/os/common/startup/ARMCMx/compilers/GCC/crt1.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios/os/common/startup/ARMCMx/compilers/GCC/crt1.c')
-rw-r--r--lib/chibios/os/common/startup/ARMCMx/compilers/GCC/crt1.c219
1 files changed, 219 insertions, 0 deletions
diff --git a/lib/chibios/os/common/startup/ARMCMx/compilers/GCC/crt1.c b/lib/chibios/os/common/startup/ARMCMx/compilers/GCC/crt1.c
new file mode 100644
index 000000000..db1a831d7
--- /dev/null
+++ b/lib/chibios/os/common/startup/ARMCMx/compilers/GCC/crt1.c
@@ -0,0 +1,219 @@
1/*
2 ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file ARMCMx/compilers/GCC/crt1.c
19 * @brief Startup stub functions.
20 *
21 * @addtogroup ARMCMx_GCC_STARTUP
22 * @{
23 */
24
25#include <stdint.h>
26#include <stdbool.h>
27
28#include "cmparams.h"
29
30/*===========================================================================*/
31/* Module local definitions. */
32/*===========================================================================*/
33
34#if !defined(CRT1_AREAS_NUMBER) || defined(__DOXYGEN__)
35#define CRT1_AREAS_NUMBER 8
36#endif
37
38#if (CRT1_AREAS_NUMBER < 0) || (CRT1_AREAS_NUMBER > 8)
39#error "CRT1_AREAS_NUMBER must be within 0 and 8"
40#endif
41
42/*===========================================================================*/
43/* Module exported variables. */
44/*===========================================================================*/
45
46/*===========================================================================*/
47/* Module local types. */
48/*===========================================================================*/
49
50/**
51 * @brief Type of an area to be initialized.
52 */
53typedef struct {
54 uint32_t *init_text_area;
55 uint32_t *init_area;
56 uint32_t *clear_area;
57 uint32_t *no_init_area;
58} ram_init_area_t;
59
60/*===========================================================================*/
61/* Module local variables. */
62/*===========================================================================*/
63
64#if (CRT1_AREAS_NUMBER > 0) || defined(__DOXYGEN__)
65extern uint32_t __ram0_init_text__, __ram0_init__, __ram0_clear__, __ram0_noinit__;
66#endif
67#if (CRT1_AREAS_NUMBER > 1) || defined(__DOXYGEN__)
68extern uint32_t __ram1_init_text__, __ram1_init__, __ram1_clear__, __ram1_noinit__;
69#endif
70#if (CRT1_AREAS_NUMBER > 2) || defined(__DOXYGEN__)
71extern uint32_t __ram2_init_text__, __ram2_init__, __ram2_clear__, __ram2_noinit__;
72#endif
73#if (CRT1_AREAS_NUMBER > 3) || defined(__DOXYGEN__)
74extern uint32_t __ram3_init_text__, __ram3_init__, __ram3_clear__, __ram3_noinit__;
75#endif
76#if (CRT1_AREAS_NUMBER > 4) || defined(__DOXYGEN__)
77extern uint32_t __ram4_init_text__, __ram4_init__, __ram4_clear__, __ram4_noinit__;
78#endif
79#if (CRT1_AREAS_NUMBER > 5) || defined(__DOXYGEN__)
80extern uint32_t __ram5_init_text__, __ram5_init__, __ram5_clear__, __ram5_noinit__;
81#endif
82#if (CRT1_AREAS_NUMBER > 6) || defined(__DOXYGEN__)
83extern uint32_t __ram6_init_text__, __ram6_init__, __ram6_clear__, __ram6_noinit__;
84#endif
85#if (CRT1_AREAS_NUMBER > 7) || defined(__DOXYGEN__)
86extern uint32_t __ram7_init_text__, __ram7_init__, __ram7_clear__, __ram7_noinit__;
87#endif
88
89/**
90 * @brief Static table of areas to be initialized.
91 */
92#if (CRT1_AREAS_NUMBER > 0) || defined(__DOXYGEN__)
93static const ram_init_area_t ram_areas[CRT1_AREAS_NUMBER] = {
94 {&__ram0_init_text__, &__ram0_init__, &__ram0_clear__, &__ram0_noinit__},
95#if (CRT1_AREAS_NUMBER > 1) || defined(__DOXYGEN__)
96 {&__ram1_init_text__, &__ram1_init__, &__ram1_clear__, &__ram1_noinit__},
97#endif
98#if (CRT1_AREAS_NUMBER > 2) || defined(__DOXYGEN__)
99 {&__ram2_init_text__, &__ram2_init__, &__ram2_clear__, &__ram2_noinit__},
100#endif
101#if (CRT1_AREAS_NUMBER > 3) || defined(__DOXYGEN__)
102 {&__ram3_init_text__, &__ram3_init__, &__ram3_clear__, &__ram3_noinit__},
103#endif
104#if (CRT1_AREAS_NUMBER > 4) || defined(__DOXYGEN__)
105 {&__ram4_init_text__, &__ram4_init__, &__ram4_clear__, &__ram4_noinit__},
106#endif
107#if (CRT1_AREAS_NUMBER > 5) || defined(__DOXYGEN__)
108 {&__ram5_init_text__, &__ram5_init__, &__ram5_clear__, &__ram5_noinit__},
109#endif
110#if (CRT1_AREAS_NUMBER > 6) || defined(__DOXYGEN__)
111 {&__ram6_init_text__, &__ram6_init__, &__ram6_clear__, &__ram6_noinit__},
112#endif
113#if (CRT1_AREAS_NUMBER > 7) || defined(__DOXYGEN__)
114 {&__ram7_init_text__, &__ram7_init__, &__ram7_clear__, &__ram7_noinit__},
115#endif
116};
117#endif
118
119/*===========================================================================*/
120/* Module local functions. */
121/*===========================================================================*/
122
123/*===========================================================================*/
124/* Module exported functions. */
125/*===========================================================================*/
126
127/**
128 * @brief Architecture-dependent core initialization.
129 * @details This hook is invoked immediately after the stack initialization
130 * and before the DATA and BSS segments initialization.
131 * @note This function is a weak symbol.
132 */
133#if !defined(__DOXYGEN__)
134__attribute__((weak))
135#endif
136/*lint -save -e9075 [8.4] All symbols are invoked from asm context.*/
137void __core_init(void) {
138
139#if CORTEX_MODEL == 7
140 SCB_EnableICache();
141 SCB_EnableDCache();
142#endif
143}
144
145/**
146 * @brief Early initialization.
147 * @details This hook is invoked immediately after the stack and core
148 * initialization and before the DATA and BSS segments
149 * initialization.
150 * @note This function is a weak symbol.
151 */
152#if !defined(__DOXYGEN__)
153__attribute__((weak))
154#endif
155/*lint -save -e9075 [8.4] All symbols are invoked from asm context.*/
156void __early_init(void) {}
157/*lint -restore*/
158
159/**
160 * @brief Late initialization.
161 * @details This hook is invoked after the DATA and BSS segments
162 * initialization and before any static constructor. The
163 * default behavior is to do nothing.
164 * @note This function is a weak symbol.
165 */
166#if !defined(__DOXYGEN__)
167__attribute__((weak))
168#endif
169/*lint -save -e9075 [8.4] All symbols are invoked from asm context.*/
170void __late_init(void) {}
171/*lint -restore*/
172
173/**
174 * @brief Default @p main() function exit handler.
175 * @details This handler is invoked or the @p main() function exit. The
176 * default behavior is to enter an infinite loop.
177 * @note This function is a weak symbol.
178 */
179#if !defined(__DOXYGEN__)
180__attribute__((noreturn, weak))
181#endif
182/*lint -save -e9075 [8.4] All symbols are invoked from asm context.*/
183void __default_exit(void) {
184/*lint -restore*/
185
186 while (true) {
187 }
188}
189
190/**
191 * @brief Performs the initialization of the various RAM areas.
192 */
193void __init_ram_areas(void) {
194#if CRT1_AREAS_NUMBER > 0
195 const ram_init_area_t *rap = ram_areas;
196
197 do {
198 uint32_t *tp = rap->init_text_area;
199 uint32_t *p = rap->init_area;
200
201 /* Copying initialization data.*/
202 while (p < rap->clear_area) {
203 *p = *tp;
204 p++;
205 tp++;
206 }
207
208 /* Zeroing clear area.*/
209 while (p < rap->no_init_area) {
210 *p = 0;
211 p++;
212 }
213 rap++;
214 }
215 while (rap < &ram_areas[CRT1_AREAS_NUMBER]);
216#endif
217}
218
219/** @} */