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|   EDI   |   ESI   |   EBX    |   EBP   |   EIP   |    to   |  *
16 *  ----------------------------------------------------------------------------------  *
17 *  ----------------------------------------------------------------------------------  *
18 *  |    8    |    9    |    10   |    11   |    12    |    13   |    14   |    15   |  *
19 *  ----------------------------------------------------------------------------------  *
20 *  |   0x20  |                                                                      |  *
21 *  ----------------------------------------------------------------------------------  *
22 *  |   data  |                                                                      |  *
23 *  ----------------------------------------------------------------------------------  *
24 *                                                                                      *
25 ****************************************************************************************/
26
27.text
28.globl _jump_fcontext
29.align 2
30_jump_fcontext:
31    leal  -0x18(%esp), %esp  /* prepare stack */
32
33#if !defined(BOOST_USE_TSX)
34    stmxcsr  (%esp)     /* save MMX control- and status-word */
35    fnstcw   0x4(%esp)  /* save x87 control-word */
36#endif
37
38    movl  %edi, 0x8(%esp)  /* save EDI */
39    movl  %esi, 0xc(%esp)  /* save ESI */
40    movl  %ebx, 0x10(%esp)  /* save EBX */
41    movl  %ebp, 0x14(%esp)  /* save EBP */
42
43    /* store ESP (pointing to context-data) in ECX */
44    movl  %esp, %ecx
45
46    /* first arg of jump_fcontext() == fcontext to jump to */
47    movl  0x1c(%esp), %eax
48
49    /* second arg of jump_fcontext() == data to be transferred */
50    movl  0x20(%esp), %edx
51
52    /* restore ESP (pointing to context-data) from EAX */
53    movl  %eax, %esp
54
55    /* return parent fcontext_t */
56    movl  %ecx, %eax
57    /* returned data is stored in EDX */
58
59    movl  0x18(%esp), %ecx  /* restore EIP */
60
61#if !defined(BOOST_USE_TSX)
62    ldmxcsr  (%esp)     /* restore MMX control- and status-word */
63    fldcw    0x4(%esp)  /* restore x87 control-word */
64#endif
65
66    movl  0x8(%esp), %edi  /* restore EDI */
67    movl  0xc(%esp), %esi  /* restore ESI */
68    movl  0x10(%esp), %ebx  /* restore EBX */
69    movl  0x14(%esp), %ebp  /* restore EBP */
70
71    leal  0x1c(%esp), %esp  /* prepare stack */
72
73    /* jump to context */
74    jmp *%ecx
75