Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/arch/x86_64 Add ucontext glue for x86_64.



details:   https://anonhg.NetBSD.org/src/rev/3ab2286e2a20
branches:  trunk
changeset: 542470:3ab2286e2a20
user:      fvdl <fvdl%NetBSD.org@localhost>
date:      Thu Jan 30 02:07:30 2003 +0000

description:
Add ucontext glue for x86_64.

diffstat:

 lib/libc/arch/x86_64/gen/Makefile.inc             |    6 +-
 lib/libc/arch/x86_64/gen/_lwp.c                   |   70 ++++++++++++++
 lib/libc/arch/x86_64/gen/makecontext.c            |  104 ++++++++++++++++++++++
 lib/libc/arch/x86_64/gen/resumecontext.S          |   68 ++++++++++++++
 lib/libc/arch/x86_64/gen/swapcontext.S            |   75 +++++++++++++++
 lib/libc/arch/x86_64/sys/__sigaction14_sigtramp.c |    6 +-
 lib/libc/arch/x86_64/sys/getcontext.S             |   63 +++++++++++++
 7 files changed, 388 insertions(+), 4 deletions(-)

diffs (truncated from 442 to 300 lines):

diff -r 91fa996e5bbe -r 3ab2286e2a20 lib/libc/arch/x86_64/gen/Makefile.inc
--- a/lib/libc/arch/x86_64/gen/Makefile.inc     Thu Jan 30 02:04:59 2003 +0000
+++ b/lib/libc/arch/x86_64/gen/Makefile.inc     Thu Jan 30 02:07:30 2003 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.2 2002/02/19 13:08:35 simonb Exp $
+#      $NetBSD: Makefile.inc,v 1.3 2003/01/30 02:07:30 fvdl Exp $
 
 # objects built from assembler sources (need lint stubs)
 SRCS+= alloca.S bswap64.S byte_swap_2.S byte_swap_4.S fabs.S modf.S \
@@ -9,8 +9,10 @@
 SRCS+= _setjmp.S
 SRCS+= __sigsetjmp14.S
 
+SRCS+= resumecontext.S swapcontext.S
+
 # objects built from C sources
-SRCS+= ldexp.c
+SRCS+= ldexp.c _lwp.c makecontext.c
 
 # Common ieee754 constants and functions
 SRCS+= ieee754_infinity.c ieee754_nanf.c
diff -r 91fa996e5bbe -r 3ab2286e2a20 lib/libc/arch/x86_64/gen/_lwp.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/arch/x86_64/gen/_lwp.c   Thu Jan 30 02:07:30 2003 +0000
@@ -0,0 +1,70 @@
+/*     $NetBSD: _lwp.c,v 1.1 2003/01/30 02:07:30 fvdl Exp $    */
+
+/*-
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Nathan J. Williams.
+ *
+ * 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 the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation 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 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 <inttypes.h>
+#include <ucontext.h>
+#include <lwp.h>
+#include <stdlib.h>
+
+void
+_lwp_makecontext(ucontext_t *u, void (*start)(void *),
+    void *arg, void *private, caddr_t stack_base, size_t stack_size)
+{
+       void **sp;
+
+       getcontext(u);
+       u->uc_link = NULL;
+
+       u->uc_stack.ss_sp = stack_base;
+       u->uc_stack.ss_size = stack_size;
+
+       /* LINTED uintptr_t is safe */
+       u->uc_mcontext.__gregs[_REG_RIP] = (uintptr_t)start;
+       
+       sp = (void **) (((uintptr_t)(stack_base + stack_size) & ~15) - 8);
+
+       /* LINTED __greg_t is safe */
+       u->uc_mcontext.__gregs[_REG_RDI] = (__greg_t)arg;
+       *--sp = (void *) _lwp_exit;
+       
+       /* LINTED uintptr_t is safe */
+       u->uc_mcontext.__gregs[_REG_URSP] = (uintptr_t) sp;
+
+       /* LINTED private is currently unused */
+}
diff -r 91fa996e5bbe -r 3ab2286e2a20 lib/libc/arch/x86_64/gen/makecontext.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/arch/x86_64/gen/makecontext.c    Thu Jan 30 02:07:30 2003 +0000
@@ -0,0 +1,104 @@
+/*     $NetBSD: makecontext.c,v 1.1 2003/01/30 02:07:31 fvdl Exp $     */
+
+/*-
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Klaus Klein.
+ *
+ * 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 the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation 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 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.
+ *
+ * Modified from the i386 version for x86_64 by fvdl%wasabisystems.com@localhost.
+ *
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: makecontext.c,v 1.1 2003/01/30 02:07:31 fvdl Exp $");
+#endif
+
+#include <inttypes.h>
+#include <stddef.h>
+#include <ucontext.h>
+#include "extern.h"
+
+#include <stdarg.h>
+
+void
+makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
+{
+       __greg_t *gr = ucp->uc_mcontext.__gregs;
+       uintptr_t *sp;
+       va_list ap;
+       int stackargs, i;
+
+       stackargs = argc - 6;
+
+       /* LINTED __greg_t is safe */
+       gr[_REG_RIP] = (__greg_t)func;
+
+       /* LINTED uintptr_t is safe */
+       sp  = (uintptr_t *)
+           ((uintptr_t)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
+
+       /* LINTED uintptr_t is safe */
+       sp  = (uintptr_t *)(((uintptr_t)sp & ~15) - 8);
+       sp--;
+       if (stackargs > 0)
+               sp -= stackargs;
+       /* LINTED __greg_t is safe */
+       gr[_REG_URSP] = (__greg_t)sp;
+       gr[_REG_RBP] = (__greg_t)0;     /* Wipe out frame pointer. */
+
+       /* Put return address on top of stack. */
+       /* LINTED uintptr_t is safe */
+       *sp++ = (uintptr_t)_resumecontext;
+
+       /*
+        * Construct argument list.
+        * The registers used to pass the first 6 arguments
+        * (rdi, rsi, rdx, rcx, r8, r9) are the first 6 in gregs,
+        * in that order, so those arguments can just be copied to
+        * the gregs array.
+        */
+       va_start(ap, argc);
+       for (i = 0; i < 6 && argc > 0; i++) {
+               argc--;
+               /* LINTED __greg_t is safe */
+               gr[i] = va_arg(ap, __greg_t);
+       }
+
+       while (stackargs-- > 0) {
+               /* LINTED uintptr_t is safe */
+               *sp++ = va_arg(ap, uintptr_t);
+       }
+
+       va_end(ap);
+}
diff -r 91fa996e5bbe -r 3ab2286e2a20 lib/libc/arch/x86_64/gen/resumecontext.S
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/arch/x86_64/gen/resumecontext.S  Thu Jan 30 02:07:30 2003 +0000
@@ -0,0 +1,68 @@
+/*     $NetBSD: resumecontext.S,v 1.1 2003/01/30 02:07:31 fvdl Exp $   */
+
+/*-
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Klaus Klein.
+ *
+ * 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 the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation 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 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.
+ *
+ * Modified for x86-64 by fvdl%wasabisystems.com@localhost
+ */
+
+#include <machine/asm.h>
+
+#if defined(LIBC_SCCS) && !defined(lint)
+       RCSID("$NetBSD: resumecontext.S,v 1.1 2003/01/30 02:07:31 fvdl Exp $")
+#endif /* LIBC_SCCS && !lint */
+
+/*
+ * This assembly-language implementation differs from the (obvious)
+ * C-language implementation only in not clobbering the previous
+ * function's return address (us), which is the point of the exercise.
+ */
+
+NENTRY(_resumecontext) /* profiling prologue would clobber TOS */
+       leaq    -(8 + 784)(%rsp),%rdi   /* retaddr + sizeof (ucontext_t) */
+       andq    $~15,%rdi               /* align on _UC_UCONTEXT_ALIGN */
+       movq    %rdi,%rsp
+#ifdef PIC
+       call    PIC_PLT(_C_LABEL(_getcontext))
+#else
+       call    _C_LABEL(_getcontext)
+#endif
+       movq    4(%rsp),%rdi
+#ifdef PIC
+       call    PIC_PLT(_C_LABEL(setcontext))
+#else
+       call    _C_LABEL(setcontext)
+#endif
+       /* NOTREACHED */
diff -r 91fa996e5bbe -r 3ab2286e2a20 lib/libc/arch/x86_64/gen/swapcontext.S
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/arch/x86_64/gen/swapcontext.S    Thu Jan 30 02:07:30 2003 +0000
@@ -0,0 +1,75 @@
+/*     $NetBSD: swapcontext.S,v 1.1 2003/01/30 02:07:31 fvdl Exp $     */
+
+/*
+ * Copyright (c) 2003 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Frank van der Linden for Wasabi Systems, Inc.
+ *
+ * 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 for the NetBSD Project by
+ *      Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse



Home | Main Index | Thread Index | Old Index