diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 2004-01-28 01:44:46 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 2004-01-28 01:44:46 +0000 |
commit | 87a384e9c6d214761684102b8f24c7a04c59906d (patch) | |
tree | 2b2f6adedb045eef2cc80bb2f6a417c2458e4686 /lib | |
parent | eb2015b73fc7e8f74be0338c16e873a01653fe03 (diff) |
things for amd64; from art@
Diffstat (limited to 'lib')
82 files changed, 3692 insertions, 0 deletions
diff --git a/lib/libc/arch/amd64/Makefile.inc b/lib/libc/arch/amd64/Makefile.inc new file mode 100644 index 00000000000..53949f1c6bc --- /dev/null +++ b/lib/libc/arch/amd64/Makefile.inc @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile.inc,v 1.1 2004/01/28 01:44:44 mickey Exp $ + +KMINCLUDES= arch/x86_64/SYS.h +KMSRCS= bcmp.S bzero.S ffs.S strcat.S strcmp.S strcpy.S strlen.S \ + htonl.S htons.S ntohl.S ntohs.S diff --git a/lib/libc/arch/amd64/SYS.h b/lib/libc/arch/amd64/SYS.h new file mode 100644 index 00000000000..bdf0bfe6d03 --- /dev/null +++ b/lib/libc/arch/amd64/SYS.h @@ -0,0 +1,107 @@ +/* $OpenBSD: SYS.h,v 1.1 2004/01/28 01:44:44 mickey Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)SYS.h 5.5 (Berkeley) 5/7/91 + * $NetBSD: SYS.h,v 1.5 2002/06/03 18:30:32 fvdl Exp $ + */ + +/* + * XXXfvdl change to use syscall/sysret. + */ + +#include <machine/asm.h> +#include <sys/syscall.h> + +#ifdef __STDC__ +#define SYSTRAP(x) movl $(SYS_ ## x),%eax; movq %rcx, %r10; syscall +#else +#define SYSTRAP(x) movl $(SYS_/**/x),%eax; movq %rcx, %r10; syscall +#endif + +#define CERROR _C_LABEL(__cerror) +#define CURBRK _C_LABEL(__curbrk) + +#define SYSENTRY(x) \ + ENTRY(_thread_sys_ ## x); \ + .weak _C_LABEL(x); \ + _C_LABEL(x) = _C_LABEL(_thread_sys_ ## x) + + +#define _SYSCALL_NOERROR(x,y) \ + SYSENTRY(x); \ + SYSTRAP(y) + +#ifdef PIC +#define _SYSCALL(x,y) \ + .text; _ALIGN_TEXT; \ + 2: mov PIC_GOT(CERROR), %rcx; \ + jmp *%rcx; \ + _SYSCALL_NOERROR(x,y); \ + jc 2b +#else +#define _SYSCALL(x,y) \ + .text; _ALIGN_TEXT; \ + 2: jmp CERROR; \ + _SYSCALL_NOERROR(x,y); \ + jc 2b +#endif + +#define SYSCALL_NOERROR(x) \ + _SYSCALL_NOERROR(x,x) + +#define SYSCALL(x) \ + _SYSCALL(x,x) + +#define PSEUDO_NOERROR(x,y) \ + _SYSCALL_NOERROR(x,y); \ + ret + +#define PSEUDO(x,y) \ + _SYSCALL(x,y); \ + ret + +#define RSYSCALL_NOERROR(x) \ + PSEUDO_NOERROR(x,x) + +#define RSYSCALL(x) \ + PSEUDO(x,x) + +#define WSYSCALL(weak,strong) \ + WEAK_ALIAS(weak,strong); \ + PSEUDO(strong,weak) + + .globl CERROR diff --git a/lib/libc/arch/amd64/gen/Makefile.inc b/lib/libc/arch/amd64/gen/Makefile.inc new file mode 100644 index 00000000000..a150d95eba0 --- /dev/null +++ b/lib/libc/arch/amd64/gen/Makefile.inc @@ -0,0 +1,7 @@ +# $OpenBSD: Makefile.inc,v 1.1 2004/01/28 01:44:44 mickey Exp $ + +SRCS+= _setjmp.S alloca.S fabs.S frexp.c infinity.c isinf.c isnan.c ldexp.c \ + modf.S setjmp.S sigsetjmp.S +SRCS+= flt_rounds.S fpgetmask.S fpgetround.S fpgetsticky.S fpsetmask.S \ + fpsetround.S fpsetsticky.S + diff --git a/lib/libc/arch/amd64/gen/_setjmp.S b/lib/libc/arch/amd64/gen/_setjmp.S new file mode 100644 index 00000000000..d9a59f7aa14 --- /dev/null +++ b/lib/libc/arch/amd64/gen/_setjmp.S @@ -0,0 +1,82 @@ +/* $OpenBSD: _setjmp.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: _setjmp.S,v 1.1 2001/06/19 00:25:02 fvdl Exp $ */ + +/* + * Copyright (c) 2001 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Frank van der Linden for Wasabi Systems, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + + +#include <machine/asm.h> +#include <machine/setjmp.h> + +/* + * C library -- _setjmp, _longjmp + * + * _longjmp(a,v) + * will generate a "return(v)" from the last call to + * _setjmp(a) + * by restoring registers from the stack. + * The previous signal state is NOT restored. + */ + +ENTRY(_setjmp) + movq (%rsp),%r11 + movq %rbx,(_JB_RBX * 8)(%rdi) + movq %rbp,(_JB_RBP * 8)(%rdi) + movq %r12,(_JB_R12 * 8)(%rdi) + movq %r13,(_JB_R13 * 8)(%rdi) + movq %r14,(_JB_R14 * 8)(%rdi) + movq %r15,(_JB_R15 * 8)(%rdi) + movq %rsp,(_JB_RSP * 8)(%rdi) + movq %r11,(_JB_PC * 8)(%rdi) + + xorl %eax,%eax + ret + +ENTRY(_longjmp) + movq (_JB_RBX * 8)(%rdi),%rbx + movq (_JB_RBP * 8)(%rdi),%rbp + movq (_JB_R12 * 8)(%rdi),%r12 + movq (_JB_R13 * 8)(%rdi),%r13 + movq (_JB_R14 * 8)(%rdi),%r14 + movq (_JB_R15 * 8)(%rdi),%r15 + movq (_JB_RSP * 8)(%rdi),%rsp + movq (_JB_PC * 8)(%rdi),%r11 + + movl %esi,%eax + testl %eax,%eax + jnz 1f + incl %eax +1: movq %r11,0(%rsp) + ret diff --git a/lib/libc/arch/amd64/gen/alloca.S b/lib/libc/arch/amd64/gen/alloca.S new file mode 100644 index 00000000000..8c15583012c --- /dev/null +++ b/lib/libc/arch/amd64/gen/alloca.S @@ -0,0 +1,13 @@ +/* $OpenBSD: alloca.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: alloca.S,v 1.1 2001/06/19 00:25:02 fvdl Exp $ */ + +#include <machine/asm.h> + +ENTRY(alloca) + popq %rdx + movq %rsp,%rcx + addq $15,%rdi /* round up to 16 bytes */ + andq $~15,%rdi + subq %rdi,%rsp + movq %rsp,%rax + jmp *%rdx diff --git a/lib/libc/arch/amd64/gen/fabs.S b/lib/libc/arch/amd64/gen/fabs.S new file mode 100644 index 00000000000..b94e862c1e9 --- /dev/null +++ b/lib/libc/arch/amd64/gen/fabs.S @@ -0,0 +1,17 @@ +/* $OpenBSD: fabs.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: fabs.S,v 1.1 2001/06/19 00:25:02 fvdl Exp $ */ + +#include <machine/asm.h> + +/* + * Ok, this sucks. Is there really no way to push an xmm register onto + * the FP stack directly? + */ + +ENTRY(fabs) + movsd %xmm0, -8(%rsp) + fldl -8(%rsp) + fabs + fstp -8(%rsp) + movsd -8(%rsp),%xmm0 + ret diff --git a/lib/libc/arch/amd64/gen/flt_rounds.S b/lib/libc/arch/amd64/gen/flt_rounds.S new file mode 100644 index 00000000000..009c59ab64a --- /dev/null +++ b/lib/libc/arch/amd64/gen/flt_rounds.S @@ -0,0 +1,30 @@ +/* $OpenBSD: flt_rounds.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: flt_rounds.S,v 1.2 2002/06/06 23:04:35 fvdl Exp $ */ + +/* + * Written by J.T. Conklin, Apr 4, 1995 + * Public domain. + */ + +#include <machine/asm.h> + + .text + _ALIGN_TEXT +_map: + .byte 1 /* round to nearest */ + .byte 3 /* round to negative infinity */ + .byte 2 /* round to positive infinity */ + .byte 0 /* round to zero */ + +ENTRY(__flt_rounds) + fnstcw -4(%rsp) + movl -4(%rsp),%eax + shrl $10,%eax + andl $3,%eax +#ifdef PIC + leaq PIC_GOT(_map),%rcx + movb (%rcx,%rax,1),%al +#else + movb _map(,%rax,1),%al +#endif + ret diff --git a/lib/libc/arch/amd64/gen/fpgetmask.S b/lib/libc/arch/amd64/gen/fpgetmask.S new file mode 100644 index 00000000000..688ba49cddc --- /dev/null +++ b/lib/libc/arch/amd64/gen/fpgetmask.S @@ -0,0 +1,27 @@ +/* $OpenBSD: fpgetmask.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: fpgetmask.S,v 1.3 2002/06/12 19:17:22 fvdl Exp $ */ + +/* + * Written by J.T. Conklin, Apr 4, 1995 + * Public domain. + */ + +#include <machine/asm.h> + +/* + * XXX only read x87 control word here. If an application only + * uses the fp* interface to manipulate FP bits, it should + * always remain in sync with the SSE mxcsr register. + */ + +#ifdef WEAK_ALIAS +WEAK_ALIAS(fpgetmask, _fpgetmask) +ENTRY(_fpgetmask) +#else +ENTRY(fpgetmask) +#endif + fnstcw -4(%rsp) + movl -4(%rsp),%eax + notl %eax + andl $63,%eax + ret diff --git a/lib/libc/arch/amd64/gen/fpgetround.S b/lib/libc/arch/amd64/gen/fpgetround.S new file mode 100644 index 00000000000..5220b3ef396 --- /dev/null +++ b/lib/libc/arch/amd64/gen/fpgetround.S @@ -0,0 +1,26 @@ +/* $OpenBSD: fpgetround.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: fpgetround.S,v 1.3 2002/06/12 19:17:22 fvdl Exp $ */ + +/* + * Written by J.T. Conklin, Apr 4, 1995 + * Public domain. + */ + +#include <machine/asm.h> + +/* + * XXX store only x87 state. If an application only uses the fp* + * interface, this should be in sync with the SSE mxcsr register. + */ + +#ifdef WEAK_ALIAS +WEAK_ALIAS(fpgetround, _fpgetround) +ENTRY(_fpgetround) +#else +ENTRY(fpgetround) +#endif + fnstcw -4(%rsp) + movl -4(%rsp),%eax + rorl $10,%eax + andl $3,%eax + ret diff --git a/lib/libc/arch/amd64/gen/fpgetsticky.S b/lib/libc/arch/amd64/gen/fpgetsticky.S new file mode 100644 index 00000000000..fd12e2b500a --- /dev/null +++ b/lib/libc/arch/amd64/gen/fpgetsticky.S @@ -0,0 +1,28 @@ +/* $OpenBSD: fpgetsticky.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: fpgetsticky.S,v 1.3 2002/06/12 19:17:22 fvdl Exp $ */ + +/* + * Written by Frank van der Linden at Wasabi Systems for NetBSD. + * Public domain. + * + */ + +#include <machine/asm.h> + +/* + * XXX read both the x87 and SSE status words here, and OR + * them to get a complete picture of exceptions. + */ + +#ifdef WEAK_ALIAS +WEAK_ALIAS(fpgetsticky, _fpgetsticky) +ENTRY(_fpgetsticky) +#else +ENTRY(fpgetsticky) +#endif + fnstsw -4(%rsp) + stmxcsr -8(%rsp) + movl -4(%rsp),%eax + orl -8(%rsp),%eax + andl $63,%eax + ret diff --git a/lib/libc/arch/amd64/gen/fpsetmask.S b/lib/libc/arch/amd64/gen/fpsetmask.S new file mode 100644 index 00000000000..665d55e8e47 --- /dev/null +++ b/lib/libc/arch/amd64/gen/fpsetmask.S @@ -0,0 +1,42 @@ +/* $OpenBSD: fpsetmask.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: fpsetmask.S,v 1.3 2002/06/12 19:17:22 fvdl Exp $ */ + +/* + * Written by Frank van der Linden at Wasabi Systems for NetBSD. + * Public domain. + */ + +#include <machine/asm.h> + +/* + * XXX set both the x87 control word and the SSE mxcsr register. + * Applications should only set exception and round flags + * via the fp*() interface, otherwise the status words + * will get our of sync. + */ + +#ifdef WEAK_ALIAS +WEAK_ALIAS(fpsetmask, _fpsetmask) +ENTRY(_fpsetmask) +#else +ENTRY(fpsetmask) +#endif + fnstcw -4(%rsp) + stmxcsr -8(%rsp) + andl $63,%edi + notl %edi + + movl -4(%rsp),%edx + movl %edx,%eax + andl %edi,%edx + movl %edx,-4(%rsp) + + movl -8(%rsp),%edx + roll $7,%edi + andl %edi,%edx + movl %edx,-8(%rsp) + + fldcw -4(%rsp) + ldmxcsr -8(%rsp) + andl $63,%eax + ret diff --git a/lib/libc/arch/amd64/gen/fpsetround.S b/lib/libc/arch/amd64/gen/fpsetround.S new file mode 100644 index 00000000000..b8508f8b6bd --- /dev/null +++ b/lib/libc/arch/amd64/gen/fpsetround.S @@ -0,0 +1,49 @@ +/* $OpenBSD: fpsetround.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: fpsetround.S,v 1.3 2002/06/12 19:17:22 fvdl Exp $ */ + +/* + * Written by Frank van der Linden at Wasabi Systems for NetBSD. + * Public domain. + */ + +#include <machine/asm.h> + +/* + * XXX set both the x87 control word and the SSE mxcsr register. + * Applications should only set exception and round flags + * via the fp*() interface, otherwise the status words + * will get our of sync. + */ + + +#ifdef WEAK_ALIAS +WEAK_ALIAS(fpsetround, _fpsetround) +ENTRY(_fpsetround) +#else +ENTRY(fpsetround) +#endif + fnstcw -4(%rsp) + stmxcsr -8(%rsp) + + andl $3,%edi + + movl -4(%rsp),%edx + rorl $10,%edx + movl %edx,%eax + andl $3,%eax + + andl $~3,%edx + orl %edi,%edx + roll $10,%edx + movl %edx,-4(%rsp) + + movl -8(%rsp),%edx + rorl $13,%edx + andl $~3,%edx + orl %edi,%edx + roll $13,%edx + movl %edx,-8(%rsp) + + ldmxcsr -8(%rsp) + fldcw -4(%rsp) + ret diff --git a/lib/libc/arch/amd64/gen/fpsetsticky.S b/lib/libc/arch/amd64/gen/fpsetsticky.S new file mode 100644 index 00000000000..c8e61101a12 --- /dev/null +++ b/lib/libc/arch/amd64/gen/fpsetsticky.S @@ -0,0 +1,43 @@ +/* $OpenBSD: fpsetsticky.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: fpsetsticky.S,v 1.3 2002/06/12 19:17:23 fvdl Exp $ */ + +/* + * Written by Frank van der Linden at Wasabi Systems for NetBSD + * Public domain. + */ + +#include <machine/asm.h> + +/* + * XXX set both the x87 status word and the SSE mxcsr register. + * Applications should only set exception and round flags + * via the fp*() interface, otherwise the status words + * will get our of sync. + */ + + +#ifdef WEAK_ALIAS +WEAK_ALIAS(fpsetsticky, _fpsetsticky) +ENTRY(_fpsetsticky) +#else +ENTRY(fpsetsticky) +#endif + fnstenv -28(%rsp) + stmxcsr -32(%rsp) + + andl $63,%edi + + movl -24(%rsp),%eax + movl %eax,%edx + andl $63,%eax + + orl %edi,%edx + movl %edx,-24(%rsp) + + movl -32(%rsp),%edx + orl %edi,%edx + movl %edx,-32(%rsp) + + ldmxcsr -32(%rsp) + fldenv -28(%rsp) + ret diff --git a/lib/libc/arch/amd64/gen/frexp.c b/lib/libc/arch/amd64/gen/frexp.c new file mode 100644 index 00000000000..bc84467fa9e --- /dev/null +++ b/lib/libc/arch/amd64/gen/frexp.c @@ -0,0 +1,74 @@ +/* $OpenBSD: frexp.c,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: frexp.c,v 1.1 2004/01/28 01:44:45 mickey Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <machine/ieee.h> + +/* + * Split the given value into a fraction in the range [0.5, 1.0) and + * an exponent, such that frac * (2^exp) == value. If value is 0, + * return 0. + */ +double +frexp(value, eptr) + double value; + int *eptr; +{ + union { + double v; + struct ieee_double s; + } u; + + if (value) { + /* + * Fractions in [0.5..1.0) have an exponent of 2^-1. + * Leave Inf and NaN alone, however. + * WHAT ABOUT DENORMS? + */ + u.v = value; + if (u.s.dbl_exp != DBL_EXP_INFNAN) { + *eptr = u.s.dbl_exp - (DBL_EXP_BIAS - 1); + u.s.dbl_exp = DBL_EXP_BIAS - 1; + } + return (u.v); + } else { + *eptr = 0; + return ((double)0); + } +} diff --git a/lib/libc/arch/amd64/gen/infinity.c b/lib/libc/arch/amd64/gen/infinity.c new file mode 100644 index 00000000000..8c7eb66d407 --- /dev/null +++ b/lib/libc/arch/amd64/gen/infinity.c @@ -0,0 +1,10 @@ +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: infinity.c,v 1.1 2004/01/28 01:44:45 mickey Exp $"; +#endif /* LIBC_SCCS and not lint */ + +/* infinity.c */ + +#include <math.h> + +/* bytes for +Infinity on a 387 */ +char __infinity[] = { 0, 0, 0, 0, 0, 0, (char)0xf0, 0x7f }; diff --git a/lib/libc/arch/amd64/gen/isinf.c b/lib/libc/arch/amd64/gen/isinf.c new file mode 100644 index 00000000000..6d29660d7f2 --- /dev/null +++ b/lib/libc/arch/amd64/gen/isinf.c @@ -0,0 +1,51 @@ +/* $OpenBSD: isinf.c,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: isinf.c,v 1.1 2004/01/28 01:44:45 mickey Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <machine/ieee.h> + +int +isinf(d) + double d; +{ + struct ieee_double *p = (struct ieee_double *)&d; + + return (p->dbl_exp == DBL_EXP_INFNAN && + p->dbl_frach == 0 && p->dbl_fracl == 0); +} diff --git a/lib/libc/arch/amd64/gen/isnan.c b/lib/libc/arch/amd64/gen/isnan.c new file mode 100644 index 00000000000..5df82ecce25 --- /dev/null +++ b/lib/libc/arch/amd64/gen/isnan.c @@ -0,0 +1,51 @@ +/* $OpenBSD: isnan.c,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: isnan.c,v 1.1 2004/01/28 01:44:45 mickey Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <machine/ieee.h> + +int +isnan(d) + double d; +{ + struct ieee_double *p = (struct ieee_double *)&d; + + return (p->dbl_exp == DBL_EXP_INFNAN && + (p->dbl_frach != 0 || p->dbl_fracl != 0)); +} diff --git a/lib/libc/arch/amd64/gen/ldexp.c b/lib/libc/arch/amd64/gen/ldexp.c new file mode 100644 index 00000000000..b3e95956652 --- /dev/null +++ b/lib/libc/arch/amd64/gen/ldexp.c @@ -0,0 +1,57 @@ +/* $OpenBSD: ldexp.c,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Charles Hannum. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: ldexp.c,v 1.1 2004/01/28 01:44:45 mickey Exp $"; +#endif /* LIBC_SCCS and not lint */ + +/* + * ldexp(value, exp): return value * (2 ** exp). + */ + +double +ldexp (double value, int exp) +{ + double temp; +#if __GNUC__ >= 2 + __asm ("fscale" + : "=t" (temp) + : "0" (value), "u" ((double)exp)); +#else + __asm ("fscale; fstp %%st(1)" + : "=f" (temp) + : "f" (value), "0" ((double)exp)); +#endif + return (temp); +} diff --git a/lib/libc/arch/amd64/gen/modf.S b/lib/libc/arch/amd64/gen/modf.S new file mode 100644 index 00000000000..9e6c13b3cb4 --- /dev/null +++ b/lib/libc/arch/amd64/gen/modf.S @@ -0,0 +1,94 @@ +/* $OpenBSD: modf.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: modf.S,v 1.1 2001/06/19 00:25:03 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Sean Eric Fagan. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)modf.s 5.5 (Berkeley) 3/18/91 + */ + +#include <machine/asm.h> + +/* + * modf(value, iptr): return fractional part of value, and stores the + * integral part into iptr (a pointer to double). + * + * Written by Sean Eric Fagan (sef@kithrup.COM) + * Sun Mar 11 20:27:30 PST 1990 + */ + +/* With CHOP mode on, frndint behaves as TRUNC does. Useful. */ +ENTRY(modf) + pushq %rbp + movq %rsp,%rbp + subq $24,%rsp + + /* + * Set chop mode. + */ + fnstcw -12(%rbp) + movw -12(%rbp),%dx + orw $3072,%dx + movw %dx,-16(%rbp) + fldcw -16(%rbp) + + /* + * Get integral part. + */ + movsd %xmm0,-24(%rbp) + fldl -24(%rbp) + frndint + fstpl -8(%rbp) + + /* + * Restore control word. + */ + fldcw -12(%rbp) + + /* + * Store integral part. + */ + movsd -8(%rbp),%xmm0 + movsd %xmm0,(%rdi) + + /* + * Get fractional part and return it. + */ + fldl -24(%rbp) + fsubl -8(%rbp) + movsd -8(%rbp),%xmm0 + + leave + ret diff --git a/lib/libc/arch/amd64/gen/setjmp.S b/lib/libc/arch/amd64/gen/setjmp.S new file mode 100644 index 00000000000..fb261616f0a --- /dev/null +++ b/lib/libc/arch/amd64/gen/setjmp.S @@ -0,0 +1,103 @@ +/* $OpenBSD: setjmp.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: __setjmp14.S,v 1.1 2001/06/19 00:25:02 fvdl Exp $ */ + +/* + * Copyright (c) 2001 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Frank van der Linden for Wasabi Systems, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + + +#include <machine/asm.h> +#include <machine/setjmp.h> + +/* + * C library -- _setjmp, _longjmp + * + * longjmp(a,v) + * will generate a "return(v)" from the last call to + * setjmp(a) + * by restoring registers from the stack. + * The previous signal state is restored. + */ + +ENTRY(setjmp) + movq (%rsp),%r11 + movq %rbx,(_JB_RBX * 8)(%rdi) + movq %rbp,(_JB_RBP * 8)(%rdi) + movq %r12,(_JB_R12 * 8)(%rdi) + movq %r13,(_JB_R13 * 8)(%rdi) + movq %r14,(_JB_R14 * 8)(%rdi) + movq %r15,(_JB_R15 * 8)(%rdi) + movq %rsp,(_JB_RSP * 8)(%rdi) + movq %r11,(_JB_PC * 8)(%rdi) + + pushq %rdi + xorq %rdi,%rdi +#ifdef PIC + call PIC_PLT(_C_LABEL(sigblock)) +#else + call _C_LABEL(sigblock) +#endif + popq %rdi + movq %rax,(_JB_SIGMASK * 8)(%rdi) + +2: xorl %eax,%eax + ret + +ENTRY(longjmp) + movq %rdi,%r12 + movl %esi,%r8d + + movq (_JB_SIGMASK * 8)(%rdi),%rdi + pushq %r8 +#ifdef PIC + call PIC_PLT(_C_LABEL(sigsetmask)) +#else + call _C_LABEL(sigsetmask) +#endif + popq %r8 + movq (_JB_RBX * 8)(%r12),%rbx + movq (_JB_RBP * 8)(%r12),%rbp + movq (_JB_R13 * 8)(%r12),%r13 + movq (_JB_R14 * 8)(%r12),%r14 + movq (_JB_R15 * 8)(%r12),%r15 + movq (_JB_RSP * 8)(%r12),%rsp + movq (_JB_PC * 8)(%r12),%r11 + movq (_JB_R12 * 8)(%r12),%r12 + + movl %r8d,%eax + testl %eax,%eax + jnz 1f + incl %eax +1: movq %r11,0(%rsp) + ret diff --git a/lib/libc/arch/amd64/gen/sigsetjmp.S b/lib/libc/arch/amd64/gen/sigsetjmp.S new file mode 100644 index 00000000000..44fb4ca2249 --- /dev/null +++ b/lib/libc/arch/amd64/gen/sigsetjmp.S @@ -0,0 +1,107 @@ +/* $OpenBSD: sigsetjmp.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: __setjmp14.S,v 1.1 2001/06/19 00:25:02 fvdl Exp $ */ + +/* + * Copyright (c) 2001 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Frank van der Linden for Wasabi Systems, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + + +#include <machine/asm.h> +#include <machine/setjmp.h> + +/* + * C library -- _setjmp, _longjmp + * + * longjmp(a,v) + * will generate a "return(v)" from the last call to + * setjmp(a) + * by restoring registers from the stack. + * The previous signal state is restored. + */ + +ENTRY(sigsetjmp) + movq (%rsp),%r11 + movq %rbx,(_JB_RBX * 8)(%rdi) + movq %rbp,(_JB_RBP * 8)(%rdi) + movq %r12,(_JB_R12 * 8)(%rdi) + movq %r13,(_JB_R13 * 8)(%rdi) + movq %r14,(_JB_R14 * 8)(%rdi) + movq %r15,(_JB_R15 * 8)(%rdi) + movq %rsp,(_JB_RSP * 8)(%rdi) + movq %r11,(_JB_PC * 8)(%rdi) + + movq %rsi,(_JB_SIGFLAG * 8)(%rdi) + testl %esi,%esi + jz 2f + + pushq %rdi + xorq %rdi,%rdi +#ifdef PIC + call PIC_PLT(_C_LABEL(sigblock)) +#else + call _C_LABEL(sigblock) +#endif + popq %rdi + movq %rax,(_JB_SIGMASK * 8)(%rdi) + +2: xorl %eax,%eax + ret + +ENTRY(siglongjmp) + movq %rdi,%r12 + pushq %rsi + cmpl $0, (_JB_SIGFLAG * 8)(%rdi) + jz 2f + + movq (_JB_SIGMASK * 8)(%rdi),%rdi +#ifdef PIC + call PIC_PLT(_C_LABEL(sigsetmask)) +#else + call _C_LABEL(sigsetmask) +#endif +2: popq %rax + movq (_JB_RBX * 8)(%r12),%rbx + movq (_JB_RBP * 8)(%r12),%rbp + movq (_JB_R13 * 8)(%r12),%r13 + movq (_JB_R14 * 8)(%r12),%r14 + movq (_JB_R15 * 8)(%r12),%r15 + movq (_JB_RSP * 8)(%r12),%rsp + movq (_JB_PC * 8)(%r12),%r11 + movq (_JB_R12 * 8)(%r12),%r12 + + testl %eax,%eax + jnz 1f + incl %eax +1: movq %r11,0(%rsp) + ret diff --git a/lib/libc/arch/amd64/net/Makefile.inc b/lib/libc/arch/amd64/net/Makefile.inc new file mode 100644 index 00000000000..4c046a624dd --- /dev/null +++ b/lib/libc/arch/amd64/net/Makefile.inc @@ -0,0 +1,4 @@ +# $OpenBSD: Makefile.inc,v 1.1 2004/01/28 01:44:45 mickey Exp $ + +SRCS+= htonl.S htons.S ntohl.S ntohs.S +LSRCS+= htonl.c htons.c ntohl.c ntohs.c diff --git a/lib/libc/arch/amd64/net/htonl.S b/lib/libc/arch/amd64/net/htonl.S new file mode 100644 index 00000000000..e4c951a4b40 --- /dev/null +++ b/lib/libc/arch/amd64/net/htonl.S @@ -0,0 +1,10 @@ +/* $OpenBSD: htonl.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ + +/* Written by Artur Grabowski. Public Domain */ + +#include <machine/asm.h> + +ENTRY(_C_LABEL(htonl)) + movl %edi,%eax + bswapl %eax + ret diff --git a/lib/libc/arch/amd64/net/htons.S b/lib/libc/arch/amd64/net/htons.S new file mode 100644 index 00000000000..80d9f9374a8 --- /dev/null +++ b/lib/libc/arch/amd64/net/htons.S @@ -0,0 +1,11 @@ +/* $OpenBSD: htons.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ + +/* Written by Artur Grabowski. Public Domain */ + +#include <machine/asm.h> + +ENTRY(_C_LABEL(htonl)) + movl %edi,%eax + xchgb %ah,%al + ret + diff --git a/lib/libc/arch/amd64/net/ntohl.S b/lib/libc/arch/amd64/net/ntohl.S new file mode 100644 index 00000000000..4a21dc541ca --- /dev/null +++ b/lib/libc/arch/amd64/net/ntohl.S @@ -0,0 +1,10 @@ +/* $OpenBSD: ntohl.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ + +/* Written by Artur Grabowski. Public Domain */ + +#include <machine/asm.h> + +ENTRY(_C_LABEL(htonl)) + movl %edi,%eax + bswapl %eax + ret diff --git a/lib/libc/arch/amd64/net/ntohs.S b/lib/libc/arch/amd64/net/ntohs.S new file mode 100644 index 00000000000..6c70cc26945 --- /dev/null +++ b/lib/libc/arch/amd64/net/ntohs.S @@ -0,0 +1,11 @@ +/* $OpenBSD: ntohs.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ + +/* Written by Artur Grabowski. Public Domain */ + +#include <machine/asm.h> + +ENTRY(_C_LABEL(htonl)) + movl %edi,%eax + xchgb %ah,%al + ret + diff --git a/lib/libc/arch/amd64/string/Makefile.inc b/lib/libc/arch/amd64/string/Makefile.inc new file mode 100644 index 00000000000..002194e1d8c --- /dev/null +++ b/lib/libc/arch/amd64/string/Makefile.inc @@ -0,0 +1,6 @@ +# $OpenBSD: Makefile.inc,v 1.1 2004/01/28 01:44:45 mickey Exp $ + +SRCS+= bcmp.c ffs.S index.c memchr.c memcmp.c bcopy.c bzero.c \ + rindex.c strcat.c strcmp.c strcpy.c strcspn.c strlen.S \ + strncat.c strncmp.c strncpy.c strpbrk.c strsep.c \ + strspn.c strstr.c swab.c memset.c strlcpy.c strlcat.c diff --git a/lib/libc/arch/amd64/string/ffs.S b/lib/libc/arch/amd64/string/ffs.S new file mode 100644 index 00000000000..2666bc49e9d --- /dev/null +++ b/lib/libc/arch/amd64/string/ffs.S @@ -0,0 +1,18 @@ +/* $OpenBSD: ffs.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* + * Written by J.T. Conklin <jtc@netbsd.org>. + * Public domain. + * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com> + */ + +#include <machine/asm.h> + +ENTRY(ffs) + bsfl %edi,%eax + jz L1 /* ZF is set if all bits are 0 */ + incl %eax /* bits numbered from 1, not 0 */ + ret + + _ALIGN_TEXT +L1: xorl %eax,%eax /* clear result */ + ret diff --git a/lib/libc/arch/amd64/string/strlen.S b/lib/libc/arch/amd64/string/strlen.S new file mode 100644 index 00000000000..3afccb8f1ac --- /dev/null +++ b/lib/libc/arch/amd64/string/strlen.S @@ -0,0 +1,18 @@ +/* $OpenBSD: strlen.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* + * Written by J.T. Conklin <jtc@netbsd.org>. + * Public domain. + * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com> + */ + +#include <machine/asm.h> + +ENTRY(strlen) + cld /* set search forward */ + xorl %eax,%eax /* set search for null terminator */ + movq $-1,%rcx /* set search for lots of characters */ + repne /* search! */ + scasb + notq %rcx /* get length by taking complement */ + leaq -1(%rcx),%rax /* and subtracting one */ + ret diff --git a/lib/libc/arch/amd64/sys/Ovfork.S b/lib/libc/arch/amd64/sys/Ovfork.S new file mode 100644 index 00000000000..865d460014f --- /dev/null +++ b/lib/libc/arch/amd64/sys/Ovfork.S @@ -0,0 +1,67 @@ +/* $OpenBSD: Ovfork.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: Ovfork.S,v 1.2 2002/06/03 18:30:33 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)Ovfork.s 5.1 (Berkeley) 4/23/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" + +/* + * pid = vfork(); + * + * %edx == 0 in parent process, %edx == 1 in child process. + * %eax == pid of child in parent, %eax == pid of parent in child. + * + */ +SYSENTRY(vfork) + popq %r9 /* my rta into r9 */ + SYSTRAP(vfork) + jc err + decl %edx + andl %edx,%eax + jmp *%r9 +err: + pushq %r9 +#ifdef PIC + movq PIC_GOT(CERROR), %rcx + jmp *%rcx +#else + jmp CERROR +#endif diff --git a/lib/libc/arch/amd64/sys/brk.S b/lib/libc/arch/amd64/sys/brk.S new file mode 100644 index 00000000000..1563091c7f3 --- /dev/null +++ b/lib/libc/arch/amd64/sys/brk.S @@ -0,0 +1,87 @@ +/* $OpenBSD: brk.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: brk.S,v 1.2 2002/06/03 18:30:33 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)brk.s 5.2 (Berkeley) 12/17/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" + + .globl _end + .globl _C_LABEL(__minbrk) + .globl CURBRK + +#ifdef WEAK_ALIAS +WEAK_ALIAS(brk, _brk) +#endif + + .data +_C_LABEL(__minbrk): + .quad _end + .text + +SYSENTRY(_brk) +#ifdef PIC + movq PIC_GOT(_C_LABEL(__minbrk)),%rdx + cmpq %rdi,(%rdx) + jb 1f + movq (%rdx),%rdi +1: + SYSTRAP(break) + jc err + movq PIC_GOT(CURBRK),%rdx # set up GOT addressing + movq %rdi,(%rdx) + xorl %eax,%eax + ret +err: + movq PIC_GOT(CERROR),%rdx + jmp *%rdx +#else + cmpq %rdi,_C_LABEL(__minbrk)(%rip) + jb 1f + movq _C_LABEL(__minbrk)(%rip),%rdi +1: + SYSTRAP(break) + jc err + movq %rdi,CURBRK(%rip) + xorl %eax,%eax + ret +err: + jmp CERROR +#endif diff --git a/lib/libc/arch/amd64/sys/cerror.S b/lib/libc/arch/amd64/sys/cerror.S new file mode 100644 index 00000000000..400bb5d81e0 --- /dev/null +++ b/lib/libc/arch/amd64/sys/cerror.S @@ -0,0 +1,55 @@ +/* $OpenBSD: cerror.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: cerror.S,v 1.2 2002/06/03 18:30:33 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)cerror.s 5.1 (Berkeley) 4/23/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" + + .globl _C_LABEL(errno) + +_ENTRY(CERROR) +#ifdef PIC + movq %rax, PIC_GOT(_C_LABEL(errno)) +#else + movq %rax, _C_LABEL(errno)(%rip) +#endif /* PIC */ + movq $-1,%rax + ret diff --git a/lib/libc/arch/amd64/sys/exect.S b/lib/libc/arch/amd64/sys/exect.S new file mode 100644 index 00000000000..31028402b6a --- /dev/null +++ b/lib/libc/arch/amd64/sys/exect.S @@ -0,0 +1,57 @@ +/* $OpenBSD: exect.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: exect.S,v 1.1 2001/06/19 00:25:06 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)exect.s 5.1 (Berkeley) 4/23/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" +#include <machine/psl.h> + +SYSENTRY(exect) + pushfq + orb $(PSL_T>>8),1(%rsp) + popfq + SYSTRAP(execve) +#ifdef PIC + movq PIC_GOT(CERROR), %rcx + jmp *%rcx +#else + jmp CERROR +#endif diff --git a/lib/libc/arch/amd64/sys/fork.S b/lib/libc/arch/amd64/sys/fork.S new file mode 100644 index 00000000000..155ee7227d6 --- /dev/null +++ b/lib/libc/arch/amd64/sys/fork.S @@ -0,0 +1,49 @@ +/* $OpenBSD: fork.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: fork.S,v 1.2 2003/02/13 02:50:51 nathanw Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)fork.s 5.1 (Berkeley) 4/23/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" + +SYSCALL(fork) + decl %edx /* from 1 to 0 in child, 0 to -1 in parent */ + andl %edx,%eax + ret /* pid = fork(); */ diff --git a/lib/libc/arch/amd64/sys/rfork.S b/lib/libc/arch/amd64/sys/rfork.S new file mode 100644 index 00000000000..caedbbd9aff --- /dev/null +++ b/lib/libc/arch/amd64/sys/rfork.S @@ -0,0 +1,48 @@ +/* $OpenBSD: rfork.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)fork.s 5.1 (Berkeley) 4/23/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" + +SYSCALL(rfork) + decl %edx /* from 1 to 0 in child, 0 to -1 in parent */ + andl %edx,%eax + ret /* pid = rfork(); */ diff --git a/lib/libc/arch/amd64/sys/sbrk.S b/lib/libc/arch/amd64/sys/sbrk.S new file mode 100644 index 00000000000..aad5f89d7d8 --- /dev/null +++ b/lib/libc/arch/amd64/sys/sbrk.S @@ -0,0 +1,82 @@ +/* $OpenBSD: sbrk.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: sbrk.S,v 1.1 2001/06/19 00:25:06 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)sbrk.s 5.1 (Berkeley) 4/23/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" + + .globl _end + .globl CURBRK + +#ifdef WEAK_ALIAS +WEAK_ALIAS(sbrk, _sbrk) +#endif + + .data +CURBRK: .quad _end + .text + +SYSENTRY(_sbrk) +#ifdef PIC + movq PIC_GOT(CURBRK),%rdx + movq (%rdx),%rax + addq %rax,%rdi + SYSTRAP(break) + jc err + movq PIC_GOT(CURBRK),%rdx + movq (%rdx),%rax + movq %rdi,(%rdx) + ret +err: + mov PIC_GOT(CERROR),%rdx + jmp *%rdx +#else + movq CURBRK(%rip),%rax + movq %rdi,%rsi + addq %rax,%rdi + SYSTRAP(break) + jc err + movq CURBRK(%rip),%rax + addq %rsi,CURBRK(%rip) + ret +err: + jmp CERROR +#endif diff --git a/lib/libc/arch/amd64/sys/sigpending.S b/lib/libc/arch/amd64/sys/sigpending.S new file mode 100644 index 00000000000..bbebd47c6bf --- /dev/null +++ b/lib/libc/arch/amd64/sys/sigpending.S @@ -0,0 +1,49 @@ +/* $OpenBSD: sigpending.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: sigpending.S,v 1.1 2001/06/19 00:25:06 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)sigpending.s 5.1 (Berkeley) 7/1/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" + +SYSCALL(sigpending) + movl %eax,(%rdi) # store old mask + xorl %eax,%eax + ret diff --git a/lib/libc/arch/amd64/sys/sigprocmask.S b/lib/libc/arch/amd64/sys/sigprocmask.S new file mode 100644 index 00000000000..3718f8de3ae --- /dev/null +++ b/lib/libc/arch/amd64/sys/sigprocmask.S @@ -0,0 +1,66 @@ +/* $OpenBSD: sigprocmask.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: sigprocmask.S,v 1.1 2001/06/19 00:25:06 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)sigprocmask.s 5.2 (Berkeley) 12/17/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" + +SYSENTRY(sigprocmask) + testq %rsi,%rsi # check new sigset pointer + jnz 1f # if not null, indirect + movl $1,%edi # SIG_BLOCK + jmp 2f +1: movl (%rsi),%esi # fetch indirect ... +2: SYSTRAP(sigprocmask) + jc err + testq %rdx,%rdx # test if old mask requested + jz out + movq %rax,(%rdx) # store old mask +out: + xorl %eax,%eax + ret +err: +#ifdef PIC + movq PIC_GOT(CERROR), %rcx + jmp *%rcx +#else + jmp CERROR +#endif diff --git a/lib/libc/arch/amd64/sys/sigreturn.S b/lib/libc/arch/amd64/sys/sigreturn.S new file mode 100644 index 00000000000..e065cbc894d --- /dev/null +++ b/lib/libc/arch/amd64/sys/sigreturn.S @@ -0,0 +1,60 @@ +/* $OpenBSD: sigreturn.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: __sigreturn14.S,v 1.1 2001/06/19 00:25:06 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)sigreturn.s 5.2 (Berkeley) 12/17/90" + */ + +#include <machine/asm.h> + +#include "SYS.h" + +/* + * We must preserve the state of the registers as the user has set them up. + */ +#if 0 /* XXXfvdl fix later, but this one is really low priority */ +#ifdef GPROF +#undef ENTRY +#define MCOUNT_SYMBOL __mcount +#define ENTRY(x) \ + .globl _/**/x; _ALIGN_TEXT; _/**/x: pusha ; \ + .data; 1:; .long 0; .text; movl $1b,%eax; call MCOUNT_SYMBOL; popa ; nop +#endif /* GPROF */ +#endif + +SYSCALL(sigreturn) + ret diff --git a/lib/libc/arch/amd64/sys/sigsuspend.S b/lib/libc/arch/amd64/sys/sigsuspend.S new file mode 100644 index 00000000000..985bf61b99d --- /dev/null +++ b/lib/libc/arch/amd64/sys/sigsuspend.S @@ -0,0 +1,58 @@ +/* $OpenBSD: sigsuspend.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: sigsuspend.S,v 1.1 2001/06/19 00:25:07 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)sigsuspend.s 5.2 (Berkeley) 12/17/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" + +SYSENTRY(sigsuspend) + movl (%rdi),%edi # indirect to mask arg + SYSTRAP(sigsuspend) + jc err + xorl %eax,%eax # shouldn t happen + ret +err: +#ifdef PIC + movq PIC_GOT(CERROR), %rcx + jmp *%rcx +#else + jmp CERROR +#endif diff --git a/lib/libc/arch/amd64/sys/syscall.S b/lib/libc/arch/amd64/sys/syscall.S new file mode 100644 index 00000000000..19b798dbc92 --- /dev/null +++ b/lib/libc/arch/amd64/sys/syscall.S @@ -0,0 +1,57 @@ +/* $OpenBSD: syscall.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: syscall.S,v 1.2 2002/06/03 18:30:33 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)syscall.s 5.1 (Berkeley) 4/23/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" + +SYSENTRY(syscall) + movl %edi,%eax + syscall + jc err + ret +err: +#ifdef PIC + movq PIC_GOT(CERROR), %rcx + jmp *%rcx +#else + jmp CERROR +#endif diff --git a/lib/libc/arch/x86_64/Makefile.inc b/lib/libc/arch/x86_64/Makefile.inc new file mode 100644 index 00000000000..53949f1c6bc --- /dev/null +++ b/lib/libc/arch/x86_64/Makefile.inc @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile.inc,v 1.1 2004/01/28 01:44:44 mickey Exp $ + +KMINCLUDES= arch/x86_64/SYS.h +KMSRCS= bcmp.S bzero.S ffs.S strcat.S strcmp.S strcpy.S strlen.S \ + htonl.S htons.S ntohl.S ntohs.S diff --git a/lib/libc/arch/x86_64/SYS.h b/lib/libc/arch/x86_64/SYS.h new file mode 100644 index 00000000000..bdf0bfe6d03 --- /dev/null +++ b/lib/libc/arch/x86_64/SYS.h @@ -0,0 +1,107 @@ +/* $OpenBSD: SYS.h,v 1.1 2004/01/28 01:44:44 mickey Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)SYS.h 5.5 (Berkeley) 5/7/91 + * $NetBSD: SYS.h,v 1.5 2002/06/03 18:30:32 fvdl Exp $ + */ + +/* + * XXXfvdl change to use syscall/sysret. + */ + +#include <machine/asm.h> +#include <sys/syscall.h> + +#ifdef __STDC__ +#define SYSTRAP(x) movl $(SYS_ ## x),%eax; movq %rcx, %r10; syscall +#else +#define SYSTRAP(x) movl $(SYS_/**/x),%eax; movq %rcx, %r10; syscall +#endif + +#define CERROR _C_LABEL(__cerror) +#define CURBRK _C_LABEL(__curbrk) + +#define SYSENTRY(x) \ + ENTRY(_thread_sys_ ## x); \ + .weak _C_LABEL(x); \ + _C_LABEL(x) = _C_LABEL(_thread_sys_ ## x) + + +#define _SYSCALL_NOERROR(x,y) \ + SYSENTRY(x); \ + SYSTRAP(y) + +#ifdef PIC +#define _SYSCALL(x,y) \ + .text; _ALIGN_TEXT; \ + 2: mov PIC_GOT(CERROR), %rcx; \ + jmp *%rcx; \ + _SYSCALL_NOERROR(x,y); \ + jc 2b +#else +#define _SYSCALL(x,y) \ + .text; _ALIGN_TEXT; \ + 2: jmp CERROR; \ + _SYSCALL_NOERROR(x,y); \ + jc 2b +#endif + +#define SYSCALL_NOERROR(x) \ + _SYSCALL_NOERROR(x,x) + +#define SYSCALL(x) \ + _SYSCALL(x,x) + +#define PSEUDO_NOERROR(x,y) \ + _SYSCALL_NOERROR(x,y); \ + ret + +#define PSEUDO(x,y) \ + _SYSCALL(x,y); \ + ret + +#define RSYSCALL_NOERROR(x) \ + PSEUDO_NOERROR(x,x) + +#define RSYSCALL(x) \ + PSEUDO(x,x) + +#define WSYSCALL(weak,strong) \ + WEAK_ALIAS(weak,strong); \ + PSEUDO(strong,weak) + + .globl CERROR diff --git a/lib/libc/arch/x86_64/gen/Makefile.inc b/lib/libc/arch/x86_64/gen/Makefile.inc new file mode 100644 index 00000000000..a150d95eba0 --- /dev/null +++ b/lib/libc/arch/x86_64/gen/Makefile.inc @@ -0,0 +1,7 @@ +# $OpenBSD: Makefile.inc,v 1.1 2004/01/28 01:44:44 mickey Exp $ + +SRCS+= _setjmp.S alloca.S fabs.S frexp.c infinity.c isinf.c isnan.c ldexp.c \ + modf.S setjmp.S sigsetjmp.S +SRCS+= flt_rounds.S fpgetmask.S fpgetround.S fpgetsticky.S fpsetmask.S \ + fpsetround.S fpsetsticky.S + diff --git a/lib/libc/arch/x86_64/gen/_setjmp.S b/lib/libc/arch/x86_64/gen/_setjmp.S new file mode 100644 index 00000000000..d9a59f7aa14 --- /dev/null +++ b/lib/libc/arch/x86_64/gen/_setjmp.S @@ -0,0 +1,82 @@ +/* $OpenBSD: _setjmp.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: _setjmp.S,v 1.1 2001/06/19 00:25:02 fvdl Exp $ */ + +/* + * Copyright (c) 2001 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Frank van der Linden for Wasabi Systems, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + + +#include <machine/asm.h> +#include <machine/setjmp.h> + +/* + * C library -- _setjmp, _longjmp + * + * _longjmp(a,v) + * will generate a "return(v)" from the last call to + * _setjmp(a) + * by restoring registers from the stack. + * The previous signal state is NOT restored. + */ + +ENTRY(_setjmp) + movq (%rsp),%r11 + movq %rbx,(_JB_RBX * 8)(%rdi) + movq %rbp,(_JB_RBP * 8)(%rdi) + movq %r12,(_JB_R12 * 8)(%rdi) + movq %r13,(_JB_R13 * 8)(%rdi) + movq %r14,(_JB_R14 * 8)(%rdi) + movq %r15,(_JB_R15 * 8)(%rdi) + movq %rsp,(_JB_RSP * 8)(%rdi) + movq %r11,(_JB_PC * 8)(%rdi) + + xorl %eax,%eax + ret + +ENTRY(_longjmp) + movq (_JB_RBX * 8)(%rdi),%rbx + movq (_JB_RBP * 8)(%rdi),%rbp + movq (_JB_R12 * 8)(%rdi),%r12 + movq (_JB_R13 * 8)(%rdi),%r13 + movq (_JB_R14 * 8)(%rdi),%r14 + movq (_JB_R15 * 8)(%rdi),%r15 + movq (_JB_RSP * 8)(%rdi),%rsp + movq (_JB_PC * 8)(%rdi),%r11 + + movl %esi,%eax + testl %eax,%eax + jnz 1f + incl %eax +1: movq %r11,0(%rsp) + ret diff --git a/lib/libc/arch/x86_64/gen/alloca.S b/lib/libc/arch/x86_64/gen/alloca.S new file mode 100644 index 00000000000..8c15583012c --- /dev/null +++ b/lib/libc/arch/x86_64/gen/alloca.S @@ -0,0 +1,13 @@ +/* $OpenBSD: alloca.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: alloca.S,v 1.1 2001/06/19 00:25:02 fvdl Exp $ */ + +#include <machine/asm.h> + +ENTRY(alloca) + popq %rdx + movq %rsp,%rcx + addq $15,%rdi /* round up to 16 bytes */ + andq $~15,%rdi + subq %rdi,%rsp + movq %rsp,%rax + jmp *%rdx diff --git a/lib/libc/arch/x86_64/gen/fabs.S b/lib/libc/arch/x86_64/gen/fabs.S new file mode 100644 index 00000000000..b94e862c1e9 --- /dev/null +++ b/lib/libc/arch/x86_64/gen/fabs.S @@ -0,0 +1,17 @@ +/* $OpenBSD: fabs.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: fabs.S,v 1.1 2001/06/19 00:25:02 fvdl Exp $ */ + +#include <machine/asm.h> + +/* + * Ok, this sucks. Is there really no way to push an xmm register onto + * the FP stack directly? + */ + +ENTRY(fabs) + movsd %xmm0, -8(%rsp) + fldl -8(%rsp) + fabs + fstp -8(%rsp) + movsd -8(%rsp),%xmm0 + ret diff --git a/lib/libc/arch/x86_64/gen/flt_rounds.S b/lib/libc/arch/x86_64/gen/flt_rounds.S new file mode 100644 index 00000000000..009c59ab64a --- /dev/null +++ b/lib/libc/arch/x86_64/gen/flt_rounds.S @@ -0,0 +1,30 @@ +/* $OpenBSD: flt_rounds.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: flt_rounds.S,v 1.2 2002/06/06 23:04:35 fvdl Exp $ */ + +/* + * Written by J.T. Conklin, Apr 4, 1995 + * Public domain. + */ + +#include <machine/asm.h> + + .text + _ALIGN_TEXT +_map: + .byte 1 /* round to nearest */ + .byte 3 /* round to negative infinity */ + .byte 2 /* round to positive infinity */ + .byte 0 /* round to zero */ + +ENTRY(__flt_rounds) + fnstcw -4(%rsp) + movl -4(%rsp),%eax + shrl $10,%eax + andl $3,%eax +#ifdef PIC + leaq PIC_GOT(_map),%rcx + movb (%rcx,%rax,1),%al +#else + movb _map(,%rax,1),%al +#endif + ret diff --git a/lib/libc/arch/x86_64/gen/fpgetmask.S b/lib/libc/arch/x86_64/gen/fpgetmask.S new file mode 100644 index 00000000000..688ba49cddc --- /dev/null +++ b/lib/libc/arch/x86_64/gen/fpgetmask.S @@ -0,0 +1,27 @@ +/* $OpenBSD: fpgetmask.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: fpgetmask.S,v 1.3 2002/06/12 19:17:22 fvdl Exp $ */ + +/* + * Written by J.T. Conklin, Apr 4, 1995 + * Public domain. + */ + +#include <machine/asm.h> + +/* + * XXX only read x87 control word here. If an application only + * uses the fp* interface to manipulate FP bits, it should + * always remain in sync with the SSE mxcsr register. + */ + +#ifdef WEAK_ALIAS +WEAK_ALIAS(fpgetmask, _fpgetmask) +ENTRY(_fpgetmask) +#else +ENTRY(fpgetmask) +#endif + fnstcw -4(%rsp) + movl -4(%rsp),%eax + notl %eax + andl $63,%eax + ret diff --git a/lib/libc/arch/x86_64/gen/fpgetround.S b/lib/libc/arch/x86_64/gen/fpgetround.S new file mode 100644 index 00000000000..5220b3ef396 --- /dev/null +++ b/lib/libc/arch/x86_64/gen/fpgetround.S @@ -0,0 +1,26 @@ +/* $OpenBSD: fpgetround.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: fpgetround.S,v 1.3 2002/06/12 19:17:22 fvdl Exp $ */ + +/* + * Written by J.T. Conklin, Apr 4, 1995 + * Public domain. + */ + +#include <machine/asm.h> + +/* + * XXX store only x87 state. If an application only uses the fp* + * interface, this should be in sync with the SSE mxcsr register. + */ + +#ifdef WEAK_ALIAS +WEAK_ALIAS(fpgetround, _fpgetround) +ENTRY(_fpgetround) +#else +ENTRY(fpgetround) +#endif + fnstcw -4(%rsp) + movl -4(%rsp),%eax + rorl $10,%eax + andl $3,%eax + ret diff --git a/lib/libc/arch/x86_64/gen/fpgetsticky.S b/lib/libc/arch/x86_64/gen/fpgetsticky.S new file mode 100644 index 00000000000..fd12e2b500a --- /dev/null +++ b/lib/libc/arch/x86_64/gen/fpgetsticky.S @@ -0,0 +1,28 @@ +/* $OpenBSD: fpgetsticky.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: fpgetsticky.S,v 1.3 2002/06/12 19:17:22 fvdl Exp $ */ + +/* + * Written by Frank van der Linden at Wasabi Systems for NetBSD. + * Public domain. + * + */ + +#include <machine/asm.h> + +/* + * XXX read both the x87 and SSE status words here, and OR + * them to get a complete picture of exceptions. + */ + +#ifdef WEAK_ALIAS +WEAK_ALIAS(fpgetsticky, _fpgetsticky) +ENTRY(_fpgetsticky) +#else +ENTRY(fpgetsticky) +#endif + fnstsw -4(%rsp) + stmxcsr -8(%rsp) + movl -4(%rsp),%eax + orl -8(%rsp),%eax + andl $63,%eax + ret diff --git a/lib/libc/arch/x86_64/gen/fpsetmask.S b/lib/libc/arch/x86_64/gen/fpsetmask.S new file mode 100644 index 00000000000..665d55e8e47 --- /dev/null +++ b/lib/libc/arch/x86_64/gen/fpsetmask.S @@ -0,0 +1,42 @@ +/* $OpenBSD: fpsetmask.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: fpsetmask.S,v 1.3 2002/06/12 19:17:22 fvdl Exp $ */ + +/* + * Written by Frank van der Linden at Wasabi Systems for NetBSD. + * Public domain. + */ + +#include <machine/asm.h> + +/* + * XXX set both the x87 control word and the SSE mxcsr register. + * Applications should only set exception and round flags + * via the fp*() interface, otherwise the status words + * will get our of sync. + */ + +#ifdef WEAK_ALIAS +WEAK_ALIAS(fpsetmask, _fpsetmask) +ENTRY(_fpsetmask) +#else +ENTRY(fpsetmask) +#endif + fnstcw -4(%rsp) + stmxcsr -8(%rsp) + andl $63,%edi + notl %edi + + movl -4(%rsp),%edx + movl %edx,%eax + andl %edi,%edx + movl %edx,-4(%rsp) + + movl -8(%rsp),%edx + roll $7,%edi + andl %edi,%edx + movl %edx,-8(%rsp) + + fldcw -4(%rsp) + ldmxcsr -8(%rsp) + andl $63,%eax + ret diff --git a/lib/libc/arch/x86_64/gen/fpsetround.S b/lib/libc/arch/x86_64/gen/fpsetround.S new file mode 100644 index 00000000000..b8508f8b6bd --- /dev/null +++ b/lib/libc/arch/x86_64/gen/fpsetround.S @@ -0,0 +1,49 @@ +/* $OpenBSD: fpsetround.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: fpsetround.S,v 1.3 2002/06/12 19:17:22 fvdl Exp $ */ + +/* + * Written by Frank van der Linden at Wasabi Systems for NetBSD. + * Public domain. + */ + +#include <machine/asm.h> + +/* + * XXX set both the x87 control word and the SSE mxcsr register. + * Applications should only set exception and round flags + * via the fp*() interface, otherwise the status words + * will get our of sync. + */ + + +#ifdef WEAK_ALIAS +WEAK_ALIAS(fpsetround, _fpsetround) +ENTRY(_fpsetround) +#else +ENTRY(fpsetround) +#endif + fnstcw -4(%rsp) + stmxcsr -8(%rsp) + + andl $3,%edi + + movl -4(%rsp),%edx + rorl $10,%edx + movl %edx,%eax + andl $3,%eax + + andl $~3,%edx + orl %edi,%edx + roll $10,%edx + movl %edx,-4(%rsp) + + movl -8(%rsp),%edx + rorl $13,%edx + andl $~3,%edx + orl %edi,%edx + roll $13,%edx + movl %edx,-8(%rsp) + + ldmxcsr -8(%rsp) + fldcw -4(%rsp) + ret diff --git a/lib/libc/arch/x86_64/gen/fpsetsticky.S b/lib/libc/arch/x86_64/gen/fpsetsticky.S new file mode 100644 index 00000000000..c8e61101a12 --- /dev/null +++ b/lib/libc/arch/x86_64/gen/fpsetsticky.S @@ -0,0 +1,43 @@ +/* $OpenBSD: fpsetsticky.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: fpsetsticky.S,v 1.3 2002/06/12 19:17:23 fvdl Exp $ */ + +/* + * Written by Frank van der Linden at Wasabi Systems for NetBSD + * Public domain. + */ + +#include <machine/asm.h> + +/* + * XXX set both the x87 status word and the SSE mxcsr register. + * Applications should only set exception and round flags + * via the fp*() interface, otherwise the status words + * will get our of sync. + */ + + +#ifdef WEAK_ALIAS +WEAK_ALIAS(fpsetsticky, _fpsetsticky) +ENTRY(_fpsetsticky) +#else +ENTRY(fpsetsticky) +#endif + fnstenv -28(%rsp) + stmxcsr -32(%rsp) + + andl $63,%edi + + movl -24(%rsp),%eax + movl %eax,%edx + andl $63,%eax + + orl %edi,%edx + movl %edx,-24(%rsp) + + movl -32(%rsp),%edx + orl %edi,%edx + movl %edx,-32(%rsp) + + ldmxcsr -32(%rsp) + fldenv -28(%rsp) + ret diff --git a/lib/libc/arch/x86_64/gen/frexp.c b/lib/libc/arch/x86_64/gen/frexp.c new file mode 100644 index 00000000000..bc84467fa9e --- /dev/null +++ b/lib/libc/arch/x86_64/gen/frexp.c @@ -0,0 +1,74 @@ +/* $OpenBSD: frexp.c,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: frexp.c,v 1.1 2004/01/28 01:44:45 mickey Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <machine/ieee.h> + +/* + * Split the given value into a fraction in the range [0.5, 1.0) and + * an exponent, such that frac * (2^exp) == value. If value is 0, + * return 0. + */ +double +frexp(value, eptr) + double value; + int *eptr; +{ + union { + double v; + struct ieee_double s; + } u; + + if (value) { + /* + * Fractions in [0.5..1.0) have an exponent of 2^-1. + * Leave Inf and NaN alone, however. + * WHAT ABOUT DENORMS? + */ + u.v = value; + if (u.s.dbl_exp != DBL_EXP_INFNAN) { + *eptr = u.s.dbl_exp - (DBL_EXP_BIAS - 1); + u.s.dbl_exp = DBL_EXP_BIAS - 1; + } + return (u.v); + } else { + *eptr = 0; + return ((double)0); + } +} diff --git a/lib/libc/arch/x86_64/gen/infinity.c b/lib/libc/arch/x86_64/gen/infinity.c new file mode 100644 index 00000000000..8c7eb66d407 --- /dev/null +++ b/lib/libc/arch/x86_64/gen/infinity.c @@ -0,0 +1,10 @@ +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: infinity.c,v 1.1 2004/01/28 01:44:45 mickey Exp $"; +#endif /* LIBC_SCCS and not lint */ + +/* infinity.c */ + +#include <math.h> + +/* bytes for +Infinity on a 387 */ +char __infinity[] = { 0, 0, 0, 0, 0, 0, (char)0xf0, 0x7f }; diff --git a/lib/libc/arch/x86_64/gen/isinf.c b/lib/libc/arch/x86_64/gen/isinf.c new file mode 100644 index 00000000000..6d29660d7f2 --- /dev/null +++ b/lib/libc/arch/x86_64/gen/isinf.c @@ -0,0 +1,51 @@ +/* $OpenBSD: isinf.c,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: isinf.c,v 1.1 2004/01/28 01:44:45 mickey Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <machine/ieee.h> + +int +isinf(d) + double d; +{ + struct ieee_double *p = (struct ieee_double *)&d; + + return (p->dbl_exp == DBL_EXP_INFNAN && + p->dbl_frach == 0 && p->dbl_fracl == 0); +} diff --git a/lib/libc/arch/x86_64/gen/isnan.c b/lib/libc/arch/x86_64/gen/isnan.c new file mode 100644 index 00000000000..5df82ecce25 --- /dev/null +++ b/lib/libc/arch/x86_64/gen/isnan.c @@ -0,0 +1,51 @@ +/* $OpenBSD: isnan.c,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: isnan.c,v 1.1 2004/01/28 01:44:45 mickey Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <machine/ieee.h> + +int +isnan(d) + double d; +{ + struct ieee_double *p = (struct ieee_double *)&d; + + return (p->dbl_exp == DBL_EXP_INFNAN && + (p->dbl_frach != 0 || p->dbl_fracl != 0)); +} diff --git a/lib/libc/arch/x86_64/gen/ldexp.c b/lib/libc/arch/x86_64/gen/ldexp.c new file mode 100644 index 00000000000..b3e95956652 --- /dev/null +++ b/lib/libc/arch/x86_64/gen/ldexp.c @@ -0,0 +1,57 @@ +/* $OpenBSD: ldexp.c,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Charles Hannum. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: ldexp.c,v 1.1 2004/01/28 01:44:45 mickey Exp $"; +#endif /* LIBC_SCCS and not lint */ + +/* + * ldexp(value, exp): return value * (2 ** exp). + */ + +double +ldexp (double value, int exp) +{ + double temp; +#if __GNUC__ >= 2 + __asm ("fscale" + : "=t" (temp) + : "0" (value), "u" ((double)exp)); +#else + __asm ("fscale; fstp %%st(1)" + : "=f" (temp) + : "f" (value), "0" ((double)exp)); +#endif + return (temp); +} diff --git a/lib/libc/arch/x86_64/gen/modf.S b/lib/libc/arch/x86_64/gen/modf.S new file mode 100644 index 00000000000..9e6c13b3cb4 --- /dev/null +++ b/lib/libc/arch/x86_64/gen/modf.S @@ -0,0 +1,94 @@ +/* $OpenBSD: modf.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: modf.S,v 1.1 2001/06/19 00:25:03 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Sean Eric Fagan. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)modf.s 5.5 (Berkeley) 3/18/91 + */ + +#include <machine/asm.h> + +/* + * modf(value, iptr): return fractional part of value, and stores the + * integral part into iptr (a pointer to double). + * + * Written by Sean Eric Fagan (sef@kithrup.COM) + * Sun Mar 11 20:27:30 PST 1990 + */ + +/* With CHOP mode on, frndint behaves as TRUNC does. Useful. */ +ENTRY(modf) + pushq %rbp + movq %rsp,%rbp + subq $24,%rsp + + /* + * Set chop mode. + */ + fnstcw -12(%rbp) + movw -12(%rbp),%dx + orw $3072,%dx + movw %dx,-16(%rbp) + fldcw -16(%rbp) + + /* + * Get integral part. + */ + movsd %xmm0,-24(%rbp) + fldl -24(%rbp) + frndint + fstpl -8(%rbp) + + /* + * Restore control word. + */ + fldcw -12(%rbp) + + /* + * Store integral part. + */ + movsd -8(%rbp),%xmm0 + movsd %xmm0,(%rdi) + + /* + * Get fractional part and return it. + */ + fldl -24(%rbp) + fsubl -8(%rbp) + movsd -8(%rbp),%xmm0 + + leave + ret diff --git a/lib/libc/arch/x86_64/gen/setjmp.S b/lib/libc/arch/x86_64/gen/setjmp.S new file mode 100644 index 00000000000..fb261616f0a --- /dev/null +++ b/lib/libc/arch/x86_64/gen/setjmp.S @@ -0,0 +1,103 @@ +/* $OpenBSD: setjmp.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: __setjmp14.S,v 1.1 2001/06/19 00:25:02 fvdl Exp $ */ + +/* + * Copyright (c) 2001 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Frank van der Linden for Wasabi Systems, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + + +#include <machine/asm.h> +#include <machine/setjmp.h> + +/* + * C library -- _setjmp, _longjmp + * + * longjmp(a,v) + * will generate a "return(v)" from the last call to + * setjmp(a) + * by restoring registers from the stack. + * The previous signal state is restored. + */ + +ENTRY(setjmp) + movq (%rsp),%r11 + movq %rbx,(_JB_RBX * 8)(%rdi) + movq %rbp,(_JB_RBP * 8)(%rdi) + movq %r12,(_JB_R12 * 8)(%rdi) + movq %r13,(_JB_R13 * 8)(%rdi) + movq %r14,(_JB_R14 * 8)(%rdi) + movq %r15,(_JB_R15 * 8)(%rdi) + movq %rsp,(_JB_RSP * 8)(%rdi) + movq %r11,(_JB_PC * 8)(%rdi) + + pushq %rdi + xorq %rdi,%rdi +#ifdef PIC + call PIC_PLT(_C_LABEL(sigblock)) +#else + call _C_LABEL(sigblock) +#endif + popq %rdi + movq %rax,(_JB_SIGMASK * 8)(%rdi) + +2: xorl %eax,%eax + ret + +ENTRY(longjmp) + movq %rdi,%r12 + movl %esi,%r8d + + movq (_JB_SIGMASK * 8)(%rdi),%rdi + pushq %r8 +#ifdef PIC + call PIC_PLT(_C_LABEL(sigsetmask)) +#else + call _C_LABEL(sigsetmask) +#endif + popq %r8 + movq (_JB_RBX * 8)(%r12),%rbx + movq (_JB_RBP * 8)(%r12),%rbp + movq (_JB_R13 * 8)(%r12),%r13 + movq (_JB_R14 * 8)(%r12),%r14 + movq (_JB_R15 * 8)(%r12),%r15 + movq (_JB_RSP * 8)(%r12),%rsp + movq (_JB_PC * 8)(%r12),%r11 + movq (_JB_R12 * 8)(%r12),%r12 + + movl %r8d,%eax + testl %eax,%eax + jnz 1f + incl %eax +1: movq %r11,0(%rsp) + ret diff --git a/lib/libc/arch/x86_64/gen/sigsetjmp.S b/lib/libc/arch/x86_64/gen/sigsetjmp.S new file mode 100644 index 00000000000..44fb4ca2249 --- /dev/null +++ b/lib/libc/arch/x86_64/gen/sigsetjmp.S @@ -0,0 +1,107 @@ +/* $OpenBSD: sigsetjmp.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: __setjmp14.S,v 1.1 2001/06/19 00:25:02 fvdl Exp $ */ + +/* + * Copyright (c) 2001 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Frank van der Linden for Wasabi Systems, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + + +#include <machine/asm.h> +#include <machine/setjmp.h> + +/* + * C library -- _setjmp, _longjmp + * + * longjmp(a,v) + * will generate a "return(v)" from the last call to + * setjmp(a) + * by restoring registers from the stack. + * The previous signal state is restored. + */ + +ENTRY(sigsetjmp) + movq (%rsp),%r11 + movq %rbx,(_JB_RBX * 8)(%rdi) + movq %rbp,(_JB_RBP * 8)(%rdi) + movq %r12,(_JB_R12 * 8)(%rdi) + movq %r13,(_JB_R13 * 8)(%rdi) + movq %r14,(_JB_R14 * 8)(%rdi) + movq %r15,(_JB_R15 * 8)(%rdi) + movq %rsp,(_JB_RSP * 8)(%rdi) + movq %r11,(_JB_PC * 8)(%rdi) + + movq %rsi,(_JB_SIGFLAG * 8)(%rdi) + testl %esi,%esi + jz 2f + + pushq %rdi + xorq %rdi,%rdi +#ifdef PIC + call PIC_PLT(_C_LABEL(sigblock)) +#else + call _C_LABEL(sigblock) +#endif + popq %rdi + movq %rax,(_JB_SIGMASK * 8)(%rdi) + +2: xorl %eax,%eax + ret + +ENTRY(siglongjmp) + movq %rdi,%r12 + pushq %rsi + cmpl $0, (_JB_SIGFLAG * 8)(%rdi) + jz 2f + + movq (_JB_SIGMASK * 8)(%rdi),%rdi +#ifdef PIC + call PIC_PLT(_C_LABEL(sigsetmask)) +#else + call _C_LABEL(sigsetmask) +#endif +2: popq %rax + movq (_JB_RBX * 8)(%r12),%rbx + movq (_JB_RBP * 8)(%r12),%rbp + movq (_JB_R13 * 8)(%r12),%r13 + movq (_JB_R14 * 8)(%r12),%r14 + movq (_JB_R15 * 8)(%r12),%r15 + movq (_JB_RSP * 8)(%r12),%rsp + movq (_JB_PC * 8)(%r12),%r11 + movq (_JB_R12 * 8)(%r12),%r12 + + testl %eax,%eax + jnz 1f + incl %eax +1: movq %r11,0(%rsp) + ret diff --git a/lib/libc/arch/x86_64/net/Makefile.inc b/lib/libc/arch/x86_64/net/Makefile.inc new file mode 100644 index 00000000000..4c046a624dd --- /dev/null +++ b/lib/libc/arch/x86_64/net/Makefile.inc @@ -0,0 +1,4 @@ +# $OpenBSD: Makefile.inc,v 1.1 2004/01/28 01:44:45 mickey Exp $ + +SRCS+= htonl.S htons.S ntohl.S ntohs.S +LSRCS+= htonl.c htons.c ntohl.c ntohs.c diff --git a/lib/libc/arch/x86_64/net/htonl.S b/lib/libc/arch/x86_64/net/htonl.S new file mode 100644 index 00000000000..e4c951a4b40 --- /dev/null +++ b/lib/libc/arch/x86_64/net/htonl.S @@ -0,0 +1,10 @@ +/* $OpenBSD: htonl.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ + +/* Written by Artur Grabowski. Public Domain */ + +#include <machine/asm.h> + +ENTRY(_C_LABEL(htonl)) + movl %edi,%eax + bswapl %eax + ret diff --git a/lib/libc/arch/x86_64/net/htons.S b/lib/libc/arch/x86_64/net/htons.S new file mode 100644 index 00000000000..80d9f9374a8 --- /dev/null +++ b/lib/libc/arch/x86_64/net/htons.S @@ -0,0 +1,11 @@ +/* $OpenBSD: htons.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ + +/* Written by Artur Grabowski. Public Domain */ + +#include <machine/asm.h> + +ENTRY(_C_LABEL(htonl)) + movl %edi,%eax + xchgb %ah,%al + ret + diff --git a/lib/libc/arch/x86_64/net/ntohl.S b/lib/libc/arch/x86_64/net/ntohl.S new file mode 100644 index 00000000000..4a21dc541ca --- /dev/null +++ b/lib/libc/arch/x86_64/net/ntohl.S @@ -0,0 +1,10 @@ +/* $OpenBSD: ntohl.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ + +/* Written by Artur Grabowski. Public Domain */ + +#include <machine/asm.h> + +ENTRY(_C_LABEL(htonl)) + movl %edi,%eax + bswapl %eax + ret diff --git a/lib/libc/arch/x86_64/net/ntohs.S b/lib/libc/arch/x86_64/net/ntohs.S new file mode 100644 index 00000000000..6c70cc26945 --- /dev/null +++ b/lib/libc/arch/x86_64/net/ntohs.S @@ -0,0 +1,11 @@ +/* $OpenBSD: ntohs.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ + +/* Written by Artur Grabowski. Public Domain */ + +#include <machine/asm.h> + +ENTRY(_C_LABEL(htonl)) + movl %edi,%eax + xchgb %ah,%al + ret + diff --git a/lib/libc/arch/x86_64/string/Makefile.inc b/lib/libc/arch/x86_64/string/Makefile.inc new file mode 100644 index 00000000000..002194e1d8c --- /dev/null +++ b/lib/libc/arch/x86_64/string/Makefile.inc @@ -0,0 +1,6 @@ +# $OpenBSD: Makefile.inc,v 1.1 2004/01/28 01:44:45 mickey Exp $ + +SRCS+= bcmp.c ffs.S index.c memchr.c memcmp.c bcopy.c bzero.c \ + rindex.c strcat.c strcmp.c strcpy.c strcspn.c strlen.S \ + strncat.c strncmp.c strncpy.c strpbrk.c strsep.c \ + strspn.c strstr.c swab.c memset.c strlcpy.c strlcat.c diff --git a/lib/libc/arch/x86_64/string/ffs.S b/lib/libc/arch/x86_64/string/ffs.S new file mode 100644 index 00000000000..2666bc49e9d --- /dev/null +++ b/lib/libc/arch/x86_64/string/ffs.S @@ -0,0 +1,18 @@ +/* $OpenBSD: ffs.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* + * Written by J.T. Conklin <jtc@netbsd.org>. + * Public domain. + * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com> + */ + +#include <machine/asm.h> + +ENTRY(ffs) + bsfl %edi,%eax + jz L1 /* ZF is set if all bits are 0 */ + incl %eax /* bits numbered from 1, not 0 */ + ret + + _ALIGN_TEXT +L1: xorl %eax,%eax /* clear result */ + ret diff --git a/lib/libc/arch/x86_64/string/strlen.S b/lib/libc/arch/x86_64/string/strlen.S new file mode 100644 index 00000000000..3afccb8f1ac --- /dev/null +++ b/lib/libc/arch/x86_64/string/strlen.S @@ -0,0 +1,18 @@ +/* $OpenBSD: strlen.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* + * Written by J.T. Conklin <jtc@netbsd.org>. + * Public domain. + * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com> + */ + +#include <machine/asm.h> + +ENTRY(strlen) + cld /* set search forward */ + xorl %eax,%eax /* set search for null terminator */ + movq $-1,%rcx /* set search for lots of characters */ + repne /* search! */ + scasb + notq %rcx /* get length by taking complement */ + leaq -1(%rcx),%rax /* and subtracting one */ + ret diff --git a/lib/libc/arch/x86_64/sys/Ovfork.S b/lib/libc/arch/x86_64/sys/Ovfork.S new file mode 100644 index 00000000000..865d460014f --- /dev/null +++ b/lib/libc/arch/x86_64/sys/Ovfork.S @@ -0,0 +1,67 @@ +/* $OpenBSD: Ovfork.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: Ovfork.S,v 1.2 2002/06/03 18:30:33 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)Ovfork.s 5.1 (Berkeley) 4/23/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" + +/* + * pid = vfork(); + * + * %edx == 0 in parent process, %edx == 1 in child process. + * %eax == pid of child in parent, %eax == pid of parent in child. + * + */ +SYSENTRY(vfork) + popq %r9 /* my rta into r9 */ + SYSTRAP(vfork) + jc err + decl %edx + andl %edx,%eax + jmp *%r9 +err: + pushq %r9 +#ifdef PIC + movq PIC_GOT(CERROR), %rcx + jmp *%rcx +#else + jmp CERROR +#endif diff --git a/lib/libc/arch/x86_64/sys/brk.S b/lib/libc/arch/x86_64/sys/brk.S new file mode 100644 index 00000000000..1563091c7f3 --- /dev/null +++ b/lib/libc/arch/x86_64/sys/brk.S @@ -0,0 +1,87 @@ +/* $OpenBSD: brk.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: brk.S,v 1.2 2002/06/03 18:30:33 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)brk.s 5.2 (Berkeley) 12/17/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" + + .globl _end + .globl _C_LABEL(__minbrk) + .globl CURBRK + +#ifdef WEAK_ALIAS +WEAK_ALIAS(brk, _brk) +#endif + + .data +_C_LABEL(__minbrk): + .quad _end + .text + +SYSENTRY(_brk) +#ifdef PIC + movq PIC_GOT(_C_LABEL(__minbrk)),%rdx + cmpq %rdi,(%rdx) + jb 1f + movq (%rdx),%rdi +1: + SYSTRAP(break) + jc err + movq PIC_GOT(CURBRK),%rdx # set up GOT addressing + movq %rdi,(%rdx) + xorl %eax,%eax + ret +err: + movq PIC_GOT(CERROR),%rdx + jmp *%rdx +#else + cmpq %rdi,_C_LABEL(__minbrk)(%rip) + jb 1f + movq _C_LABEL(__minbrk)(%rip),%rdi +1: + SYSTRAP(break) + jc err + movq %rdi,CURBRK(%rip) + xorl %eax,%eax + ret +err: + jmp CERROR +#endif diff --git a/lib/libc/arch/x86_64/sys/cerror.S b/lib/libc/arch/x86_64/sys/cerror.S new file mode 100644 index 00000000000..400bb5d81e0 --- /dev/null +++ b/lib/libc/arch/x86_64/sys/cerror.S @@ -0,0 +1,55 @@ +/* $OpenBSD: cerror.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: cerror.S,v 1.2 2002/06/03 18:30:33 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)cerror.s 5.1 (Berkeley) 4/23/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" + + .globl _C_LABEL(errno) + +_ENTRY(CERROR) +#ifdef PIC + movq %rax, PIC_GOT(_C_LABEL(errno)) +#else + movq %rax, _C_LABEL(errno)(%rip) +#endif /* PIC */ + movq $-1,%rax + ret diff --git a/lib/libc/arch/x86_64/sys/exect.S b/lib/libc/arch/x86_64/sys/exect.S new file mode 100644 index 00000000000..31028402b6a --- /dev/null +++ b/lib/libc/arch/x86_64/sys/exect.S @@ -0,0 +1,57 @@ +/* $OpenBSD: exect.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: exect.S,v 1.1 2001/06/19 00:25:06 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)exect.s 5.1 (Berkeley) 4/23/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" +#include <machine/psl.h> + +SYSENTRY(exect) + pushfq + orb $(PSL_T>>8),1(%rsp) + popfq + SYSTRAP(execve) +#ifdef PIC + movq PIC_GOT(CERROR), %rcx + jmp *%rcx +#else + jmp CERROR +#endif diff --git a/lib/libc/arch/x86_64/sys/fork.S b/lib/libc/arch/x86_64/sys/fork.S new file mode 100644 index 00000000000..155ee7227d6 --- /dev/null +++ b/lib/libc/arch/x86_64/sys/fork.S @@ -0,0 +1,49 @@ +/* $OpenBSD: fork.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: fork.S,v 1.2 2003/02/13 02:50:51 nathanw Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)fork.s 5.1 (Berkeley) 4/23/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" + +SYSCALL(fork) + decl %edx /* from 1 to 0 in child, 0 to -1 in parent */ + andl %edx,%eax + ret /* pid = fork(); */ diff --git a/lib/libc/arch/x86_64/sys/rfork.S b/lib/libc/arch/x86_64/sys/rfork.S new file mode 100644 index 00000000000..caedbbd9aff --- /dev/null +++ b/lib/libc/arch/x86_64/sys/rfork.S @@ -0,0 +1,48 @@ +/* $OpenBSD: rfork.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)fork.s 5.1 (Berkeley) 4/23/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" + +SYSCALL(rfork) + decl %edx /* from 1 to 0 in child, 0 to -1 in parent */ + andl %edx,%eax + ret /* pid = rfork(); */ diff --git a/lib/libc/arch/x86_64/sys/sbrk.S b/lib/libc/arch/x86_64/sys/sbrk.S new file mode 100644 index 00000000000..aad5f89d7d8 --- /dev/null +++ b/lib/libc/arch/x86_64/sys/sbrk.S @@ -0,0 +1,82 @@ +/* $OpenBSD: sbrk.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: sbrk.S,v 1.1 2001/06/19 00:25:06 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)sbrk.s 5.1 (Berkeley) 4/23/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" + + .globl _end + .globl CURBRK + +#ifdef WEAK_ALIAS +WEAK_ALIAS(sbrk, _sbrk) +#endif + + .data +CURBRK: .quad _end + .text + +SYSENTRY(_sbrk) +#ifdef PIC + movq PIC_GOT(CURBRK),%rdx + movq (%rdx),%rax + addq %rax,%rdi + SYSTRAP(break) + jc err + movq PIC_GOT(CURBRK),%rdx + movq (%rdx),%rax + movq %rdi,(%rdx) + ret +err: + mov PIC_GOT(CERROR),%rdx + jmp *%rdx +#else + movq CURBRK(%rip),%rax + movq %rdi,%rsi + addq %rax,%rdi + SYSTRAP(break) + jc err + movq CURBRK(%rip),%rax + addq %rsi,CURBRK(%rip) + ret +err: + jmp CERROR +#endif diff --git a/lib/libc/arch/x86_64/sys/sigpending.S b/lib/libc/arch/x86_64/sys/sigpending.S new file mode 100644 index 00000000000..bbebd47c6bf --- /dev/null +++ b/lib/libc/arch/x86_64/sys/sigpending.S @@ -0,0 +1,49 @@ +/* $OpenBSD: sigpending.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: sigpending.S,v 1.1 2001/06/19 00:25:06 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)sigpending.s 5.1 (Berkeley) 7/1/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" + +SYSCALL(sigpending) + movl %eax,(%rdi) # store old mask + xorl %eax,%eax + ret diff --git a/lib/libc/arch/x86_64/sys/sigprocmask.S b/lib/libc/arch/x86_64/sys/sigprocmask.S new file mode 100644 index 00000000000..3718f8de3ae --- /dev/null +++ b/lib/libc/arch/x86_64/sys/sigprocmask.S @@ -0,0 +1,66 @@ +/* $OpenBSD: sigprocmask.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: sigprocmask.S,v 1.1 2001/06/19 00:25:06 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)sigprocmask.s 5.2 (Berkeley) 12/17/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" + +SYSENTRY(sigprocmask) + testq %rsi,%rsi # check new sigset pointer + jnz 1f # if not null, indirect + movl $1,%edi # SIG_BLOCK + jmp 2f +1: movl (%rsi),%esi # fetch indirect ... +2: SYSTRAP(sigprocmask) + jc err + testq %rdx,%rdx # test if old mask requested + jz out + movq %rax,(%rdx) # store old mask +out: + xorl %eax,%eax + ret +err: +#ifdef PIC + movq PIC_GOT(CERROR), %rcx + jmp *%rcx +#else + jmp CERROR +#endif diff --git a/lib/libc/arch/x86_64/sys/sigreturn.S b/lib/libc/arch/x86_64/sys/sigreturn.S new file mode 100644 index 00000000000..e065cbc894d --- /dev/null +++ b/lib/libc/arch/x86_64/sys/sigreturn.S @@ -0,0 +1,60 @@ +/* $OpenBSD: sigreturn.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: __sigreturn14.S,v 1.1 2001/06/19 00:25:06 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)sigreturn.s 5.2 (Berkeley) 12/17/90" + */ + +#include <machine/asm.h> + +#include "SYS.h" + +/* + * We must preserve the state of the registers as the user has set them up. + */ +#if 0 /* XXXfvdl fix later, but this one is really low priority */ +#ifdef GPROF +#undef ENTRY +#define MCOUNT_SYMBOL __mcount +#define ENTRY(x) \ + .globl _/**/x; _ALIGN_TEXT; _/**/x: pusha ; \ + .data; 1:; .long 0; .text; movl $1b,%eax; call MCOUNT_SYMBOL; popa ; nop +#endif /* GPROF */ +#endif + +SYSCALL(sigreturn) + ret diff --git a/lib/libc/arch/x86_64/sys/sigsuspend.S b/lib/libc/arch/x86_64/sys/sigsuspend.S new file mode 100644 index 00000000000..985bf61b99d --- /dev/null +++ b/lib/libc/arch/x86_64/sys/sigsuspend.S @@ -0,0 +1,58 @@ +/* $OpenBSD: sigsuspend.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: sigsuspend.S,v 1.1 2001/06/19 00:25:07 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)sigsuspend.s 5.2 (Berkeley) 12/17/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" + +SYSENTRY(sigsuspend) + movl (%rdi),%edi # indirect to mask arg + SYSTRAP(sigsuspend) + jc err + xorl %eax,%eax # shouldn t happen + ret +err: +#ifdef PIC + movq PIC_GOT(CERROR), %rcx + jmp *%rcx +#else + jmp CERROR +#endif diff --git a/lib/libc/arch/x86_64/sys/syscall.S b/lib/libc/arch/x86_64/sys/syscall.S new file mode 100644 index 00000000000..19b798dbc92 --- /dev/null +++ b/lib/libc/arch/x86_64/sys/syscall.S @@ -0,0 +1,57 @@ +/* $OpenBSD: syscall.S,v 1.1 2004/01/28 01:44:45 mickey Exp $ */ +/* $NetBSD: syscall.S,v 1.2 2002/06/03 18:30:33 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)syscall.s 5.1 (Berkeley) 4/23/90 + */ + +#include <machine/asm.h> + +#include "SYS.h" + +SYSENTRY(syscall) + movl %edi,%eax + syscall + jc err + ret +err: +#ifdef PIC + movq PIC_GOT(CERROR), %rcx + jmp *%rcx +#else + jmp CERROR +#endif |