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_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    /* Workaround for Errata 185 RAM: RAM corruption at extreme corners
220     * found at the Errata document for your device located
221     * at https://infocenter.nordicsemi.com/index.jsp */
222
223    LDR     R0, =0x10000130
224    LDR     R0, [R0]
225    LDR     R1, =0x10000134
226    LDR     R1, [R1]
227
228    CMP     R0, #0xA
229    BNE     skip
230    CMP     R1, #0x0
231    BNE     skip
232
233    LDR     R0, =0x40000EE4
234    LDR     R2, [R0]
235    LDR     R3, =0xFFFFFF8F
236    ANDS    R2, R2, R3
237    LDR     R3, =0x00000040
238    ORRS    R2, R2, R3
239    STR     R2, [R0]
240
241skip:
242
243/* Loop to copy data from read only memory to RAM.
244 * The ranges of copy from/to are specified by following symbols:
245 *      __etext: LMA of start of the section to copy from. Usually end of text
246 *      __data_start__: VMA of start of the section to copy to.
247 *      __bss_start__: VMA of end of the section to copy to. Normally __data_end__ is used, but by using __bss_start__
248 *                    the user can add their own initialized data section before BSS section with the INSERT AFTER command.
249 *
250 * All addresses must be aligned to 4 bytes boundary.
251 */
252#ifndef __STARTUP_SKIP_ETEXT
253    ldr r1, =__etext
254    ldr r2, =__data_start__
255    ldr r3, =__bss_start__
256
257    subs r3, r3, r2
258    ble .L_loop1_done
259
260.L_loop1:
261    subs r3, r3, #4
262    ldr r0, [r1,r3]
263    str r0, [r2,r3]
264    bgt .L_loop1
265
266.L_loop1_done:
267#endif
268
269/* This part of work usually is done in C library startup code. Otherwise,
270 * define __STARTUP_CLEAR_BSS to enable it in this startup. This section
271 * clears the RAM where BSS data is located.
272 *
273 * The BSS section is specified by following symbols
274 *    __bss_start__: start of the BSS section.
275 *    __bss_end__: end of the BSS section.
276 *
277 * All addresses must be aligned to 4 bytes boundary.
278 */
279#ifdef __STARTUP_CLEAR_BSS
280    ldr r1, =__bss_start__
281    ldr r2, =__bss_end__
282
283    movs r0, 0
284
285    subs r2, r2, r1
286    ble .L_loop3_done
287
288.L_loop3:
289    subs r2, r2, #4
290    str r0, [r1, r2]
291    bgt .L_loop3
292
293.L_loop3_done:
294#endif /* __STARTUP_CLEAR_BSS */
295
296/* Execute SystemInit function. */
297    bl SystemInit
298
299/* Call _start function provided by libraries.
300 * If those libraries are not accessible, define __START as your entry point.
301 */
302#ifndef __START
303#define __START _start
304#endif
305    bl __START
306
307    .pool
308    .size   Reset_Handler,.-Reset_Handler
309
310    .section ".text"
311
312
313/* Dummy Exception Handlers (infinite loops which can be modified) */
314
315    .weak   NMI_Handler
316    .type   NMI_Handler, %function
317NMI_Handler:
318    b       .
319    .size   NMI_Handler, . - NMI_Handler
320
321
322    .weak   HardFault_Handler
323    .type   HardFault_Handler, %function
324HardFault_Handler:
325    b       .
326    .size   HardFault_Handler, . - HardFault_Handler
327
328
329    .weak   MemoryManagement_Handler
330    .type   MemoryManagement_Handler, %function
331MemoryManagement_Handler:
332    b       .
333    .size   MemoryManagement_Handler, . - MemoryManagement_Handler
334
335
336    .weak   BusFault_Handler
337    .type   BusFault_Handler, %function
338BusFault_Handler:
339    b       .
340    .size   BusFault_Handler, . - BusFault_Handler
341
342
343    .weak   UsageFault_Handler
344    .type   UsageFault_Handler, %function
345UsageFault_Handler:
346    b       .
347    .size   UsageFault_Handler, . - UsageFault_Handler
348
349
350    .weak   SVC_Handler
351    .type   SVC_Handler, %function
352SVC_Handler:
353    b       .
354    .size   SVC_Handler, . - SVC_Handler
355
356
357    .weak   DebugMon_Handler
358    .type   DebugMon_Handler, %function
359DebugMon_Handler:
360    b       .
361    .size   DebugMon_Handler, . - DebugMon_Handler
362
363
364    .weak   PendSV_Handler
365    .type   PendSV_Handler, %function
366PendSV_Handler:
367    b       .
368    .size   PendSV_Handler, . - PendSV_Handler
369
370
371    .weak   SysTick_Handler
372    .type   SysTick_Handler, %function
373SysTick_Handler:
374    b       .
375    .size   SysTick_Handler, . - SysTick_Handler
376
377
378/* IRQ Handlers */
379
380    .globl  Default_Handler
381    .type   Default_Handler, %function
382Default_Handler:
383    b       .
384    .size   Default_Handler, . - Default_Handler
385
386    .macro  IRQ handler
387    .weak   \handler
388    .set    \handler, Default_Handler
389    .endm
390
391    IRQ  POWER_CLOCK_IRQHandler
392    IRQ  RADIO_IRQHandler
393    IRQ  UARTE0_UART0_IRQHandler
394    IRQ  TWIM0_TWIS0_TWI0_IRQHandler
395    IRQ  SPIM0_SPIS0_SPI0_IRQHandler
396    IRQ  GPIOTE_IRQHandler
397    IRQ  SAADC_IRQHandler
398    IRQ  TIMER0_IRQHandler
399    IRQ  TIMER1_IRQHandler
400    IRQ  TIMER2_IRQHandler
401    IRQ  RTC0_IRQHandler
402    IRQ  TEMP_IRQHandler
403    IRQ  RNG_IRQHandler
404    IRQ  ECB_IRQHandler
405    IRQ  CCM_AAR_IRQHandler
406    IRQ  WDT_IRQHandler
407    IRQ  RTC1_IRQHandler
408    IRQ  QDEC_IRQHandler
409    IRQ  COMP_IRQHandler
410    IRQ  SWI0_EGU0_IRQHandler
411    IRQ  SWI1_EGU1_IRQHandler
412    IRQ  SWI2_IRQHandler
413    IRQ  SWI3_IRQHandler
414    IRQ  SWI4_IRQHandler
415    IRQ  SWI5_IRQHandler
416    IRQ  PWM0_IRQHandler
417    IRQ  PDM_IRQHandler
418
419  .end
420