Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | /* File: startup_armv7-m.S |
2 | * Purpose: startup file for armv7-m architecture devices. |
||
3 | * Should be used with GCC for ARM Embedded Processors |
||
4 | * Version: V2.00 |
||
5 | * Date: 16 November 2015 |
||
6 | * |
||
7 | */ |
||
8 | /* Copyright (c) 2011 - 2015 ARM LIMITED |
||
9 | |||
10 | All rights reserved. |
||
11 | Redistribution and use in source and binary forms, with or without |
||
12 | modification, are permitted provided that the following conditions are met: |
||
13 | - Redistributions of source code must retain the above copyright |
||
14 | notice, this list of conditions and the following disclaimer. |
||
15 | - Redistributions in binary form must reproduce the above copyright |
||
16 | notice, this list of conditions and the following disclaimer in the |
||
17 | documentation and/or other materials provided with the distribution. |
||
18 | - Neither the name of ARM nor the names of its contributors may be used |
||
19 | to endorse or promote products derived from this software without |
||
20 | specific prior written permission. |
||
21 | * |
||
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
25 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE |
||
26 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
27 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
28 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
29 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
30 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
32 | POSSIBILITY OF SUCH DAMAGE. |
||
33 | ---------------------------------------------------------------------------*/ |
||
34 | |||
35 | |||
36 | .syntax unified |
||
37 | .arch armv7-m |
||
38 | |||
39 | .section .stack |
||
40 | .align 3 |
||
41 | #ifdef __STACK_SIZE |
||
42 | .equ Stack_Size, __STACK_SIZE |
||
43 | #else |
||
44 | .equ Stack_Size, 0x00000400 |
||
45 | #endif |
||
46 | .globl __StackTop |
||
47 | .globl __StackLimit |
||
48 | __StackLimit: |
||
49 | .space Stack_Size |
||
50 | .size __StackLimit, . - __StackLimit |
||
51 | __StackTop: |
||
52 | .size __StackTop, . - __StackTop |
||
53 | |||
54 | .section .heap |
||
55 | .align 3 |
||
56 | #ifdef __HEAP_SIZE |
||
57 | .equ Heap_Size, __HEAP_SIZE |
||
58 | #else |
||
59 | .equ Heap_Size, 0x00000C00 |
||
60 | #endif |
||
61 | .globl __HeapBase |
||
62 | .globl __HeapLimit |
||
63 | __HeapBase: |
||
64 | .if Heap_Size |
||
65 | .space Heap_Size |
||
66 | .endif |
||
67 | .size __HeapBase, . - __HeapBase |
||
68 | __HeapLimit: |
||
69 | .size __HeapLimit, . - __HeapLimit |
||
70 | |||
71 | .section .vectors |
||
72 | .align 2 |
||
73 | .globl __Vectors |
||
74 | __Vectors: |
||
75 | .long __StackTop /* Top of Stack */ |
||
76 | .long Reset_Handler /* Reset Handler */ |
||
77 | .long NMI_Handler /* NMI Handler */ |
||
78 | .long HardFault_Handler /* Hard Fault Handler */ |
||
79 | .long MemManage_Handler /* MPU Fault Handler */ |
||
80 | .long BusFault_Handler /* Bus Fault Handler */ |
||
81 | .long UsageFault_Handler /* Usage Fault Handler */ |
||
82 | .long 0 /* Reserved */ |
||
83 | .long 0 /* Reserved */ |
||
84 | .long 0 /* Reserved */ |
||
85 | .long 0 /* Reserved */ |
||
86 | .long SVC_Handler /* SVCall Handler */ |
||
87 | .long DebugMon_Handler /* Debug Monitor Handler */ |
||
88 | .long 0 /* Reserved */ |
||
89 | .long PendSV_Handler /* PendSV Handler */ |
||
90 | .long SysTick_Handler /* SysTick Handler */ |
||
91 | |||
92 | .size __Vectors, . - __Vectors |
||
93 | |||
94 | .text |
||
95 | .thumb |
||
96 | .thumb_func |
||
97 | .align 2 |
||
98 | .globl Reset_Handler |
||
99 | .type Reset_Handler, %function |
||
100 | Reset_Handler: |
||
101 | /* Firstly it copies data from read only memory to RAM. There are two schemes |
||
102 | * to copy. One can copy more than one sections. Another can only copy |
||
103 | * one section. The former scheme needs more instructions and read-only |
||
104 | * data to implement than the latter. |
||
105 | * Macro __STARTUP_COPY_MULTIPLE is used to choose between two schemes. */ |
||
106 | |||
107 | #ifdef __STARTUP_COPY_MULTIPLE |
||
108 | /* Multiple sections scheme. |
||
109 | * |
||
110 | * Between symbol address __copy_table_start__ and __copy_table_end__, |
||
111 | * there are array of triplets, each of which specify: |
||
112 | * offset 0: LMA of start of a section to copy from |
||
113 | * offset 4: VMA of start of a section to copy to |
||
114 | * offset 8: size of the section to copy. Must be multiply of 4 |
||
115 | * |
||
116 | * All addresses must be aligned to 4 bytes boundary. |
||
117 | */ |
||
118 | ldr r4, =__copy_table_start__ |
||
119 | ldr r5, =__copy_table_end__ |
||
120 | |||
121 | .L_loop0: |
||
122 | cmp r4, r5 |
||
123 | bge .L_loop0_done |
||
124 | ldr r1, [r4] |
||
125 | ldr r2, [r4, #4] |
||
126 | ldr r3, [r4, #8] |
||
127 | |||
128 | .L_loop0_0: |
||
129 | subs r3, #4 |
||
130 | ittt ge |
||
131 | ldrge r0, [r1, r3] |
||
132 | strge r0, [r2, r3] |
||
133 | bge .L_loop0_0 |
||
134 | |||
135 | adds r4, #12 |
||
136 | b .L_loop0 |
||
137 | |||
138 | .L_loop0_done: |
||
139 | #else |
||
140 | /* Single section scheme. |
||
141 | * |
||
142 | * The ranges of copy from/to are specified by following symbols |
||
143 | * __etext: LMA of start of the section to copy from. Usually end of text |
||
144 | * __data_start__: VMA of start of the section to copy to |
||
145 | * __data_end__: VMA of end of the section to copy to |
||
146 | * |
||
147 | * All addresses must be aligned to 4 bytes boundary. |
||
148 | */ |
||
149 | ldr r1, =__etext |
||
150 | ldr r2, =__data_start__ |
||
151 | ldr r3, =__data_end__ |
||
152 | |||
153 | .L_loop1: |
||
154 | cmp r2, r3 |
||
155 | ittt lt |
||
156 | ldrlt r0, [r1], #4 |
||
157 | strlt r0, [r2], #4 |
||
158 | blt .L_loop1 |
||
159 | #endif /*__STARTUP_COPY_MULTIPLE */ |
||
160 | |||
161 | /* This part of work usually is done in C library startup code. Otherwise, |
||
162 | * define this macro to enable it in this startup. |
||
163 | * |
||
164 | * There are two schemes too. One can clear multiple BSS sections. Another |
||
165 | * can only clear one section. The former is more size expensive than the |
||
166 | * latter. |
||
167 | * |
||
168 | * Define macro __STARTUP_CLEAR_BSS_MULTIPLE to choose the former. |
||
169 | * Otherwise efine macro __STARTUP_CLEAR_BSS to choose the later. |
||
170 | */ |
||
171 | #ifdef __STARTUP_CLEAR_BSS_MULTIPLE |
||
172 | /* Multiple sections scheme. |
||
173 | * |
||
174 | * Between symbol address __copy_table_start__ and __copy_table_end__, |
||
175 | * there are array of tuples specifying: |
||
176 | * offset 0: Start of a BSS section |
||
177 | * offset 4: Size of this BSS section. Must be multiply of 4 |
||
178 | */ |
||
179 | ldr r3, =__zero_table_start__ |
||
180 | ldr r4, =__zero_table_end__ |
||
181 | |||
182 | .L_loop2: |
||
183 | cmp r3, r4 |
||
184 | bge .L_loop2_done |
||
185 | ldr r1, [r3] |
||
186 | ldr r2, [r3, #4] |
||
187 | movs r0, 0 |
||
188 | |||
189 | .L_loop2_0: |
||
190 | subs r2, #4 |
||
191 | itt ge |
||
192 | strge r0, [r1, r2] |
||
193 | bge .L_loop2_0 |
||
194 | |||
195 | adds r3, #8 |
||
196 | b .L_loop2 |
||
197 | .L_loop2_done: |
||
198 | #elif defined (__STARTUP_CLEAR_BSS) |
||
199 | /* Single BSS section scheme. |
||
200 | * |
||
201 | * The BSS section is specified by following symbols |
||
202 | * __bss_start__: start of the BSS section. |
||
203 | * __bss_end__: end of the BSS section. |
||
204 | * |
||
205 | * Both addresses must be aligned to 4 bytes boundary. |
||
206 | */ |
||
207 | ldr r1, =__bss_start__ |
||
208 | ldr r2, =__bss_end__ |
||
209 | |||
210 | movs r0, 0 |
||
211 | .L_loop3: |
||
212 | cmp r1, r2 |
||
213 | itt lt |
||
214 | strlt r0, [r1], #4 |
||
215 | blt .L_loop3 |
||
216 | #endif /* __STARTUP_CLEAR_BSS_MULTIPLE || __STARTUP_CLEAR_BSS */ |
||
217 | |||
218 | #ifndef __NO_SYSTEM_INIT |
||
219 | bl SystemInit |
||
220 | #endif |
||
221 | |||
222 | #ifndef __START |
||
223 | #define __START _start |
||
224 | #endif |
||
225 | bl __START |
||
226 | |||
227 | .pool |
||
228 | .size Reset_Handler, . - Reset_Handler |
||
229 | |||
230 | .align 1 |
||
231 | .thumb_func |
||
232 | .weak Default_Handler |
||
233 | .type Default_Handler, %function |
||
234 | Default_Handler: |
||
235 | bkpt #0 |
||
236 | b . |
||
237 | .size Default_Handler, . - Default_Handler |
||
238 | |||
239 | /* Macro to define default handlers. Default handler |
||
240 | * will be weak symbol and just dead loops. They can be |
||
241 | * overwritten by other handlers */ |
||
242 | .macro def_irq_handler handler_name |
||
243 | .weak \handler_name |
||
244 | .set \handler_name, Default_Handler |
||
245 | .endm |
||
246 | |||
247 | def_irq_handler NMI_Handler |
||
248 | def_irq_handler HardFault_Handler |
||
249 | def_irq_handler MemManage_Handler |
||
250 | def_irq_handler BusFault_Handler |
||
251 | def_irq_handler UsageFault_Handler |
||
252 | def_irq_handler SVC_Handler |
||
253 | def_irq_handler DebugMon_Handler |
||
254 | def_irq_handler PendSV_Handler |
||
255 | def_irq_handler SysTick_Handler |
||
256 | |||
257 | .end |