1 /* $NetBSD: bcopy.S,v 1.6 2013/09/07 19:06:29 chs Exp $ */
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1990 The Regents of the University of California.
34 * All rights reserved.
36 * This code is derived from software contributed to Berkeley by
37 * the Systems Programming Group of the University of Utah Computer
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 #include <machine/asm.h>
67 #if defined(LIBC_SCCS) && !defined(lint)
69 RCSID("from: @(#)bcopy.s 5.1 (Berkeley) 5/12/90")
71 RCSID("$NetBSD: bcopy.S,v 1.6 2013/09/07 19:06:29 chs Exp $")
73 #endif /* LIBC_SCCS and not lint */
78 #elif defined(MEMMOVE)
85 #if defined(MEMCOPY) || defined(MEMMOVE)
86 movl 4(%sp),%a1 | dest address
87 movl 8(%sp),%a0 | src address
89 movl 4(%sp),%a0 | src address
90 movl 8(%sp),%a1 | dest address
92 movl 12(%sp),%d1 | count
94 cmpl %a1,%a0 | src after dest?
95 jlt .Lbcback | yes, must copy backwards
98 * It isn't worth the overhead of aligning to {long}word boundries
99 * if the string is too short.
106 * The 68010 cannot access a word or long on an odd boundary,
107 * period. If the source and the destination addresses aren't
108 * of the same evenness, we're forced to do a bytewise copy.
114 #endif /* __mc68010__ */
118 btst #0,%d0 | if (dst & 1)
120 movb (%a0)+,(%a1)+ | *(char *)dst++ = *(char *) src++
123 /* long word align */
124 btst #1,%d0 | if (dst & 2)
126 movw (%a0)+,(%a1)+ | *(short *)dst++ = *(short *) dst++
127 subql #2,%d1 | len -= 2
129 /* copy by 8 longwords */
131 lsrl #5,%d0 | cnt = len / 32
132 jeq .Lbcflong | if (cnt)
133 andl #31,%d1 | len %= 32
134 subql #1,%d0 | set up for dbf
136 movl (%a0)+,(%a1)+ | copy 8 long words
144 #ifndef __mcoldfire__
145 dbf %d0,.Lbcf32loop | till done
152 /* copy by longwords */
154 lsrl #2,%d0 | cnt = len / 4
155 jeq .Lbcfbyte | if (cnt)
156 subql #1,%d0 | set up for dbf
158 movl (%a0)+,(%a1)+ | copy longwords
160 subql #1,%d0 | decrement
161 jcc .Lbcflloop | til done
163 dbf %d0,.Lbcflloop | til done
165 andl #3,%d1 | len %= 4
168 subql #1,%d1 | set up for dbf
170 movb (%a0)+,(%a1)+ | copy bytes
173 subql #1,%d0 | decrement
174 jcc .Lbcfbloop | til done
176 dbf %d1,.Lbcfbloop | till done
179 #if defined(MEMCOPY) || defined(MEMMOVE)
180 movl 4(%sp),%d0 | dest address
181 #if defined(__SVR4_ABI__)
189 addl %d1,%a0 | src pointer to end
190 addl %d1,%a1 | dest pointer to end
193 * It isn't worth the overhead of aligning to {long}word boundries
194 * if the string is too short.
201 * The 68010 cannot access a word or long on an odd boundary,
202 * period. If the source and the destination addresses aren't
203 * of the same evenness, we're forced to do a bytewise copy.
209 #endif /* __mc68010__ */
213 btst #0,%d0 | if (dst & 1)
215 movb -(%a0),-(%a1) | *(char *)dst-- = *(char *) src--
218 /* long word align */
219 btst #1,%d0 | if (dst & 2)
221 movw -(%a0),-(%a1) | *(short *)dst-- = *(short *) dst--
222 subql #2,%d1 | len -= 2
224 /* copy by 8 longwords */
226 lsrl #5,%d0 | cnt = len / 32
227 jeq .Lbcblong | if (cnt)
228 andl #31,%d1 | len %= 32
229 subql #1,%d0 | set up for dbf
231 movl -(%a0),-(%a1) | copy 8 long words
239 #ifndef __mcoldfire__
240 dbf %d0,.Lbcb32loop | till done
247 /* copy by longwords */
249 lsrl #2,%d0 | cnt = len / 4
250 jeq .Lbcbbyte | if (cnt)
251 subql #1,%d0 | set up for dbf
253 movl -(%a0),-(%a1) | copy longwords
255 subql #1,%d0 | decrement
256 jcc .Lbcblloop | til done
258 dbf %d0,.Lbcblloop | til done
260 andl #3,%d1 | len %= 4
263 subql #1,%d1 | set up for dbf
265 movb -(%a0),-(%a1) | copy bytes
268 subql #1,%d0 | decrement
269 jcc .Lbcbbloop | til done
271 dbf %d1,.Lbcbbloop | till done
274 #if defined(MEMCOPY) || defined(MEMMOVE)
275 movl 4(%sp),%d0 | dest address
276 #if defined(__SVR4_ABI__)