Add ucontext glue for x86_64.

This commit is contained in:
fvdl 2003-01-30 02:07:30 +00:00
parent aa0d12cace
commit 894bd3ad9d
7 changed files with 388 additions and 4 deletions

View File

@ -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) # 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 \ SRCS+= alloca.S bswap64.S byte_swap_2.S byte_swap_4.S fabs.S modf.S \
@ -9,8 +9,10 @@ SRCS+= __setjmp14.S
SRCS+= _setjmp.S SRCS+= _setjmp.S
SRCS+= __sigsetjmp14.S SRCS+= __sigsetjmp14.S
SRCS+= resumecontext.S swapcontext.S
# objects built from C sources # objects built from C sources
SRCS+= ldexp.c SRCS+= ldexp.c _lwp.c makecontext.c
# Common ieee754 constants and functions # Common ieee754 constants and functions
SRCS+= ieee754_infinity.c ieee754_nanf.c SRCS+= ieee754_infinity.c ieee754_nanf.c

View File

@ -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 */
}

View File

@ -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.
*
*/
#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);
}

View File

@ -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
*/
#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 */

View File

@ -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
* or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC
* 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>
#if defined(LIBC_SCCS) && !defined(lint)
RCSID("$NetBSD: swapcontext.S,v 1.1 2003/01/30 02:07:31 fvdl Exp $")
#endif /* LIBC_SCCS && !lint */
/*
* 56 == offsetof(ucontext_t, uc_mcontext)
* 21 == _REG_RIP
* 24 == _REG_URSP
*/
ENTRY(swapcontext)
pushq %r12
pushq %r13
movq %rdi,%r12 /* preserve oucp */
movq %rsi,%r13 /* preserve ucp */
#ifdef PIC
call PIC_PLT(_C_LABEL(getcontext))
#else
call _C_LABEL(getcontext)
#endif
testl %eax,%eax
jnz 2f
movq (%rsp),%r11
movq %r11,(56 + 21 * 8)(%r12)
leaq 8(%rsp),%r11
movq %r11,(56 + 24 * 8)(%r12)
movq %r13,%rdi
#ifdef PIC
call PIC_PLT(_C_LABEL(setcontext))
#else
call _C_LABEL(setcontext)
#endif
2:
popq %r13
popq %r12
ret

View File

@ -1,4 +1,4 @@
/* $NetBSD: __sigaction14_sigtramp.c,v 1.1 2002/07/09 23:32:39 thorpej Exp $ */ /* $NetBSD: __sigaction14_sigtramp.c,v 1.2 2003/01/30 02:07:32 fvdl Exp $ */
/*- /*-
* Copyright (c) 2002 The NetBSD Foundation, Inc. * Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -43,8 +43,10 @@
#include "extern.h" #include "extern.h"
__weak_alias(__sigaction14, __libc_sigaction14)
int int
__sigaction14(int sig, const struct sigaction *act, struct sigaction *oact) __libc_sigaction14(int sig, const struct sigaction *act, struct sigaction *oact)
{ {
extern int __sigtramp_sigcontext_1[]; extern int __sigtramp_sigcontext_1[];

View File

@ -0,0 +1,63 @@
/* $NetBSD: getcontext.S,v 1.1 2003/01/30 02:07:32 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
* or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "SYS.h"
#if defined(SYSLIBC_SCCS) && !defined(lint)
RCSID("$NetBSD: getcontext.S,v 1.1 2003/01/30 02:07:32 fvdl Exp $")
#endif
#ifdef WEAK_ALIAS
WEAK_ALIAS(getcontext, _getcontext)
#endif
/*
* 56 == offsetof(ucontext_t, uc_mcontext)
* 14 == _REG_RAX
* 21 == _REG_RIP
* 24 == _REG_URSP
*/
_SYSCALL(_getcontext,getcontext)
movq (%rsp),%r11
movq %r11,(56 + 21 * 8)(%rdi)
leaq 8(%rsp),%r11
movq %r11,(56 + 24 * 8)(%rdi)
movq $0,(56 + 14 * 8)(%rdi)
xorl %eax,%eax
ret