bf533_string.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * U-boot - bf533_string.c Contains library routines.
  3. *
  4. * Copyright (c) 2005 blackfin.uclinux.org
  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., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <asm/setup.h>
  29. #include <asm/page.h>
  30. #include <asm/cpu/defBF533.h>
  31. void *dma_memcpy(void *,const void *,size_t);
  32. char *strcpy(char *dest, const char *src)
  33. {
  34. char *xdest = dest;
  35. char temp = 0;
  36. __asm__ __volatile__
  37. ("1:\t%2 = B [%1++] (Z);\n\t"
  38. "B [%0++] = %2;\n\t"
  39. "CC = %2;\n\t"
  40. "if cc jump 1b (bp);\n":"=a"(dest), "=a"(src), "=d"(temp)
  41. :"0"(dest), "1"(src), "2"(temp):"memory");
  42. return xdest;
  43. }
  44. char *strncpy(char *dest, const char *src, size_t n)
  45. {
  46. char *xdest = dest;
  47. char temp = 0;
  48. if (n == 0)
  49. return xdest;
  50. __asm__ __volatile__
  51. ("1:\t%3 = B [%1++] (Z);\n\t"
  52. "B [%0++] = %3;\n\t"
  53. "CC = %3;\n\t"
  54. "if ! cc jump 2f;\n\t"
  55. "%2 += -1;\n\t"
  56. "CC = %2 == 0;\n\t"
  57. "if ! cc jump 1b (bp);\n"
  58. "2:\n":"=a"(dest), "=a"(src), "=da"(n), "=d"(temp)
  59. :"0"(dest), "1"(src), "2"(n), "3"(temp)
  60. :"memory");
  61. return xdest;
  62. }
  63. int strcmp(const char *cs, const char *ct)
  64. {
  65. char __res1, __res2;
  66. __asm__
  67. ("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),
  76. "=d"(__res2)
  77. : "0"(cs), "1"(ct));
  78. return __res1;
  79. }
  80. int strncmp(const char *cs, const char *ct, size_t count)
  81. {
  82. char __res1, __res2;
  83. if (!count)
  84. return 0;
  85. __asm__
  86. ("1:\t%3 = B[%0++] (Z);\n\t" /* get *cs */
  87. "%4 = B[%1++] (Z);\n\t" /* get *ct */
  88. "CC = %3 == %4;\n\t" /* compare a byte */
  89. "if ! cc jump 3f;\n\t" /* not equal, break out */
  90. "CC = %3;\n\t" /* at end of cs? */
  91. "if ! cc jump 4f;\n\t" /* yes, all done */
  92. "%2 += -1;\n\t" /* no, adjust count */
  93. "CC = %2 == 0;\n\t" "if ! cc jump 1b;\n" /* more to do, keep going */
  94. "2:\t%3 = 0;\n\t" /* strings are equal */
  95. "jump.s 4f;\n" "3:\t%3 = %3 - %4;\n" /* *cs - *ct */
  96. "4:": "=a"(cs), "=a"(ct), "=da"(count), "=d"(__res1),
  97. "=d"(__res2)
  98. : "0"(cs), "1"(ct), "2"(count));
  99. return __res1;
  100. }
  101. /*
  102. * memcpy - Copy one area of memory to another
  103. * @dest: Where to copy to
  104. * @src: Where to copy from
  105. * @count: The size of the area.
  106. *
  107. * You should not use this function to access IO space, use memcpy_toio()
  108. * or memcpy_fromio() instead.
  109. */
  110. void * memcpy(void * dest,const void *src,size_t count)
  111. {
  112. char *tmp = (char *) dest, *s = (char *) src;
  113. /* Turn off the cache, if destination in the L1 memory */
  114. if ( (tmp >= (char *)L1_ISRAM) && (tmp < (char *)L1_ISRAM_END)
  115. || (tmp >= (char *)DATA_BANKA_SRAM) && (tmp < DATA_BANKA_SRAM_END)
  116. || (tmp >= (char *)DATA_BANKB_SRAM) && (tmp < DATA_BANKB_SRAM_END) ){
  117. if(icache_status()){
  118. blackfin_icache_flush_range(src, src+count);
  119. icache_disable();
  120. }
  121. if(dcache_status()){
  122. blackfin_dcache_flush_range(src, src+count);
  123. dcache_disable();
  124. }
  125. dma_memcpy(dest,src,count);
  126. }else{
  127. while(count--)
  128. *tmp++ = *s++;
  129. }
  130. return dest;
  131. }
  132. void *dma_memcpy(void * dest,const void *src,size_t count)
  133. {
  134. *pMDMA_D0_IRQ_STATUS = DMA_DONE | DMA_ERR;
  135. /* Copy sram functions from sdram to sram */
  136. /* Setup destination start address */
  137. *pMDMA_D0_START_ADDR = (volatile void **)dest;
  138. /* Setup destination xcount */
  139. *pMDMA_D0_X_COUNT = count ;
  140. /* Setup destination xmodify */
  141. *pMDMA_D0_X_MODIFY = 1;
  142. /* Setup Source start address */
  143. *pMDMA_S0_START_ADDR = (volatile void **)src;
  144. /* Setup Source xcount */
  145. *pMDMA_S0_X_COUNT = count;
  146. /* Setup Source xmodify */
  147. *pMDMA_S0_X_MODIFY = 1;
  148. /* Enable source DMA */
  149. *pMDMA_S0_CONFIG = (DMAEN);
  150. asm("ssync;");
  151. *pMDMA_D0_CONFIG = ( WNR | DMAEN);
  152. while(*pMDMA_D0_IRQ_STATUS & DMA_RUN){
  153. *pMDMA_D0_IRQ_STATUS |= (DMA_DONE | DMA_ERR);
  154. }
  155. *pMDMA_D0_IRQ_STATUS |= (DMA_DONE | DMA_ERR);
  156. dest += count;
  157. src += count;
  158. return dest;
  159. }