]>
Commit | Line | Data |
---|---|---|
b168057a | 1 | /* Copyright (C) 2001-2015 Free Software Foundation, Inc. |
9bab9806 UD |
2 | This file is part of the GNU C Library. |
3 | Contributed by Jakub Jelinek <jakub@redhat.com>. | |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
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. | |
9bab9806 UD |
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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
9bab9806 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
9bab9806 UD |
18 | |
19 | #include <stdarg.h> | |
20 | #include <stdio.h> | |
21 | #include <stdlib.h> | |
22 | #include <ucontext.h> | |
23 | ||
60e8270d DM |
24 | extern void __start_context (struct ucontext *ucp); |
25 | ||
9bab9806 UD |
26 | void |
27 | __makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...) | |
28 | { | |
29 | extern void __makecontext_ret (void); | |
30 | unsigned long *sp, *topsp; | |
31 | va_list ap; | |
32 | int i; | |
33 | ||
a1bcbd40 | 34 | sp = (unsigned long *) ((long) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size); |
9bab9806 | 35 | sp -= (argc > 6 ? argc : 6) + 32; |
a1bcbd40 | 36 | sp = (unsigned long *) (((long) sp) & -16L); |
9bab9806 UD |
37 | topsp = sp + (argc > 6 ? argc : 6) + 16; |
38 | ||
39 | ucp->uc_mcontext.mc_gregs[MC_PC] = (long) func; | |
40 | ucp->uc_mcontext.mc_gregs[MC_NPC] = ((long) func) + 4; | |
41 | ucp->uc_mcontext.mc_gregs[MC_O6] = ((long) sp) - 0x7ff; | |
60e8270d | 42 | ucp->uc_mcontext.mc_gregs[MC_O7] = ((long) __start_context) - 8; |
9bab9806 UD |
43 | ucp->uc_mcontext.mc_fp = ((long) topsp) - 0x7ff; |
44 | ucp->uc_mcontext.mc_i7 = 0; | |
45 | topsp[14] = 0; | |
46 | topsp[15] = 0; | |
47 | sp[8] = (long) ucp->uc_link; | |
48 | va_start (ap, argc); | |
49 | for (i = 0; i < argc; ++i) | |
50 | if (i < 6) | |
51 | ucp->uc_mcontext.mc_gregs[MC_O0 + i] = va_arg (ap, long); | |
52 | else | |
53 | sp[16 + i] = va_arg (ap, long); | |
54 | va_end (ap); | |
55 | } | |
56 | ||
9bab9806 | 57 | weak_alias (__makecontext, makecontext) |