]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/commpage/bzero_scalar.s
xnu-792.6.61.tar.gz
[apple/xnu.git] / osfmk / i386 / commpage / bzero_scalar.s
1 /*
2 * Copyright (c) 2003 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 %edi
69 pushl %ebx
70 movl 12(%esp),%edi
71 movl 16(%esp),%ecx
72
73 cld /* set fill direction forward */
74 xorl %eax,%eax /* set fill data to 0 */
75
76 /*
77 * if the string is too short, it's really not worth the overhead
78 * of aligning to word boundries, etc. So we jump to a plain
79 * unaligned set.
80 */
81 cmpl $0x0f,%ecx
82 jle L1
83
84 movl %edi,%edx /* compute misalignment */
85 negl %edx
86 andl $3,%edx
87 movl %ecx,%ebx
88 subl %edx,%ebx
89
90 movl %edx,%ecx /* zero until word aligned */
91 rep
92 stosb
93
94 movl %ebx,%ecx /* zero by words */
95 shrl $2,%ecx
96 rep
97 stosl
98
99 movl %ebx,%ecx
100 andl $3,%ecx /* zero remainder by bytes */
101 L1: rep
102 stosb
103
104 popl %ebx
105 popl %edi
106 ret
107
108 COMMPAGE_DESCRIPTOR(bzero_scalar,_COMM_PAGE_BZERO,0,0)