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