fiber_continue_x86_64.s 1.72 KB
Newer Older
1 2
	.file	"fiber_continue_x86_64.s"
	.text
3 4
	.global	__fiber_continue
	.type	__fiber_continue, @function
5 6

.align 16
7 8 9
__fiber_continue:
        # Parameter List (in order)
        # rdi = pointer to continuation (should hold value of target stack will be filled with this continuation)
10

11 12 13 14 15
        # Return
        # rax = continuation that returned control back to the caller (null if fallthrough)

        ############### Save State ###############
        # Make space for all register state we will store.
16 17
        leaq -0x38(%rsp), %rsp

18
        # Store calee saved general registers.
19 20 21 22 23 24
        movq %r12, 0x00(%rsp)
        movq %r13, 0x08(%rsp)
        movq %r14, 0x10(%rsp)
        movq %r15, 0x18(%rsp)
        movq %rbx, 0x20(%rsp)
        movq %rbp, 0x28(%rsp)
25
        # Store MMX control- and status-word
26
        stmxcsr 0x30(%rsp)
27
        # Store x87 control-word
28
        fnstcw 0x34(%rsp)
29
        ############### Save State ###############
30

31
        # Perform change to new stack.
32
        # Keep old stack as result from this function
33
        movq %rsp, %rax
34
        # switch to new stack pointer
35
        movq %rdi, %rsp
36

37
        ############ Restore State  ############
38 39 40 41 42 43 44 45 46 47 48 49 50 51
        # restore calee saved general registers
        movq 0x00(%rsp), %r12
        movq 0x08(%rsp), %r13
        movq 0x10(%rsp), %r14
        movq 0x18(%rsp), %r15
        movq 0x20(%rsp), %rbx
        movq 0x28(%rsp), %rbp
        # restore MMX control- and status-word
        ldmxcsr 0x30(%rsp)
        # restore x87 control-word
        fldcw 0x34(%rsp)

        # Free space for restored state
        leaq 0x38(%rsp), %rsp
52
        ############ Restore State  ############
53

54
        # Return the context we came from as a continuation.
55
        # Result is already in rax.
56
        ret