Add Changelog ...
[glibc.git] / sysdeps / unix / sysv / linux / tile / makecontext.c
blobe3f66bccb0f861e0235f306aee350a9cd7d9c1d3
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/>. */
19 #include <stdarg.h>
20 #include <stdio.h>
21 #include <stdint.h>
22 #include <stdlib.h>
23 #include <ucontext.h>
24 #include <arch/abi.h>
26 void
27 __makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
29 extern void __startcontext (void);
30 uint_reg_t *sp, *args;
31 va_list ap;
32 int i;
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. */
39 if (argc > 10)
40 sp -= 2 + (argc - 10);
42 sp[0] = sp[1] = 0;
44 /* Set parameters. */
45 va_start (ap, argc);
46 args = &ucp->uc_mcontext.gregs[0];
47 for (i = 0; i < argc; i++)
49 if (i == 10)
50 args = &sp[2];
51 *args++ = va_arg (ap, long);
53 va_end (ap);
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)