diff options
Diffstat (limited to 'lib/libc/powerpc64/gen')
-rw-r--r-- | lib/libc/powerpc64/gen/Makefile.inc | 6 | ||||
-rw-r--r-- | lib/libc/powerpc64/gen/_ctx_start.S | 68 | ||||
-rw-r--r-- | lib/libc/powerpc64/gen/_setjmp.S | 153 | ||||
-rw-r--r-- | lib/libc/powerpc64/gen/fabs.S | 36 | ||||
-rw-r--r-- | lib/libc/powerpc64/gen/flt_rounds.c | 55 | ||||
-rw-r--r-- | lib/libc/powerpc64/gen/fpgetmask.c | 47 | ||||
-rw-r--r-- | lib/libc/powerpc64/gen/fpgetround.c | 47 | ||||
-rw-r--r-- | lib/libc/powerpc64/gen/fpgetsticky.c | 49 | ||||
-rw-r--r-- | lib/libc/powerpc64/gen/fpsetmask.c | 51 | ||||
-rw-r--r-- | lib/libc/powerpc64/gen/fpsetround.c | 51 | ||||
-rw-r--r-- | lib/libc/powerpc64/gen/infinity.c | 28 | ||||
-rw-r--r-- | lib/libc/powerpc64/gen/makecontext.c | 127 | ||||
-rw-r--r-- | lib/libc/powerpc64/gen/setjmp.S | 174 | ||||
-rw-r--r-- | lib/libc/powerpc64/gen/signalcontext.c | 102 | ||||
-rw-r--r-- | lib/libc/powerpc64/gen/sigsetjmp.S | 181 | ||||
-rw-r--r-- | lib/libc/powerpc64/gen/syncicache.c | 100 |
16 files changed, 1275 insertions, 0 deletions
diff --git a/lib/libc/powerpc64/gen/Makefile.inc b/lib/libc/powerpc64/gen/Makefile.inc new file mode 100644 index 000000000000..c48ff05ae552 --- /dev/null +++ b/lib/libc/powerpc64/gen/Makefile.inc @@ -0,0 +1,6 @@ +SRCS += _ctx_start.S fabs.S flt_rounds.c fpgetmask.c fpgetround.c \ + fpgetsticky.c fpsetmask.c fpsetround.c \ + infinity.c ldexp.c makecontext.c _setjmp.S \ + setjmp.S sigsetjmp.S signalcontext.c syncicache.c \ + trivial-getcontextx.c + diff --git a/lib/libc/powerpc64/gen/_ctx_start.S b/lib/libc/powerpc64/gen/_ctx_start.S new file mode 100644 index 000000000000..98225f9c1138 --- /dev/null +++ b/lib/libc/powerpc64/gen/_ctx_start.S @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2004 Suleiman Souhlal + * 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 <machine/asm.h> + .globl CNAME(_ctx_done) + .globl CNAME(abort) + + ENTRY(_ctx_start) +#if !defined(_CALL_ELF) || _CALL_ELF == 1 + /* Load values from function descriptor */ + ld %r2,8(%r14) + ld %r14,0(%r14) +#else + /* + * The stack frame was already set up in makecontext(), + * so we can safely use the guaranteed fields here. + * + * Note we do step on the allocated stack frame's TOC, + * but since we never return from this function (i.e. + * never restore the stack frame) this should be safe. + */ + std %r2,24(%r1) /* save TOC */ + + /* Load global entry point */ + mr %r12,%r14 +#endif + mtlr %r14 + blrl /* branch to start function */ + mr %r3,%r15 /* pass pointer to ucontext as argument */ + nop +#if defined(_CALL_ELF) && _CALL_ELF != 1 + /* Restore TOC */ + ld %r2,24(%r1) +#endif + bl CNAME(_ctx_done) /* branch to ctxt completion func */ + /* + * we should never return from the + * above branch. + */ + nop + bl CNAME(abort) /* abort */ + nop + END(_ctx_start) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libc/powerpc64/gen/_setjmp.S b/lib/libc/powerpc64/gen/_setjmp.S new file mode 100644 index 000000000000..94a744b4fa28 --- /dev/null +++ b/lib/libc/powerpc64/gen/_setjmp.S @@ -0,0 +1,153 @@ +/*- + * Copyright (c) 2002 Peter Grehan. + * 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. + */ +/* $NetBSD: _setjmp.S,v 1.1 1997/03/29 20:55:53 thorpej Exp $ */ + +#include <machine/asm.h> +/* + * C library -- _setjmp, _longjmp + * + * _longjmp(a,v) + * will generate a "return(v?v:1)" from the last call to + * _setjmp(a) + * by restoring registers from the stack. + * The previous signal state is NOT restored. + * + * jmpbuf layout: + * +------------+ + * | unused | + * +------------+ + * | unused | + * | | + * | (4 words) | + * | | + * +------------+ + * | saved regs | + * | ... | + */ + +ENTRY(_setjmp) + mflr %r11 + mfcr %r12 + mr %r10,%r1 + mr %r9,%r2 + std %r9,40 + 0*8(%r3) + stfd %f14,40 + 23*8(%r3) + std %r10,40 + 1*8(%r3) + stfd %f15,40 + 24*8(%r3) + std %r11,40 + 2*8(%r3) + stfd %f16,40 + 25*8(%r3) + std %r12,40 + 3*8(%r3) + stfd %f17,40 + 26*8(%r3) + std %r13,40 + 4*8(%r3) + stfd %f18,40 + 27*8(%r3) + std %r14,40 + 5*8(%r3) + stfd %f19,40 + 28*8(%r3) + std %r15,40 + 6*8(%r3) + stfd %f20,40 + 29*8(%r3) + std %r16,40 + 7*8(%r3) + stfd %f21,40 + 30*8(%r3) + std %r17,40 + 8*8(%r3) + stfd %f22,40 + 31*8(%r3) + std %r18,40 + 9*8(%r3) + stfd %f23,40 + 32*8(%r3) + std %r19,40 + 10*8(%r3) + stfd %f24,40 + 33*8(%r3) + std %r20,40 + 11*8(%r3) + stfd %f25,40 + 34*8(%r3) + std %r21,40 + 12*8(%r3) + stfd %f26,40 + 35*8(%r3) + std %r22,40 + 13*8(%r3) + stfd %f27,40 + 36*8(%r3) + std %r23,40 + 14*8(%r3) + stfd %f28,40 + 37*8(%r3) + std %r24,40 + 15*8(%r3) + stfd %f29,40 + 38*8(%r3) + std %r25,40 + 16*8(%r3) + stfd %f30,40 + 39*8(%r3) + std %r26,40 + 17*8(%r3) + stfd %f31,40 + 40*8(%r3) + std %r27,40 + 18*8(%r3) + std %r28,40 + 19*8(%r3) + std %r29,40 + 20*8(%r3) + std %r30,40 + 21*8(%r3) + std %r31,40 + 22*8(%r3) + li %r3,0 + blr +END(_setjmp) + +ENTRY(_longjmp) + ld %r9,40 + 0*8(%r3) + lfd %f14,40 + 23*8(%r3) + ld %r10,40 + 1*8(%r3) + lfd %f15,40 + 24*8(%r3) + ld %r11,40 + 2*8(%r3) + lfd %f16,40 + 25*8(%r3) + ld %r12,40 + 3*8(%r3) + lfd %f17,40 + 26*8(%r3) + ld %r14,40 + 5*8(%r3) + lfd %f18,40 + 27*8(%r3) + ld %r15,40 + 6*8(%r3) + lfd %f19,40 + 28*8(%r3) + ld %r16,40 + 7*8(%r3) + lfd %f20,40 + 29*8(%r3) + ld %r17,40 + 8*8(%r3) + lfd %f21,40 + 30*8(%r3) + ld %r18,40 + 9*8(%r3) + lfd %f22,40 + 31*8(%r3) + ld %r19,40 + 10*8(%r3) + lfd %f23,40 + 32*8(%r3) + ld %r20,40 + 11*8(%r3) + lfd %f24,40 + 33*8(%r3) + ld %r21,40 + 12*8(%r3) + lfd %f25,40 + 34*8(%r3) + ld %r22,40 + 13*8(%r3) + lfd %f26,40 + 35*8(%r3) + ld %r23,40 + 14*8(%r3) + lfd %f27,40 + 36*8(%r3) + ld %r24,40 + 15*8(%r3) + lfd %f28,40 + 37*8(%r3) + ld %r25,40 + 16*8(%r3) + lfd %f29,40 + 38*8(%r3) + ld %r26,40 + 17*8(%r3) + lfd %f30,40 + 39*8(%r3) + ld %r27,40 + 18*8(%r3) + lfd %f31,40 + 40*8(%r3) + ld %r28,40 + 19*8(%r3) + ld %r29,40 + 20*8(%r3) + ld %r30,40 + 21*8(%r3) + ld %r31,40 + 22*8(%r3) + + mtlr %r11 + mtcr %r12 + mr %r2,%r9 + mr %r1,%r10 + or. %r3,%r4,%r4 + bnelr + li %r3,1 + blr +END(_longjmp) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libc/powerpc64/gen/fabs.S b/lib/libc/powerpc64/gen/fabs.S new file mode 100644 index 000000000000..d9dbf9d86fe0 --- /dev/null +++ b/lib/libc/powerpc64/gen/fabs.S @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2004 Peter Grehan. + * 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 <machine/asm.h> +/* + * double fabs(double) + */ +ENTRY(fabs) + fabs %f1,%f1 + blr +END(fabs) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libc/powerpc64/gen/flt_rounds.c b/lib/libc/powerpc64/gen/flt_rounds.c new file mode 100644 index 000000000000..800ec6944d79 --- /dev/null +++ b/lib/libc/powerpc64/gen/flt_rounds.c @@ -0,0 +1,55 @@ +/* $NetBSD: flt_rounds.c,v 1.4.10.3 2002/03/22 20:41:53 nathanw Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * 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 <machine/float.h> + +#ifndef _SOFT_FLOAT +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() +{ + uint64_t fpscr; + + __asm__ __volatile("mffs %0" : "=f"(fpscr)); + return map[(fpscr & 0x03)]; +} +#endif diff --git a/lib/libc/powerpc64/gen/fpgetmask.c b/lib/libc/powerpc64/gen/fpgetmask.c new file mode 100644 index 000000000000..6817a32bdc65 --- /dev/null +++ b/lib/libc/powerpc64/gen/fpgetmask.c @@ -0,0 +1,47 @@ +/* $NetBSD: fpgetmask.c,v 1.3 2002/01/13 21:45:47 thorpej Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * 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> + +#ifndef _SOFT_FLOAT +fp_except_t +fpgetmask() +{ + u_int64_t fpscr; + + __asm__("mffs %0" : "=f"(fpscr)); + return ((fp_except_t)((fpscr >> 3) & 0x1f)); +} +#endif diff --git a/lib/libc/powerpc64/gen/fpgetround.c b/lib/libc/powerpc64/gen/fpgetround.c new file mode 100644 index 000000000000..b135807b613f --- /dev/null +++ b/lib/libc/powerpc64/gen/fpgetround.c @@ -0,0 +1,47 @@ +/* $NetBSD: fpgetround.c,v 1.3 2002/01/13 21:45:47 thorpej Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * 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> + +#ifndef _SOFT_FLOAT +fp_rnd_t +fpgetround() +{ + u_int64_t fpscr; + + __asm__("mffs %0" : "=f"(fpscr)); + return ((fp_rnd_t)(fpscr & 0x3)); +} +#endif diff --git a/lib/libc/powerpc64/gen/fpgetsticky.c b/lib/libc/powerpc64/gen/fpgetsticky.c new file mode 100644 index 000000000000..3512c97f8cf9 --- /dev/null +++ b/lib/libc/powerpc64/gen/fpgetsticky.c @@ -0,0 +1,49 @@ +/* $NetBSD: fpgetsticky.c,v 1.3 2002/01/13 21:45:48 thorpej Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * 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 "namespace.h" + +#include <sys/types.h> +#include <ieeefp.h> + +#ifndef _SOFT_FLOAT +fp_except_t +fpgetsticky() +{ + u_int64_t fpscr; + + __asm__ __volatile("mffs %0" : "=f"(fpscr)); + return ((fp_except_t)((fpscr >> 25) & 0x1f)); +} +#endif diff --git a/lib/libc/powerpc64/gen/fpsetmask.c b/lib/libc/powerpc64/gen/fpsetmask.c new file mode 100644 index 000000000000..4170b385e9e4 --- /dev/null +++ b/lib/libc/powerpc64/gen/fpsetmask.c @@ -0,0 +1,51 @@ +/* $NetBSD: fpsetmask.c,v 1.3 2002/01/13 21:45:48 thorpej Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * 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> + +#ifndef _SOFT_FLOAT +fp_except_t +fpsetmask(fp_except_t mask) +{ + u_int64_t fpscr; + fp_except_t old; + + __asm__("mffs %0" : "=f"(fpscr)); + old = (fp_except_t)((fpscr >> 3) & 0x1f); + fpscr = (fpscr & 0xffffff07) | ((mask & 0x1f) << 3); + __asm__ __volatile("mtfsf 0xff,%0" :: "f"(fpscr)); + return (old); +} +#endif diff --git a/lib/libc/powerpc64/gen/fpsetround.c b/lib/libc/powerpc64/gen/fpsetround.c new file mode 100644 index 000000000000..2a70fd781474 --- /dev/null +++ b/lib/libc/powerpc64/gen/fpsetround.c @@ -0,0 +1,51 @@ +/* $NetBSD: fpsetround.c,v 1.3 2002/01/13 21:45:48 thorpej Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * 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> + +#ifndef _SOFT_FLOAT +fp_rnd_t +fpsetround(fp_rnd_t rnd_dir) +{ + u_int64_t fpscr; + fp_rnd_t old; + + __asm__ __volatile("mffs %0" : "=f"(fpscr)); + old = (fp_rnd_t)(fpscr & 0x3); + fpscr = (fpscr & 0xfffffffc) | rnd_dir; + __asm__ __volatile("mtfsf 0xff,%0" :: "f"(fpscr)); + return (old); +} +#endif diff --git a/lib/libc/powerpc64/gen/infinity.c b/lib/libc/powerpc64/gen/infinity.c new file mode 100644 index 000000000000..6e11371e6eb3 --- /dev/null +++ b/lib/libc/powerpc64/gen/infinity.c @@ -0,0 +1,28 @@ +#include <sys/cdefs.h> +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: infinity.c,v 1.2 1998/11/14 19:31:02 christos Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +/* infinity.c */ + +#include <math.h> + +/* bytes for +Infinity on powerpc */ +const union __infinity_un __infinity = { +#if BYTE_ORDER == BIG_ENDIAN + { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 } +#else + { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f } +#endif +}; + +/* bytes for NaN */ +const union __nan_un __nan = { +#if BYTE_ORDER == BIG_ENDIAN + {0xff, 0xc0, 0, 0} +#else + { 0, 0, 0xc0, 0xff } +#endif +}; + diff --git a/lib/libc/powerpc64/gen/makecontext.c b/lib/libc/powerpc64/gen/makecontext.c new file mode 100644 index 000000000000..9e3a976fa1bd --- /dev/null +++ b/lib/libc/powerpc64/gen/makecontext.c @@ -0,0 +1,127 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2004 Suleiman Souhlal + * 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/param.h> + +#include <stdarg.h> +#include <stdlib.h> +#include <unistd.h> +#include <stdio.h> +#include <ucontext.h> + +__weak_reference(__makecontext, makecontext); + +void _ctx_done(ucontext_t *ucp); +void _ctx_start(void); + +void +_ctx_done(ucontext_t *ucp) +{ + if (ucp->uc_link == NULL) + exit(0); + else { + /* invalidate context */ + ucp->uc_mcontext.mc_len = 0; + + setcontext((const ucontext_t *)ucp->uc_link); + + abort(); /* should never return from above call */ + } +} + +void +__makecontext(ucontext_t *ucp, void (*start)(void), int argc, ...) +{ + mcontext_t *mc; + char *sp; + va_list ap; + int i, regargs, stackargs; + + /* Sanity checks */ + if ((ucp == NULL) || (argc < 0) + || (ucp->uc_stack.ss_sp == NULL) + || (ucp->uc_stack.ss_size < MINSIGSTKSZ)) { + /* invalidate context */ + ucp->uc_mcontext.mc_len = 0; + return; + } + + /* + * The stack must have space for the frame pointer, saved + * link register, overflow arguments, and be 16-byte + * aligned. + */ + stackargs = (argc > 8) ? argc - 8 : 0; + sp = (char *) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size + - sizeof(uintptr_t)*(stackargs + 6); + sp = (char *)((uintptr_t)sp & ~0x1f); + + mc = &ucp->uc_mcontext; + + /* + * Up to 8 register args. Assumes all args are 64-bit and + * integer only. Not sure how to cater for floating point. + */ + regargs = (argc > 8) ? 8 : argc; + va_start(ap, argc); + for (i = 0; i < regargs; i++) + mc->mc_gpr[3 + i] = va_arg(ap, uint64_t); + + /* + * Overflow args go onto the stack + */ + if (argc > 8) { + uint64_t *argp; + + /* Skip past frame pointer and saved LR */ +#if !defined(_CALL_ELF) || _CALL_ELF == 1 + argp = (uint64_t *)sp + 6; +#else + argp = (uint64_t *)sp + 4; +#endif + + for (i = 0; i < stackargs; i++) + *argp++ = va_arg(ap, uint64_t); + } + va_end(ap); + + /* + * Use caller-saved regs 14/15 to hold params that _ctx_start + * will use to invoke the user-supplied func + */ +#if !defined(_CALL_ELF) || _CALL_ELF == 1 + /* Cast to ensure this is treated as a function descriptor. */ + mc->mc_srr0 = *(uintptr_t *)_ctx_start; +#else + mc->mc_srr0 = (uintptr_t) _ctx_start; + mc->mc_gpr[12] = (uintptr_t) _ctx_start;/* required for prologue */ +#endif + mc->mc_gpr[1] = (uintptr_t) sp; /* new stack pointer */ + mc->mc_gpr[14] = (uintptr_t) start; /* r14 <- start */ + mc->mc_gpr[15] = (uintptr_t) ucp; /* r15 <- ucp */ +} diff --git a/lib/libc/powerpc64/gen/setjmp.S b/lib/libc/powerpc64/gen/setjmp.S new file mode 100644 index 000000000000..7cf48d63ec82 --- /dev/null +++ b/lib/libc/powerpc64/gen/setjmp.S @@ -0,0 +1,174 @@ +/*- + * Copyright (c) 2002 Peter Grehan. + * 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. + */ +/* $NetBSD: setjmp.S,v 1.3 1998/10/03 12:30:38 tsubai Exp $ */ + +#include <machine/asm.h> +#include <sys/syscall.h> + +/* + * C library -- setjmp, longjmp + * + * longjmp(a,v) + * will generate a "return(v?v:1)" from the last call to + * setjmp(a) + * by restoring registers from the stack. + * The previous signal state is restored. + * + * jmpbuf layout: + * +------------+ + * | unused | + * +------------+ + * | sig state | + * | | + * | (4 words) | + * | | + * +------------+ + * | saved regs | + * | ... | + */ + +ENTRY(setjmp) + mr %r6,%r3 + li %r3,1 /* SIG_BLOCK, but doesn't matter */ + /* since set == NULL */ + li %r4,0 /* set = NULL */ + mr %r5,%r6 /* &oset */ + addi %r5,%r5,4 + li %r0, SYS_sigprocmask /*sigprocmask(SIG_BLOCK, NULL, &oset)*/ + sc /*assume no error XXX */ + mflr %r11 /* r11 <- link reg */ + mfcr %r12 /* r12 <- condition reg */ + mr %r10,%r1 /* r10 <- stackptr */ + mr %r9,%r2 /* r9 <- global ptr */ + + std %r9,40 + 0*8(%r6) + stfd %f14,40 + 23*8(%r6) + std %r10,40 + 1*8(%r6) + stfd %f15,40 + 24*8(%r6) + std %r11,40 + 2*8(%r6) + stfd %f16,40 + 25*8(%r6) + std %r12,40 + 3*8(%r6) + stfd %f17,40 + 26*8(%r6) + std %r13,40 + 4*8(%r6) + stfd %f18,40 + 27*8(%r6) + std %r14,40 + 5*8(%r6) + stfd %f19,40 + 28*8(%r6) + std %r15,40 + 6*8(%r6) + stfd %f20,40 + 29*8(%r6) + std %r16,40 + 7*8(%r6) + stfd %f21,40 + 30*8(%r6) + std %r17,40 + 8*8(%r6) + stfd %f22,40 + 31*8(%r6) + std %r18,40 + 9*8(%r6) + stfd %f23,40 + 32*8(%r6) + std %r19,40 + 10*8(%r6) + stfd %f24,40 + 33*8(%r6) + std %r20,40 + 11*8(%r6) + stfd %f25,40 + 34*8(%r6) + std %r21,40 + 12*8(%r6) + stfd %f26,40 + 35*8(%r6) + std %r22,40 + 13*8(%r6) + stfd %f27,40 + 36*8(%r6) + std %r23,40 + 14*8(%r6) + stfd %f28,40 + 37*8(%r6) + std %r24,40 + 15*8(%r6) + stfd %f29,40 + 38*8(%r6) + std %r25,40 + 16*8(%r6) + stfd %f30,40 + 39*8(%r6) + std %r26,40 + 17*8(%r6) + stfd %f31,40 + 40*8(%r6) + std %r27,40 + 18*8(%r6) + std %r28,40 + 19*8(%r6) + std %r29,40 + 20*8(%r6) + std %r30,40 + 21*8(%r6) + std %r31,40 + 22*8(%r6) + + /* XXX Altivec regs */ + + li %r3,0 /* return (0) */ + blr +END(setjmp) + + WEAK_REFERENCE(__longjmp, longjmp) +ENTRY(__longjmp) + ld %r9,40 + 0*8(%r3) + lfd %f14,40 + 23*8(%r3) + ld %r10,40 + 1*8(%r3) + lfd %f15,40 + 24*8(%r3) + ld %r11,40 + 2*8(%r3) + lfd %f16,40 + 25*8(%r3) + ld %r12,40 + 3*8(%r3) + lfd %f17,40 + 26*8(%r3) + ld %r14,40 + 5*8(%r3) + lfd %f18,40 + 27*8(%r3) + ld %r15,40 + 6*8(%r3) + lfd %f19,40 + 28*8(%r3) + ld %r16,40 + 7*8(%r3) + lfd %f20,40 + 29*8(%r3) + ld %r17,40 + 8*8(%r3) + lfd %f21,40 + 30*8(%r3) + ld %r18,40 + 9*8(%r3) + lfd %f22,40 + 31*8(%r3) + ld %r19,40 + 10*8(%r3) + lfd %f23,40 + 32*8(%r3) + ld %r20,40 + 11*8(%r3) + lfd %f24,40 + 33*8(%r3) + ld %r21,40 + 12*8(%r3) + lfd %f25,40 + 34*8(%r3) + ld %r22,40 + 13*8(%r3) + lfd %f26,40 + 35*8(%r3) + ld %r23,40 + 14*8(%r3) + lfd %f27,40 + 36*8(%r3) + ld %r24,40 + 15*8(%r3) + lfd %f28,40 + 37*8(%r3) + ld %r25,40 + 16*8(%r3) + lfd %f29,40 + 38*8(%r3) + ld %r26,40 + 17*8(%r3) + lfd %f30,40 + 39*8(%r3) + ld %r27,40 + 18*8(%r3) + lfd %f31,40 + 40*8(%r3) + ld %r28,40 + 19*8(%r3) + ld %r29,40 + 20*8(%r3) + ld %r30,40 + 21*8(%r3) + ld %r31,40 + 22*8(%r3) + mr %r6,%r4 /* save val param */ + mtlr %r11 /* r11 -> link reg */ + mtcr %r12 /* r12 -> condition reg */ + mr %r2,%r9 /* r9 -> global ptr */ + mr %r1,%r10 /* r10 -> stackptr */ + mr %r4,%r3 + li %r3,3 /* SIG_SETMASK */ + addi %r4,%r4,4 /* &set */ + li %r5,0 /* oset = NULL */ + li %r0,SYS_sigprocmask /* sigprocmask(SIG_SET, &set, NULL) */ + sc /* assume no error XXX */ + or. %r3,%r6,%r6 + bnelr + li %r3,1 + blr +END(__longjmp) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libc/powerpc64/gen/signalcontext.c b/lib/libc/powerpc64/gen/signalcontext.c new file mode 100644 index 000000000000..de0b2109bba4 --- /dev/null +++ b/lib/libc/powerpc64/gen/signalcontext.c @@ -0,0 +1,102 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2004 Marcel Moolenaar, Peter Grehan + * 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/param.h> +#include <sys/ucontext.h> +#include <signal.h> +#include <stdlib.h> +#include <strings.h> + +typedef void (*handler_t)(uint32_t, uint32_t, uint32_t); + +/* Prototypes */ +static void ctx_wrapper(ucontext_t *ucp, handler_t func, uint32_t sig, + uint32_t sig_si, uint32_t sig_uc); + +__weak_reference(__signalcontext, signalcontext); + +int +__signalcontext(ucontext_t *ucp, int sig, __sighandler_t *func) +{ + siginfo_t *sig_si; + ucontext_t *sig_uc; + uintptr_t sp; + + /* Bail out if we don't have a valid ucontext pointer. */ + if (ucp == NULL) + abort(); + + /* + * Build a 16-byte-aligned signal frame + */ + sp = (ucp->uc_mcontext.mc_gpr[1] - sizeof(ucontext_t)) & ~15UL; + sig_uc = (ucontext_t *)sp; + bcopy(ucp, sig_uc, sizeof(*sig_uc)); + sp = (sp - sizeof(siginfo_t)) & ~15UL; + sig_si = (siginfo_t *)sp; + bzero(sig_si, sizeof(*sig_si)); + sig_si->si_signo = sig; + + /* + * Subtract 48 bytes from stack to allow for frameptr + */ + sp -= 6*sizeof(uint64_t); + sp &= ~15UL; + + /* + * Setup the ucontext of the signal handler. + */ + bzero(&ucp->uc_mcontext, sizeof(ucp->uc_mcontext)); + ucp->uc_link = sig_uc; + sigdelset(&ucp->uc_sigmask, sig); + + ucp->uc_mcontext.mc_vers = _MC_VERSION; + ucp->uc_mcontext.mc_len = sizeof(struct __mcontext); + ucp->uc_mcontext.mc_srr0 = (uint64_t) ctx_wrapper; + ucp->uc_mcontext.mc_gpr[1] = (uint64_t) sp; + ucp->uc_mcontext.mc_gpr[3] = (uint64_t) func; + ucp->uc_mcontext.mc_gpr[4] = (uint64_t) sig; + ucp->uc_mcontext.mc_gpr[5] = (uint64_t) sig_si; + ucp->uc_mcontext.mc_gpr[6] = (uint64_t) sig_uc; + + return (0); +} + +static void +ctx_wrapper(ucontext_t *ucp, handler_t func, uint32_t sig, uint32_t sig_si, + uint32_t sig_uc) +{ + + (*func)(sig, sig_si, sig_uc); + if (ucp->uc_link == NULL) + exit(0); + setcontext((const ucontext_t *)ucp->uc_link); + /* should never get here */ + abort(); + /* NOTREACHED */ +} diff --git a/lib/libc/powerpc64/gen/sigsetjmp.S b/lib/libc/powerpc64/gen/sigsetjmp.S new file mode 100644 index 000000000000..58fa188daaa4 --- /dev/null +++ b/lib/libc/powerpc64/gen/sigsetjmp.S @@ -0,0 +1,181 @@ +/*- + * Copyright (c) 2002 Peter Grehan. + * 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. + */ +/* $NetBSD: sigsetjmp.S,v 1.4 1998/10/03 12:30:38 tsubai Exp $ */ + +#include <machine/asm.h> +/* + * C library -- sigsetjmp, siglongjmp + * + * siglongjmp(a,v) + * will generate a "return(v?v:1)" from the last call to + * sigsetjmp(a, savemask) + * by restoring registers from the stack. + * The previous signal state is restored if savemask is non-zero + * + * jmpbuf layout: + * +------------+ + * | savemask | + * +------------+ + * | sig state | + * | | + * | (4 words) | + * | | + * +------------+ + * | saved regs | + * | ... | + */ + + +#include <sys/syscall.h> + +ENTRY(sigsetjmp) + mr %r6,%r3 + stw %r4,0(%r3) + or. %r7,%r4,%r4 + beq 1f + li %r3,1 /* SIG_BLOCK, but doesn't matter */ + /* since set == NULL */ + li %r4,0 /* set = NULL */ + mr %r5,%r6 /* &oset */ + addi %r5,%r5,4 + li %r0, SYS_sigprocmask /* sigprocmask(SIG_BLOCK, NULL, &oset)*/ + sc /* assume no error XXX */ +1: + mflr %r11 + mfcr %r12 + mr %r10,%r1 + mr %r9,%r2 + + std %r9,40 + 0*8(%r6) + stfd %f14,40 + 23*8(%r6) + std %r10,40 + 1*8(%r6) + stfd %f15,40 + 24*8(%r6) + std %r11,40 + 2*8(%r6) + stfd %f16,40 + 25*8(%r6) + std %r12,40 + 3*8(%r6) + stfd %f17,40 + 26*8(%r6) + std %r13,40 + 4*8(%r6) + stfd %f18,40 + 27*8(%r6) + std %r14,40 + 5*8(%r6) + stfd %f19,40 + 28*8(%r6) + std %r15,40 + 6*8(%r6) + stfd %f20,40 + 29*8(%r6) + std %r16,40 + 7*8(%r6) + stfd %f21,40 + 30*8(%r6) + std %r17,40 + 8*8(%r6) + stfd %f22,40 + 31*8(%r6) + std %r18,40 + 9*8(%r6) + stfd %f23,40 + 32*8(%r6) + std %r19,40 + 10*8(%r6) + stfd %f24,40 + 33*8(%r6) + std %r20,40 + 11*8(%r6) + stfd %f25,40 + 34*8(%r6) + std %r21,40 + 12*8(%r6) + stfd %f26,40 + 35*8(%r6) + std %r22,40 + 13*8(%r6) + stfd %f27,40 + 36*8(%r6) + std %r23,40 + 14*8(%r6) + stfd %f28,40 + 37*8(%r6) + std %r24,40 + 15*8(%r6) + stfd %f29,40 + 38*8(%r6) + std %r25,40 + 16*8(%r6) + stfd %f30,40 + 39*8(%r6) + std %r26,40 + 17*8(%r6) + stfd %f31,40 + 40*8(%r6) + std %r27,40 + 18*8(%r6) + std %r28,40 + 19*8(%r6) + std %r29,40 + 20*8(%r6) + std %r30,40 + 21*8(%r6) + std %r31,40 + 22*8(%r6) + + li %r3,0 + blr +END(sigsetjmp) + +ENTRY(siglongjmp) + ld %r9,40 + 0*8(%r3) + lfd %f14,40 + 23*8(%r3) + ld %r10,40 + 1*8(%r3) + lfd %f15,40 + 24*8(%r3) + ld %r11,40 + 2*8(%r3) + lfd %f16,40 + 25*8(%r3) + ld %r12,40 + 3*8(%r3) + lfd %f17,40 + 26*8(%r3) + ld %r14,40 + 5*8(%r3) + lfd %f18,40 + 27*8(%r3) + ld %r15,40 + 6*8(%r3) + lfd %f19,40 + 28*8(%r3) + ld %r16,40 + 7*8(%r3) + lfd %f20,40 + 29*8(%r3) + ld %r17,40 + 8*8(%r3) + lfd %f21,40 + 30*8(%r3) + ld %r18,40 + 9*8(%r3) + lfd %f22,40 + 31*8(%r3) + ld %r19,40 + 10*8(%r3) + lfd %f23,40 + 32*8(%r3) + ld %r20,40 + 11*8(%r3) + lfd %f24,40 + 33*8(%r3) + ld %r21,40 + 12*8(%r3) + lfd %f25,40 + 34*8(%r3) + ld %r22,40 + 13*8(%r3) + lfd %f26,40 + 35*8(%r3) + ld %r23,40 + 14*8(%r3) + lfd %f27,40 + 36*8(%r3) + ld %r24,40 + 15*8(%r3) + lfd %f28,40 + 37*8(%r3) + ld %r25,40 + 16*8(%r3) + lfd %f29,40 + 38*8(%r3) + ld %r26,40 + 17*8(%r3) + lfd %f30,40 + 39*8(%r3) + ld %r27,40 + 18*8(%r3) + lfd %f31,40 + 40*8(%r3) + ld %r28,40 + 19*8(%r3) + ld %r29,40 + 20*8(%r3) + ld %r30,40 + 21*8(%r3) + ld %r31,40 + 22*8(%r3) + + lwz %r7,0(%r3) + mr %r6,%r4 + mtlr %r11 + mtcr %r12 + mr %r2,%r9 + mr %r1,%r10 + or. %r7,%r7,%r7 + beq 1f + mr %r4,%r3 + li %r3,3 /* SIG_SETMASK */ + addi %r4,%r4,4 /* &set */ + li %r5,0 /* oset = NULL */ + li %r0,SYS_sigprocmask /* sigprocmask(SIG_SET, &set, NULL) */ + sc /* assume no error XXX */ +1: + or. %r3,%r6,%r6 + bnelr + li %r3,1 + blr +END(siglongjmp) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libc/powerpc64/gen/syncicache.c b/lib/libc/powerpc64/gen/syncicache.c new file mode 100644 index 000000000000..7885a36bd1d1 --- /dev/null +++ b/lib/libc/powerpc64/gen/syncicache.c @@ -0,0 +1,100 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (C) 1995-1997, 1999 Wolfgang Solfrank. + * Copyright (C) 1995-1997, 1999 TooLs GmbH. + * 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 TooLs GmbH. + * 4. The name of TooLs GmbH may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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. + * + * $NetBSD: syncicache.c,v 1.2 1999/05/05 12:36:40 tsubai Exp $ + */ + +#include <sys/param.h> +#if defined(_KERNEL) || defined(_STANDALONE) +#include <sys/time.h> +#include <sys/proc.h> +#include <vm/vm.h> +#endif +#include <sys/sysctl.h> + +#include <machine/cpu.h> +#include <machine/md_var.h> + +#ifdef _STANDALONE +int cacheline_size = 32; +#endif + +#if !defined(_KERNEL) && !defined(_STANDALONE) +#include <stdlib.h> + +int cacheline_size = 0; + +static void getcachelinesize(void); + +static void +getcachelinesize() +{ + static int cachemib[] = { CTL_MACHDEP, CPU_CACHELINE }; + long clen; + + clen = sizeof(cacheline_size); + + if (sysctl(cachemib, nitems(cachemib), &cacheline_size, &clen, + NULL, 0) < 0 || !cacheline_size) { + abort(); + } +} +#endif + +void +__syncicache(void *from, int len) +{ + off_t l, off; + char *p; + +#if !defined(_KERNEL) && !defined(_STANDALONE) + if (!cacheline_size) + getcachelinesize(); +#endif + + off = (uintptr_t)from & (cacheline_size - 1); + l = len += off; + p = (char *)from - off; + + do { + __asm __volatile ("dcbst 0,%0" :: "r"(p)); + p += cacheline_size; + } while ((l -= cacheline_size) > 0); + __asm __volatile ("sync"); + p = (char *)from - off; + do { + __asm __volatile ("icbi 0,%0" :: "r"(p)); + p += cacheline_size; + } while ((len -= cacheline_size) > 0); + __asm __volatile ("sync; isync"); +} + |