Home | History | Annotate | Download | only in string
      1 /*	$OpenBSD: bcopy.S,v 1.5 2005/08/07 11:30:38 espie Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1990 The Regents of the University of California.
      5  * All rights reserved.
      6  *
      7  * This code is derived from locore.s.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. Neither the name of the University nor the names of its contributors
     18  *    may be used to endorse or promote products derived from this software
     19  *    without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  * SUCH DAMAGE.
     32  */
     33 
     34 #include <machine/asm.h>
     35 
     36 	/*
     37 	 * (ov)bcopy (src,dst,cnt)
     38 	 *  ws (at) tools.de     (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
     39 	 */
     40 
     41 #ifdef MEMCOPY
     42 ENTRY(memcpy)
     43 #else
     44 #ifdef MEMMOVE
     45 ENTRY(memmove)
     46 #else
     47 ENTRY(bcopy)
     48 #endif
     49 #endif
     50 	pushl	%esi
     51 	pushl	%edi
     52 #if defined(MEMCOPY) || defined(MEMMOVE)
     53 	movl	12(%esp),%edi
     54 	movl	16(%esp),%esi
     55 	movl	%edi, %eax
     56 #else
     57 	movl	12(%esp),%esi
     58 	movl	16(%esp),%edi
     59 #endif
     60 	movl	20(%esp),%ecx
     61 	movl	%ecx,%edx
     62 	cmpl	%esi,%edi	/* potentially overlapping? */
     63 	jnb	1f
     64 	cld			/* nope, copy forwards. */
     65 	shrl	$2,%ecx		/* copy by words */
     66 	rep
     67 	movsl
     68 	movl	%edx,%ecx
     69 	andl	$3,%ecx		/* any bytes left? */
     70 	rep
     71 	movsb
     72 	popl	%edi
     73 	popl	%esi
     74 	ret
     75 1:
     76 	addl	%ecx,%edi	/* copy backwards. */
     77 	addl	%ecx,%esi
     78 	std
     79 	andl	$3,%ecx		/* any fractional bytes? */
     80 	decl	%edi
     81 	decl	%esi
     82 	rep
     83 	movsb
     84 	movl	%edx,%ecx
     85 	shrl	$2,%ecx
     86 	subl	$3,%esi
     87 	subl	$3,%edi
     88 	rep
     89 	movsl
     90 	popl	%edi
     91 	popl	%esi
     92 	cld
     93 	ret
     94