gcc_startup_nrf51.s 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /* Copyright (c) 2013 ARM LIMITED
  2. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions are met:
  5. - Redistributions of source code must retain the above copyright
  6. notice, this list of conditions and the following disclaimer.
  7. - Redistributions in binary form must reproduce the above copyright
  8. notice, this list of conditions and the following disclaimer in the
  9. documentation and/or other materials provided with the distribution.
  10. - Neither the name of ARM nor the names of its contributors may be used
  11. to endorse or promote products derived from this software without
  12. specific prior written permission.
  13. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  14. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  16. ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
  17. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23. POSSIBILITY OF SUCH DAMAGE.
  24. ---------------------------------------------------------------------------*/
  25. .syntax unified
  26. .arch armv6-m
  27. .section .stack
  28. .align 3
  29. #ifdef __STACK_SIZE
  30. .equ Stack_Size, __STACK_SIZE
  31. #else
  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. #ifdef __HEAP_SIZE
  44. .equ Heap_Size, __HEAP_SIZE
  45. #else
  46. .equ Heap_Size, 2048
  47. #endif
  48. .globl __HeapBase
  49. .globl __HeapLimit
  50. __HeapBase:
  51. .if Heap_Size
  52. .space Heap_Size
  53. .endif
  54. .size __HeapBase, . - __HeapBase
  55. __HeapLimit:
  56. .size __HeapLimit, . - __HeapLimit
  57. .section .isr_vector
  58. .align 2
  59. .globl __isr_vector
  60. __isr_vector:
  61. .long __StackTop /* Top of Stack */
  62. .long Reset_Handler
  63. .long NMI_Handler
  64. .long HardFault_Handler
  65. .long 0 /*Reserved */
  66. .long 0 /*Reserved */
  67. .long 0 /*Reserved */
  68. .long 0 /*Reserved */
  69. .long 0 /*Reserved */
  70. .long 0 /*Reserved */
  71. .long 0 /*Reserved */
  72. .long SVC_Handler
  73. .long 0 /*Reserved */
  74. .long 0 /*Reserved */
  75. .long PendSV_Handler
  76. .long SysTick_Handler
  77. /* External Interrupts */
  78. .long POWER_CLOCK_IRQHandler
  79. .long RADIO_IRQHandler
  80. .long UART0_IRQHandler
  81. .long SPI0_TWI0_IRQHandler
  82. .long SPI1_TWI1_IRQHandler
  83. .long 0 /*Reserved */
  84. .long GPIOTE_IRQHandler
  85. .long ADC_IRQHandler
  86. .long TIMER0_IRQHandler
  87. .long TIMER1_IRQHandler
  88. .long TIMER2_IRQHandler
  89. .long RTC0_IRQHandler
  90. .long TEMP_IRQHandler
  91. .long RNG_IRQHandler
  92. .long ECB_IRQHandler
  93. .long CCM_AAR_IRQHandler
  94. .long WDT_IRQHandler
  95. .long RTC1_IRQHandler
  96. .long QDEC_IRQHandler
  97. .long LPCOMP_IRQHandler
  98. .long SWI0_IRQHandler
  99. .long SWI1_IRQHandler
  100. .long SWI2_IRQHandler
  101. .long SWI3_IRQHandler
  102. .long SWI4_IRQHandler
  103. .long SWI5_IRQHandler
  104. .long 0 /*Reserved */
  105. .long 0 /*Reserved */
  106. .long 0 /*Reserved */
  107. .long 0 /*Reserved */
  108. .long 0 /*Reserved */
  109. .long 0 /*Reserved */
  110. .size __isr_vector, . - __isr_vector
  111. /* Reset Handler */
  112. .equ NRF_POWER_RAMON_ADDRESS, 0x40000524
  113. .equ NRF_POWER_RAMONB_ADDRESS, 0x40000554
  114. .equ NRF_POWER_RAMONx_RAMxON_ONMODE_Msk, 0x3
  115. .text
  116. .thumb
  117. .thumb_func
  118. .align 1
  119. .globl Reset_Handler
  120. .type Reset_Handler, %function
  121. Reset_Handler:
  122. MOVS R1, #NRF_POWER_RAMONx_RAMxON_ONMODE_Msk
  123. LDR R0, =NRF_POWER_RAMON_ADDRESS
  124. LDR R2, [R0]
  125. ORRS R2, R1
  126. STR R2, [R0]
  127. LDR R0, =NRF_POWER_RAMONB_ADDRESS
  128. LDR R2, [R0]
  129. ORRS R2, R1
  130. STR R2, [R0]
  131. /* Loop to copy data from read only memory to RAM.
  132. * The ranges of copy from/to are specified by following symbols:
  133. * __etext: LMA of start of the section to copy from. Usually end of text
  134. * __data_start__: VMA of start of the section to copy to.
  135. * __bss_start__: VMA of end of the section to copy to. Normally __data_end__ is used, but by using __bss_start__
  136. * the user can add their own initialized data section before BSS section with the INTERT AFTER command.
  137. *
  138. * All addresses must be aligned to 4 bytes boundary.
  139. */
  140. ldr r1, =__etext
  141. ldr r2, =__data_start__
  142. ldr r3, =__bss_start__
  143. subs r3, r2
  144. ble .L_loop1_done
  145. .L_loop1:
  146. subs r3, #4
  147. ldr r0, [r1,r3]
  148. str r0, [r2,r3]
  149. bgt .L_loop1
  150. .L_loop1_done:
  151. /* This part of work usually is done in C library startup code. Otherwise,
  152. * define __STARTUP_CLEAR_BSS to enable it in this startup. This section
  153. * clears the RAM where BSS data is located.
  154. *
  155. * The BSS section is specified by following symbols
  156. * __bss_start__: start of the BSS section.
  157. * __bss_end__: end of the BSS section.
  158. *
  159. * All addresses must be aligned to 4 bytes boundary.
  160. */
  161. #ifdef __STARTUP_CLEAR_BSS
  162. ldr r1, =__bss_start__
  163. ldr r2, =__bss_end__
  164. movs r0, 0
  165. subs r2, r1
  166. ble .L_loop3_done
  167. .L_loop3:
  168. subs r2, #4
  169. str r0, [r1, r2]
  170. bgt .L_loop3
  171. .L_loop3_done:
  172. #endif /* __STARTUP_CLEAR_BSS */
  173. /* Execute SystemInit function. */
  174. bl SystemInit
  175. /* Call _start function provided by libraries.
  176. * If those libraries are not accessible, define __START as your entry point.
  177. */
  178. #ifndef __START
  179. #define __START _start
  180. #endif
  181. bl __START
  182. .pool
  183. .size Reset_Handler,.-Reset_Handler
  184. .section ".text"
  185. /* Dummy Exception Handlers (infinite loops which can be modified) */
  186. .weak NMI_Handler
  187. .type NMI_Handler, %function
  188. NMI_Handler:
  189. b .
  190. .size NMI_Handler, . - NMI_Handler
  191. .weak HardFault_Handler
  192. .type HardFault_Handler, %function
  193. HardFault_Handler:
  194. b .
  195. .size HardFault_Handler, . - HardFault_Handler
  196. .weak SVC_Handler
  197. .type SVC_Handler, %function
  198. SVC_Handler:
  199. b .
  200. .size SVC_Handler, . - SVC_Handler
  201. .weak PendSV_Handler
  202. .type PendSV_Handler, %function
  203. PendSV_Handler:
  204. b .
  205. .size PendSV_Handler, . - PendSV_Handler
  206. .weak SysTick_Handler
  207. .type SysTick_Handler, %function
  208. SysTick_Handler:
  209. b .
  210. .size SysTick_Handler, . - SysTick_Handler
  211. /* IRQ Handlers */
  212. .globl Default_Handler
  213. .type Default_Handler, %function
  214. Default_Handler:
  215. b .
  216. .size Default_Handler, . - Default_Handler
  217. .macro IRQ handler
  218. .weak \handler
  219. .set \handler, Default_Handler
  220. .endm
  221. IRQ POWER_CLOCK_IRQHandler
  222. IRQ RADIO_IRQHandler
  223. IRQ UART0_IRQHandler
  224. IRQ SPI0_TWI0_IRQHandler
  225. IRQ SPI1_TWI1_IRQHandler
  226. IRQ GPIOTE_IRQHandler
  227. IRQ ADC_IRQHandler
  228. IRQ TIMER0_IRQHandler
  229. IRQ TIMER1_IRQHandler
  230. IRQ TIMER2_IRQHandler
  231. IRQ RTC0_IRQHandler
  232. IRQ TEMP_IRQHandler
  233. IRQ RNG_IRQHandler
  234. IRQ ECB_IRQHandler
  235. IRQ CCM_AAR_IRQHandler
  236. IRQ WDT_IRQHandler
  237. IRQ RTC1_IRQHandler
  238. IRQ QDEC_IRQHandler
  239. IRQ LPCOMP_IRQHandler
  240. IRQ SWI0_IRQHandler
  241. IRQ SWI1_IRQHandler
  242. IRQ SWI2_IRQHandler
  243. IRQ SWI3_IRQHandler
  244. IRQ SWI4_IRQHandler
  245. IRQ SWI5_IRQHandler
  246. .end