xref: /netbsd-src/common/lib/libc/arch/i386/string/small/memcpy.S (revision 19ef5b5b0bcb90f63509df6e78769de1b57c2758)
1*19ef5b5bSuebayasi/*	$NetBSD: memcpy.S,v 1.2 2014/05/23 03:17:31 uebayasi Exp $	*/
2bdaa91a3Sjoerg/*-
3bdaa91a3Sjoerg * Copyright (c) 2011 The NetBSD Foundation, Inc.
4bdaa91a3Sjoerg * All rights reserved.
5bdaa91a3Sjoerg *
6bdaa91a3Sjoerg * This code is derived from software contributed to The NetBSD Foundation
7bdaa91a3Sjoerg * by Joerg Sonnenberger.
8bdaa91a3Sjoerg *
9bdaa91a3Sjoerg * Redistribution and use in source and binary forms, with or without
10bdaa91a3Sjoerg * modification, are permitted provided that the following conditions
11bdaa91a3Sjoerg * are met:
12bdaa91a3Sjoerg * 1. Redistributions of source code must retain the above copyright
13bdaa91a3Sjoerg *    notice, this list of conditions and the following disclaimer.
14bdaa91a3Sjoerg * 2. Redistributions in binary form must reproduce the above copyright
15bdaa91a3Sjoerg *    notice, this list of conditions and the following disclaimer in the
16bdaa91a3Sjoerg *    documentation and/or other materials provided with the distribution.
17bdaa91a3Sjoerg *
18bdaa91a3Sjoerg * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19bdaa91a3Sjoerg * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20bdaa91a3Sjoerg * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21bdaa91a3Sjoerg * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22bdaa91a3Sjoerg * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23bdaa91a3Sjoerg * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24bdaa91a3Sjoerg * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25bdaa91a3Sjoerg * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26bdaa91a3Sjoerg * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27bdaa91a3Sjoerg * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28bdaa91a3Sjoerg * POSSIBILITY OF SUCH DAMAGE.
29bdaa91a3Sjoerg */
30bdaa91a3Sjoerg
31bdaa91a3Sjoerg#include <machine/asm.h>
32*19ef5b5bSuebayasi	RCSID("$NetBSD: memcpy.S,v 1.2 2014/05/23 03:17:31 uebayasi Exp $")
33bdaa91a3Sjoerg
34bdaa91a3Sjoerg#  ifdef BCOPY
35bdaa91a3SjoergENTRY(bcopy)
36bdaa91a3Sjoerg	pushl	%esi
37bdaa91a3Sjoerg	pushl	%edi
38bdaa91a3Sjoerg	movl	12(%esp), %esi
39bdaa91a3Sjoerg	movl	16(%esp), %edi
40bdaa91a3Sjoerg	jmp	__memmove_start
41bdaa91a3Sjoerg#  endif
42bdaa91a3Sjoerg#  if defined(MEMMOVE)
43bdaa91a3SjoergENTRY(memcpy)
44bdaa91a3SjoergENTRY(memmove)
45bdaa91a3Sjoerg	pushl	%esi
46bdaa91a3Sjoerg	pushl	%edi
47bdaa91a3Sjoerg	movl	12(%esp), %edi
48bdaa91a3Sjoerg	movl	16(%esp), %esi
49bdaa91a3Sjoerg	.globl __memmove_start
50bdaa91a3Sjoerg__memmove_start:
51bdaa91a3Sjoerg	movl	20(%esp), %ecx
52bdaa91a3Sjoerg	pushl	%edi
53bdaa91a3Sjoerg	testl %ecx, %ecx
54bdaa91a3Sjoerg	jz 2f
55bdaa91a3Sjoerg	cmpl	%esi, %edi
56bdaa91a3Sjoerg	jb 1f
57bdaa91a3Sjoerg	addl %ecx, %esi
58bdaa91a3Sjoerg	decl %esi
59bdaa91a3Sjoerg	addl %ecx, %edi
60bdaa91a3Sjoerg	decl %edi
61bdaa91a3Sjoerg	std
62bdaa91a3Sjoerg1:
63bdaa91a3Sjoerg	rep
64bdaa91a3Sjoerg	movsb
65bdaa91a3Sjoerg2:
66bdaa91a3Sjoerg	cld
67bdaa91a3Sjoerg	popl	%eax
68bdaa91a3Sjoerg	popl	%edi
69bdaa91a3Sjoerg	popl	%esi
70bdaa91a3Sjoerg	ret
71*19ef5b5bSuebayasiEND(memcpy)
72*19ef5b5bSuebayasiEND(memmove)
73bdaa91a3Sjoerg#  endif /* MEMMOVE */
74*19ef5b5bSuebayasi#  ifdef BCOPY
75*19ef5b5bSuebayasiEND(bcopy)
76*19ef5b5bSuebayasi#  endif
77