1 /* Copyright (C) 2011 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <http://www.gnu.org/licenses/>. */
27 __makecontext (ucontext_t
*ucp
, void (*func
) (void), int argc
, ...)
29 extern void __startcontext (void);
30 uint_reg_t
*sp
, *args
;
34 /* Initialize the top of stack. */
35 sp
= (uint_reg_t
*) ((((intptr_t) ucp
->uc_stack
.ss_sp
36 + ucp
->uc_stack
.ss_size
) & -16L) - 16);
38 /* Allow room for memory-passed arguments if necessary. */
40 sp
-= 2 + (argc
- 10);
46 args
= &ucp
->uc_mcontext
.gregs
[0];
47 for (i
= 0; i
< argc
; i
++)
51 *args
++ = va_arg (ap
, long);
55 /* Pass (*func) to __startcontext in pc. */
56 ucp
->uc_mcontext
.pc
= (long) func
;
58 /* Set stack pointer. */
59 ucp
->uc_mcontext
.sp
= (long) sp
;
61 /* Set the return address to trampoline. */
62 ucp
->uc_mcontext
.lr
= (long) __startcontext
;
64 /* Pass ucp->uc_link to __start_context in r30. */
65 ucp
->uc_mcontext
.gregs
[30] = (long) ucp
->uc_link
;
67 weak_alias (__makecontext
, makecontext
)