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