xref: /freebsd/lib/libc/i386/string/bcopy.S (revision c04447ba036a1a1edc8afeb5a4eaece51da9721c)
12ceb2ce9SGarrett Wollman/*-
22ceb2ce9SGarrett Wollman * Copyright (c) 1990 The Regents of the University of California.
32ceb2ce9SGarrett Wollman * All rights reserved.
42ceb2ce9SGarrett Wollman *
51c33c5a7SBruce Evans * This code is derived from locore.s.
62ceb2ce9SGarrett Wollman *
72ceb2ce9SGarrett Wollman * Redistribution and use in source and binary forms, with or without
82ceb2ce9SGarrett Wollman * modification, are permitted provided that the following conditions
92ceb2ce9SGarrett Wollman * are met:
102ceb2ce9SGarrett Wollman * 1. Redistributions of source code must retain the above copyright
112ceb2ce9SGarrett Wollman *    notice, this list of conditions and the following disclaimer.
122ceb2ce9SGarrett Wollman * 2. Redistributions in binary form must reproduce the above copyright
132ceb2ce9SGarrett Wollman *    notice, this list of conditions and the following disclaimer in the
142ceb2ce9SGarrett Wollman *    documentation and/or other materials provided with the distribution.
152ceb2ce9SGarrett Wollman * 3. All advertising materials mentioning features or use of this software
162ceb2ce9SGarrett Wollman *    must display the following acknowledgement:
172ceb2ce9SGarrett Wollman *	This product includes software developed by the University of
182ceb2ce9SGarrett Wollman *	California, Berkeley and its contributors.
192ceb2ce9SGarrett Wollman * 4. Neither the name of the University nor the names of its contributors
202ceb2ce9SGarrett Wollman *    may be used to endorse or promote products derived from this software
212ceb2ce9SGarrett Wollman *    without specific prior written permission.
222ceb2ce9SGarrett Wollman *
232ceb2ce9SGarrett Wollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
242ceb2ce9SGarrett Wollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
252ceb2ce9SGarrett Wollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
262ceb2ce9SGarrett Wollman * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
272ceb2ce9SGarrett Wollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
282ceb2ce9SGarrett Wollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
292ceb2ce9SGarrett Wollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
302ceb2ce9SGarrett Wollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
312ceb2ce9SGarrett Wollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
322ceb2ce9SGarrett Wollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
332ceb2ce9SGarrett Wollman * SUCH DAMAGE.
342ceb2ce9SGarrett Wollman */
352ceb2ce9SGarrett Wollman
361c33c5a7SBruce Evans#include <machine/asm.h>
37c04447baSDavid E. O'Brien__FBSDID("$FreeBSD$");
382ceb2ce9SGarrett Wollman
39c04447baSDavid E. O'Brien#if 0
401c33c5a7SBruce Evans	RCSID("$NetBSD: bcopy.S,v 1.6 1996/11/12 00:50:06 jtc Exp $")
41c04447baSDavid E. O'Brien#endif
422ceb2ce9SGarrett Wollman
432ceb2ce9SGarrett Wollman	/*
442ceb2ce9SGarrett Wollman	 * (ov)bcopy (src,dst,cnt)
452ceb2ce9SGarrett Wollman	 *  ws@tools.de     (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
462ceb2ce9SGarrett Wollman	 */
472ceb2ce9SGarrett Wollman
481c33c5a7SBruce Evans#ifdef MEMCOPY
491c33c5a7SBruce EvansENTRY(memcpy)
501c33c5a7SBruce Evans#else
511c33c5a7SBruce Evans#ifdef MEMMOVE
521c33c5a7SBruce EvansENTRY(memmove)
531c33c5a7SBruce Evans#else
542ceb2ce9SGarrett WollmanENTRY(bcopy)
551c33c5a7SBruce Evans#endif
561c33c5a7SBruce Evans#endif
572ceb2ce9SGarrett Wollman	pushl	%esi
582ceb2ce9SGarrett Wollman	pushl	%edi
591c33c5a7SBruce Evans#if defined(MEMCOPY) || defined(MEMMOVE)
601c33c5a7SBruce Evans	movl	12(%esp),%edi
611c33c5a7SBruce Evans	movl	16(%esp),%esi
621c33c5a7SBruce Evans#else
632ceb2ce9SGarrett Wollman	movl	12(%esp),%esi
642ceb2ce9SGarrett Wollman	movl	16(%esp),%edi
651c33c5a7SBruce Evans#endif
662ceb2ce9SGarrett Wollman	movl	20(%esp),%ecx
67aacd7f34SDavid Greenman	movl	%edi,%eax
68aacd7f34SDavid Greenman	subl	%esi,%eax
69aacd7f34SDavid Greenman	cmpl	%ecx,%eax	/* overlapping? */
70aacd7f34SDavid Greenman	jb	1f
712ceb2ce9SGarrett Wollman	cld			/* nope, copy forwards. */
722ceb2ce9SGarrett Wollman	shrl	$2,%ecx		/* copy by words */
732ceb2ce9SGarrett Wollman	rep
742ceb2ce9SGarrett Wollman	movsl
752ceb2ce9SGarrett Wollman	movl	20(%esp),%ecx
762ceb2ce9SGarrett Wollman	andl	$3,%ecx		/* any bytes left? */
772ceb2ce9SGarrett Wollman	rep
782ceb2ce9SGarrett Wollman	movsb
791c33c5a7SBruce Evans#if defined(MEMCOPY) || defined(MEMMOVE)
801c33c5a7SBruce Evans	movl	12(%esp),%eax
811c33c5a7SBruce Evans#endif
822ceb2ce9SGarrett Wollman	popl	%edi
832ceb2ce9SGarrett Wollman	popl	%esi
842ceb2ce9SGarrett Wollman	ret
852ceb2ce9SGarrett Wollman1:
862ceb2ce9SGarrett Wollman	addl	%ecx,%edi	/* copy backwards. */
872ceb2ce9SGarrett Wollman	addl	%ecx,%esi
881c33c5a7SBruce Evans	std
891c33c5a7SBruce Evans	andl	$3,%ecx		/* any fractional bytes? */
902ceb2ce9SGarrett Wollman	decl	%edi
912ceb2ce9SGarrett Wollman	decl	%esi
922ceb2ce9SGarrett Wollman	rep
932ceb2ce9SGarrett Wollman	movsb
942ceb2ce9SGarrett Wollman	movl	20(%esp),%ecx	/* copy remainder by words */
952ceb2ce9SGarrett Wollman	shrl	$2,%ecx
962ceb2ce9SGarrett Wollman	subl	$3,%esi
972ceb2ce9SGarrett Wollman	subl	$3,%edi
982ceb2ce9SGarrett Wollman	rep
992ceb2ce9SGarrett Wollman	movsl
1001c33c5a7SBruce Evans#if defined(MEMCOPY) || defined(MEMMOVE)
1011c33c5a7SBruce Evans	movl	12(%esp),%eax
1021c33c5a7SBruce Evans#endif
1032ceb2ce9SGarrett Wollman	popl	%edi
1042ceb2ce9SGarrett Wollman	popl	%esi
1052ceb2ce9SGarrett Wollman	cld
1062ceb2ce9SGarrett Wollman	ret
107