]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/i386/swapcontext.S
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / i386 / swapcontext.S
1 /* Save current context and install the given one.
2 Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
20
21 #include <sysdep.h>
22
23 #include "ucontext_i.h"
24
25
26 ENTRY(__swapcontext)
27 /* Load address of the context data structure we save in. */
28 movl 4(%esp), %eax
29
30 /* Return value of swapcontext. EAX is the only register whose
31 value is not preserved. */
32 movl $0, oEAX(%eax)
33
34 /* Save the 32-bit register values and the return address. */
35 movl %ecx, oECX(%eax)
36 movl %edx, oEDX(%eax)
37 movl %edi, oEDI(%eax)
38 movl %esi, oESI(%eax)
39 movl %ebp, oEBP(%eax)
40 movl (%esp), %ecx
41 movl %ecx, oEIP(%eax)
42 leal 4(%esp), %ecx
43 movl %ecx, oESP(%eax)
44 movl %ebx, oEBX(%eax)
45
46 /* Save the FS segment register. */
47 xorl %edx, %edx
48 movw %fs, %dx
49 movl %edx, oFS(%eax)
50
51 /* We have separate floating-point register content memory on the
52 stack. We use the __fpregs_mem block in the context. Set the
53 links up correctly. */
54 leal oFPREGSMEM(%eax), %ecx
55 movl %ecx, oFPREGS(%eax)
56 /* Save the floating-point context. */
57 fnstenv (%ecx)
58
59 /* Load address of the context data structure we have to load. */
60 movl 8(%esp), %ecx
61
62 /* Save the current signal mask and install the new one. */
63 pushl %ebx
64 leal oSIGMASK(%eax), %edx
65 leal oSIGMASK(%ecx), %ecx
66 movl $SIG_SETMASK, %ebx
67 movl $__NR_sigprocmask, %eax
68 ENTER_KERNEL
69 popl %ebx
70 cmpl $-4095, %eax /* Check %eax for error. */
71 jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
72
73 /* EAX was modified, reload it. */
74 movl 8(%esp), %eax
75
76 /* Restore the floating-point context. Not the registers, only the
77 rest. */
78 movl oFPREGS(%eax), %ecx
79 fldenv (%ecx)
80
81 /* Restore the FS segment register. We don't touch the GS register
82 since it is used for threads. */
83 movl oFS(%eax), %edx
84 movw %dx, %fs
85
86 /* Fetch the address to return to. */
87 movl oEIP(%eax), %ecx
88
89 /* Load the new stack pointer. */
90 movl oESP(%eax), %esp
91
92 /* Push the return address on the new stack so we can return there. */
93 pushl %ecx
94
95 /* Load the values of all the 32-bit registers (except ESP).
96 Since we are loading from EAX, it must be last. */
97 movl oEDI(%eax), %edi
98 movl oESI(%eax), %esi
99 movl oEBP(%eax), %ebp
100 movl oEBX(%eax), %ebx
101 movl oEDX(%eax), %edx
102 movl oECX(%eax), %ecx
103 movl oEAX(%eax), %eax
104
105 /* The following 'ret' will pop the address of the code and jump
106 to it. */
107
108 L(pseudo_end):
109 ret
110 PSEUDO_END(__swapcontext)
111
112 weak_alias(__swapcontext, swapcontext)