gcc_startup_nrf52840.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /*
  2. Copyright (c) 2009-2020 ARM Limited. All rights reserved.
  3. SPDX-License-Identifier: Apache-2.0
  4. Licensed under the Apache License, Version 2.0 (the License); you may
  5. not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an AS IS BASIS, WITHOUT
  10. WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. NOTICE: This file has been modified by Nordic Semiconductor ASA.
  14. */
  15. .syntax unified
  16. .arch armv7e-m
  17. #ifdef __STARTUP_CONFIG
  18. #include "startup_config.h"
  19. #ifndef __STARTUP_CONFIG_STACK_ALIGNEMENT
  20. #define __STARTUP_CONFIG_STACK_ALIGNEMENT 3
  21. #endif
  22. #endif
  23. .section .stack
  24. #if defined(__STARTUP_CONFIG)
  25. .align __STARTUP_CONFIG_STACK_ALIGNEMENT
  26. .equ Stack_Size, __STARTUP_CONFIG_STACK_SIZE
  27. #elif defined(__STACK_SIZE)
  28. .align 3
  29. .equ Stack_Size, __STACK_SIZE
  30. #else
  31. .align 3
  32. .equ Stack_Size, 16384
  33. #endif
  34. .globl __StackTop
  35. .globl __StackLimit
  36. __StackLimit:
  37. .space Stack_Size
  38. .size __StackLimit, . - __StackLimit
  39. __StackTop:
  40. .size __StackTop, . - __StackTop
  41. .section .heap
  42. .align 3
  43. #if defined(__STARTUP_CONFIG)
  44. .equ Heap_Size, __STARTUP_CONFIG_HEAP_SIZE
  45. #elif defined(__HEAP_SIZE)
  46. .equ Heap_Size, __HEAP_SIZE
  47. #else
  48. .equ Heap_Size, 16384
  49. #endif
  50. .globl __HeapBase
  51. .globl __HeapLimit
  52. __HeapBase:
  53. .if Heap_Size
  54. .space Heap_Size
  55. .endif
  56. .size __HeapBase, . - __HeapBase
  57. __HeapLimit:
  58. .size __HeapLimit, . - __HeapLimit
  59. .section .isr_vector, "ax"
  60. .align 2
  61. .globl __isr_vector
  62. __isr_vector:
  63. .long __StackTop /* Top of Stack */
  64. .long Reset_Handler
  65. .long NMI_Handler
  66. .long HardFault_Handler
  67. .long MemoryManagement_Handler
  68. .long BusFault_Handler
  69. .long UsageFault_Handler
  70. .long 0 /*Reserved */
  71. .long 0 /*Reserved */
  72. .long 0 /*Reserved */
  73. .long 0 /*Reserved */
  74. .long SVC_Handler
  75. .long DebugMon_Handler
  76. .long 0 /*Reserved */
  77. .long PendSV_Handler
  78. .long SysTick_Handler
  79. /* External Interrupts */
  80. .long POWER_CLOCK_IRQHandler
  81. .long RADIO_IRQHandler
  82. .long UARTE0_UART0_IRQHandler
  83. .long SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler
  84. .long SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler
  85. .long NFCT_IRQHandler
  86. .long GPIOTE_IRQHandler
  87. .long SAADC_IRQHandler
  88. .long TIMER0_IRQHandler
  89. .long TIMER1_IRQHandler
  90. .long TIMER2_IRQHandler
  91. .long RTC0_IRQHandler
  92. .long TEMP_IRQHandler
  93. .long RNG_IRQHandler
  94. .long ECB_IRQHandler
  95. .long CCM_AAR_IRQHandler
  96. .long WDT_IRQHandler
  97. .long RTC1_IRQHandler
  98. .long QDEC_IRQHandler
  99. .long COMP_LPCOMP_IRQHandler
  100. .long SWI0_EGU0_IRQHandler
  101. .long SWI1_EGU1_IRQHandler
  102. .long SWI2_EGU2_IRQHandler
  103. .long SWI3_EGU3_IRQHandler
  104. .long SWI4_EGU4_IRQHandler
  105. .long SWI5_EGU5_IRQHandler
  106. .long TIMER3_IRQHandler
  107. .long TIMER4_IRQHandler
  108. .long PWM0_IRQHandler
  109. .long PDM_IRQHandler
  110. .long 0 /*Reserved */
  111. .long 0 /*Reserved */
  112. .long MWU_IRQHandler
  113. .long PWM1_IRQHandler
  114. .long PWM2_IRQHandler
  115. .long SPIM2_SPIS2_SPI2_IRQHandler
  116. .long RTC2_IRQHandler
  117. .long I2S_IRQHandler
  118. .long FPU_IRQHandler
  119. .long USBD_IRQHandler
  120. .long UARTE1_IRQHandler
  121. .long QSPI_IRQHandler
  122. .long CRYPTOCELL_IRQHandler
  123. .long 0 /*Reserved */
  124. .long 0 /*Reserved */
  125. .long PWM3_IRQHandler
  126. .long 0 /*Reserved */
  127. .long SPIM3_IRQHandler
  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. .size __isr_vector, . - __isr_vector
  193. /* Reset Handler */
  194. .text
  195. .thumb
  196. .thumb_func
  197. .align 1
  198. .globl Reset_Handler
  199. .type Reset_Handler, %function
  200. Reset_Handler:
  201. /* Loop to copy data from read only memory to RAM.
  202. * The ranges of copy from/to are specified by following symbols:
  203. * __etext: LMA of start of the section to copy from. Usually end of text
  204. * __data_start__: VMA of start of the section to copy to.
  205. * __bss_start__: VMA of end of the section to copy to. Normally __data_end__ is used, but by using __bss_start__
  206. * the user can add their own initialized data section before BSS section with the INSERT AFTER command.
  207. *
  208. * All addresses must be aligned to 4 bytes boundary.
  209. */
  210. #ifndef __STARTUP_SKIP_ETEXT
  211. ldr r1, =__etext
  212. ldr r2, =__data_start__
  213. ldr r3, =__bss_start__
  214. subs r3, r3, r2
  215. ble .L_loop1_done
  216. .L_loop1:
  217. subs r3, r3, #4
  218. ldr r0, [r1,r3]
  219. str r0, [r2,r3]
  220. bgt .L_loop1
  221. .L_loop1_done:
  222. #endif
  223. /* This part of work usually is done in C library startup code. Otherwise,
  224. * define __STARTUP_CLEAR_BSS to enable it in this startup. This section
  225. * clears the RAM where BSS data is located.
  226. *
  227. * The BSS section is specified by following symbols
  228. * __bss_start__: start of the BSS section.
  229. * __bss_end__: end of the BSS section.
  230. *
  231. * All addresses must be aligned to 4 bytes boundary.
  232. */
  233. #ifdef __STARTUP_CLEAR_BSS
  234. ldr r1, =__bss_start__
  235. ldr r2, =__bss_end__
  236. movs r0, 0
  237. subs r2, r2, r1
  238. ble .L_loop3_done
  239. .L_loop3:
  240. subs r2, r2, #4
  241. str r0, [r1, r2]
  242. bgt .L_loop3
  243. .L_loop3_done:
  244. #endif /* __STARTUP_CLEAR_BSS */
  245. /* Execute SystemInit function. */
  246. bl SystemInit
  247. /* Call _start function provided by libraries.
  248. * If those libraries are not accessible, define __START as your entry point.
  249. */
  250. #ifndef __START
  251. #define __START _start
  252. #endif
  253. bl __START
  254. .pool
  255. .size Reset_Handler,.-Reset_Handler
  256. .section ".text"
  257. /* Dummy Exception Handlers (infinite loops which can be modified) */
  258. .weak NMI_Handler
  259. .type NMI_Handler, %function
  260. NMI_Handler:
  261. b .
  262. .size NMI_Handler, . - NMI_Handler
  263. .weak HardFault_Handler
  264. .type HardFault_Handler, %function
  265. HardFault_Handler:
  266. b .
  267. .size HardFault_Handler, . - HardFault_Handler
  268. .weak MemoryManagement_Handler
  269. .type MemoryManagement_Handler, %function
  270. MemoryManagement_Handler:
  271. b .
  272. .size MemoryManagement_Handler, . - MemoryManagement_Handler
  273. .weak BusFault_Handler
  274. .type BusFault_Handler, %function
  275. BusFault_Handler:
  276. b .
  277. .size BusFault_Handler, . - BusFault_Handler
  278. .weak UsageFault_Handler
  279. .type UsageFault_Handler, %function
  280. UsageFault_Handler:
  281. b .
  282. .size UsageFault_Handler, . - UsageFault_Handler
  283. .weak SVC_Handler
  284. .type SVC_Handler, %function
  285. SVC_Handler:
  286. b .
  287. .size SVC_Handler, . - SVC_Handler
  288. .weak DebugMon_Handler
  289. .type DebugMon_Handler, %function
  290. DebugMon_Handler:
  291. b .
  292. .size DebugMon_Handler, . - DebugMon_Handler
  293. .weak PendSV_Handler
  294. .type PendSV_Handler, %function
  295. PendSV_Handler:
  296. b .
  297. .size PendSV_Handler, . - PendSV_Handler
  298. .weak SysTick_Handler
  299. .type SysTick_Handler, %function
  300. SysTick_Handler:
  301. b .
  302. .size SysTick_Handler, . - SysTick_Handler
  303. /* IRQ Handlers */
  304. .globl Default_Handler
  305. .type Default_Handler, %function
  306. Default_Handler:
  307. b .
  308. .size Default_Handler, . - Default_Handler
  309. .macro IRQ handler
  310. .weak \handler
  311. .set \handler, Default_Handler
  312. .endm
  313. IRQ POWER_CLOCK_IRQHandler
  314. IRQ RADIO_IRQHandler
  315. IRQ UARTE0_UART0_IRQHandler
  316. IRQ SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler
  317. IRQ SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler
  318. IRQ NFCT_IRQHandler
  319. IRQ GPIOTE_IRQHandler
  320. IRQ SAADC_IRQHandler
  321. IRQ TIMER0_IRQHandler
  322. IRQ TIMER1_IRQHandler
  323. IRQ TIMER2_IRQHandler
  324. IRQ RTC0_IRQHandler
  325. IRQ TEMP_IRQHandler
  326. IRQ RNG_IRQHandler
  327. IRQ ECB_IRQHandler
  328. IRQ CCM_AAR_IRQHandler
  329. IRQ WDT_IRQHandler
  330. IRQ RTC1_IRQHandler
  331. IRQ QDEC_IRQHandler
  332. IRQ COMP_LPCOMP_IRQHandler
  333. IRQ SWI0_EGU0_IRQHandler
  334. IRQ SWI1_EGU1_IRQHandler
  335. IRQ SWI2_EGU2_IRQHandler
  336. IRQ SWI3_EGU3_IRQHandler
  337. IRQ SWI4_EGU4_IRQHandler
  338. IRQ SWI5_EGU5_IRQHandler
  339. IRQ TIMER3_IRQHandler
  340. IRQ TIMER4_IRQHandler
  341. IRQ PWM0_IRQHandler
  342. IRQ PDM_IRQHandler
  343. IRQ MWU_IRQHandler
  344. IRQ PWM1_IRQHandler
  345. IRQ PWM2_IRQHandler
  346. IRQ SPIM2_SPIS2_SPI2_IRQHandler
  347. IRQ RTC2_IRQHandler
  348. IRQ I2S_IRQHandler
  349. IRQ FPU_IRQHandler
  350. IRQ USBD_IRQHandler
  351. IRQ UARTE1_IRQHandler
  352. IRQ QSPI_IRQHandler
  353. IRQ CRYPTOCELL_IRQHandler
  354. IRQ PWM3_IRQHandler
  355. IRQ SPIM3_IRQHandler
  356. .end