]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/ia64/makecontext.c
Update.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / ia64 / makecontext.c
1 /* Copyright (C) 2001 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
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 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20 #include <libintl.h>
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <ucontext.h>
25 #include <sys/rse.h>
26
27
28 struct fdesc
29 {
30 unsigned long ip;
31 unsigned long gp;
32 };
33
34 #define PUSH(val) \
35 do { \
36 if (ia64_rse_is_rnat_slot (rbs)) \
37 *rbs++ = 0; \
38 *rbs++ = (val); \
39 } while (0)
40
41
42 /* This implementation can handle an ARGC value of at most 8 and
43 values can be passed only in integer registers (r32-r39). */
44
45 void
46 __makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
47 {
48 struct sigcontext *sc = &ucp->uc_mcontext;
49 extern void __start_context (ucontext_t *link, long gp, ...);
50 unsigned long stack_start, stack_end;
51 va_list ap;
52 long *rbs;
53 int i;
54
55 stack_start = (long) sc->sc_stack.ss_sp;
56 stack_end = (long) sc->sc_stack.ss_sp + sc->sc_stack.ss_size;
57
58 stack_start = (stack_start + 7) & -8;
59 stack_end = (stack_start + 15) & -16;
60
61 if (argc > 8)
62 {
63 fprintf (stderr, _("\
64 makecontext: does not know how to handle more than 8 arguments\n"));
65 exit (-1);
66 }
67
68 /* set the entry point and global pointer: */
69 sc->sc_br[0] = ((struct fdesc *) &__start_context)->ip;
70 sc->sc_br[1] = ((struct fdesc *) func)->ip;
71 sc->sc_gr[1] = ((struct fdesc *) func)->gp;
72
73 /* set up the call frame: */
74 sc->sc_ar_pfs = ((sc->sc_ar_pfs & ~0x3fffffffffUL)
75 | (argc + 2) | ((argc + 2) << 7));
76 rbs = (long *) stack_start;
77 PUSH((long) ucp->uc_link);
78 PUSH(((struct fdesc *) &__start_context)->gp);
79 va_start (ap, argc);
80 for (i = 0; i < argc; ++i)
81 PUSH(va_arg (ap, long));
82 va_end (ap);
83
84 /* set the memory and register stack pointers: */
85 sc->sc_ar_bsp = (long) rbs;
86 sc->sc_gr[12] = stack_end - 16;
87
88 /* clear the NaT bits for r1 and r12: */
89 sc->sc_nat &= ~((1 << 1) | (1 << 12));
90 sc->sc_ar_rnat = 0;
91 }
92
93 weak_alias (__makecontext, makecontext)