memcpy.S 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * File: arch/blackfin/lib/memcpy.S
  3. * Based on:
  4. * Author:
  5. *
  6. * Created:
  7. * Description: internal version of memcpy(), issued by the compiler
  8. * to copy blocks of data around.
  9. * This is really memmove() - it has to be able to deal with
  10. * possible overlaps, because that ambiguity is when the compiler
  11. * gives up and calls a function. We have our own, internal version
  12. * so that we get something we trust, even if the user has redefined
  13. * the normal symbol.
  14. *
  15. * Modified:
  16. * Copyright 2004-2006 Analog Devices Inc.
  17. *
  18. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  19. *
  20. * This program is free software; you can redistribute it and/or modify
  21. * it under the terms of the GNU General Public License as published by
  22. * the Free Software Foundation; either version 2 of the License, or
  23. * (at your option) any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License
  31. * along with this program; if not, see the file COPYING, or write
  32. * to the Free Software Foundation, Inc.,
  33. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  34. */
  35. #include <linux/linkage.h>
  36. /* void *memcpy(void *dest, const void *src, size_t n);
  37. * R0 = To Address (dest) (leave unchanged to form result)
  38. * R1 = From Address (src)
  39. * R2 = count
  40. *
  41. * Note: Favours word alignment
  42. */
  43. #ifdef CONFIG_MEMCPY_L1
  44. .section .l1.text
  45. #else
  46. .text
  47. #endif
  48. .align 2
  49. ENTRY(_memcpy)
  50. CC = R2 <= 0; /* length not positive? */
  51. IF CC JUMP .L_P1L2147483647; /* Nothing to do */
  52. P0 = R0 ; /* dst*/
  53. P1 = R1 ; /* src*/
  54. P2 = R2 ; /* length */
  55. /* check for overlapping data */
  56. CC = R1 < R0; /* src < dst */
  57. IF !CC JUMP .Lno_overlap;
  58. R3 = R1 + R2;
  59. CC = R0 < R3; /* and dst < src+len */
  60. IF CC JUMP .Lhas_overlap;
  61. .Lno_overlap:
  62. /* Check for aligned data.*/
  63. R3 = R1 | R0;
  64. R0 = 0x3;
  65. R3 = R3 & R0;
  66. CC = R3; /* low bits set on either address? */
  67. IF CC JUMP .Lnot_aligned;
  68. /* Both addresses are word-aligned, so we can copy
  69. at least part of the data using word copies.*/
  70. P2 = P2 >> 2;
  71. CC = P2 <= 2;
  72. IF !CC JUMP .Lmore_than_seven;
  73. /* less than eight bytes... */
  74. P2 = R2;
  75. LSETUP(.Lthree_start, .Lthree_end) LC0=P2;
  76. R0 = R1; /* setup src address for return */
  77. .Lthree_start:
  78. R3 = B[P1++] (X);
  79. .Lthree_end:
  80. B[P0++] = R3;
  81. RTS;
  82. .Lmore_than_seven:
  83. /* There's at least eight bytes to copy. */
  84. P2 += -1; /* because we unroll one iteration */
  85. LSETUP(.Lword_loop, .Lword_loop) LC0=P2;
  86. R0 = R1;
  87. I1 = P1;
  88. R3 = [I1++];
  89. .Lword_loop:
  90. MNOP || [P0++] = R3 || R3 = [I1++];
  91. [P0++] = R3;
  92. /* Any remaining bytes to copy? */
  93. R3 = 0x3;
  94. R3 = R2 & R3;
  95. CC = R3 == 0;
  96. P1 = I1; /* in case there's something left, */
  97. IF !CC JUMP .Lbytes_left;
  98. RTS;
  99. .Lbytes_left: P2 = R3;
  100. .Lnot_aligned:
  101. /* From here, we're copying byte-by-byte. */
  102. LSETUP (.Lbyte_start, .Lbyte_end) LC0=P2;
  103. R0 = R1; /* Save src address for return */
  104. .Lbyte_start:
  105. R1 = B[P1++] (X);
  106. .Lbyte_end:
  107. B[P0++] = R1;
  108. .L_P1L2147483647:
  109. RTS;
  110. .Lhas_overlap:
  111. /* Need to reverse the copying, because the
  112. * dst would clobber the src.
  113. * Don't bother to work out alignment for
  114. * the reverse case.
  115. */
  116. R0 = R1; /* save src for later. */
  117. P0 = P0 + P2;
  118. P0 += -1;
  119. P1 = P1 + P2;
  120. P1 += -1;
  121. LSETUP(.Lover_start, .Lover_end) LC0=P2;
  122. .Lover_start:
  123. R1 = B[P1--] (X);
  124. .Lover_end:
  125. B[P0--] = R1;
  126. RTS;