]>
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 | ||
8 | /**************************************************************************************** | |
9 | * * | |
10 | * ---------------------------------------------------------------------------------- * | |
11 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * | |
12 | * ---------------------------------------------------------------------------------- * | |
13 | * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | * | |
14 | * ---------------------------------------------------------------------------------- * | |
b32b8144 | 15 | * | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | * |
7c673cae FG |
16 | * ---------------------------------------------------------------------------------- * |
17 | * ---------------------------------------------------------------------------------- * | |
18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * | |
19 | * ---------------------------------------------------------------------------------- * | |
20 | * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | * | |
21 | * ---------------------------------------------------------------------------------- * | |
b32b8144 | 22 | * | R15 | RBX | RBP | RIP | * |
7c673cae FG |
23 | * ---------------------------------------------------------------------------------- * |
24 | * * | |
25 | ****************************************************************************************/ | |
26 | ||
27 | .text | |
28 | .globl make_fcontext | |
29 | .type make_fcontext,@function | |
30 | .align 16 | |
31 | make_fcontext: | |
32 | /* first arg of make_fcontext() == top of context-stack */ | |
33 | movq %rdi, %rax | |
34 | ||
35 | /* shift address in RAX to lower 16 byte boundary */ | |
36 | andq $-16, %rax | |
37 | ||
38 | /* reserve space for context-data on context-stack */ | |
39 | /* on context-function entry: (RSP -0x8) % 16 == 0 */ | |
40 | leaq -0x40(%rax), %rax | |
41 | ||
42 | /* third arg of make_fcontext() == address of context-function */ | |
b32b8144 FG |
43 | /* stored in RBX */ |
44 | movq %rdx, 0x28(%rax) | |
45 | ||
46 | /* save MMX control- and status-word */ | |
47 | stmxcsr (%rax) | |
48 | /* save x87 control-word */ | |
49 | fnstcw 0x4(%rax) | |
50 | ||
51 | /* compute abs address of label trampoline */ | |
52 | leaq trampoline(%rip), %rcx | |
53 | /* save address of trampoline as return-address for context-function */ | |
54 | /* will be entered after calling jump_fcontext() first time */ | |
55 | movq %rcx, 0x38(%rax) | |
7c673cae FG |
56 | |
57 | /* compute abs address of label finish */ | |
58 | leaq finish(%rip), %rcx | |
59 | /* save address of finish as return-address for context-function */ | |
60 | /* will be entered after context-function returns */ | |
b32b8144 | 61 | movq %rcx, 0x30(%rax) |
7c673cae FG |
62 | |
63 | ret /* return pointer to context-data */ | |
64 | ||
b32b8144 FG |
65 | trampoline: |
66 | /* store return address on stack */ | |
67 | /* fix stack alignment */ | |
68 | push %rbp | |
69 | /* jump to context-function */ | |
70 | jmp *%rbx | |
71 | ||
7c673cae FG |
72 | finish: |
73 | /* exit code is zero */ | |
74 | xorq %rdi, %rdi | |
75 | /* exit application */ | |
76 | call _exit@PLT | |
77 | hlt | |
78 | .size make_fcontext,.-make_fcontext | |
79 | ||
80 | /* Mark that we don't need executable stack. */ | |
81 | .section .note.GNU-stack,"",%progbits |