diff options
Diffstat (limited to 'library/fibers/switchstack_gcc_64_linux_mac.s')
-rw-r--r-- | library/fibers/switchstack_gcc_64_linux_mac.s | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/library/fibers/switchstack_gcc_64_linux_mac.s b/library/fibers/switchstack_gcc_64_linux_mac.s new file mode 100644 index 0000000..ced6a5d --- /dev/null +++ b/library/fibers/switchstack_gcc_64_linux_mac.s @@ -0,0 +1,44 @@ +.text +.globl _switchStackInternal + +_switchStackInternal: + // save callee-saved registers + push %rbp + movq %rsp, %rbp + push %rbx + push %r12 + push %r13 + push %r14 + push %r15 + + // store SIMD floating point control word + sub $4, %rsp + stmxcsr (%rsp) + + // store floating point control bytes + sub $4, %rsp + fstcw (%rsp) + + // save the old stack pointer (second arg in rsi) + movq %rsp, (%rsi) + // set the new stack pointer (first arg in rdi) + movq %rdi, %rsp + + // restore floating point control bytes + fnclex + fldcw (%rsp) + add $4, %rsp + + // restore SIMD floating point control word + ldmxcsr (%rsp) + add $4, %rsp + + // pop callee-saved registers + pop %r15 + pop %r14 + pop %r13 + pop %r12 + pop %rbx + pop %rbp + + retq |