]>
Commit | Line | Data |
---|---|---|
9171fc81 MF |
1 | /* |
2 | * U-boot - string.c Contains library routines. | |
3 | * | |
d31eb385 | 4 | * Copyright (c) 2005-2008 Analog Devices Inc. |
9171fc81 MF |
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 <config.h> | |
30 | #include <asm/blackfin.h> | |
31 | #include <asm/io.h> | |
32 | #include <asm/mach-common/bits/dma.h> | |
33 | ||
34 | char *strcpy(char *dest, const char *src) | |
35 | { | |
36 | char *xdest = dest; | |
37 | char temp = 0; | |
38 | ||
39 | __asm__ __volatile__ ( | |
40 | "1:\t%2 = B [%1++] (Z);\n\t" | |
41 | "B [%0++] = %2;\n\t" | |
42 | "CC = %2;\n\t" | |
43 | "if cc jump 1b (bp);\n" | |
44 | : "=a"(dest), "=a"(src), "=d"(temp) | |
45 | : "0"(dest), "1"(src), "2"(temp) | |
46 | : "memory"); | |
47 | ||
48 | return xdest; | |
49 | } | |
50 | ||
51 | char *strncpy(char *dest, const char *src, size_t n) | |
52 | { | |
53 | char *xdest = dest; | |
54 | char temp = 0; | |
55 | ||
56 | if (n == 0) | |
57 | return xdest; | |
58 | ||
59 | __asm__ __volatile__ ( | |
60 | "1:\t%3 = B [%1++] (Z);\n\t" | |
61 | "B [%0++] = %3;\n\t" | |
62 | "CC = %3;\n\t" | |
63 | "if ! cc jump 2f;\n\t" | |
64 | "%2 += -1;\n\t" | |
65 | "CC = %2 == 0;\n\t" | |
66 | "if ! cc jump 1b (bp);\n" | |
67 | "2:\n" | |
68 | : "=a"(dest), "=a"(src), "=da"(n), "=d"(temp) | |
69 | : "0"(dest), "1"(src), "2"(n), "3"(temp) | |
70 | : "memory"); | |
71 | ||
72 | return xdest; | |
73 | } | |
74 | ||
75 | int strcmp(const char *cs, const char *ct) | |
76 | { | |
77 | char __res1, __res2; | |
78 | ||
79 | __asm__ ( | |
80 | "1:\t%2 = B[%0++] (Z);\n\t" /* get *cs */ | |
81 | "%3 = B[%1++] (Z);\n\t" /* get *ct */ | |
82 | "CC = %2 == %3;\n\t" /* compare a byte */ | |
83 | "if ! cc jump 2f;\n\t" /* not equal, break out */ | |
84 | "CC = %2;\n\t" /* at end of cs? */ | |
85 | "if cc jump 1b (bp);\n\t" /* no, keep going */ | |
86 | "jump.s 3f;\n" /* strings are equal */ | |
87 | "2:\t%2 = %2 - %3;\n" /* *cs - *ct */ | |
88 | "3:\n" | |
89 | : "=a"(cs), "=a"(ct), "=d"(__res1), "=d"(__res2) | |
90 | : "0"(cs), "1"(ct)); | |
91 | ||
92 | return __res1; | |
93 | } | |
94 | ||
95 | int strncmp(const char *cs, const char *ct, size_t count) | |
96 | { | |
97 | char __res1, __res2; | |
98 | ||
99 | if (!count) | |
100 | return 0; | |
101 | ||
102 | __asm__( | |
103 | "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:" | |
114 | : "=a"(cs), "=a"(ct), "=da"(count), "=d"(__res1), "=d"(__res2) | |
115 | : "0"(cs), "1"(ct), "2"(count)); | |
116 | ||
117 | return __res1; | |
118 | } | |
119 | ||
120 | #ifdef bfin_write_MDMA1_D0_IRQ_STATUS | |
121 | # define bfin_write_MDMA_D0_IRQ_STATUS bfin_write_MDMA1_D0_IRQ_STATUS | |
122 | # define bfin_write_MDMA_D0_START_ADDR bfin_write_MDMA1_D0_START_ADDR | |
123 | # define bfin_write_MDMA_D0_X_COUNT bfin_write_MDMA1_D0_X_COUNT | |
124 | # define bfin_write_MDMA_D0_X_MODIFY bfin_write_MDMA1_D0_X_MODIFY | |
125 | # define bfin_write_MDMA_D0_CONFIG bfin_write_MDMA1_D0_CONFIG | |
126 | # define bfin_write_MDMA_S0_START_ADDR bfin_write_MDMA1_S0_START_ADDR | |
127 | # define bfin_write_MDMA_S0_X_COUNT bfin_write_MDMA1_S0_X_COUNT | |
128 | # define bfin_write_MDMA_S0_X_MODIFY bfin_write_MDMA1_S0_X_MODIFY | |
129 | # define bfin_write_MDMA_S0_CONFIG bfin_write_MDMA1_S0_CONFIG | |
130 | # define bfin_write_MDMA_D0_IRQ_STATUS bfin_write_MDMA1_D0_IRQ_STATUS | |
131 | # define bfin_read_MDMA_D0_IRQ_STATUS bfin_read_MDMA1_D0_IRQ_STATUS | |
132 | #endif | |
d31eb385 MF |
133 | /* This version misbehaves for count values of 0 and 2^16+. |
134 | * Perhaps we should detect that ? Nowhere do we actually | |
135 | * use dma memcpy for those types of lengths though ... | |
136 | */ | |
21d63136 | 137 | void dma_memcpy_nocache(void *dst, const void *src, size_t count) |
9171fc81 | 138 | { |
d31eb385 MF |
139 | /* Scratchpad cannot be a DMA source or destination */ |
140 | if (((unsigned long)src >= L1_SRAM_SCRATCH && | |
141 | (unsigned long)src < L1_SRAM_SCRATCH_END) || | |
142 | ((unsigned long)dst >= L1_SRAM_SCRATCH && | |
143 | (unsigned long)dst < L1_SRAM_SCRATCH_END)) | |
144 | hang(); | |
145 | ||
21d63136 MF |
146 | bfin_write_MDMA_S0_CONFIG(0); |
147 | bfin_write_MDMA_D0_CONFIG(0); | |
148 | bfin_write_MDMA_D0_IRQ_STATUS(DMA_RUN | DMA_DONE | DMA_ERR); | |
9171fc81 MF |
149 | |
150 | /* Copy sram functions from sdram to sram */ | |
151 | /* Setup destination start address */ | |
152 | bfin_write_MDMA_D0_START_ADDR(dst); | |
153 | /* Setup destination xcount */ | |
154 | bfin_write_MDMA_D0_X_COUNT(count); | |
155 | /* Setup destination xmodify */ | |
156 | bfin_write_MDMA_D0_X_MODIFY(1); | |
157 | ||
158 | /* Setup Source start address */ | |
159 | bfin_write_MDMA_S0_START_ADDR(src); | |
160 | /* Setup Source xcount */ | |
161 | bfin_write_MDMA_S0_X_COUNT(count); | |
162 | /* Setup Source xmodify */ | |
163 | bfin_write_MDMA_S0_X_MODIFY(1); | |
164 | ||
165 | /* Enable source DMA */ | |
166 | bfin_write_MDMA_S0_CONFIG(DMAEN); | |
9171fc81 MF |
167 | |
168 | bfin_write_MDMA_D0_CONFIG(WNR | DMAEN); | |
21d63136 | 169 | SSYNC(); |
9171fc81 MF |
170 | |
171 | while (bfin_read_MDMA_D0_IRQ_STATUS() & DMA_RUN) | |
21d63136 MF |
172 | continue; |
173 | ||
174 | bfin_write_MDMA_D0_IRQ_STATUS(bfin_read_MDMA_D0_IRQ_STATUS() | DMA_RUN | DMA_DONE | DMA_ERR); | |
175 | bfin_write_MDMA_D0_CONFIG(0); | |
176 | bfin_write_MDMA_S0_CONFIG(0); | |
177 | } | |
178 | void *dma_memcpy(void *dst, const void *src, size_t count) | |
179 | { | |
180 | if (dcache_status()) | |
181 | blackfin_dcache_flush_range(src, src + count); | |
182 | ||
183 | dma_memcpy_nocache(dst, src, count); | |
9171fc81 MF |
184 | |
185 | if (icache_status()) | |
186 | blackfin_icache_flush_range(dst, dst + count); | |
187 | ||
188 | if (dcache_status()) | |
189 | blackfin_dcache_invalidate_range(dst, dst + count); | |
190 | ||
191 | return dst; | |
192 | } | |
193 | ||
194 | /* | |
195 | * memcpy - Copy one area of memory to another | |
196 | * @dest: Where to copy to | |
197 | * @src: Where to copy from | |
198 | * @count: The size of the area. | |
199 | * | |
200 | * We need to have this wrapper in memcpy() as common code may call memcpy() | |
201 | * to load up L1 regions. Consider loading an ELF which has sections with | |
202 | * LMA's pointing to L1. The common code ELF loader will simply use memcpy() | |
203 | * to move the ELF's sections into the right place. We need to catch that | |
204 | * here and redirect to dma_memcpy(). | |
205 | */ | |
206 | extern void *memcpy_ASM(void *dst, const void *src, size_t count); | |
207 | void *memcpy(void *dst, const void *src, size_t count) | |
208 | { | |
209 | if (!count) | |
210 | return dst; | |
211 | ||
212 | if (addr_bfin_on_chip_mem(dst)) { | |
213 | /* L1 is the destination */ | |
214 | return dma_memcpy(dst, src, count); | |
215 | ||
216 | } else if (addr_bfin_on_chip_mem(src)) { | |
217 | /* L1 is the source */ | |
218 | return dma_memcpy(dst, src, count); | |
219 | ||
220 | } else | |
221 | /* No L1 is involved, so just call regular memcpy */ | |
222 | return memcpy_ASM(dst, src, count); | |
223 | } |