11849Swollman/*
21849Swollman * Copyright (c) 1993 Winning Strategies, Inc.
31849Swollman * All rights reserved.
41849Swollman *
51849Swollman * Redistribution and use in source and binary forms, with or without
61849Swollman * modification, are permitted provided that the following conditions
71849Swollman * are met:
81849Swollman * 1. Redistributions of source code must retain the above copyright
91849Swollman *    notice, this list of conditions and the following disclaimer.
101849Swollman * 2. Redistributions in binary form must reproduce the above copyright
111849Swollman *    notice, this list of conditions and the following disclaimer in the
121849Swollman *    documentation and/or other materials provided with the distribution.
131849Swollman * 3. All advertising materials mentioning features or use of this software
141849Swollman *    must display the following acknowledgement:
151849Swollman *      This product includes software developed by Winning Strategies, Inc.
161849Swollman * 4. The name of the author may not be used to endorse or promote products
171849Swollman *    derived from this software without specific prior written permission
181849Swollman *
191849Swollman * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
201849Swollman * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
211849Swollman * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
221849Swollman * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
231849Swollman * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
241849Swollman * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
251849Swollman * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
261849Swollman * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
271849Swollman * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
281849Swollman * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
291849Swollman */
301849Swollman
3185437Speter#include <machine/asm.h>
3293000Sobrien__FBSDID("$FreeBSD$");
331849Swollman
341849Swollman/*
351849Swollman * memset(void *b, int c, size_t len)
361849Swollman *	write len bytes of value c (converted to an unsigned char) to
371849Swollman *	the string b.
381849Swollman *
391849Swollman * Written by:
401849Swollman *	J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
411849Swollman */
421849Swollman
431849SwollmanENTRY(memset)
441849Swollman	pushl	%edi
451849Swollman	pushl	%ebx
461849Swollman	movl	12(%esp),%edi
471849Swollman	movzbl	16(%esp),%eax		/* unsigned char, zero extend */
481849Swollman	movl	20(%esp),%ecx
491849Swollman	pushl	%edi			/* push address of buffer */
501849Swollman
511849Swollman	cld				/* set fill direction forward */
521849Swollman
531849Swollman	/*
541849Swollman	 * if the string is too short, it's really not worth the overhead
551849Swollman	 * of aligning to word boundries, etc.  So we jump to a plain
561849Swollman	 * unaligned set.
571849Swollman	 */
581849Swollman	cmpl	$0x0f,%ecx
591849Swollman	jle	L1
601849Swollman
611849Swollman	movb	%al,%ah			/* copy char to all bytes in word */
621849Swollman	movl	%eax,%edx
631849Swollman	sall	$16,%eax
641849Swollman	orl	%edx,%eax
651849Swollman
661849Swollman	movl	%edi,%edx		/* compute misalignment */
671849Swollman	negl	%edx
681849Swollman	andl	$3,%edx
691849Swollman	movl	%ecx,%ebx
701849Swollman	subl	%edx,%ebx
711849Swollman
721849Swollman	movl	%edx,%ecx		/* set until word aligned */
731849Swollman	rep
741849Swollman	stosb
751849Swollman
761849Swollman	movl	%ebx,%ecx
771849Swollman	shrl	$2,%ecx			/* set by words */
781849Swollman	rep
791849Swollman	stosl
801849Swollman
811849Swollman	movl	%ebx,%ecx		/* set remainder by bytes */
821849Swollman	andl	$3,%ecx
831849SwollmanL1:	rep
841849Swollman	stosb
851849Swollman
861849Swollman	popl	%eax			/* pop address of buffer */
871849Swollman	popl	%ebx
881849Swollman	popl	%edi
891849Swollman	ret
90184548SpeterEND(memset)
91217106Skib
92217106Skib	.section .note.GNU-stack,"",%progbits
93