bcopy.S revision 1.1 1 1.1 christos /* $NetBSD: bcopy.S,v 1.1 2005/12/20 19:28:49 christos Exp $ */
2 1.1 christos
3 1.1 christos /*-
4 1.1 christos * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 1.1 christos * All rights reserved.
6 1.1 christos *
7 1.1 christos * This code is derived from software contributed to The NetBSD Foundation
8 1.1 christos * by J.T. Conklin.
9 1.1 christos *
10 1.1 christos * Redistribution and use in source and binary forms, with or without
11 1.1 christos * modification, are permitted provided that the following conditions
12 1.1 christos * are met:
13 1.1 christos * 1. Redistributions of source code must retain the above copyright
14 1.1 christos * notice, this list of conditions and the following disclaimer.
15 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 christos * notice, this list of conditions and the following disclaimer in the
17 1.1 christos * documentation and/or other materials provided with the distribution.
18 1.1 christos * 3. All advertising materials mentioning features or use of this software
19 1.1 christos * must display the following acknowledgement:
20 1.1 christos * This product includes software developed by the NetBSD
21 1.1 christos * Foundation, Inc. and its contributors.
22 1.1 christos * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 christos * contributors may be used to endorse or promote products derived
24 1.1 christos * from this software without specific prior written permission.
25 1.1 christos *
26 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 christos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 christos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 christos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 christos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 christos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 christos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 christos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 christos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 christos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 christos * POSSIBILITY OF SUCH DAMAGE.
37 1.1 christos */
38 1.1 christos
39 1.1 christos /*-
40 1.1 christos * Copyright (c) 1990 The Regents of the University of California.
41 1.1 christos * All rights reserved.
42 1.1 christos *
43 1.1 christos * This code is derived from software contributed to Berkeley by
44 1.1 christos * the Systems Programming Group of the University of Utah Computer
45 1.1 christos * Science Department.
46 1.1 christos *
47 1.1 christos * Redistribution and use in source and binary forms, with or without
48 1.1 christos * modification, are permitted provided that the following conditions
49 1.1 christos * are met:
50 1.1 christos * 1. Redistributions of source code must retain the above copyright
51 1.1 christos * notice, this list of conditions and the following disclaimer.
52 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
53 1.1 christos * notice, this list of conditions and the following disclaimer in the
54 1.1 christos * documentation and/or other materials provided with the distribution.
55 1.1 christos * 3. Neither the name of the University nor the names of its contributors
56 1.1 christos * may be used to endorse or promote products derived from this software
57 1.1 christos * without specific prior written permission.
58 1.1 christos *
59 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 1.1 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 1.1 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 1.1 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 1.1 christos * SUCH DAMAGE.
70 1.1 christos */
71 1.1 christos
72 1.1 christos #include <machine/asm.h>
73 1.1 christos
74 1.1 christos #if defined(LIBC_SCCS) && !defined(lint)
75 1.1 christos #if 0
76 1.1 christos RCSID("from: @(#)bcopy.s 5.1 (Berkeley) 5/12/90")
77 1.1 christos #else
78 1.1 christos RCSID("$NetBSD: bcopy.S,v 1.1 2005/12/20 19:28:49 christos Exp $")
79 1.1 christos #endif
80 1.1 christos #endif /* LIBC_SCCS and not lint */
81 1.1 christos
82 1.1 christos
83 1.1 christos #ifdef MEMCOPY
84 1.1 christos ENTRY(memcpy)
85 1.1 christos #else
86 1.1 christos #ifdef MEMMOVE
87 1.1 christos ENTRY(memmove)
88 1.1 christos #else
89 1.1 christos ENTRY(bcopy)
90 1.1 christos #endif
91 1.1 christos #endif
92 1.1 christos #if defined(MEMCOPY) || defined(MEMMOVE)
93 1.1 christos movl %sp@(4),%a1 | dest address
94 1.1 christos movl %sp@(8),%a0 | src address
95 1.1 christos #else
96 1.1 christos movl %sp@(4),%a0 | src address
97 1.1 christos movl %sp@(8),%a1 | dest address
98 1.1 christos #endif
99 1.1 christos movl %sp@(12),%d1 | count
100 1.1 christos
101 1.1 christos cmpl %a1,%a0 | src after dest?
102 1.1 christos jlt Lbcback | yes, must copy backwards
103 1.1 christos
104 1.1 christos /*
105 1.1 christos * It isn't worth the overhead of aligning to {long}word boundries
106 1.1 christos * if the string is too short.
107 1.1 christos */
108 1.1 christos cmpl #8,%d1
109 1.1 christos jlt Lbcfbyte
110 1.1 christos
111 1.1 christos #ifdef __mc68010__
112 1.1 christos /*
113 1.1 christos * The 68010 cannot access a word or long on an odd boundary,
114 1.1 christos * period. If the source and the destination addresses aren't
115 1.1 christos * of the same evenness, we're forced to do a bytewise copy.
116 1.1 christos */
117 1.1 christos movl %a0,%d0
118 1.1 christos addl %a1,%d0
119 1.1 christos btst #0,%d0
120 1.1 christos jne Lbcfbyte
121 1.1 christos #endif /* __mc68010__ */
122 1.1 christos
123 1.1 christos /* word align */
124 1.1 christos movl %a1,%d0
125 1.1 christos btst #0,%d0 | if (dst & 1)
126 1.1 christos jeq Lbcfalgndw |
127 1.1 christos movb %a0@+,%a1@+ | *(char *)dst++ = *(char *) src++
128 1.1 christos subql #1,%d1 | len--
129 1.1 christos Lbcfalgndw:
130 1.1 christos /* long word align */
131 1.1 christos btst #1,%d0 | if (dst & 2)
132 1.1 christos jeq Lbcfalgndl
133 1.1 christos movw %a0@+,%a1@+ | *(short *)dst++ = *(short *) dst++
134 1.1 christos subql #2,%d1 | len -= 2
135 1.1 christos Lbcfalgndl:
136 1.1 christos /* copy by 8 longwords */
137 1.1 christos movel %d1,%d0
138 1.1 christos lsrl #5,%d0 | cnt = len / 32
139 1.1 christos jeq Lbcflong | if (cnt)
140 1.1 christos andl #31,%d1 | len %= 32
141 1.1 christos subql #1,%d0 | set up for dbf
142 1.1 christos Lbcf32loop:
143 1.1 christos movl %a0@+,%a1@+ | copy 8 long words
144 1.1 christos movl %a0@+,%a1@+
145 1.1 christos movl %a0@+,%a1@+
146 1.1 christos movl %a0@+,%a1@+
147 1.1 christos movl %a0@+,%a1@+
148 1.1 christos movl %a0@+,%a1@+
149 1.1 christos movl %a0@+,%a1@+
150 1.1 christos movl %a0@+,%a1@+
151 1.1 christos dbf %d0,Lbcf32loop | till done
152 1.1 christos clrw %d0
153 1.1 christos subql #1,%d0
154 1.1 christos jcc Lbcf32loop
155 1.1 christos
156 1.1 christos Lbcflong:
157 1.1 christos /* copy by longwords */
158 1.1 christos movel %d1,%d0
159 1.1 christos lsrl #2,%d0 | cnt = len / 4
160 1.1 christos jeq Lbcfbyte | if (cnt)
161 1.1 christos subql #1,%d0 | set up for dbf
162 1.1 christos Lbcflloop:
163 1.1 christos movl %a0@+,%a1@+ | copy longwords
164 1.1 christos dbf %d0,Lbcflloop | til done
165 1.1 christos andl #3,%d1 | len %= 4
166 1.1 christos jeq Lbcdone
167 1.1 christos
168 1.1 christos subql #1,%d1 | set up for dbf
169 1.1 christos Lbcfbloop:
170 1.1 christos movb %a0@+,%a1@+ | copy bytes
171 1.1 christos Lbcfbyte:
172 1.1 christos dbf %d1,Lbcfbloop | till done
173 1.1 christos Lbcdone:
174 1.1 christos #if defined(MEMCOPY) || defined(MEMMOVE)
175 1.1 christos movl %sp@(4),%d0 | dest address
176 1.1 christos #if defined(__SVR4_ABI__)
177 1.1 christos moveal %d0,%a0
178 1.1 christos #endif
179 1.1 christos #endif
180 1.1 christos rts
181 1.1 christos
182 1.1 christos
183 1.1 christos Lbcback:
184 1.1 christos addl %d1,%a0 | src pointer to end
185 1.1 christos addl %d1,%a1 | dest pointer to end
186 1.1 christos
187 1.1 christos /*
188 1.1 christos * It isn't worth the overhead of aligning to {long}word boundries
189 1.1 christos * if the string is too short.
190 1.1 christos */
191 1.1 christos cmpl #8,%d1
192 1.1 christos jlt Lbcbbyte
193 1.1 christos
194 1.1 christos #ifdef __mc68010__
195 1.1 christos /*
196 1.1 christos * The 68010 cannot access a word or long on an odd boundary,
197 1.1 christos * period. If the source and the destination addresses aren't
198 1.1 christos * of the same evenness, we're forced to do a bytewise copy.
199 1.1 christos */
200 1.1 christos movl %a0,%d0
201 1.1 christos addl %a1,%d0
202 1.1 christos btst #0,%d0
203 1.1 christos jne Lbcbbyte
204 1.1 christos #endif /* __mc68010__ */
205 1.1 christos
206 1.1 christos /* word align */
207 1.1 christos movl %a1,%d0
208 1.1 christos btst #0,%d0 | if (dst & 1)
209 1.1 christos jeq Lbcbalgndw |
210 1.1 christos movb %a0@-,%a1@- | *(char *)dst-- = *(char *) src--
211 1.1 christos subql #1,%d1 | len--
212 1.1 christos Lbcbalgndw:
213 1.1 christos /* long word align */
214 1.1 christos btst #1,%d0 | if (dst & 2)
215 1.1 christos jeq Lbcbalgndl
216 1.1 christos movw %a0@-,%a1@- | *(short *)dst-- = *(short *) dst--
217 1.1 christos subql #2,%d1 | len -= 2
218 1.1 christos Lbcbalgndl:
219 1.1 christos /* copy by 8 longwords */
220 1.1 christos movel %d1,%d0
221 1.1 christos lsrl #5,%d0 | cnt = len / 32
222 1.1 christos jeq Lbcblong | if (cnt)
223 1.1 christos andl #31,%d1 | len %= 32
224 1.1 christos subql #1,%d0 | set up for dbf
225 1.1 christos Lbcb32loop:
226 1.1 christos movl %a0@-,%a1@- | copy 8 long words
227 1.1 christos movl %a0@-,%a1@-
228 1.1 christos movl %a0@-,%a1@-
229 1.1 christos movl %a0@-,%a1@-
230 1.1 christos movl %a0@-,%a1@-
231 1.1 christos movl %a0@-,%a1@-
232 1.1 christos movl %a0@-,%a1@-
233 1.1 christos movl %a0@-,%a1@-
234 1.1 christos dbf %d0,Lbcb32loop | till done
235 1.1 christos clrw %d0
236 1.1 christos subql #1,%d0
237 1.1 christos jcc Lbcb32loop
238 1.1 christos
239 1.1 christos Lbcblong:
240 1.1 christos /* copy by longwords */
241 1.1 christos movel %d1,%d0
242 1.1 christos lsrl #2,%d0 | cnt = len / 4
243 1.1 christos jeq Lbcbbyte | if (cnt)
244 1.1 christos subql #1,%d0 | set up for dbf
245 1.1 christos Lbcblloop:
246 1.1 christos movl %a0@-,%a1@- | copy longwords
247 1.1 christos dbf %d0,Lbcblloop | til done
248 1.1 christos andl #3,%d1 | len %= 4
249 1.1 christos jeq Lbcdone
250 1.1 christos
251 1.1 christos subql #1,%d1 | set up for dbf
252 1.1 christos Lbcbbloop:
253 1.1 christos movb %a0@-,%a1@- | copy bytes
254 1.1 christos Lbcbbyte:
255 1.1 christos dbf %d1,Lbcbbloop | till done
256 1.1 christos
257 1.1 christos #if defined(MEMCOPY) || defined(MEMMOVE)
258 1.1 christos movl %sp@(4),%d0 | dest address
259 1.1 christos #if defined(__SVR4_ABI__)
260 1.1 christos moveal %d0,%a0
261 1.1 christos #endif
262 1.1 christos #endif
263 1.1 christos rts
264