1 /* Save current context and install the given one.
2 Copyright (C) 2001-2012 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/>. */
22 #include "ucontext_i.h"
26 /* Load address of the context data structure we save in. */
29 /* Return value of swapcontext. EAX is the only register whose
30 value is not preserved. */
33 /* Save the 32-bit register values and the return address. */
45 /* Save the FS segment register. */
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. */
58 /* Load address of the context data structure we have to load. */
61 /* Save the current signal mask and install the new one. */
63 leal oSIGMASK(%eax), %edx
64 leal oSIGMASK(%ecx), %ecx
65 movl $SIG_SETMASK, %ebx
66 movl $__NR_sigprocmask, %eax
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. */
75 /* Restore the floating-point context. Not the registers, only the
77 movl oFPREGS(%eax), %ecx
80 /* Restore the FS segment register. We don't touch the GS register
81 since it is used for threads. */
85 /* Fetch the address to return to. */
88 /* Load the new stack pointer. */
91 /* Push the return address on the new stack so we can return there. */
94 /* Load the values of all the 32-bit registers (except ESP).
95 Since we are loading from EAX, it must be last. */
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
107 PSEUDO_END(__swapcontext)
109 weak_alias (__swapcontext, swapcontext)