|
Packit |
6c4009 |
/* Save current context and install the given one.
|
|
Packit |
6c4009 |
Copyright (C) 2001-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <sysdep.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include "ucontext_i.h"
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
ENTRY(__swapcontext)
|
|
Packit |
6c4009 |
/* Load address of the context data structure we save in. */
|
|
Packit |
6c4009 |
movl 4(%esp), %eax
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Return value of swapcontext. EAX is the only register whose
|
|
Packit |
6c4009 |
value is not preserved. */
|
|
Packit |
6c4009 |
movl $0, oEAX(%eax)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Save the 32-bit register values and the return address. */
|
|
Packit |
6c4009 |
movl %ecx, oECX(%eax)
|
|
Packit |
6c4009 |
movl %edx, oEDX(%eax)
|
|
Packit |
6c4009 |
movl %edi, oEDI(%eax)
|
|
Packit |
6c4009 |
movl %esi, oESI(%eax)
|
|
Packit |
6c4009 |
movl %ebp, oEBP(%eax)
|
|
Packit |
6c4009 |
movl (%esp), %ecx
|
|
Packit |
6c4009 |
movl %ecx, oEIP(%eax)
|
|
Packit |
6c4009 |
leal 4(%esp), %ecx
|
|
Packit |
6c4009 |
movl %ecx, oESP(%eax)
|
|
Packit |
6c4009 |
movl %ebx, oEBX(%eax)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Save the FS segment register. */
|
|
Packit |
6c4009 |
xorl %edx, %edx
|
|
Packit |
6c4009 |
movw %fs, %dx
|
|
Packit |
6c4009 |
movl %edx, oFS(%eax)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* We have separate floating-point register content memory on the
|
|
Packit |
6c4009 |
stack. We use the __fpregs_mem block in the context. Set the
|
|
Packit |
6c4009 |
links up correctly. */
|
|
Packit |
6c4009 |
leal oFPREGSMEM(%eax), %ecx
|
|
Packit |
6c4009 |
movl %ecx, oFPREGS(%eax)
|
|
Packit |
6c4009 |
/* Save the floating-point context. */
|
|
Packit |
6c4009 |
fnstenv (%ecx)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Load address of the context data structure we have to load. */
|
|
Packit |
6c4009 |
movl 8(%esp), %ecx
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Save the current signal mask and install the new one. */
|
|
Packit |
6c4009 |
pushl %ebx
|
|
Packit |
6c4009 |
leal oSIGMASK(%eax), %edx
|
|
Packit |
6c4009 |
leal oSIGMASK(%ecx), %ecx
|
|
Packit |
6c4009 |
movl $SIG_SETMASK, %ebx
|
|
Packit |
6c4009 |
movl $__NR_sigprocmask, %eax
|
|
Packit |
6c4009 |
ENTER_KERNEL
|
|
Packit |
6c4009 |
popl %ebx
|
|
Packit |
6c4009 |
cmpl $-4095, %eax /* Check %eax for error. */
|
|
Packit |
6c4009 |
jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* EAX was modified, reload it. */
|
|
Packit |
6c4009 |
movl 8(%esp), %eax
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Restore the floating-point context. Not the registers, only the
|
|
Packit |
6c4009 |
rest. */
|
|
Packit |
6c4009 |
movl oFPREGS(%eax), %ecx
|
|
Packit |
6c4009 |
fldenv (%ecx)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Restore the FS segment register. We don't touch the GS register
|
|
Packit |
6c4009 |
since it is used for threads. */
|
|
Packit |
6c4009 |
movl oFS(%eax), %edx
|
|
Packit |
6c4009 |
movw %dx, %fs
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Fetch the address to return to. */
|
|
Packit |
6c4009 |
movl oEIP(%eax), %ecx
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Load the new stack pointer. */
|
|
Packit |
6c4009 |
movl oESP(%eax), %esp
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Push the return address on the new stack so we can return there. */
|
|
Packit |
6c4009 |
pushl %ecx
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Load the values of all the 32-bit registers (except ESP).
|
|
Packit |
6c4009 |
Since we are loading from EAX, it must be last. */
|
|
Packit |
6c4009 |
movl oEDI(%eax), %edi
|
|
Packit |
6c4009 |
movl oESI(%eax), %esi
|
|
Packit |
6c4009 |
movl oEBP(%eax), %ebp
|
|
Packit |
6c4009 |
movl oEBX(%eax), %ebx
|
|
Packit |
6c4009 |
movl oEDX(%eax), %edx
|
|
Packit |
6c4009 |
movl oECX(%eax), %ecx
|
|
Packit |
6c4009 |
movl oEAX(%eax), %eax
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* The following 'ret' will pop the address of the code and jump
|
|
Packit |
6c4009 |
to it. */
|
|
Packit |
6c4009 |
ret
|
|
Packit |
6c4009 |
PSEUDO_END(__swapcontext)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
weak_alias (__swapcontext, swapcontext)
|