2 Copyright (C) 2002-2014 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
26 /* makecontext sets up a stack and the registers for the
27 user context. The stack looks like this:
29 +-----------------------+
30 | padding as required |
31 +-----------------------+
32 sp -> | parameter 7-n |
33 +-----------------------+
35 The registers are set up like this:
36 %x0 .. %x7: parameter 1 to 8
42 __makecontext (ucontext_t
*ucp
, void (*func
) (void), int argc
, ...)
44 extern void __startcontext (void);
45 unsigned long int *sp
;
49 sp
= (unsigned long int *)
50 ((uintptr_t) ucp
->uc_stack
.ss_sp
+ ucp
->uc_stack
.ss_size
);
52 /* Allocate stack arguments. */
53 sp
-= argc
< 8 ? 0 : argc
- 8;
55 /* Keep the stack aligned. */
56 sp
= (unsigned long int *) (((uintptr_t) sp
) & -16L);
58 ucp
->uc_mcontext
.regs
[19] = (uintptr_t) ucp
->uc_link
;
59 ucp
->uc_mcontext
.sp
= (uintptr_t) sp
;
60 ucp
->uc_mcontext
.pc
= (uintptr_t) func
;
61 ucp
->uc_mcontext
.regs
[29] = (uintptr_t) 0;
62 ucp
->uc_mcontext
.regs
[30] = (uintptr_t) &__startcontext
;
65 for (i
= 0; i
< argc
; ++i
)
67 ucp
->uc_mcontext
.regs
[i
] = va_arg (ap
, unsigned long int);
69 sp
[i
- 8] = va_arg (ap
, unsigned long int);
74 weak_alias (__makecontext
, makecontext
)