summaryrefslogtreecommitdiffstats
path: root/sys/lib/libkern/arch
diff options
context:
space:
mode:
authormickey <mickey@openbsd.org>1996-03-08 23:42:59 +0000
committermickey <mickey@openbsd.org>1996-03-08 23:42:59 +0000
commit7fde9e0dc22beb7d437468cb50f0893c861cf235 (patch)
tree08400cb2dd9d834d6e06e343519bbc0dfa30deb6 /sys/lib/libkern/arch
parentFrom NetBSD: (diff)
downloadwireguard-openbsd-7fde9e0dc22beb7d437468cb50f0893c861cf235.tar.xz
wireguard-openbsd-7fde9e0dc22beb7d437468cb50f0893c861cf235.zip
From NetBSD:
linux compatibility changes.
Diffstat (limited to 'sys/lib/libkern/arch')
-rw-r--r--sys/lib/libkern/arch/i386/Makefile.inc2
-rw-r--r--sys/lib/libkern/arch/i386/memset.S58
2 files changed, 59 insertions, 1 deletions
diff --git a/sys/lib/libkern/arch/i386/Makefile.inc b/sys/lib/libkern/arch/i386/Makefile.inc
index 533df315a66..cbeec30a509 100644
--- a/sys/lib/libkern/arch/i386/Makefile.inc
+++ b/sys/lib/libkern/arch/i386/Makefile.inc
@@ -1,5 +1,5 @@
# $NetBSD: Makefile.inc,v 1.7 1995/10/07 09:52:48 mycroft Exp $
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
- bcmp.S ffs.S strcat.S strcmp.S strcpy.S strlen.S strncmp.c \
+ bcmp.S ffs.S memset.S strcat.S strcmp.S strcpy.S strlen.S strncmp.c \
strncpy.c scanc.S skpc.S locc.S htonl.S htons.S ntohl.S ntohs.S
diff --git a/sys/lib/libkern/arch/i386/memset.S b/sys/lib/libkern/arch/i386/memset.S
new file mode 100644
index 00000000000..da90db37568
--- /dev/null
+++ b/sys/lib/libkern/arch/i386/memset.S
@@ -0,0 +1,58 @@
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ */
+
+#include <machine/asm.h>
+
+#if defined(LIBC_SCCS)
+ RCSID("$NetBSD: memset.S,v 1.8 1995/04/28 22:58:05 jtc Exp $")
+#endif
+
+ENTRY(memset)
+ pushl %edi
+ pushl %ebx
+ movl 12(%esp),%edi
+ movzbl 16(%esp),%eax /* unsigned char, zero extend */
+ movl 20(%esp),%ecx
+ pushl %edi /* push address of buffer */
+
+ cld /* set fill direction forward */
+
+ /*
+ * if the string is too short, it's really not worth the overhead
+ * of aligning to word boundries, etc. So we jump to a plain
+ * unaligned set.
+ */
+ cmpl $0x0f,%ecx
+ jle L1
+
+ movb %al,%ah /* copy char to all bytes in word */
+ movl %eax,%edx
+ sall $16,%eax
+ orl %edx,%eax
+
+ movl %edi,%edx /* compute misalignment */
+ negl %edx
+ andl $3,%edx
+ movl %ecx,%ebx
+ subl %edx,%ebx
+
+ movl %edx,%ecx /* set until word aligned */
+ rep
+ stosb
+
+ movl %ebx,%ecx
+ shrl $2,%ecx /* set by words */
+ rep
+ stosl
+
+ movl %ebx,%ecx /* set remainder by bytes */
+ andl $3,%ecx
+L1: rep
+ stosb
+
+ popl %eax /* pop address of buffer */
+ popl %ebx
+ popl %edi
+ ret