2 * U-boot - bf533_string.c Contains library routines.
4 * Copyright (c) 2005-2007 Analog Devices Inc.
6 * (C) Copyright 2000-2004
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 * See file CREDITS for list of people who contributed to this
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.
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.
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,
30 #include <asm/blackfin.h>
33 #include <asm/mach-common/bits/dma.h>
35 char *strcpy(char *dest
, const char *src
)
41 ("1:\t%2 = B [%1++] (Z);\n\t"
44 "if cc jump 1b (bp);\n":"=a"(dest
), "=a"(src
), "=d"(temp
)
45 :"0"(dest
), "1"(src
), "2"(temp
):"memory");
50 char *strncpy(char *dest
, const char *src
, size_t n
)
59 ("1:\t%3 = B [%1++] (Z);\n\t"
62 "if ! cc jump 2f;\n\t"
65 "if ! cc jump 1b (bp);\n"
66 "2:\n":"=a"(dest
), "=a"(src
), "=da"(n
), "=d"(temp
)
67 :"0"(dest
), "1"(src
), "2"(n
), "3"(temp
)
73 int strcmp(const char *cs
, const char *ct
)
77 __asm__("1:\t%2 = B[%0++] (Z);\n\t" /* get *cs */
78 "%3 = B[%1++] (Z);\n\t" /* get *ct */
79 "CC = %2 == %3;\n\t" /* compare a byte */
80 "if ! cc jump 2f;\n\t" /* not equal, break out */
81 "CC = %2;\n\t" /* at end of cs? */
82 "if cc jump 1b (bp);\n\t" /* no, keep going */
83 "jump.s 3f;\n" /* strings are equal */
84 "2:\t%2 = %2 - %3;\n" /* *cs - *ct */
85 "3:\n": "=a"(cs
), "=a"(ct
), "=d"(__res1
), "=d"(__res2
)
91 int strncmp(const char *cs
, const char *ct
, size_t count
)
98 __asm__("1:\t%3 = B[%0++] (Z);\n\t" /* get *cs */
99 "%4 = B[%1++] (Z);\n\t" /* get *ct */
100 "CC = %3 == %4;\n\t" /* compare a byte */
101 "if ! cc jump 3f;\n\t" /* not equal, break out */
102 "CC = %3;\n\t" /* at end of cs? */
103 "if ! cc jump 4f;\n\t" /* yes, all done */
104 "%2 += -1;\n\t" /* no, adjust count */
105 "CC = %2 == 0;\n\t" "if ! cc jump 1b;\n" /* more to do, keep going */
106 "2:\t%3 = 0;\n\t" /* strings are equal */
107 "jump.s 4f;\n" "3:\t%3 = %3 - %4;\n" /* *cs - *ct */
108 "4:": "=a"(cs
), "=a"(ct
), "=da"(count
), "=d"(__res1
),
110 : "0"(cs
), "1"(ct
), "2"(count
));
115 #ifndef pMDMA_D0_IRQ_STATUS
116 # define pMDMA_D0_IRQ_STATUS pMDMA1_D0_IRQ_STATUS
117 # define pMDMA_D0_START_ADDR pMDMA1_D0_START_ADDR
118 # define pMDMA_D0_X_COUNT pMDMA1_D0_X_COUNT
119 # define pMDMA_D0_X_MODIFY pMDMA1_D0_X_MODIFY
120 # define pMDMA_D0_CONFIG pMDMA1_D0_CONFIG
121 # define pMDMA_S0_IRQ_STATUS pMDMA1_S0_IRQ_STATUS
122 # define pMDMA_S0_START_ADDR pMDMA1_S0_START_ADDR
123 # define pMDMA_S0_X_COUNT pMDMA1_S0_X_COUNT
124 # define pMDMA_S0_X_MODIFY pMDMA1_S0_X_MODIFY
125 # define pMDMA_S0_CONFIG pMDMA1_S0_CONFIG
128 static void *dma_memcpy(void *dest
, const void *src
, size_t count
)
130 *pMDMA_D0_IRQ_STATUS
= DMA_DONE
| DMA_ERR
;
132 /* Copy sram functions from sdram to sram */
133 /* Setup destination start address */
134 *pMDMA_D0_START_ADDR
= (volatile void **)dest
;
135 /* Setup destination xcount */
136 *pMDMA_D0_X_COUNT
= count
;
137 /* Setup destination xmodify */
138 *pMDMA_D0_X_MODIFY
= 1;
140 /* Setup Source start address */
141 *pMDMA_S0_START_ADDR
= (volatile void **)src
;
142 /* Setup Source xcount */
143 *pMDMA_S0_X_COUNT
= count
;
144 /* Setup Source xmodify */
145 *pMDMA_S0_X_MODIFY
= 1;
147 /* Enable source DMA */
148 *pMDMA_S0_CONFIG
= (DMAEN
);
151 *pMDMA_D0_CONFIG
= (WNR
| DMAEN
);
153 while (*pMDMA_D0_IRQ_STATUS
& DMA_RUN
) {
154 *pMDMA_D0_IRQ_STATUS
|= (DMA_DONE
| DMA_ERR
);
156 *pMDMA_D0_IRQ_STATUS
|= (DMA_DONE
| DMA_ERR
);
164 * memcpy - Copy one area of memory to another
165 * @dest: Where to copy to
166 * @src: Where to copy from
167 * @count: The size of the area.
169 * You should not use this function to access IO space, use memcpy_toio()
170 * or memcpy_fromio() instead.
172 extern void *memcpy_ASM(void *dest
, const void *src
, size_t count
);
173 void *memcpy(void *dest
, const void *src
, size_t count
)
175 char *tmp
= (char *) dest
, *s
= (char *) src
;
177 if (dcache_status()) {
178 blackfin_dcache_flush_range(src
, src
+count
);
180 /* L1_INST_SRAM can only be accessed via dma */
181 if ((tmp
>= (char *)L1_INST_SRAM
) && (tmp
< (char *)L1_INST_SRAM_END
)) {
182 /* L1 is the destination */
183 dma_memcpy(dest
,src
,count
);
184 } else if ((s
>= (char *)L1_INST_SRAM
) && (s
< (char *)L1_INST_SRAM_END
)) {
185 /* L1 is the source */
186 dma_memcpy(dest
,src
,count
);
188 if (icache_status()) {
189 blackfin_icache_flush_range(dest
, dest
+count
);
191 if (dcache_status()) {
192 blackfin_dcache_invalidate_range(dest
, dest
+count
);
195 memcpy_ASM(dest
,src
,count
);