jump_i386_ms_pe_gas.asm 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. Copyright Oliver Kowalke 2009.
  3. Copyright Thomas Sailer 2013.
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. */
  8. /*************************************************************************************
  9. * --------------------------------------------------------------------------------- *
  10. * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
  11. * --------------------------------------------------------------------------------- *
  12. * | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | *
  13. * --------------------------------------------------------------------------------- *
  14. * | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | *
  15. * --------------------------------------------------------------------------------- *
  16. * --------------------------------------------------------------------------------- *
  17. * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
  18. * --------------------------------------------------------------------------------- *
  19. * | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | *
  20. * --------------------------------------------------------------------------------- *
  21. * | ESI | EBX | EBP | EIP | to | data | EH NXT |SEH HNDLR| *
  22. * --------------------------------------------------------------------------------- *
  23. **************************************************************************************/
  24. .file "jump_i386_ms_pe_gas.asm"
  25. .text
  26. .p2align 4,,15
  27. .globl _jump_fcontext
  28. .def _jump_fcontext; .scl 2; .type 32; .endef
  29. _jump_fcontext:
  30. /* prepare stack */
  31. leal -0x2c(%esp), %esp
  32. #if !defined(BOOST_USE_TSX)
  33. /* save MMX control- and status-word */
  34. stmxcsr (%esp)
  35. /* save x87 control-word */
  36. fnstcw 0x4(%esp)
  37. #endif
  38. /* load NT_TIB */
  39. movl %fs:(0x18), %edx
  40. /* load fiber local storage */
  41. movl 0x10(%edx), %eax
  42. movl %eax, 0x8(%esp)
  43. /* load current dealloction stack */
  44. movl 0xe0c(%edx), %eax
  45. movl %eax, 0xc(%esp)
  46. /* load current stack limit */
  47. movl 0x8(%edx), %eax
  48. movl %eax, 0x10(%esp)
  49. /* load current stack base */
  50. movl 0x4(%edx), %eax
  51. movl %eax, 0x14(%esp)
  52. /* load current SEH exception list */
  53. movl (%edx), %eax
  54. movl %eax, 0x18(%esp)
  55. movl %edi, 0x1c(%esp) /* save EDI */
  56. movl %esi, 0x20(%esp) /* save ESI */
  57. movl %ebx, 0x24(%esp) /* save EBX */
  58. movl %ebp, 0x28(%esp) /* save EBP */
  59. /* store ESP (pointing to context-data) in EAX */
  60. movl %esp, %eax
  61. /* firstarg of jump_fcontext() == fcontext to jump to */
  62. movl 0x30(%esp), %ecx
  63. /* restore ESP (pointing to context-data) from ECX */
  64. movl %ecx, %esp
  65. #if !defined(BOOST_USE_TSX)
  66. /* restore MMX control- and status-word */
  67. ldmxcsr (%esp)
  68. /* restore x87 control-word */
  69. fldcw 0x4(%esp)
  70. #endif
  71. /* restore NT_TIB into EDX */
  72. movl %fs:(0x18), %edx
  73. /* restore fiber local storage */
  74. movl 0x8(%esp), %ecx
  75. movl %ecx, 0x10(%edx)
  76. /* restore current deallocation stack */
  77. movl 0xc(%esp), %ecx
  78. movl %ecx, 0xe0c(%edx)
  79. /* restore current stack limit */
  80. movl 0x10(%esp), %ecx
  81. movl %ecx, 0x8(%edx)
  82. /* restore current stack base */
  83. movl 0x14(%esp), %ecx
  84. movl %ecx, 0x4(%edx)
  85. /* restore current SEH exception list */
  86. movl 0x18(%esp), %ecx
  87. movl %ecx, (%edx)
  88. movl 0x2c(%esp), %ecx /* restore EIP */
  89. movl 0x1c(%esp), %edi /* restore EDI */
  90. movl 0x20(%esp), %esi /* restore ESI */
  91. movl 0x24(%esp), %ebx /* restore EBX */
  92. movl 0x28(%esp), %ebp /* restore EBP */
  93. /* prepare stack */
  94. leal 0x30(%esp), %esp
  95. /* return transfer_t */
  96. /* FCTX == EAX, DATA == EDX */
  97. movl 0x34(%eax), %edx
  98. /* jump to context */
  99. jmp *%ecx
  100. .section .drectve
  101. .ascii " -export:\"jump_fcontext\""