xref: /nrf52832-nimble/nordic/nrfx/mdk/gcc_startup_nrf52.S (revision 150812a83cab50279bd772ef6db1bfaf255f2c5b)
1/*
2
3Copyright (c) 2009-2018 ARM Limited. All rights reserved.
4
5    SPDX-License-Identifier: Apache-2.0
6
7Licensed under the Apache License, Version 2.0 (the License); you may
8not use this file except in compliance with the License.
9You may obtain a copy of the License at
10
11    www.apache.org/licenses/LICENSE-2.0
12
13Unless required by applicable law or agreed to in writing, software
14distributed under the License is distributed on an AS IS BASIS, WITHOUT
15WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16See the License for the specific language governing permissions and
17limitations under the License.
18
19NOTICE: This file has been modified by Nordic Semiconductor ASA.
20
21*/
22
23    .syntax unified
24    .arch armv7e-m
25
26#ifdef __STARTUP_CONFIG
27#include "startup_config.h"
28#ifndef __STARTUP_CONFIG_STACK_ALIGNEMENT
29#define __STARTUP_CONFIG_STACK_ALIGNEMENT 3
30#endif
31#endif
32
33    .section .stack
34#if defined(__STARTUP_CONFIG)
35    .align __STARTUP_CONFIG_STACK_ALIGNEMENT
36    .equ    Stack_Size, __STARTUP_CONFIG_STACK_SIZE
37#elif defined(__STACK_SIZE)
38    .align 3
39    .equ    Stack_Size, __STACK_SIZE
40#else
41    .align 3
42    .equ    Stack_Size, 8192
43#endif
44    .globl __StackTop
45    .globl __StackLimit
46__StackLimit:
47    .space Stack_Size
48    .size __StackLimit, . - __StackLimit
49__StackTop:
50    .size __StackTop, . - __StackTop
51
52    .section .heap
53    .align 3
54#if defined(__STARTUP_CONFIG)
55    .equ Heap_Size, __STARTUP_CONFIG_HEAP_SIZE
56#elif defined(__HEAP_SIZE)
57    .equ Heap_Size, __HEAP_SIZE
58#else
59    .equ Heap_Size, 8192
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 .isr_vector
72    .align 2
73    .globl __isr_vector
74__isr_vector:
75    .long   __StackTop                  /* Top of Stack */
76    .long   Reset_Handler
77    .long   NMI_Handler
78    .long   HardFault_Handler
79    .long   MemoryManagement_Handler
80    .long   BusFault_Handler
81    .long   UsageFault_Handler
82    .long   0                           /*Reserved */
83    .long   0                           /*Reserved */
84    .long   0                           /*Reserved */
85    .long   0                           /*Reserved */
86    .long   SVC_Handler
87    .long   DebugMon_Handler
88    .long   0                           /*Reserved */
89    .long   PendSV_Handler
90    .long   SysTick_Handler
91
92  /* External Interrupts */
93    .long   POWER_CLOCK_IRQHandler
94    .long   RADIO_IRQHandler
95    .long   UARTE0_UART0_IRQHandler
96    .long   SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler
97    .long   SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler
98    .long   NFCT_IRQHandler
99    .long   GPIOTE_IRQHandler
100    .long   SAADC_IRQHandler
101    .long   TIMER0_IRQHandler
102    .long   TIMER1_IRQHandler
103    .long   TIMER2_IRQHandler
104    .long   RTC0_IRQHandler
105    .long   TEMP_IRQHandler
106    .long   RNG_IRQHandler
107    .long   ECB_IRQHandler
108    .long   CCM_AAR_IRQHandler
109    .long   WDT_IRQHandler
110    .long   RTC1_IRQHandler
111    .long   QDEC_IRQHandler
112    .long   COMP_LPCOMP_IRQHandler
113    .long   SWI0_EGU0_IRQHandler
114    .long   SWI1_EGU1_IRQHandler
115    .long   SWI2_EGU2_IRQHandler
116    .long   SWI3_EGU3_IRQHandler
117    .long   SWI4_EGU4_IRQHandler
118    .long   SWI5_EGU5_IRQHandler
119    .long   TIMER3_IRQHandler
120    .long   TIMER4_IRQHandler
121    .long   PWM0_IRQHandler
122    .long   PDM_IRQHandler
123    .long   0                           /*Reserved */
124    .long   0                           /*Reserved */
125    .long   MWU_IRQHandler
126    .long   PWM1_IRQHandler
127    .long   PWM2_IRQHandler
128    .long   SPIM2_SPIS2_SPI2_IRQHandler
129    .long   RTC2_IRQHandler
130    .long   I2S_IRQHandler
131    .long   FPU_IRQHandler
132    .long   0                           /*Reserved */
133    .long   0                           /*Reserved */
134    .long   0                           /*Reserved */
135    .long   0                           /*Reserved */
136    .long   0                           /*Reserved */
137    .long   0                           /*Reserved */
138    .long   0                           /*Reserved */
139    .long   0                           /*Reserved */
140    .long   0                           /*Reserved */
141    .long   0                           /*Reserved */
142    .long   0                           /*Reserved */
143    .long   0                           /*Reserved */
144    .long   0                           /*Reserved */
145    .long   0                           /*Reserved */
146    .long   0                           /*Reserved */
147    .long   0                           /*Reserved */
148    .long   0                           /*Reserved */
149    .long   0                           /*Reserved */
150    .long   0                           /*Reserved */
151    .long   0                           /*Reserved */
152    .long   0                           /*Reserved */
153    .long   0                           /*Reserved */
154    .long   0                           /*Reserved */
155    .long   0                           /*Reserved */
156    .long   0                           /*Reserved */
157    .long   0                           /*Reserved */
158    .long   0                           /*Reserved */
159    .long   0                           /*Reserved */
160    .long   0                           /*Reserved */
161    .long   0                           /*Reserved */
162    .long   0                           /*Reserved */
163    .long   0                           /*Reserved */
164    .long   0                           /*Reserved */
165    .long   0                           /*Reserved */
166    .long   0                           /*Reserved */
167    .long   0                           /*Reserved */
168    .long   0                           /*Reserved */
169    .long   0                           /*Reserved */
170    .long   0                           /*Reserved */
171    .long   0                           /*Reserved */
172    .long   0                           /*Reserved */
173    .long   0                           /*Reserved */
174    .long   0                           /*Reserved */
175    .long   0                           /*Reserved */
176    .long   0                           /*Reserved */
177    .long   0                           /*Reserved */
178    .long   0                           /*Reserved */
179    .long   0                           /*Reserved */
180    .long   0                           /*Reserved */
181    .long   0                           /*Reserved */
182    .long   0                           /*Reserved */
183    .long   0                           /*Reserved */
184    .long   0                           /*Reserved */
185    .long   0                           /*Reserved */
186    .long   0                           /*Reserved */
187    .long   0                           /*Reserved */
188    .long   0                           /*Reserved */
189    .long   0                           /*Reserved */
190    .long   0                           /*Reserved */
191    .long   0                           /*Reserved */
192    .long   0                           /*Reserved */
193    .long   0                           /*Reserved */
194    .long   0                           /*Reserved */
195    .long   0                           /*Reserved */
196    .long   0                           /*Reserved */
197    .long   0                           /*Reserved */
198    .long   0                           /*Reserved */
199    .long   0                           /*Reserved */
200    .long   0                           /*Reserved */
201    .long   0                           /*Reserved */
202    .long   0                           /*Reserved */
203    .long   0                           /*Reserved */
204    .long   0                           /*Reserved */
205
206    .size __isr_vector, . - __isr_vector
207
208/* Reset Handler */
209
210
211    .text
212    .thumb
213    .thumb_func
214    .align 1
215    .globl Reset_Handler
216    .type Reset_Handler, %function
217Reset_Handler:
218
219
220/* Loop to copy data from read only memory to RAM.
221 * The ranges of copy from/to are specified by following symbols:
222 *      __etext: LMA of start of the section to copy from. Usually end of text
223 *      __data_start__: VMA of start of the section to copy to.
224 *      __bss_start__: VMA of end of the section to copy to. Normally __data_end__ is used, but by using __bss_start__
225 *                    the user can add their own initialized data section before BSS section with the INTERT AFTER command.
226 *
227 * All addresses must be aligned to 4 bytes boundary.
228 */
229    ldr r1, =__etext
230    ldr r2, =__data_start__
231    ldr r3, =__bss_start__
232
233    subs r3, r3, r2
234    ble .L_loop1_done
235
236.L_loop1:
237    subs r3, r3, #4
238    ldr r0, [r1,r3]
239    str r0, [r2,r3]
240    bgt .L_loop1
241
242.L_loop1_done:
243
244/* This part of work usually is done in C library startup code. Otherwise,
245 * define __STARTUP_CLEAR_BSS to enable it in this startup. This section
246 * clears the RAM where BSS data is located.
247 *
248 * The BSS section is specified by following symbols
249 *    __bss_start__: start of the BSS section.
250 *    __bss_end__: end of the BSS section.
251 *
252 * All addresses must be aligned to 4 bytes boundary.
253 */
254#ifdef __STARTUP_CLEAR_BSS
255    ldr r1, =__bss_start__
256    ldr r2, =__bss_end__
257
258    movs r0, 0
259
260    subs r2, r2, r1
261    ble .L_loop3_done
262
263.L_loop3:
264    subs r2, r2, #4
265    str r0, [r1, r2]
266    bgt .L_loop3
267
268.L_loop3_done:
269#endif /* __STARTUP_CLEAR_BSS */
270
271/* Execute SystemInit function. */
272    bl SystemInit
273
274/* Call _start function provided by libraries.
275 * If those libraries are not accessible, define __START as your entry point.
276 */
277#ifndef __START
278#define __START _start
279#endif
280    bl __START
281
282    .pool
283    .size   Reset_Handler,.-Reset_Handler
284
285    .section ".text"
286
287
288/* Dummy Exception Handlers (infinite loops which can be modified) */
289
290    .weak   NMI_Handler
291    .type   NMI_Handler, %function
292NMI_Handler:
293    b       .
294    .size   NMI_Handler, . - NMI_Handler
295
296
297    .weak   HardFault_Handler
298    .type   HardFault_Handler, %function
299HardFault_Handler:
300    b       .
301    .size   HardFault_Handler, . - HardFault_Handler
302
303
304    .weak   MemoryManagement_Handler
305    .type   MemoryManagement_Handler, %function
306MemoryManagement_Handler:
307    b       .
308    .size   MemoryManagement_Handler, . - MemoryManagement_Handler
309
310
311    .weak   BusFault_Handler
312    .type   BusFault_Handler, %function
313BusFault_Handler:
314    b       .
315    .size   BusFault_Handler, . - BusFault_Handler
316
317
318    .weak   UsageFault_Handler
319    .type   UsageFault_Handler, %function
320UsageFault_Handler:
321    b       .
322    .size   UsageFault_Handler, . - UsageFault_Handler
323
324
325    .weak   SVC_Handler
326    .type   SVC_Handler, %function
327SVC_Handler:
328    b       .
329    .size   SVC_Handler, . - SVC_Handler
330
331
332    .weak   DebugMon_Handler
333    .type   DebugMon_Handler, %function
334DebugMon_Handler:
335    b       .
336    .size   DebugMon_Handler, . - DebugMon_Handler
337
338
339    .weak   PendSV_Handler
340    .type   PendSV_Handler, %function
341PendSV_Handler:
342    b       .
343    .size   PendSV_Handler, . - PendSV_Handler
344
345
346    .weak   SysTick_Handler
347    .type   SysTick_Handler, %function
348SysTick_Handler:
349    b       .
350    .size   SysTick_Handler, . - SysTick_Handler
351
352
353/* IRQ Handlers */
354
355    .globl  Default_Handler
356    .type   Default_Handler, %function
357Default_Handler:
358    b       .
359    .size   Default_Handler, . - Default_Handler
360
361    .macro  IRQ handler
362    .weak   \handler
363    .set    \handler, Default_Handler
364    .endm
365
366    IRQ  POWER_CLOCK_IRQHandler
367    IRQ  RADIO_IRQHandler
368    IRQ  UARTE0_UART0_IRQHandler
369    IRQ  SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler
370    IRQ  SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler
371    IRQ  NFCT_IRQHandler
372    IRQ  GPIOTE_IRQHandler
373    IRQ  SAADC_IRQHandler
374    IRQ  TIMER0_IRQHandler
375    IRQ  TIMER1_IRQHandler
376    IRQ  TIMER2_IRQHandler
377    IRQ  RTC0_IRQHandler
378    IRQ  TEMP_IRQHandler
379    IRQ  RNG_IRQHandler
380    IRQ  ECB_IRQHandler
381    IRQ  CCM_AAR_IRQHandler
382    IRQ  WDT_IRQHandler
383    IRQ  RTC1_IRQHandler
384    IRQ  QDEC_IRQHandler
385    IRQ  COMP_LPCOMP_IRQHandler
386    IRQ  SWI0_EGU0_IRQHandler
387    IRQ  SWI1_EGU1_IRQHandler
388    IRQ  SWI2_EGU2_IRQHandler
389    IRQ  SWI3_EGU3_IRQHandler
390    IRQ  SWI4_EGU4_IRQHandler
391    IRQ  SWI5_EGU5_IRQHandler
392    IRQ  TIMER3_IRQHandler
393    IRQ  TIMER4_IRQHandler
394    IRQ  PWM0_IRQHandler
395    IRQ  PDM_IRQHandler
396    IRQ  MWU_IRQHandler
397    IRQ  PWM1_IRQHandler
398    IRQ  PWM2_IRQHandler
399    IRQ  SPIM2_SPIS2_SPI2_IRQHandler
400    IRQ  RTC2_IRQHandler
401    IRQ  I2S_IRQHandler
402    IRQ  FPU_IRQHandler
403
404  .end
405