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 | EXIT | * 16 * ---------------------------------------------------------------------------------- * 17 * * 18 ****************************************************************************************/ 19 20.text 21.globl make_fcontext 22.align 2 23.type make_fcontext,@function 24make_fcontext: 25 /* first arg of make_fcontext() == top of context-stack */ 26 movl 0x4(%esp), %eax 27 28 /* reserve space for first argument of context-function 29 rax might already point to a 16byte border */ 30 leal -0x8(%eax), %eax 31 32 /* shift address in EAX to lower 16 byte boundary */ 33 andl $-16, %eax 34 35 /* reserve space for context-data on context-stack */ 36 /* size for fc_mxcsr .. EIP + return-address for context-function */ 37 /* on context-function entry: (ESP -0x4) % 8 == 0 */ 38 leal -0x20(%eax), %eax 39 40 /* third arg of make_fcontext() == address of context-function */ 41 movl 0xc(%esp), %edx 42 movl %edx, 0x18(%eax) 43 44 /* save MMX control- and status-word */ 45 stmxcsr (%eax) 46 /* save x87 control-word */ 47 fnstcw 0x4(%eax) 48 49 /* compute abs address of label finish */ 50 call 1f 51 /* address of label 1 */ 521: popl %ecx 53 /* compute abs address of label finish */ 54 addl $finish-1b, %ecx 55 /* save address of finish as return-address for context-function */ 56 /* will be entered after context-function returns */ 57 movl %ecx, 0x1c(%eax) 58 59 ret /* return pointer to context-data */ 60 61finish: 62 call 2f 63 /* address of label 2 */ 642: popl %ebx 65 /* compute address of GOT and store it in EBX */ 66 addl $_GLOBAL_OFFSET_TABLE_+[.-2b], %ebx 67 68 /* exit code is zero */ 69 xorl %eax, %eax 70 movl %eax, (%esp) 71 /* exit application */ 72 call _exit@PLT 73 hlt 74.size make_fcontext,.-make_fcontext 75 76/* Mark that we don't need executable stack. */ 77.section .note.GNU-stack,"",%progbits 78