Blame


1 41b3e8b9 2020-01-20 rsc /* Copyright (C) 2001 Free Software Foundation, Inc.
2 41b3e8b9 2020-01-20 rsc This file is part of the GNU C Library.
3 41b3e8b9 2020-01-20 rsc Contributed by Jakub Jelinek <jakub@redhat.com>.
4 41b3e8b9 2020-01-20 rsc
5 41b3e8b9 2020-01-20 rsc The GNU C Library is free software; you can redistribute it and/or
6 41b3e8b9 2020-01-20 rsc modify it under the terms of the GNU Lesser General Public
7 41b3e8b9 2020-01-20 rsc License as published by the Free Software Foundation; either
8 41b3e8b9 2020-01-20 rsc version 2.1 of the License, or (at your option) any later version.
9 41b3e8b9 2020-01-20 rsc
10 41b3e8b9 2020-01-20 rsc The GNU C Library is distributed in the hope that it will be useful,
11 41b3e8b9 2020-01-20 rsc but WITHOUT ANY WARRANTY; without even the implied warranty of
12 41b3e8b9 2020-01-20 rsc MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 41b3e8b9 2020-01-20 rsc Lesser General Public License for more details.
14 41b3e8b9 2020-01-20 rsc
15 41b3e8b9 2020-01-20 rsc You should have received a copy of the GNU Lesser General Public
16 41b3e8b9 2020-01-20 rsc License along with the GNU C Library; if not, write to the Free
17 41b3e8b9 2020-01-20 rsc Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 41b3e8b9 2020-01-20 rsc 02111-1307 USA. */
19 41b3e8b9 2020-01-20 rsc
20 41b3e8b9 2020-01-20 rsc #include <ucontext.h>
21 41b3e8b9 2020-01-20 rsc
22 41b3e8b9 2020-01-20 rsc #define UC_M_PC 40
23 41b3e8b9 2020-01-20 rsc #define UC_M_NPC 48
24 41b3e8b9 2020-01-20 rsc
25 41b3e8b9 2020-01-20 rsc extern int __getcontext (ucontext_t *ucp);
26 41b3e8b9 2020-01-20 rsc extern int __setcontext (const ucontext_t *ucp, int restoremask);
27 41b3e8b9 2020-01-20 rsc
28 41b3e8b9 2020-01-20 rsc int
29 41b3e8b9 2020-01-20 rsc swapcontext (ucontext_t *oucp, const ucontext_t *ucp)
30 41b3e8b9 2020-01-20 rsc {
31 41b3e8b9 2020-01-20 rsc extern void __swapcontext_ret (void);
32 41b3e8b9 2020-01-20 rsc /* Save the current machine context to oucp. */
33 41b3e8b9 2020-01-20 rsc __getcontext (oucp);
34 41b3e8b9 2020-01-20 rsc /* Modify oucp to skip the __setcontext call on reactivation. */
35 41b3e8b9 2020-01-20 rsc *(long*)((char*)oucp+UC_M_PC) = (long)__swapcontext_ret;
36 41b3e8b9 2020-01-20 rsc *(long*)((char*)oucp+UC_M_NPC) = (long)__swapcontext_ret + 4;
37 41b3e8b9 2020-01-20 rsc /* Restore the machine context in ucp. */
38 41b3e8b9 2020-01-20 rsc __setcontext (ucp, 1);
39 41b3e8b9 2020-01-20 rsc return 0;
40 41b3e8b9 2020-01-20 rsc }
41 41b3e8b9 2020-01-20 rsc
42 41b3e8b9 2020-01-20 rsc asm (" \n\
43 41b3e8b9 2020-01-20 rsc .text \n\
44 41b3e8b9 2020-01-20 rsc .type __swapcontext_ret, #function \n\
45 41b3e8b9 2020-01-20 rsc __swapcontext_ret: \n\
46 41b3e8b9 2020-01-20 rsc return %i7 + 8 \n\
47 41b3e8b9 2020-01-20 rsc clr %o0 \n\
48 41b3e8b9 2020-01-20 rsc .size __swapcontext_ret, .-__swapcontext_ret \n\
49 41b3e8b9 2020-01-20 rsc ");