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