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