xref: /PHP-8.2/Zend/asm/make_i386_sysv_elf_gas.S (revision 49551d7c)
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/****************************************************************************************
9 *                                                                                      *
10 *  ----------------------------------------------------------------------------------  *
11 *  |    0    |    1    |    2    |    3    |    4     |    5    |    6    |    7    |  *
12 *  ----------------------------------------------------------------------------------  *
13 *  |   0x0   |   0x4   |   0x8   |   0xc   |   0x10   |   0x14  |   0x18  |   0x1c  |  *
14 *  ----------------------------------------------------------------------------------  *
15 *  | fc_mxcsr|fc_x87_cw|  guard  |   EDI   |   ESI    |   EBX   |   EBP   |   EIP   |  *
16 *  ----------------------------------------------------------------------------------  *
17 *  ----------------------------------------------------------------------------------  *
18 *  |    8    |    9    |    10   |    11   |    12    |    13   |    14   |    15   |  *
19 *  ----------------------------------------------------------------------------------  *
20 *  |   0x20  |   0x24  |   0x28  |                                                  |  *
21 *  ----------------------------------------------------------------------------------  *
22 *  |  hidden |    to   |   data  |                                                  |  *
23 *  ----------------------------------------------------------------------------------  *
24 *                                                                                      *
25 ****************************************************************************************/
26
27.file "make_i386_sysv_elf_gas.S"
28.text
29.globl make_fcontext
30.align 2
31.type make_fcontext,@function
32make_fcontext:
33    /* first arg of make_fcontext() == top of context-stack */
34    movl  0x4(%esp), %eax
35
36    /* reserve space for first argument of context-function
37       eax might already point to a 16byte border */
38    leal  -0x8(%eax), %eax
39
40    /* shift address in EAX to lower 16 byte boundary */
41    andl  $-16, %eax
42
43    /* reserve space for context-data on context-stack, and align the stack */
44    leal  -0x34(%eax), %eax
45
46    /* third arg of make_fcontext() == address of context-function */
47    /* stored in EBX */
48    movl  0xc(%esp), %ecx
49    movl  %ecx, 0x14(%eax)
50
51    /* save MMX control- and status-word */
52    stmxcsr (%eax)
53    /* save x87 control-word */
54    fnstcw  0x4(%eax)
55
56#if defined(BOOST_CONTEXT_TLS_STACK_PROTECTOR)
57    /* save stack guard */
58    movl  %gs:0x14, %ecx    /* read stack guard from TLS record */
59    movl  %ecx, 0x8(%eax)   /* save stack guard */
60#endif
61
62    /* return transport_t */
63    /* FCTX == EDI, DATA == ESI */
64    leal  0xc(%eax), %ecx
65    movl  %ecx, 0x20(%eax)
66
67    /* compute abs address of label trampoline */
68    call  1f
69    /* address of trampoline 1 */
701:  popl  %ecx
71    /* compute abs address of label trampoline */
72    addl  $trampoline-1b, %ecx
73    /* save address of trampoline as return address */
74    /* will be entered after calling jump_fcontext() first time */
75    movl  %ecx, 0x1c(%eax)
76
77    /* compute abs address of label finish */
78    call  2f
79    /* address of label 2 */
802:  popl  %ecx
81    /* compute abs address of label finish */
82    addl  $finish-2b, %ecx
83    /* save address of finish as return-address for context-function */
84    /* will be entered after context-function returns */
85    movl  %ecx, 0x18(%eax)
86
87    ret /* return pointer to context-data */
88
89trampoline:
90    /* move transport_t for entering context-function */
91    movl  %edi, (%esp)
92    movl  %esi, 0x4(%esp)
93    pushl %ebp
94    /* jump to context-function */
95    jmp *%ebx
96
97finish:
98    call  3f
99    /* address of label 3 */
1003:  popl  %ebx
101    /* compute address of GOT and store it in EBX */
102    addl  $_GLOBAL_OFFSET_TABLE_+[.-3b], %ebx
103
104    /* exit code is zero */
105    xorl  %eax, %eax
106    movl  %eax, (%esp)
107    /* exit application */
108    call  _exit@PLT
109    hlt
110.size make_fcontext,.-make_fcontext
111
112/* Mark that we don't need executable stack.  */
113.section .note.GNU-stack,"",%progbits
114