1/*
2
3Copyright (c) 2009-2020 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, 2048
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, 2048
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, "ax"
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   TWIM0_TWIS0_TWI0_SPIM1_SPIS1_SPI1_IRQHandler
97    .long   SPIM0_SPIS0_SPI0_IRQHandler
98    .long   0                           /*Reserved */
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_IRQHandler
113    .long   SWI0_EGU0_IRQHandler
114    .long   SWI1_EGU1_IRQHandler
115    .long   SWI2_IRQHandler
116    .long   SWI3_IRQHandler
117    .long   SWI4_IRQHandler
118    .long   SWI5_IRQHandler
119    .long   0                           /*Reserved */
120    .long   0                           /*Reserved */
121    .long   PWM0_IRQHandler
122    .long   PDM_IRQHandler
123    .long   0                           /*Reserved */
124    .long   0                           /*Reserved */
125    .long   0                           /*Reserved */
126    .long   0                           /*Reserved */
127    .long   0                           /*Reserved */
128    .long   0                           /*Reserved */
129    .long   0                           /*Reserved */
130    .long   0                           /*Reserved */
131    .long   0                           /*Reserved */
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 INSERT AFTER command.
226 *
227 * All addresses must be aligned to 4 bytes boundary.
228 */
229#ifndef __STARTUP_SKIP_ETEXT
230    ldr r1, =__etext
231    ldr r2, =__data_start__
232    ldr r3, =__bss_start__
233
234    subs r3, r3, r2
235    ble .L_loop1_done
236
237.L_loop1:
238    subs r3, r3, #4
239    ldr r0, [r1,r3]
240    str r0, [r2,r3]
241    bgt .L_loop1
242
243.L_loop1_done:
244#endif
245
246/* This part of work usually is done in C library startup code. Otherwise,
247 * define __STARTUP_CLEAR_BSS to enable it in this startup. This section
248 * clears the RAM where BSS data is located.
249 *
250 * The BSS section is specified by following symbols
251 *    __bss_start__: start of the BSS section.
252 *    __bss_end__: end of the BSS section.
253 *
254 * All addresses must be aligned to 4 bytes boundary.
255 */
256#ifdef __STARTUP_CLEAR_BSS
257    ldr r1, =__bss_start__
258    ldr r2, =__bss_end__
259
260    movs r0, 0
261
262    subs r2, r2, r1
263    ble .L_loop3_done
264
265.L_loop3:
266    subs r2, r2, #4
267    str r0, [r1, r2]
268    bgt .L_loop3
269
270.L_loop3_done:
271#endif /* __STARTUP_CLEAR_BSS */
272
273/* Execute SystemInit function. */
274    bl SystemInit
275
276/* Call _start function provided by libraries.
277 * If those libraries are not accessible, define __START as your entry point.
278 */
279#ifndef __START
280#define __START _start
281#endif
282    bl __START
283
284    .pool
285    .size   Reset_Handler,.-Reset_Handler
286
287    .section ".text"
288
289
290/* Dummy Exception Handlers (infinite loops which can be modified) */
291
292    .weak   NMI_Handler
293    .type   NMI_Handler, %function
294NMI_Handler:
295    b       .
296    .size   NMI_Handler, . - NMI_Handler
297
298
299    .weak   HardFault_Handler
300    .type   HardFault_Handler, %function
301HardFault_Handler:
302    b       .
303    .size   HardFault_Handler, . - HardFault_Handler
304
305
306    .weak   MemoryManagement_Handler
307    .type   MemoryManagement_Handler, %function
308MemoryManagement_Handler:
309    b       .
310    .size   MemoryManagement_Handler, . - MemoryManagement_Handler
311
312
313    .weak   BusFault_Handler
314    .type   BusFault_Handler, %function
315BusFault_Handler:
316    b       .
317    .size   BusFault_Handler, . - BusFault_Handler
318
319
320    .weak   UsageFault_Handler
321    .type   UsageFault_Handler, %function
322UsageFault_Handler:
323    b       .
324    .size   UsageFault_Handler, . - UsageFault_Handler
325
326
327    .weak   SVC_Handler
328    .type   SVC_Handler, %function
329SVC_Handler:
330    b       .
331    .size   SVC_Handler, . - SVC_Handler
332
333
334    .weak   DebugMon_Handler
335    .type   DebugMon_Handler, %function
336DebugMon_Handler:
337    b       .
338    .size   DebugMon_Handler, . - DebugMon_Handler
339
340
341    .weak   PendSV_Handler
342    .type   PendSV_Handler, %function
343PendSV_Handler:
344    b       .
345    .size   PendSV_Handler, . - PendSV_Handler
346
347
348    .weak   SysTick_Handler
349    .type   SysTick_Handler, %function
350SysTick_Handler:
351    b       .
352    .size   SysTick_Handler, . - SysTick_Handler
353
354
355/* IRQ Handlers */
356
357    .globl  Default_Handler
358    .type   Default_Handler, %function
359Default_Handler:
360    b       .
361    .size   Default_Handler, . - Default_Handler
362
363    .macro  IRQ handler
364    .weak   \handler
365    .set    \handler, Default_Handler
366    .endm
367
368    IRQ  POWER_CLOCK_IRQHandler
369    IRQ  RADIO_IRQHandler
370    IRQ  UARTE0_UART0_IRQHandler
371    IRQ  TWIM0_TWIS0_TWI0_SPIM1_SPIS1_SPI1_IRQHandler
372    IRQ  SPIM0_SPIS0_SPI0_IRQHandler
373    IRQ  GPIOTE_IRQHandler
374    IRQ  SAADC_IRQHandler
375    IRQ  TIMER0_IRQHandler
376    IRQ  TIMER1_IRQHandler
377    IRQ  TIMER2_IRQHandler
378    IRQ  RTC0_IRQHandler
379    IRQ  TEMP_IRQHandler
380    IRQ  RNG_IRQHandler
381    IRQ  ECB_IRQHandler
382    IRQ  CCM_AAR_IRQHandler
383    IRQ  WDT_IRQHandler
384    IRQ  RTC1_IRQHandler
385    IRQ  QDEC_IRQHandler
386    IRQ  COMP_IRQHandler
387    IRQ  SWI0_EGU0_IRQHandler
388    IRQ  SWI1_EGU1_IRQHandler
389    IRQ  SWI2_IRQHandler
390    IRQ  SWI3_IRQHandler
391    IRQ  SWI4_IRQHandler
392    IRQ  SWI5_IRQHandler
393    IRQ  PWM0_IRQHandler
394    IRQ  PDM_IRQHandler
395
396  .end
397