1 /* Copyright (C) 2001 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 /* This implementation can handle any ARGC value but only
27 normal integer type parameters. Parameters of type float,
28 double, complex and structure with sizes 0, 2, 4 or 8
30 makecontext sets up a stack and the registers for the
31 user context. The stack looks like this:
33 %r15 -> +-----------------------+
34 8 | back chain (zero) | 0
36 144 | save area for (*func) | 16
37 +-----------------------+
38 n | overflow parameters | 160
39 +-----------------------+
40 The registers are set up like this:
41 %r2-%r6: parameters 1 to 5
43 %r8 : uc_link from ucontext structure
44 %r9 : address of setcontext
45 %r14 : return address to uc_link trampoline
48 The trampoline looks like this:
54 __makecontext (ucontext_t
*ucp
, void (*func
) (void), int argc
, ...)
56 extern void __makecontext_ret (void);
61 sp
= (unsigned long *) (((unsigned long) ucp
->uc_stack
.ss_sp
62 + ucp
->uc_stack
.ss_size
) & -8L);
64 /* Set the return address to trampoline. */
65 ucp
->uc_mcontext
.gregs
[14] = (long) __makecontext_ret
;
67 /* Set register parameters. */
69 for (i
= 0; (i
< argc
) && (i
< 5); i
++)
70 ucp
->uc_mcontext
.gregs
[2+i
] = va_arg (ap
, long);
72 /* The remaining arguments go to the overflow area. */
75 for (i
= 5; i
< argc
; i
++)
76 sp
[i
] = va_arg(ap
, long);
80 /* Make room for the save area and set the backchain. */
84 /* Pass (*func) to __start_context in %r7. */
85 ucp
->uc_mcontext
.gregs
[7] = (long) func
;
87 /* Pass ucp->uc_link to __start_context in %r8. */
88 ucp
->uc_mcontext
.gregs
[8] = (long) ucp
->uc_link
;
90 /* Pass address of setcontext in %r9. */
91 ucp
->uc_mcontext
.gregs
[9] = (long) &setcontext
;
93 /* Set stack pointer. */
94 ucp
->uc_mcontext
.gregs
[15] = (long) sp
;
98 ".type __makecontext_ret,@function\n"
99 "__makecontext_ret:\n"
103 ".size __makecontext_ret, .-__makecontext_ret");
105 weak_alias (__makecontext
, makecontext
)