string.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. * Copyright (c) 1994, 95, 96, 97, 98, 2000, 01 Ralf Baechle
  7. * Copyright (c) 2000 by Silicon Graphics, Inc.
  8. * Copyright (c) 2001 MIPS Technologies, Inc.
  9. */
  10. #ifndef _ASM_STRING_H
  11. #define _ASM_STRING_H
  12. #include <linux/config.h>
  13. /*
  14. * Most of the inline functions are rather naive implementations so I just
  15. * didn't bother updating them for 64-bit ...
  16. */
  17. #ifdef CONFIG_32BIT
  18. #ifndef IN_STRING_C
  19. #define __HAVE_ARCH_STRCPY
  20. static __inline__ char *strcpy(char *__dest, __const__ char *__src)
  21. {
  22. char *__xdest = __dest;
  23. __asm__ __volatile__(
  24. ".set\tnoreorder\n\t"
  25. ".set\tnoat\n"
  26. "1:\tlbu\t$1,(%1)\n\t"
  27. "addiu\t%1,1\n\t"
  28. "sb\t$1,(%0)\n\t"
  29. "bnez\t$1,1b\n\t"
  30. "addiu\t%0,1\n\t"
  31. ".set\tat\n\t"
  32. ".set\treorder"
  33. : "=r" (__dest), "=r" (__src)
  34. : "0" (__dest), "1" (__src)
  35. : "memory");
  36. return __xdest;
  37. }
  38. #define __HAVE_ARCH_STRNCPY
  39. static __inline__ char *strncpy(char *__dest, __const__ char *__src, size_t __n)
  40. {
  41. char *__xdest = __dest;
  42. if (__n == 0)
  43. return __xdest;
  44. __asm__ __volatile__(
  45. ".set\tnoreorder\n\t"
  46. ".set\tnoat\n"
  47. "1:\tlbu\t$1,(%1)\n\t"
  48. "subu\t%2,1\n\t"
  49. "sb\t$1,(%0)\n\t"
  50. "beqz\t$1,2f\n\t"
  51. "addiu\t%0,1\n\t"
  52. "bnez\t%2,1b\n\t"
  53. "addiu\t%1,1\n"
  54. "2:\n\t"
  55. ".set\tat\n\t"
  56. ".set\treorder"
  57. : "=r" (__dest), "=r" (__src), "=r" (__n)
  58. : "0" (__dest), "1" (__src), "2" (__n)
  59. : "memory");
  60. return __xdest;
  61. }
  62. #define __HAVE_ARCH_STRCMP
  63. static __inline__ int strcmp(__const__ char *__cs, __const__ char *__ct)
  64. {
  65. int __res;
  66. __asm__ __volatile__(
  67. ".set\tnoreorder\n\t"
  68. ".set\tnoat\n\t"
  69. "lbu\t%2,(%0)\n"
  70. "1:\tlbu\t$1,(%1)\n\t"
  71. "addiu\t%0,1\n\t"
  72. "bne\t$1,%2,2f\n\t"
  73. "addiu\t%1,1\n\t"
  74. "bnez\t%2,1b\n\t"
  75. "lbu\t%2,(%0)\n\t"
  76. #if defined(CONFIG_CPU_R3000)
  77. "nop\n\t"
  78. #endif
  79. "move\t%2,$1\n"
  80. "2:\tsubu\t%2,$1\n"
  81. "3:\t.set\tat\n\t"
  82. ".set\treorder"
  83. : "=r" (__cs), "=r" (__ct), "=r" (__res)
  84. : "0" (__cs), "1" (__ct));
  85. return __res;
  86. }
  87. #endif /* !defined(IN_STRING_C) */
  88. #define __HAVE_ARCH_STRNCMP
  89. static __inline__ int
  90. strncmp(__const__ char *__cs, __const__ char *__ct, size_t __count)
  91. {
  92. int __res;
  93. __asm__ __volatile__(
  94. ".set\tnoreorder\n\t"
  95. ".set\tnoat\n"
  96. "1:\tlbu\t%3,(%0)\n\t"
  97. "beqz\t%2,2f\n\t"
  98. "lbu\t$1,(%1)\n\t"
  99. "subu\t%2,1\n\t"
  100. "bne\t$1,%3,3f\n\t"
  101. "addiu\t%0,1\n\t"
  102. "bnez\t%3,1b\n\t"
  103. "addiu\t%1,1\n"
  104. "2:\n\t"
  105. #if defined(CONFIG_CPU_R3000)
  106. "nop\n\t"
  107. #endif
  108. "move\t%3,$1\n"
  109. "3:\tsubu\t%3,$1\n\t"
  110. ".set\tat\n\t"
  111. ".set\treorder"
  112. : "=r" (__cs), "=r" (__ct), "=r" (__count), "=r" (__res)
  113. : "0" (__cs), "1" (__ct), "2" (__count));
  114. return __res;
  115. }
  116. #endif /* CONFIG_32BIT */
  117. #define __HAVE_ARCH_MEMSET
  118. extern void *memset(void *__s, int __c, size_t __count);
  119. #define __HAVE_ARCH_MEMCPY
  120. extern void *memcpy(void *__to, __const__ void *__from, size_t __n);
  121. #define __HAVE_ARCH_MEMMOVE
  122. extern void *memmove(void *__dest, __const__ void *__src, size_t __n);
  123. #ifdef CONFIG_32BIT
  124. #define __HAVE_ARCH_MEMSCAN
  125. static __inline__ void *memscan(void *__addr, int __c, size_t __size)
  126. {
  127. char *__end = (char *)__addr + __size;
  128. unsigned char __uc = (unsigned char) __c;
  129. __asm__(".set\tpush\n\t"
  130. ".set\tnoat\n\t"
  131. ".set\treorder\n\t"
  132. "1:\tbeq\t%0,%1,2f\n\t"
  133. "addiu\t%0,1\n\t"
  134. "lbu\t$1,-1(%0)\n\t"
  135. "bne\t$1,%z4,1b\n"
  136. "2:\t.set\tpop"
  137. : "=r" (__addr), "=r" (__end)
  138. : "0" (__addr), "1" (__end), "Jr" (__uc));
  139. return __addr;
  140. }
  141. #endif /* CONFIG_32BIT */
  142. #endif /* _ASM_STRING_H */