1*2fe8fb19SBen Gras /* $NetBSD: _lwp.c,v 1.4 2005/06/12 05:21:25 lukem Exp $ */ 2*2fe8fb19SBen Gras 3*2fe8fb19SBen Gras /* 4*2fe8fb19SBen Gras * Copyright (c) 2001 Wasabi Systems, Inc. 5*2fe8fb19SBen Gras * All rights reserved. 6*2fe8fb19SBen Gras * 7*2fe8fb19SBen Gras * Written by Jason R. Thorpe for Wasabi Systems, Inc. 8*2fe8fb19SBen Gras * 9*2fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without 10*2fe8fb19SBen Gras * modification, are permitted provided that the following conditions 11*2fe8fb19SBen Gras * are met: 12*2fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright 13*2fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer. 14*2fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 15*2fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer in the 16*2fe8fb19SBen Gras * documentation and/or other materials provided with the distribution. 17*2fe8fb19SBen Gras * 3. All advertising materials mentioning features or use of this software 18*2fe8fb19SBen Gras * must display the following acknowledgement: 19*2fe8fb19SBen Gras * This product includes software developed for the NetBSD Project by 20*2fe8fb19SBen Gras * Wasabi Systems, Inc. 21*2fe8fb19SBen Gras * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22*2fe8fb19SBen Gras * or promote products derived from this software without specific prior 23*2fe8fb19SBen Gras * written permission. 24*2fe8fb19SBen Gras * 25*2fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26*2fe8fb19SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27*2fe8fb19SBen Gras * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28*2fe8fb19SBen Gras * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29*2fe8fb19SBen Gras * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30*2fe8fb19SBen Gras * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31*2fe8fb19SBen Gras * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32*2fe8fb19SBen Gras * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33*2fe8fb19SBen Gras * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34*2fe8fb19SBen Gras * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35*2fe8fb19SBen Gras * POSSIBILITY OF SUCH DAMAGE. 36*2fe8fb19SBen Gras */ 37*2fe8fb19SBen Gras 38*2fe8fb19SBen Gras #include <sys/cdefs.h> 39*2fe8fb19SBen Gras #if defined(LIBC_SCCS) && !defined(lint) 40*2fe8fb19SBen Gras __RCSID("$NetBSD: _lwp.c,v 1.4 2005/06/12 05:21:25 lukem Exp $"); 41*2fe8fb19SBen Gras #endif /* LIBC_SCCS and not lint */ 42*2fe8fb19SBen Gras 43*2fe8fb19SBen Gras #include "namespace.h" 44*2fe8fb19SBen Gras #include <sys/types.h> 45*2fe8fb19SBen Gras #include <ucontext.h> 46*2fe8fb19SBen Gras #include <lwp.h> 47*2fe8fb19SBen Gras #include <stdlib.h> 48*2fe8fb19SBen Gras 49*2fe8fb19SBen Gras void 50*2fe8fb19SBen Gras _lwp_makecontext(ucontext_t *u, void (*start)(void *), 51*2fe8fb19SBen Gras void *arg, void *private, caddr_t stack_base, size_t stack_size) 52*2fe8fb19SBen Gras { 53*2fe8fb19SBen Gras void **sp; 54*2fe8fb19SBen Gras 55*2fe8fb19SBen Gras getcontext(u); 56*2fe8fb19SBen Gras u->uc_link = NULL; 57*2fe8fb19SBen Gras 58*2fe8fb19SBen Gras u->uc_stack.ss_sp = stack_base; 59*2fe8fb19SBen Gras u->uc_stack.ss_size = stack_size; 60*2fe8fb19SBen Gras 61*2fe8fb19SBen Gras sp = (void **) (stack_base + stack_size); 62*2fe8fb19SBen Gras 63*2fe8fb19SBen Gras /* 64*2fe8fb19SBen Gras * Note: We make sure the stack is 8-byte aligned, here. 65*2fe8fb19SBen Gras */ 66*2fe8fb19SBen Gras 67*2fe8fb19SBen Gras u->uc_mcontext.__gregs[_REG_R0] = (__greg_t) arg; 68*2fe8fb19SBen Gras u->uc_mcontext.__gregs[_REG_SP] = ((__greg_t) sp) & ~7; 69*2fe8fb19SBen Gras u->uc_mcontext.__gregs[_REG_LR] = (__greg_t) _lwp_exit; 70*2fe8fb19SBen Gras u->uc_mcontext.__gregs[_REG_PC] = (__greg_t) start; 71*2fe8fb19SBen Gras } 72