]>
Commit | Line | Data |
---|---|---|
a678c13b | 1 | /* Save current context and install the given one. |
2b778ceb | 2 | Copyright (C) 2001-2021 Free Software Foundation, Inc. |
a678c13b TS |
3 | This file is part of the GNU C Library. |
4 | Contributed by Ulrich Drepper <drepper@redhat.com>, 2001. | |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
7 | modify it under the terms of the GNU Lesser General Public | |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
10 | ||
11 | The GNU C Library is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Lesser General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public | |
17 | License along with the GNU C Library; if not, see | |
18 | <https://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #include <sysdep.h> | |
21 | ||
22 | #include "ucontext_i.h" | |
23 | ||
24 | ||
25 | ENTRY(__swapcontext) | |
26 | /* Load address of the context data structure we save in. */ | |
27 | movl 4(%esp), %eax | |
28 | ||
29 | /* Return value of swapcontext. EAX is the only register whose | |
30 | value is not preserved. */ | |
31 | movl $0, oEAX(%eax) | |
32 | ||
33 | /* Save the 32-bit register values and the return address. */ | |
34 | movl %ecx, oECX(%eax) | |
35 | movl %edx, oEDX(%eax) | |
36 | movl %edi, oEDI(%eax) | |
37 | movl %esi, oESI(%eax) | |
38 | movl %ebp, oEBP(%eax) | |
39 | movl (%esp), %ecx | |
40 | movl %ecx, oEIP(%eax) | |
41 | leal 4(%esp), %ecx | |
42 | movl %ecx, oESP(%eax) | |
43 | movl %ebx, oEBX(%eax) | |
44 | ||
45 | /* Save the FS segment register. */ | |
46 | xorl %edx, %edx | |
47 | movw %fs, %dx | |
48 | movl %edx, oFS(%eax) | |
49 | ||
50 | leal oFPREGS(%eax), %ecx | |
51 | /* Save the floating-point context. */ | |
52 | fnstenv (%ecx) | |
53 | ||
54 | /* Load address of the context data structure we have to load. */ | |
55 | movl 8(%esp), %ecx | |
56 | ||
57 | /* Save the current signal mask and install the new one. */ | |
58 | subl $12, %esp | |
59 | cfi_adjust_cfa_offset (12) | |
60 | leal oSIGMASK(%eax), %eax | |
61 | movl %eax, 8(%esp) | |
62 | leal oSIGMASK(%ecx), %eax | |
63 | movl %eax, 4(%esp) | |
64 | movl $SIG_SETMASK, (%esp) | |
65 | call HIDDEN_JUMPTARGET (__sigprocmask) | |
66 | addl $12, %esp | |
67 | cfi_adjust_cfa_offset (-12) | |
68 | testl %eax, %eax | |
69 | jne L(pseudo_end) | |
70 | ||
71 | /* EAX was modified, reload it. */ | |
72 | movl 8(%esp), %eax | |
73 | ||
74 | /* Restore the floating-point context. Not the registers, only the | |
75 | rest. */ | |
76 | leal oFPREGS(%eax), %ecx | |
77 | fldenv (%ecx) | |
78 | ||
79 | /* Restore the FS segment register. We don't touch the GS register | |
80 | since it is used for threads. */ | |
81 | movl oFS(%eax), %edx | |
82 | movw %dx, %fs | |
83 | ||
84 | /* Fetch the address to return to. */ | |
85 | movl oEIP(%eax), %ecx | |
86 | ||
87 | /* Load the new stack pointer. */ | |
88 | movl oESP(%eax), %esp | |
89 | ||
90 | /* Push the return address on the new stack so we can return there. */ | |
91 | pushl %ecx | |
92 | ||
93 | /* Load the values of all the 32-bit registers (except ESP). | |
94 | Since we are loading from EAX, it must be last. */ | |
95 | movl oEDI(%eax), %edi | |
96 | movl oESI(%eax), %esi | |
97 | movl oEBP(%eax), %ebp | |
98 | movl oEBX(%eax), %ebx | |
99 | movl oEDX(%eax), %edx | |
100 | movl oECX(%eax), %ecx | |
101 | movl oEAX(%eax), %eax | |
102 | ||
103 | /* The following 'ret' will pop the address of the code and jump | |
104 | to it. */ | |
105 | ||
106 | L(pseudo_end): | |
107 | ret | |
108 | PSEUDO_END(__swapcontext) | |
109 | ||
110 | weak_alias (__swapcontext, swapcontext) |