diff options
Diffstat (limited to 'lib/chibios/os/common/startup/ARMCMx-SB/compilers/GCC/crt0.S')
-rw-r--r-- | lib/chibios/os/common/startup/ARMCMx-SB/compilers/GCC/crt0.S | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/lib/chibios/os/common/startup/ARMCMx-SB/compilers/GCC/crt0.S b/lib/chibios/os/common/startup/ARMCMx-SB/compilers/GCC/crt0.S new file mode 100644 index 000000000..13aa78a9f --- /dev/null +++ b/lib/chibios/os/common/startup/ARMCMx-SB/compilers/GCC/crt0.S | |||
@@ -0,0 +1,190 @@ | |||
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 crt0.S | ||
19 | * @brief Generic ARMv7-M sandbox startup file for ChibiOS. | ||
20 | * | ||
21 | * @addtogroup ARMCMx_GCC_STARTUP_V7M_SB | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | /*===========================================================================*/ | ||
26 | /* Module constants. */ | ||
27 | /*===========================================================================*/ | ||
28 | |||
29 | #if !defined(FALSE) || defined(__DOXYGEN__) | ||
30 | #define FALSE 0 | ||
31 | #endif | ||
32 | |||
33 | #if !defined(TRUE) || defined(__DOXYGEN__) | ||
34 | #define TRUE 1 | ||
35 | #endif | ||
36 | |||
37 | /*===========================================================================*/ | ||
38 | /* Module pre-compile time settings. */ | ||
39 | /*===========================================================================*/ | ||
40 | |||
41 | /** | ||
42 | * @brief Stack segments initialization switch. | ||
43 | */ | ||
44 | #if !defined(CRT0_STACKS_FILL_PATTERN) || defined(__DOXYGEN__) | ||
45 | #define CRT0_STACKS_FILL_PATTERN 0x55555555 | ||
46 | #endif | ||
47 | |||
48 | /** | ||
49 | * @brief Stack segments initialization switch. | ||
50 | */ | ||
51 | #if !defined(CRT0_INIT_STACKS) || defined(__DOXYGEN__) | ||
52 | #define CRT0_INIT_STACKS TRUE | ||
53 | #endif | ||
54 | |||
55 | /** | ||
56 | * @brief DATA segment initialization switch. | ||
57 | */ | ||
58 | #if !defined(CRT0_INIT_DATA) || defined(__DOXYGEN__) | ||
59 | #define CRT0_INIT_DATA TRUE | ||
60 | #endif | ||
61 | |||
62 | /** | ||
63 | * @brief BSS segment initialization switch. | ||
64 | */ | ||
65 | #if !defined(CRT0_INIT_BSS) || defined(__DOXYGEN__) | ||
66 | #define CRT0_INIT_BSS TRUE | ||
67 | #endif | ||
68 | |||
69 | /** | ||
70 | * @brief Constructors invocation switch. | ||
71 | */ | ||
72 | #if !defined(CRT0_CALL_CONSTRUCTORS) || defined(__DOXYGEN__) | ||
73 | #define CRT0_CALL_CONSTRUCTORS TRUE | ||
74 | #endif | ||
75 | |||
76 | /** | ||
77 | * @brief Destructors invocation switch. | ||
78 | */ | ||
79 | #if !defined(CRT0_CALL_DESTRUCTORS) || defined(__DOXYGEN__) | ||
80 | #define CRT0_CALL_DESTRUCTORS TRUE | ||
81 | #endif | ||
82 | |||
83 | /*===========================================================================*/ | ||
84 | /* Code section. */ | ||
85 | /*===========================================================================*/ | ||
86 | |||
87 | #if !defined(__DOXYGEN__) | ||
88 | |||
89 | .syntax unified | ||
90 | .cpu cortex-m3 | ||
91 | |||
92 | .thumb | ||
93 | |||
94 | .section .sandbox, "ax" | ||
95 | .align 4 | ||
96 | .globl _sandbox | ||
97 | _sandbox: .long 0xFE9154C0 | ||
98 | .long 0x0C4519EF | ||
99 | .long 16 | ||
100 | .long 0 | ||
101 | b _crt0_entry | ||
102 | |||
103 | .text | ||
104 | /* | ||
105 | * CRT0 entry point. | ||
106 | */ | ||
107 | .align 2 | ||
108 | .thumb_func | ||
109 | .global _crt0_entry | ||
110 | _crt0_entry: | ||
111 | |||
112 | /* PSP stack pointers initialization.*/ | ||
113 | ldr r0, =__user_psp_end__ | ||
114 | msr PSP, r0 | ||
115 | |||
116 | #if CRT0_INIT_STACKS == TRUE | ||
117 | /* User process Stack initialization. Note, it assumes that the | ||
118 | stack size is a multiple of 4 so the linker file must | ||
119 | ensure this.*/ | ||
120 | ldr r0, =CRT0_STACKS_FILL_PATTERN | ||
121 | ldr r1, =__user_psp_base__ | ||
122 | ldr r2, =__user_psp_end__ | ||
123 | upsloop: | ||
124 | cmp r1, r2 | ||
125 | itt lo | ||
126 | strlo r0, [r1], #4 | ||
127 | blo upsloop | ||
128 | #endif /* CRT0_INIT_STACKS == TRUE */ | ||
129 | |||
130 | #if CRT0_INIT_DATA == TRUE | ||
131 | /* Data initialization. Note, it assumes that the DATA size | ||
132 | is a multiple of 4 so the linker file must ensure this.*/ | ||
133 | ldr r1, =__textdata_base__ | ||
134 | ldr r2, =__data_base__ | ||
135 | ldr r3, =__data_end__ | ||
136 | dloop: | ||
137 | cmp r2, r3 | ||
138 | ittt lo | ||
139 | ldrlo r0, [r1], #4 | ||
140 | strlo r0, [r2], #4 | ||
141 | blo dloop | ||
142 | #endif /* CRT0_INIT_DATA == TRUE */ | ||
143 | |||
144 | #if CRT0_INIT_BSS == TRUE | ||
145 | /* BSS initialization. Note, it assumes that the DATA size | ||
146 | is a multiple of 4 so the linker file must ensure this.*/ | ||
147 | movs r0, #0 | ||
148 | ldr r1, =__bss_base__ | ||
149 | ldr r2, =__bss_end__ | ||
150 | bloop: | ||
151 | cmp r1, r2 | ||
152 | itt lo | ||
153 | strlo r0, [r1], #4 | ||
154 | blo bloop | ||
155 | #endif /* CRT0_INIT_BSS == TRUE */ | ||
156 | |||
157 | #if CRT0_CALL_CONSTRUCTORS == TRUE | ||
158 | /* Constructors invocation.*/ | ||
159 | ldr r4, =__init_array_base__ | ||
160 | ldr r5, =__init_array_end__ | ||
161 | initloop: | ||
162 | cmp r4, r5 | ||
163 | bge endinitloop | ||
164 | ldr r1, [r4], #4 | ||
165 | blx r1 | ||
166 | b initloop | ||
167 | endinitloop: | ||
168 | #endif /* CRT0_CALL_CONSTRUCTORS == TRUE */ | ||
169 | |||
170 | /* Main program invocation, r0 contains the returned value.*/ | ||
171 | bl main | ||
172 | |||
173 | #if CRT0_CALL_DESTRUCTORS == TRUE | ||
174 | /* Destructors invocation.*/ | ||
175 | ldr r4, =__fini_array_base__ | ||
176 | ldr r5, =__fini_array_end__ | ||
177 | finiloop: | ||
178 | cmp r4, r5 | ||
179 | bge endfiniloop | ||
180 | ldr r1, [r4], #4 | ||
181 | blx r1 | ||
182 | b finiloop | ||
183 | endfiniloop: | ||
184 | #endif /* CRT0_CALL_DESTRUCTORS == TRUE */ | ||
185 | |||
186 | .exitloop: b .exitloop | ||
187 | |||
188 | #endif /* !defined(__DOXYGEN__) */ | ||
189 | |||
190 | /** @} */ | ||