您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

264 行
7.2KB

  1. /* File: startup_ARMCM0.S
  2. * Purpose: startup file for Cortex-M0 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 armv6-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 0 /* Reserved */
  73. .long 0 /* Reserved */
  74. .long 0 /* Reserved */
  75. .long 0 /* Reserved */
  76. .long 0 /* Reserved */
  77. .long 0 /* Reserved */
  78. .long 0 /* Reserved */
  79. .long SVC_Handler /* SVCall Handler */
  80. .long 0 /* Reserved */
  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 1
  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. blt .L_loop0_0_done
  121. ldr r0, [r1, r3]
  122. str r0, [r2, r3]
  123. b .L_loop0_0
  124. .L_loop0_0_done:
  125. adds r4, #12
  126. b .L_loop0
  127. .L_loop0_done:
  128. #else
  129. /* Single section scheme.
  130. *
  131. * The ranges of copy from/to are specified by following symbols
  132. * __etext: LMA of start of the section to copy from. Usually end of text
  133. * __data_start__: VMA of start of the section to copy to
  134. * __data_end__: VMA of end of the section to copy to
  135. *
  136. * All addresses must be aligned to 4 bytes boundary.
  137. */
  138. ldr r1, =__etext
  139. ldr r2, =__data_start__
  140. ldr r3, =__data_end__
  141. subs r3, r2
  142. ble .L_loop1_done
  143. .L_loop1:
  144. subs r3, #4
  145. ldr r0, [r1,r3]
  146. str r0, [r2,r3]
  147. bgt .L_loop1
  148. .L_loop1_done:
  149. #endif /*__STARTUP_COPY_MULTIPLE */
  150. /* This part of work usually is done in C library startup code. Otherwise,
  151. * define this macro to enable it in this startup.
  152. *
  153. * There are two schemes too. One can clear multiple BSS sections. Another
  154. * can only clear one section. The former is more size expensive than the
  155. * latter.
  156. *
  157. * Define macro __STARTUP_CLEAR_BSS_MULTIPLE to choose the former.
  158. * Otherwise efine macro __STARTUP_CLEAR_BSS to choose the later.
  159. */
  160. #ifdef __STARTUP_CLEAR_BSS_MULTIPLE
  161. /* Multiple sections scheme.
  162. *
  163. * Between symbol address __copy_table_start__ and __copy_table_end__,
  164. * there are array of tuples specifying:
  165. * offset 0: Start of a BSS section
  166. * offset 4: Size of this BSS section. Must be multiply of 4
  167. */
  168. ldr r3, =__zero_table_start__
  169. ldr r4, =__zero_table_end__
  170. .L_loop2:
  171. cmp r3, r4
  172. bge .L_loop2_done
  173. ldr r1, [r3]
  174. ldr r2, [r3, #4]
  175. movs r0, 0
  176. .L_loop2_0:
  177. subs r2, #4
  178. blt .L_loop2_0_done
  179. str r0, [r1, r2]
  180. b .L_loop2_0
  181. .L_loop2_0_done:
  182. adds r3, #8
  183. b .L_loop2
  184. .L_loop2_done:
  185. #elif defined (__STARTUP_CLEAR_BSS)
  186. /* Single BSS section scheme.
  187. *
  188. * The BSS section is specified by following symbols
  189. * __bss_start__: start of the BSS section.
  190. * __bss_end__: end of the BSS section.
  191. *
  192. * Both addresses must be aligned to 4 bytes boundary.
  193. */
  194. ldr r1, =__bss_start__
  195. ldr r2, =__bss_end__
  196. movs r0, 0
  197. subs r2, r1
  198. ble .L_loop3_done
  199. .L_loop3:
  200. subs r2, #4
  201. str r0, [r1, r2]
  202. bgt .L_loop3
  203. .L_loop3_done:
  204. #endif /* __STARTUP_CLEAR_BSS_MULTIPLE || __STARTUP_CLEAR_BSS */
  205. #ifndef __NO_SYSTEM_INIT
  206. bl SystemInit
  207. #endif
  208. #ifndef __START
  209. #define __START _start
  210. #endif
  211. bl __START
  212. .pool
  213. .size Reset_Handler, . - Reset_Handler
  214. .align 1
  215. .thumb_func
  216. .weak Default_Handler
  217. .type Default_Handler, %function
  218. Default_Handler:
  219. b .
  220. .size Default_Handler, . - Default_Handler
  221. /* Macro to define default handlers. Default handler
  222. * will be weak symbol and just dead loops. They can be
  223. * overwritten by other handlers */
  224. .macro def_irq_handler handler_name
  225. .weak \handler_name
  226. .set \handler_name, Default_Handler
  227. .endm
  228. def_irq_handler NMI_Handler
  229. def_irq_handler HardFault_Handler
  230. def_irq_handler SVC_Handler
  231. def_irq_handler PendSV_Handler
  232. def_irq_handler SysTick_Handler
  233. def_irq_handler DEF_IRQHandler
  234. .end