diff options
Diffstat (limited to 'lib/libc/sparc64/gen')
-rw-r--r-- | lib/libc/sparc64/gen/Makefile.inc | 7 | ||||
-rw-r--r-- | lib/libc/sparc64/gen/_ctx_start.S | 36 | ||||
-rw-r--r-- | lib/libc/sparc64/gen/_set_tp.c | 35 | ||||
-rw-r--r-- | lib/libc/sparc64/gen/_setjmp.S | 79 | ||||
-rw-r--r-- | lib/libc/sparc64/gen/assym.s | 18 | ||||
-rw-r--r-- | lib/libc/sparc64/gen/fabs.S | 35 | ||||
-rw-r--r-- | lib/libc/sparc64/gen/fixunsdfsi.S | 93 | ||||
-rw-r--r-- | lib/libc/sparc64/gen/flt_rounds.c | 26 | ||||
-rw-r--r-- | lib/libc/sparc64/gen/fpgetmask.c | 22 | ||||
-rw-r--r-- | lib/libc/sparc64/gen/fpgetround.c | 21 | ||||
-rw-r--r-- | lib/libc/sparc64/gen/fpgetsticky.c | 21 | ||||
-rw-r--r-- | lib/libc/sparc64/gen/fpsetmask.c | 28 | ||||
-rw-r--r-- | lib/libc/sparc64/gen/fpsetround.c | 30 | ||||
-rw-r--r-- | lib/libc/sparc64/gen/infinity.c | 17 | ||||
-rw-r--r-- | lib/libc/sparc64/gen/makecontext.c | 89 | ||||
-rw-r--r-- | lib/libc/sparc64/gen/setjmp.S | 88 | ||||
-rw-r--r-- | lib/libc/sparc64/gen/signalcontext.c | 77 | ||||
-rw-r--r-- | lib/libc/sparc64/gen/sigsetjmp.S | 56 |
18 files changed, 778 insertions, 0 deletions
diff --git a/lib/libc/sparc64/gen/Makefile.inc b/lib/libc/sparc64/gen/Makefile.inc new file mode 100644 index 000000000000..5442a33fdb18 --- /dev/null +++ b/lib/libc/sparc64/gen/Makefile.inc @@ -0,0 +1,7 @@ +# $FreeBSD$ + +SRCS+= _ctx_start.S _setjmp.S fabs.S fixunsdfsi.S flt_rounds.c fpgetmask.c \ + fpgetround.c fpgetsticky.c fpsetmask.c fpsetround.c \ + infinity.c ldexp.c makecontext.c \ + signalcontext.c setjmp.S sigsetjmp.S _set_tp.c \ + trivial-getcontextx.c diff --git a/lib/libc/sparc64/gen/_ctx_start.S b/lib/libc/sparc64/gen/_ctx_start.S new file mode 100644 index 000000000000..4ba3fd80624b --- /dev/null +++ b/lib/libc/sparc64/gen/_ctx_start.S @@ -0,0 +1,36 @@ +/*- + * Copyright (c) 2003 Jake Burkholder. + * 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> +__FBSDID("$FreeBSD$"); + +ENTRY(_ctx_start) + call %g1 + mov %g2, %l0 + call _ctx_done + mov %l0, %o0 + illtrap +END(_ctx_start) diff --git a/lib/libc/sparc64/gen/_set_tp.c b/lib/libc/sparc64/gen/_set_tp.c new file mode 100644 index 000000000000..7632951c4b8c --- /dev/null +++ b/lib/libc/sparc64/gen/_set_tp.c @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2004 Doug Rabson + * 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. + * + * $FreeBSD$ + */ +#include "libc_private.h" + +void +_set_tp(void *tpval) +{ + + __asm __volatile("mov %0, %%g7" : : "r" (tpval)); +} diff --git a/lib/libc/sparc64/gen/_setjmp.S b/lib/libc/sparc64/gen/_setjmp.S new file mode 100644 index 000000000000..724c2c0148c0 --- /dev/null +++ b/lib/libc/sparc64/gen/_setjmp.S @@ -0,0 +1,79 @@ +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: Header: _setjmp.s,v 1.1 91/07/06 16:45:53 torek Exp + */ + +#if defined(LIBC_SCCS) && !defined(lint) + .asciz "@(#)_setjmp.s 8.1 (Berkeley) 6/4/93" +#if 0 + RCSID("$NetBSD: _setjmp.S,v 1.4 1998/10/08 02:27:59 eeh Exp $") +#endif +#endif /* LIBC_SCCS and not lint */ +#include <machine/asm.h> +__FBSDID("$FreeBSD$"); + +#include "assym.s" + + .register %g2,#ignore + .register %g3,#ignore + +/* + * C library -- _setjmp, _longjmp + * + * _longjmp(a,v) + * will generate a "return(v?v:1)" from + * the last call to + * _setjmp(a) + * by restoring the previous context. + * The previous signal state is NOT restored. + */ + +ENTRY(_setjmp) + stx %sp, [%o0 + _JB_SP] + stx %o7, [%o0 + _JB_PC] + retl + clr %o0 +END(_setjmp) + + .weak CNAME(_longjmp) + .set CNAME(_longjmp),CNAME(___longjmp) +ENTRY(___longjmp) + save %sp, -CCFSZ, %sp + flushw + ldx [%i0 + _JB_SP], %fp + ldx [%i0 + _JB_PC], %i7 + mov 1, %i0 + movrnz %i1, %i1, %i0 + ret + restore +END(___longjmp) diff --git a/lib/libc/sparc64/gen/assym.s b/lib/libc/sparc64/gen/assym.s new file mode 100644 index 000000000000..7b205db2b690 --- /dev/null +++ b/lib/libc/sparc64/gen/assym.s @@ -0,0 +1,18 @@ +/* + * Offsets into into structures used from asm. Must be kept in sync with + * appropriate headers. + * + * $FreeBSD$ + */ + +#define _JB_FP 0x0 +#define _JB_PC 0x8 +#define _JB_SP 0x10 +#define _JB_SIGMASK 0x18 +#define _JB_SIGFLAG 0x28 + +#define SIG_BLOCK 1 +#define SIG_SETMASK 3 + +#define FSR_RD_MASK 0xc0000000 +#define FSR_RD_RD_Z 0x40000000 diff --git a/lib/libc/sparc64/gen/fabs.S b/lib/libc/sparc64/gen/fabs.S new file mode 100644 index 000000000000..bbc744af8a8b --- /dev/null +++ b/lib/libc/sparc64/gen/fabs.S @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2002 by Thomas Moestl <tmm@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 ``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> +__FBSDID("$FreeBSD$"); + +/* + * double fabs(double); + */ +ENTRY(fabs) + retl + fabsd %f0, %f0 +END(fabs) diff --git a/lib/libc/sparc64/gen/fixunsdfsi.S b/lib/libc/sparc64/gen/fixunsdfsi.S new file mode 100644 index 000000000000..77c3059b0103 --- /dev/null +++ b/lib/libc/sparc64/gen/fixunsdfsi.S @@ -0,0 +1,93 @@ +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: Header: fixunsdfsi.s,v 1.3 91/10/08 00:03:15 torek Exp + */ + +#include <machine/asm.h> + +#if defined(LIBC_SCCS) && !defined(lint) + .asciz "@(#)fixunsdfsi.s 8.1 (Berkeley) 6/4/93" +#if 0 + RCSID("$NetBSD: fixunsdfsi.S,v 1.3 2000/07/25 04:26:12 mycroft Exp $") +#endif +#endif /* LIBC_SCCS and not lint */ +__FBSDID("$FreeBSD$"); + +/* + * Convert double to unsigned integer (for gcc). + * + * I have made the output for NaN agree with the Sun compiler, not + * that it really matters, by using `fbul,a'. + */ + + + .align 8 +.Lbig: + .word 0x43e00000 ! .double 2^63 + .word 0 ! (who me, not trust the assembler?) + +/* + * Same as above but to unsigned long + */ +ENTRY(__dtoul) + PIC_PROLOGUE(%o4, %o5) + sub %sp, 16, %sp + std %f2, [%sp + CCFSZ + SPOFF + 8] + SET(.Lbig, %o5, %o3) + ldd [%o3], %f2 + fcmped %f0, %f2 ! d < 2^63, or NaN, or -Inf? + fbul,a 1f ! if so, use fdtox to convert to long + fdtox %f0, %f0 ! (this includes negatives!) + + ! d does not fit in a long, so subtract 2^63, convert, + ! and add 2^63 again (sigh). Just hope the intermediate + ! fits (if not, the result is undefined anyway). + + fsubd %f0, %f2, %f0 ! d -= 2^63 + fdtox %f0, %f0 ! convert to long + std %f0, [%sp + CCFSZ + SPOFF] ! move into return reg + ldx [%sp + CCFSZ + SPOFF], %o0 + sethi %hi(0x80000000), %o1 + sllx %o1, 32, %o1 + add %o0, %o1, %o0 ! add 2^63 + ldd [%sp + CCFSZ + SPOFF + 8], %f2 + retl + add %sp, 16, %sp + +1: + std %f0, [%sp + CCFSZ + SPOFF] ! return result + ldx [%sp + CCFSZ + SPOFF], %o0 + ldd [%sp + CCFSZ + SPOFF + 8], %f2 + retl + add %sp, 16, %sp +END(__dtoul) diff --git a/lib/libc/sparc64/gen/flt_rounds.c b/lib/libc/sparc64/gen/flt_rounds.c new file mode 100644 index 000000000000..706ef5a0dc6a --- /dev/null +++ b/lib/libc/sparc64/gen/flt_rounds.c @@ -0,0 +1,26 @@ +/* + * Written by J.T. Conklin, Apr 10, 1995 + * Public domain. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/types.h> +#include <machine/float.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() +{ + int x; + + __asm("st %%fsr,%0" : "=m" (*&x)); + return map[(x >> 30) & 0x03]; +} diff --git a/lib/libc/sparc64/gen/fpgetmask.c b/lib/libc/sparc64/gen/fpgetmask.c new file mode 100644 index 000000000000..05b151af0d10 --- /dev/null +++ b/lib/libc/sparc64/gen/fpgetmask.c @@ -0,0 +1,22 @@ +/* $NetBSD: fpgetmask.c,v 1.2 2002/01/13 21:45:50 thorpej Exp $ */ + +/* + * Written by J.T. Conklin, Apr 10, 1995 + * Public domain. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + + +#include <machine/fsr.h> +#include <ieeefp.h> + +fp_except_t +fpgetmask() +{ + unsigned int x; + + __asm__("st %%fsr,%0" : "=m" (x)); + return (FSR_GET_TEM(x)); +} diff --git a/lib/libc/sparc64/gen/fpgetround.c b/lib/libc/sparc64/gen/fpgetround.c new file mode 100644 index 000000000000..dbc90d728bd1 --- /dev/null +++ b/lib/libc/sparc64/gen/fpgetround.c @@ -0,0 +1,21 @@ +/* $NetBSD: fpgetround.c,v 1.2 2002/01/13 21:45:50 thorpej Exp $ */ + +/* + * Written by J.T. Conklin, Apr 10, 1995 + * Public domain. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <machine/fsr.h> +#include <ieeefp.h> + +fp_rnd_t +fpgetround() +{ + unsigned int x; + + __asm__("st %%fsr,%0" : "=m" (x)); + return ((fp_rnd_t)FSR_GET_RD(x)); +} diff --git a/lib/libc/sparc64/gen/fpgetsticky.c b/lib/libc/sparc64/gen/fpgetsticky.c new file mode 100644 index 000000000000..274566acd48a --- /dev/null +++ b/lib/libc/sparc64/gen/fpgetsticky.c @@ -0,0 +1,21 @@ +/* $NetBSD: fpgetsticky.c,v 1.2 2002/01/13 21:45:50 thorpej Exp $ */ + +/* + * Written by J.T. Conklin, Apr 10, 1995 + * Public domain. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <machine/fsr.h> +#include <ieeefp.h> + +fp_except_t +fpgetsticky() +{ + unsigned int x; + + __asm__("st %%fsr,%0" : "=m" (x)); + return (FSR_GET_AEXC(x)); +} diff --git a/lib/libc/sparc64/gen/fpsetmask.c b/lib/libc/sparc64/gen/fpsetmask.c new file mode 100644 index 000000000000..9aefb137837a --- /dev/null +++ b/lib/libc/sparc64/gen/fpsetmask.c @@ -0,0 +1,28 @@ +/* + * Written by J.T. Conklin, Apr 10, 1995 + * Public domain. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <machine/fsr.h> +#include <ieeefp.h> + +fp_except_t +fpsetmask(mask) + fp_except_t mask; +{ + fp_except_t old; + fp_except_t new; + + __asm__("st %%fsr,%0" : "=m" (old)); + + new = old; + new &= ~FSR_TEM_MASK; + new |= FSR_TEM(mask & FSR_EXC_MASK); + + __asm__("ld %0,%%fsr" : : "m" (new)); + + return (FSR_GET_TEM(old)); +} diff --git a/lib/libc/sparc64/gen/fpsetround.c b/lib/libc/sparc64/gen/fpsetround.c new file mode 100644 index 000000000000..1e27f596c16c --- /dev/null +++ b/lib/libc/sparc64/gen/fpsetround.c @@ -0,0 +1,30 @@ +/* $NetBSD: fpsetround.c,v 1.2 2002/01/13 21:45:51 thorpej Exp $ */ + +/* + * Written by J.T. Conklin, Apr 10, 1995 + * Public domain. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <machine/fsr.h> +#include <ieeefp.h> + +fp_rnd_t +fpsetround(rnd_dir) + fp_rnd_t rnd_dir; +{ + unsigned int old; + unsigned int new; + + __asm__("st %%fsr,%0" : "=m" (old)); + + new = old; + new &= ~FSR_RD_MASK; + new |= FSR_RD((unsigned int)rnd_dir & 0x03); + + __asm__("ld %0,%%fsr" : : "m" (new)); + + return ((fp_rnd_t)FSR_GET_RD(old)); +} diff --git a/lib/libc/sparc64/gen/infinity.c b/lib/libc/sparc64/gen/infinity.c new file mode 100644 index 000000000000..6d0d9344b190 --- /dev/null +++ b/lib/libc/sparc64/gen/infinity.c @@ -0,0 +1,17 @@ +#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 +__FBSDID("$FreeBSD$"); + +/* infinity.c */ + +#include <math.h> + +/* bytes for +Infinity on a sparc */ +const union __infinity_un __infinity = { { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 } }; + +/* bytes for NaN */ +const union __nan_un __nan = { { 0xff, 0xc0, 0, 0 } }; diff --git a/lib/libc/sparc64/gen/makecontext.c b/lib/libc/sparc64/gen/makecontext.c new file mode 100644 index 000000000000..42bcc8803060 --- /dev/null +++ b/lib/libc/sparc64/gen/makecontext.c @@ -0,0 +1,89 @@ +/*- + * Copyright (c) 2003 Jake Burkholder. + * 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> +__FBSDID("$FreeBSD$"); + +#include <sys/param.h> +#include <sys/signal.h> +#include <sys/ucontext.h> + +#include <machine/frame.h> +#include <machine/tstate.h> + +#include <errno.h> +#include <stdarg.h> +#include <stdlib.h> +#include <unistd.h> + +__weak_reference(__makecontext, makecontext); + +void _ctx_done(ucontext_t *ucp); +void _ctx_start(void); + +void +__makecontext(ucontext_t *ucp, void (*start)(void), int argc, ...) +{ + mcontext_t *mc; + uint64_t sp; + va_list ap; + int i; + + mc = &ucp->uc_mcontext; + if (ucp == NULL || + (mc->_mc_flags & ((1L << _MC_VERSION_BITS) - 1)) != _MC_VERSION) + return; + if ((argc < 0) || (argc > 6) || + (ucp->uc_stack.ss_sp == NULL) || + (ucp->uc_stack.ss_size < MINSIGSTKSZ)) { + mc->_mc_flags = 0; + return; + } + mc = &ucp->uc_mcontext; + sp = (uint64_t)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size; + va_start(ap, argc); + for (i = 0; i < argc; i++) + mc->mc_out[i] = va_arg(ap, uint64_t); + va_end(ap); + mc->mc_global[1] = (uint64_t)start; + mc->mc_global[2] = (uint64_t)ucp; + mc->mc_out[6] = sp - SPOFF - sizeof(struct frame); + mc->_mc_tnpc = (uint64_t)_ctx_start + 4; + mc->_mc_tpc = (uint64_t)_ctx_start; +} + +void +_ctx_done(ucontext_t *ucp) +{ + + if (ucp->uc_link == NULL) + exit(0); + else { + ucp->uc_mcontext._mc_flags = 0; + setcontext((const ucontext_t *)ucp->uc_link); + abort(); + } +} diff --git a/lib/libc/sparc64/gen/setjmp.S b/lib/libc/sparc64/gen/setjmp.S new file mode 100644 index 000000000000..8161b7ae48f9 --- /dev/null +++ b/lib/libc/sparc64/gen/setjmp.S @@ -0,0 +1,88 @@ +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: Header: _setjmp.s,v 1.1 91/07/06 16:45:53 torek Exp + */ + +#if defined(LIBC_SCCS) && !defined(lint) + .asciz "@(#)_setjmp.s 8.1 (Berkeley) 6/4/93" +#if 0 + RCSID("$NetBSD: _setjmp.S,v 1.4 1998/10/08 02:27:59 eeh Exp $") +#endif +#endif /* LIBC_SCCS and not lint */ +#include <machine/asm.h> +__FBSDID("$FreeBSD$"); + +#include "assym.s" + + .register %g2,#ignore + .register %g3,#ignore + +/* + * C library -- setjmp, longjmp + * + * longjmp(a,v) + * will generate a "return(v?v:1)" from + * the last call to + * setjmp(a) + * by restoring the previous context. + */ + +ENTRY(setjmp) + save %sp, -CCFSZ, %sp + mov SIG_BLOCK, %o0 + clr %o1 + call CNAME(sigprocmask) + add %i0, _JB_SIGMASK, %o2 + restore + stx %sp, [%o0 + _JB_SP] + stx %o7, [%o0 + _JB_PC] + retl + clr %o0 +END(setjmp) + + .weak CNAME(longjmp) + .set CNAME(longjmp),CNAME(__longjmp) +ENTRY(__longjmp) + save %sp, -CCFSZ, %sp + flushw + mov SIG_SETMASK, %o0 + add %i0, _JB_SIGMASK, %o1 + call CNAME(sigprocmask) + clr %o2 + ldx [%i0 + _JB_SP], %fp + ldx [%i0 + _JB_PC], %i7 + mov 1, %i0 + movrnz %i1, %i1, %i0 + ret + restore +END(__longjmp) diff --git a/lib/libc/sparc64/gen/signalcontext.c b/lib/libc/sparc64/gen/signalcontext.c new file mode 100644 index 000000000000..159184513807 --- /dev/null +++ b/lib/libc/sparc64/gen/signalcontext.c @@ -0,0 +1,77 @@ +/*- + * Copyright (c) 2003 Jake Burkholder. + * 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> +__FBSDID("$FreeBSD$"); + +#include <sys/param.h> +#include <sys/ucontext.h> + +#include <machine/frame.h> +#include <machine/sigframe.h> + +#include <errno.h> +#include <signal.h> +#include <stdarg.h> +#include <stdlib.h> +#include <strings.h> +#include <unistd.h> + +__weak_reference(__signalcontext, signalcontext); + +extern void _ctx_start(void); + +int +__signalcontext(ucontext_t *ucp, int sig, __sighandler_t *func) +{ + struct sigframe *sfp; + struct frame *fp; + mcontext_t *mc; + + mc = &ucp->uc_mcontext; + sfp = (struct sigframe *)(mc->_mc_sp + SPOFF) - 1; + fp = (struct frame *)sfp - 1; + + bzero(fp, sizeof(*fp)); + + bzero(sfp, sizeof(*sfp)); + bcopy(ucp, &sfp->sf_uc, sizeof(*ucp)); + sfp->sf_si.si_signo = sig; + + mc->mc_global[1] = (uint64_t)func; + mc->mc_global[2] = (uint64_t)ucp; + mc->mc_out[0] = sig; + mc->mc_out[1] = (uint64_t)&sfp->sf_si; + mc->mc_out[2] = (uint64_t)&sfp->sf_uc; + mc->mc_out[6] = (uint64_t)fp - SPOFF; + mc->_mc_tnpc = (uint64_t)_ctx_start + 4; + mc->_mc_tpc = (uint64_t)_ctx_start; + + ucp->uc_link = &sfp->sf_uc; + sigdelset(&ucp->uc_sigmask, sig); + + return (0); +} diff --git a/lib/libc/sparc64/gen/sigsetjmp.S b/lib/libc/sparc64/gen/sigsetjmp.S new file mode 100644 index 000000000000..4e4456648c66 --- /dev/null +++ b/lib/libc/sparc64/gen/sigsetjmp.S @@ -0,0 +1,56 @@ +/* + * Copyright (c) 1995 Paul Kranenburg + * 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 Paul Kranenburg. + * 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 <machine/asm.h> +__FBSDID("$FreeBSD$"); + +#include "assym.s" + +ENTRY(sigsetjmp) + PIC_PROLOGUE(%o3, %o2) + SET(CNAME(setjmp), %o2, %o3) + SET(CNAME(_setjmp), %o2, %o4) + movrnz %o1, %o3, %o4 + jmp %o4 + stx %o1, [%o0 + _JB_SIGFLAG] +END(sigsetjmp) + + .weak CNAME(siglongjmp); + .set CNAME(siglongjmp),CNAME(__siglongjmp); +ENTRY(__siglongjmp) + PIC_PROLOGUE(%o3, %o2) + SET(CNAME(longjmp), %o2, %o3) + SET(CNAME(_longjmp), %o2, %o4) + ldx [%o0 + _JB_SIGFLAG], %o2 + movrnz %o2, %o3, %o4 + jmp %o4 + nop +END(__siglongjmp) |