-
Notifications
You must be signed in to change notification settings - Fork 1
/
startup.S
176 lines (144 loc) · 4.71 KB
/
startup.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/******************************************************************************
* author: Freddie Chopin, http://www.freddiechopin.info/
* file: startup.S
* last change: 2012-03-18
*
* chip: ARMv7-M(E) (Cortex-M3 / Cortex-M4)
* compiler: arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.6.2
* 20110921 (release) [ARM/embedded-4_6-branch revision 182083]
*
* description:
* ARMv7-M(E) (Cortex-M3 / Cortex-M4) assembly startup code
******************************************************************************/
/*
+=============================================================================+
| includes
+=============================================================================+
*/
#include "hdr/hdr_special_registers.h"
/*
+=============================================================================+
| ARMv7-M(E) (Cortex-M3 / Cortex-M4) startup code
+=============================================================================+
*/
.text
.balign 2
.syntax unified
.thumb
.thumb_func
.global Reset_Handler
Reset_Handler:
/*
+-----------------------------------------------------------------------------+
| Initialize the process stack pointer
+-----------------------------------------------------------------------------+
*/
ldr r0, =__process_stack_end
msr PSP, r0
/*
+-----------------------------------------------------------------------------+
| Thread mode uses process stack (PSP) and is privileged
+-----------------------------------------------------------------------------+
*/
movs r0, #CONTROL_ALTERNATE_STACK
msr CONTROL, r0
isb
/*
+-----------------------------------------------------------------------------+
| Branch to low_level_init_0() function (.data and .bss are not initialized!)
+-----------------------------------------------------------------------------+
*/
ldr r0, =low_level_init_0
blx r0
/*
+-----------------------------------------------------------------------------+
| Initialize .data section
+-----------------------------------------------------------------------------+
*/
ldr r1, =__data_init_start
ldr r2, =__data_start
ldr r3, =__data_end
1: cmp r2, r3
ittt lo
ldrlo r0, [r1], #4
strlo r0, [r2], #4
blo 1b
/*
+-----------------------------------------------------------------------------+
| Zero-init .bss section
+-----------------------------------------------------------------------------+
*/
movs r0, #0
ldr r1, =__bss_start
ldr r2, =__bss_end
1: cmp r1, r2
itt lo
strlo r0, [r1], #4
blo 1b
/*
+-----------------------------------------------------------------------------+
| Call C++ constructors for global and static objects
+-----------------------------------------------------------------------------+
*/
#ifdef __USES_CXX
ldr r0, =__libc_init_array
blx r0
#endif
/*
+-----------------------------------------------------------------------------+
| Branch to low_level_init_1() function
+-----------------------------------------------------------------------------+
*/
ldr r0, =low_level_init_1
blx r0
/*
+-----------------------------------------------------------------------------+
| Branch to main() with link
+-----------------------------------------------------------------------------+
*/
ldr r0, =main
blx r0
/*
+-----------------------------------------------------------------------------+
| Call C++ destructors for global and static objects
+-----------------------------------------------------------------------------+
*/
#ifdef __USES_CXX
ldr r0, =__libc_fini_array
blx r0
#endif
/*
+-----------------------------------------------------------------------------+
| On return - loop till the end of the world
+-----------------------------------------------------------------------------+
*/
b .
/*
+=============================================================================+
| __default_low_level_init() - replacement for undefined low_level_init_0()
| and/or low_level_init_1(). This function just returns.
+=============================================================================+
*/
.text
.balign 2
.syntax unified
.thumb
.thumb_func
.global __default_low_level_init
__default_low_level_init:
bx lr
/*
+=============================================================================+
| assign undefined low_level_init_0() and/or low_level_init_1() to
| __default_low_level_init()
+=============================================================================+
*/
.weak low_level_init_0
.global low_level_init_0
.set low_level_init_0, __default_low_level_init
.weak low_level_init_1
.global low_level_init_1
.set low_level_init_1, __default_low_level_init
/******************************************************************************
* END OF FILE
******************************************************************************/