]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/context/src/asm/make_i386_ms_pe_gas.asm
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / context / src / asm / make_i386_ms_pe_gas.asm
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 * | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | *
14 * --------------------------------------------------------------------------------- *
15 * | fc_strg |fc_deallo| limit | base | fc_seh | EDI | ESI | EBX | *
16 * --------------------------------------------------------------------------------- *
17 * --------------------------------------------------------------------------------- *
18 * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
19 * --------------------------------------------------------------------------------- *
20 * | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | *
21 * --------------------------------------------------------------------------------- *
22 * | EBP | EIP | to | data | | EH NXT |SEH HNDLR| | *
23 * --------------------------------------------------------------------------------- *
24 *************************************************************************************/
25
26 .file "make_i386_ms_pe_gas.asm"
27 .text
28 .p2align 4,,15
29 .globl _make_fcontext
30 .def _make_fcontext; .scl 2; .type 32; .endef
31 _make_fcontext:
32 /* first arg of make_fcontext() == top of context-stack */
33 movl 0x04(%esp), %eax
34
35 /* reserve space for first argument of context-function */
36 /* EAX might already point to a 16byte border */
37 leal -0x08(%eax), %eax
38
39 /* shift address in EAX to lower 16 byte boundary */
40 andl $-16, %eax
41
42 /* reserve space for context-data on context-stack */
43 /* size for fc_mxcsr .. EIP + return-address for context-function */
44 /* on context-function entry: (ESP -0x4) % 8 == 0 */
45 /* additional space is required for SEH */
46 leal -0x48(%eax), %eax
47
48 /* first arg of make_fcontext() == top of context-stack */
49 movl 0x04(%esp), %ecx
50 /* save top address of context stack as 'base' */
51 movl %ecx, 0xc(%eax)
52 /* second arg of make_fcontext() == size of context-stack */
53 movl 0x08(%esp), %edx
54 /* negate stack size for LEA instruction (== substraction) */
55 negl %edx
56 /* compute bottom address of context stack (limit) */
57 leal (%ecx,%edx), %ecx
58 /* save bottom address of context-stack as 'limit' */
59 movl %ecx, 0x8(%eax)
60 /* save bottom address of context-stack as 'dealloction stack' */
61 movl %ecx, 0x4(%eax)
62 /* set fiber-storage to zero */
63 xorl %ecx, %ecx
64 movl %ecx, (%eax)
65
66 /* third arg of make_fcontext() == address of context-function */
67 /* stored in EBX */
68 movl 0xc(%esp), %ecx
69 movl %ecx, 0x1c(%eax)
70
71 /* compute abs address of label trampoline */
72 movl $trampoline, %ecx
73 /* save address of trampoline as return-address for context-function */
74 /* will be entered after calling jump_fcontext() first time */
75 movl %ecx, 0x24(%eax)
76
77 /* compute abs address of label finish */
78 movl $finish, %ecx
79 /* save address of finish as return-address for context-function */
80 /* will be entered after context-function returns */
81 movl %ecx, 0x20(%eax)
82
83 /* traverse current seh chain to get the last exception handler installed by Windows */
84 /* note that on Windows Server 2008 and 2008 R2, SEHOP is activated by default */
85 /* the exception handler chain is tested for the presence of ntdll.dll!FinalExceptionHandler */
86 /* at its end by RaiseException all seh andlers are disregarded if not present and the */
87 /* program is aborted */
88 /* load NT_TIB into ECX */
89 movl %fs:(0x0), %ecx
90
91 walk:
92 /* load 'next' member of current SEH into EDX */
93 movl (%ecx), %edx
94 /* test if 'next' of current SEH is last (== 0xffffffff) */
95 incl %edx
96 jz found
97 decl %edx
98 /* exchange content; ECX contains address of next SEH */
99 xchgl %ecx, %edx
100 /* inspect next SEH */
101 jmp walk
102
103 found:
104 /* load 'handler' member of SEH == address of last SEH handler installed by Windows */
105 movl 0x04(%ecx), %ecx
106 /* save address in ECX as SEH handler for context */
107 movl %ecx, 0x38(%eax)
108 /* set ECX to -1 */
109 movl $0xffffffff, %ecx
110 /* save ECX as next SEH item */
111 movl %ecx, 0x34(%eax)
112 /* load address of next SEH item */
113 leal 0x34(%eax), %ecx
114 /* save next SEH */
115 movl %ecx, 0x10(%eax)
116
117 /* return pointer to context-data */
118 ret
119
120 trampoline:
121 /* move transport_t for entering context-function */
122 /* FCTX == EAX, DATA == EDX */
123 movl %eax, (%esp)
124 movl %edx, 0x4(%esp)
125 /* label finish as return-address */
126 pushl %ebp
127 /* jump to context-function */
128 jmp *%ebx
129
130 finish:
131 /* ESP points to same address as ESP on entry of context function + 0x4 */
132 xorl %eax, %eax
133 /* exit code is zero */
134 movl %eax, (%esp)
135 /* exit application */
136 call __exit
137 hlt
138
139 .def __exit; .scl 2; .type 32; .endef /* standard C library function */
140
141 .section .drectve
142 .ascii " -export:\"make_fcontext\""