Ticket #7262: boost-mingw.patch

File boost-mingw.patch, 35.0 KB (added by anonymous, 10 years ago)

boost::context compilation for MinGW (gas port of masm files)

  • libs/context/build/Jamfile.v2

    old new  
    282284   ;
    283285
    284286alias asm_context_sources
     287   : asm/make_i386_ms_pe_gas.S
     288     asm/jump_i386_ms_pe_gas.S
     289     dummy.cpp
     290   : <address-model>32
     291     <architecture>x86
     292     <binary-format>pe
     293     <target-os>windows
     294     <toolset>gcc
     295   ;
     296
     297alias asm_context_sources
    285298   : asm/make_i386_ms_pe_masm.asm
    286299     asm/jump_i386_ms_pe_masm.asm
    287300     dummy.cpp
     
    379392   ;
    380393
    381394alias asm_context_sources
     395   : asm/make_x86_64_ms_pe_gas.S
     396     asm/jump_x86_64_ms_pe_gas.S
     397     dummy.cpp
     398   : <address-model>64
     399     <architecture>x86
     400     <binary-format>pe
     401     <target-os>windows
     402     <toolset>gcc
     403   ;
     404
     405alias asm_context_sources
    382406   : asm/make_x86_64_ms_pe_masm.asm
    383407     asm/jump_x86_64_ms_pe_masm.asm
    384408     dummy.cpp
  • libs/context/src/asm/make_i386_ms_pe_gas.S

    old new  
     1/*
     2            Copyright Oliver Kowalke 2009.
     3            Copyright Thomas Sailer 2013.
     4   Distributed under the Boost Software License, Version 1.0.
     5      (See accompanying file LICENSE_1_0.txt or copy at
     6            http://www.boost.org/LICENSE_1_0.txt)
     7*/
     8
     9/********************************************************************
     10 *                                                                  *
     11 *  --------------------------------------------------------------  *
     12 *  |    0    |    1    |    2    |    3    |    4     |    5    |  *
     13 *  --------------------------------------------------------------  *
     14 *  |    0h   |   04h   |   08h   |   0ch   |   010h   |   014h  |  *
     15 *  --------------------------------------------------------------  *
     16 *  |   EDI   |   ESI   |   EBX   |   EBP   |   ESP    |   EIP   |  *
     17 *  --------------------------------------------------------------  *
     18 *  --------------------------------------------------------------  *
     19 *  |    6    |    7    |    8    |                              |  *
     20 *  --------------------------------------------------------------  *
     21 *  |   018h  |   01ch  |   020h  |                              |  *
     22 *  --------------------------------------------------------------  *
     23 *  |    sp   |   size  |  limit  |                              |  *
     24 *  --------------------------------------------------------------  *
     25 *  --------------------------------------------------------------  *
     26 *  |    9    |                                                  |  *
     27 *  --------------------------------------------------------------  *
     28 *  |  024h   |                                                  |  *
     29 *  --------------------------------------------------------------  *
     30 *  |fc_execpt|                                                  |  *
     31 *  --------------------------------------------------------------  *
     32 *  --------------------------------------------------------------  *
     33 *  |   10    |                                                  |  *
     34 *  --------------------------------------------------------------  *
     35 *  |  028h   |                                                  |  *
     36 *  --------------------------------------------------------------  *
     37 *  |fc_strage|                                                  |  *
     38 *  --------------------------------------------------------------  *
     39 *  --------------------------------------------------------------  *
     40 *  |   11    |    12   |                                        |  *
     41 *  --------------------------------------------------------------  *
     42 *  |  02ch   |   030h  |                                        |  *
     43 *  --------------------------------------------------------------  *
     44 *  | fc_mxcsr|fc_x87_cw|                                        |  *
     45 *  --------------------------------------------------------------  *
     46 *                                                                  *
     47 * *****************************************************************/
     48
     49.file   "make_i386_ms_pe_gas.S"
     50.text
     51.p2align 4,,15
     52.globl  _make_fcontext
     53.def    _make_fcontext; .scl    2;      .type   32;     .endef
     54_make_fcontext:
     55    movl    0x04(%esp), %eax        /* load 1. arg of make_fcontext, pointer to context stack (base) */
     56    leal    -0x34(%eax),%eax        /* reserve space for fcontext_t at top of context stack */
     57
     58    /* shift address in EAX to lower 16 byte boundary */
     59    /* == pointer to fcontext_t and address of context stack */
     60    andl    $-16,       %eax
     61
     62    movl    0x04(%esp), %ecx        /* load 1. arg of make_fcontext, pointer to context stack (base) */
     63    movl    %ecx,       0x18(%eax)  /* save address of context stack (base) in fcontext_t */
     64    movl    0x08(%esp), %edx        /* load 2. arg of make_fcontext, context stack size */
     65    movl    %edx,       0x1c(%eax)  /* save context stack size in fcontext_t */
     66    negl    %edx                    /* negate stack size for LEA instruction (== substraction) */
     67    leal    (%ecx,%edx),%ecx        /* compute bottom address of context stack (limit) */
     68    movl    %ecx,       0x20(%eax)  /* save address of context stack (limit) in fcontext_t */
     69    movl    0x0c(%esp), %ecx        /* load 3. arg of make_fcontext, pointer to context function */
     70    movl    %ecx,       0x14(%eax)  /* save address of context function in fcontext_t */
     71
     72    stmxcsr 0x02c(%eax)             /* save MMX control word */
     73    fnstcw  0x030(%eax)             /* save x87 control word */
     74
     75    leal    -0x1c(%eax),%edx        /* reserve space for last frame and seh on context stack, (ESP - 0x4) % 16 == 0 */
     76    movl    %edx,       0x10(%eax)  /* save address in EDX as stack pointer for context function */
     77
     78    movl    $finish,    %ecx        /* abs address of finish */
     79    movl    %ecx,       (%edx)      /* save address of finish as return address for context function */
     80                                    /* entered after context function returns */
     81
     82    /* traverse current seh chain to get the last exception handler installed by Windows */
     83    /* note that on Windows Server 2008 and 2008 R2, SEHOP is activated by default */
     84    /* the exception handler chain is tested for the presence of ntdll.dll!FinalExceptionHandler */
     85    /* at its end by RaiseException all seh andlers are disregarded if not present and the */
     86    /* program is aborted */
     87    movl    %fs:(0x18), %ecx        /* load NT_TIB into ECX */
     88
     89walk:
     90    movl    (%ecx),     %edx        /* load 'next' member of current SEH into EDX */
     91    incl    %edx                    /* test if 'next' of current SEH is last (== 0xffffffff) */
     92    jz      found
     93    decl    %edx
     94    xchgl    %ecx,      %edx        /* exchange content; ECX contains address of next SEH */
     95    jmp     walk                    /* inspect next SEH */
     96
     97found:
     98    movl    0x04(%ecx), %ecx        /* load 'handler' member of SEH == address of last SEH handler installed by Windows */
     99    movl    0x10(%eax), %edx        /* load address of stack pointer for context function */
     100    movl    %ecx,       0x18(%edx)  /* save address in ECX as SEH handler for context */
     101    movl    $0xffffffff,%ecx        /* set ECX to -1 */
     102    movl    %ecx,       0x14(%edx)  /* save ECX as next SEH item */
     103    leal    0x14(%edx), %ecx        /* load address of next SEH item */
     104    movl    %ecx,       0x24(%eax)  /* save next SEH */
     105
     106    ret
     107
     108finish:
     109    /* ESP points to same address as ESP on entry of context function + 0x4 */
     110    xorl    %eax,       %eax
     111    movl    %eax,       (%esp)      /* exit code is zero */
     112    call    __exit                  /* exit application */
     113    hlt
     114
     115.def    __exit; .scl    2;      .type   32;     .endef  /* standard C library function */
  • libs/context/src/asm/jump_i386_ms_pe_gas.S

    old new  
     1/*
     2            Copyright Oliver Kowalke 2009.
     3            Copyright Thomas Sailer 2013.
     4   Distributed under the Boost Software License, Version 1.0.
     5      (See accompanying file LICENSE_1_0.txt or copy at
     6            http://www.boost.org/LICENSE_1_0.txt)
     7*/
     8
     9/********************************************************************
     10 *                                                                  *
     11 *  --------------------------------------------------------------  *
     12 *  |    0    |    1    |    2    |    3    |    4     |    5    |  *
     13 *  --------------------------------------------------------------  *
     14 *  |    0h   |   04h   |   08h   |   0ch   |   010h   |   014h  |  *
     15 *  --------------------------------------------------------------  *
     16 *  |   EDI   |   ESI   |   EBX   |   EBP   |   ESP    |   EIP   |  *
     17 *  --------------------------------------------------------------  *
     18 *  --------------------------------------------------------------  *
     19 *  |    6    |    7    |    8    |                              |  *
     20 *  --------------------------------------------------------------  *
     21 *  |   018h  |   01ch  |   020h  |                              |  *
     22 *  --------------------------------------------------------------  *
     23 *  |    sp   |   size  |  limit  |                              |  *
     24 *  --------------------------------------------------------------  *
     25 *  --------------------------------------------------------------  *
     26 *  |    9    |                                                  |  *
     27 *  --------------------------------------------------------------  *
     28 *  |  024h   |                                                  |  *
     29 *  --------------------------------------------------------------  *
     30 *  |fc_execpt|                                                  |  *
     31 *  --------------------------------------------------------------  *
     32 *  --------------------------------------------------------------  *
     33 *  |   10    |                                                  |  *
     34 *  --------------------------------------------------------------  *
     35 *  |  028h   |                                                  |  *
     36 *  --------------------------------------------------------------  *
     37 *  |fc_strage|                                                  |  *
     38 *  --------------------------------------------------------------  *
     39 *  --------------------------------------------------------------  *
     40 *  |   11    |    12   |                                        |  *
     41 *  --------------------------------------------------------------  *
     42 *  |  02ch   |   030h  |                                        |  *
     43 *  --------------------------------------------------------------  *
     44 *  | fc_mxcsr|fc_x87_cw|                                        |  *
     45 *  --------------------------------------------------------------  *
     46 *                                                                  *
     47 * *****************************************************************/
     48
     49.file   "jump_i386_ms_pe_gas.S"
     50.text
     51.p2align 4,,15
     52.globl  _jump_fcontext
     53.def    _jump_fcontext; .scl    2;      .type   32;     .endef
     54_jump_fcontext:
     55    movl    0x04(%esp), %ecx        /* load address of the first fcontext_t arg */
     56    movl    %edi,       (%ecx)      /* save EDI */
     57    movl    %esi,       0x04(%ecx)  /* save ESI */
     58    movl    %ebx,       0x08(%ecx)  /* save EBX */
     59    movl    %ebp,       0x0c(%ecx)  /* save EBP */
     60
     61    movl    %fs:(0x18), %edx        /* load NT_TIB */
     62    movl    (%edx),     %eax        /* load current SEH exception list */
     63    movl    %eax,       0x24(%ecx)  /* save current exception list */
     64    movl    0x04(%edx), %eax        /* load current stack base */
     65    movl    %eax,       0x18(%ecx)  /* save current stack base */
     66    movl    0x08(%edx), %eax        /* load current stack limit */
     67    movl    %eax,       0x20(%ecx)  /* save current stack limit */
     68    movl    0x10(%edx), %eax        /* load fiber local storage */
     69    movl    %eax,       0x28(%ecx)  /* save fiber local storage */
     70
     71    leal    0x04(%esp), %eax        /* exclude the return address */
     72    movl    %eax,       0x10(%ecx)  /* save as stack pointer */
     73    movl    (%esp),     %eax        /* load return address */
     74    movl    %eax,       0x14(%ecx)  /* save return address */
     75
     76    movl    0x08(%esp), %edx        /* load address of the second fcontext_t arg */
     77    movl    (%edx),     %edi        /* restore EDI */
     78    movl    0x04(%edx), %esi        /* restore ESI */
     79    movl    0x08(%edx), %ebx        /* restore EBX */
     80    movl    0x0c(%edx), %ebp        /* restore EBP */
     81
     82    movl    0x10(%esp), %eax        /* check if fpu enve preserving was requested */
     83    testl   %eax,       %eax
     84    je      1f
     85
     86    stmxcsr 0x2c(%ecx)              /* save MMX control word */
     87    fnstcw  0x30(%ecx)              /* save x87 control word */
     88    ldmxcsr 0x2c(%edx)              /* restore MMX control word */
     89    fldcw   0x30(%edx)              /* restore x87 control word */
     901:
     91    movl    %edx,       %ecx       
     92    movl    %fs:(0x18), %edx        /* load NT_TIB */
     93    movl    0x24(%ecx), %eax        /* load SEH exception list */
     94    movl    %eax,       (%edx)      /* restore next SEH item */
     95    movl    0x18(%ecx), %eax        /* load stack base */
     96    movl    %eax,       0x04(%edx)  /* restore stack base */
     97    movl    0x20(%ecx), %eax        /* load stack limit */
     98    movl    %eax,       0x08(%edx)  /* restore stack limit */
     99    movl    0x28(%ecx), %eax        /* load fiber local storage */
     100    movl    %eax,       0x10(%edx)  /* restore fiber local storage */
     101                                   
     102    movl    0x0c(%esp), %eax        /* use third arg as return value after jump */
     103                                   
     104    movl    0x10(%ecx), %esp        /* restore ESP */
     105    movl    %eax,       0x04(%esp)  /* use third arg as first arg in context function */
     106    movl    0x14(%ecx), %ecx        /* fetch the address to return to */
     107
     108    jmp     *%ecx                   /* indirect jump to context */
  • libs/context/src/asm/make_x86_64_ms_pe_gas.S

    old new  
     1/*
     2            Copyright Oliver Kowalke 2009.
     3            Copyright Thomas Sailer 2013.
     4   Distributed under the Boost Software License, Version 1.0.
     5      (See accompanying file LICENSE_1_0.txt or copy at
     6            http://www.boost.org/LICENSE_1_0.txt)
     7*/
     8
     9/****************************************************************************************
     10 *                                                                                      *
     11 *  ----------------------------------------------------------------------------------  *
     12 *  |    0    |    1    |    2    |    3    |    4     |    5    |    6    |    7    |  *
     13 *  ----------------------------------------------------------------------------------  *
     14 *  |   0x0   |   0x4   |   0x8   |   0xc   |   0x10   |   0x14  |   0x18  |   0x1c  |  *
     15 *  ----------------------------------------------------------------------------------  *
     16 *  |        R12        |         R13       |         R14        |        R15        |  *
     17 *  ----------------------------------------------------------------------------------  *
     18 *  ----------------------------------------------------------------------------------  *
     19 *  |    8    |    9    |   10    |   11    |    12    |    13   |    14   |    15   |  *
     20 *  ----------------------------------------------------------------------------------  *
     21 *  |   0x20  |   0x24  |   0x28  |  0x2c   |   0x30   |   0x34  |   0x38  |   0x3c  |  *
     22 *  ----------------------------------------------------------------------------------  *
     23 *  |        RDI        |        RSI        |         RBX        |        RBP        |  *
     24 *  ----------------------------------------------------------------------------------  *
     25 *  ----------------------------------------------------------------------------------  *
     26 *  |    16   |    17   |    18   |    19   |                                        |  *
     27 *  ----------------------------------------------------------------------------------  *
     28 *  |   0x40  |   0x44  |   0x48  |   0x4c  |                                        |  *
     29 *  ----------------------------------------------------------------------------------  *
     30 *  |        RSP        |        RIP        |                                        |  *
     31 *  ----------------------------------------------------------------------------------  *
     32 *  ----------------------------------------------------------------------------------  *
     33 *  |    20   |    21   |    22   |    23   |    24    |    25   |                   |  *
     34 *  ----------------------------------------------------------------------------------  *
     35 *  |   0x50  |   0x54  |   0x58  |   0x5c  |   0x60   |   0x64  |                   |  *
     36 *  ----------------------------------------------------------------------------------  *
     37 *  |        sp         |       size        |        limit       |                   |  *
     38 *  ----------------------------------------------------------------------------------  *
     39 *  ----------------------------------------------------------------------------------  *
     40 *  |    26   |   27    |                                                            |  *
     41 *  ----------------------------------------------------------------------------------  *
     42 *  |   0x68  |   0x6c  |                                                            |  *
     43 *  ----------------------------------------------------------------------------------  *
     44 *  |      fbr_strg     |                                                            |  *
     45 *  ----------------------------------------------------------------------------------  *
     46 *  ----------------------------------------------------------------------------------  *
     47 *  |    28   |   29    |    30   |    31   |    32    |    33   |   34    |   35    |  *
     48 *  ----------------------------------------------------------------------------------  *
     49 *  |   0x70  |   0x74  |   0x78  |   0x7c  |   0x80   |   0x84  |  0x88   |  0x8c   |  *
     50 *  ----------------------------------------------------------------------------------  *
     51 *  | fc_mxcsr|fc_x87_cw|      fc_xmm       |      SEE registers (XMM6-XMM15)        |  *
     52 *  ----------------------------------------------------------------------------------  *
     53 *  ----------------------------------------------------------------------------------  *
     54 *  |   36    |    37   |    38   |    39   |    40    |    41   |   42    |   43    |  *
     55 *  ----------------------------------------------------------------------------------  *
     56 *  |  0x90   |   0x94  |   0x98  |   0x9c  |   0xa0   |   0xa4  |  0xa8   |  0xac   |  *
     57 *  ----------------------------------------------------------------------------------  *
     58 *  |                          SEE registers (XMM6-XMM15)                            |  *
     59 *  ----------------------------------------------------------------------------------  *
     60 *  ----------------------------------------------------------------------------------  *
     61 *  |    44    |   45    |    46   |    47  |    48    |    49   |   50    |   51    |  *
     62 *  ----------------------------------------------------------------------------------  *
     63 *  |   0xb0   |  0xb4   |  0xb8   |  0xbc  |   0xc0   |   0xc4  |  0xc8   |  0xcc   |  *
     64 *  ----------------------------------------------------------------------------------  *
     65 *  |                          SEE registers (XMM6-XMM15)                            |  *
     66 *  ----------------------------------------------------------------------------------  *
     67 *  ----------------------------------------------------------------------------------  *
     68 *  |    52    |   53    |    54   |   55   |    56    |    57   |   58    |   59    |  *
     69 *  ----------------------------------------------------------------------------------  *
     70 *  |   0xd0   |  0xd4   |   0xd8  |  0xdc  |   0xe0   |  0xe4   |  0xe8   |  0xec   |  *
     71 *  ----------------------------------------------------------------------------------  *
     72 *  |                          SEE registers (XMM6-XMM15)                            |  *
     73 *  ----------------------------------------------------------------------------------  *
     74 *  ----------------------------------------------------------------------------------  *
     75 *  |    60   |    61   |    62    |    63  |    64    |    65   |   66    |   67    |  *
     76 *  ----------------------------------------------------------------------------------  *
     77 *  |  0xf0   |  0xf4   |   0xf8   |  0xfc  |   0x100  |  0x104  |  0x108  |  0x10c  |  *
     78 *  ----------------------------------------------------------------------------------  *
     79 *  |                          SEE registers (XMM6-XMM15)                            |  *
     80 *  ----------------------------------------------------------------------------------  *
     81 *  ----------------------------------------------------------------------------------  *
     82 *  |    68   |    69   |    70    |    71  |    72    |    73   |   74    |   75    |  *
     83 *  ----------------------------------------------------------------------------------  *
     84 *  |  0x110  |  0x114  |   0x118  |  0x11c |   0x120  |  0x124  |  0x128  |  0x12c  |  *
     85 *  ----------------------------------------------------------------------------------  *
     86 *  |                          SEE registers (XMM6-XMM15)                            |  *
     87 *  ----------------------------------------------------------------------------------  *
     88 *                                                                                      *
     89 * *************************************************************************************/
     90
     91.file   "make_x86_64_ms_pe_gas.S"
     92.text
     93.p2align 4,,15
     94.globl  make_fcontext
     95.def    make_fcontext;  .scl    2;      .type   32;     .endef
     96.seh_proc       make_fcontext
     97make_fcontext:
     98.seh_endprologue
     99    leaq    -0x130(%rcx),%rax       /* reserve space for fcontext_t at top of context stack */
     100
     101    /* shift address in RAX to lower 16 byte boundary */
     102    /* == pointer to fcontext_t and address of context stack */
     103    andq    $-16,       %rax
     104
     105    movq    %r8,        0x48(%rax)  /* save address of context function in fcontext_t */
     106    movq    %rdx,       0x58(%rax)  /* save context stack size in fcontext_t */
     107    movq    %rcx,       0x50(%rax)  /* save address of context stack pointer (base) in fcontext_t */
     108
     109    negq    %rdx                    /* negate stack size for LEA instruction (== substraction) */
     110    leaq    (%rcx,%rdx),%rcx        /* compute bottom address of context stack (limit) */
     111    movq    %rcx,       0x60(%rax)  /* save bottom address of context stack (limit) in fcontext_t */
     112
     113    stmxcsr 0x70(%rax)              /* save MMX control and status word */
     114    fnstcw  0x74(%rax)              /* save x87 control word */
     115
     116    leaq    -0x28(%rax),%rdx        /* reserve 32byte shadow space + return address on stack, (RSP - 0x8) % 16 == 0 */
     117    movq    %rdx,       0x40(%rax)  /* save address in RDX as stack pointer for context function */
     118
     119    leaq    finish(%rip),%rcx       /* compute abs address of label finish */
     120    movq    %rcx,(%rdx)             /* save address of finish as return address for context function */
     121                                    /* entered after context function returns */
     122
     123    ret
     124
     125finish:
     126    /* RSP points to same address as RSP on entry of context function + 0x8 */
     127    xorq    %rcx,       %rcx        /* exit code is zero */
     128    call    _exit                   /* exit application */
     129    hlt
     130.seh_endproc
     131
     132.def    _exit;  .scl    2;      .type   32;     .endef  /* standard C library function */
  • libs/context/src/asm/jump_x86_64_ms_pe_gas.S

    old new  
     1/*
     2            Copyright Oliver Kowalke 2009.
     3            Copyright Thomas Sailer 2013.
     4   Distributed under the Boost Software License, Version 1.0.
     5      (See accompanying file LICENSE_1_0.txt or copy at
     6            http://www.boost.org/LICENSE_1_0.txt)
     7*/
     8
     9/****************************************************************************************
     10 *                                                                                      *
     11 *  ----------------------------------------------------------------------------------  *
     12 *  |    0    |    1    |    2    |    3    |    4     |    5    |    6    |    7    |  *
     13 *  ----------------------------------------------------------------------------------  *
     14 *  |   0x0   |   0x4   |   0x8   |   0xc   |   0x10   |   0x14  |   0x18  |   0x1c  |  *
     15 *  ----------------------------------------------------------------------------------  *
     16 *  |        R12        |         R13       |         R14        |        R15        |  *
     17 *  ----------------------------------------------------------------------------------  *
     18 *  ----------------------------------------------------------------------------------  *
     19 *  |    8    |    9    |   10    |   11    |    12    |    13   |    14   |    15   |  *
     20 *  ----------------------------------------------------------------------------------  *
     21 *  |   0x20  |   0x24  |   0x28  |  0x2c   |   0x30   |   0x34  |   0x38  |   0x3c  |  *
     22 *  ----------------------------------------------------------------------------------  *
     23 *  |        RDI        |        RSI        |         RBX        |        RBP        |  *
     24 *  ----------------------------------------------------------------------------------  *
     25 *  ----------------------------------------------------------------------------------  *
     26 *  |    16   |    17   |    18   |    19   |                                        |  *
     27 *  ----------------------------------------------------------------------------------  *
     28 *  |   0x40  |   0x44  |   0x48  |   0x4c  |                                        |  *
     29 *  ----------------------------------------------------------------------------------  *
     30 *  |        RSP        |        RIP        |                                        |  *
     31 *  ----------------------------------------------------------------------------------  *
     32 *  ----------------------------------------------------------------------------------  *
     33 *  |    20   |    21   |    22   |    23   |    24    |    25   |                   |  *
     34 *  ----------------------------------------------------------------------------------  *
     35 *  |   0x50  |   0x54  |   0x58  |   0x5c  |   0x60   |   0x64  |                   |  *
     36 *  ----------------------------------------------------------------------------------  *
     37 *  |        sp         |       size        |        limit       |                   |  *
     38 *  ----------------------------------------------------------------------------------  *
     39 *  ----------------------------------------------------------------------------------  *
     40 *  |    26   |   27    |                                                            |  *
     41 *  ----------------------------------------------------------------------------------  *
     42 *  |   0x68  |   0x6c  |                                                            |  *
     43 *  ----------------------------------------------------------------------------------  *
     44 *  |      fbr_strg     |                                                            |  *
     45 *  ----------------------------------------------------------------------------------  *
     46 *  ----------------------------------------------------------------------------------  *
     47 *  |    28   |   29    |    30   |    31   |    32    |    33   |   34    |   35    |  *
     48 *  ----------------------------------------------------------------------------------  *
     49 *  |   0x70  |   0x74  |   0x78  |   0x7c  |   0x80   |   0x84  |  0x88   |  0x8c   |  *
     50 *  ----------------------------------------------------------------------------------  *
     51 *  | fc_mxcsr|fc_x87_cw|      fc_xmm       |      SEE registers (XMM6-XMM15)        |  *
     52 *  ----------------------------------------------------------------------------------  *
     53 *  ----------------------------------------------------------------------------------  *
     54 *  |   36    |    37   |    38   |    39   |    40    |    41   |   42    |   43    |  *
     55 *  ----------------------------------------------------------------------------------  *
     56 *  |  0x90   |   0x94  |   0x98  |   0x9c  |   0xa0   |   0xa4  |  0xa8   |  0xac   |  *
     57 *  ----------------------------------------------------------------------------------  *
     58 *  |                          SEE registers (XMM6-XMM15)                            |  *
     59 *  ----------------------------------------------------------------------------------  *
     60 *  ----------------------------------------------------------------------------------  *
     61 *  |    44    |   45    |    46   |    47  |    48    |    49   |   50    |   51    |  *
     62 *  ----------------------------------------------------------------------------------  *
     63 *  |   0xb0   |  0xb4   |  0xb8   |  0xbc  |   0xc0   |   0xc4  |  0xc8   |  0xcc   |  *
     64 *  ----------------------------------------------------------------------------------  *
     65 *  |                          SEE registers (XMM6-XMM15)                            |  *
     66 *  ----------------------------------------------------------------------------------  *
     67 *  ----------------------------------------------------------------------------------  *
     68 *  |    52    |   53    |    54   |   55   |    56    |    57   |   58    |   59    |  *
     69 *  ----------------------------------------------------------------------------------  *
     70 *  |   0xd0   |  0xd4   |   0xd8  |  0xdc  |   0xe0   |  0xe4   |  0xe8   |  0xec   |  *
     71 *  ----------------------------------------------------------------------------------  *
     72 *  |                          SEE registers (XMM6-XMM15)                            |  *
     73 *  ----------------------------------------------------------------------------------  *
     74 *  ----------------------------------------------------------------------------------  *
     75 *  |    60   |    61   |    62    |    63  |    64    |    65   |   66    |   67    |  *
     76 *  ----------------------------------------------------------------------------------  *
     77 *  |  0xf0   |  0xf4   |   0xf8   |  0xfc  |   0x100  |  0x104  |  0x108  |  0x10c  |  *
     78 *  ----------------------------------------------------------------------------------  *
     79 *  |                          SEE registers (XMM6-XMM15)                            |  *
     80 *  ----------------------------------------------------------------------------------  *
     81 *  ----------------------------------------------------------------------------------  *
     82 *  |    68   |    69   |    70    |    71  |    72    |    73   |   74    |   75    |  *
     83 *  ----------------------------------------------------------------------------------  *
     84 *  |  0x110  |  0x114  |   0x118  |  0x11c |   0x120  |  0x124  |  0x128  |  0x12c  |  *
     85 *  ----------------------------------------------------------------------------------  *
     86 *  |                          SEE registers (XMM6-XMM15)                            |  *
     87 *  ----------------------------------------------------------------------------------  *
     88 *                                                                                      *
     89 * *************************************************************************************/
     90
     91.file   "jump_x86_64_ms_pe_gas.S"
     92.text
     93.p2align 4,,15
     94.globl  jump_fcontext
     95.def    jump_fcontext;  .scl    2;      .type   32;     .endef
     96.seh_proc       jump_fcontext
     97jump_fcontext:
     98.seh_endprologue
     99    movq    %r12,       (%rcx)      /* save R12 */
     100    movq    %r13,       0x08(%rcx)  /* save R13 */
     101    movq    %r14,       0x10(%rcx)  /* save R14 */
     102    movq    %r15,       0x18(%rcx)  /* save R15 */
     103    movq    %rdi,       0x20(%rcx)  /* save RDI */
     104    movq    %rsi,       0x28(%rcx)  /* save RSI */
     105    movq    %rbx,       0x30(%rcx)  /* save RBX */
     106    movq    %rbp,       0x38(%rcx)  /* save RBP */
     107
     108    movq    %gs:(0x30), %r10        /* load NT_TIB */
     109    movq    0x08(%r10), %rax        /* load current stack base */
     110    movq    %rax,       0x50(%rcx)  /* save current stack base */
     111    movq    0x10(%r10), %rax        /* load current stack limit */
     112    movq    %rax,       0x60(%rcx)  /* save current stack limit */
     113    movq    0x18(%r10), %rax        /* load fiber local storage */
     114    movq    %rax,       0x68(%rcx)  /* save fiber local storage */
     115
     116    testq   %r9,        %r9
     117    je      1f
     118
     119    stmxcsr 0x70(%rcx)              /* save MMX control and status word */
     120    fnstcw  0x74(%rcx)              /* save x87 control word */
     121    /* save XMM storage */
     122    /* save start address of SSE register block in R10 */
     123    leaq    0x90(%rcx), %r10
     124    /* shift address in R10 to lower 16 byte boundary */
     125    /* == pointer to SEE register block */
     126    andq    $-16,       %r10
     127
     128    movaps  %xmm6,      (%r10)
     129    movaps  %xmm7,      0x10(%r10)
     130    movaps  %xmm8,      0x20(%r10)
     131    movaps  %xmm9,      0x30(%r10)
     132    movaps  %xmm10,     0x40(%r10)
     133    movaps  %xmm11,     0x50(%r10)
     134    movaps  %xmm12,     0x60(%r10)
     135    movaps  %xmm13,     0x70(%r10)
     136    movaps  %xmm14,     0x80(%r10)
     137    movaps  %xmm15,     0x90(%r10)
     138
     139    ldmxcsr 0x70(%rdx)              /* restore MMX control and status word */
     140    fldcw   0x74(%rdx)              /* restore x87 control word */
     141    /* restore XMM storage */
     142        /* save start address of SSE register block in R10 */
     143    leaq    0x90(%rdx), %r10
     144    /* shift address in R10 to lower 16 byte boundary */
     145    /* == pointer to SEE register block */
     146    andq    $-16,       %r10
     147
     148    movaps  (%r10),     %xmm6
     149    movaps  0x10(%r10), %xmm7
     150    movaps  0x20(%r10), %xmm8
     151    movaps  0x30(%r10), %xmm9
     152    movaps  0x40(%r10), %xmm10
     153    movaps  0x50(%r10), %xmm11
     154    movaps  0x60(%r10), %xmm12
     155    movaps  0x70(%r10), %xmm13
     156    movaps  0x80(%r10), %xmm14
     157    movaps  0x90(%r10), %xmm15
     158
     1591:
     160    leaq    0x08(%rsp), %rax        /* exclude the return address */
     161    movq    %rax,       0x40(%rcx)  /* save as stack pointer */
     162    movq    (%rsp),     %rax        /* load return address */
     163    movq    %rax,       0x48(%rcx)  /* save return address */
     164
     165    movq    (%rdx),     %r12        /* restore R12 */
     166    movq    0x08(%rdx), %r13        /* restore R13 */
     167    movq    0x10(%rdx), %r14        /* restore R14 */
     168    movq    0x18(%rdx), %r15        /* restore R15 */
     169    movq    0x20(%rdx), %rdi        /* restore RDI */
     170    movq    0x28(%rdx), %rsi        /* restore RSI */
     171    movq    0x30(%rdx), %rbx        /* restore RBX */
     172    movq    0x38(%rdx), %rbp        /* restore RBP */
     173
     174    movq    %gs:(0x30), %r10        /* load NT_TIB */
     175    movq    0x50(%rdx), %rax        /* load stack base */
     176    movq    %rax,       0x08(%r10)  /* restore stack base */
     177    movq    0x60(%rdx), %rax        /* load stack limit */
     178    movq    %rax,       0x10(%r10)  /* restore stack limit */
     179    movq    0x68(%rdx), %rax        /* load fiber local storage */
     180    movq    %rax,       0x18(%r10)  /* restore fiber local storage */
     181
     182    movq    0x40(%rdx), %rsp        /* restore RSP */
     183    movq    0x48(%rdx), %r10        /* fetch the address to returned to */
     184
     185    movq    %r8,        %rax        /* use third arg as return value after jump */
     186    movq    %r8,        %rcx        /* use third arg as first arg in context function */
     187
     188    jmp     *%r10                   /* indirect jump to caller */
     189.seh_endproc