ontop_i386_ms_pe_masm.asm 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. ; Copyright Oliver Kowalke 2009.
  2. ; Distributed under the Boost Software License, Version 1.0.
  3. ; (See accompanying file LICENSE_1_0.txt or copy at
  4. ; http://www.boost.org/LICENSE_1_0.txt)
  5. ; ---------------------------------------------------------------------------------
  6. ; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
  7. ; ---------------------------------------------------------------------------------
  8. ; | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch |
  9. ; ---------------------------------------------------------------------------------
  10. ; | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI |
  11. ; ---------------------------------------------------------------------------------
  12. ; ---------------------------------------------------------------------------------
  13. ; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
  14. ; ---------------------------------------------------------------------------------
  15. ; | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch |
  16. ; ---------------------------------------------------------------------------------
  17. ; | ESI | EBX | EBP | EIP | to | data | EH NXT |SEH HNDLR|
  18. ; ---------------------------------------------------------------------------------
  19. .386
  20. .XMM
  21. .model flat, c
  22. .code
  23. ontop_fcontext PROC BOOST_CONTEXT_EXPORT
  24. ; prepare stack
  25. lea esp, [esp-02ch]
  26. IFNDEF BOOST_USE_TSX
  27. ; save MMX control- and status-word
  28. stmxcsr [esp]
  29. ; save x87 control-word
  30. fnstcw [esp+04h]
  31. ENDIF
  32. assume fs:nothing
  33. ; load NT_TIB into ECX
  34. mov edx, fs:[018h]
  35. assume fs:error
  36. ; load fiber local storage
  37. mov eax, [edx+010h]
  38. mov [esp+08h], eax
  39. ; load current deallocation stack
  40. mov eax, [edx+0e0ch]
  41. mov [esp+0ch], eax
  42. ; load current stack limit
  43. mov eax, [edx+08h]
  44. mov [esp+010h], eax
  45. ; load current stack base
  46. mov eax, [edx+04h]
  47. mov [esp+014h], eax
  48. ; load current SEH exception list
  49. mov eax, [edx]
  50. mov [esp+018h], eax
  51. mov [esp+01ch], edi ; save EDI
  52. mov [esp+020h], esi ; save ESI
  53. mov [esp+024h], ebx ; save EBX
  54. mov [esp+028h], ebp ; save EBP
  55. ; store ESP (pointing to context-data) in ECX
  56. mov ecx, esp
  57. ; first arg of ontop_fcontext() == fcontext to jump to
  58. mov eax, [esp+030h]
  59. ; pass parent fcontext_t
  60. mov [eax+030h], ecx
  61. ; second arg of ontop_fcontext() == data to be transferred
  62. mov ecx, [esp+034h]
  63. ; pass data
  64. mov [eax+034h], ecx
  65. ; third arg of ontop_fcontext() == ontop-function
  66. mov ecx, [esp+038h]
  67. ; restore ESP (pointing to context-data) from EAX
  68. mov esp, eax
  69. IFNDEF BOOST_USE_TSX
  70. ; restore MMX control- and status-word
  71. ldmxcsr [esp]
  72. ; restore x87 control-word
  73. fldcw [esp+04h]
  74. ENDIF
  75. assume fs:nothing
  76. ; load NT_TIB into EDX
  77. mov edx, fs:[018h]
  78. assume fs:error
  79. ; restore fiber local storage
  80. mov eax, [esp+08h]
  81. mov [edx+010h], eax
  82. ; restore current deallocation stack
  83. mov eax, [esp+0ch]
  84. mov [edx+0e0ch], eax
  85. ; restore current stack limit
  86. mov eax, [esp+010h]
  87. mov [edx+08h], eax
  88. ; restore current stack base
  89. mov eax, [esp+014h]
  90. mov [edx+04h], eax
  91. ; restore current SEH exception list
  92. mov eax, [esp+018h]
  93. mov [edx], eax
  94. mov edi, [esp+01ch] ; restore EDI
  95. mov esi, [esp+020h] ; restore ESI
  96. mov ebx, [esp+024h] ; restore EBX
  97. mov ebp, [esp+028h] ; restore EBP
  98. ; prepare stack
  99. lea esp, [esp+02ch]
  100. ; keep return-address on stack
  101. ; jump to context
  102. jmp ecx
  103. ontop_fcontext ENDP
  104. END