public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Iain Buclaw <ibuclaw@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/users/ibuclaw/heads/darwin)] D, Darwin : OS-specific version of fibre_switchContext.
Date: Sat, 10 Apr 2021 17:01:32 +0000 (GMT)	[thread overview]
Message-ID: <20210410170132.A331A3A0702F@sourceware.org> (raw)

https://gcc.gnu.org/g:d17435597c873aebdfaf14e8bd579ee8e5583113

commit d17435597c873aebdfaf14e8bd579ee8e5583113
Author: Iain Sandoe <iain@sandoe.co.uk>
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 <cet.h>
 #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


             reply	other threads:[~2021-04-10 17:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-10 17:01 Iain Buclaw [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-04-10 15:05 Iain Buclaw
2021-03-14 22:01 Iain Buclaw
2021-03-07 17:02 Iain Buclaw
2021-01-30 19:09 Iain Buclaw
2021-01-28 17:32 Iain Buclaw

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210410170132.A331A3A0702F@sourceware.org \
    --to=ibuclaw@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).