sparc64: add basic support
[uclibc-ng.git] / libc / sysdeps / linux / sparc64 / makecontext.c
blob3750f012cf60904ddd753ee5892659e0bf48b354
1 /* Copyright (C) 2001-2017 Free Software Foundation, Inc.
2 Contributed by Jakub Jelinek <jakub@redhat.com>.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
18 #include <stdarg.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <ucontext.h>
23 extern void __start_context (struct ucontext *ucp);
25 void
26 __makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
28 extern void __makecontext_ret (void);
29 unsigned long *sp, *topsp;
30 va_list ap;
31 int i;
33 sp = (unsigned long *) ((long) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
34 sp -= (argc > 6 ? argc : 6) + 32;
35 sp = (unsigned long *) (((long) sp) & -16L);
36 topsp = sp + (argc > 6 ? argc : 6) + 16;
38 ucp->uc_mcontext.mc_gregs[MC_PC] = (long) func;
39 ucp->uc_mcontext.mc_gregs[MC_NPC] = ((long) func) + 4;
40 ucp->uc_mcontext.mc_gregs[MC_O6] = ((long) sp) - 0x7ff;
41 ucp->uc_mcontext.mc_gregs[MC_O7] = ((long) __start_context) - 8;
42 ucp->uc_mcontext.mc_fp = ((long) topsp) - 0x7ff;
43 ucp->uc_mcontext.mc_i7 = 0;
44 topsp[14] = 0;
45 topsp[15] = 0;
46 sp[8] = (long) ucp->uc_link;
47 va_start (ap, argc);
48 for (i = 0; i < argc; ++i)
49 if (i < 6)
50 ucp->uc_mcontext.mc_gregs[MC_O0 + i] = va_arg (ap, long);
51 else
52 sp[16 + i] = va_arg (ap, long);
53 va_end (ap);
56 weak_alias (__makecontext, makecontext)