]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/bcopy.s
xnu-792.6.56.tar.gz
[apple/xnu.git] / osfmk / i386 / bcopy.s
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
ff6e181a
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
1c79356b 12 *
ff6e181a
A
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
ff6e181a
A
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
1c79356b
A
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*
24 * @OSF_COPYRIGHT@
25 */
26/*
27 * Mach Operating System
28 * Copyright (c) 1991,1990 Carnegie Mellon University
29 * All Rights Reserved.
30 *
31 * Permission to use, copy, modify and distribute this software and its
32 * documentation is hereby granted, provided that both the copyright
33 * notice and this permission notice appear in all copies of the
34 * software, derivative works or modified versions, and any portions
35 * thereof, and that both notices appear in supporting documentation.
36 *
37 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
38 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
39 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 *
41 * Carnegie Mellon requests users of this software to return to
42 *
43 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
44 * School of Computer Science
45 * Carnegie Mellon University
46 * Pittsburgh PA 15213-3890
47 *
48 * any improvements or extensions that they make and grant Carnegie Mellon
49 * the rights to redistribute these changes.
50 */
51/*
52 */
53
54#include <i386/asm.h>
55
56/* void *memcpy((void *) to, (const void *) from, (size_t) bcount) */
57
58ENTRY(memcpy)
59 pushl %edi
60 pushl %esi
61 movl 8+ 4(%esp),%edi /* to */
62 movl %edi,%eax /* returns its first argument */
63 movl 8+ 8(%esp),%esi /* from */
64memcpy_common:
65 movl 8+ 12(%esp),%edx /* number of bytes */
66 cld
67/* move longs*/
68 movl %edx,%ecx
69 sarl $2,%ecx
70 rep
71 movsl
72/* move bytes*/
73 movl %edx,%ecx
74 andl $3,%ecx
75 rep
76 movsb
77 popl %esi
78 popl %edi
79 ret
80
81/* void bcopy((const char *) from, (char *) to, (unsigned int) count) */
82
83ENTRY(bcopy_no_overwrite)
84 pushl %edi
85 pushl %esi
86 movl 8+ 8(%esp),%edi /* to */
87 movl 8+ 4(%esp),%esi /* from */
88 jmp memcpy_common
89
90/* bcopy16(from, to, bcount) using word moves */
91
92ENTRY(bcopy16)
93 pushl %edi
94 pushl %esi
95 movl 8+12(%esp),%edx /* 8 for the two pushes above */
96 movl 8+ 8(%esp),%edi
97 movl 8+ 4(%esp),%esi
98/* move words */
990: cld
100 movl %edx,%ecx
101 sarl $1,%ecx
102 rep
103 movsw
104/* move bytes */
105 movl %edx,%ecx
106 andl $1,%ecx
107 rep
108 movsb
109 popl %esi
110 popl %edi
111 ret
112
91447636
A
113
114 /*
115 * Based on NetBSD's bcopy.S from their libc.
116 * bcopy(src, dst, cnt)
117 * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
118 */
119ENTRY(bcopy)
120 pushl %esi
121 pushl %edi
122 movl 12(%esp),%esi
123 movl 16(%esp),%edi
124 movl 20(%esp),%ecx
125
126 movl %edi,%edx
127 subl %esi,%edx
128 cmpl %ecx,%edx /* overlapping && src < dst? */
129 movl %ecx,%edx
130 jb 1f
131
132 shrl $2,%ecx /* copy by 32-bit words */
133 cld /* nope, copy forwards */
134 rep
135 movsl
136 movl %edx,%ecx
137 andl $3,%ecx /* any bytes left? */
138 rep
139 movsb
140 popl %edi
141 popl %esi
142 ret
143
144
1451:
146 addl %ecx,%edi /* copy backwards */
147 addl %ecx,%esi
148 decl %edi
149 decl %esi
150 andl $3,%ecx /* any fractional bytes? */
151 std
152 rep
153 movsb
154 movl %edx,%ecx /* copy remainder by 32-bit words */
155 shrl $2,%ecx
156 subl $3,%esi
157 subl $3,%edi
158 rep
159 movsl
160 popl %edi
161 popl %esi
162 cld
163 ret