From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1873) id A331A3A0702F; Sat, 10 Apr 2021 17:01:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A331A3A0702F Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Iain Buclaw To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/ibuclaw/heads/darwin)] D, Darwin : OS-specific version of fibre_switchContext. X-Act-Checkin: gcc X-Git-Author: Iain Sandoe X-Git-Refname: refs/users/ibuclaw/heads/darwin X-Git-Oldrev: 48bdd96265011e76dc6905df969124c364d5fff3 X-Git-Newrev: d17435597c873aebdfaf14e8bd579ee8e5583113 Message-Id: <20210410170132.A331A3A0702F@sourceware.org> Date: Sat, 10 Apr 2021 17:01:32 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Apr 2021 17:01:32 -0000 https://gcc.gnu.org/g:d17435597c873aebdfaf14e8bd579ee8e5583113 commit d17435597c873aebdfaf14e8bd579ee8e5583113 Author: Iain Sandoe Date: Thu Dec 10 14:31:10 2020 +0000 D, Darwin : OS-specific version of fibre_switchContext. Cater for Mach-O assemblers in two places: 1/ Use .p2align to make it specific that we have power-of-2 alignment demands. 2/ Provide a CFI and FDE without relying on .cfi_xxxx directives which are not supported by all Darwin's assemblers and are not yet in use for GCC. Diff: --- libphobos/libdruntime/config/x86/switchcontext.S | 160 +++++++++++++++++++++-- 1 file changed, 150 insertions(+), 10 deletions(-) diff --git a/libphobos/libdruntime/config/x86/switchcontext.S b/libphobos/libdruntime/config/x86/switchcontext.S index 8af3f5488ba..86187c938e5 100644 --- a/libphobos/libdruntime/config/x86/switchcontext.S +++ b/libphobos/libdruntime/config/x86/switchcontext.S @@ -29,13 +29,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see # include #endif -#if defined(__i386__) && !defined(__CET__) +#if !defined(__MACH__) +# if defined(__i386__) && !defined(__CET__) .text .globl CSYM(fiber_switchContext) -#if defined(__ELF__) +# if defined(__ELF__) .type CSYM(fiber_switchContext), @function -#endif +# endif .align 16 CSYM(fiber_switchContext): .cfi_startproc @@ -63,17 +64,17 @@ CSYM(fiber_switchContext): // 'return' to complete switch ret .cfi_endproc -#if defined(__ELF__) +# if defined(__ELF__) .size CSYM(fiber_switchContext),.-CSYM(fiber_switchContext) -#endif +# endif -#elif defined(__x86_64__) && !defined(__ILP32__) && !defined(__CET__) +# elif defined(__x86_64__) && !defined(__ILP32__) && !defined(__CET__) .text .globl CSYM(fiber_switchContext) -#if defined(__ELF__) +# if defined(__ELF__) .type CSYM(fiber_switchContext), @function -#endif +# endif .align 16 CSYM(fiber_switchContext): .cfi_startproc @@ -102,8 +103,147 @@ CSYM(fiber_switchContext): // 'return' to complete switch ret .cfi_endproc -#if defined(__ELF__) +# if defined(__ELF__) .size CSYM(fiber_switchContext),.-CSYM(fiber_switchContext) -#endif +# endif +# endif + +#elif !defined(__CET__) /* Mach-O / Darwin without CET. */ + +# if defined(__i386__) + + .text + .globl CSYM(fiber_switchContext) + .p2align 4 +CSYM(fiber_switchContext): +LFB0: + // save current stack state + push %ebp + mov %esp, %ebp + push %edi + push %esi + push %ebx + push %eax + + // store oldp again with more accurate address + mov 8(%ebp), %eax + mov %esp, (%eax) + // load newp to begin context switch + mov 12(%ebp), %esp + + // load saved state from new stack + pop %eax + pop %ebx + pop %esi + pop %edi + pop %ebp + // 'return' to complete switch + ret +LFE0: + +/* CFI */ + .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support +EH_frame1: + .set L$set$0,LECIE1-LSCIE1 + .long L$set$0 # Length of Common Information Entry +LSCIE1: + .long 0 # CIE Identifier Tag + .byte 0x1 # CIE Version + .ascii "zR\0" # CIE Augmentation + .byte 0x1 # uleb128 0x1; CIE Code Alignment Factor + .byte 0x7c # sleb128 -4; CIE Data Alignment Factor + .byte 0x8 # CIE RA Column + .byte 0x1 # uleb128 0x1; Augmentation size + .byte 0x10 # FDE Encoding (pcrel) + .byte 0xc # DW_CFA_def_cfa + .byte 0x5 # uleb128 0x5 + .byte 0x4 # uleb128 0x4 + .byte 0x88 # DW_CFA_offset, column 0x8 + .byte 0x1 # uleb128 0x1 + .p2align 2,0 +LECIE1: + +/* minimal FDE - does not record the stack frame changes. */ +LSFDE1: + .set L$set$1,LEFDE1-LASFDE1 + .long L$set$1 # FDE Length +LASFDE1: + .long LASFDE1-EH_frame1 # FDE CIE offset + .long LFB0-. # FDE initial location + .set L$set$2,LFE0-LFB0 + .long L$set$2 # FDE address range + .byte 0 # uleb128 0; Augmentation size + .p2align 2,0 +LEFDE1: + +# elif defined(__x86_64__) && !defined(__ILP32__) + + .text + .globl CSYM(fiber_switchContext) + .p2align 4 +CSYM(fiber_switchContext): +LFB0: + // Save current stack state.save current stack state + push %rbp + mov %rsp, %rbp + push %r15 + push %r14 + push %r13 + push %r12 + push %rbx + + // store oldp again with more accurate address + mov %rsp, (%rdi) + // load newp to begin context switch + mov %rsi, %rsp + + // load saved state from new stack + pop %rbx + pop %r12 + pop %r13 + pop %r14 + pop %r15 + pop %rbp + + // 'return' to complete switch + ret +LFE0: + +/* CFI */ + .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support +EH_frame1: + .set L$set$0,LECIE1-LSCIE1 + .long L$set$0 # Length of Common Information Entry +LSCIE1: + .long 0 # CIE Identifier Tag + .byte 0x1 # CIE Version + .ascii "zR\0" # CIE Augmentation + .byte 0x1 # uleb128 0x1; CIE Code Alignment Factor + .byte 0x78 # sleb128 -8; CIE Data Alignment Factor + .byte 0x10 # CIE RA Column + .byte 0x1 # uleb128 0x1; Augmentation size + .byte 0x10 # FDE Encoding (pcrel) + .byte 0xc # DW_CFA_def_cfa + .byte 0x7 # uleb128 0x7 + .byte 0x8 # uleb128 0x8 + .byte 0x90 # DW_CFA_offset, column 0x10 + .byte 0x1 # uleb128 0x1 + .p2align 3,0 +LECIE1: + +/* minimal FDE - does not record the stack frame changes. */ +LSFDE1: + .set L$set$1,LEFDE1-LASFDE1 + .long L$set$1 # FDE Length +LASFDE1: + .long LASFDE1-EH_frame1 # FDE CIE offset + .quad LFB0-. # FDE initial location + .set L$set$2,LFE0-LFB0 + .quad L$set$2 # FDE address range + .byte 0 # uleb128 0; Augmentation size + .p2align 3,0 +LEFDE1: + +# endif #endif