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 "jump_x86_64_sysv_elf_gas.S" 29#else 30 31.file "jump_i386_sysv_elf_gas.S" 32.text 33.globl jump_fcontext 34.align 2 35.type jump_fcontext,@function 36jump_fcontext: 37 leal -0x1c(%esp), %esp /* prepare stack */ 38 39#if !defined(BOOST_USE_TSX) 40 stmxcsr (%esp) /* save MMX control- and status-word */ 41 fnstcw 0x4(%esp) /* save x87 control-word */ 42#endif 43 44#if defined(BOOST_CONTEXT_TLS_STACK_PROTECTOR) 45 movl %gs:0x14, %ecx /* read stack guard from TLS record */ 46 movl %ecx, 0x8(%esp) /* save stack guard */ 47#endif 48 49 movl %edi, 0xc(%esp) /* save EDI */ 50 movl %esi, 0x10(%esp) /* save ESI */ 51 movl %ebx, 0x14(%esp) /* save EBX */ 52 movl %ebp, 0x18(%esp) /* save EBP */ 53 54 /* store ESP (pointing to context-data) in ECX */ 55 movl %esp, %ecx 56 57 /* first arg of jump_fcontext() == fcontext to jump to */ 58 movl 0x24(%esp), %eax 59 60 /* second arg of jump_fcontext() == data to be transferred */ 61 movl 0x28(%esp), %edx 62 63 /* restore ESP (pointing to context-data) from EAX */ 64 movl %eax, %esp 65 66 /* address of returned transport_t */ 67 movl 0x20(%esp), %eax 68 /* return parent fcontext_t */ 69 movl %ecx, (%eax) 70 /* return data */ 71 movl %edx, 0x4(%eax) 72 73 movl 0x1c(%esp), %ecx /* restore EIP */ 74 75#if !defined(BOOST_USE_TSX) 76 ldmxcsr (%esp) /* restore MMX control- and status-word */ 77 fldcw 0x4(%esp) /* restore x87 control-word */ 78#endif 79 80#if defined(BOOST_CONTEXT_TLS_STACK_PROTECTOR) 81 movl 0x8(%esp), %edx /* load stack guard */ 82 movl %edx, %gs:0x14 /* restore stack guard to TLS record */ 83#endif 84 85 movl 0xc(%esp), %edi /* restore EDI */ 86 movl 0x10(%esp), %esi /* restore ESI */ 87 movl 0x14(%esp), %ebx /* restore EBX */ 88 movl 0x18(%esp), %ebp /* restore EBP */ 89 90 leal 0x24(%esp), %esp /* prepare stack */ 91 92 /* jump to context */ 93 jmp *%ecx 94.size jump_fcontext,.-jump_fcontext 95 96/* Mark that we don't need executable stack. */ 97.section .note.GNU-stack,"",%progbits 98 99#endif 100