/*1* Copyright (c) 1993 Winning Strategies, Inc.2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. All advertising materials mentioning features or use of this software13* must display the following acknowledgement:14* This product includes software developed by Winning Strategies, Inc.15* 4. The name of the author may not be used to endorse or promote products16* derived from this software without specific prior written permission17*18* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR19* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES20* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.21* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,22* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT23* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,24* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY25* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF27* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28*/2930#include <machine/asm.h>31/*32* memset(void *b, int c, size_t len)33* write len bytes of value c (converted to an unsigned char) to34* the string b.35*36* Written by:37* J.T. Conklin ([email protected]), Winning Strategies, Inc.38*/3940ENTRY(memset)41pushl %edi42pushl %ebx43movl 12(%esp),%edi44movzbl 16(%esp),%eax /* unsigned char, zero extend */45movl 20(%esp),%ecx46pushl %edi /* push address of buffer */4748cld /* set fill direction forward */4950/*51* if the string is too short, it's really not worth the overhead52* of aligning to word boundries, etc. So we jump to a plain53* unaligned set.54*/55cmpl $0x0f,%ecx56jle L15758movb %al,%ah /* copy char to all bytes in word */59movl %eax,%edx60sall $16,%eax61orl %edx,%eax6263movl %edi,%edx /* compute misalignment */64negl %edx65andl $3,%edx66movl %ecx,%ebx67subl %edx,%ebx6869movl %edx,%ecx /* set until word aligned */70rep71stosb7273movl %ebx,%ecx74shrl $2,%ecx /* set by words */75rep76stosl7778movl %ebx,%ecx /* set remainder by bytes */79andl $3,%ecx80L1: rep81stosb8283popl %eax /* pop address of buffer */84popl %ebx85popl %edi86ret87END(memset)8889.section .note.GNU-stack,"",%progbits909192