startup_gcc.s 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. .syntax unified
  22. .cpu cortex-m4
  23. .fpu softvfp
  24. .thumb
  25. .global g_pfnVectors
  26. .global Default_Handler
  27. /* start address for the initialization values of the .data section.
  28. defined in linker script */
  29. .word _sidata
  30. /* start address for the .data section. defined in linker script */
  31. .word _sdata
  32. /* end address for the .data section. defined in linker script */
  33. .word _edata
  34. /* start address for the .bss section. defined in linker script */
  35. .word _sbss
  36. /* end address for the .bss section. defined in linker script */
  37. .word _ebss
  38. /* stack used for SystemInit_ExtMemCtl; always internal RAM used */
  39. /**
  40. * @brief This is the code that gets called when the processor first
  41. * starts execution following a reset event. Only the absolutely
  42. * necessary set is performed, after which the application
  43. * supplied main() routine is called.
  44. * @param None
  45. * @retval : None
  46. */
  47. .section .text.Reset_Handler
  48. .weak Reset_Handler
  49. .type Reset_Handler, %function
  50. Reset_Handler:
  51. ldr sp, =_estack /* set stack pointer */
  52. /* Copy the data segment initializers from flash to SRAM */
  53. ldr r0, =_sdata
  54. ldr r1, =_edata
  55. ldr r2, =_sidata
  56. movs r3, #0
  57. b LoopCopyDataInit
  58. CopyDataInit:
  59. ldr r4, [r2, r3]
  60. str r4, [r0, r3]
  61. adds r3, r3, #4
  62. LoopCopyDataInit:
  63. adds r4, r0, r3
  64. cmp r4, r1
  65. bcc CopyDataInit
  66. /* Zero fill the bss segment. */
  67. ldr r2, =_sbss
  68. ldr r4, =_ebss
  69. movs r3, #0
  70. b LoopFillZerobss
  71. FillZerobss:
  72. str r3, [r2]
  73. adds r2, r2, #4
  74. LoopFillZerobss:
  75. cmp r2, r4
  76. bcc FillZerobss
  77. /* Call the clock system intitialization function.*/
  78. bl SystemInit
  79. /* Call static constructors */
  80. bl __libc_init_array
  81. /* Call the application's entry point.*/
  82. bl entry
  83. bx lr
  84. .size Reset_Handler, .-Reset_Handler
  85. /**
  86. * @brief This is the code that gets called when the processor receives an
  87. * unexpected interrupt. This simply enters an infinite loop, preserving
  88. * the system state for examination by a debugger.
  89. * @param None
  90. * @retval None
  91. */
  92. .section .text.Default_Handler,"ax",%progbits
  93. Default_Handler:
  94. Infinite_Loop:
  95. b Infinite_Loop
  96. .size Default_Handler, .-Default_Handler
  97. /******************************************************************************
  98. *
  99. * The minimal vector table for a Cortex M3. Note that the proper constructs
  100. * must be placed on this to ensure that it ends up at physical address
  101. * 0x0000.0000.
  102. *
  103. *******************************************************************************/
  104. .section .isr_vector,"a",%progbits
  105. .type g_pfnVectors, %object
  106. .size g_pfnVectors, .-g_pfnVectors
  107. g_pfnVectors:
  108. .word _estack
  109. .word Reset_Handler
  110. .word HardFault_Handler
  111. .word HardFault_Handler
  112. .word HardFault_Handler
  113. .word HardFault_Handler
  114. .word HardFault_Handler
  115. .word 0
  116. .word 0
  117. .word 0
  118. .word 0
  119. .word SVC_Handler
  120. .word DebugMon_Handler
  121. .word 0
  122. .word PendSV_Handler
  123. .word SysTick_Handler
  124. /* External Interrupts */
  125. .word ISR_GlobalHandler /* Window WatchDog */
  126. .word ISR_GlobalHandler /* PVD through EXTI Line detection */
  127. .word ISR_GlobalHandler /* Tamper and TimeStamps through the EXTI line */
  128. .word ISR_GlobalHandler /* RTC Wakeup through the EXTI line */
  129. .word ISR_GlobalHandler /* FLASH */
  130. .word ISR_GlobalHandler /* RCC */
  131. .word ISR_GlobalHandler /* EXTI Line0 */
  132. .word ISR_GlobalHandler /* EXTI Line1 */
  133. .word ISR_GlobalHandler /* EXTI Line2 */
  134. .word ISR_GlobalHandler /* EXTI Line3 */
  135. .word ISR_GlobalHandler /* EXTI Line4 */
  136. .word ISR_GlobalHandler /* DMA1 Stream 0 */
  137. .word ISR_GlobalHandler /* DMA1 Stream 1 */
  138. .word ISR_GlobalHandler /* DMA1 Stream 2 */
  139. .word ISR_GlobalHandler /* DMA1 Stream 3 */
  140. .word ISR_GlobalHandler /* DMA1 Stream 4 */
  141. .word ISR_GlobalHandler /* DMA1 Stream 5 */
  142. .word ISR_GlobalHandler /* DMA1 Stream 6 */
  143. .word ISR_GlobalHandler /* ADC1, ADC2 and ADC3s */
  144. .word ISR_GlobalHandler /* CAN1 TX */
  145. .word ISR_GlobalHandler /* CAN1 RX0 */
  146. .word ISR_GlobalHandler /* CAN1 RX1 */
  147. .word ISR_GlobalHandler /* CAN1 SCE */
  148. .word ISR_GlobalHandler /* External Line[9:5]s */
  149. .word ISR_GlobalHandler /* TIM1 Break and TIM9 */
  150. .word ISR_GlobalHandler /* TIM1 Update and TIM10 */
  151. .word ISR_GlobalHandler /* TIM1 Trigger and Commutation and TIM11 */
  152. .word ISR_GlobalHandler /* TIM1 Capture Compare */
  153. .word ISR_GlobalHandler /* TIM2 */
  154. .word ISR_GlobalHandler /* TIM3 */
  155. .word ISR_GlobalHandler /* TIM4 */
  156. .word ISR_GlobalHandler /* I2C1 Event */
  157. .word ISR_GlobalHandler /* I2C1 Error */
  158. .word ISR_GlobalHandler /* I2C2 Event */
  159. .word ISR_GlobalHandler /* I2C2 Error */
  160. .word ISR_GlobalHandler /* SPI1 */
  161. .word ISR_GlobalHandler /* SPI2 */
  162. .word ISR_GlobalHandler /* USART1 */
  163. .word ISR_GlobalHandler /* USART2 */
  164. .word ISR_GlobalHandler /* USART3 */
  165. .word ISR_GlobalHandler /* External Line[15:10]s */
  166. .word ISR_GlobalHandler /* RTC Alarm (A and B) through EXTI Line */
  167. .word ISR_GlobalHandler /* USB OTG FS Wakeup through EXTI line */
  168. .word ISR_GlobalHandler /* TIM8 Break and TIM12 */
  169. .word ISR_GlobalHandler /* TIM8 Update and TIM13 */
  170. .word ISR_GlobalHandler /* TIM8 Trigger and Commutation and TIM14 */
  171. .word ISR_GlobalHandler /* TIM8 Capture Compare */
  172. .word ISR_GlobalHandler /* DMA1 Stream7 */
  173. .word ISR_GlobalHandler /* FSMC */
  174. .word ISR_GlobalHandler /* SDIO */
  175. .word ISR_GlobalHandler /* TIM5 */
  176. .word ISR_GlobalHandler /* SPI3 */
  177. .word ISR_GlobalHandler /* UART4 */
  178. .word ISR_GlobalHandler /* UART5 */
  179. .word ISR_GlobalHandler /* TIM6 and DAC1&2 underrun errors */
  180. .word ISR_GlobalHandler /* TIM7 */
  181. .word ISR_GlobalHandler /* DMA2 Stream 0 */
  182. .word ISR_GlobalHandler /* DMA2 Stream 1 */
  183. .word ISR_GlobalHandler /* DMA2 Stream 2 */
  184. .word ISR_GlobalHandler /* DMA2 Stream 3 */
  185. .word ISR_GlobalHandler /* DMA2 Stream 4 */
  186. .word ISR_GlobalHandler /* Ethernet */
  187. .word ISR_GlobalHandler /* Ethernet Wakeup through EXTI line */
  188. .word ISR_GlobalHandler /* CAN2 TX */
  189. .word ISR_GlobalHandler /* CAN2 RX0 */
  190. .word ISR_GlobalHandler /* CAN2 RX1 */
  191. .word ISR_GlobalHandler /* CAN2 SCE */
  192. .word ISR_GlobalHandler /* USB OTG FS */
  193. .word ISR_GlobalHandler /* DMA2 Stream 5 */
  194. .word ISR_GlobalHandler /* DMA2 Stream 6 */
  195. .word ISR_GlobalHandler /* DMA2 Stream 7 */
  196. .word ISR_GlobalHandler /* USART6 */
  197. .word ISR_GlobalHandler /* I2C3 event */
  198. .word ISR_GlobalHandler /* I2C3 error */
  199. .word ISR_GlobalHandler /* USB OTG HS End Point 1 Out */
  200. .word ISR_GlobalHandler /* USB OTG HS End Point 1 In */
  201. .word ISR_GlobalHandler /* USB OTG HS Wakeup through EXTI */
  202. .word ISR_GlobalHandler /* USB OTG HS */
  203. .word ISR_GlobalHandler /* DCMI */
  204. .word ISR_GlobalHandler /* CRYP crypto */
  205. .word ISR_GlobalHandler /* Hash and Rng */
  206. .word ISR_GlobalHandler /* FPU */
  207. .word ISR_GlobalHandler /* UART7 */
  208. .word ISR_GlobalHandler /* UART8 */
  209. .word ISR_GlobalHandler /* SPI4 */
  210. .word ISR_GlobalHandler /* SPI5 */
  211. .word ISR_GlobalHandler /* SPI6 */
  212. .word ISR_GlobalHandler /* SAI1 */
  213. .word ISR_GlobalHandler /* LTDC_IRQHandler */
  214. .word ISR_GlobalHandler /* LTDC_ER_IRQHandler */
  215. .word ISR_GlobalHandler /* DMA2D
  216. /*******************************************************************************
  217. *
  218. * Provide weak aliases for each Exception handler to the Default_Handler.
  219. * As they are weak aliases, any function with the same name will override
  220. * this definition.
  221. *
  222. *******************************************************************************/
  223. .weak NMI_Handler
  224. .thumb_set NMI_Handler,Default_Handler
  225. .weak HardFault_Handler
  226. .thumb_set HardFault_Handler,Default_Handler
  227. .weak MemManage_Handler
  228. .thumb_set MemManage_Handler,Default_Handler
  229. .weak BusFault_Handler
  230. .thumb_set BusFault_Handler,Default_Handler
  231. .weak UsageFault_Handler
  232. .thumb_set UsageFault_Handler,Default_Handler
  233. .weak SVC_Handler
  234. .thumb_set SVC_Handler,Default_Handler
  235. .weak DebugMon_Handler
  236. .thumb_set DebugMon_Handler,Default_Handler
  237. .weak PendSV_Handler
  238. .thumb_set PendSV_Handler,Default_Handler
  239. .weak SysTick_Handler
  240. .thumb_set SysTick_Handler,Default_Handler