bzero.S revision 184548
1239278Sgonzo/*
2239278Sgonzo * Copyright (c) 1993 Winning Strategies, Inc.
3239278Sgonzo * All rights reserved.
4239278Sgonzo *
5239278Sgonzo * Redistribution and use in source and binary forms, with or without
6239278Sgonzo * modification, are permitted provided that the following conditions
7239278Sgonzo * are met:
8239278Sgonzo * 1. Redistributions of source code must retain the above copyright
9239278Sgonzo *    notice, this list of conditions and the following disclaimer.
10239278Sgonzo * 2. Redistributions in binary form must reproduce the above copyright
11239278Sgonzo *    notice, this list of conditions and the following disclaimer in the
12239278Sgonzo *    documentation and/or other materials provided with the distribution.
13239278Sgonzo * 3. All advertising materials mentioning features or use of this software
14239278Sgonzo *    must display the following acknowledgement:
15239278Sgonzo *      This product includes software developed by Winning Strategies, Inc.
16239278Sgonzo * 4. The name of the author may not be used to endorse or promote products
17239278Sgonzo *    derived from this software without specific prior written permission
18239278Sgonzo *
19239278Sgonzo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20239278Sgonzo * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21239278Sgonzo * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22239278Sgonzo * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23239278Sgonzo * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24239278Sgonzo * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25239278Sgonzo * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26239278Sgonzo * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27239278Sgonzo * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28239278Sgonzo * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29239278Sgonzo */
30239278Sgonzo
31239278Sgonzo#include <machine/asm.h>
32239278Sgonzo__FBSDID("$FreeBSD: head/lib/libc/i386/string/bzero.S 184548 2008-11-02 01:28:47Z peter $");
33239278Sgonzo
34239278Sgonzo/*
35239278Sgonzo * bzero (void *b, size_t len)
36242692Skevlo *	write len zero bytes to the string b.
37239278Sgonzo *
38239278Sgonzo * Written by:
39239278Sgonzo *	J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
40239278Sgonzo */
41239278Sgonzo
42239278SgonzoENTRY(bzero)
43239278Sgonzo	pushl	%edi
44239278Sgonzo	pushl	%ebx
45239278Sgonzo	movl	12(%esp),%edi
46239278Sgonzo	movl	16(%esp),%ecx
47239278Sgonzo
48239278Sgonzo	cld				/* set fill direction forward */
49239278Sgonzo	xorl	%eax,%eax		/* set fill data to 0 */
50239278Sgonzo
51239278Sgonzo	/*
52239278Sgonzo	 * if the string is too short, it's really not worth the overhead
53239278Sgonzo	 * of aligning to word boundries, etc.  So we jump to a plain
54239278Sgonzo	 * unaligned set.
55239278Sgonzo	 */
56239278Sgonzo	cmpl	$0x0f,%ecx
57239278Sgonzo	jle	L1
58239278Sgonzo
59239278Sgonzo	movl	%edi,%edx		/* compute misalignment */
60239278Sgonzo	negl	%edx
61239278Sgonzo	andl	$3,%edx
62239278Sgonzo	movl	%ecx,%ebx
63239278Sgonzo	subl	%edx,%ebx
64239278Sgonzo
65239278Sgonzo	movl	%edx,%ecx		/* zero until word aligned */
66239278Sgonzo	rep
67239278Sgonzo	stosb
68239278Sgonzo
69239278Sgonzo	movl	%ebx,%ecx		/* zero by words */
70239278Sgonzo	shrl	$2,%ecx
71239278Sgonzo	rep
72239278Sgonzo	stosl
73239278Sgonzo
74239278Sgonzo	movl	%ebx,%ecx
75239278Sgonzo	andl	$3,%ecx			/* zero remainder by bytes */
76239278SgonzoL1:	rep
77239278Sgonzo	stosb
78239278Sgonzo
79239278Sgonzo	popl	%ebx
80239278Sgonzo	popl	%edi
81239278Sgonzo	ret
82277996SloosEND(bzero)
83239278Sgonzo