startup_run_in_ram.s 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. .word _sitext
  40. .word _sstext
  41. .word _setext
  42. /**
  43. * @brief This is the code that gets called when the processor first
  44. * starts execution following a reset event. Only the absolutely
  45. * necessary set is performed, after which the application
  46. * supplied main() routine is called.
  47. * @param None
  48. * @retval : None
  49. */
  50. .section .text.Reset_Handler
  51. .weak Reset_Handler
  52. .type Reset_Handler, %function
  53. Reset_Handler:
  54. movs r0, #0
  55. movs r1, #0
  56. movs r2, #0
  57. movs r3, #0
  58. movs r4, #0
  59. movs r5, #0
  60. movs r6, #0
  61. movs r7, #0
  62. LDR R0, =g_pfnVectors
  63. LDR R1, =0xE000ED08
  64. STR R0,[R1]
  65. ldr sp, =_estack /* set stack pointer */
  66. /* Copy the data segment initializers from flash to SRAM */
  67. movs r1, #0
  68. b LoopCopyTextInit
  69. CopyTextInit:
  70. ldr r3, =_sitext
  71. ldr r3, [r3, r1]
  72. str r3, [r0, r1]
  73. adds r1, r1, #4
  74. LoopCopyTextInit:
  75. ldr r0, =_sstext
  76. ldr r3, =_setext
  77. adds r2, r0, r1
  78. cmp r2, r3
  79. bcc CopyTextInit
  80. movs r1, #0
  81. b LoopCopyDataInit
  82. CopyDataInit:
  83. ldr r3, =_sidata
  84. ldr r3, [r3, r1]
  85. str r3, [r0, r1]
  86. adds r1, r1, #4
  87. LoopCopyDataInit:
  88. ldr r0, =_sdata
  89. ldr r3, =_edata
  90. adds r2, r0, r1
  91. cmp r2, r3
  92. bcc CopyDataInit
  93. ldr r2, =_sbss
  94. b LoopFillZerobss
  95. /* Zero fill the bss segment. */
  96. FillZerobss:
  97. movs r3, #0
  98. str r3, [r2], #4
  99. LoopFillZerobss:
  100. ldr r3, = _ebss
  101. cmp r2, r3
  102. bcc FillZerobss
  103. /* Call the clock system intitialization function.*/
  104. bl SystemInit
  105. /* Call static constructors */
  106. bl __libc_init_array /*目前看来这个没什么用,如果代码量有超可以去掉*/
  107. /* Call the application's entry point.*/
  108. bl main
  109. bx lr
  110. .size Reset_Handler, .-Reset_Handler
  111. /**
  112. * @brief This is the code that gets called when the processor receives an
  113. * unexpected interrupt. This simply enters an infinite loop, preserving
  114. * the system state for examination by a debugger.
  115. * @param None
  116. * @retval None
  117. */
  118. .section .text.Default_Handler,"ax",%progbits
  119. Default_Handler:
  120. Infinite_Loop:
  121. b Infinite_Loop
  122. .size Default_Handler, .-Default_Handler
  123. /******************************************************************************
  124. *
  125. * The minimal vector table for a Cortex M3. Note that the proper constructs
  126. * must be placed on this to ensure that it ends up at physical address
  127. * 0x0000.0000.
  128. *
  129. *******************************************************************************/
  130. .section .isr_vector,"a",%progbits
  131. .type g_pfnVectors, %object
  132. .size g_pfnVectors, .-g_pfnVectors
  133. g_pfnVectors:
  134. .word _estack
  135. .word Reset_Handler
  136. .word NMI_Handler
  137. .word HardFault_Handler
  138. .word MemManage_Handler
  139. .word BusFault_Handler
  140. .word UsageFault_Handler
  141. .word 0
  142. .word 0
  143. .word 0
  144. .word 0
  145. .word SVC_Handler
  146. .word DebugMon_Handler
  147. .word 0
  148. .word PendSV_Handler
  149. .word SysTick_Handler
  150. /* External Interrupts */
  151. .word ISR_GlobalHandler
  152. .word ISR_GlobalHandler
  153. .word ISR_GlobalHandler
  154. .word ISR_GlobalHandler
  155. .word ISR_GlobalHandler
  156. .word ISR_GlobalHandler
  157. .word ISR_GlobalHandler
  158. .word ISR_GlobalHandler
  159. .word ISR_GlobalHandler
  160. .word ISR_GlobalHandler
  161. .word ISR_GlobalHandler
  162. .word ISR_GlobalHandler
  163. .word ISR_GlobalHandler
  164. .word ISR_GlobalHandler
  165. .word ISR_GlobalHandler
  166. .word ISR_GlobalHandler
  167. .word ISR_GlobalHandler
  168. .word ISR_GlobalHandler
  169. .word ISR_GlobalHandler
  170. .word ISR_GlobalHandler
  171. .word ISR_GlobalHandler
  172. .word ISR_GlobalHandler
  173. .word ISR_GlobalHandler
  174. .word ISR_GlobalHandler
  175. .word ISR_GlobalHandler
  176. .word ISR_GlobalHandler
  177. .word ISR_GlobalHandler
  178. .word ISR_GlobalHandler
  179. .word ISR_GlobalHandler
  180. .word ISR_GlobalHandler
  181. .word ISR_GlobalHandler
  182. .word ISR_GlobalHandler
  183. .word ISR_GlobalHandler
  184. .word ISR_GlobalHandler
  185. .word ISR_GlobalHandler
  186. .word ISR_GlobalHandler
  187. .word ISR_GlobalHandler
  188. .word ISR_GlobalHandler
  189. .word ISR_GlobalHandler
  190. .word ISR_GlobalHandler
  191. .word ISR_GlobalHandler
  192. .word ISR_GlobalHandler
  193. .word ISR_GlobalHandler
  194. .word ISR_GlobalHandler
  195. .word ISR_GlobalHandler
  196. .word ISR_GlobalHandler
  197. .word ISR_GlobalHandler
  198. .word ISR_GlobalHandler
  199. .word ISR_GlobalHandler
  200. .word ISR_GlobalHandler
  201. .word ISR_GlobalHandler
  202. .word ISR_GlobalHandler
  203. .word ISR_GlobalHandler
  204. .word ISR_GlobalHandler
  205. .word ISR_GlobalHandler
  206. .word ISR_GlobalHandler
  207. .word ISR_GlobalHandler
  208. .word ISR_GlobalHandler
  209. .word ISR_GlobalHandler
  210. .word ISR_GlobalHandler
  211. .word ISR_GlobalHandler
  212. .word ISR_GlobalHandler
  213. .word ISR_GlobalHandler
  214. .word ISR_GlobalHandler
  215. .word ISR_GlobalHandler
  216. .word ISR_GlobalHandler
  217. .word ISR_GlobalHandler
  218. .word ISR_GlobalHandler
  219. .word ISR_GlobalHandler
  220. .word ISR_GlobalHandler
  221. .word ISR_GlobalHandler
  222. .word ISR_GlobalHandler
  223. .word ISR_GlobalHandler
  224. .word ISR_GlobalHandler
  225. .word ISR_GlobalHandler
  226. .word ISR_GlobalHandler
  227. .word ISR_GlobalHandler
  228. .word ISR_GlobalHandler
  229. .word ISR_GlobalHandler
  230. .word ISR_GlobalHandler
  231. .word ISR_GlobalHandler
  232. .word ISR_GlobalHandler
  233. .word ISR_GlobalHandler
  234. .word ISR_GlobalHandler
  235. .word ISR_GlobalHandler
  236. .word ISR_GlobalHandler
  237. .word ISR_GlobalHandler
  238. .word ISR_GlobalHandler
  239. .word ISR_GlobalHandler
  240. .word ISR_GlobalHandler
  241. .word ISR_GlobalHandler
  242. /*******************************************************************************
  243. *
  244. * Provide weak aliases for each Exception handler to the Default_Handler.
  245. * As they are weak aliases, any function with the same name will override
  246. * this definition.
  247. *
  248. *******************************************************************************/
  249. .weak NMI_Handler
  250. .thumb_set NMI_Handler,Default_Handler
  251. .section .text.CmTrace_Handler
  252. .type CmTrace_Handler, %function
  253. CmTrace_Handler:
  254. MOV r0, lr /* get lr */
  255. MOV r1, sp /* get stack pointer (current is MSP) */
  256. BL cm_backtrace_fault
  257. Fault_Loop:
  258. BL Fault_Loop /* while(1) */
  259. .weak NMI_Handler
  260. .thumb_set NMI_Handler,CmTrace_Handler
  261. .weak HardFault_Handler
  262. .thumb_set HardFault_Handler,CmTrace_Handler
  263. .weak MemManage_Handler
  264. .thumb_set MemManage_Handler,CmTrace_Handler
  265. .weak BusFault_Handler
  266. .thumb_set BusFault_Handler,CmTrace_Handler
  267. .weak UsageFault_Handler
  268. .thumb_set UsageFault_Handler,CmTrace_Handler
  269. .weak SVC_Handler
  270. .thumb_set SVC_Handler,Default_Handler
  271. .weak DebugMon_Handler
  272. .thumb_set DebugMon_Handler,Default_Handler
  273. .weak PendSV_Handler
  274. .thumb_set PendSV_Handler,Default_Handler
  275. .weak SysTick_Handler
  276. .thumb_set SysTick_Handler,Default_Handler
  277. .weak ISR_GlobalHandler
  278. .thumb_set ISR_GlobalHandler,Default_Handler