• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_mxcsr|fc_x87_cw| fc_strg |fc_deallo|  limit  |   base  |  fc_seh |   EDI   | *
16*  --------------------------------------------------------------------------------- *
17*  --------------------------------------------------------------------------------- *
18*  |    8    |    9    |   10    |    11   |    12   |    13   |    14   |    15   | *
19*  --------------------------------------------------------------------------------- *
20*  |   020h  |  024h   |  028h   |   02ch  |   030h  |   034h  |   038h  |   03ch  | *
21*  --------------------------------------------------------------------------------- *
22*  |   ESI   |   EBX   |   EBP   |   EIP   |    to   |   data  |  EH NXT |SEH HNDLR| *
23*  --------------------------------------------------------------------------------- *
24**************************************************************************************/
25
26.file	"jump_i386_ms_pe_gas.asm"
27.text
28.p2align 4,,15
29
30/* mark as using no unregistered SEH handlers */
31.globl	@feat.00
32.def	@feat.00;	.scl	3;	.type	0;	.endef
33.set    @feat.00,   1
34
35.globl	_jump_fcontext
36.def	_jump_fcontext;	.scl	2;	.type	32;	.endef
37_jump_fcontext:
38    /* prepare stack */
39    leal  -0x2c(%esp), %esp
40
41#if !defined(BOOST_USE_TSX)
42    /* save MMX control- and status-word */
43    stmxcsr  (%esp)
44    /* save x87 control-word */
45    fnstcw  0x4(%esp)
46#endif
47
48    /* load NT_TIB */
49    movl  %fs:(0x18), %edx
50    /* load fiber local storage */
51    movl  0x10(%edx), %eax
52    movl  %eax, 0x8(%esp)
53    /* load current dealloction stack */
54    movl  0xe0c(%edx), %eax
55    movl  %eax, 0xc(%esp)
56    /* load current stack limit */
57    movl  0x8(%edx), %eax
58    movl  %eax, 0x10(%esp)
59    /* load current stack base */
60    movl  0x4(%edx), %eax
61    movl  %eax, 0x14(%esp)
62    /* load current SEH exception list */
63    movl  (%edx), %eax
64    movl  %eax, 0x18(%esp)
65
66    movl  %edi, 0x1c(%esp)  /* save EDI */
67    movl  %esi, 0x20(%esp)  /* save ESI */
68    movl  %ebx, 0x24(%esp)  /* save EBX */
69    movl  %ebp, 0x28(%esp)  /* save EBP */
70
71    /* store ESP (pointing to context-data) in EAX */
72    movl  %esp, %eax
73
74    /* firstarg of jump_fcontext() == fcontext to jump to */
75    movl  0x30(%esp), %ecx
76
77    /* restore ESP (pointing to context-data) from ECX */
78    movl  %ecx, %esp
79
80#if !defined(BOOST_USE_TSX)
81    /* restore MMX control- and status-word */
82    ldmxcsr  (%esp)
83    /* restore x87 control-word */
84    fldcw  0x4(%esp)
85#endif
86
87    /* restore NT_TIB into EDX */
88    movl  %fs:(0x18), %edx
89    /* restore fiber local storage */
90    movl  0x8(%esp), %ecx
91    movl  %ecx, 0x10(%edx)
92    /* restore current deallocation stack */
93    movl  0xc(%esp), %ecx
94    movl  %ecx, 0xe0c(%edx)
95    /* restore current stack limit */
96    movl  0x10(%esp), %ecx
97    movl  %ecx, 0x8(%edx)
98    /* restore current stack base */
99    movl  0x14(%esp), %ecx
100    movl  %ecx, 0x4(%edx)
101    /* restore current SEH exception list */
102    movl  0x18(%esp), %ecx
103    movl  %ecx, (%edx)
104
105    movl  0x2c(%esp), %ecx  /* restore EIP */
106
107    movl  0x1c(%esp), %edi  /* restore EDI */
108    movl  0x20(%esp), %esi  /* restore ESI */
109    movl  0x24(%esp), %ebx  /* restore EBX */
110    movl  0x28(%esp), %ebp  /* restore EBP */
111
112    /* prepare stack */
113    leal  0x30(%esp), %esp
114
115    /* return transfer_t */
116    /* FCTX == EAX, DATA == EDX */
117    movl  0x34(%eax), %edx
118
119    /* jump to context */
120    jmp *%ecx
121
122.section .drectve
123.ascii " -export:\"_jump_fcontext\""
124