summaryrefslogtreecommitdiffstats
path: root/library/fibers/switchstack_gcc_32_win.s
blob: 2e8c140fec5fe164b114c6176f31fd5ceae8778b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
.global _switchStackInternal 
.section .text 
.def _switchStackInternal ; .scl 2 ; .type 32 ; .endef 

_switchStackInternal:
    // save callee-saved registers
    push %ebp
    movl %esp, %ebp
    push %ebx
    push %esi
    push %edi

    // store SIMD floating point control word
    sub $4, %esp
    stmxcsr (%esp)

    // store floating point control bytes
    sub $4, %esp
    fstcw (%esp)

    // save the old stack pointer
    movl 0xc(%ebp), %edx
    movl %esp, (%edx)
    // set the new stack pointer
    movl 0x8(%ebp), %esp

    // restore floating point control bytes
    fnclex
    fldcw (%esp)
    add $4, %esp

    // restore SIMD floating point control word
    ldmxcsr (%esp)
    add $4, %esp

    // pop callee-saved registers
    pop %edi
    pop %esi
    pop %ebx
    pop %ebp
    
    ret