startup_m0.s 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. .syntax unified
  2. .arch armv6-m
  3. .extern main
  4. .section .stack
  5. .align 3
  6. .equ Stack_Size, 0x800
  7. .globl __StackTop
  8. .globl __StackLimit
  9. __StackLimit:
  10. .space Stack_Size
  11. .size __StackLimit, . - __StackLimit
  12. __StackTop:
  13. .size __StackTop, . - __StackTop
  14. .section .heap
  15. .align 3
  16. .equ Heap_Size, 0
  17. .globl __HeapBase
  18. .globl __HeapLimit
  19. __HeapBase:
  20. .if Heap_Size
  21. .space Heap_Size
  22. .endif
  23. .size __HeapBase, . - __HeapBase
  24. __HeapLimit:
  25. .size __HeapLimit, . - __HeapLimit
  26. .section .isr_vector
  27. .align 2
  28. .globl __isr_vector
  29. __isr_vector:
  30. .long 0x10014000
  31. .long Reset_Handler
  32. .long NMI_Handler
  33. .long HardFault_Handler
  34. .long 0
  35. .long 0
  36. .long 0
  37. .long 0
  38. .long 0
  39. .long 0
  40. .long 0
  41. .long 0
  42. .long 0
  43. .long 0
  44. .long 0
  45. .long SysTick_Handler
  46. .long usb_handler
  47. .long iicd_handler
  48. .long qspi_handler
  49. .long spid_handler
  50. .long uart_handler
  51. .long uartb_handler
  52. .long adcd_handler
  53. .long i2s_handler
  54. .long bt_handler
  55. .long rsa_handler
  56. .size __isr_vector, . - __isr_vector
  57. .text
  58. .thumb
  59. .thumb_func
  60. .align 1
  61. .globl Reset_Handler
  62. .type Reset_Handler, %function
  63. Reset_Handler:
  64. ldr r1, =__etext
  65. ldr r2, =__data_start__
  66. ldr r3, =__data_end__
  67. subs r3, r2
  68. ble .L_loop1_done
  69. .L_loop1:
  70. subs r3, #4
  71. ldr r0, [r1,r3]
  72. str r0, [r2,r3]
  73. bgt .L_loop1
  74. .L_loop1_done:
  75. /* Single BSS section scheme.
  76. *
  77. * The BSS section is specified by following symbols
  78. * __bss_start__: start of the BSS section.
  79. * __bss_end__: end of the BSS section.
  80. *
  81. * Both addresses must be aligned to 4 bytes boundary.
  82. */
  83. ldr r1, =__bss_start__
  84. ldr r2, =__bss_end__
  85. movs r0, 0
  86. subs r2, r1
  87. ble .L_loop3_done
  88. .L_loop3:
  89. subs r2, #4
  90. str r0, [r1, r2]
  91. bgt .L_loop3
  92. .L_loop3_done:
  93. ldr r0,=0x12345
  94. ldr r3,=0x1111
  95. bl main
  96. .pool
  97. .size Reset_Handler, . - Reset_Handler
  98. .align 1
  99. .thumb_func
  100. .weak Default_Handler
  101. .type Default_Handler, %function
  102. Default_Handler:
  103. b .
  104. .size Default_Handler, . - Default_Handler
  105. /* Macro to define default handlers. Default handler
  106. * will be weak symbol and just dead loops. They can be
  107. * overwritten by other handlers */
  108. .macro def_irq_handler handler_name
  109. .weak \handler_name
  110. .set \handler_name, Default_Handler
  111. .endm
  112. def_irq_handler NMI_Handler
  113. def_irq_handler HardFault_Handler
  114. def_irq_handler SVC_Handler
  115. def_irq_handler PendSV_Handler
  116. def_irq_handler SysTick_Handler
  117. def_irq_handler DEF_IRQHandler
  118. def_irq_handler usb_handler
  119. def_irq_handler iicd_handler
  120. def_irq_handler qspi_handler
  121. def_irq_handler spid_handler
  122. def_irq_handler uart_handler
  123. def_irq_handler uartb_handler
  124. def_irq_handler adcd_handler
  125. def_irq_handler i2s_handler
  126. def_irq_handler bt_handler
  127. def_irq_handler rsa_handler
  128. @ int __aeabi_idiv(int num:r0, int denom:r1)
  129. @
  130. @ Divide r0 by r1 and return quotient in r0 (all signed).
  131. @ Use __aeabi_uidivmod() but check signs before and change signs afterwards.
  132. @
  133. .syntax unified @should be here
  134. .thumb_func
  135. .global __aeabi_idiv
  136. __aeabi_idiv:
  137. cmp r0, #0
  138. bge L_num_pos
  139. rsbs r0, #0
  140. cmp r1, #0
  141. bge L_neg_result
  142. rsbs r1, #0 @ den = -den
  143. b __aeabi_uidivmod
  144. L_num_pos:
  145. cmp r1, #0
  146. bge __aeabi_uidivmod
  147. rsbs r1, #0 @ den = -den
  148. L_neg_result:
  149. push {lr}
  150. bl __aeabi_uidivmod
  151. rsbs r0, #0 @ quot = -quot
  152. pop {pc}
  153. @ {int quotient:r0, int remainder:r1}
  154. @ __aeabi_idivmod(int numerator:r0, int denominator:r1)
  155. @
  156. @ Divide r0 by r1 and return the quotient in r0 and the remainder in r1
  157. @
  158. .thumb_func
  159. .global __aeabi_idivmod
  160. __aeabi_idivmod:
  161. cmp r0, #0
  162. bge L_num_pos_bis
  163. rsbs r0, #0 @ num = -num
  164. cmp r1, #0
  165. bge L_neg_both
  166. rsbs r1, #0 @ den = -den
  167. push {lr}
  168. bl __aeabi_uidivmod
  169. rsbs r1, #0 @ rem = -rem
  170. pop {pc}
  171. L_neg_both:
  172. push {lr}
  173. bl __aeabi_uidivmod
  174. rsbs r0, #0 @ quot = -quot
  175. rsbs r1, #0 @ rem = -rem
  176. pop {pc}
  177. L_num_pos_bis:
  178. cmp r1, #0
  179. bge __aeabi_uidivmod
  180. rsbs r1, #0 @ den = -den
  181. push {lr}
  182. bl __aeabi_uidivmod
  183. rsbs r0, #0 @ quot = -quot
  184. pop {pc}
  185. @ unsigned __aeabi_uidiv(unsigned num, unsigned denom)
  186. @
  187. @ Just an alias for __aeabi_uidivmod(), the remainder is ignored
  188. @
  189. .thumb_func
  190. .global __aeabi_uidiv
  191. __aeabi_uidiv:
  192. @ {unsigned quotient:r0, unsigned remainder:r1}
  193. @ __aeabi_uidivmod(unsigned numerator:r0, unsigned denominator:r1)
  194. @
  195. @ Divide r0 by r1 and return the quotient in r0 and the remainder in r1
  196. @
  197. .thumb_func
  198. .global __aeabi_uidivmod
  199. __aeabi_uidivmod:
  200. cmp r1, #0
  201. bne L_no_div0
  202. b __aeabi_idiv0
  203. L_no_div0:
  204. @ Shift left the denominator until it is greater than the numerator
  205. movs r2, #1 @ counter
  206. movs r3, #0 @ result
  207. cmp r0, r1
  208. bls L_sub_loop0
  209. adds r1, #0 @ dont shift if denominator would overflow
  210. bmi L_sub_loop0
  211. L_denom_shift_loop:
  212. lsls r2, #1
  213. lsls r1, #1
  214. bmi L_sub_loop0
  215. cmp r0, r1
  216. bhi L_denom_shift_loop
  217. L_sub_loop0:
  218. cmp r0, r1
  219. bcc L_dont_sub0 @ if (num>denom)
  220. subs r0, r1 @ numerator -= denom
  221. orrs r3, r2 @ result(r3) |= bitmask(r2)
  222. L_dont_sub0:
  223. lsrs r1, #1 @ denom(r1) >>= 1
  224. lsrs r2, #1 @ bitmask(r2) >>= 1
  225. bne L_sub_loop0
  226. mov r1, r0 @ remainder(r1) = numerator(r0)
  227. mov r0, r3 @ quotient(r0) = result(r3)
  228. bx lr
  229. __aeabi_idiv0:
  230. b __aeabi_idiv0
  231. .end