ARM application development SDK for MNT ZZ9000 graphics and coprocessor card for classic Amiga computers.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

memmove.S 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* Runtime ABI for the ARM Cortex-M0
  2. * memmove.S: move memory block
  3. *
  4. * Copyright (c) 2017 Jörg Mische <bobbl@gmx.de>
  5. *
  6. * Permission to use, copy, modify, and/or distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  16. * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. .syntax unified
  19. .text
  20. .thumb
  21. .cpu cortex-m0
  22. @ void __aeabi_memmove8(void *r0, const void *r1, size_t r2);
  23. @
  24. @ Move r2 bytes from r1 to r0 and check for overlap.
  25. @ r1 and r0 must be aligned to 8 bytes.
  26. @
  27. .thumb_func
  28. .global __aeabi_memmove8
  29. __aeabi_memmove8:
  30. @ void __aeabi_memmove4(void *r0, const void *r1, size_t r2);
  31. @
  32. @ Move r2 bytes from r1 to r0 and check for overlap.
  33. @ r1 and r0 must be aligned to 4 bytes.
  34. @
  35. .thumb_func
  36. .global __aeabi_memmove4
  37. __aeabi_memmove4:
  38. cmp r0, r1
  39. bls __aeabi_memcpy4
  40. adds r3, r1, r2
  41. cmp r0, r3
  42. bhs __aeabi_memcpy4
  43. b .Lbackward_entry
  44. .Lbackward_loop:
  45. ldrb r3, [r1, r2]
  46. strb r3, [r0, r2]
  47. .Lbackward_entry:
  48. subs r2, #1
  49. bhs .Lbackward_loop
  50. bx lr
  51. @ void __aeabi_memmove(void *r0, const void *r1, size_t r2);
  52. @
  53. @ Move r2 bytes from r1 to r0 and check for overlap.
  54. @ r0 and r1 need not be aligned.
  55. @
  56. .thumb_func
  57. .global __aeabi_memmove
  58. __aeabi_memmove:
  59. cmp r0, r1
  60. bls __aeabi_memcpy
  61. adds r3, r1, r2
  62. cmp r0, r3
  63. blo .Lbackward_entry
  64. @ void __aeabi_memcpy(void *r0, const void *r1, size_t r2);
  65. @
  66. @ Move r2 bytes from r1 to r0. No overlap allowed.
  67. @ r0 and r1 need not be aligned.
  68. @
  69. .thumb_func
  70. .global __aeabi_memcpy
  71. __aeabi_memcpy:
  72. cmp r2, #8
  73. blo .Lforward1
  74. mov r3, r0
  75. eors r3, r1
  76. lsls r3, r3, #30
  77. bne .Lforward1
  78. lsrs r3, r0, #1
  79. bcc .Lalign2
  80. ldrb r3, [r1]
  81. strb r3, [r0]
  82. adds r0, #1
  83. adds r1, #1
  84. subs r2, #1
  85. .Lalign2:
  86. lsrs r3, r0, #2
  87. bcc .Lalign4
  88. ldrh r3, [r1]
  89. strh r3, [r0]
  90. adds r0, #2
  91. adds r1, #2
  92. subs r2, #2
  93. .Lalign4:
  94. @ void __aeabi_memcpy8(void *r0, const void *r1, size_t r2);
  95. @
  96. @ Move r2 bytes from r1 to r0. No overlap allowed.
  97. @ r0 and r1 must be aligned to 8 bytes.
  98. @
  99. .thumb_func
  100. .global __aeabi_memcpy8
  101. __aeabi_memcpy8:
  102. @ void __aeabi_memcpy4(void *r0, const void *r1, size_t r2);
  103. @
  104. @ Move r2 bytes from r1 to r0. No overlap allowed.
  105. @ r0 and r1 must be aligned to 4 bytes.
  106. @
  107. .thumb_func
  108. .global __aeabi_memcpy4
  109. __aeabi_memcpy4:
  110. subs r2, #20
  111. blo .Lforward4
  112. push {r4, r5, r6, r7}
  113. .Lforward20_loop:
  114. ldm r1!, {r3, r4, r5, r6, r7}
  115. stm r0!, {r3, r4, r5, r6, r7}
  116. subs r2, #20
  117. bhs .Lforward20_loop
  118. pop {r4, r5, r6, r7}
  119. .Lforward4:
  120. adds r2, #16
  121. blo .Lforward4_corr
  122. .Lforward4_loop:
  123. ldm r1!, {r3}
  124. stm r0!, {r3}
  125. subs r2, #4
  126. bhs .Lforward4_loop
  127. .Lforward4_corr:
  128. adds r2, #4
  129. .Lforward1:
  130. orrs r2, r2
  131. beq 9f
  132. push {r4}
  133. eors r4, r4
  134. .Lforward1_loop:
  135. ldrb r3, [r1, r4]
  136. strb r3, [r0, r4]
  137. adds r4, #1
  138. cmp r4, r2
  139. blo .Lforward1_loop
  140. pop {r4}
  141. 9: bx lr