You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /* File: startup_ARMCM4.S
  2. * Purpose: startup file for Cortex-M4 devices. Should use with
  3. * GCC for ARM Embedded Processors
  4. * Version: V2.0
  5. * Date: 16 August 2013
  6. *
  7. /* Copyright (c) 2011 - 2013 ARM LIMITED
  8. All rights reserved.
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions are met:
  11. - Redistributions of source code must retain the above copyright
  12. notice, this list of conditions and the following disclaimer.
  13. - Redistributions in binary form must reproduce the above copyright
  14. notice, this list of conditions and the following disclaimer in the
  15. documentation and/or other materials provided with the distribution.
  16. - Neither the name of ARM nor the names of its contributors may be used
  17. to endorse or promote products derived from this software without
  18. specific prior written permission.
  19. *
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
  24. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30. POSSIBILITY OF SUCH DAMAGE.
  31. ---------------------------------------------------------------------------*/
  32. .syntax unified
  33. .arch armv7e-m
  34. .section .stack
  35. .align 3
  36. #ifdef __STACK_SIZE
  37. .equ Stack_Size, __STACK_SIZE
  38. #else
  39. .equ Stack_Size, 0xc00
  40. #endif
  41. .globl __StackTop
  42. .globl __StackLimit
  43. __StackLimit:
  44. .space Stack_Size
  45. .size __StackLimit, . - __StackLimit
  46. __StackTop:
  47. .size __StackTop, . - __StackTop
  48. .section .heap
  49. .align 3
  50. #ifdef __HEAP_SIZE
  51. .equ Heap_Size, __HEAP_SIZE
  52. #else
  53. .equ Heap_Size, 0
  54. #endif
  55. .globl __HeapBase
  56. .globl __HeapLimit
  57. __HeapBase:
  58. .if Heap_Size
  59. .space Heap_Size
  60. .endif
  61. .size __HeapBase, . - __HeapBase
  62. __HeapLimit:
  63. .size __HeapLimit, . - __HeapLimit
  64. .section .isr_vector
  65. .align 2
  66. .globl __isr_vector
  67. __isr_vector:
  68. .long __StackTop /* Top of Stack */
  69. .long Reset_Handler /* Reset Handler */
  70. .long NMI_Handler /* NMI Handler */
  71. .long HardFault_Handler /* Hard Fault Handler */
  72. .long MemManage_Handler /* MPU Fault Handler */
  73. .long BusFault_Handler /* Bus Fault Handler */
  74. .long UsageFault_Handler /* Usage Fault Handler */
  75. .long 0 /* Reserved */
  76. .long 0 /* Reserved */
  77. .long 0 /* Reserved */
  78. .long 0 /* Reserved */
  79. .long SVC_Handler /* SVCall Handler */
  80. .long DebugMon_Handler /* Debug Monitor Handler */
  81. .long 0 /* Reserved */
  82. .long PendSV_Handler /* PendSV Handler */
  83. .long SysTick_Handler /* SysTick Handler */
  84. /* External interrupts */
  85. .long Default_Handler
  86. .size __isr_vector, . - __isr_vector
  87. .text
  88. .thumb
  89. .thumb_func
  90. .align 2
  91. .globl Reset_Handler
  92. .type Reset_Handler, %function
  93. Reset_Handler:
  94. /* Firstly it copies data from read only memory to RAM. There are two schemes
  95. * to copy. One can copy more than one sections. Another can only copy
  96. * one section. The former scheme needs more instructions and read-only
  97. * data to implement than the latter.
  98. * Macro __STARTUP_COPY_MULTIPLE is used to choose between two schemes. */
  99. #ifdef __STARTUP_COPY_MULTIPLE
  100. /* Multiple sections scheme.
  101. *
  102. * Between symbol address __copy_table_start__ and __copy_table_end__,
  103. * there are array of triplets, each of which specify:
  104. * offset 0: LMA of start of a section to copy from
  105. * offset 4: VMA of start of a section to copy to
  106. * offset 8: size of the section to copy. Must be multiply of 4
  107. *
  108. * All addresses must be aligned to 4 bytes boundary.
  109. */
  110. ldr r4, =__copy_table_start__
  111. ldr r5, =__copy_table_end__
  112. .L_loop0:
  113. cmp r4, r5
  114. bge .L_loop0_done
  115. ldr r1, [r4]
  116. ldr r2, [r4, #4]
  117. ldr r3, [r4, #8]
  118. .L_loop0_0:
  119. subs r3, #4
  120. ittt ge
  121. ldrge r0, [r1, r3]
  122. strge r0, [r2, r3]
  123. bge .L_loop0_0
  124. adds r4, #12
  125. b .L_loop0
  126. .L_loop0_done:
  127. #else
  128. /* Single section scheme.
  129. *
  130. * The ranges of copy from/to are specified by following symbols
  131. * __etext: LMA of start of the section to copy from. Usually end of text
  132. * __data_start__: VMA of start of the section to copy to
  133. * __data_end__: VMA of end of the section to copy to
  134. *
  135. * All addresses must be aligned to 4 bytes boundary.
  136. */
  137. ldr r1, =__etext
  138. ldr r2, =__data_start__
  139. ldr r3, =__data_end__
  140. .L_loop1:
  141. cmp r2, r3
  142. ittt lt
  143. ldrlt r0, [r1], #4
  144. strlt r0, [r2], #4
  145. blt .L_loop1
  146. #endif /*__STARTUP_COPY_MULTIPLE */
  147. /* This part of work usually is done in C library startup code. Otherwise,
  148. * define this macro to enable it in this startup.
  149. *
  150. * There are two schemes too. One can clear multiple BSS sections. Another
  151. * can only clear one section. The former is more size expensive than the
  152. * latter.
  153. *
  154. * Define macro __STARTUP_CLEAR_BSS_MULTIPLE to choose the former.
  155. * Otherwise efine macro __STARTUP_CLEAR_BSS to choose the later.
  156. */
  157. #ifdef __STARTUP_CLEAR_BSS_MULTIPLE
  158. /* Multiple sections scheme.
  159. *
  160. * Between symbol address __copy_table_start__ and __copy_table_end__,
  161. * there are array of tuples specifying:
  162. * offset 0: Start of a BSS section
  163. * offset 4: Size of this BSS section. Must be multiply of 4
  164. */
  165. ldr r3, =__zero_table_start__
  166. ldr r4, =__zero_table_end__
  167. .L_loop2:
  168. cmp r3, r4
  169. bge .L_loop2_done
  170. ldr r1, [r3]
  171. ldr r2, [r3, #4]
  172. movs r0, 0
  173. .L_loop2_0:
  174. subs r2, #4
  175. itt ge
  176. strge r0, [r1, r2]
  177. bge .L_loop2_0
  178. adds r3, #8
  179. b .L_loop2
  180. .L_loop2_done:
  181. #elif defined (__STARTUP_CLEAR_BSS)
  182. /* Single BSS section scheme.
  183. *
  184. * The BSS section is specified by following symbols
  185. * __bss_start__: start of the BSS section.
  186. * __bss_end__: end of the BSS section.
  187. *
  188. * Both addresses must be aligned to 4 bytes boundary.
  189. */
  190. ldr r1, =__bss_start__
  191. ldr r2, =__bss_end__
  192. movs r0, 0
  193. .L_loop3:
  194. cmp r1, r2
  195. itt lt
  196. strlt r0, [r1], #4
  197. blt .L_loop3
  198. #endif /* __STARTUP_CLEAR_BSS_MULTIPLE || __STARTUP_CLEAR_BSS */
  199. #ifndef __NO_SYSTEM_INIT
  200. bl SystemInit
  201. #endif
  202. #ifndef __START
  203. #define __START _start
  204. #endif
  205. bl __START
  206. .pool
  207. .size Reset_Handler, . - Reset_Handler
  208. .align 1
  209. .thumb_func
  210. .weak Default_Handler
  211. .type Default_Handler, %function
  212. Default_Handler:
  213. b .
  214. .size Default_Handler, . - Default_Handler
  215. /* Macro to define default handlers. Default handler
  216. * will be weak symbol and just dead loops. They can be
  217. * overwritten by other handlers */
  218. .macro def_irq_handler handler_name
  219. .weak \handler_name
  220. .set \handler_name, Default_Handler
  221. .endm
  222. def_irq_handler NMI_Handler
  223. def_irq_handler HardFault_Handler
  224. def_irq_handler MemManage_Handler
  225. def_irq_handler BusFault_Handler
  226. def_irq_handler UsageFault_Handler
  227. def_irq_handler SVC_Handler
  228. def_irq_handler DebugMon_Handler
  229. def_irq_handler PendSV_Handler
  230. def_irq_handler SysTick_Handler
  231. def_irq_handler DEF_IRQHandler
  232. .end