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|        R12        |         R13        |        R14        |  *
16 *  ----------------------------------------------------------------------------------  *
17 *  ----------------------------------------------------------------------------------  *
18 *  |    8    |    9    |   10    |   11    |    12    |    13   |    14   |    15   |  *
19 *  ----------------------------------------------------------------------------------  *
20 *  |   0x20  |   0x24  |   0x28  |  0x2c   |   0x30   |   0x34  |   0x38  |   0x3c  |  *
21 *  ----------------------------------------------------------------------------------  *
22 *  |        R15        |        RBX        |         RBP        |        RIP        |  *
23 *  ----------------------------------------------------------------------------------  *
24 *                                                                                      *
25 ****************************************************************************************/
26
27.file "jump_x86_64_sysv_elf_gas.S"
28.text
29.globl jump_fcontext
30.type jump_fcontext,@function
31.align 16
32jump_fcontext:
33    leaq  -0x38(%rsp), %rsp /* prepare stack */
34
35#if !defined(BOOST_USE_TSX)
36    stmxcsr  (%rsp)     /* save MMX control- and status-word */
37    fnstcw   0x4(%rsp)  /* save x87 control-word */
38#endif
39
40    movq  %r12, 0x8(%rsp)  /* save R12 */
41    movq  %r13, 0x10(%rsp)  /* save R13 */
42    movq  %r14, 0x18(%rsp)  /* save R14 */
43    movq  %r15, 0x20(%rsp)  /* save R15 */
44    movq  %rbx, 0x28(%rsp)  /* save RBX */
45    movq  %rbp, 0x30(%rsp)  /* save RBP */
46
47    /* store RSP (pointing to context-data) in RAX */
48    movq  %rsp, %rax
49
50    /* restore RSP (pointing to context-data) from RDI */
51    movq  %rdi, %rsp
52
53    movq  0x38(%rsp), %r8  /* restore return-address */
54
55#if !defined(BOOST_USE_TSX)
56    ldmxcsr  (%rsp)     /* restore MMX control- and status-word */
57    fldcw    0x4(%rsp)  /* restore x87 control-word */
58#endif
59
60    movq  0x8(%rsp), %r12  /* restore R12 */
61    movq  0x10(%rsp), %r13  /* restore R13 */
62    movq  0x18(%rsp), %r14  /* restore R14 */
63    movq  0x20(%rsp), %r15  /* restore R15 */
64    movq  0x28(%rsp), %rbx  /* restore RBX */
65    movq  0x30(%rsp), %rbp  /* restore RBP */
66
67    leaq  0x40(%rsp), %rsp /* prepare stack */
68
69    /* return transfer_t from jump */
70#if !defined(_ILP32)
71    /* RAX == fctx, RDX == data */
72    movq  %rsi, %rdx
73#else
74    /* RAX == data:fctx */
75    salq  $32, %rsi
76    orq   %rsi, %rax
77#endif
78    /* pass transfer_t as first arg in context function */
79#if !defined(_ILP32)
80    /* RDI == fctx, RSI == data */
81#else
82    /* RDI == data:fctx */
83#endif
84    movq  %rax, %rdi
85
86    /* indirect jump to context */
87    jmp  *%r8
88.size jump_fcontext,.-jump_fcontext
89
90/* Mark that we don't need executable stack.  */
91.section .note.GNU-stack,"",%progbits
92