ontop_i386_ms_pe_gas.asm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 "ontop_i386_ms_pe_gas.asm"
  25. .text
  26. .p2align 4,,15
  27. .globl _ontop_fcontext
  28. .def _ontop_fcontext; .scl 2; .type 32; .endef
  29. _ontop_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 ECX */
  60. movl %esp, %ecx
  61. /* first arg of ontop_fcontext() == fcontext to jump to */
  62. movl 0x30(%esp), %eax
  63. /* pass parent fcontext_t */
  64. movl %ecx, 0x30(%eax)
  65. /* second arg of ontop_fcontext() == data to be transferred */
  66. movl 0x34(%esp), %ecx
  67. /* pass data */
  68. movl %ecx, 0x34(%eax)
  69. /* third arg of ontop_fcontext() == ontop-function */
  70. movl 0x38(%esp), %ecx
  71. /* restore ESP (pointing to context-data) from EDX */
  72. movl %eax, %esp
  73. #if !defined(BOOST_USE_TSX)
  74. /* restore MMX control- and status-word */
  75. ldmxcsr (%esp)
  76. /* restore x87 control-word */
  77. fldcw 0x4(%esp)
  78. #endif
  79. /* restore NT_TIB into EDX */
  80. movl %fs:(0x18), %edx
  81. /* restore fiber local storage */
  82. movl 0x8(%esp), %eax
  83. movl %eax, 0x10(%edx)
  84. /* restore current deallocation stack */
  85. movl 0xc(%esp), %eax
  86. movl %eax, 0xe0c(%edx)
  87. /* restore current stack limit */
  88. movl 0x10(%esp), %eax
  89. movl %eax, 0x08(%edx)
  90. /* restore current stack base */
  91. movl 0x14(%esp), %eax
  92. movl %eax, 0x04(%edx)
  93. /* restore current SEH exception list */
  94. movl 0x18(%esp), %eax
  95. movl %eax, (%edx)
  96. movl 0x1c(%esp), %edi /* restore EDI */
  97. movl 0x20(%esp), %esi /* restore ESI */
  98. movl 0x24(%esp), %ebx /* restore EBX */
  99. movl 0x28(%esp), %ebp /* restore EBP */
  100. /* prepare stack */
  101. leal 0x2c(%esp), %esp
  102. /* keep return-address on stack */
  103. /* jump to context */
  104. jmp *%ecx
  105. .section .drectve
  106. .ascii " -export:\"ontop_fcontext\""