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