swapcontext.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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.
  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(__swapcontext)
  19. /* Load address of the context data structure we save in. */
  20. movl 4(%esp), %eax
  21. /* Return value of swapcontext. 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
  33. movl %ecx, oESP(%eax)
  34. movl %ebx, oEBX(%eax)
  35. /* Save the FS segment register. */
  36. xorl %edx, %edx
  37. movw %fs, %dx
  38. movl %edx, oFS(%eax)
  39. /* We have separate floating-point register content memory on the
  40. stack. We use the __fpregs_mem block in the context. Set the
  41. links up correctly. */
  42. leal oFPREGSMEM(%eax), %ecx
  43. movl %ecx, oFPREGS(%eax)
  44. /* Save the floating-point context. */
  45. fnstenv (%ecx)
  46. /* Load address of the context data structure we have to load. */
  47. movl 8(%esp), %ecx
  48. /* Save the current signal mask and install the new one. */
  49. pushl %ebx
  50. leal oSIGMASK(%eax), %edx
  51. leal oSIGMASK(%ecx), %ecx
  52. movl $SIG_SETMASK, %ebx
  53. movl $__NR_sigprocmask, %eax
  54. ENTER_KERNEL
  55. popl %ebx
  56. cmpl $-4095, %eax /* Check %eax for error. */
  57. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  58. /* EAX was modified, reload it. */
  59. movl 8(%esp), %eax
  60. /* Restore the floating-point context. Not the registers, only the
  61. rest. */
  62. movl oFPREGS(%eax), %ecx
  63. fldenv (%ecx)
  64. /* Restore the FS segment register. We don't touch the GS register
  65. since it is used for threads. */
  66. movl oFS(%eax), %edx
  67. movw %dx, %fs
  68. /* Fetch the address to return to. */
  69. movl oEIP(%eax), %ecx
  70. /* Load the new stack pointer. */
  71. movl oESP(%eax), %esp
  72. /* Push the return address on the new stack so we can return there. */
  73. pushl %ecx
  74. /* Load the values of all the 32-bit registers (except ESP).
  75. Since we are loading from EAX, it must be last. */
  76. movl oEDI(%eax), %edi
  77. movl oESI(%eax), %esi
  78. movl oEBP(%eax), %ebp
  79. movl oEBX(%eax), %ebx
  80. movl oEDX(%eax), %edx
  81. movl oECX(%eax), %ecx
  82. movl oEAX(%eax), %eax
  83. /* The following 'ret' will pop the address of the code and jump
  84. to it. */
  85. L(pseudo_end):
  86. ret
  87. PSEUDO_END(__swapcontext)
  88. weak_alias (__swapcontext, swapcontext)