summaryrefslogtreecommitdiffstats
path: root/library/fibers/switchstack_msvc_32.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'library/fibers/switchstack_msvc_32.cpp')
-rw-r--r--library/fibers/switchstack_msvc_32.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/library/fibers/switchstack_msvc_32.cpp b/library/fibers/switchstack_msvc_32.cpp
new file mode 100644
index 0000000..eae68ee
--- /dev/null
+++ b/library/fibers/switchstack_msvc_32.cpp
@@ -0,0 +1,44 @@
+extern "C" {
+void __declspec(naked) _switchStackInternal(void* to, void** from)
+{
+ __asm {
+ // save callee-saved registers
+ PUSH EBP
+ MOV EBP, ESP
+ PUSH EBX
+ PUSH ESI
+ PUSH EDI
+
+ // store SIMD floating point control word
+ SUB ESP, 4
+ STMXCSR [ESP]
+
+ // store floating point control bytes
+ SUB ESP, 4
+ FSTCW [ESP]
+
+ // save the old stack pointer
+ MOV EDX, dword ptr 12[EBP]
+ MOV [EDX], ESP
+ // set the new stack pointer
+ MOV ESP, dword ptr 8[EBP]
+
+ // restore floating point control bytes
+ FNCLEX
+ FLDCW [ESP]
+ ADD ESP, 4
+
+ // restore SIMD floating point control word
+ LDMXCSR [ESP]
+ ADD ESP, 4
+
+ // pop callee-saved registers
+ POP EDI
+ POP ESI
+ POP EBX
+ POP EBP
+
+ RET
+ }
+}
+}