summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormycroft <mycroft@NetBSD.org>1998-02-22 09:08:34 +0000
committermycroft <mycroft@NetBSD.org>1998-02-22 09:08:34 +0000
commit4477c62148acdd930b2f477eeb22016ebcc370ba (patch)
tree728f15ab1ec07aab0eec0aed0611befbb9205007
parentf9485294268c17edd493e48f742cb2054cb68dd4 (diff)
Add various things from libc.
-rw-r--r--sys/lib/libkern/arch/ns32k/Makefile.inc6
-rw-r--r--sys/lib/libkern/arch/ns32k/SYS.h51
-rw-r--r--sys/lib/libkern/arch/ns32k/htonl.S9
-rw-r--r--sys/lib/libkern/arch/ns32k/htons.S9
-rw-r--r--sys/lib/libkern/arch/ns32k/memcpy.S12
-rw-r--r--sys/lib/libkern/arch/ns32k/memset.S9
-rw-r--r--sys/lib/libkern/arch/ns32k/ntohl.S9
-rw-r--r--sys/lib/libkern/arch/ns32k/ntohs.S9
-rw-r--r--sys/lib/libkern/arch/ns32k/strchr.S141
-rw-r--r--sys/lib/libkern/arch/ns32k/strrchr.S140
10 files changed, 353 insertions, 42 deletions
diff --git a/sys/lib/libkern/arch/ns32k/Makefile.inc b/sys/lib/libkern/arch/ns32k/Makefile.inc
index 51aa3ba2d21..fbd1661da1b 100644
--- a/sys/lib/libkern/arch/ns32k/Makefile.inc
+++ b/sys/lib/libkern/arch/ns32k/Makefile.inc
@@ -1,11 +1,11 @@
-# $NetBSD: Makefile.inc,v 1.15 1998/02/22 08:53:33 mycroft Exp $
+# $NetBSD: Makefile.inc,v 1.16 1998/02/22 09:08:34 mycroft Exp $
SRCS+= __main.c __assert.c \
imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
bswap16.c bswap32.c bswap64.c \
bcmp.S bcopy.S bzero.S ffs.S \
- memchr.S \
- strcat.S strcmp.S strcpy.S strlen.S strncasecmp.c strncmp.S strncpy.S \
+ memchr.S memcpy.S memset.S \
+ strcat.S strchr.S strcmp.S strcpy.S strlen.S strrchr.S strncasecmp.c strncmp.S strncpy.S \
scanc.c skpc.c \
htonl.S htons.S ntohl.S ntohs.S \
random.S
diff --git a/sys/lib/libkern/arch/ns32k/SYS.h b/sys/lib/libkern/arch/ns32k/SYS.h
index d881cb71460..c501160b698 100644
--- a/sys/lib/libkern/arch/ns32k/SYS.h
+++ b/sys/lib/libkern/arch/ns32k/SYS.h
@@ -1,3 +1,5 @@
+/* $NetBSD: SYS.h,v 1.5 1998/02/22 09:08:34 mycroft Exp $ */
+
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@@ -35,8 +37,6 @@
*
* @(#)SYS.h 5.5 (Berkeley) 5/7/91
*
- * $NetBSD: SYS.h,v 1.4 1997/10/13 11:57:04 lukem Exp $
- *
* Modified for the ns532 by Phil Nelson, 12/1/92
*
*/
@@ -44,33 +44,38 @@
#include <machine/asm.h>
#include <sys/syscall.h>
-#define SYSTRAP(x) \
- movd CAT(SYS_,x),r0; \
- SVC
+#define SYSTRAP(x) \
+ movd CAT(SYS_,x),r0; \
+ svc
-#define SYSCALL_NOERROR(x) \
- ENTRY(x); \
- SYSTRAP(x);
+#define _SYSCALL_NOERROR(x,y) \
+ ENTRY(x); \
+ SYSTRAP(y)
-#define RSYSCALL_NOERROR(x) \
- SYSCALL_NOERROR(x); \
- ret 0
-
-#define SYSCALL(x) \
- SYSCALL_NOERROR(x); \
+#define _SYSCALL(x,y) \
+ _SYSCALL_NOERROR(x,y); \
bcs cerror
-#define RSYSCALL(x) \
- SYSCALL(x); \
+#define SYSCALL_NOERROR(x) \
+ _SYSCALL_NOERROR(x,x)
+
+#define SYSCALL(x) \
+ _SYSCALL(x,x)
+
+#define PSEUDO_NOERROR(x,y) \
+ _SYSCALL_NOERROR(x,y); \
ret 0
-#define PSEUDO(x,y) \
- ENTRY(x); \
- SYSTRAP(y); \
+#define PSEUDO(x,y) \
+ _SYSCALL(x,y); \
ret 0
-#define CALL(x,y) \
- bsr CAT(_,y); \
- adjspd -4*x
+#define RSYSCALL_NOERROR(x) \
+ PSEUDO_NOERROR(x,x)
- .globl cerror
+#define RSYSCALL(x) \
+ PSEUDO(x,x)
+
+#define CALL(x,y) \
+ bsr CAT(_,y); \
+ adjspd -4*x
diff --git a/sys/lib/libkern/arch/ns32k/htonl.S b/sys/lib/libkern/arch/ns32k/htonl.S
index 7157f589e29..53e182e09a0 100644
--- a/sys/lib/libkern/arch/ns32k/htonl.S
+++ b/sys/lib/libkern/arch/ns32k/htonl.S
@@ -1,3 +1,5 @@
+/* $NetBSD: htonl.S,v 1.5 1998/02/22 09:08:34 mycroft Exp $ */
+
/*
* Mach Operating System
* Copyright (c) 1992 Carnegie Mellon University
@@ -29,13 +31,14 @@
* HISTORY
* 11-May-92 Johannes Helander (jvh) at Helsinki University of Technology
* Created.
- *
- * $NetBSD: htonl.S,v 1.4 1997/10/13 11:57:10 lukem Exp $
*/
#include <machine/asm.h>
- .text
+#if defined(LIBC_SCCS)
+ RCSID("$NetBSD: htonl.S,v 1.5 1998/02/22 09:08:34 mycroft Exp $")
+#endif
+
ENTRY(htonl)
movd S_ARG0,r0
rotw 8,r0
diff --git a/sys/lib/libkern/arch/ns32k/htons.S b/sys/lib/libkern/arch/ns32k/htons.S
index 2bb67411390..ae9cda26ff0 100644
--- a/sys/lib/libkern/arch/ns32k/htons.S
+++ b/sys/lib/libkern/arch/ns32k/htons.S
@@ -1,3 +1,5 @@
+/* $NetBSD: htons.S,v 1.5 1998/02/22 09:08:34 mycroft Exp $ */
+
/*
* Mach Operating System
* Copyright (c) 1992 Carnegie Mellon University
@@ -29,13 +31,14 @@
* HISTORY
* 11-May-92 Johannes Helander (jvh) at Helsinki University of Technology
* Created.
- *
- * $NetBSD: htons.S,v 1.4 1997/10/13 11:57:15 lukem Exp $
*/
#include <machine/asm.h>
- .text
+#if defined(LIBC_SCCS)
+ RCSID("$NetBSD: htons.S,v 1.5 1998/02/22 09:08:34 mycroft Exp $")
+#endif
+
ENTRY(htons)
movzwd S_ARG0,r0
rotw 8,r0
diff --git a/sys/lib/libkern/arch/ns32k/memcpy.S b/sys/lib/libkern/arch/ns32k/memcpy.S
index 317ec5bd373..5ed8135fc62 100644
--- a/sys/lib/libkern/arch/ns32k/memcpy.S
+++ b/sys/lib/libkern/arch/ns32k/memcpy.S
@@ -1,3 +1,5 @@
+/* $NetBSD: memcpy.S,v 1.2 1998/02/22 09:08:35 mycroft Exp $ */
+
/*
* Written by Matthias Pfaller, 1996
* Public domain.
@@ -6,7 +8,13 @@
#include <machine/asm.h>
#if defined(LIBC_SCCS)
- RCSID("$NetBSD: memcpy.S,v 1.1 1996/11/07 07:36:18 matthias Exp $")
+ RCSID("$NetBSD: memcpy.S,v 1.2 1998/02/22 09:08:35 mycroft Exp $")
+# if defined(BCOPY)
+ RCSID("$Masqueraded: as bcopy $")
+# endif
+# if defined(MEMMOVE)
+ RCSID("$Masqueraded: as memmove $")
+# endif
#endif
#if !defined(BCOPY) && !defined(MEMMOVE)
@@ -25,7 +33,7 @@ ENTRY(memcpy)
* s and d may overlap.
*/
-# ifdef _KERNEL
+# if defined(_KERNEL)
ALTENTRY(ovbcopy,bcopy)
# endif
diff --git a/sys/lib/libkern/arch/ns32k/memset.S b/sys/lib/libkern/arch/ns32k/memset.S
index 69b93aa209b..4bd9c9cbb83 100644
--- a/sys/lib/libkern/arch/ns32k/memset.S
+++ b/sys/lib/libkern/arch/ns32k/memset.S
@@ -1,3 +1,5 @@
+/* $NetBSD: memset.S,v 1.2 1998/02/22 09:08:35 mycroft Exp $ */
+
/*
* Written by Matthias Pfaller, 1996
* Public domain.
@@ -6,10 +8,13 @@
#include <machine/asm.h>
#if defined(LIBC_SCCS)
- RCSID("$NetBSD: memset.S,v 1.1 1996/11/07 07:36:19 matthias Exp $")
+ RCSID("$NetBSD: memset.S,v 1.2 1998/02/22 09:08:35 mycroft Exp $")
+# if defined(BZERO)
+ RCSID("$Masqueraded: as bzero $")
+# endif
#endif
-#ifndef BZERO
+#if !defined(BZERO)
/*
* void *
* memset (void *b, int c, size_t len)
diff --git a/sys/lib/libkern/arch/ns32k/ntohl.S b/sys/lib/libkern/arch/ns32k/ntohl.S
index 02f83d949ca..38592e22633 100644
--- a/sys/lib/libkern/arch/ns32k/ntohl.S
+++ b/sys/lib/libkern/arch/ns32k/ntohl.S
@@ -1,3 +1,5 @@
+/* $NetBSD: ntohl.S,v 1.5 1998/02/22 09:08:35 mycroft Exp $ */
+
/*
* Mach Operating System
* Copyright (c) 1992 Carnegie Mellon University
@@ -29,13 +31,14 @@
* HISTORY
* 11-May-92 Johannes Helander (jvh) at Helsinki University of Technology
* Created.
- *
- * $NetBSD: ntohl.S,v 1.4 1997/10/13 11:57:20 lukem Exp $
*/
#include <machine/asm.h>
- .text
+#if defined(LIBC_SCCS)
+ RCSID("$NetBSD: ntohl.S,v 1.5 1998/02/22 09:08:35 mycroft Exp $")
+#endif
+
ENTRY(ntohl)
movd S_ARG0,r0
rotw 8,r0
diff --git a/sys/lib/libkern/arch/ns32k/ntohs.S b/sys/lib/libkern/arch/ns32k/ntohs.S
index 39f29e64502..9c4c13cac92 100644
--- a/sys/lib/libkern/arch/ns32k/ntohs.S
+++ b/sys/lib/libkern/arch/ns32k/ntohs.S
@@ -1,3 +1,5 @@
+/* $NetBSD: ntohs.S,v 1.5 1998/02/22 09:08:35 mycroft Exp $ */
+
/*
* Mach Operating System
* Copyright (c) 1992 Carnegie Mellon University
@@ -29,13 +31,14 @@
* HISTORY
* 11-May-92 Johannes Helander (jvh) at Helsinki University of Technology
* Created.
- *
- * $NetBSD: ntohs.S,v 1.4 1997/10/13 11:57:23 lukem Exp $
*/
#include <machine/asm.h>
- .text
+#if defined(LIBC_SCCS)
+ RCSID("$NetBSD: ntohs.S,v 1.5 1998/02/22 09:08:35 mycroft Exp $")
+#endif
+
ENTRY(ntohs)
movzwd S_ARG0,r0
rotw 8,r0
diff --git a/sys/lib/libkern/arch/ns32k/strchr.S b/sys/lib/libkern/arch/ns32k/strchr.S
new file mode 100644
index 00000000000..87241d8075d
--- /dev/null
+++ b/sys/lib/libkern/arch/ns32k/strchr.S
@@ -0,0 +1,141 @@
+/* $NetBSD: strchr.S,v 1.1 1998/02/22 09:08:35 mycroft Exp $ */
+
+/*
+ * Written by Matthias Pfaller, 1996
+ * Public domain.
+ */
+
+#include <machine/asm.h>
+
+#if defined(LIBC_SCCS)
+ RCSID("$NetBSD: strchr.S,v 1.1 1998/02/22 09:08:35 mycroft Exp $")
+# if defined(INDEX)
+ RCSID("$Masqueraded: as index $")
+# endif
+#endif
+
+#if !defined(INDEX)
+/*
+ * char *
+ * strchr (const char *s, int c)
+ * locate the first occurrence of c in the string s.
+ */
+ENTRY(strchr)
+#else
+/*
+ * char *
+ * index (const char *s, int c)
+ * locate the first occurrence of c in the string s.
+ */
+ENTRY(index)
+#endif
+ enter [r3,r4,r5],0
+ movd B_ARG0,r0
+ movzbd B_ARG1,r1
+ movd 0x01010101,r5
+ muld r1,r5
+
+ /*
+ * First begin by seeing if we can doubleword align the
+ * pointer. The following code only aligns the pointer in r0.
+ */
+
+ movqd 3,r3
+ andd r0,r3
+
+0: casew 1f(pc)[r3:w]
+1: .word 5f-0b
+ .word 2f-0b
+ .word 3f-0b
+ .word 4f-0b
+
+ .align 2,0xa2
+2: cmpb r5,0(r0) ; beq 6f ; cmpqb 0,0(r0) ; beq notfound
+ cmpb r5,1(r0) ; beq 7f ; cmpqb 0,1(r0) ; beq notfound
+ cmpb r5,2(r0) ; beq 8f ; cmpqb 0,2(r0) ; beq notfound
+ addqd 3,r0
+ br 5f
+
+ .align 2,0xa2
+3: cmpb r5,0(r0) ; beq 6f ; cmpqb 0,0(r0) ; beq notfound
+ cmpb r5,1(r0) ; beq 7f ; cmpqb 0,1(r0) ; beq notfound
+ addqd 2,r0
+ br 5f
+
+ .align 2,0xa2
+4: cmpb r5,0(r0) ; beq 6f ; cmpqb 0,0(r0) ; beq notfound
+ addqd 1,r0
+
+ /*
+ * Okay, when we get down here R0 points at a double word
+ * algined source block of bytes.
+ * This guy processes four bytes at a time and checks for the
+ * zero terminating byte amongst the bytes in the double word.
+ * This algorithm is de to Dave Rand.
+ *
+ * Sneaky test for zero amongst four bytes:
+ *
+ * xxyyzztt
+ * -01010101
+ * ---------
+ * aabbccdd
+ * bic xxyyzztt
+ * ---------
+ * eeffgghh ee=0x80 if xx=0, ff=0x80 if yy=0, etc.
+ *
+ * This whole result will be zero if there
+ * was no zero byte, it will be non-zero if
+ * there is a zero byte present.
+ */
+
+5: movd 0x01010101,r2 /* Magic number to use */
+ movd 0x80808080,r3 /* Another magic number. */
+
+ addqd -4,r0
+
+ .align 2,0xa2
+0: movd 4(r0),r1 /* Get next double word. */
+ addd 4,r0 /* Advance pointer */
+ movd r1,r4 /* Save for storage later. */
+ subd r2,r1 /* Gets borrow if byte = 0. */
+ bicd r4,r1 /* Clear original bits. */
+ andd r3,r1 /* See if borrow occurred. */
+ cmpqd 0,r1
+ bne 1f /* See if this DWORD contained a 0. */
+ xord r5,r4 /* Convert any 'c' to 0. */
+ movd r4,r1
+ subd r2,r1
+ bicd r4,r1
+ andd r3,r1
+ cmpqd 0,r1
+ beq 0b
+
+ /*
+ * At this point, r0 points at a double word which
+ * contains a zero byte or c.
+ */
+
+1: cmpb r5,0(r0) ; beq 6f ; cmpqb 0,0(r0) ; beq notfound
+ cmpb r5,1(r0) ; beq 7f ; cmpqb 0,1(r0) ; beq notfound
+ cmpb r5,2(r0) ; beq 8f ; cmpqb 0,2(r0) ; beq notfound
+ cmpb r5,3(r0) ; beq 9f
+
+notfound:
+ movqd 0,r0
+ exit [r3,r4,r5]
+ ret 0
+
+6: exit [r3,r4,r5]
+ ret 0
+
+7: addqd 1,r0
+ exit [r3,r4,r5]
+ ret 0
+
+8: addqd 2,r0
+ exit [r3,r4,r5]
+ ret 0
+
+9: addqd 3,r0
+ exit [r3,r4,r5]
+ ret 0
diff --git a/sys/lib/libkern/arch/ns32k/strrchr.S b/sys/lib/libkern/arch/ns32k/strrchr.S
new file mode 100644
index 00000000000..5a1f12be40d
--- /dev/null
+++ b/sys/lib/libkern/arch/ns32k/strrchr.S
@@ -0,0 +1,140 @@
+/* $NetBSD: strrchr.S,v 1.1 1998/02/22 09:08:35 mycroft Exp $ */
+
+/*
+ * Written by Matthias Pfaller, 1996
+ * Public domain.
+ */
+
+#include <machine/asm.h>
+
+#if defined(LIBC_SCCS)
+ RCSID("$NetBSD: strrchr.S,v 1.1 1998/02/22 09:08:35 mycroft Exp $")
+# if defined(RINDEX)
+ RCSID("$Masqueraded: as rindex $")
+# endif
+#endif
+
+#if !defined(RINDEX)
+/*
+ * char *
+ * strrchr (const char *s, int c)
+ * locate the last occurrence of c in the string s.
+ */
+ENTRY(strrchr)
+#else
+/*
+ * char *
+ * rindex (const char *s, int c)
+ * locate the last occurrence of c in the string s.
+ */
+ENTRY(rindex)
+#endif
+ enter [r3,r4,r5,r6,r7],0
+ movd B_ARG0,r0
+ movzbd B_ARG1,r1
+ movd 0x01010101,r5
+ movqd 0,r6
+ muld r1,r5
+
+ /*
+ * First begin by seeing if we can doubleword align the
+ * pointer. The following code aligns the pointer in r0.
+ */
+
+ movqd 3,r3
+ andd r0,r3
+
+0: casew 1f(pc)[r3:w]
+1: .word 5f-0b
+ .word 2f-0b
+ .word 3f-0b
+ .word 4f-0b
+
+ .align 2,0xa2
+2: cmpb r5,0(r0) ; bne 0f ; movd r0,r6 ; 0: cmpqb 0,0(r0) ; beq 8f
+ cmpb r5,1(r0) ; bne 0f ; movd r0,r6 ; 0: cmpqb 0,1(r0) ; beq 8f
+ cmpb r5,2(r0) ; bne 0f ; movd r0,r6 ; 0: cmpqb 0,2(r0) ; beq 8f
+ addqd 3,r0
+ br 5f
+
+ .align 2,0xa2
+3: cmpb r5,0(r0) ; bne 0f ; movd r0,r6 ; 0: cmpqb 0,0(r0) ; beq 8f
+ cmpb r5,1(r0) ; bne 0f ; movd r0,r6 ; 0: cmpqb 0,1(r0) ; beq 8f
+ addqd 2,r0
+ br 5f
+
+ .align 2,0xa2
+4: cmpb r5,0(r0) ; bne 0f ; movd r0,r6 ; 0: cmpqb 0,0(r0) ; beq 8f
+ addqd 1,r0
+
+ /*
+ * Okay, when we get down here r0 points at a double word
+ * algined source block of bytes.
+ * This guy processes four bytes at a time and checks for the
+ * zero terminating byte amongst the bytes in the double word.
+ * This algorithm is de to Dave Rand.
+ *
+ * Sneaky test for zero amongst four bytes:
+ *
+ * xxyyzztt
+ * -01010101
+ * ---------
+ * aabbccdd
+ * bic xxyyzztt
+ * ---------
+ * eeffgghh ee=0x80 if xx=0, ff=0x80 if yy=0, etc.
+ *
+ * This whole result will be zero if there
+ * was no zero byte, it will be non-zero if
+ * there is a zero byte present.
+ */
+
+5: movd 0x01010101,r2 /* Magic number to use */
+ movd 0x80808080,r3 /* Another magic number. */
+
+ addqd -4,r0
+ br 1f
+
+ .align 2,0xa2
+0: movd r4,r1
+ subd r2,r1 /* Gets borrow if byte = 0. */
+ bicd r4,r1 /* Clear original bits. */
+ andd r3,r1 /* See if borrow occurred. */
+ cmpqd 0,r1
+ bne 8f /* See if this DWORD contained a 0. */
+1: movd 4(r0),r4 /* Get next double word. */
+ addd 4,r0 /* Advance pointer */
+ xord r5,r4 /* Convert any 'c' to 0. */
+ movd r4,r1
+ subd r2,r1
+ bicd r4,r1
+ andd r3,r1
+ xord r5,r4
+ cmpqd 0,r1
+ beq 0b
+ movd r6,r7
+ movd r0,r6
+ br 0b
+
+ /*
+ * At this point, r6 points at a double word which
+ * contains c or r6 is zero.
+ */
+
+8: movqd 0,r0
+9: cmpqd 0,r6
+ beq 2f
+
+ cmpb r5,0(r6) ; bne 0f ; movd r6,r0 ; 0: cmpqb 0,0(r6) ; beq 1f
+ cmpb r5,1(r6) ; bne 0f ; addr 1(r6),r0 ; 0: cmpqb 0,1(r6) ; beq 1f
+ cmpb r5,2(r6) ; bne 0f ; addr 2(r6),r0 ; 0: cmpqb 0,2(r6) ; beq 1f
+ cmpb r5,3(r6) ; bne 1f ; addr 3(r6),r0 ; 1: cmpqd 0,r0 ; bne 2f
+
+ /*
+ * Maybe the last match was behind the end of the string.
+ */
+ movd r7,r6
+ br 9b
+
+2: exit [r3,r4,r5,r6,r7]
+ ret 0