bf533_string.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * U-boot - bf533_string.c Contains library routines.
  3. *
  4. * Copyright (c) 2005-2007 Analog Devices Inc.
  5. *
  6. * (C) Copyright 2000-2004
  7. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  25. * MA 02110-1301 USA
  26. */
  27. #include <common.h>
  28. #include <asm/setup.h>
  29. #include <config.h>
  30. #include <asm/blackfin.h>
  31. #include <asm/io.h>
  32. extern void blackfin_icache_flush_range(const void *, const void *);
  33. extern void blackfin_dcache_flush_range(const void *, const void *);
  34. extern void *memcpy_ASM(void *dest, const void *src, size_t count);
  35. void *dma_memcpy(void *, const void *, size_t);
  36. char *strcpy(char *dest, const char *src)
  37. {
  38. char *xdest = dest;
  39. char temp = 0;
  40. __asm__ __volatile__
  41. ("1:\t%2 = B [%1++] (Z);\n\t"
  42. "B [%0++] = %2;\n\t"
  43. "CC = %2;\n\t"
  44. "if cc jump 1b (bp);\n":"=a"(dest), "=a"(src), "=d"(temp)
  45. :"0"(dest), "1"(src), "2"(temp):"memory");
  46. return xdest;
  47. }
  48. char *strncpy(char *dest, const char *src, size_t n)
  49. {
  50. char *xdest = dest;
  51. char temp = 0;
  52. if (n == 0)
  53. return xdest;
  54. __asm__ __volatile__
  55. ("1:\t%3 = B [%1++] (Z);\n\t"
  56. "B [%0++] = %3;\n\t"
  57. "CC = %3;\n\t"
  58. "if ! cc jump 2f;\n\t"
  59. "%2 += -1;\n\t"
  60. "CC = %2 == 0;\n\t"
  61. "if ! cc jump 1b (bp);\n"
  62. "2:\n":"=a"(dest), "=a"(src), "=da"(n), "=d"(temp)
  63. :"0"(dest), "1"(src), "2"(n), "3"(temp)
  64. :"memory");
  65. return xdest;
  66. }
  67. int strcmp(const char *cs, const char *ct)
  68. {
  69. char __res1, __res2;
  70. __asm__("1:\t%2 = B[%0++] (Z);\n\t" /* get *cs */
  71. "%3 = B[%1++] (Z);\n\t" /* get *ct */
  72. "CC = %2 == %3;\n\t" /* compare a byte */
  73. "if ! cc jump 2f;\n\t" /* not equal, break out */
  74. "CC = %2;\n\t" /* at end of cs? */
  75. "if cc jump 1b (bp);\n\t" /* no, keep going */
  76. "jump.s 3f;\n" /* strings are equal */
  77. "2:\t%2 = %2 - %3;\n" /* *cs - *ct */
  78. "3:\n": "=a"(cs), "=a"(ct), "=d"(__res1), "=d"(__res2)
  79. : "0"(cs), "1"(ct));
  80. return __res1;
  81. }
  82. int strncmp(const char *cs, const char *ct, size_t count)
  83. {
  84. char __res1, __res2;
  85. if (!count)
  86. return 0;
  87. __asm__("1:\t%3 = B[%0++] (Z);\n\t" /* get *cs */
  88. "%4 = B[%1++] (Z);\n\t" /* get *ct */
  89. "CC = %3 == %4;\n\t" /* compare a byte */
  90. "if ! cc jump 3f;\n\t" /* not equal, break out */
  91. "CC = %3;\n\t" /* at end of cs? */
  92. "if ! cc jump 4f;\n\t" /* yes, all done */
  93. "%2 += -1;\n\t" /* no, adjust count */
  94. "CC = %2 == 0;\n\t" "if ! cc jump 1b;\n" /* more to do, keep going */
  95. "2:\t%3 = 0;\n\t" /* strings are equal */
  96. "jump.s 4f;\n" "3:\t%3 = %3 - %4;\n" /* *cs - *ct */
  97. "4:": "=a"(cs), "=a"(ct), "=da"(count), "=d"(__res1),
  98. "=d"(__res2)
  99. : "0"(cs), "1"(ct), "2"(count));
  100. return __res1;
  101. }
  102. /*
  103. * memcpy - Copy one area of memory to another
  104. * @dest: Where to copy to
  105. * @src: Where to copy from
  106. * @count: The size of the area.
  107. *
  108. * You should not use this function to access IO space, use memcpy_toio()
  109. * or memcpy_fromio() instead.
  110. */
  111. void *memcpy(void *dest, const void *src, size_t count)
  112. {
  113. char *tmp = (char *)dest, *s = (char *)src;
  114. /* L1_ISRAM can only be accessed via dma */
  115. if ((tmp >= (char *)L1_ISRAM) && (tmp < (char *)L1_ISRAM_END)) {
  116. /* L1 is the destination */
  117. dma_memcpy(dest, src, count);
  118. if (icache_status()) {
  119. blackfin_icache_flush_range(src, src + count);
  120. }
  121. } else if ((s >= (char *)L1_ISRAM) && (s < (char *)L1_ISRAM_END)) {
  122. /* L1 is the source */
  123. dma_memcpy(dest, src, count);
  124. if (icache_status()) {
  125. blackfin_icache_flush_range(dest, dest + count);
  126. }
  127. if (dcache_status()) {
  128. blackfin_dcache_flush_range(dest, dest + count);
  129. }
  130. } else {
  131. memcpy_ASM(dest, src, count);
  132. }
  133. return dest;
  134. }
  135. void *dma_memcpy(void *dest, const void *src, size_t count)
  136. {
  137. *pMDMA_D0_IRQ_STATUS = DMA_DONE | DMA_ERR;
  138. /* Copy sram functions from sdram to sram */
  139. /* Setup destination start address */
  140. *pMDMA_D0_START_ADDR = (volatile void **)dest;
  141. /* Setup destination xcount */
  142. *pMDMA_D0_X_COUNT = count;
  143. /* Setup destination xmodify */
  144. *pMDMA_D0_X_MODIFY = 1;
  145. /* Setup Source start address */
  146. *pMDMA_S0_START_ADDR = (volatile void **)src;
  147. /* Setup Source xcount */
  148. *pMDMA_S0_X_COUNT = count;
  149. /* Setup Source xmodify */
  150. *pMDMA_S0_X_MODIFY = 1;
  151. /* Enable source DMA */
  152. *pMDMA_S0_CONFIG = (DMAEN);
  153. sync();
  154. *pMDMA_D0_CONFIG = (WNR | DMAEN);
  155. while (*pMDMA_D0_IRQ_STATUS & DMA_RUN) {
  156. *pMDMA_D0_IRQ_STATUS |= (DMA_DONE | DMA_ERR);
  157. }
  158. *pMDMA_D0_IRQ_STATUS |= (DMA_DONE | DMA_ERR);
  159. dest += count;
  160. src += count;
  161. return dest;
  162. }