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