diff options
author | Dale Rahn <drahn@cvs.openbsd.org> | 2020-06-25 02:03:56 +0000 |
---|---|---|
committer | Dale Rahn <drahn@cvs.openbsd.org> | 2020-06-25 02:03:56 +0000 |
commit | f7796cef2bb42fee344b534619580aa9b69f21ef (patch) | |
tree | 440969f9816097492418610f2b00962a6e13eb0c /lib | |
parent | e54a3d86f16ddde6d2d4d35438f36c96f1876a93 (diff) |
PowerPC64 libc gen files
Initial attempt to port powerpc code to powerpc64
Expects TOC loading in ENTRY(),
ok kettenis@
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/arch/powerpc64/gen/Makefile.inc | 5 | ||||
-rw-r--r-- | lib/libc/arch/powerpc64/gen/_atomic_lock.c | 53 | ||||
-rw-r--r-- | lib/libc/arch/powerpc64/gen/fabs.c | 37 | ||||
-rw-r--r-- | lib/libc/arch/powerpc64/gen/flt_rounds.c | 60 | ||||
-rw-r--r-- | lib/libc/arch/powerpc64/gen/fpgetmask.c | 43 | ||||
-rw-r--r-- | lib/libc/arch/powerpc64/gen/fpgetround.c | 44 | ||||
-rw-r--r-- | lib/libc/arch/powerpc64/gen/fpgetsticky.c | 43 | ||||
-rw-r--r-- | lib/libc/arch/powerpc64/gen/fpsetmask.c | 48 | ||||
-rw-r--r-- | lib/libc/arch/powerpc64/gen/fpsetround.c | 48 | ||||
-rw-r--r-- | lib/libc/arch/powerpc64/gen/fpsetsticky.c | 52 | ||||
-rw-r--r-- | lib/libc/arch/powerpc64/gen/infinity.c | 9 | ||||
-rw-r--r-- | lib/libc/arch/powerpc64/gen/nan.c | 9 | ||||
-rw-r--r-- | lib/libc/arch/powerpc64/gen/setjmp.S | 188 | ||||
-rw-r--r-- | lib/libc/arch/powerpc64/gen/sigsetjmp.S | 173 |
14 files changed, 812 insertions, 0 deletions
diff --git a/lib/libc/arch/powerpc64/gen/Makefile.inc b/lib/libc/arch/powerpc64/gen/Makefile.inc new file mode 100644 index 00000000000..6b2e4613ee8 --- /dev/null +++ b/lib/libc/arch/powerpc64/gen/Makefile.inc @@ -0,0 +1,5 @@ +SRCS+= infinity.c setjmp.S sigsetjmp.S flt_rounds.c ldexp.c modf.c nan.c +SRCS+= fabs.c +SRCS+= fpgetmask.c fpsetmask.c +SRCS+= fpgetround.c fpsetround.c +SRCS+= fpgetsticky.c fpsetsticky.c diff --git a/lib/libc/arch/powerpc64/gen/_atomic_lock.c b/lib/libc/arch/powerpc64/gen/_atomic_lock.c new file mode 100644 index 00000000000..56faf2a61df --- /dev/null +++ b/lib/libc/arch/powerpc64/gen/_atomic_lock.c @@ -0,0 +1,53 @@ +/* $OpenBSD: _atomic_lock.c,v 1.1 2020/06/25 02:03:55 drahn Exp $ */ +/* + * Copyright (c) 1998 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. + */ + +/* + * Atomic lock for powerpc + */ + +#include <machine/spinlock.h> + +int +_atomic_lock(volatile _atomic_lock_t *lock) +{ + _atomic_lock_t old; + + __asm__("1: ldarx 0,0,%1 \n" + " stdcx. %2,0,%1 \n" + " bne- 1b \n" + " mr %0, 0 \n" + : "=r" (old), "=r" (lock) + : "r" (_ATOMIC_LOCK_LOCKED), "1" (lock) : "0" + ); + + return (old != _ATOMIC_LOCK_UNLOCKED); + + /* + * Dale <drahn@openbsd.org> says: + * Side note. to prevent two processes from accessing + * the same address with the ldarx in one instruction + * and the stdcx in another process, the current powerpc + * kernel uses a stdcx instruction without the corresponding + * lwarx which causes any reservation of a process + * to be removed. if a context switch occurs + * between the two accesses the store will not occur + * and the condition code will cause it to loop. If on + * a dual processor machine, the reserve will cause + * appropriate bus cycle accesses to notify other + * processors. + */ +} diff --git a/lib/libc/arch/powerpc64/gen/fabs.c b/lib/libc/arch/powerpc64/gen/fabs.c new file mode 100644 index 00000000000..ac76e936c1d --- /dev/null +++ b/lib/libc/arch/powerpc64/gen/fabs.c @@ -0,0 +1,37 @@ +/* $OpenBSD: fabs.c,v 1.1 2020/06/25 02:03:55 drahn Exp $ */ + +/* + * Copyright (c) 2002 Theo de Raadt + * 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 ``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 <math.h> + +double +fabs(double x) +{ + __asm__ volatile("fabs %0,%1" : "=f"(x) : "f"(x)); + return (x); +} + +__strong_alias(fabsl, fabs); diff --git a/lib/libc/arch/powerpc64/gen/flt_rounds.c b/lib/libc/arch/powerpc64/gen/flt_rounds.c new file mode 100644 index 00000000000..940465350a0 --- /dev/null +++ b/lib/libc/arch/powerpc64/gen/flt_rounds.c @@ -0,0 +1,60 @@ +/* $OpenBSD: flt_rounds.c,v 1.1 2020/06/25 02:03:55 drahn Exp $ */ +/* $NetBSD: flt_rounds.c,v 1.5 2001/05/25 12:14:05 simonb 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 <float.h> +#include <ieeefp.h> + + +static const int map[] = { + 1, /* round to nearest */ + 0, /* round to zero */ + 2, /* round to positive infinity */ + 3 /* round to negative infinity */ +}; + +int +__flt_rounds(void) +{ +#ifdef _SOFT_FLOAT + return map[fpgetround()]; +#else + double tmp; + int x; + + __asm__ volatile("mffs %0; stfiwx %0,0,%1" : "=f"(tmp): "b"(&x)); + return map[x & 0x03]; +#endif +} +DEF_STRONG(__flt_rounds); diff --git a/lib/libc/arch/powerpc64/gen/fpgetmask.c b/lib/libc/arch/powerpc64/gen/fpgetmask.c new file mode 100644 index 00000000000..1f7ff74af90 --- /dev/null +++ b/lib/libc/arch/powerpc64/gen/fpgetmask.c @@ -0,0 +1,43 @@ +/* $OpenBSD: fpgetmask.c,v 1.1 2020/06/25 02:03:55 drahn Exp $ */ +/* $NetBSD: fpgetmask.c,v 1.1 1999/07/07 01:55:07 danw Exp $ */ + +/* + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Dan Winship. + * + * 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 <sys/types.h> +#include <ieeefp.h> + +fp_except +fpgetmask() +{ + u_int64_t fpscr; + + __asm__ volatile("mffs %0" : "=f"(fpscr)); + return ((fpscr >> 3) & 0x1f); +} diff --git a/lib/libc/arch/powerpc64/gen/fpgetround.c b/lib/libc/arch/powerpc64/gen/fpgetround.c new file mode 100644 index 00000000000..8e9472cd7d8 --- /dev/null +++ b/lib/libc/arch/powerpc64/gen/fpgetround.c @@ -0,0 +1,44 @@ +/* $OpenBSD: fpgetround.c,v 1.1 2020/06/25 02:03:55 drahn Exp $ */ +/* $NetBSD: fpgetround.c,v 1.1 1999/07/07 01:55:08 danw Exp $ */ + +/* + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Dan Winship. + * + * 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 <sys/types.h> +#include <ieeefp.h> + +fp_rnd +fpgetround(void) +{ + u_int64_t fpscr; + + __asm__ volatile("mffs %0" : "=f"(fpscr)); + return (fpscr & 0x3); +} +DEF_WEAK(fpgetround); diff --git a/lib/libc/arch/powerpc64/gen/fpgetsticky.c b/lib/libc/arch/powerpc64/gen/fpgetsticky.c new file mode 100644 index 00000000000..5336944b8b4 --- /dev/null +++ b/lib/libc/arch/powerpc64/gen/fpgetsticky.c @@ -0,0 +1,43 @@ +/* $OpenBSD: fpgetsticky.c,v 1.1 2020/06/25 02:03:55 drahn Exp $ */ +/* $NetBSD: fpgetsticky.c,v 1.1 1999/07/07 01:55:08 danw Exp $ */ + +/* + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Dan Winship. + * + * 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 <sys/types.h> +#include <ieeefp.h> + +fp_except +fpgetsticky() +{ + u_int64_t fpscr; + + __asm__ volatile("mffs %0" : "=f"(fpscr)); + return ((fpscr >> 25) & 0x1f); +} diff --git a/lib/libc/arch/powerpc64/gen/fpsetmask.c b/lib/libc/arch/powerpc64/gen/fpsetmask.c new file mode 100644 index 00000000000..eed6c5e1fa4 --- /dev/null +++ b/lib/libc/arch/powerpc64/gen/fpsetmask.c @@ -0,0 +1,48 @@ +/* $OpenBSD: fpsetmask.c,v 1.1 2020/06/25 02:03:55 drahn Exp $ */ +/* $NetBSD: fpsetmask.c,v 1.1 1999/07/07 01:55:08 danw Exp $ */ + +/* + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Dan Winship. + * + * 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 <sys/types.h> +#include <ieeefp.h> + +fp_except +fpsetmask(mask) + fp_except mask; +{ + u_int64_t fpscr; + fp_rnd old; + + __asm__ volatile("mffs %0" : "=f"(fpscr)); + old = (fpscr >> 3) & 0x1f; + fpscr = (fpscr & 0xffffff07ULL) | (mask << 3); + __asm__ volatile("mtfsf 0xff,%0" :: "f"(fpscr)); + return (old); +} diff --git a/lib/libc/arch/powerpc64/gen/fpsetround.c b/lib/libc/arch/powerpc64/gen/fpsetround.c new file mode 100644 index 00000000000..8c9a7a7e1e6 --- /dev/null +++ b/lib/libc/arch/powerpc64/gen/fpsetround.c @@ -0,0 +1,48 @@ +/* $OpenBSD: fpsetround.c,v 1.1 2020/06/25 02:03:55 drahn Exp $ */ +/* $NetBSD: fpsetround.c,v 1.1 1999/07/07 01:55:08 danw Exp $ */ + +/* + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Dan Winship. + * + * 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 <sys/types.h> +#include <ieeefp.h> + +fp_rnd +fpsetround(rnd_dir) + fp_rnd rnd_dir; +{ + u_int64_t fpscr; + fp_rnd old; + + __asm__ volatile("mffs %0" : "=f"(fpscr)); + old = fpscr & 0x3; + fpscr = (fpscr & 0xfffffffcULL) | rnd_dir; + __asm__ volatile("mtfsf 0xff,%0" :: "f"(fpscr)); + return (old); +} diff --git a/lib/libc/arch/powerpc64/gen/fpsetsticky.c b/lib/libc/arch/powerpc64/gen/fpsetsticky.c new file mode 100644 index 00000000000..90f2977f91e --- /dev/null +++ b/lib/libc/arch/powerpc64/gen/fpsetsticky.c @@ -0,0 +1,52 @@ +/* $OpenBSD: fpsetsticky.c,v 1.1 2020/06/25 02:03:55 drahn Exp $ */ +/* $NetBSD: fpsetsticky.c,v 1.1 1999/07/07 01:55:08 danw Exp $ */ + +/* + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Dan Winship. + * + * 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 <sys/types.h> +#include <ieeefp.h> + +fp_except +fpsetsticky(mask) + fp_except mask; +{ + u_int64_t fpscr; + fp_rnd old; + + __asm__ volatile("mffs %0" : "=f"(fpscr)); + old = (fpscr >> 25) & 0x1f; + fpscr = (fpscr & 0xe1ffffffULL) | ((mask & 0xf) << 25); + if (mask & FP_X_INV) + fpscr |= 0x400; + else + fpscr &= 0xfe07f8ffULL; + __asm__ volatile("mtfsf 0xff,%0" :: "f"(fpscr)); + return (old); +} diff --git a/lib/libc/arch/powerpc64/gen/infinity.c b/lib/libc/arch/powerpc64/gen/infinity.c new file mode 100644 index 00000000000..9dd9b23dd26 --- /dev/null +++ b/lib/libc/arch/powerpc64/gen/infinity.c @@ -0,0 +1,9 @@ +/* $OpenBSD: infinity.c,v 1.1 2020/06/25 02:03:55 drahn Exp $ */ + +/* infinity.c */ + +#include <math.h> + +/* bytes for +Infinity on a PowerPC */ +char __infinity[] __attribute__((__aligned__(sizeof(double)))) = + { 0x7f, (char)0xf0, 0, 0, 0, 0, 0, 0 }; diff --git a/lib/libc/arch/powerpc64/gen/nan.c b/lib/libc/arch/powerpc64/gen/nan.c new file mode 100644 index 00000000000..4c664577a20 --- /dev/null +++ b/lib/libc/arch/powerpc64/gen/nan.c @@ -0,0 +1,9 @@ +/* $OpenBSD: nan.c,v 1.1 2020/06/25 02:03:55 drahn Exp $ */ + +/* Written by Martynas Venckus. Public Domain. */ + +#include <math.h> + +/* bytes for qNaN on a powerpc (IEEE single format) */ +char __nan[] __attribute__((__aligned__(sizeof(float)))) = + { 0x7f, 0xc0, 0, 0 }; diff --git a/lib/libc/arch/powerpc64/gen/setjmp.S b/lib/libc/arch/powerpc64/gen/setjmp.S new file mode 100644 index 00000000000..eb370c188f2 --- /dev/null +++ b/lib/libc/arch/powerpc64/gen/setjmp.S @@ -0,0 +1,188 @@ +/* $OpenBSD: setjmp.S,v 1.1 2020/06/25 02:03:55 drahn Exp $ */ +/* + * Copyright (c) 2020 Dale Rahn. 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 ``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.h" +#include <machine/asm.h> + +/* int setjmp(jmp_buf env) */ + +#define JMP_r1 0x08 +#define JMP_r14 0x10 +#define JMP_r15 0x18 +#define JMP_r16 0x20 +#define JMP_r17 0x28 +#define JMP_r18 0x30 +#define JMP_r19 0x38 +#define JMP_r20 0x40 +#define JMP_r21 0x48 +#define JMP_r22 0x50 +#define JMP_r23 0x58 +#define JMP_r24 0x60 +#define JMP_r25 0x68 +#define JMP_r26 0x70 +#define JMP_r27 0x78 +#define JMP_r28 0x80 +#define JMP_r29 0x88 +#define JMP_r30 0x90 +#define JMP_r31 0x98 +#define JMP_lr 0xa0 +#define JMP_cr 0xa8 +#define JMP_ctr 0xb0 +#define JMP_xer 0xb8 +#define JMP_sig 0xc0 + + .section .openbsd.randomdata,"aw",@progbits + .balign 4 + .globl __jmpxor + .hidden __jmpxor +__jmpxor: + .zero 8*2 # (r1, lr) + END(__jmpxor) + .type __jmpxor,@object + + +/* int setjmp(jmp_buf env); */ +ENTRY(setjmp) + mr %r5, %r3 /* save jmpbuf addr in r5 */ + li %r3, 1 /* how = SIG_BLOCK */ + li %r4, 0 /* oset = empty */ + li %r0, SYS_sigprocmask + sc + std %r3, JMP_sig(%r5) + mr %r3, %r5 + b _setjmp + nop + +ENTRY(_setjmp) + mr %r5, %r3 /* save jmpbuf addr in r5 */ + + addis %r7, %r2, __jmpxor@toc@ha + addi %r7, %r7, __jmpxor@toc@l + ld %r0, 0(%r7) /* xor for r1 */ + ld %r7, 8(%r7) /* xor for lr, overwrite addr */ + + /* r1, r14-r31 */ + xor %r0, %r0, %r1 /* use and overwrite the r1 xor */ + std %r0, JMP_r1(%r5) + std %r14, JMP_r14(%r5) + std %r15, JMP_r15(%r5) + std %r16, JMP_r16(%r5) + std %r17, JMP_r17(%r5) + std %r18, JMP_r18(%r5) + std %r19, JMP_r19(%r5) + std %r20, JMP_r20(%r5) + std %r21, JMP_r21(%r5) + std %r22, JMP_r22(%r5) + std %r23, JMP_r23(%r5) + std %r24, JMP_r24(%r5) + std %r25, JMP_r25(%r5) + std %r26, JMP_r26(%r5) + std %r27, JMP_r27(%r5) + std %r28, JMP_r28(%r5) + std %r29, JMP_r29(%r5) + std %r30, JMP_r30(%r5) + std %r31, JMP_r31(%r5) + /* lr, cr, ctr, xer */ + mflr %r6 + xor %r7, %r6, %r7 /* use and overwrite the lr xor */ + std %r7, JMP_lr(%r5) + mfcr %r0 + stw %r0, JMP_cr(3) + mfctr %r0 + std %r0, JMP_ctr(%r5) + mfxer %r0 + std %r0, JMP_xer(%r5) + /* floating point is all caller save */ + li %r3, 0 + blr +END(_setjmp) +END(setjmp) + + +/* void longjmp(jmp_buf env, int val); */ +ENTRY(longjmp) + mr %r5, %r3 /* save jmpbuf addr in r5 */ + mr %r6, %r4 /* save val in r6 */ + li %r3, 3 /* how = SIG_SETMASK */ + ld %r4, JMP_sig(%r5) /* oset from the jmpbuf */ + li %r0, SYS_sigprocmask + sc + nop + b 1f + nop + +/* _longjmp(jmp_buf env, int val); */ + +ENTRY(_longjmp) + mr %r5, %r3 /* save jmpbuf addr in r5 */ + mr %r6, %r4 /* save val in r6 */ +1: + addis %r9, %r2, __jmpxor@toc@ha + addi %r9, %r9, __jmpxor@toc@l + ld %r8, 0(%r9) /* xor for r1 */ + ld %r9, 8(%r9) /* xor for lr, overwrite addr */ + + /* r1, r14-r31 */ + ld %r0, JMP_r1(%r5) + xor %r1, %r0, %r8 /* use the r1 xor */ + ld %r14, JMP_r14(%r5) + ld %r15, JMP_r15(%r5) + ld %r16, JMP_r16(%r5) + ld %r17, JMP_r17(%r5) + ld %r18, JMP_r18(%r5) + ld %r19, JMP_r19(%r5) + ld %r20, JMP_r20(%r5) + ld %r21, JMP_r21(%r5) + ld %r22, JMP_r22(%r5) + ld %r23, JMP_r23(%r5) + ld %r24, JMP_r24(%r5) + ld %r25, JMP_r25(%r5) + ld %r26, JMP_r26(%r5) + ld %r27, JMP_r27(%r5) + ld %r28, JMP_r28(%r5) + ld %r29, JMP_r29(%r5) + ld %r30, JMP_r30(%r5) + ld %r31, JMP_r31(%r5) + /* cr, lr, ctr, xer */ + ld %r8, JMP_cr(%r5) /* overwrite the r1 xor */ + mtcr %r8 + ld %r0, JMP_lr(%r5) + xor %r0, %r0, %r9 /* use the lr xor */ + mtlr %r0 + ld %r9, JMP_ctr(%r5) /* overwrite the lr xor */ + mtctr %r9 + ld %r0, JMP_xer(%r5) + mtxer %r0 + /* floating point is all caller save */ + + /* if return val in r6 == 0, return 1, not 0 */ + mr %r3, %r6 + cmpwi %r6, 0 + bnelr + li %r3, 1 + blr +END(_longjmp) +END(longjmp) diff --git a/lib/libc/arch/powerpc64/gen/sigsetjmp.S b/lib/libc/arch/powerpc64/gen/sigsetjmp.S new file mode 100644 index 00000000000..a2fe1488583 --- /dev/null +++ b/lib/libc/arch/powerpc64/gen/sigsetjmp.S @@ -0,0 +1,173 @@ +/* $OpenBSD: sigsetjmp.S,v 1.1 2020/06/25 02:03:55 drahn Exp $ */ +/* + * Copyright (c) 2020 Dale Rahn. 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 ``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.h" +#include <machine/asm.h> + +#define JMP_sigflag 0x00 +#define JMP_r1 0x08 +#define JMP_r14 0x10 +#define JMP_r15 0x18 +#define JMP_r16 0x20 +#define JMP_r17 0x28 +#define JMP_r18 0x30 +#define JMP_r19 0x38 +#define JMP_r20 0x40 +#define JMP_r21 0x48 +#define JMP_r22 0x50 +#define JMP_r23 0x58 +#define JMP_r24 0x60 +#define JMP_r25 0x68 +#define JMP_r26 0x70 +#define JMP_r27 0x78 +#define JMP_r28 0x80 +#define JMP_r29 0x88 +#define JMP_r30 0x90 +#define JMP_r31 0x98 +#define JMP_lr 0xa0 +#define JMP_cr 0xa8 +#define JMP_ctr 0xb0 +#define JMP_xer 0xb8 +#define JMP_sig 0xc0 +#define JMP_sigmask 0xc8 + + + .extern __jmpxor + +/* int sigsetjmp(sigjmp_buf env, int savemask) */ +ENTRY(sigsetjmp) + mr %r5, %r3 /* save jmpbuf addr in r5 */ + std %r4, JMP_sigflag(%r5) + or. %r4, %r4, %r4 + beq 1f + li %r3, 1 /* how = SIG_BLOCK */ + li %r4, 0 /* oset = empty */ + li %r0, SYS_sigprocmask + sc + nop + std %r3, JMP_sigmask(5) + + addis %r7, %r2, __jmpxor@toc@ha + addi %r7, %r7, __jmpxor@toc@l + ld %r8, 0(%r7) /* xor for r1 */ + ld %r7, 8(%r7) /* xor for lr, overwrite addr */ + + /* r1, r14-r31 */ + xor %r0, %r8, %r1 /* use and overwrite the r1 xor */ + std %r0, JMP_r1 (%r5) + std %r14, JMP_r14(%r5) + std %r15, JMP_r15(%r5) + std %r16, JMP_r16(%r5) + std %r17, JMP_r17(%r5) + std %r18, JMP_r18(%r5) + std %r19, JMP_r19(%r5) + std %r20, JMP_r20(%r5) + std %r21, JMP_r21(%r5) + std %r22, JMP_r22(%r5) + std %r23, JMP_r23(%r5) + std %r24, JMP_r24(%r5) + std %r25, JMP_r25(%r5) + std %r26, JMP_r26(%r5) + std %r27, JMP_r27(%r5) + std %r28, JMP_r28(%r5) + std %r29, JMP_r29(%r5) + std %r30, JMP_r30(%r5) + std %r31, JMP_r31(%r5) + /* lr, cr, ctr, xer */ + mflr %r0 + xor %r7, %r0, %r7 /* use and overwrite the lr xor */ + std %r7, JMP_lr(%r5) + mfcr %r0 + std %r0, JMP_cr(%r5) + mfctr %r0 + std %r0, JMP_ctr(%r5) + mfctr %r0 + mfxer %r0 + std %r0, JMP_xer(%r5) + /* f14-f31, fpscr */ + li %r3, 0 + blr +END(sigsetjmp) + + +/* int siglongjmp(sigjmp_buf env, int val) */ +ENTRY(siglongjmp) + mr %r5, %r3 /* save jmpbuf addr in r5 */ + mr %r6, %r4 /* save val in r6 */ + ld %r4, JMP_sigflag(%r5) /* do we need to restore sigmask? */ + or. %r4, %r4, %r4 + beq 1f + + li %r3, 3 /* how = SIG_SETMASK */ + ld %r4, JMP_sigmask(%r5) /* oset from the jmpbuf */ + li %r0, SYS_sigprocmask + sc +1: + addis %r9, %r2, __jmpxor@toc@ha + addi %r9, %r9, __jmpxor@toc@l + ld %r8, 0(%r9) /* xor for r1 */ + ld %r9, 8(%r9) /* xor for lr, overwrite addr */ + + /* r1, r14-r31 */ + ld %r0, JMP_r1(%r5) + xor %r1, %r0, %r8 /* use the r1 xor */ + ld %r14, JMP_r14(%r5) + ld %r15, JMP_r15(%r5) + ld %r16, JMP_r16(%r5) + ld %r17, JMP_r17(%r5) + ld %r18, JMP_r18(%r5) + ld %r19, JMP_r19(%r5) + ld %r20, JMP_r20(%r5) + ld %r21, JMP_r21(%r5) + ld %r22, JMP_r22(%r5) + ld %r23, JMP_r23(%r5) + ld %r24, JMP_r24(%r5) + ld %r25, JMP_r25(%r5) + ld %r26, JMP_r26(%r5) + ld %r27, JMP_r27(%r5) + ld %r28, JMP_r28(%r5) + ld %r29, JMP_r29(%r5) + ld %r30, JMP_r30(%r5) + ld %r31, JMP_r31(%r5) + /* cr, lr, ctr, xer */ + ld %r8, JMP_cr(%r5) /* overwrite the r1 xor */ + mtcr %r8 + ld %r0, JMP_lr(%r5) + xor %r0, %r0, %r9 /* use the lr xor */ + mtlr %r0 + ld %r9, JMP_ctr(%r5) /* overwrite the lr xor */ + mtctr %r9 + ld %r0, JMP_xer(%r5) + mtxer %r0 + /* floating point is all caller save */ + + /* if return val in r6 == 0, return 1, not 0 */ + mr %r3, %r6 + cmpwi %r6, 0 + bnelr + li %r3, 1 + blr +END(siglongjmp) |