xref: /freebsd/lib/libc/i386/string/bcopy.S (revision 1d386b48a555f61cb7325543adbbb5c3f3407a66)
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.
15fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors
162ceb2ce9SGarrett Wollman *    may be used to endorse or promote products derived from this software
172ceb2ce9SGarrett Wollman *    without specific prior written permission.
182ceb2ce9SGarrett Wollman *
192ceb2ce9SGarrett Wollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
202ceb2ce9SGarrett Wollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
212ceb2ce9SGarrett Wollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
222ceb2ce9SGarrett Wollman * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
232ceb2ce9SGarrett Wollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
242ceb2ce9SGarrett Wollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
252ceb2ce9SGarrett Wollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
262ceb2ce9SGarrett Wollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
272ceb2ce9SGarrett Wollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
282ceb2ce9SGarrett Wollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
292ceb2ce9SGarrett Wollman * SUCH DAMAGE.
302ceb2ce9SGarrett Wollman */
312ceb2ce9SGarrett Wollman
321c33c5a7SBruce Evans#include <machine/asm.h>
33c04447baSDavid E. O'Brien#if 0
341c33c5a7SBruce Evans	RCSID("$NetBSD: bcopy.S,v 1.6 1996/11/12 00:50:06 jtc Exp $")
35c04447baSDavid E. O'Brien#endif
362ceb2ce9SGarrett Wollman
372ceb2ce9SGarrett Wollman	/*
382ceb2ce9SGarrett Wollman	 * (ov)bcopy (src,dst,cnt)
392ceb2ce9SGarrett Wollman	 *  ws@tools.de     (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
402ceb2ce9SGarrett Wollman	 */
412ceb2ce9SGarrett Wollman
421c33c5a7SBruce Evans#ifdef MEMCOPY
431c33c5a7SBruce EvansENTRY(memcpy)
441c33c5a7SBruce Evans#else
451c33c5a7SBruce Evans#ifdef MEMMOVE
461c33c5a7SBruce EvansENTRY(memmove)
471c33c5a7SBruce Evans#else
482ceb2ce9SGarrett WollmanENTRY(bcopy)
491c33c5a7SBruce Evans#endif
501c33c5a7SBruce Evans#endif
512ceb2ce9SGarrett Wollman	pushl	%esi
522ceb2ce9SGarrett Wollman	pushl	%edi
531c33c5a7SBruce Evans#if defined(MEMCOPY) || defined(MEMMOVE)
541c33c5a7SBruce Evans	movl	12(%esp),%edi
551c33c5a7SBruce Evans	movl	16(%esp),%esi
56f927dfabSMaxim Sobolev	movl	%edi,%eax
571c33c5a7SBruce Evans#else
582ceb2ce9SGarrett Wollman	movl	12(%esp),%esi
592ceb2ce9SGarrett Wollman	movl	16(%esp),%edi
601c33c5a7SBruce Evans#endif
612ceb2ce9SGarrett Wollman	movl	20(%esp),%ecx
62f927dfabSMaxim Sobolev	movl	%edi,%edx
63f927dfabSMaxim Sobolev	subl	%esi,%edx
64f927dfabSMaxim Sobolev	cmpl	%ecx,%edx	/* overlapping? */
65*23ec0d58SMateusz Guzik	jb	2f
662ceb2ce9SGarrett Wollman	cld			/* nope, copy forwards. */
67f927dfabSMaxim Sobolev	movl	%ecx,%edx
682ceb2ce9SGarrett Wollman	shrl	$2,%ecx		/* copy by words */
692ceb2ce9SGarrett Wollman	rep
702ceb2ce9SGarrett Wollman	movsl
71f927dfabSMaxim Sobolev	movl	%edx,%ecx
722ceb2ce9SGarrett Wollman	andl	$3,%ecx		/* any bytes left? */
73*23ec0d58SMateusz Guzik	jne	1f
74*23ec0d58SMateusz Guzik	popl	%edi
75*23ec0d58SMateusz Guzik	popl	%esi
76*23ec0d58SMateusz Guzik	ret
77*23ec0d58SMateusz Guzik1:
782ceb2ce9SGarrett Wollman	rep
792ceb2ce9SGarrett Wollman	movsb
802ceb2ce9SGarrett Wollman	popl	%edi
812ceb2ce9SGarrett Wollman	popl	%esi
822ceb2ce9SGarrett Wollman	ret
83*23ec0d58SMateusz Guzik2:
842ceb2ce9SGarrett Wollman	addl	%ecx,%edi	/* copy backwards. */
852ceb2ce9SGarrett Wollman	addl	%ecx,%esi
861c33c5a7SBruce Evans	std
87f927dfabSMaxim Sobolev	movl	%ecx,%edx
882ceb2ce9SGarrett Wollman	decl	%edi
892ceb2ce9SGarrett Wollman	decl	%esi
90*23ec0d58SMateusz Guzik	andl	$3,%ecx		/* any fractional bytes? */
91*23ec0d58SMateusz Guzik	je	3f
922ceb2ce9SGarrett Wollman	rep
932ceb2ce9SGarrett Wollman	movsb
94*23ec0d58SMateusz Guzik3:
95f927dfabSMaxim Sobolev	movl	%edx,%ecx	/* copy remainder by words */
962ceb2ce9SGarrett Wollman	shrl	$2,%ecx
972ceb2ce9SGarrett Wollman	subl	$3,%esi
982ceb2ce9SGarrett Wollman	subl	$3,%edi
992ceb2ce9SGarrett Wollman	rep
1002ceb2ce9SGarrett Wollman	movsl
1012ceb2ce9SGarrett Wollman	popl	%edi
1022ceb2ce9SGarrett Wollman	popl	%esi
1032ceb2ce9SGarrett Wollman	cld
1042ceb2ce9SGarrett Wollman	ret
105ed820052SPeter Wemm#ifdef MEMCOPY
106ed820052SPeter WemmEND(memcpy)
107ed820052SPeter Wemm#else
108ed820052SPeter Wemm#ifdef MEMMOVE
109ed820052SPeter WemmEND(memmove)
110ed820052SPeter Wemm#else
111ed820052SPeter WemmEND(bcopy)
112ed820052SPeter Wemm#endif
113ed820052SPeter Wemm#endif
11493ab7586SKonstantin Belousov
11593ab7586SKonstantin Belousov	.section .note.GNU-stack,"",%progbits
116