]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/sparc/sparc64/makecontext.c
Update.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / sparc / sparc64 / makecontext.c
1 /* Copyright (C) 2001 Free Software Foundation, Inc.
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
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 <stdarg.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <ucontext.h>
24
25 void
26 __makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
27 {
28 extern void __makecontext_ret (void);
29 unsigned long *sp, *topsp;
30 va_list ap;
31 int i;
32
33 sp = (long *) ((long) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
34 sp -= (argc > 6 ? argc : 6) + 32;
35 sp = (long *) (((long) sp) & -16L);
36 topsp = sp + (argc > 6 ? argc : 6) + 16;
37
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) __makecontext_ret) - 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);
54 }
55
56 asm (" \n\
57 .text \n\
58 .type __makecontext_ret, #function \n\
59 __makecontext_ret: \n\
60 mov 1, %o1 \n\
61 call __setcontext \n\
62 mov %i0, %o0 \n\
63 unimp 0 \n\
64 .size __makecontext_ret, .-__makecontext_ret \n\
65 ");
66
67 weak_alias (__makecontext, makecontext)