xref: /PHP-8.4/Zend/asm/jump_i386_ms_pe_masm.asm (revision c276c16b)
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
27jump_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 EAX
64    mov  eax, esp
65
66    ; firstarg of jump_fcontext() == fcontext to jump to
67    mov  ecx, [esp+030h]
68
69    ; restore ESP (pointing to context-data) from ECX
70    mov  esp, ecx
71
72IFNDEF BOOST_USE_TSX
73    ; restore MMX control- and status-word
74    ldmxcsr  [esp]
75    ; restore x87 control-word
76    fldcw  [esp+04h]
77ENDIF
78
79    assume  fs:nothing
80    ; load NT_TIB into EDX
81    mov  edx, fs:[018h]
82    assume  fs:error
83    ; restore fiber local storage
84    mov  ecx, [esp+08h]
85    mov  [edx+010h], ecx
86    ; restore current deallocation stack
87    mov  ecx, [esp+0ch]
88    mov  [edx+0e0ch], ecx
89    ; restore current stack limit
90    mov  ecx, [esp+010h]
91    mov  [edx+08h], ecx
92    ; restore current stack base
93    mov  ecx, [esp+014h]
94    mov  [edx+04h], ecx
95    ; restore current SEH exception list
96    mov  ecx, [esp+018h]
97    mov  [edx], ecx
98
99    mov  ecx, [esp+02ch]  ; restore EIP
100
101    mov  edi, [esp+01ch]  ; restore EDI
102    mov  esi, [esp+020h]  ; restore ESI
103    mov  ebx, [esp+024h]  ; restore EBX
104    mov  ebp, [esp+028h]  ; restore EBP
105
106    ; prepare stack
107    lea  esp, [esp+030h]
108
109    ; return transfer_t
110    ; FCTX == EAX, DATA == EDX
111    mov  edx, [eax+034h]
112
113    ; jump to context
114    jmp ecx
115jump_fcontext ENDP
116END
117