]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
b32b8144 FG |
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 | ****************************************************************************************/ | |
7c673cae FG |
26 | |
27 | .text | |
28 | .globl _make_fcontext | |
29 | .align 2 | |
30 | _make_fcontext: | |
31 | /* first arg of make_fcontext() == top of context-stack */ | |
32 | movl 0x4(%esp), %eax | |
33 | ||
34 | /* reserve space for first argument of context-function | |
b32b8144 | 35 | eax might already point to a 16byte border */ |
7c673cae FG |
36 | leal -0x8(%eax), %eax |
37 | ||
38 | /* shift address in EAX to lower 16 byte boundary */ | |
39 | andl $-16, %eax | |
40 | ||
41 | /* reserve space for context-data on context-stack */ | |
b32b8144 | 42 | leal -0x2c(%eax), %eax |
7c673cae | 43 | |
b32b8144 | 44 | /* third arg of make_fcontext() == address of context-function */ |
7c673cae | 45 | /* stored in EBX */ |
b32b8144 FG |
46 | movl 0xc(%esp), %ecx |
47 | movl %ecx, 0x10(%eax) | |
7c673cae | 48 | |
b32b8144 FG |
49 | /* save MMX control- and status-word */ |
50 | stmxcsr (%eax) | |
51 | /* save x87 control-word */ | |
52 | fnstcw 0x4(%eax) | |
7c673cae FG |
53 | |
54 | /* compute abs address of label trampoline */ | |
55 | call 1f | |
56 | /* address of trampoline 1 */ | |
57 | 1: popl %ecx | |
58 | /* compute abs address of label trampoline */ | |
59 | addl $trampoline-1b, %ecx | |
60 | /* save address of trampoline as return address */ | |
61 | /* will be entered after calling jump_fcontext() first time */ | |
b32b8144 | 62 | movl %ecx, 0x18(%eax) |
7c673cae FG |
63 | |
64 | /* compute abs address of label finish */ | |
65 | call 2f | |
66 | /* address of label 2 */ | |
67 | 2: popl %ecx | |
68 | /* compute abs address of label finish */ | |
69 | addl $finish-2b, %ecx | |
70 | /* save address of finish as return-address for context-function */ | |
71 | /* will be entered after context-function returns */ | |
b32b8144 | 72 | movl %ecx, 0x14(%eax) |
7c673cae FG |
73 | |
74 | ret /* return pointer to context-data */ | |
75 | ||
76 | trampoline: | |
77 | /* move transport_t for entering context-function */ | |
b32b8144 FG |
78 | movl %eax, (%esp) |
79 | movl %edx, 0x4(%esp) | |
7c673cae FG |
80 | pushl %ebp |
81 | /* jump to context-function */ | |
82 | jmp *%ebx | |
83 | ||
84 | finish: | |
85 | /* exit code is zero */ | |
86 | xorl %eax, %eax | |
87 | movl %eax, (%esp) | |
88 | /* exit application */ | |
89 | call __exit | |
90 | hlt |