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