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.text
75.align 5, 0x90
76Lbcopy_scalar:
77	pushl	%ebp		/* set up a frame for backtraces */
78	movl	%esp,%ebp
79        pushl   %esi
80        pushl   %edi
81        movl    8(%ebp),%esi
82        movl    12(%ebp),%edi
83	jmp	1f
84/*
85** These need to be 32 bytes from Lbcopy_scalar
86*/
87.align 5, 0x90
88Lmemcpy_scalar:
89Lmemmove_scalar:
90	pushl	%ebp		/* set up a frame for backtraces */
91	movl	%esp,%ebp
92        pushl   %esi
93        pushl   %edi
94        movl    8(%ebp),%edi
95        movl    12(%ebp),%esi
96        movl    %edi,%eax
971:
98        movl    16(%ebp),%ecx
99        movl    %edi,%edx
100        subl    %esi,%edx
101        cmpl    %ecx,%edx       /* overlapping? */
102        jb      2f
103        cld                     /* nope, copy forwards. */
104        movl    %ecx,%edx
105        shrl    $2,%ecx         /* copy by words */
106        rep
107        movsl
108        movl    %edx,%ecx
109        andl    $3,%ecx         /* any bytes left? */
110        rep
111        movsb
112        popl    %edi
113        popl    %esi
114	popl	%ebp
115        ret
1162:
117        addl    %ecx,%edi       /* copy backwards. */
118        addl    %ecx,%esi
119        std
120        movl    %ecx,%edx
121        andl    $3,%ecx         /* any fractional bytes? */
122        decl    %edi
123        decl    %esi
124        rep
125        movsb
126        movl    %edx,%ecx       /* copy remainder by words */
127        shrl    $2,%ecx
128        subl    $3,%esi
129        subl    $3,%edi
130        rep
131        movsl
132        popl    %edi
133        popl    %esi
134	popl	%ebp
135        cld
136        ret
137
138	COMMPAGE_DESCRIPTOR(bcopy_scalar,_COMM_PAGE_BCOPY,0,kHasSSE2+kHasSupplementalSSE3)
139