11da177eLinus Torvalds/*
2bf7b4c1Helge Deller * Copyright (c) 1993 Winning Strategies, Inc.
31da177eLinus Torvalds * All rights reserved.
4bf7b4c1Helge Deller *
51da177eLinus Torvalds * Redistribution and use in source and binary forms, with or without
6bf7b4c1Helge Deller * modification, are permitted provided that the following conditions
71da177eLinus Torvalds * are met:
8bf7b4c1Helge Deller * 1. Redistributions of source code must retain the above copyright
9bf7b4c1Helge Deller *    notice, this list of conditions and the following disclaimer.
10bf7b4c1Helge Deller * 2. Redistributions in binary form must reproduce the above copyright
111da177eLinus Torvalds *    notice, this list of conditions and the following disclaimer in the
121da177eLinus Torvalds *    documentation and/or other materials provided with the distribution.
13bf7b4c1Helge Deller * 3. All advertising materials mentioning features or use of this software
14bf7b4c1Helge Deller *    must display the following acknowledgement:
15bf7b4c1Helge Deller *      This product includes software developed by Winning Strategies, Inc.
161da177eLinus Torvalds * 4. The name of the author may not be used to endorse or promote products
17bf7b4c1Helge Deller *    derived from this software without specific prior written permission
181da177eLinus Torvalds *
19bf7b4c1Helge Deller * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20bf7b4c1Helge Deller * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21bf7b4c1Helge Deller * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22bf7b4c1Helge Deller * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23bf7b4c1Helge Deller * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24bf7b4c1Helge Deller * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25bf7b4c1Helge Deller * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
261da177eLinus Torvalds * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27bf7b4c1Helge Deller * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28bf7b4c1Helge Deller * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29bf7b4c1Helge Deller */
30bf7b4c1Helge Deller
31bf7b4c1Helge Deller#include <machine/asm.h>
32bf7b4c1Helge Deller__FBSDID("$FreeBSD$");
33bf7b4c1Helge Deller
34bf7b4c1Helge Deller/*
35bf7b4c1Helge Deller * memset(void *b, int c, size_t len)
36bf7b4c1Helge Deller *	write len bytes of value c (converted to an unsigned char) to
37bf7b4c1Helge Deller *	the string b.
38bf7b4c1Helge Deller *
39bf7b4c1Helge Deller * Written by:
40bf7b4c1Helge Deller *	J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
41bf7b4c1Helge Deller */
42bf7b4c1Helge Deller
43bf7b4c1Helge DellerENTRY(memset)
44bf7b4c1Helge Deller	pushl	%edi
45bf7b4c1Helge Deller	pushl	%ebx
46bf7b4c1Helge Deller	movl	12(%esp),%edi
47bf7b4c1Helge Deller	movzbl	16(%esp),%eax		/* unsigned char, zero extend */
48bf7b4c1Helge Deller	movl	20(%esp),%ecx
49bf7b4c1Helge Deller	pushl	%edi			/* push address of buffer */
50bf7b4c1Helge Deller
51bf7b4c1Helge Deller	cld				/* set fill direction forward */
52bf7b4c1Helge Deller
53bf7b4c1Helge Deller	/*
54bf7b4c1Helge Deller	 * if the string is too short, it's really not worth the overhead
55bf7b4c1Helge Deller	 * of aligning to word boundries, etc.  So we jump to a plain
56bf7b4c1Helge Deller	 * unaligned set.
57bf7b4c1Helge Deller	 */
58bf7b4c1Helge Deller	cmpl	$0x0f,%ecx
59bf7b4c1Helge Deller	jle	L1
60bf7b4c1Helge Deller
61bf7b4c1Helge Deller	movb	%al,%ah			/* copy char to all bytes in word */
62bf7b4c1Helge Deller	movl	%eax,%edx
63bf7b4c1Helge Deller	sall	$16,%eax
64bf7b4c1Helge Deller	orl	%edx,%eax
65bf7b4c1Helge Deller
66bf7b4c1Helge Deller	movl	%edi,%edx		/* compute misalignment */
67bf7b4c1Helge Deller	negl	%edx
68bf7b4c1Helge Deller	andl	$3,%edx
69bf7b4c1Helge Deller	movl	%ecx,%ebx
70bf7b4c1Helge Deller	subl	%edx,%ebx
71bf7b4c1Helge Deller
72bf7b4c1Helge Deller	movl	%edx,%ecx		/* set until word aligned */
731da177eLinus Torvalds	rep
74bf7b4c1Helge Deller	stosb
75bf7b4c1Helge Deller
76bf7b4c1Helge Deller	movl	%ebx,%ecx
77bf7b4c1Helge Deller	shrl	$2,%ecx			/* set by words */
78bf7b4c1Helge Deller	rep
79bf7b4c1Helge Deller	stosl
80bf7b4c1Helge Deller
81bf7b4c1Helge Deller	movl	%ebx,%ecx		/* set remainder by bytes */
82bf7b4c1Helge Deller	andl	$3,%ecx
83bf7b4c1Helge DellerL1:	rep
84bf7b4c1Helge Deller	stosb
85bf7b4c1Helge Deller
86bf7b4c1Helge Deller	popl	%eax			/* pop address of buffer */
87bf7b4c1Helge Deller	popl	%ebx
88bf7b4c1Helge Deller	popl	%edi
89bf7b4c1Helge Deller	ret
90bf7b4c1Helge DellerEND(memset)
91bf7b4c1Helge Deller
92bf7b4c1Helge Deller	.section .note.GNU-stack,"",%progbits
93bf7b4c1Helge Deller