startup_full.s 14 KB

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