]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/commpage/bzero_scalar.s
9e3195681fcd67d8174bf2c946e42adb36912ed2
[apple/xnu.git] / osfmk / i386 / commpage / bzero_scalar.s
1 /*
2 * Copyright (c) 2003-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * Copyright (c) 1993 Winning Strategies, Inc.
24 * All rights reserved.
25 *
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
28 * are met:
29 * 1. Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in the
33 * documentation and/or other materials provided with the distribution.
34 * 3. All advertising materials mentioning features or use of this software
35 * must display the following acknowledgement:
36 * This product includes software developed by Winning Strategies, Inc.
37 * 4. The name of the author may not be used to endorse or promote products
38 * derived from this software withough specific prior written permission
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
41 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
43 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
44 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
46 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
47 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
48 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
49 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 *
51 */
52
53 #include <sys/appleapiopts.h>
54 #include <machine/cpu_capabilities.h>
55 #include <machine/commpage.h>
56
57 /*
58 * bzero (void *b, size_t len)
59 * write len zero bytes to the string b.
60 *
61 * Written by:
62 * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
63 */
64
65 .text
66 .align 5, 0x90
67 Lbzero_scalar:
68 pushl %ebp /* set up a frame for backtraces */
69 movl %esp,%ebp
70 pushl %edi
71 pushl %ebx
72 movl 8(%ebp),%edi
73 movl 12(%ebp),%ecx
74
75 cld /* set fill direction forward */
76 xorl %eax,%eax /* set fill data to 0 */
77
78 /*
79 * if the string is too short, it's really not worth the overhead
80 * of aligning to word boundries, etc. So we jump to a plain
81 * unaligned set.
82 */
83 cmpl $0x0f,%ecx
84 jbe L1
85
86 movl %edi,%edx /* compute misalignment */
87 negl %edx
88 andl $3,%edx
89 movl %ecx,%ebx
90 subl %edx,%ebx
91
92 movl %edx,%ecx /* zero until word aligned */
93 rep
94 stosb
95
96 movl %ebx,%ecx /* zero by words */
97 shrl $2,%ecx
98 rep
99 stosl
100
101 movl %ebx,%ecx
102 andl $3,%ecx /* zero remainder by bytes */
103 L1: rep
104 stosb
105
106 popl %ebx
107 popl %edi
108 popl %ebp
109 ret
110
111 COMMPAGE_DESCRIPTOR(bzero_scalar,_COMM_PAGE_BZERO,0,kHasSSE2)