jump_i386_ms_pe_masm.asm 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. jump_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 EAX
  56. mov eax, esp
  57. ; firstarg of jump_fcontext() == fcontext to jump to
  58. mov ecx, [esp+030h]
  59. ; restore ESP (pointing to context-data) from ECX
  60. mov esp, ecx
  61. IFNDEF BOOST_USE_TSX
  62. ; restore MMX control- and status-word
  63. ldmxcsr [esp]
  64. ; restore x87 control-word
  65. fldcw [esp+04h]
  66. ENDIF
  67. assume fs:nothing
  68. ; load NT_TIB into EDX
  69. mov edx, fs:[018h]
  70. assume fs:error
  71. ; restore fiber local storage
  72. mov ecx, [esp+08h]
  73. mov [edx+010h], ecx
  74. ; restore current deallocation stack
  75. mov ecx, [esp+0ch]
  76. mov [edx+0e0ch], ecx
  77. ; restore current stack limit
  78. mov ecx, [esp+010h]
  79. mov [edx+08h], ecx
  80. ; restore current stack base
  81. mov ecx, [esp+014h]
  82. mov [edx+04h], ecx
  83. ; restore current SEH exception list
  84. mov ecx, [esp+018h]
  85. mov [edx], ecx
  86. mov ecx, [esp+02ch] ; restore EIP
  87. mov edi, [esp+01ch] ; restore EDI
  88. mov esi, [esp+020h] ; restore ESI
  89. mov ebx, [esp+024h] ; restore EBX
  90. mov ebp, [esp+028h] ; restore EBP
  91. ; prepare stack
  92. lea esp, [esp+030h]
  93. ; return transfer_t
  94. ; FCTX == EAX, DATA == EDX
  95. mov edx, [eax+034h]
  96. ; jump to context
  97. jmp ecx
  98. jump_fcontext ENDP
  99. END