memzero.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * linux/arch/arm/lib/memzero.S
  3. *
  4. * Copyright (C) 1995-2000 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/linkage.h>
  11. #include <asm/assembler.h>
  12. #include <asm/unwind.h>
  13. #include <asm/export.h>
  14. .text
  15. .align 5
  16. .word 0
  17. /*
  18. * Align the pointer in r0. r3 contains the number of bytes that we are
  19. * mis-aligned by, and r1 is the number of bytes. If r1 < 4, then we
  20. * don't bother; we use byte stores instead.
  21. */
  22. UNWIND( .fnstart )
  23. 1: subs r1, r1, #4 @ 1 do we have enough
  24. blt 5f @ 1 bytes to align with?
  25. cmp r3, #2 @ 1
  26. strltb r2, [r0], #1 @ 1
  27. strleb r2, [r0], #1 @ 1
  28. strb r2, [r0], #1 @ 1
  29. add r1, r1, r3 @ 1 (r1 = r1 - (4 - r3))
  30. /*
  31. * The pointer is now aligned and the length is adjusted. Try doing the
  32. * memzero again.
  33. */
  34. ENTRY(__memzero)
  35. mov r2, #0 @ 1
  36. ands r3, r0, #3 @ 1 unaligned?
  37. bne 1b @ 1
  38. /*
  39. * r3 = 0, and we know that the pointer in r0 is aligned to a word boundary.
  40. */
  41. cmp r1, #16 @ 1 we can skip this chunk if we
  42. blt 4f @ 1 have < 16 bytes
  43. #if ! CALGN(1)+0
  44. /*
  45. * We need an extra register for this loop - save the return address and
  46. * use the LR
  47. */
  48. str lr, [sp, #-4]! @ 1
  49. UNWIND( .fnend )
  50. UNWIND( .fnstart )
  51. UNWIND( .save {lr} )
  52. mov ip, r2 @ 1
  53. mov lr, r2 @ 1
  54. 3: subs r1, r1, #64 @ 1 write 32 bytes out per loop
  55. stmgeia r0!, {r2, r3, ip, lr} @ 4
  56. stmgeia r0!, {r2, r3, ip, lr} @ 4
  57. stmgeia r0!, {r2, r3, ip, lr} @ 4
  58. stmgeia r0!, {r2, r3, ip, lr} @ 4
  59. bgt 3b @ 1
  60. ldmeqfd sp!, {pc} @ 1/2 quick exit
  61. /*
  62. * No need to correct the count; we're only testing bits from now on
  63. */
  64. tst r1, #32 @ 1
  65. stmneia r0!, {r2, r3, ip, lr} @ 4
  66. stmneia r0!, {r2, r3, ip, lr} @ 4
  67. tst r1, #16 @ 1 16 bytes or more?
  68. stmneia r0!, {r2, r3, ip, lr} @ 4
  69. ldr lr, [sp], #4 @ 1
  70. UNWIND( .fnend )
  71. #else
  72. /*
  73. * This version aligns the destination pointer in order to write
  74. * whole cache lines at once.
  75. */
  76. stmfd sp!, {r4-r7, lr}
  77. UNWIND( .fnend )
  78. UNWIND( .fnstart )
  79. UNWIND( .save {r4-r7, lr} )
  80. mov r4, r2
  81. mov r5, r2
  82. mov r6, r2
  83. mov r7, r2
  84. mov ip, r2
  85. mov lr, r2
  86. cmp r1, #96
  87. andgts ip, r0, #31
  88. ble 3f
  89. rsb ip, ip, #32
  90. sub r1, r1, ip
  91. movs ip, ip, lsl #(32 - 4)
  92. stmcsia r0!, {r4, r5, r6, r7}
  93. stmmiia r0!, {r4, r5}
  94. movs ip, ip, lsl #2
  95. strcs r2, [r0], #4
  96. 3: subs r1, r1, #64
  97. stmgeia r0!, {r2-r7, ip, lr}
  98. stmgeia r0!, {r2-r7, ip, lr}
  99. bgt 3b
  100. ldmeqfd sp!, {r4-r7, pc}
  101. tst r1, #32
  102. stmneia r0!, {r2-r7, ip, lr}
  103. tst r1, #16
  104. stmneia r0!, {r4-r7}
  105. ldmfd sp!, {r4-r7, lr}
  106. UNWIND( .fnend )
  107. #endif
  108. UNWIND( .fnstart )
  109. 4: tst r1, #8 @ 1 8 bytes or more?
  110. stmneia r0!, {r2, r3} @ 2
  111. tst r1, #4 @ 1 4 bytes or more?
  112. strne r2, [r0], #4 @ 1
  113. /*
  114. * When we get here, we've got less than 4 bytes to zero. We
  115. * may have an unaligned pointer as well.
  116. */
  117. 5: tst r1, #2 @ 1 2 bytes or more?
  118. strneb r2, [r0], #1 @ 1
  119. strneb r2, [r0], #1 @ 1
  120. tst r1, #1 @ 1 a byte left over
  121. strneb r2, [r0], #1 @ 1
  122. ret lr @ 1
  123. UNWIND( .fnend )
  124. ENDPROC(__memzero)
  125. EXPORT_SYMBOL(__memzero)