]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/commpage/bcopy_scalar.s
xnu-1456.1.26.tar.gz
[apple/xnu.git] / osfmk / i386 / commpage / bcopy_scalar.s
1 /*
2 * Copyright (c) 2003-2006 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 /*-
30 * Copyright (c) 1990 The Regents of the University of California.
31 * All rights reserved.
32 *
33 * This code is derived from locore.s.
34 *
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
37 * are met:
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. All advertising materials mentioning features or use of this software
44 * must display the following acknowledgement:
45 * This product includes software developed by the University of
46 * California, Berkeley and its contributors.
47 * 4. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE.
62 */
63
64 #include <sys/appleapiopts.h>
65 #include <machine/cpu_capabilities.h>
66 #include <machine/commpage.h>
67 #include <machine/asm.h>
68
69 /*
70 * (ov)bcopy (src,dst,cnt)
71 * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
72 */
73
74 COMMPAGE_FUNCTION_START(bcopy_scalar, 32, 5)
75 pushl %ebp /* set up a frame for backtraces */
76 movl %esp,%ebp
77 pushl %esi
78 pushl %edi
79 movl 8(%ebp),%esi
80 movl 12(%ebp),%edi
81 jmp 1f
82 /*
83 * These need to be 32 bytes from Lbcopy_scalar
84 */
85 .align 5, 0x90
86 Lmemcpy_scalar:
87 Lmemmove_scalar:
88 pushl %ebp /* set up a frame for backtraces */
89 movl %esp,%ebp
90 pushl %esi
91 pushl %edi
92 movl 8(%ebp),%edi
93 movl 12(%ebp),%esi
94 movl %edi,%eax
95 1:
96 movl 16(%ebp),%ecx
97 movl %edi,%edx
98 subl %esi,%edx
99 cmpl %ecx,%edx /* overlapping? */
100 jb 2f
101 cld /* nope, copy forwards. */
102 movl %ecx,%edx
103 shrl $2,%ecx /* copy by words */
104 rep
105 movsl
106 movl %edx,%ecx
107 andl $3,%ecx /* any bytes left? */
108 rep
109 movsb
110 popl %edi
111 popl %esi
112 popl %ebp
113 ret
114 2:
115 addl %ecx,%edi /* copy backwards. */
116 addl %ecx,%esi
117 std
118 movl %ecx,%edx
119 andl $3,%ecx /* any fractional bytes? */
120 decl %edi
121 decl %esi
122 rep
123 movsb
124 movl %edx,%ecx /* copy remainder by words */
125 shrl $2,%ecx
126 subl $3,%esi
127 subl $3,%edi
128 rep
129 movsl
130 popl %edi
131 popl %esi
132 popl %ebp
133 cld
134 ret
135
136 COMMPAGE_DESCRIPTOR(bcopy_scalar,_COMM_PAGE_BCOPY,0,kHasSSE2+kHasSupplementalSSE3)