]> git.ipfire.org Git - people/ms/u-boot.git/blame - lib_blackfin/bf533_string.c
* Add support for ymodem protocol download
[people/ms/u-boot.git] / lib_blackfin / bf533_string.c
CommitLineData
6cb142fa
WD
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
28#include <common.h>
29#include <asm/setup.h>
30#include <asm/page.h>
31#include <asm/cpu/defBF533.h>
32
33void *dma_memcpy(void *,const void *,size_t);
34
35char *strcpy(char *dest, const char *src)
36{
37 char *xdest = dest;
38 char temp = 0;
39
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
47 return xdest;
48}
49
50char *strncpy(char *dest, const char *src, size_t n)
51{
52 char *xdest = dest;
53 char temp = 0;
54
55 if (n == 0)
56 return xdest;
57
58 __asm__ __volatile__
59 ("1:\t%3 = B [%1++] (Z);\n\t"
60 "B [%0++] = %3;\n\t"
61 "CC = %3;\n\t"
62 "if ! cc jump 2f;\n\t"
63 "%2 += -1;\n\t"
64 "CC = %2 == 0;\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)
68 :"memory");
69
70 return xdest;
71}
72
73int strcmp(const char *cs, const char *ct)
74{
75 char __res1, __res2;
76
77 __asm__
78 ("1:\t%2 = B[%0++] (Z);\n\t" /* get *cs */
79 "%3 = B[%1++] (Z);\n\t" /* get *ct */
80 "CC = %2 == %3;\n\t" /* compare a byte */
81 "if ! cc jump 2f;\n\t" /* not equal, break out */
82 "CC = %2;\n\t" /* at end of cs? */
83 "if cc jump 1b (bp);\n\t" /* no, keep going */
84 "jump.s 3f;\n" /* strings are equal */
85 "2:\t%2 = %2 - %3;\n" /* *cs - *ct */
86 "3:\n": "=a"(cs), "=a"(ct), "=d"(__res1),
87 "=d"(__res2)
88 : "0"(cs), "1"(ct));
89
90 return __res1;
91}
92
93int strncmp(const char *cs, const char *ct, size_t count)
94{
95 char __res1, __res2;
96
97 if (!count)
98 return 0;
99
100 __asm__
101 ("1:\t%3 = B[%0++] (Z);\n\t" /* get *cs */
102 "%4 = B[%1++] (Z);\n\t" /* get *ct */
103 "CC = %3 == %4;\n\t" /* compare a byte */
104 "if ! cc jump 3f;\n\t" /* not equal, break out */
105 "CC = %3;\n\t" /* at end of cs? */
106 "if ! cc jump 4f;\n\t" /* yes, all done */
107 "%2 += -1;\n\t" /* no, adjust count */
108 "CC = %2 == 0;\n\t" "if ! cc jump 1b;\n" /* more to do, keep going */
109 "2:\t%3 = 0;\n\t" /* strings are equal */
110 "jump.s 4f;\n" "3:\t%3 = %3 - %4;\n" /* *cs - *ct */
111 "4:": "=a"(cs), "=a"(ct), "=da"(count), "=d"(__res1),
112 "=d"(__res2)
113 : "0"(cs), "1"(ct), "2"(count));
114
115 return __res1;
116}
117
118/*
119 * memcpy - Copy one area of memory to another
120 * @dest: Where to copy to
121 * @src: Where to copy from
122 * @count: The size of the area.
123 *
124 * You should not use this function to access IO space, use memcpy_toio()
125 * or memcpy_fromio() instead.
126 */
127void * memcpy(void * dest,const void *src,size_t count)
128{
129 char *tmp = (char *) dest, *s = (char *) src;
8e7b703a 130
6cb142fa
WD
131/* Turn off the cache, if destination in the L1 memory */
132 if ( (tmp >= (char *)L1_ISRAM) && (tmp < (char *)L1_ISRAM_END)
133 || (tmp >= (char *)DATA_BANKA_SRAM) && (tmp < DATA_BANKA_SRAM_END)
134 || (tmp >= (char *)DATA_BANKB_SRAM) && (tmp < DATA_BANKB_SRAM_END) ){
135 if(icache_status()){
136 blackfin_icache_flush_range(src, src+count);
137 icache_disable();
138 }
139 if(dcache_status()){
140 blackfin_dcache_flush_range(src, src+count);
141 dcache_disable();
142 }
143 dma_memcpy(dest,src,count);
144 }else{
145 while(count--)
146 *tmp++ = *s++;
147 }
148 return dest;
149}
150
151void *dma_memcpy(void * dest,const void *src,size_t count)
152{
8e7b703a 153
6cb142fa
WD
154 *pMDMA_D0_IRQ_STATUS = DMA_DONE | DMA_ERR;
155
156 /* Copy sram functions from sdram to sram */
157 /* Setup destination start address */
158 *pMDMA_D0_START_ADDR = (volatile void **)dest;
159 /* Setup destination xcount */
160 *pMDMA_D0_X_COUNT = count ;
161 /* Setup destination xmodify */
162 *pMDMA_D0_X_MODIFY = 1;
163
164 /* Setup Source start address */
165 *pMDMA_S0_START_ADDR = (volatile void **)src;
166 /* Setup Source xcount */
167 *pMDMA_S0_X_COUNT = count;
168 /* Setup Source xmodify */
169 *pMDMA_S0_X_MODIFY = 1;
170
171 /* Enable source DMA */
172 *pMDMA_S0_CONFIG = (DMAEN);
173 asm("ssync;");
174
175 *pMDMA_D0_CONFIG = ( WNR | DMAEN);
8e7b703a 176
6cb142fa
WD
177 while(*pMDMA_D0_IRQ_STATUS & DMA_RUN){
178 *pMDMA_D0_IRQ_STATUS |= (DMA_DONE | DMA_ERR);
179 }
180 *pMDMA_D0_IRQ_STATUS |= (DMA_DONE | DMA_ERR);
181
182 dest += count;
183 src += count;
184 return dest;
185}