]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/i386/getcontext.S
2.5-18.1
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / i386 / getcontext.S
CommitLineData
71483c00 1/* Save current context.
0ecb606c 2 Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
71483c00
UD
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
41bdb6e2
AJ
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.
71483c00
UD
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
41bdb6e2 14 Lesser General Public License for more details.
71483c00 15
41bdb6e2
AJ
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. */
71483c00
UD
20
21#include <sysdep.h>
22
23#include "ucontext_i.h"
24
25
26ENTRY(__getcontext)
27 /* Load address of the context data structure. */
28 movl 4(%esp), %eax
29
30 /* Return value of getcontext. 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 /* Exclude the return address. */
43 movl %ecx, oESP(%eax)
44 movl %ebx, oEBX(%eax)
45
e14b1447
UD
46 /* Save the FS segment register. We don't touch the GS register
47 since it is used for threads. */
71483c00 48 xorl %edx, %edx
e14b1447
UD
49 movw %fs, %dx
50 movl %edx, oFS(%eax)
71483c00
UD
51
52 /* We have separate floating-point register content memory on the
53 stack. We use the __fpregs_mem block in the context. Set the
54 links up correctly. */
55 leal oFPREGSMEM(%eax), %ecx
56 movl %ecx, oFPREGS(%eax)
57 /* Save the floating-point context. */
58 fnstenv (%ecx)
24176967
UD
59 /* And load it right back since the processor changes the mask.
60 Intel thought this opcode to be used in interrupt handlers which
61 would block all exceptions. */
62 fldenv (%ecx)
71483c00
UD
63
64 /* Save the current signal mask. */
65 pushl %ebx
0ecb606c
JJ
66 cfi_adjust_cfa_offset (4)
67 cfi_rel_offset (ebx, 0)
71483c00
UD
68 leal oSIGMASK(%eax), %edx
69 xorl %ecx, %ecx
70 movl $SIG_BLOCK, %ebx
71 movl $__NR_sigprocmask, %eax
097eca29 72 ENTER_KERNEL
71483c00 73 popl %ebx
0ecb606c
JJ
74 cfi_adjust_cfa_offset (-4)
75 cfi_restore (ebx)
71483c00
UD
76 cmpl $-4095, %eax /* Check %eax for error. */
77 jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
78
79 /* All done, return 0 for success. */
80 xorl %eax, %eax
81L(pseudo_end):
82 ret
83PSEUDO_END(__getcontext)
84
0ecb606c 85weak_alias (__getcontext, getcontext)