xref: /php-src/Zend/asm/jump_x86_64_ms_pe_gas.S (revision ff76cb73)
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* ---------------------------------------------------------------------------------- *
11* |     0   |     1   |     2    |     3   |     4   |     5   |     6   |     7   | *
12* ---------------------------------------------------------------------------------- *
13* |    0x0  |    0x4  |    0x8   |    0xc  |   0x10  |   0x14  |   0x18  |   0x1c  | *
14* ---------------------------------------------------------------------------------- *
15* |                          SEE registers (XMM6-XMM15)                            | *
16* ---------------------------------------------------------------------------------- *
17* ---------------------------------------------------------------------------------- *
18* |     8   |    9    |    10    |    11   |    12   |    13   |    14   |    15   | *
19* ---------------------------------------------------------------------------------- *
20* |   0x20  |  0x24   |   0x28   |   0x2c  |   0x30  |   0x34  |   0x38  |   0x3c  | *
21* ---------------------------------------------------------------------------------- *
22* |                          SEE registers (XMM6-XMM15)                            | *
23* ---------------------------------------------------------------------------------- *
24* ---------------------------------------------------------------------------------- *
25* |    16   |    17   |    18   |    19    |    20   |    21   |    22   |    23   | *
26* ---------------------------------------------------------------------------------- *
27* |   0xe40  |   0x44 |   0x48  |   0x4c   |   0x50  |   0x54  |   0x58  |   0x5c  | *
28* ---------------------------------------------------------------------------------- *
29* |                          SEE registers (XMM6-XMM15)                            | *
30* ---------------------------------------------------------------------------------- *
31* ---------------------------------------------------------------------------------- *
32* |    24   |   25    |    26    |   27    |    28   |    29   |    30   |    31   | *
33* ---------------------------------------------------------------------------------- *
34* |   0x60  |   0x64  |   0x68   |   0x6c  |   0x70  |   0x74  |   0x78  |   0x7c  | *
35* ---------------------------------------------------------------------------------- *
36* |                          SEE registers (XMM6-XMM15)                            | *
37* ---------------------------------------------------------------------------------- *
38* ---------------------------------------------------------------------------------- *
39* |    32   |   32    |    33    |   34    |    35   |    36   |    37   |    38   | *
40* ---------------------------------------------------------------------------------- *
41* |   0x80  |   0x84  |   0x88   |   0x8c  |   0x90  |   0x94  |   0x98  |   0x9c  | *
42* ---------------------------------------------------------------------------------- *
43* |                          SEE registers (XMM6-XMM15)                            | *
44* ---------------------------------------------------------------------------------- *
45* ---------------------------------------------------------------------------------- *
46* |    39   |   40    |    41    |   42    |    43   |    44   |    45   |    46   | *
47* ---------------------------------------------------------------------------------- *
48* |   0xa0  |   0xa4  |   0xa8   |   0xac  |   0xb0  |   0xb4  |   0xb8  |   0xbc  | *
49* ---------------------------------------------------------------------------------- *
50* | fc_mxcsr|fc_x87_cw|     <alignment>    |       fbr_strg    |      fc_dealloc   | *
51* ---------------------------------------------------------------------------------- *
52* ---------------------------------------------------------------------------------- *
53* |    47   |   48    |    49    |   50    |    51   |    52   |    53   |    54   | *
54* ---------------------------------------------------------------------------------- *
55* |   0xc0  |   0xc4  |   0xc8   |   0xcc  |   0xd0  |   0xd4  |   0xd8  |   0xdc  | *
56* ---------------------------------------------------------------------------------- *
57* |        limit      |         base       |         R12       |         R13       | *
58* ---------------------------------------------------------------------------------- *
59* ---------------------------------------------------------------------------------- *
60* |    55   |   56    |    57    |   58    |    59   |    60   |    61   |    62   | *
61* ---------------------------------------------------------------------------------- *
62* |   0xe0  |   0xe4  |   0xe8   |   0xec  |   0xf0  |   0xf4  |   0xf8  |   0xfc  | *
63* ---------------------------------------------------------------------------------- *
64* |        R14        |         R15        |         RDI       |        RSI        | *
65* ---------------------------------------------------------------------------------- *
66* ---------------------------------------------------------------------------------- *
67* |    63   |   64    |    65    |   66    |    67   |    68   |    69   |    70   | *
68* ---------------------------------------------------------------------------------- *
69* |  0x100  |  0x104  |  0x108   |  0x10c  |  0x110  |  0x114  |  0x118  |  0x11c  | *
70* ---------------------------------------------------------------------------------- *
71* |        RBX        |         RBP        |       hidden      |        RIP        | *
72* ---------------------------------------------------------------------------------- *
73* ---------------------------------------------------------------------------------- *
74* |    71   |   72    |    73    |   74    |    75   |    76   |    77   |    78   | *
75* ---------------------------------------------------------------------------------- *
76* |  0x120  |  0x124  |  0x128   |  0x12c  |  0x130  |  0x134  |  0x138  |  0x13c  | *
77* ---------------------------------------------------------------------------------- *
78* |                                   parameter area                               | *
79* ---------------------------------------------------------------------------------- *
80* ---------------------------------------------------------------------------------- *
81* |    79   |   80    |    81    |   82    |    83   |    84   |    85   |    86   | *
82* ---------------------------------------------------------------------------------- *
83* |  0x140  |  0x144  |  0x148   |  0x14c  |  0x150  |  0x154  |  0x158  |  0x15c  | *
84* ---------------------------------------------------------------------------------- *
85* |       FCTX        |        DATA        |                                       | *
86* ---------------------------------------------------------------------------------- *
87**************************************************************************************/
88
89.file	"jump_x86_64_ms_pe_gas.asm"
90.text
91.p2align 4,,15
92.def	jump_fcontext;	.scl	2;	.type	32;	.endef
93.seh_proc	jump_fcontext
94jump_fcontext:
95.seh_endprologue
96
97    leaq  -0x118(%rsp), %rsp /* prepare stack */
98
99#if !defined(BOOST_USE_TSX)
100    /* save XMM storage */
101    movaps  %xmm6, 0x0(%rsp)
102    movaps  %xmm7, 0x10(%rsp)
103    movaps  %xmm8, 0x20(%rsp)
104    movaps  %xmm9, 0x30(%rsp)
105    movaps  %xmm10, 0x40(%rsp)
106    movaps  %xmm11, 0x50(%rsp)
107    movaps  %xmm12, 0x60(%rsp)
108    movaps  %xmm13, 0x70(%rsp)
109    movaps  %xmm14, 0x80(%rsp)
110    movaps  %xmm15, 0x90(%rsp)
111    stmxcsr  0xa0(%rsp)  /* save MMX control- and status-word */
112    fnstcw   0xa4(%rsp)  /* save x87 control-word */
113#endif
114
115    /* load NT_TIB */
116    movq  %gs:(0x30), %r10
117    /* save fiber local storage */
118    movq  0x20(%r10), %rax
119    movq  %rax, 0xb0(%rsp)
120    /* save current deallocation stack */
121    movq  0x1478(%r10), %rax
122    movq  %rax, 0xb8(%rsp)
123    /* save current stack limit */
124    movq  0x10(%r10), %rax
125    movq  %rax, 0xc0(%rsp)
126    /* save current stack base */
127    movq  0x08(%r10), %rax
128    movq  %rax, 0xc8(%rsp)
129
130    movq  %r12, 0xd0(%rsp)  /* save R12 */
131    movq  %r13, 0xd8(%rsp)  /* save R13 */
132    movq  %r14, 0xe0(%rsp)  /* save R14 */
133    movq  %r15, 0xe8(%rsp)  /* save R15 */
134    movq  %rdi, 0xf0(%rsp)  /* save RDI */
135    movq  %rsi, 0xf8(%rsp)  /* save RSI */
136    movq  %rbx, 0x100(%rsp)  /* save RBX */
137    movq  %rbp, 0x108(%rsp)  /* save RBP */
138
139    movq  %rcx, 0x110(%rsp)  /* save hidden address of transport_t */
140
141    /* preserve RSP (pointing to context-data) in R9 */
142    movq  %rsp, %r9
143
144    /* restore RSP (pointing to context-data) from RDX */
145    movq  %rdx, %rsp
146
147#if !defined(BOOST_USE_TSX)
148    /* restore XMM storage */
149    movaps  0x0(%rsp), %xmm6
150    movaps  0x10(%rsp), %xmm7
151    movaps  0x20(%rsp), %xmm8
152    movaps  0x30(%rsp), %xmm9
153    movaps  0x40(%rsp), %xmm10
154    movaps  0x50(%rsp), %xmm11
155    movaps  0x60(%rsp), %xmm12
156    movaps  0x70(%rsp), %xmm13
157    movaps  0x80(%rsp), %xmm14
158    movaps  0x90(%rsp), %xmm15
159 	ldmxcsr 0xa0(%rsp) /* restore MMX control- and status-word */
160 	fldcw   0xa4(%rsp) /* restore x87 control-word */
161#endif
162
163    /* load NT_TIB */
164    movq  %gs:(0x30), %r10
165    /* restore fiber local storage */
166    movq  0xb0(%rsp), %rax
167    movq  %rax, 0x20(%r10)
168    /* restore current deallocation stack */
169    movq  0xb8(%rsp), %rax
170    movq  %rax, 0x1478(%r10)
171    /* restore current stack limit */
172    movq  0xc0(%rsp), %rax
173    movq  %rax, 0x10(%r10)
174    /* restore current stack base */
175    movq  0xc8(%rsp), %rax
176    movq  %rax, 0x08(%r10)
177
178    movq  0xd0(%rsp),  %r12  /* restore R12 */
179    movq  0xd8(%rsp),  %r13  /* restore R13 */
180    movq  0xe0(%rsp),  %r14  /* restore R14 */
181    movq  0xe8(%rsp),  %r15  /* restore R15 */
182    movq  0xf0(%rsp),  %rdi  /* restore RDI */
183    movq  0xf8(%rsp),  %rsi  /* restore RSI */
184    movq  0x100(%rsp), %rbx  /* restore RBX */
185    movq  0x108(%rsp), %rbp  /* restore RBP */
186
187    movq  0x110(%rsp), %rax  /* restore hidden address of transport_t */
188
189    leaq  0x118(%rsp), %rsp /* prepare stack */
190
191    /* restore return-address */
192    popq  %r10
193
194    /* transport_t returned in RAX */
195    /* return parent fcontext_t */
196    movq  %r9, 0x0(%rax)
197    /* return data */
198    movq  %r8, 0x8(%rax)
199
200    /* transport_t as 1.arg of context-function */
201    movq  %rax, %rcx
202
203    /* indirect jump to context */
204    jmp  *%r10
205.seh_endproc
206