Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / unix / sysv / linux / i386 / swapcontext.S
blob5c832c9d1e7fa89b70ca89f57edc4d671c0a1f1e
1 /* Save current context and install the given one.
2    Copyright (C) 2001-2014 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4    Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
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.
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.
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    <http://www.gnu.org/licenses/>.  */
20 #include <sysdep.h>
22 #include "ucontext_i.h"
25 ENTRY(__swapcontext)
26         /* Load address of the context data structure we save in.  */
27         movl    4(%esp), %eax
29         /* Return value of swapcontext.  EAX is the only register whose
30            value is not preserved.  */
31         movl    $0, oEAX(%eax)
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)
45         /* Save the FS segment register.  */
46         xorl    %edx, %edx
47         movw    %fs, %dx
48         movl    %edx, oFS(%eax)
50         /* We have separate floating-point register content memory on the
51            stack.  We use the __fpregs_mem block in the context.  Set the
52            links up correctly.  */
53         leal    oFPREGSMEM(%eax), %ecx
54         movl    %ecx, oFPREGS(%eax)
55         /* Save the floating-point context.  */
56         fnstenv (%ecx)
58         /* Load address of the context data structure we have to load.  */
59         movl    8(%esp), %ecx
61         /* Save the current signal mask and install the new one.  */
62         pushl   %ebx
63         leal    oSIGMASK(%eax), %edx
64         leal    oSIGMASK(%ecx), %ecx
65         movl    $SIG_SETMASK, %ebx
66         movl    $__NR_sigprocmask, %eax
67         ENTER_KERNEL
68         popl    %ebx
69         cmpl    $-4095, %eax            /* Check %eax for error.  */
70         jae     SYSCALL_ERROR_LABEL     /* Jump to error handler if error.  */
72         /* EAX was modified, reload it.  */
73         movl    8(%esp), %eax
75         /* Restore the floating-point context.  Not the registers, only the
76            rest.  */
77         movl    oFPREGS(%eax), %ecx
78         fldenv  (%ecx)
80         /* Restore the FS segment register.  We don't touch the GS register
81            since it is used for threads.  */
82         movl    oFS(%eax), %edx
83         movw    %dx, %fs
85         /* Fetch the address to return to.  */
86         movl    oEIP(%eax), %ecx
88         /* Load the new stack pointer.  */
89         movl    oESP(%eax), %esp
91         /* Push the return address on the new stack so we can return there.  */
92         pushl   %ecx
94         /* Load the values of all the 32-bit registers (except ESP).
95            Since we are loading from EAX, it must be last.  */
96         movl    oEDI(%eax), %edi
97         movl    oESI(%eax), %esi
98         movl    oEBP(%eax), %ebp
99         movl    oEBX(%eax), %ebx
100         movl    oEDX(%eax), %edx
101         movl    oECX(%eax), %ecx
102         movl    oEAX(%eax), %eax
104         /* The following 'ret' will pop the address of the code and jump
105            to it.  */
106         ret
107 PSEUDO_END(__swapcontext)
109 weak_alias (__swapcontext, swapcontext)