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.

memset.S 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* Runtime ABI for the ARM Cortex-M0
  2. * memset.S: set memory region
  3. *
  4. * Copyright (c) 2013 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_memclr(void *r0, size_t r1)
  23. @
  24. @ Set the r1 bytes beginning with *r0 to 0.
  25. @
  26. .thumb_func
  27. .global __aeabi_memclr
  28. __aeabi_memclr:
  29. eors r2, r2 @ fallthrough to memset
  30. @ void __aeabi_memset(void *r0, size_t r1, int r2)
  31. @
  32. @ Set the r1 bytes beginning with *r0 to r2
  33. @
  34. .thumb_func
  35. .global __aeabi_memset
  36. __aeabi_memset:
  37. @ check if length=0
  38. cmp r1, #0
  39. beq L_return1
  40. movs r3, #1 @ set one byte if odd address
  41. tst r0, r3
  42. beq L_align2
  43. strb r2, [r0]
  44. adds r0, #1
  45. subs r1, #1
  46. beq L_return1
  47. L_align2:
  48. movs r3, #2 @ set one halfword if address is not 32 bit aligned
  49. tst r0, r3
  50. beq __aeabi_memset4
  51. strb r2, [r0]
  52. cmp r1, #1 @ if length is 1 copy only 1 byte
  53. beq L_return1
  54. strb r2, [r0, #1]
  55. adds r0, #2
  56. subs r1, #2
  57. bne __aeabi_memset4
  58. L_return1:
  59. bx lr
  60. @ void __aeabi_memclr4(void *r0, size_t r1)
  61. @
  62. @ Set the r1 bytes beginning with *r0 to 0.
  63. @ r0 must be 4-byte-aligned
  64. @
  65. .thumb_func
  66. .global __aeabi_memclr4
  67. __aeabi_memclr4:
  68. @ void __aeabi_memclr8(void *r0, size_t r1)
  69. @
  70. @ Set the r1 bytes beginning with *r0 to 0.
  71. @ r0 must be 8-byte-aligned
  72. @
  73. .thumb_func
  74. .global __aeabi_memclr8
  75. __aeabi_memclr8:
  76. eors r2, r2 @ fallthrough to memset4
  77. @ void __aeabi_memset4(void *r0, size_t r1, int r2)
  78. @
  79. @ Set the r1 bytes beginning with *r0 to r2.
  80. @ r0 must be 4-byte-aligned
  81. @
  82. .thumb_func
  83. .global __aeabi_memset4
  84. __aeabi_memset4:
  85. @ void __aeabi_memset8(void *r0, size_t r1, int r2)
  86. @
  87. @ Set the r1 bytes beginning with *r0 to r2.
  88. @ r0 must be 8-byte-aligned
  89. @
  90. .thumb_func
  91. .global __aeabi_memset8
  92. __aeabi_memset8:
  93. subs r1, #4
  94. blo L_last_3bytes
  95. lsls r2, r2, #24 @ copy lowest byte of r2 to all other bytes in r2
  96. lsrs r3, r2, #8
  97. orrs r2, r3
  98. lsrs r3, r2, #16
  99. orrs r2, r3
  100. L_loop:
  101. str r2, [r0]
  102. adds r0, #4
  103. subs r1, #4
  104. bhs L_loop
  105. L_last_3bytes: @ r1 = remaining len - 4
  106. adds r1, #2
  107. blo L_one_left @ branch if r1 was -4 or -3
  108. strh r2, [r0]
  109. beq L_return2 @ finished if r1 was -2
  110. strb r2, [r0, #2]
  111. L_return2:
  112. bx lr
  113. L_one_left:
  114. adds r1, #1
  115. bne L_return3
  116. strb r2, [r0]
  117. L_return3:
  118. bx lr