bf533_string.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 <config.h>
  29. #include <asm/blackfin.h>
  30. #include <asm/io.h>
  31. #include "cache.h"
  32. #include <asm/mach-common/bits/dma.h>
  33. char *strcpy(char *dest, const char *src)
  34. {
  35. char *xdest = dest;
  36. char temp = 0;
  37. __asm__ __volatile__
  38. ("1:\t%2 = B [%1++] (Z);\n\t"
  39. "B [%0++] = %2;\n\t"
  40. "CC = %2;\n\t"
  41. "if cc jump 1b (bp);\n":"=a"(dest), "=a"(src), "=d"(temp)
  42. :"0"(dest), "1"(src), "2"(temp):"memory");
  43. return xdest;
  44. }
  45. char *strncpy(char *dest, const char *src, size_t n)
  46. {
  47. char *xdest = dest;
  48. char temp = 0;
  49. if (n == 0)
  50. return xdest;
  51. __asm__ __volatile__
  52. ("1:\t%3 = B [%1++] (Z);\n\t"
  53. "B [%0++] = %3;\n\t"
  54. "CC = %3;\n\t"
  55. "if ! cc jump 2f;\n\t"
  56. "%2 += -1;\n\t"
  57. "CC = %2 == 0;\n\t"
  58. "if ! cc jump 1b (bp);\n"
  59. "2:\n":"=a"(dest), "=a"(src), "=da"(n), "=d"(temp)
  60. :"0"(dest), "1"(src), "2"(n), "3"(temp)
  61. :"memory");
  62. return xdest;
  63. }
  64. int strcmp(const char *cs, const char *ct)
  65. {
  66. char __res1, __res2;
  67. __asm__("1:\t%2 = B[%0++] (Z);\n\t" /* get *cs */
  68. "%3 = B[%1++] (Z);\n\t" /* get *ct */
  69. "CC = %2 == %3;\n\t" /* compare a byte */
  70. "if ! cc jump 2f;\n\t" /* not equal, break out */
  71. "CC = %2;\n\t" /* at end of cs? */
  72. "if cc jump 1b (bp);\n\t" /* no, keep going */
  73. "jump.s 3f;\n" /* strings are equal */
  74. "2:\t%2 = %2 - %3;\n" /* *cs - *ct */
  75. "3:\n": "=a"(cs), "=a"(ct), "=d"(__res1), "=d"(__res2)
  76. : "0"(cs), "1"(ct));
  77. return __res1;
  78. }
  79. int strncmp(const char *cs, const char *ct, size_t count)
  80. {
  81. char __res1, __res2;
  82. if (!count)
  83. return 0;
  84. __asm__("1:\t%3 = B[%0++] (Z);\n\t" /* get *cs */
  85. "%4 = B[%1++] (Z);\n\t" /* get *ct */
  86. "CC = %3 == %4;\n\t" /* compare a byte */
  87. "if ! cc jump 3f;\n\t" /* not equal, break out */
  88. "CC = %3;\n\t" /* at end of cs? */
  89. "if ! cc jump 4f;\n\t" /* yes, all done */
  90. "%2 += -1;\n\t" /* no, adjust count */
  91. "CC = %2 == 0;\n\t" "if ! cc jump 1b;\n" /* more to do, keep going */
  92. "2:\t%3 = 0;\n\t" /* strings are equal */
  93. "jump.s 4f;\n" "3:\t%3 = %3 - %4;\n" /* *cs - *ct */
  94. "4:": "=a"(cs), "=a"(ct), "=da"(count), "=d"(__res1),
  95. "=d"(__res2)
  96. : "0"(cs), "1"(ct), "2"(count));
  97. return __res1;
  98. }
  99. #ifndef pMDMA_D0_IRQ_STATUS
  100. # define pMDMA_D0_IRQ_STATUS pMDMA1_D0_IRQ_STATUS
  101. # define pMDMA_D0_START_ADDR pMDMA1_D0_START_ADDR
  102. # define pMDMA_D0_X_COUNT pMDMA1_D0_X_COUNT
  103. # define pMDMA_D0_X_MODIFY pMDMA1_D0_X_MODIFY
  104. # define pMDMA_D0_CONFIG pMDMA1_D0_CONFIG
  105. # define pMDMA_S0_IRQ_STATUS pMDMA1_S0_IRQ_STATUS
  106. # define pMDMA_S0_START_ADDR pMDMA1_S0_START_ADDR
  107. # define pMDMA_S0_X_COUNT pMDMA1_S0_X_COUNT
  108. # define pMDMA_S0_X_MODIFY pMDMA1_S0_X_MODIFY
  109. # define pMDMA_S0_CONFIG pMDMA1_S0_CONFIG
  110. #endif
  111. static void *dma_memcpy(void *dest, const void *src, size_t count)
  112. {
  113. *pMDMA_D0_IRQ_STATUS = DMA_DONE | DMA_ERR;
  114. /* Copy sram functions from sdram to sram */
  115. /* Setup destination start address */
  116. *pMDMA_D0_START_ADDR = (volatile void **)dest;
  117. /* Setup destination xcount */
  118. *pMDMA_D0_X_COUNT = count;
  119. /* Setup destination xmodify */
  120. *pMDMA_D0_X_MODIFY = 1;
  121. /* Setup Source start address */
  122. *pMDMA_S0_START_ADDR = (volatile void **)src;
  123. /* Setup Source xcount */
  124. *pMDMA_S0_X_COUNT = count;
  125. /* Setup Source xmodify */
  126. *pMDMA_S0_X_MODIFY = 1;
  127. /* Enable source DMA */
  128. *pMDMA_S0_CONFIG = (DMAEN);
  129. SSYNC();
  130. *pMDMA_D0_CONFIG = (WNR | DMAEN);
  131. while (*pMDMA_D0_IRQ_STATUS & DMA_RUN) {
  132. *pMDMA_D0_IRQ_STATUS |= (DMA_DONE | DMA_ERR);
  133. }
  134. *pMDMA_D0_IRQ_STATUS |= (DMA_DONE | DMA_ERR);
  135. dest += count;
  136. src += count;
  137. return dest;
  138. }
  139. /*
  140. * memcpy - Copy one area of memory to another
  141. * @dest: Where to copy to
  142. * @src: Where to copy from
  143. * @count: The size of the area.
  144. *
  145. * You should not use this function to access IO space, use memcpy_toio()
  146. * or memcpy_fromio() instead.
  147. */
  148. extern void *memcpy_ASM(void *dest, const void *src, size_t count);
  149. void *memcpy(void *dest, const void *src, size_t count)
  150. {
  151. char *tmp = (char *) dest, *s = (char *) src;
  152. if (dcache_status()) {
  153. blackfin_dcache_flush_range(src, src+count);
  154. }
  155. /* L1_INST_SRAM can only be accessed via dma */
  156. if ((tmp >= (char *)L1_INST_SRAM) && (tmp < (char *)L1_INST_SRAM_END)) {
  157. /* L1 is the destination */
  158. dma_memcpy(dest,src,count);
  159. } else if ((s >= (char *)L1_INST_SRAM) && (s < (char *)L1_INST_SRAM_END)) {
  160. /* L1 is the source */
  161. dma_memcpy(dest,src,count);
  162. if (icache_status()) {
  163. blackfin_icache_flush_range(dest, dest+count);
  164. }
  165. if (dcache_status()) {
  166. blackfin_dcache_invalidate_range(dest, dest+count);
  167. }
  168. } else {
  169. memcpy_ASM(dest,src,count);
  170. }
  171. return dest;
  172. }