Update copyright notices with scripts/update-copyrights
[glibc.git] / ports / sysdeps / unix / sysv / linux / ia64 / makecontext.c
blob67ba3e0d6cb12978f1b59944109ca6525c46c280
1 /* Copyright (C) 2001-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.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, see
17 <http://www.gnu.org/licenses/>. */
19 #include <libintl.h>
20 #include <stdarg.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <ucontext.h>
24 #include <sys/rse.h>
25 #include <link.h>
26 #include <dl-fptr.h>
29 #define PUSH(val) \
30 do { \
31 if (ia64_rse_is_rnat_slot (rbs)) \
32 *rbs++ = 0; \
33 *rbs++ = (val); \
34 } while (0)
37 /* This implementation can handle an ARGC value of at most 8 and
38 values can be passed only in integer registers (r32-r39). */
40 void
41 __makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
43 struct sigcontext *sc = &ucp->uc_mcontext;
44 extern void __start_context (ucontext_t *link, long gp, ...);
45 unsigned long stack_start, stack_end;
46 va_list ap;
47 unsigned long *rbs;
48 int i;
50 stack_start = (long) sc->sc_stack.ss_sp;
51 stack_end = (long) sc->sc_stack.ss_sp + sc->sc_stack.ss_size;
53 stack_start = (stack_start + 7) & -8;
54 stack_end = stack_end & -16;
56 if (argc > 8)
58 fprintf (stderr, _("\
59 makecontext: does not know how to handle more than 8 arguments\n"));
60 exit (-1);
63 /* set the entry point and global pointer: */
64 sc->sc_br[0] = ELF_PTR_TO_FDESC (&__start_context)->ip;
65 sc->sc_br[1] = ELF_PTR_TO_FDESC (func)->ip;
66 sc->sc_gr[1] = ELF_PTR_TO_FDESC (func)->gp;
68 /* set up the call frame: */
69 sc->sc_ar_pfs = ((sc->sc_ar_pfs & ~0x3fffffffffUL)
70 | (argc + 2) | ((argc + 2) << 7));
71 rbs = (unsigned long *) stack_start;
72 PUSH((long) ucp->uc_link);
73 PUSH(ELF_PTR_TO_FDESC (&__start_context)->gp);
74 va_start (ap, argc);
75 for (i = 0; i < argc; ++i)
76 PUSH(va_arg (ap, long));
77 va_end (ap);
79 /* set the memory and register stack pointers: */
80 sc->sc_ar_bsp = (long) rbs;
81 sc->sc_gr[12] = stack_end - 16;
83 /* clear the NaT bits for r1 and r12: */
84 sc->sc_nat &= ~((1 << 1) | (1 << 12));
85 sc->sc_ar_rnat = 0;
88 weak_alias (__makecontext, makecontext)