gcc_startup_nrf51.S 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*
  2. Copyright (c) 2009-2018 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 armv6-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, 2048
  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, 2048
  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
  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 0 /*Reserved */
  68. .long 0 /*Reserved */
  69. .long 0 /*Reserved */
  70. .long 0 /*Reserved */
  71. .long 0 /*Reserved */
  72. .long 0 /*Reserved */
  73. .long 0 /*Reserved */
  74. .long SVC_Handler
  75. .long 0 /*Reserved */
  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 UART0_IRQHandler
  83. .long SPI0_TWI0_IRQHandler
  84. .long SPI1_TWI1_IRQHandler
  85. .long 0 /*Reserved */
  86. .long GPIOTE_IRQHandler
  87. .long ADC_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 LPCOMP_IRQHandler
  100. .long SWI0_IRQHandler
  101. .long SWI1_IRQHandler
  102. .long SWI2_IRQHandler
  103. .long SWI3_IRQHandler
  104. .long SWI4_IRQHandler
  105. .long SWI5_IRQHandler
  106. .long 0 /*Reserved */
  107. .long 0 /*Reserved */
  108. .long 0 /*Reserved */
  109. .long 0 /*Reserved */
  110. .long 0 /*Reserved */
  111. .long 0 /*Reserved */
  112. .size __isr_vector, . - __isr_vector
  113. /* Reset Handler */
  114. .equ NRF_POWER_RAMON_ADDRESS, 0x40000524
  115. .equ NRF_POWER_RAMONB_ADDRESS, 0x40000554
  116. .equ NRF_POWER_RAMONx_RAMxON_ONMODE_Msk, 0x3
  117. .text
  118. .thumb
  119. .thumb_func
  120. .align 1
  121. .globl Reset_Handler
  122. .type Reset_Handler, %function
  123. Reset_Handler:
  124. MOVS R1, #NRF_POWER_RAMONx_RAMxON_ONMODE_Msk
  125. LDR R0, =NRF_POWER_RAMON_ADDRESS
  126. LDR R2, [R0]
  127. ORRS R2, R1
  128. STR R2, [R0]
  129. LDR R0, =NRF_POWER_RAMONB_ADDRESS
  130. LDR R2, [R0]
  131. ORRS R2, R1
  132. STR R2, [R0]
  133. /* Loop to copy data from read only memory to RAM.
  134. * The ranges of copy from/to are specified by following symbols:
  135. * __etext: LMA of start of the section to copy from. Usually end of text
  136. * __data_start__: VMA of start of the section to copy to.
  137. * __bss_start__: VMA of end of the section to copy to. Normally __data_end__ is used, but by using __bss_start__
  138. * the user can add their own initialized data section before BSS section with the INTERT AFTER command.
  139. *
  140. * All addresses must be aligned to 4 bytes boundary.
  141. */
  142. ldr r1, =__etext
  143. ldr r2, =__data_start__
  144. ldr r3, =__bss_start__
  145. subs r3, r3, r2
  146. ble .L_loop1_done
  147. .L_loop1:
  148. subs r3, r3, #4
  149. ldr r0, [r1,r3]
  150. str r0, [r2,r3]
  151. bgt .L_loop1
  152. .L_loop1_done:
  153. /* This part of work usually is done in C library startup code. Otherwise,
  154. * define __STARTUP_CLEAR_BSS to enable it in this startup. This section
  155. * clears the RAM where BSS data is located.
  156. *
  157. * The BSS section is specified by following symbols
  158. * __bss_start__: start of the BSS section.
  159. * __bss_end__: end of the BSS section.
  160. *
  161. * All addresses must be aligned to 4 bytes boundary.
  162. */
  163. #ifdef __STARTUP_CLEAR_BSS
  164. ldr r1, =__bss_start__
  165. ldr r2, =__bss_end__
  166. movs r0, 0
  167. subs r2, r2, r1
  168. ble .L_loop3_done
  169. .L_loop3:
  170. subs r2, r2, #4
  171. str r0, [r1, r2]
  172. bgt .L_loop3
  173. .L_loop3_done:
  174. #endif /* __STARTUP_CLEAR_BSS */
  175. /* Execute SystemInit function. */
  176. bl SystemInit
  177. /* Call _start function provided by libraries.
  178. * If those libraries are not accessible, define __START as your entry point.
  179. */
  180. #ifndef __START
  181. #define __START _start
  182. #endif
  183. bl __START
  184. .pool
  185. .size Reset_Handler,.-Reset_Handler
  186. .section ".text"
  187. /* Dummy Exception Handlers (infinite loops which can be modified) */
  188. .weak NMI_Handler
  189. .type NMI_Handler, %function
  190. NMI_Handler:
  191. b .
  192. .size NMI_Handler, . - NMI_Handler
  193. .weak HardFault_Handler
  194. .type HardFault_Handler, %function
  195. HardFault_Handler:
  196. b .
  197. .size HardFault_Handler, . - HardFault_Handler
  198. .weak SVC_Handler
  199. .type SVC_Handler, %function
  200. SVC_Handler:
  201. b .
  202. .size SVC_Handler, . - SVC_Handler
  203. .weak PendSV_Handler
  204. .type PendSV_Handler, %function
  205. PendSV_Handler:
  206. b .
  207. .size PendSV_Handler, . - PendSV_Handler
  208. .weak SysTick_Handler
  209. .type SysTick_Handler, %function
  210. SysTick_Handler:
  211. b .
  212. .size SysTick_Handler, . - SysTick_Handler
  213. /* IRQ Handlers */
  214. .globl Default_Handler
  215. .type Default_Handler, %function
  216. Default_Handler:
  217. b .
  218. .size Default_Handler, . - Default_Handler
  219. .macro IRQ handler
  220. .weak \handler
  221. .set \handler, Default_Handler
  222. .endm
  223. IRQ POWER_CLOCK_IRQHandler
  224. IRQ RADIO_IRQHandler
  225. IRQ UART0_IRQHandler
  226. IRQ SPI0_TWI0_IRQHandler
  227. IRQ SPI1_TWI1_IRQHandler
  228. IRQ GPIOTE_IRQHandler
  229. IRQ ADC_IRQHandler
  230. IRQ TIMER0_IRQHandler
  231. IRQ TIMER1_IRQHandler
  232. IRQ TIMER2_IRQHandler
  233. IRQ RTC0_IRQHandler
  234. IRQ TEMP_IRQHandler
  235. IRQ RNG_IRQHandler
  236. IRQ ECB_IRQHandler
  237. IRQ CCM_AAR_IRQHandler
  238. IRQ WDT_IRQHandler
  239. IRQ RTC1_IRQHandler
  240. IRQ QDEC_IRQHandler
  241. IRQ LPCOMP_IRQHandler
  242. IRQ SWI0_IRQHandler
  243. IRQ SWI1_IRQHandler
  244. IRQ SWI2_IRQHandler
  245. IRQ SWI3_IRQHandler
  246. IRQ SWI4_IRQHandler
  247. IRQ SWI5_IRQHandler
  248. .end