getcontext.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Save current context.
  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.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <sysdep.h>
  17. #include "ucontext_i.h"
  18. ENTRY(__getcontext)
  19. /* Load address of the context data structure. */
  20. movl 4(%esp), %eax
  21. /* Return value of getcontext. EAX is the only register whose
  22. value is not preserved. */
  23. movl $0, oEAX(%eax)
  24. /* Save the 32-bit register values and the return address. */
  25. movl %ecx, oECX(%eax)
  26. movl %edx, oEDX(%eax)
  27. movl %edi, oEDI(%eax)
  28. movl %esi, oESI(%eax)
  29. movl %ebp, oEBP(%eax)
  30. movl (%esp), %ecx
  31. movl %ecx, oEIP(%eax)
  32. leal 4(%esp), %ecx /* Exclude the return address. */
  33. movl %ecx, oESP(%eax)
  34. movl %ebx, oEBX(%eax)
  35. /* Save the FS segment register. We don't touch the GS register
  36. since it is used for threads. */
  37. xorl %edx, %edx
  38. movw %fs, %dx
  39. movl %edx, oFS(%eax)
  40. /* We have separate floating-point register content memory on the
  41. stack. We use the __fpregs_mem block in the context. Set the
  42. links up correctly. */
  43. leal oFPREGSMEM(%eax), %ecx
  44. movl %ecx, oFPREGS(%eax)
  45. /* Save the floating-point context. */
  46. fnstenv (%ecx)
  47. /* And load it right back since the processor changes the mask.
  48. Intel thought this opcode to be used in interrupt handlers which
  49. would block all exceptions. */
  50. fldenv (%ecx)
  51. /* Save the current signal mask. */
  52. pushl %ebx
  53. cfi_adjust_cfa_offset (4)
  54. cfi_rel_offset (ebx, 0)
  55. leal oSIGMASK(%eax), %edx
  56. xorl %ecx, %ecx
  57. movl $SIG_BLOCK, %ebx
  58. movl $__NR_sigprocmask, %eax
  59. ENTER_KERNEL
  60. popl %ebx
  61. cfi_adjust_cfa_offset (-4)
  62. cfi_restore (ebx)
  63. cmpl $-4095, %eax /* Check %eax for error. */
  64. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  65. /* All done, return 0 for success. */
  66. xorl %eax, %eax
  67. L(pseudo_end):
  68. ret
  69. PSEUDO_END(__getcontext)
  70. weak_alias (__getcontext, getcontext)