string.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file COPYING in the main directory of this archive
  4. * for more details.
  5. */
  6. #define __IN_STRING_C
  7. #include <linux/module.h>
  8. #include <linux/string.h>
  9. char *strcpy(char *dest, const char *src)
  10. {
  11. return __kernel_strcpy(dest, src);
  12. }
  13. EXPORT_SYMBOL(strcpy);
  14. char *strcat(char *dest, const char *src)
  15. {
  16. return __kernel_strcpy(dest + __kernel_strlen(dest), src);
  17. }
  18. EXPORT_SYMBOL(strcat);
  19. void *memset(void *s, int c, size_t count)
  20. {
  21. void *xs = s;
  22. size_t temp, temp1;
  23. if (!count)
  24. return xs;
  25. c &= 0xff;
  26. c |= c << 8;
  27. c |= c << 16;
  28. if ((long)s & 1) {
  29. char *cs = s;
  30. *cs++ = c;
  31. s = cs;
  32. count--;
  33. }
  34. if (count > 2 && (long)s & 2) {
  35. short *ss = s;
  36. *ss++ = c;
  37. s = ss;
  38. count -= 2;
  39. }
  40. temp = count >> 2;
  41. if (temp) {
  42. long *ls = s;
  43. asm volatile (
  44. " movel %1,%2\n"
  45. " andw #7,%2\n"
  46. " lsrl #3,%1\n"
  47. " negw %2\n"
  48. " jmp %%pc@(2f,%2:w:2)\n"
  49. "1: movel %3,%0@+\n"
  50. " movel %3,%0@+\n"
  51. " movel %3,%0@+\n"
  52. " movel %3,%0@+\n"
  53. " movel %3,%0@+\n"
  54. " movel %3,%0@+\n"
  55. " movel %3,%0@+\n"
  56. " movel %3,%0@+\n"
  57. "2: dbra %1,1b\n"
  58. " clrw %1\n"
  59. " subql #1,%1\n"
  60. " jpl 1b"
  61. : "=a" (ls), "=d" (temp), "=&d" (temp1)
  62. : "d" (c), "0" (ls), "1" (temp));
  63. s = ls;
  64. }
  65. if (count & 2) {
  66. short *ss = s;
  67. *ss++ = c;
  68. s = ss;
  69. }
  70. if (count & 1) {
  71. char *cs = s;
  72. *cs = c;
  73. }
  74. return xs;
  75. }
  76. EXPORT_SYMBOL(memset);
  77. void *memcpy(void *to, const void *from, size_t n)
  78. {
  79. void *xto = to;
  80. size_t temp, temp1;
  81. if (!n)
  82. return xto;
  83. if ((long)to & 1) {
  84. char *cto = to;
  85. const char *cfrom = from;
  86. *cto++ = *cfrom++;
  87. to = cto;
  88. from = cfrom;
  89. n--;
  90. }
  91. if (n > 2 && (long)to & 2) {
  92. short *sto = to;
  93. const short *sfrom = from;
  94. *sto++ = *sfrom++;
  95. to = sto;
  96. from = sfrom;
  97. n -= 2;
  98. }
  99. temp = n >> 2;
  100. if (temp) {
  101. long *lto = to;
  102. const long *lfrom = from;
  103. asm volatile (
  104. " movel %2,%3\n"
  105. " andw #7,%3\n"
  106. " lsrl #3,%2\n"
  107. " negw %3\n"
  108. " jmp %%pc@(1f,%3:w:2)\n"
  109. "4: movel %0@+,%1@+\n"
  110. " movel %0@+,%1@+\n"
  111. " movel %0@+,%1@+\n"
  112. " movel %0@+,%1@+\n"
  113. " movel %0@+,%1@+\n"
  114. " movel %0@+,%1@+\n"
  115. " movel %0@+,%1@+\n"
  116. " movel %0@+,%1@+\n"
  117. "1: dbra %2,4b\n"
  118. " clrw %2\n"
  119. " subql #1,%2\n"
  120. " jpl 4b"
  121. : "=a" (lfrom), "=a" (lto), "=d" (temp), "=&d" (temp1)
  122. : "0" (lfrom), "1" (lto), "2" (temp));
  123. to = lto;
  124. from = lfrom;
  125. }
  126. if (n & 2) {
  127. short *sto = to;
  128. const short *sfrom = from;
  129. *sto++ = *sfrom++;
  130. to = sto;
  131. from = sfrom;
  132. }
  133. if (n & 1) {
  134. char *cto = to;
  135. const char *cfrom = from;
  136. *cto = *cfrom;
  137. }
  138. return xto;
  139. }
  140. EXPORT_SYMBOL(memcpy);