startup_full.s 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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 HardFault_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. movs r0, #0
  52. movs r1, #0
  53. movs r2, #0
  54. movs r3, #0
  55. movs r4, #0
  56. movs r5, #0
  57. movs r6, #0
  58. movs r7, #0
  59. LDR R0, =g_pfnVectors
  60. LDR R1, =0xE000ED08
  61. STR R0,[R1]
  62. ldr sp, =_estack /* set stack pointer */
  63. /* Copy the data segment initializers from flash to SRAM */
  64. movs r1, #0
  65. b LoopCopyDataInit
  66. CopyDataInit:
  67. ldr r3, =_sidata
  68. ldr r3, [r3, r1]
  69. str r3, [r0, r1]
  70. adds r1, r1, #4
  71. LoopCopyDataInit:
  72. ldr r0, =_sdata
  73. ldr r3, =_edata
  74. adds r2, r0, r1
  75. cmp r2, r3
  76. bcc CopyDataInit
  77. ldr r2, =_sbss
  78. b LoopFillZerobss
  79. /* Zero fill the bss segment. */
  80. FillZerobss:
  81. movs r3, #0
  82. str r3, [r2], #4
  83. LoopFillZerobss:
  84. ldr r3, = _ebss
  85. cmp r2, r3
  86. bcc FillZerobss
  87. /* Call the clock system intitialization function.*/
  88. bl SystemInit
  89. /* Call static constructors */
  90. bl __libc_init_array /*目前看来这个没什么用,如果代码量有超可以去掉*/
  91. /* Call the application's entry point.*/
  92. bl main
  93. bx lr
  94. .size Reset_Handler, .-Reset_Handler
  95. /**
  96. * @brief This is the code that gets called when the processor receives an
  97. * unexpected interrupt. This simply enters an infinite loop, preserving
  98. * the system state for examination by a debugger.
  99. * @param None
  100. * @retval None
  101. */
  102. .section .text.Default_Handler,"ax",%progbits
  103. Default_Handler:
  104. Infinite_Loop:
  105. b Infinite_Loop
  106. .size Default_Handler, .-Default_Handler
  107. /******************************************************************************
  108. *
  109. * The minimal vector table for a Cortex M3. Note that the proper constructs
  110. * must be placed on this to ensure that it ends up at physical address
  111. * 0x0000.0000.
  112. *
  113. *******************************************************************************/
  114. .section .isr_vector,"a",%progbits
  115. .type g_pfnVectors, %object
  116. .size g_pfnVectors, .-g_pfnVectors
  117. g_pfnVectors:
  118. .word _estack
  119. .word Reset_Handler
  120. .word NMI_Handler
  121. .word HardFault_Handler
  122. .word MemManage_Handler
  123. .word BusFault_Handler
  124. .word UsageFault_Handler
  125. .word 0
  126. .word 0
  127. .word 0
  128. .word 0
  129. .word SVC_Handler
  130. .word DebugMon_Handler
  131. .word 0
  132. .word PendSV_Handler
  133. .word SysTick_Handler
  134. /* External Interrupts */
  135. .word ISR_GlobalHandler /* Window WatchDog */
  136. .word ISR_GlobalHandler /* PVD through EXTI Line detection */
  137. .word ISR_GlobalHandler /* Tamper and TimeStamps through the EXTI line */
  138. .word ISR_GlobalHandler /* RTC Wakeup through the EXTI line */
  139. .word ISR_GlobalHandler /* FLASH */
  140. .word ISR_GlobalHandler /* RCC */
  141. .word ISR_GlobalHandler /* EXTI Line0 */
  142. .word ISR_GlobalHandler /* EXTI Line1 */
  143. .word ISR_GlobalHandler /* EXTI Line2 */
  144. .word ISR_GlobalHandler /* EXTI Line3 */
  145. .word ISR_GlobalHandler /* EXTI Line4 */
  146. .word ISR_GlobalHandler /* DMA1 Stream 0 */
  147. .word ISR_GlobalHandler /* DMA1 Stream 1 */
  148. .word ISR_GlobalHandler /* DMA1 Stream 2 */
  149. .word ISR_GlobalHandler /* DMA1 Stream 3 */
  150. .word ISR_GlobalHandler /* DMA1 Stream 4 */
  151. .word ISR_GlobalHandler /* DMA1 Stream 5 */
  152. .word ISR_GlobalHandler /* DMA1 Stream 6 */
  153. .word ISR_GlobalHandler /* ADC1, ADC2 and ADC3s */
  154. .word ISR_GlobalHandler /* CAN1 TX */
  155. .word ISR_GlobalHandler /* CAN1 RX0 */
  156. .word ISR_GlobalHandler /* CAN1 RX1 */
  157. .word ISR_GlobalHandler /* CAN1 SCE */
  158. .word ISR_GlobalHandler /* External Line[9:5]s */
  159. .word ISR_GlobalHandler /* TIM1 Break and TIM9 */
  160. .word ISR_GlobalHandler /* TIM1 Update and TIM10 */
  161. .word ISR_GlobalHandler /* TIM1 Trigger and Commutation and TIM11 */
  162. .word ISR_GlobalHandler /* TIM1 Capture Compare */
  163. .word ISR_GlobalHandler /* TIM2 */
  164. .word ISR_GlobalHandler /* TIM3 */
  165. .word ISR_GlobalHandler /* TIM4 */
  166. .word ISR_GlobalHandler /* I2C1 Event */
  167. .word ISR_GlobalHandler /* I2C1 Error */
  168. .word ISR_GlobalHandler /* I2C2 Event */
  169. .word ISR_GlobalHandler /* I2C2 Error */
  170. .word ISR_GlobalHandler /* SPI1 */
  171. .word ISR_GlobalHandler /* SPI2 */
  172. .word ISR_GlobalHandler /* USART1 */
  173. .word ISR_GlobalHandler /* USART2 */
  174. .word ISR_GlobalHandler /* USART3 */
  175. .word ISR_GlobalHandler /* External Line[15:10]s */
  176. .word ISR_GlobalHandler /* RTC Alarm (A and B) through EXTI Line */
  177. .word ISR_GlobalHandler /* USB OTG FS Wakeup through EXTI line */
  178. .word ISR_GlobalHandler /* TIM8 Break and TIM12 */
  179. .word ISR_GlobalHandler /* TIM8 Update and TIM13 */
  180. .word ISR_GlobalHandler /* TIM8 Trigger and Commutation and TIM14 */
  181. .word ISR_GlobalHandler /* TIM8 Capture Compare */
  182. .word ISR_GlobalHandler /* DMA1 Stream7 */
  183. .word ISR_GlobalHandler /* FSMC */
  184. .word ISR_GlobalHandler /* SDIO */
  185. .word ISR_GlobalHandler /* TIM5 */
  186. .word ISR_GlobalHandler /* SPI3 */
  187. .word ISR_GlobalHandler /* UART4 */
  188. .word ISR_GlobalHandler /* UART5 */
  189. .word ISR_GlobalHandler /* TIM6 and DAC1&2 underrun errors */
  190. .word ISR_GlobalHandler /* TIM7 */
  191. .word ISR_GlobalHandler /* DMA2 Stream 0 */
  192. .word ISR_GlobalHandler /* DMA2 Stream 1 */
  193. .word ISR_GlobalHandler /* DMA2 Stream 2 */
  194. .word ISR_GlobalHandler /* DMA2 Stream 3 */
  195. .word ISR_GlobalHandler /* DMA2 Stream 4 */
  196. .word ISR_GlobalHandler /* Ethernet */
  197. .word ISR_GlobalHandler /* Ethernet Wakeup through EXTI line */
  198. .word ISR_GlobalHandler /* CAN2 TX */
  199. .word ISR_GlobalHandler /* CAN2 RX0 */
  200. .word ISR_GlobalHandler /* CAN2 RX1 */
  201. .word ISR_GlobalHandler /* CAN2 SCE */
  202. .word ISR_GlobalHandler /* USB OTG FS */
  203. .word ISR_GlobalHandler /* DMA2 Stream 5 */
  204. .word ISR_GlobalHandler /* DMA2 Stream 6 */
  205. .word ISR_GlobalHandler /* DMA2 Stream 7 */
  206. .word ISR_GlobalHandler /* USART6 */
  207. .word ISR_GlobalHandler /* I2C3 event */
  208. .word ISR_GlobalHandler /* I2C3 error */
  209. .word ISR_GlobalHandler /* USB OTG HS End Point 1 Out */
  210. .word ISR_GlobalHandler /* USB OTG HS End Point 1 In */
  211. .word ISR_GlobalHandler /* USB OTG HS Wakeup through EXTI */
  212. .word ISR_GlobalHandler /* USB OTG HS */
  213. .word ISR_GlobalHandler /* DCMI */
  214. .word ISR_GlobalHandler /* CRYP crypto */
  215. .word ISR_GlobalHandler /* Hash and Rng */
  216. .word ISR_GlobalHandler /* FPU */
  217. .word ISR_GlobalHandler /* UART7 */
  218. .word ISR_GlobalHandler /* UART8 */
  219. .word ISR_GlobalHandler /* SPI4 */
  220. .word ISR_GlobalHandler /* SPI5 */
  221. .word ISR_GlobalHandler /* SPI6 */
  222. .word ISR_GlobalHandler /* SAI1 */
  223. .word ISR_GlobalHandler /* LTDC_IRQHandler */
  224. .word ISR_GlobalHandler /* LTDC_ER_IRQHandler */
  225. .word ISR_GlobalHandler /* DMA2D
  226. /*******************************************************************************
  227. *
  228. * Provide weak aliases for each Exception handler to the Default_Handler.
  229. * As they are weak aliases, any function with the same name will override
  230. * this definition.
  231. *
  232. *******************************************************************************/
  233. .weak NMI_Handler
  234. .thumb_set NMI_Handler,Default_Handler
  235. .section .text.CmTrace_Handler
  236. .type CmTrace_Handler, %function
  237. CmTrace_Handler:
  238. MOV r0, lr /* get lr */
  239. MOV r1, sp /* get stack pointer (current is MSP) */
  240. BL cm_backtrace_fault
  241. Fault_Loop:
  242. BL Fault_Loop /* while(1) */
  243. .weak NMI_Handler
  244. .thumb_set NMI_Handler,CmTrace_Handler
  245. .weak HardFault_Handler
  246. .thumb_set HardFault_Handler,CmTrace_Handler
  247. .weak MemManage_Handler
  248. .thumb_set MemManage_Handler,CmTrace_Handler
  249. .weak BusFault_Handler
  250. .thumb_set BusFault_Handler,CmTrace_Handler
  251. .weak UsageFault_Handler
  252. .thumb_set UsageFault_Handler,CmTrace_Handler
  253. .weak SVC_Handler
  254. .thumb_set SVC_Handler,Default_Handler
  255. .weak DebugMon_Handler
  256. .thumb_set DebugMon_Handler,Default_Handler
  257. .weak PendSV_Handler
  258. .thumb_set PendSV_Handler,Default_Handler
  259. .weak SysTick_Handler
  260. .thumb_set SysTick_Handler,Default_Handler
  261. .weak ISR_GlobalHandler
  262. .thumb_set ISR_GlobalHandler,Default_Handler
  263. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/