diff options
author | Patrick Wildt <patrick@cvs.openbsd.org> | 2017-01-11 18:09:25 +0000 |
---|---|---|
committer | Patrick Wildt <patrick@cvs.openbsd.org> | 2017-01-11 18:09:25 +0000 |
commit | 5ac54d6d074524c6711b6b26803db1023de49c10 (patch) | |
tree | da47725aec1468544921882b607a64b60914a865 /lib/libc/arch | |
parent | 4009b5e2d48bb5ac4159e510e77b93c9bb9d0d7e (diff) |
Add support for AArch64.
Diffstat (limited to 'lib/libc/arch')
42 files changed, 1789 insertions, 0 deletions
diff --git a/lib/libc/arch/aarch64/DEFS.h b/lib/libc/arch/aarch64/DEFS.h new file mode 100644 index 00000000000..04662946862 --- /dev/null +++ b/lib/libc/arch/aarch64/DEFS.h @@ -0,0 +1,61 @@ +/* $OpenBSD: DEFS.h,v 1.1 2017/01/11 18:09:24 patrick 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. 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 $ + */ + +#include <machine/asm.h> + +/* + * We define a hidden alias with the prefix "_libc_" for each global symbol + * that may be used internally. By referencing _libc_x instead of x, other + * parts of libc prevent overriding by the application and avoid unnecessary + * relocations. + */ +#define _HIDDEN(x) _libc_##x +#define _HIDDEN_ALIAS(x,y) \ + STRONG_ALIAS(_HIDDEN(x),y); \ + .hidden _HIDDEN(x) +#define _HIDDEN_FALIAS(x,y) \ + _HIDDEN_ALIAS(x,y); \ + .type _HIDDEN(x),@function + +/* + * For functions implemented in ASM that aren't syscalls. + * END_STRONG(x) Like DEF_STRONG() in C; for standard/reserved C names + * END_WEAK(x) Like DEF_WEAK() in C; for non-ISO C names + */ +#define END_STRONG(x) END(x); _HIDDEN_FALIAS(x,x); END(_HIDDEN(x)) +#define END_WEAK(x) END_STRONG(x); .weak x + diff --git a/lib/libc/arch/aarch64/Makefile.inc b/lib/libc/arch/aarch64/Makefile.inc new file mode 100644 index 00000000000..20eea05c66b --- /dev/null +++ b/lib/libc/arch/aarch64/Makefile.inc @@ -0,0 +1,6 @@ +# $OpenBSD: Makefile.inc,v 1.1 2017/01/11 18:09:24 patrick Exp $ +# $NetBSD: Makefile.inc,v 1.5 2002/07/10 04:29:06 thorpej Exp $ + +.include <bsd.own.mk> + +CERROR= cerror.S diff --git a/lib/libc/arch/aarch64/SYS.h b/lib/libc/arch/aarch64/SYS.h new file mode 100644 index 00000000000..e52b7fe5ebf --- /dev/null +++ b/lib/libc/arch/aarch64/SYS.h @@ -0,0 +1,108 @@ +/* $OpenBSD: SYS.h,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* $NetBSD: SYS.h,v 1.8 2003/08/07 16:42:02 agc 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. 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 + */ + +#include "DEFS.h" +#include <sys/syscall.h> +#include <arm64/swi.h> + +#define SYSENTRY(x) \ + .weak _C_LABEL(x); \ + _C_LABEL(x) = _C_LABEL(_thread_sys_ ## x); \ + ENTRY(_thread_sys_ ## x) +#define SYSENTRY_HIDDEN(x) \ + ENTRY(_thread_sys_ ## x) +#define __END_HIDDEN(x) \ + END(_thread_sys_ ## x); \ + _HIDDEN_FALIAS(x, _thread_sys_ ## x); \ + END(_HIDDEN(x)) +#define __END(x) \ + __END_HIDDEN(x); END(x) + +#define SYSTRAP(x) \ + ldr x8, =SYS_ ## x; \ + svc 0 + +#define CERROR _C_LABEL(__cerror) + +#define _SYSCALL_NOERROR(x,y) \ + SYSENTRY(x); \ + SYSTRAP(y) +#define _SYSCALL_HIDDEN_NOERROR(x,y) \ + SYSENTRY_HIDDEN(x); \ + SYSTRAP(y) + +#define _SYSCALL(x, y) \ + _SYSCALL_NOERROR(x,y); \ + bcs CERROR +#define _SYSCALL_HIDDEN(x, y) \ + _SYSCALL_HIDDEN_NOERROR(x,y); \ + bcs CERROR + +#define SYSCALL_NOERROR(x) \ + _SYSCALL_NOERROR(x,x) + +#define SYSCALL(x) \ + _SYSCALL(x,x) + + +#define PSEUDO_NOERROR(x,y) \ + _SYSCALL_NOERROR(x,y); \ + ret; \ + __END(x) + +#define PSEUDO(x,y) \ + _SYSCALL(x,y); \ + ret; \ + __END(x) +#define PSEUDO_HIDDEN(x,y) \ + _SYSCALL_HIDDEN(x,y); \ + ret; \ + __END_HIDDEN(x) + +#define RSYSCALL_NOERROR(x) \ + PSEUDO_NOERROR(x,x) + +#define RSYSCALL(x) \ + PSEUDO(x,x) +#define RSYSCALL_HIDDEN(x) \ + PSEUDO_HIDDEN(x,x) +#define SYSCALL_END(x) \ + __END(x) +#define SYSCALL_END_HIDDEN(x) \ + __END_HIDDEN(x) + + .globl CERROR diff --git a/lib/libc/arch/aarch64/Symbols.list b/lib/libc/arch/aarch64/Symbols.list new file mode 100644 index 00000000000..3ee01d71eae --- /dev/null +++ b/lib/libc/arch/aarch64/Symbols.list @@ -0,0 +1,15 @@ +__bswap16 +__bswap32 +__mcount +__multf3 +_fpgetmask +_fpgetround +_fpgetsticky +_fpsetmask +_fpsetround +_fpsetsticky +_mcount +_memcpy +_stack +end +fabsl diff --git a/lib/libc/arch/aarch64/gdtoa/Makefile.inc b/lib/libc/arch/aarch64/gdtoa/Makefile.inc new file mode 100644 index 00000000000..dd5219036dd --- /dev/null +++ b/lib/libc/arch/aarch64/gdtoa/Makefile.inc @@ -0,0 +1,3 @@ +# $OpenBSD: Makefile.inc,v 1.1 2017/01/11 18:09:24 patrick Exp $ + +SRCS+= strtord.c strtorQ.c diff --git a/lib/libc/arch/aarch64/gdtoa/arith.h b/lib/libc/arch/aarch64/gdtoa/arith.h new file mode 100644 index 00000000000..32513b96e90 --- /dev/null +++ b/lib/libc/arch/aarch64/gdtoa/arith.h @@ -0,0 +1,6 @@ +#define IEEE_8087 +#define Arith_Kind_ASL 1 +#define Long int +#define Intcast (int)(long) +#define Double_Align +#define X64_bit_pointers diff --git a/lib/libc/arch/aarch64/gdtoa/gd_qnan.h b/lib/libc/arch/aarch64/gdtoa/gd_qnan.h new file mode 100644 index 00000000000..9593d5c247f --- /dev/null +++ b/lib/libc/arch/aarch64/gdtoa/gd_qnan.h @@ -0,0 +1,12 @@ +#define f_QNAN 0x7fc00000 +#define d_QNAN0 0x0 +#define d_QNAN1 0x7ff80000 +#define ld_QNAN0 0x0 +#define ld_QNAN1 0x0 +#define ld_QNAN2 0x0 +#define ld_QNAN3 0x7fff8000 +#define ldus_QNAN0 0x0 +#define ldus_QNAN1 0x0 +#define ldus_QNAN2 0x0 +#define ldus_QNAN3 0x0 +#define ldus_QNAN4 0x0 diff --git a/lib/libc/arch/aarch64/gdtoa/strtold.c b/lib/libc/arch/aarch64/gdtoa/strtold.c new file mode 100644 index 00000000000..4115a146d6c --- /dev/null +++ b/lib/libc/arch/aarch64/gdtoa/strtold.c @@ -0,0 +1,46 @@ +/* $OpenBSD: strtold.c,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/*- + * Copyright (c) 2003 David Schultz <das@FreeBSD.ORG> + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +/* + * Machine-dependent glue to integrate David Gay's gdtoa + * package into libc for architectures where a long double + * uses quad precision, such as sparc64. + */ + +#include <float.h> + +#include "gdtoaimp.h" + +long double +strtold(const char * __restrict s, char ** __restrict sp) +{ + long double result; + + strtorQ(s, sp, FLT_ROUNDS, &result); + return result; +} +DEF_STRONG(strtold); diff --git a/lib/libc/arch/aarch64/gen/Makefile.inc b/lib/libc/arch/aarch64/gen/Makefile.inc new file mode 100644 index 00000000000..a7b1b73f3ef --- /dev/null +++ b/lib/libc/arch/aarch64/gen/Makefile.inc @@ -0,0 +1,12 @@ +# $OpenBSD: Makefile.inc,v 1.1 2017/01/11 18:09:24 patrick Exp $ +# $NetBSD: Makefile.inc,v 1.6 2003/08/01 17:03:47 lukem Exp $ + +SRCS+= byte_swap_2.S byte_swap_4.S fabs.c flt_rounds.c infinity.c +SRCS+= ldexp.c modf.c nan.c +SRCS+= setjmp.S _setjmp.S sigsetjmp.S +SRCS+= clz_tab.c +SRCS+= fpgetmask.c fpgetround.c fpgetsticky.c +SRCS+= fpsetmask.c fpsetround.c fpsetsticky.c +SRCS+= fpclassifyl.c +SRCS+= isfinitel.c isinfl.c isnanl.c isnormall.c +SRCS+= signbitl.c diff --git a/lib/libc/arch/aarch64/gen/_setjmp.S b/lib/libc/arch/aarch64/gen/_setjmp.S new file mode 100644 index 00000000000..220ef839a97 --- /dev/null +++ b/lib/libc/arch/aarch64/gen/_setjmp.S @@ -0,0 +1,99 @@ +/* $OpenBSD: _setjmp.S,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/*- + * Copyright (c) 2014 Andrew Turner + * Copyright (c) 2014 The FreeBSD Foundation + * All rights reserved. + * + * Portions of this software were developed by Andrew Turner + * under sponsorship from the FreeBSD Foundation + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + */ + +#include "DEFS.h" +#include <machine/setjmp.h> + +ENTRY(_setjmp) + /* Store the magic value and stack pointer */ + ldr x8, .Lmagic + mov x9, sp + stp x8, x9, [x0], #16 + + /* Store the general purpose registers and lr */ + stp x19, x20, [x0], #16 + stp x21, x22, [x0], #16 + stp x23, x24, [x0], #16 + stp x25, x26, [x0], #16 + stp x27, x28, [x0], #16 + stp x29, x30, [x0], #16 + +#ifndef _STANDALONE + /* Store the vfp registers */ + stp d8, d9, [x0], #16 + stp d10, d11, [x0], #16 + stp d12, d13, [x0], #16 + stp d14, d15, [x0] +#endif + + /* Return value */ + mov x0, #0 + ret + .align 3 +.Lmagic: + .quad _JB_MAGIC__SETJMP +END_STRONG(_setjmp) + +ENTRY(_longjmp) + /* Check the magic value */ + ldr x8, [x0], #8 + ldr x9, .Lmagic + cmp x8, x9 + b.ne botch + + /* Restore the stack pointer */ + ldr x8, [x0], #8 + mov sp, x8 + + /* Restore the general purpose registers and lr */ + ldp x19, x20, [x0], #16 + ldp x21, x22, [x0], #16 + ldp x23, x24, [x0], #16 + ldp x25, x26, [x0], #16 + ldp x27, x28, [x0], #16 + ldp x29, x30, [x0], #16 + +#ifndef _STANDALONE + /* Restore the vfp registers */ + ldp d8, d9, [x0], #16 + ldp d10, d11, [x0], #16 + ldp d12, d13, [x0], #16 + ldp d14, d15, [x0] +#endif + + /* Load the return value */ + mov x0, x1 + ret + +botch: + bl _HIDDEN(abort) +END_STRONG(_longjmp) diff --git a/lib/libc/arch/aarch64/gen/byte_swap_2.S b/lib/libc/arch/aarch64/gen/byte_swap_2.S new file mode 100644 index 00000000000..5bd951ee8a4 --- /dev/null +++ b/lib/libc/arch/aarch64/gen/byte_swap_2.S @@ -0,0 +1,42 @@ +/* $OpenBSD: byte_swap_2.S,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* $NetBSD: byte_swap_2.S,v 1.3 2003/04/05 23:08:51 bjh21 Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#include <machine/asm.h> + +_ENTRY(_C_LABEL(__bswap16)) +_ENTRY(_C_LABEL(ntohs)) +_ENTRY(_C_LABEL(htons)) +_PROF_PROLOGUE + and w8, w0, #0xffff + ubfx w0, w0, #8, #8 + bfi w0, w8, #8, #16 + ret diff --git a/lib/libc/arch/aarch64/gen/byte_swap_4.S b/lib/libc/arch/aarch64/gen/byte_swap_4.S new file mode 100644 index 00000000000..6d9119b2230 --- /dev/null +++ b/lib/libc/arch/aarch64/gen/byte_swap_4.S @@ -0,0 +1,40 @@ +/* $OpenBSD: byte_swap_4.S,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* $NetBSD: byte_swap_4.S,v 1.2 2003/04/05 23:08:51 bjh21 Exp $ */ + +/*- + * Copyright (c) 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Neil A. Carson + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#include <machine/asm.h> + +_ENTRY(_C_LABEL(__bswap32)) +_ENTRY(_C_LABEL(ntohl)) +_ENTRY(_C_LABEL(htonl)) +_PROF_PROLOGUE + rev w0, w0 + ret diff --git a/lib/libc/arch/aarch64/gen/clz_tab.c b/lib/libc/arch/aarch64/gen/clz_tab.c new file mode 100644 index 00000000000..2135debb702 --- /dev/null +++ b/lib/libc/arch/aarch64/gen/clz_tab.c @@ -0,0 +1,34 @@ +const unsigned char __clz_tab[] = { + 0, 1, 2, 2, 3, 3, 3, 3, + 4, 4, 4, 4, 4, 4, 4, 4, + 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, + 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8 +}; diff --git a/lib/libc/arch/aarch64/gen/fabs.c b/lib/libc/arch/aarch64/gen/fabs.c new file mode 100644 index 00000000000..9688c091b29 --- /dev/null +++ b/lib/libc/arch/aarch64/gen/fabs.c @@ -0,0 +1,35 @@ +/* $OpenBSD: fabs.c,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* + * Copyright (c) 2008 Martynas Venckus <martynas@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> +#include <machine/ieee.h> +#include <math.h> + +/* + * fabs(d) returns the absolute value of d. + */ +double +fabs(double d) +{ + struct ieee_double *p = (struct ieee_double *)&d; + + p->dbl_sign = 0; + + return(d); +} + +__strong_alias(fabsl, fabs); diff --git a/lib/libc/arch/aarch64/gen/flt_rounds.c b/lib/libc/arch/aarch64/gen/flt_rounds.c new file mode 100644 index 00000000000..717e4102b4f --- /dev/null +++ b/lib/libc/arch/aarch64/gen/flt_rounds.c @@ -0,0 +1,77 @@ +/* $OpenBSD: flt_rounds.c,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* $NetBSD: flt_rounds.c,v 1.1 2000/12/29 20:13:48 bjh21 Exp $ */ + +/* + * Copyright (c) 1996 Mark Brinicombe + * All rights reserved. + * + * 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 Mark Brinicombe + * for the NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 <sys/types.h> +#include <ieeefp.h> +#include <float.h> + +static const int map[] = { + 1, /* round to nearest */ + 2, /* round to positive infinity */ + 3, /* round to negative infinity */ + 0 /* round to zero */ +}; + +/* + * Return the current FP rounding mode + * + * Returns: + * 0 - round to zero + * 1 - round to nearest + * 2 - round to postive infinity + * 3 - round to negative infinity + * + * ok all we need to do is get the current FP rounding mode + * index our map table and return the appropriate value. + * + * HOWEVER: + * The ARM FPA codes the rounding mode into the actual FP instructions + * so there is no such thing as a global rounding mode. + * The default is round to nearest if rounding is not explicitly specified. + * FP instructions generated by GCC will not explicitly specify a rounding + * mode. + * + * So the best we can do it to return the rounding mode FP instructions + * use if rounding is not specified which is round to nearest. + * + * This could change in the future with new floating point emulators or + * soft float FP libraries. + */ + +int +__flt_rounds() +{ + return(map[fpgetround()]); +} +DEF_STRONG(__flt_rounds); diff --git a/lib/libc/arch/aarch64/gen/fpclassifyl.c b/lib/libc/arch/aarch64/gen/fpclassifyl.c new file mode 100644 index 00000000000..80e0a0698d3 --- /dev/null +++ b/lib/libc/arch/aarch64/gen/fpclassifyl.c @@ -0,0 +1,45 @@ +/* $OpenBSD: fpclassifyl.c,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* + * Copyright (c) 2008 Martynas Venckus <martynas@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> +#include <machine/ieee.h> +#include <math.h> + +int +__fpclassifyl(long double e) +{ + struct ieee_ext *p = (struct ieee_ext *)&e; + + if (p->ext_exp == 0) { + if (p->ext_frach == 0 && p->ext_frachm == 0 && + p->ext_fraclm == 0 && p->ext_fracl == 0) + return FP_ZERO; + else + return FP_SUBNORMAL; + } + + if (p->ext_exp == EXT_EXP_INFNAN) { + if (p->ext_frach == 0 && p->ext_frachm == 0 && + p->ext_fraclm == 0 && p->ext_fracl == 0) + return FP_INFINITE; + else + return FP_NAN; + } + + return FP_NORMAL; +} +DEF_STRONG(__fpclassifyl); diff --git a/lib/libc/arch/aarch64/gen/fpgetmask.c b/lib/libc/arch/aarch64/gen/fpgetmask.c new file mode 100644 index 00000000000..c2158c75963 --- /dev/null +++ b/lib/libc/arch/aarch64/gen/fpgetmask.c @@ -0,0 +1,48 @@ +/* $OpenBSD: fpgetmask.c,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* + * Copyright (C) 2014 Andrew Turner + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + */ + +#include <sys/cdefs.h> + +#include <sys/types.h> +#include <ieeefp.h> + +#ifdef __weak_alias +__weak_alias(_fpgetmask,fpgetmask); +#endif + +#define FP_X_MASK (FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL | FP_X_IMP) + +fp_except +fpgetmask(void) +{ + fp_except mask; + + __asm __volatile("mrs %x0, fpcr" : "=&r"(mask)); + + return ((mask >> 8) & FP_X_MASK); +} diff --git a/lib/libc/arch/aarch64/gen/fpgetround.c b/lib/libc/arch/aarch64/gen/fpgetround.c new file mode 100644 index 00000000000..fa7dda454c7 --- /dev/null +++ b/lib/libc/arch/aarch64/gen/fpgetround.c @@ -0,0 +1,46 @@ +/* $OpenBSD: fpgetround.c,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* + * Copyright (C) 2014 Andrew Turner + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + */ + +#include <sys/cdefs.h> + +#include <sys/types.h> +#include <ieeefp.h> + +#ifdef __weak_alias +__weak_alias(_fpgetround,fpgetround); +#endif + +fp_rnd +fpgetround(void) +{ + uint32_t fpscr; + + __asm __volatile("mrs %x0, fpcr" : "=&r"(fpscr)); + + return ((fpscr >> 22) & 3); +} diff --git a/lib/libc/arch/aarch64/gen/fpgetsticky.c b/lib/libc/arch/aarch64/gen/fpgetsticky.c new file mode 100644 index 00000000000..852e97e550b --- /dev/null +++ b/lib/libc/arch/aarch64/gen/fpgetsticky.c @@ -0,0 +1,48 @@ +/* $OpenBSD: fpgetsticky.c,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* + * Copyright (C) 2014 Andrew Turner + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + */ + +#include <sys/cdefs.h> + +#include <sys/types.h> +#include <ieeefp.h> + +#ifdef __weak_alias +__weak_alias(_fpgetsticky,fpgetsticky); +#endif + +#define FP_X_MASK (FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL | FP_X_IMP) + +fp_except +fpgetsticky(void) +{ + fp_except old; + + __asm __volatile("mrs %x0, fpcr" : "=&r"(old)); + + return (old & FP_X_MASK); +} diff --git a/lib/libc/arch/aarch64/gen/fpsetmask.c b/lib/libc/arch/aarch64/gen/fpsetmask.c new file mode 100644 index 00000000000..997e2da31be --- /dev/null +++ b/lib/libc/arch/aarch64/gen/fpsetmask.c @@ -0,0 +1,51 @@ +/* $OpenBSD: fpsetmask.c,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* + * Copyright (C) 2014 Andrew Turner + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + */ + +#include <sys/cdefs.h> + +#include <sys/types.h> +#include <ieeefp.h> + +#ifdef __weak_alias +__weak_alias(_fpsetmask,fpsetmask); +#endif + +#define FP_X_MASK (FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL | FP_X_IMP) + +fp_except +fpsetmask(fp_except mask) +{ + fp_except old, new; + + __asm __volatile("mrs %x0, fpcr" : "=&r"(old)); + mask = (mask & FP_X_MASK) << 8; + new = (old & ~(FP_X_MASK << 8)) | mask; + __asm __volatile("msr fpcr, %x0" : : "r"(new)); + + return ((old >> 8) & FP_X_MASK); +} diff --git a/lib/libc/arch/aarch64/gen/fpsetround.c b/lib/libc/arch/aarch64/gen/fpsetround.c new file mode 100644 index 00000000000..05f1c6e7d4e --- /dev/null +++ b/lib/libc/arch/aarch64/gen/fpsetround.c @@ -0,0 +1,49 @@ +/* $OpenBSD: fpsetround.c,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* + * Copyright (C) 2014 Andrew Turner + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + */ + +#include <sys/cdefs.h> + +#include <sys/types.h> +#include <ieeefp.h> + +#ifdef __weak_alias +__weak_alias(_fpsetround,fpsetround); +#endif + +fp_rnd +fpsetround(fp_rnd rnd_dir) +{ + uint32_t old, new; + + __asm __volatile("mrs %x0, fpcr" : "=&r"(old)); + new = old & ~(3 << 22); + new |= rnd_dir << 22; + __asm __volatile("msr fpcr, %x0" : : "r"(new)); + + return ((old >> 22) & 3); +} diff --git a/lib/libc/arch/aarch64/gen/fpsetsticky.c b/lib/libc/arch/aarch64/gen/fpsetsticky.c new file mode 100644 index 00000000000..7a4994f8220 --- /dev/null +++ b/lib/libc/arch/aarch64/gen/fpsetsticky.c @@ -0,0 +1,51 @@ +/* $OpenBSD: fpsetsticky.c,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* + * Copyright (C) 2014 Andrew Turner + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + */ + +#include <sys/cdefs.h> + +#include <sys/types.h> +#include <ieeefp.h> + +#ifdef __weak_alias +__weak_alias(_fpsetsticky,fpsetsticky); +#endif + +#define FP_X_MASK (FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL | FP_X_IMP) + +fp_except +fpsetsticky(fp_except except) +{ + fp_except old, new; + + __asm __volatile("mrs %x0, fpcr" : "=&r"(old)); + new = old & ~(FP_X_MASK); + new &= ~except; + __asm __volatile("msr fpcr, %x0" : : "r"(new)); + + return (old & except); +} diff --git a/lib/libc/arch/aarch64/gen/infinity.c b/lib/libc/arch/aarch64/gen/infinity.c new file mode 100644 index 00000000000..a845539ec8b --- /dev/null +++ b/lib/libc/arch/aarch64/gen/infinity.c @@ -0,0 +1,16 @@ +/* $OpenBSD: infinity.c,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* $NetBSD: infinity.c,v 1.3 2002/02/19 20:08:19 bjh21 Exp $ */ + +/* + * IEEE-compatible infinity.c -- public domain. + */ + +#include <endian.h> +#include <math.h> + +char __infinity[] __attribute__((__aligned__(sizeof(double)))) = +#if BYTE_ORDER == BIG_ENDIAN + { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0}; +#else + { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f}; +#endif diff --git a/lib/libc/arch/aarch64/gen/isfinitel.c b/lib/libc/arch/aarch64/gen/isfinitel.c new file mode 100644 index 00000000000..eeffa6f3e16 --- /dev/null +++ b/lib/libc/arch/aarch64/gen/isfinitel.c @@ -0,0 +1,28 @@ +/* $OpenBSD: isfinitel.c,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* + * Copyright (c) 2008 Martynas Venckus <martynas@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> +#include <machine/ieee.h> +#include <math.h> + +int +__isfinitel(long double e) +{ + struct ieee_ext *p = (struct ieee_ext *)&e; + + return (p->ext_exp != EXT_EXP_INFNAN); +} diff --git a/lib/libc/arch/aarch64/gen/isinfl.c b/lib/libc/arch/aarch64/gen/isinfl.c new file mode 100644 index 00000000000..86bea7075bd --- /dev/null +++ b/lib/libc/arch/aarch64/gen/isinfl.c @@ -0,0 +1,30 @@ +/* $OpenBSD: isinfl.c,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* + * Copyright (c) 2008 Martynas Venckus <martynas@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> +#include <machine/ieee.h> +#include <math.h> + +int +__isinfl(long double e) +{ + struct ieee_ext *p = (struct ieee_ext *)&e; + + return (p->ext_exp == EXT_EXP_INFNAN && + p->ext_frach == 0 && p->ext_frachm == 0 && + p->ext_fraclm == 0 && p->ext_fracl == 0); +} diff --git a/lib/libc/arch/aarch64/gen/isnanl.c b/lib/libc/arch/aarch64/gen/isnanl.c new file mode 100644 index 00000000000..a8d08f1da73 --- /dev/null +++ b/lib/libc/arch/aarch64/gen/isnanl.c @@ -0,0 +1,30 @@ +/* $OpenBSD: isnanl.c,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* + * Copyright (c) 2008 Martynas Venckus <martynas@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> +#include <machine/ieee.h> +#include <math.h> + +int +__isnanl(long double e) +{ + struct ieee_ext *p = (struct ieee_ext *)&e; + + return (p->ext_exp == EXT_EXP_INFNAN && + (p->ext_frach != 0 || p->ext_frachm != 0 || + p->ext_fraclm != 0 || p->ext_fracl != 0)); +} diff --git a/lib/libc/arch/aarch64/gen/isnormall.c b/lib/libc/arch/aarch64/gen/isnormall.c new file mode 100644 index 00000000000..2e3d8b5fc8f --- /dev/null +++ b/lib/libc/arch/aarch64/gen/isnormall.c @@ -0,0 +1,28 @@ +/* $OpenBSD: isnormall.c,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* + * Copyright (c) 2008 Martynas Venckus <martynas@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> +#include <machine/ieee.h> +#include <math.h> + +int +__isnormall(long double e) +{ + struct ieee_ext *p = (struct ieee_ext *)&e; + + return (p->ext_exp != 0 && p->ext_exp != EXT_EXP_INFNAN); +} diff --git a/lib/libc/arch/aarch64/gen/nan.c b/lib/libc/arch/aarch64/gen/nan.c new file mode 100644 index 00000000000..eca9a48c383 --- /dev/null +++ b/lib/libc/arch/aarch64/gen/nan.c @@ -0,0 +1,14 @@ +/* $OpenBSD: nan.c,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ + +/* Written by Martynas Venckus. Public Domain. */ + +#include <endian.h> +#include <math.h> + +/* bytes for qNaN on an arm (IEEE single format) */ +char __nan[] __attribute__((__aligned__(sizeof(float)))) = +#if BYTE_ORDER == BIG_ENDIAN + { 0x7f, 0xc0, 0, 0 }; +#else /* BYTE_ORDER == BIG_ENDIAN */ + { 0, 0, 0xc0, 0x7f }; +#endif /* BYTE_ORDER == BIG_ENDIAN */ diff --git a/lib/libc/arch/aarch64/gen/setjmp.S b/lib/libc/arch/aarch64/gen/setjmp.S new file mode 100644 index 00000000000..ba4010be7ff --- /dev/null +++ b/lib/libc/arch/aarch64/gen/setjmp.S @@ -0,0 +1,118 @@ +/* $OpenBSD: setjmp.S,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/*- + * Copyright (c) 2014 Andrew Turner + * Copyright (c) 2014 The FreeBSD Foundation + * All rights reserved. + * + * Portions of this software were developed by Andrew Turner + * under sponsorship from the FreeBSD Foundation + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + */ + +#include "SYS.h" +#include <machine/setjmp.h> + +ENTRY(setjmp) + stp x0, x30, [sp, #-16]! + + /* Store the signal mask */ + add x2, x0, #(_JB_SIGMASK * 8) /* oset */ + mov x1, #0 /* set */ + mov x0, #1 /* SIG_BLOCK */ + SYSTRAP(sigprocmask) + + ldp x0, x30, [sp], #16 + + /* Store the magic value and stack pointer */ + ldr x8, .Lmagic + mov x9, sp + stp x8, x9, [x0], #16 + + /* Store the general purpose registers and lr */ + stp x19, x20, [x0], #16 + stp x21, x22, [x0], #16 + stp x23, x24, [x0], #16 + stp x25, x26, [x0], #16 + stp x27, x28, [x0], #16 + stp x29, x30, [x0], #16 + + /* Store the vfp registers */ + stp d8, d9, [x0], #16 + stp d10, d11, [x0], #16 + stp d12, d13, [x0], #16 + stp d14, d15, [x0] + + /* Return value */ + mov x0, #0 + ret + + .align 3 +.Lmagic: + .quad _JB_MAGIC_SETJMP +END_STRONG(setjmp) + +ENTRY(longjmp) + stp x0, x1, [sp, #-32]! + str x30, [sp, #24] + + /* Restore the signal mask */ + mov x2, #0 /* oset */ + add x1, x0, #(_JB_SIGMASK * 8) /* set */ + mov x0, #3 /* SIG_SETMASK */ + SYSTRAP(sigprocmask) + + ldr x30, [sp, #24] + ldp x0, x1, [sp], #32 + + /* Check the magic value */ + ldr x8, [x0], #8 + ldr x9, .Lmagic + cmp x8, x9 + b.ne botch + + /* Restore the stack pointer */ + ldr x8, [x0], #8 + mov sp, x8 + + /* Restore the general purpose registers and lr */ + ldp x19, x20, [x0], #16 + ldp x21, x22, [x0], #16 + ldp x23, x24, [x0], #16 + ldp x25, x26, [x0], #16 + ldp x27, x28, [x0], #16 + ldp x29, x30, [x0], #16 + + /* Restore the vfp registers */ + ldp d8, d9, [x0], #16 + ldp d10, d11, [x0], #16 + ldp d12, d13, [x0], #16 + ldp d14, d15, [x0] + + /* Load the return value */ + mov x0, x1 + ret + +botch: + bl _HIDDEN(abort) +END_STRONG(longjmp) diff --git a/lib/libc/arch/aarch64/gen/signbitl.c b/lib/libc/arch/aarch64/gen/signbitl.c new file mode 100644 index 00000000000..7afd4eaf0d7 --- /dev/null +++ b/lib/libc/arch/aarch64/gen/signbitl.c @@ -0,0 +1,28 @@ +/* $OpenBSD: signbitl.c,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* + * Copyright (c) 2008 Martynas Venckus <martynas@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> +#include <machine/ieee.h> +#include <math.h> + +int +__signbitl(long double e) +{ + struct ieee_ext *p = (struct ieee_ext *)&e; + + return p->ext_sign; +} diff --git a/lib/libc/arch/aarch64/gen/sigsetjmp.S b/lib/libc/arch/aarch64/gen/sigsetjmp.S new file mode 100644 index 00000000000..186859bb52f --- /dev/null +++ b/lib/libc/arch/aarch64/gen/sigsetjmp.S @@ -0,0 +1,53 @@ +/* $OpenBSD: sigsetjmp.S,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/*- + * Copyright (c) 2014 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Andrew Turner under + * sponsorship from the FreeBSD Foundation. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include <machine/asm.h> + +#include <machine/setjmp.h> + +ENTRY(sigsetjmp) + cmp x1, #0 + b.eq _C_LABEL(_setjmp) + b _C_LABEL(setjmp) +//END(sigsetjmp) + +ENTRY(siglongjmp) + /* Load the _setjmp magic */ + ldr x2, .Lmagic + ldr x3, [x0] + + /* Check the magic */ + cmp x2, x3 + b.eq _C_LABEL(_longjmp) + b _C_LABEL(longjmp) +.Lmagic: + .align 3 + .quad _JB_MAGIC__SETJMP +//END(siglongjmp) diff --git a/lib/libc/arch/aarch64/net/Makefile.inc b/lib/libc/arch/aarch64/net/Makefile.inc new file mode 100644 index 00000000000..f88d6126c4e --- /dev/null +++ b/lib/libc/arch/aarch64/net/Makefile.inc @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile.inc,v 1.1 2017/01/11 18:09:24 patrick Exp $ +# $NetBSD: Makefile.inc,v 1.1 2000/12/29 20:13:53 bjh21 Exp $ + +# hton* and nto* functions provided by ../gen/byte_swap_*.S +SRCS+= diff --git a/lib/libc/arch/aarch64/string/Makefile.inc b/lib/libc/arch/aarch64/string/Makefile.inc new file mode 100644 index 00000000000..a44e1d0265e --- /dev/null +++ b/lib/libc/arch/aarch64/string/Makefile.inc @@ -0,0 +1,9 @@ +# $OpenBSD: Makefile.inc,v 1.1 2017/01/11 18:09:24 patrick Exp $ + +SRCS+= bcopy.c memcpy.c memmove.c \ + strchr.c strrchr.c \ + bcmp.c bzero.c ffs.c memchr.c memcmp.c memset.c \ + strcmp.c strncmp.c \ + strcat.c strcpy.c strcspn.c strlen.c strlcat.c strlcpy.c \ + strncat.c strncpy.c strpbrk.c strsep.c \ + strspn.c swab.c strstr.c diff --git a/lib/libc/arch/aarch64/sys/Ovfork.S b/lib/libc/arch/aarch64/sys/Ovfork.S new file mode 100644 index 00000000000..daf30211c56 --- /dev/null +++ b/lib/libc/arch/aarch64/sys/Ovfork.S @@ -0,0 +1,55 @@ +/* $OpenBSD: Ovfork.S,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* $NetBSD: Ovfork.S,v 1.6 2003/08/07 16:42:03 agc Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * 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. + * + * from: @(#)Ovfork.s 5.1 (Berkeley) 4/23/90 + */ + +#include "SYS.h" + +/* + * pid = vfork(); + * + * On return from the SWI: + * r1 == 0 in parent process, r1 == 1 in child process. + * r0 == pid of child in parent, r0 == pid of parent in child. + */ + .text + .align 0 + +SYSENTRY_HIDDEN(vfork) + mov x2, x30 + SYSTRAP(vfork) + bcs CERROR + sub x1, x1, #1 /* r1 == 0xffffffff if parent, 0 if child */ + and x0, x0, x1 /* r0 == 0 if child, else unchanged */ + mov x30, x2 + ret +SYSCALL_END_HIDDEN(vfork) diff --git a/lib/libc/arch/aarch64/sys/brk.S b/lib/libc/arch/aarch64/sys/brk.S new file mode 100644 index 00000000000..0a259b1edcc --- /dev/null +++ b/lib/libc/arch/aarch64/sys/brk.S @@ -0,0 +1,96 @@ +/* $OpenBSD: brk.S,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* $NetBSD: brk.S,v 1.7 2003/12/26 11:23:44 martin Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * 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. + * + * from: @(#)brk.s 5.2 (Berkeley) 12/17/90 + */ + +#include "SYS.h" + + .globl _C_LABEL(end) + .globl CURBRK + +#ifdef WEAK_ALIAS +WEAK_ALIAS(brk, _brk) +#endif + + .data + .align 0 + .globl _C_LABEL(__minbrk) + .type _C_LABEL(__minbrk),#object +_C_LABEL(__minbrk): + .quad _C_LABEL(end) + +/* + * Change the data segment size + */ +SYSENTRY(_brk) +#ifdef __PIC__ + /* Setup the GOT */ + adrp x3, :got:minbrk + ldr x1, [x3, #:got_lo12:minbrk] +#else + ldr x1, .Lminbrk +#endif + /* Get the minimum allowable brk address */ + ldr x1, [x1] + + /* + * Valid the address specified and set to the minimum + * if the address is below minbrk. + */ + cmp x0, x1 + b.ge 1f + mov x0, x1 +1: + mov x2, x0 + SYSTRAP(break) + bcs CERROR + +#ifdef __PIC__ + adrp x3, :got:minbrk + ldr x1, [x3, #:got_lo12:minbrk] +#else + ldr x1, .Lcurbrk +#endif + /* Store the new address in curbrk */ + str x2, [x1] + + /* Return 0 for success */ + mov x0, #0x00000000 + ret + + .align 3 +#if !defined(__PIC__) +.Lminbrk: + .quad _C_LABEL(__minbrk) +.Lcurbrk: + .quad CURBRK +#endif diff --git a/lib/libc/arch/aarch64/sys/cerror.S b/lib/libc/arch/aarch64/sys/cerror.S new file mode 100644 index 00000000000..68edada6834 --- /dev/null +++ b/lib/libc/arch/aarch64/sys/cerror.S @@ -0,0 +1,44 @@ +/* $OpenBSD: cerror.S,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/*- + * Copyright (c) 2014 Andrew Turner + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + */ + +#include "SYS.h" + +_ENTRY(CERROR) + stp x0, x30, [sp,#-16]! + bl _C_LABEL(__errno) + ldp x1, x30, [sp],#16 + str x1, [x0] + movn x0, #0 + movn x1, #0 + ret +END(CERROR) + +#if !defined(__PIC__) +.Lerrno: + .word errno +#endif diff --git a/lib/libc/arch/aarch64/sys/sbrk.S b/lib/libc/arch/aarch64/sys/sbrk.S new file mode 100644 index 00000000000..8732a96b860 --- /dev/null +++ b/lib/libc/arch/aarch64/sys/sbrk.S @@ -0,0 +1,86 @@ +/* $OpenBSD: sbrk.S,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* $NetBSD: sbrk.S,v 1.7 2003/08/07 16:42:05 agc Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * 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. + * + * from: @(#)sbrk.s 5.1 (Berkeley) 4/23/90 + */ + +#include "SYS.h" + + .globl _C_LABEL(end) + +#ifdef WEAK_ALIAS +WEAK_ALIAS(sbrk, _sbrk) +#endif + + .data + .align 0 + .globl CURBRK + .type CURBRK,#object + .globl minbrk + .type minbrk,#object +CURBRK: + .quad _C_LABEL(end) +_ASM_LABEL(minbrk): + .quad _C_LABEL(end) + +/* + * Change the data segment size + */ +SYSENTRY(_sbrk) +#ifdef __PIC__ + /* Setup the GOT */ + adrp x3, :got:CURBRK + ldr x2, [x3, #:got_lo12:CURBRK] +#else + ldr x2, .Lcurbrk +#endif + /* Get the current brk address */ + ldr x1, [x2] + + /* Calculate new value */ + mov x3, x0 + add x0, x0, x1 + SYSTRAP(break) + bcs CERROR + + /* Store new curbrk value */ + ldr x0, [x2] + add x1, x0, x3 + str x1, [x2] + + /* Return old curbrk value */ + ret + + .align 0 +#if !defined(__PIC__) +.Lcurbrk: + .word CURBRK +#endif diff --git a/lib/libc/arch/aarch64/sys/sigpending.S b/lib/libc/arch/aarch64/sys/sigpending.S new file mode 100644 index 00000000000..65265363115 --- /dev/null +++ b/lib/libc/arch/aarch64/sys/sigpending.S @@ -0,0 +1,43 @@ +/* $OpenBSD: sigpending.S,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* $NetBSD: sigpending.S,v 1.5 2003/08/07 16:42:05 agc Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * 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. + * + * from: @(#)sigpending.s 5.1 (Berkeley) 7/1/90 + */ + +#include "SYS.h" + +SYSENTRY(sigpending) + ldr w0, [x0] + SYSTRAP(sigpending) + bcs CERROR + mov x0, #0 + ret +SYSCALL_END(sigpending) diff --git a/lib/libc/arch/aarch64/sys/sigprocmask.S b/lib/libc/arch/aarch64/sys/sigprocmask.S new file mode 100644 index 00000000000..6de70f6a1f5 --- /dev/null +++ b/lib/libc/arch/aarch64/sys/sigprocmask.S @@ -0,0 +1,53 @@ +/* $OpenBSD: sigprocmask.S,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* $NetBSD: sigprocmask.S,v 1.5 2003/08/07 16:42:05 agc Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * 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. + * + * from: @(#)sigprocmask.s 5.2 (Berkeley) 12/17/90 + */ + +#include "SYS.h" + +SYSENTRY_HIDDEN(sigprocmask) + cbz x1, 2f + ldr w1, [x1] + b 2f +1: + mov w0, #0x00000001 + mov x1, #0x00000000 +2: + + SYSTRAP(sigprocmask) + bcs CERROR + cbz x2, 1f + str w0, [x2] +1: + mov x0, #0x00000000 + ret +SYSCALL_END_HIDDEN(sigprocmask) diff --git a/lib/libc/arch/aarch64/sys/sigsuspend.S b/lib/libc/arch/aarch64/sys/sigsuspend.S new file mode 100644 index 00000000000..9be04da1525 --- /dev/null +++ b/lib/libc/arch/aarch64/sys/sigsuspend.S @@ -0,0 +1,43 @@ +/* $OpenBSD: sigsuspend.S,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* $NetBSD: sigsuspend.S,v 1.6 2003/08/07 16:42:05 agc Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * 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. + * + * from: @(#)sigsuspend.s 5.2 (Berkeley) 12/17/90 + */ + +#include "SYS.h" + +SYSENTRY_HIDDEN(sigsuspend) + ldr w0, [x0] + SYSTRAP(sigsuspend) + bcs CERROR + mov x0, #0 + ret +SYSCALL_END_HIDDEN(sigsuspend) diff --git a/lib/libc/arch/aarch64/sys/syscall.S b/lib/libc/arch/aarch64/sys/syscall.S new file mode 100644 index 00000000000..4f7488a8929 --- /dev/null +++ b/lib/libc/arch/aarch64/sys/syscall.S @@ -0,0 +1,37 @@ +/* $OpenBSD: syscall.S,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* $NetBSD: syscall.S,v 1.4 2003/08/07 16:42:05 agc Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * 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. + * + * from: @(#)syscall.s 5.1 (Berkeley) 4/23/90 + */ + +#include "SYS.h" + +RSYSCALL(syscall) diff --git a/lib/libc/arch/aarch64/sys/tfork_thread.S b/lib/libc/arch/aarch64/sys/tfork_thread.S new file mode 100644 index 00000000000..333dd0461bb --- /dev/null +++ b/lib/libc/arch/aarch64/sys/tfork_thread.S @@ -0,0 +1,39 @@ +/* $OpenBSD: tfork_thread.S,v 1.1 2017/01/11 18:09:24 patrick Exp $ */ +/* + * Copyright (c) 2005 Dale Rahn <drahn@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#include <sys/syscall.h> +#include <machine/asm.h> +#include "SYS.h" + +/* + * r0 r1 r2 r3 + * __tfork_thread(param, psize, start_fnc, start_arg); + */ + +ENTRY(__tfork_thread) + SYSTRAP(__tfork) + bcs CERROR + + /* check if we are parent or child */ + cbz x1, 1f + ret + +1: + /* child */ + mov x0, x3 + blr x2 + SYSTRAP(__threxit) +END(__tfork_thread) |