summaryrefslogtreecommitdiffstats
path: root/lib/libc/sparc64
diff options
context:
space:
mode:
authorjake <jake@FreeBSD.org>2003-04-01 23:28:50 +0000
committerjake <jake@FreeBSD.org>2003-04-01 23:28:50 +0000
commitde291c89d2f7d81c90afea79c2e84112fbadbf86 (patch)
tree7a9b8d4231d0246a36d25af0440cefe8c4b6b832 /lib/libc/sparc64
parentac9bc07ca9180456780c4e82536485b56171bc92 (diff)
downloadFreeBSD-src-de291c89d2f7d81c90afea79c2e84112fbadbf86.zip
FreeBSD-src-de291c89d2f7d81c90afea79c2e84112fbadbf86.tar.gz
Implement makecontext.
Diffstat (limited to 'lib/libc/sparc64')
-rw-r--r--lib/libc/sparc64/gen/Makefile.inc7
-rw-r--r--lib/libc/sparc64/gen/_ctx_start.S36
-rw-r--r--lib/libc/sparc64/gen/makecontext.c89
3 files changed, 129 insertions, 3 deletions
diff --git a/lib/libc/sparc64/gen/Makefile.inc b/lib/libc/sparc64/gen/Makefile.inc
index 9024d28..85ecfbd 100644
--- a/lib/libc/sparc64/gen/Makefile.inc
+++ b/lib/libc/sparc64/gen/Makefile.inc
@@ -1,5 +1,6 @@
# $FreeBSD$
-SRCS+= _setjmp.S fabs.S fixunsdfsi.S flt_rounds.c fpgetmask.c fpgetround.c \
- fpgetsticky.c fpsetmask.c fpsetround.c fpsetsticky.c frexp.c \
- infinity.c isinf.c ldexp.c modf.S setjmp.S sigsetjmp.S
+SRCS+= _ctx_start.S _setjmp.S fabs.S fixunsdfsi.S flt_rounds.c fpgetmask.c \
+ fpgetround.c fpgetsticky.c fpsetmask.c fpsetround.c fpsetsticky.c \
+ frexp.c infinity.c isinf.c ldexp.c makecontext.c modf.S setjmp.S \
+ sigsetjmp.S
diff --git a/lib/libc/sparc64/gen/_ctx_start.S b/lib/libc/sparc64/gen/_ctx_start.S
new file mode 100644
index 0000000..4ba3fd8
--- /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/makecontext.c b/lib/libc/sparc64/gen/makecontext.c
new file mode 100644
index 0000000..95795de
--- /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();
+ }
+}
OpenPOWER on IntegriCloud