1 /* Copyright (C) 2012 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
21 /* Number of arguments that go in registers. */
24 /* Take a context previously prepared via getcontext() and set to
25 call func() with the given int only args. */
27 __makecontext (ucontext_t
*ucp
, void (*func
) (void), int argc
, ...)
29 extern void __startcontext (void);
30 unsigned long *funcstack
;
32 unsigned long *regptr
;
36 /* Start at the top of stack. */
37 funcstack
= (unsigned long *) (ucp
->uc_stack
.ss_sp
+ ucp
->uc_stack
.ss_size
);
39 /* Ensure the stack stays eight byte aligned. */
40 misaligned
= ((unsigned long) funcstack
& 4) != 0;
42 if ((argc
> NREG_ARGS
) && (argc
& 1) != 0)
43 misaligned
= !misaligned
;
50 /* Reserve space for the on-stack arguments. */
52 funcstack
-= (argc
- NREG_ARGS
);
54 ucp
->uc_mcontext
.arm_sp
= (unsigned long) funcstack
;
55 ucp
->uc_mcontext
.arm_pc
= (unsigned long) func
;
57 /* Exit to startcontext() with the next context in R4 */
58 ucp
->uc_mcontext
.arm_r4
= (unsigned long) ucp
->uc_link
;
59 ucp
->uc_mcontext
.arm_lr
= (unsigned long) __startcontext
;
61 /* The first four arguments go into registers. */
62 regptr
= &(ucp
->uc_mcontext
.arm_r0
);
64 for (reg
= 0; (reg
< argc
) && (reg
< NREG_ARGS
); reg
++)
65 *regptr
++ = va_arg (vl
, unsigned long);
67 /* And the remainder on the stack. */
68 for (; reg
< argc
; reg
++)
69 *funcstack
++ = va_arg (vl
, unsigned long);
73 weak_alias (__makecontext
, makecontext
)