public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/ibuclaw/heads/darwin)] D, Darwin, PPC : Implement thread interfaces.
@ 2021-04-19 18:06 Iain Buclaw
  0 siblings, 0 replies; 8+ messages in thread
From: Iain Buclaw @ 2021-04-19 18:06 UTC (permalink / raw)
  To: gcc-cvs

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

commit e39559b4297912145d0a25faa551edfe657837f6
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Fri Dec 11 00:55:38 2020 +0000

    D, Darwin, PPC : Implement thread interfaces.
    
    This provides the implementation for the threads and fibres
    interfaces for PowerPC Darwin (32 and 64 bit).

Diff:
---
 libphobos/libdruntime/core/thread/fiber.d    | 1 +
 libphobos/libdruntime/core/thread/osthread.d | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/libphobos/libdruntime/core/thread/fiber.d b/libphobos/libdruntime/core/thread/fiber.d
index 4ae0d033be1..b61bc065c9c 100644
--- a/libphobos/libdruntime/core/thread/fiber.d
+++ b/libphobos/libdruntime/core/thread/fiber.d
@@ -147,6 +147,7 @@ private
         }
         else version (Posix)
         {
+            version = AsmPPC64_Posix;
             version = AlignFiberStackTo16Byte;
         }
     }
diff --git a/libphobos/libdruntime/core/thread/osthread.d b/libphobos/libdruntime/core/thread/osthread.d
index 31764e69691..238e05a584a 100644
--- a/libphobos/libdruntime/core/thread/osthread.d
+++ b/libphobos/libdruntime/core/thread/osthread.d
@@ -37,6 +37,11 @@ else version (TVOS)
     version = Darwin;
 else version (WatchOS)
     version = Darwin;
+version (Darwin)
+{
+    version (PPC) version = Darwin_AnyPPC;
+    version (PPC64) version = Darwin_AnyPPC;
+}
 
 version (Shared)
     version (GNU)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [gcc(refs/users/ibuclaw/heads/darwin)] D, Darwin, PPC : Implement thread interfaces.
@ 2021-09-17 14:34 Iain Buclaw
  0 siblings, 0 replies; 8+ messages in thread
From: Iain Buclaw @ 2021-09-17 14:34 UTC (permalink / raw)
  To: gcc-cvs

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

commit f9b2cedd1c241c34935e784b75ea6d92ee854e3f
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Fri Dec 11 00:55:38 2020 +0000

    D, Darwin, PPC : Implement thread interfaces.
    
    This provides the implementation for the threads and fibres
    interfaces for PowerPC Darwin (32 and 64 bit).

Diff:
---
 libphobos/libdruntime/core/thread/fiber.d    | 1 +
 libphobos/libdruntime/core/thread/osthread.d | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/libphobos/libdruntime/core/thread/fiber.d b/libphobos/libdruntime/core/thread/fiber.d
index 4ae0d033be1..b61bc065c9c 100644
--- a/libphobos/libdruntime/core/thread/fiber.d
+++ b/libphobos/libdruntime/core/thread/fiber.d
@@ -147,6 +147,7 @@ private
         }
         else version (Posix)
         {
+            version = AsmPPC64_Posix;
             version = AlignFiberStackTo16Byte;
         }
     }
diff --git a/libphobos/libdruntime/core/thread/osthread.d b/libphobos/libdruntime/core/thread/osthread.d
index 9fcd30e50fb..9fe791dbe96 100644
--- a/libphobos/libdruntime/core/thread/osthread.d
+++ b/libphobos/libdruntime/core/thread/osthread.d
@@ -37,6 +37,11 @@ else version (TVOS)
     version = Darwin;
 else version (WatchOS)
     version = Darwin;
+version (Darwin)
+{
+    version (PPC) version = Darwin_AnyPPC;
+    version (PPC64) version = Darwin_AnyPPC;
+}
 
 version (Shared)
     version (GNU)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [gcc(refs/users/ibuclaw/heads/darwin)] D, Darwin, PPC : Implement thread interfaces.
@ 2021-04-10 17:02 Iain Buclaw
  0 siblings, 0 replies; 8+ messages in thread
From: Iain Buclaw @ 2021-04-10 17:02 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:75f0bfd6821869b155937b353d5ed2bf0023d25c

commit 75f0bfd6821869b155937b353d5ed2bf0023d25c
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Fri Dec 11 00:55:38 2020 +0000

    D, Darwin, PPC : Implement thread interfaces.
    
    This provides the implementation for the threads and fibres
    interfaces for PowerPC Darwin (32 and 64 bit).

Diff:
---
 libphobos/libdruntime/core/thread/fiber.d    | 45 +++++++++++++-
 libphobos/libdruntime/core/thread/osthread.d | 92 ++++++++++++++++++++++++++++
 2 files changed, 134 insertions(+), 3 deletions(-)

diff --git a/libphobos/libdruntime/core/thread/fiber.d b/libphobos/libdruntime/core/thread/fiber.d
index 1161914a8a2..ffd3968ef2c 100644
--- a/libphobos/libdruntime/core/thread/fiber.d
+++ b/libphobos/libdruntime/core/thread/fiber.d
@@ -69,7 +69,8 @@ private
     }
     else version (X86)
     {
-        version = AlignFiberStackTo16Byte;
+        version (OSX)
+            version = AlignFiberStackTo16Byte;
 
         version (CET)
         {
@@ -121,7 +122,12 @@ private
     }
     else version (PPC)
     {
-        version (Posix)
+        version (OSX)
+        {
+            version = AlignFiberStackTo16Byte;
+            version = AsmPPC_External_Darwin;
+        }
+        else version (Posix)
         {
             version = AsmPPC_Posix;
             version = AsmExternal;
@@ -129,8 +135,14 @@ private
     }
     else version (PPC64)
     {
-        version (Posix)
+        version (OSX)
+        {
+            version = AlignFiberStackTo16Byte;
+            version = AsmPPC_External_Darwin;
+        }
+        else version (Posix)
         {
+            version = AsmPPC64_Posix;
             version = AlignFiberStackTo16Byte;
         }
     }
@@ -175,6 +187,7 @@ private
         version (AsmX86_Posix)      {} else
         version (AsmX86_64_Windows) {} else
         version (AsmX86_64_Posix)   {} else
+        version (AsmPPC_External_Darwin) {} else
         version (AsmExternal)       {} else
         {
             // NOTE: The ucontext implementation requires architecture specific
@@ -231,6 +244,10 @@ private
       version (AArch64)
           extern (C) void fiber_trampoline() nothrow;
   }
+  else version (AsmPPC_External_Darwin)
+  {
+      extern (C) void fiber_switchContext( void** oldp, void* newp ) nothrow @nogc;
+  }
   else
     extern (C) void fiber_switchContext( void** oldp, void* newp ) nothrow @nogc
     {
@@ -1384,6 +1401,28 @@ private:
 
             assert( (cast(size_t) pstack & 0x0f) == 0 );
         }
+        else version (AsmPPC_External_Darwin)
+        {
+            version (StackGrowsDown) {}
+            else static assert(false, "PowerPC Darwin only supports decrementing stacks");
+
+            uint wsize = size_t.sizeof;
+
+            // linkage + regs + FPRs + VRs
+            uint space = 8 * wsize + 20 * wsize + 18 * 8 + 12 * 16;
+            (cast(ubyte*)pstack - space)[0 .. space] = 0;
+
+            pstack -= wsize * 6;
+            *cast(size_t*)pstack = cast(size_t) &fiber_entryPoint; // LR
+            pstack -= wsize * 22;
+
+            // On Darwin PPC64 pthread self is in R13 (which is reserved).
+            // At present, it is not safe to migrate fibres between threads, but if that
+            // changes, then updating the value of R13 will also need to be handled.
+            version (PPC64)
+              *cast(size_t*)(pstack + wsize) = cast(size_t) Thread.getThis().m_addr;
+            assert( (cast(size_t) pstack & 0x0f) == 0 );
+        }
         else version (AsmMIPS_O32_Posix)
         {
             version (StackGrowsDown) {}
diff --git a/libphobos/libdruntime/core/thread/osthread.d b/libphobos/libdruntime/core/thread/osthread.d
index 282e7b8ac90..de5df33ac7a 100644
--- a/libphobos/libdruntime/core/thread/osthread.d
+++ b/libphobos/libdruntime/core/thread/osthread.d
@@ -37,6 +37,11 @@ else version (TVOS)
     version = Darwin;
 else version (WatchOS)
     version = Darwin;
+version (Darwin)
+{
+    version (PPC) version = Darwin_AnyPPC;
+    version (PPC64) version = Darwin_AnyPPC;
+}
 
 version (Shared)
     version (GNU)
@@ -420,6 +425,17 @@ class Thread : ThreadBase
         {
             uint[16]        m_reg; // r0-r15
         }
+        else version (PPC)
+        {
+            // Make the assumption that we only care about non-fp and non-vr regs.
+            // ??? : it seems plausible that a valid address can be copied into a VR.
+            uint[32]        m_reg; //  r0-31
+        }
+        else version (PPC64)
+        {
+            // As above.
+            ulong[32]       m_reg; // r0-31
+        }
         else
         {
             static assert(false, "Architecture not supported." );
@@ -1429,6 +1445,60 @@ in (fn)
             }
             sp = cast(void*)&regs[0];
         }
+        else version (PPC)
+        {
+            void*[19] regs = void;
+            asm pure nothrow @nogc
+            {
+                "stw r13, %0" : "=m" (regs[ 0]);
+                "stw r14, %0" : "=m" (regs[ 1]);
+                "stw r15, %0" : "=m" (regs[ 2]);
+                "stw r16, %0" : "=m" (regs[ 3]);
+                "stw r17, %0" : "=m" (regs[ 4]);
+                "stw r18, %0" : "=m" (regs[ 5]);
+                "stw r19, %0" : "=m" (regs[ 6]);
+                "stw r20, %0" : "=m" (regs[ 7]);
+                "stw r21, %0" : "=m" (regs[ 9]);
+                "stw r22, %0" : "=m" (regs[ 9]);
+                "stw r23, %0" : "=m" (regs[10]);
+                "stw r24, %0" : "=m" (regs[11]);
+                "stw r25, %0" : "=m" (regs[12]);
+                "stw r26, %0" : "=m" (regs[13]);
+                "stw r27, %0" : "=m" (regs[14]);
+                "stw r28, %0" : "=m" (regs[15]);
+                "stw r29, %0" : "=m" (regs[16]);
+                "stw r30, %0" : "=m" (regs[17]);
+                "stw r31, %0" : "=m" (regs[18]);
+            }
+            sp = cast(void*)&regs[0];
+        }
+        else version (PPC64)
+        {
+            void*[19] regs = void;
+            asm pure nothrow @nogc
+            {
+                "std r13, %0" : "=m" (regs[ 0]);
+                "std r14, %0" : "=m" (regs[ 1]);
+                "std r15, %0" : "=m" (regs[ 2]);
+                "std r16, %0" : "=m" (regs[ 3]);
+                "std r17, %0" : "=m" (regs[ 4]);
+                "std r18, %0" : "=m" (regs[ 5]);
+                "std r19, %0" : "=m" (regs[ 6]);
+                "std r20, %0" : "=m" (regs[ 7]);
+                "std r21, %0" : "=m" (regs[ 8]);
+                "std r22, %0" : "=m" (regs[ 9]);
+                "std r23, %0" : "=m" (regs[10]);
+                "std r24, %0" : "=m" (regs[11]);
+                "std r25, %0" : "=m" (regs[12]);
+                "std r26, %0" : "=m" (regs[13]);
+                "std r27, %0" : "=m" (regs[14]);
+                "std r28, %0" : "=m" (regs[15]);
+                "std r29, %0" : "=m" (regs[16]);
+                "std r30, %0" : "=m" (regs[17]);
+                "std r31, %0" : "=m" (regs[18]);
+            }
+            sp = cast(void*)&regs[0];
+        }
         else
         {
             __builtin_unwind_init();
@@ -1826,6 +1896,28 @@ private extern (D) bool suspend( Thread t ) nothrow @nogc
             t.m_reg[14] = state.lr;
             t.m_reg[15] = state.pc;
         }
+        else version (PPC)
+        {
+            ppc_thread_state_t    state = void;
+            mach_msg_type_number_t  count = PPC_THREAD_STATE_COUNT;
+
+            if ( thread_get_state( t.m_tmach, PPC_THREAD_STATE, &state, &count ) != KERN_SUCCESS )
+                onThreadError( "Unable to load thread state" );
+            if ( !t.m_lock )
+                t.m_curr.tstack = cast(void*) state.r[1];
+            t.m_reg[] = state.r[];
+        }
+        else version (PPC64)
+        {
+            ppc_thread_state64_t    state = void;
+            mach_msg_type_number_t  count = PPC_THREAD_STATE64_COUNT;
+
+            if ( thread_get_state( t.m_tmach, PPC_THREAD_STATE64, &state, &count ) != KERN_SUCCESS )
+                onThreadError( "Unable to load thread state" );
+            if ( !t.m_lock )
+                t.m_curr.tstack = cast(void*) state.r[1];
+            t.m_reg[] = state.r[];
+        }
         else
         {
             static assert(false, "Architecture not supported." );


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [gcc(refs/users/ibuclaw/heads/darwin)] D, Darwin, PPC : Implement thread interfaces.
@ 2021-04-10 15:05 Iain Buclaw
  0 siblings, 0 replies; 8+ messages in thread
From: Iain Buclaw @ 2021-04-10 15:05 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:4f2b5da11d836f669723ad27ea3bb6a9f7523840

commit 4f2b5da11d836f669723ad27ea3bb6a9f7523840
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Fri Dec 11 00:55:38 2020 +0000

    D, Darwin, PPC : Implement thread interfaces.
    
    This provides the implementation for the threads and fibres
    interfaces for PowerPC Darwin (32 and 64 bit).

Diff:
---
 libphobos/libdruntime/core/thread/fiber.d    | 45 +++++++++++++-
 libphobos/libdruntime/core/thread/osthread.d | 92 ++++++++++++++++++++++++++++
 2 files changed, 134 insertions(+), 3 deletions(-)

diff --git a/libphobos/libdruntime/core/thread/fiber.d b/libphobos/libdruntime/core/thread/fiber.d
index 1161914a8a2..ffd3968ef2c 100644
--- a/libphobos/libdruntime/core/thread/fiber.d
+++ b/libphobos/libdruntime/core/thread/fiber.d
@@ -69,7 +69,8 @@ private
     }
     else version (X86)
     {
-        version = AlignFiberStackTo16Byte;
+        version (OSX)
+            version = AlignFiberStackTo16Byte;
 
         version (CET)
         {
@@ -121,7 +122,12 @@ private
     }
     else version (PPC)
     {
-        version (Posix)
+        version (OSX)
+        {
+            version = AlignFiberStackTo16Byte;
+            version = AsmPPC_External_Darwin;
+        }
+        else version (Posix)
         {
             version = AsmPPC_Posix;
             version = AsmExternal;
@@ -129,8 +135,14 @@ private
     }
     else version (PPC64)
     {
-        version (Posix)
+        version (OSX)
+        {
+            version = AlignFiberStackTo16Byte;
+            version = AsmPPC_External_Darwin;
+        }
+        else version (Posix)
         {
+            version = AsmPPC64_Posix;
             version = AlignFiberStackTo16Byte;
         }
     }
@@ -175,6 +187,7 @@ private
         version (AsmX86_Posix)      {} else
         version (AsmX86_64_Windows) {} else
         version (AsmX86_64_Posix)   {} else
+        version (AsmPPC_External_Darwin) {} else
         version (AsmExternal)       {} else
         {
             // NOTE: The ucontext implementation requires architecture specific
@@ -231,6 +244,10 @@ private
       version (AArch64)
           extern (C) void fiber_trampoline() nothrow;
   }
+  else version (AsmPPC_External_Darwin)
+  {
+      extern (C) void fiber_switchContext( void** oldp, void* newp ) nothrow @nogc;
+  }
   else
     extern (C) void fiber_switchContext( void** oldp, void* newp ) nothrow @nogc
     {
@@ -1384,6 +1401,28 @@ private:
 
             assert( (cast(size_t) pstack & 0x0f) == 0 );
         }
+        else version (AsmPPC_External_Darwin)
+        {
+            version (StackGrowsDown) {}
+            else static assert(false, "PowerPC Darwin only supports decrementing stacks");
+
+            uint wsize = size_t.sizeof;
+
+            // linkage + regs + FPRs + VRs
+            uint space = 8 * wsize + 20 * wsize + 18 * 8 + 12 * 16;
+            (cast(ubyte*)pstack - space)[0 .. space] = 0;
+
+            pstack -= wsize * 6;
+            *cast(size_t*)pstack = cast(size_t) &fiber_entryPoint; // LR
+            pstack -= wsize * 22;
+
+            // On Darwin PPC64 pthread self is in R13 (which is reserved).
+            // At present, it is not safe to migrate fibres between threads, but if that
+            // changes, then updating the value of R13 will also need to be handled.
+            version (PPC64)
+              *cast(size_t*)(pstack + wsize) = cast(size_t) Thread.getThis().m_addr;
+            assert( (cast(size_t) pstack & 0x0f) == 0 );
+        }
         else version (AsmMIPS_O32_Posix)
         {
             version (StackGrowsDown) {}
diff --git a/libphobos/libdruntime/core/thread/osthread.d b/libphobos/libdruntime/core/thread/osthread.d
index 282e7b8ac90..de5df33ac7a 100644
--- a/libphobos/libdruntime/core/thread/osthread.d
+++ b/libphobos/libdruntime/core/thread/osthread.d
@@ -37,6 +37,11 @@ else version (TVOS)
     version = Darwin;
 else version (WatchOS)
     version = Darwin;
+version (Darwin)
+{
+    version (PPC) version = Darwin_AnyPPC;
+    version (PPC64) version = Darwin_AnyPPC;
+}
 
 version (Shared)
     version (GNU)
@@ -420,6 +425,17 @@ class Thread : ThreadBase
         {
             uint[16]        m_reg; // r0-r15
         }
+        else version (PPC)
+        {
+            // Make the assumption that we only care about non-fp and non-vr regs.
+            // ??? : it seems plausible that a valid address can be copied into a VR.
+            uint[32]        m_reg; //  r0-31
+        }
+        else version (PPC64)
+        {
+            // As above.
+            ulong[32]       m_reg; // r0-31
+        }
         else
         {
             static assert(false, "Architecture not supported." );
@@ -1429,6 +1445,60 @@ in (fn)
             }
             sp = cast(void*)&regs[0];
         }
+        else version (PPC)
+        {
+            void*[19] regs = void;
+            asm pure nothrow @nogc
+            {
+                "stw r13, %0" : "=m" (regs[ 0]);
+                "stw r14, %0" : "=m" (regs[ 1]);
+                "stw r15, %0" : "=m" (regs[ 2]);
+                "stw r16, %0" : "=m" (regs[ 3]);
+                "stw r17, %0" : "=m" (regs[ 4]);
+                "stw r18, %0" : "=m" (regs[ 5]);
+                "stw r19, %0" : "=m" (regs[ 6]);
+                "stw r20, %0" : "=m" (regs[ 7]);
+                "stw r21, %0" : "=m" (regs[ 9]);
+                "stw r22, %0" : "=m" (regs[ 9]);
+                "stw r23, %0" : "=m" (regs[10]);
+                "stw r24, %0" : "=m" (regs[11]);
+                "stw r25, %0" : "=m" (regs[12]);
+                "stw r26, %0" : "=m" (regs[13]);
+                "stw r27, %0" : "=m" (regs[14]);
+                "stw r28, %0" : "=m" (regs[15]);
+                "stw r29, %0" : "=m" (regs[16]);
+                "stw r30, %0" : "=m" (regs[17]);
+                "stw r31, %0" : "=m" (regs[18]);
+            }
+            sp = cast(void*)&regs[0];
+        }
+        else version (PPC64)
+        {
+            void*[19] regs = void;
+            asm pure nothrow @nogc
+            {
+                "std r13, %0" : "=m" (regs[ 0]);
+                "std r14, %0" : "=m" (regs[ 1]);
+                "std r15, %0" : "=m" (regs[ 2]);
+                "std r16, %0" : "=m" (regs[ 3]);
+                "std r17, %0" : "=m" (regs[ 4]);
+                "std r18, %0" : "=m" (regs[ 5]);
+                "std r19, %0" : "=m" (regs[ 6]);
+                "std r20, %0" : "=m" (regs[ 7]);
+                "std r21, %0" : "=m" (regs[ 8]);
+                "std r22, %0" : "=m" (regs[ 9]);
+                "std r23, %0" : "=m" (regs[10]);
+                "std r24, %0" : "=m" (regs[11]);
+                "std r25, %0" : "=m" (regs[12]);
+                "std r26, %0" : "=m" (regs[13]);
+                "std r27, %0" : "=m" (regs[14]);
+                "std r28, %0" : "=m" (regs[15]);
+                "std r29, %0" : "=m" (regs[16]);
+                "std r30, %0" : "=m" (regs[17]);
+                "std r31, %0" : "=m" (regs[18]);
+            }
+            sp = cast(void*)&regs[0];
+        }
         else
         {
             __builtin_unwind_init();
@@ -1826,6 +1896,28 @@ private extern (D) bool suspend( Thread t ) nothrow @nogc
             t.m_reg[14] = state.lr;
             t.m_reg[15] = state.pc;
         }
+        else version (PPC)
+        {
+            ppc_thread_state_t    state = void;
+            mach_msg_type_number_t  count = PPC_THREAD_STATE_COUNT;
+
+            if ( thread_get_state( t.m_tmach, PPC_THREAD_STATE, &state, &count ) != KERN_SUCCESS )
+                onThreadError( "Unable to load thread state" );
+            if ( !t.m_lock )
+                t.m_curr.tstack = cast(void*) state.r[1];
+            t.m_reg[] = state.r[];
+        }
+        else version (PPC64)
+        {
+            ppc_thread_state64_t    state = void;
+            mach_msg_type_number_t  count = PPC_THREAD_STATE64_COUNT;
+
+            if ( thread_get_state( t.m_tmach, PPC_THREAD_STATE64, &state, &count ) != KERN_SUCCESS )
+                onThreadError( "Unable to load thread state" );
+            if ( !t.m_lock )
+                t.m_curr.tstack = cast(void*) state.r[1];
+            t.m_reg[] = state.r[];
+        }
         else
         {
             static assert(false, "Architecture not supported." );


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [gcc(refs/users/ibuclaw/heads/darwin)] D, Darwin, PPC : Implement thread interfaces.
@ 2021-03-14 22:01 Iain Buclaw
  0 siblings, 0 replies; 8+ messages in thread
From: Iain Buclaw @ 2021-03-14 22:01 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:150aecac91c24187bbb33c6bb4e56b196698dead

commit 150aecac91c24187bbb33c6bb4e56b196698dead
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Fri Dec 11 00:55:38 2020 +0000

    D, Darwin, PPC : Implement thread interfaces.
    
    This provides the implementation for the threads and fibres
    interfaces for PowerPC Darwin (32 and 64 bit).

Diff:
---
 libphobos/libdruntime/core/thread/fiber.d    | 45 +++++++++++++-
 libphobos/libdruntime/core/thread/osthread.d | 92 ++++++++++++++++++++++++++++
 2 files changed, 134 insertions(+), 3 deletions(-)

diff --git a/libphobos/libdruntime/core/thread/fiber.d b/libphobos/libdruntime/core/thread/fiber.d
index 1161914a8a2..ffd3968ef2c 100644
--- a/libphobos/libdruntime/core/thread/fiber.d
+++ b/libphobos/libdruntime/core/thread/fiber.d
@@ -69,7 +69,8 @@ private
     }
     else version (X86)
     {
-        version = AlignFiberStackTo16Byte;
+        version (OSX)
+            version = AlignFiberStackTo16Byte;
 
         version (CET)
         {
@@ -121,7 +122,12 @@ private
     }
     else version (PPC)
     {
-        version (Posix)
+        version (OSX)
+        {
+            version = AlignFiberStackTo16Byte;
+            version = AsmPPC_External_Darwin;
+        }
+        else version (Posix)
         {
             version = AsmPPC_Posix;
             version = AsmExternal;
@@ -129,8 +135,14 @@ private
     }
     else version (PPC64)
     {
-        version (Posix)
+        version (OSX)
+        {
+            version = AlignFiberStackTo16Byte;
+            version = AsmPPC_External_Darwin;
+        }
+        else version (Posix)
         {
+            version = AsmPPC64_Posix;
             version = AlignFiberStackTo16Byte;
         }
     }
@@ -175,6 +187,7 @@ private
         version (AsmX86_Posix)      {} else
         version (AsmX86_64_Windows) {} else
         version (AsmX86_64_Posix)   {} else
+        version (AsmPPC_External_Darwin) {} else
         version (AsmExternal)       {} else
         {
             // NOTE: The ucontext implementation requires architecture specific
@@ -231,6 +244,10 @@ private
       version (AArch64)
           extern (C) void fiber_trampoline() nothrow;
   }
+  else version (AsmPPC_External_Darwin)
+  {
+      extern (C) void fiber_switchContext( void** oldp, void* newp ) nothrow @nogc;
+  }
   else
     extern (C) void fiber_switchContext( void** oldp, void* newp ) nothrow @nogc
     {
@@ -1384,6 +1401,28 @@ private:
 
             assert( (cast(size_t) pstack & 0x0f) == 0 );
         }
+        else version (AsmPPC_External_Darwin)
+        {
+            version (StackGrowsDown) {}
+            else static assert(false, "PowerPC Darwin only supports decrementing stacks");
+
+            uint wsize = size_t.sizeof;
+
+            // linkage + regs + FPRs + VRs
+            uint space = 8 * wsize + 20 * wsize + 18 * 8 + 12 * 16;
+            (cast(ubyte*)pstack - space)[0 .. space] = 0;
+
+            pstack -= wsize * 6;
+            *cast(size_t*)pstack = cast(size_t) &fiber_entryPoint; // LR
+            pstack -= wsize * 22;
+
+            // On Darwin PPC64 pthread self is in R13 (which is reserved).
+            // At present, it is not safe to migrate fibres between threads, but if that
+            // changes, then updating the value of R13 will also need to be handled.
+            version (PPC64)
+              *cast(size_t*)(pstack + wsize) = cast(size_t) Thread.getThis().m_addr;
+            assert( (cast(size_t) pstack & 0x0f) == 0 );
+        }
         else version (AsmMIPS_O32_Posix)
         {
             version (StackGrowsDown) {}
diff --git a/libphobos/libdruntime/core/thread/osthread.d b/libphobos/libdruntime/core/thread/osthread.d
index 316ba92c391..2b29cdc4ea4 100644
--- a/libphobos/libdruntime/core/thread/osthread.d
+++ b/libphobos/libdruntime/core/thread/osthread.d
@@ -37,6 +37,11 @@ else version (TVOS)
     version = Darwin;
 else version (WatchOS)
     version = Darwin;
+version (Darwin)
+{
+    version (PPC) version = Darwin_AnyPPC;
+    version (PPC64) version = Darwin_AnyPPC;
+}
 
 version (Shared)
     version (GNU)
@@ -420,6 +425,17 @@ class Thread : ThreadBase
         {
             uint[16]        m_reg; // r0-r15
         }
+        else version (PPC)
+        {
+            // Make the assumption that we only care about non-fp and non-vr regs.
+            // ??? : it seems plausible that a valid address can be copied into a VR.
+            uint[32]        m_reg; //  r0-31
+        }
+        else version (PPC64)
+        {
+            // As above.
+            ulong[32]       m_reg; // r0-31
+        }
         else
         {
             static assert(false, "Architecture not supported." );
@@ -1429,6 +1445,60 @@ in (fn)
             }
             sp = cast(void*)&regs[0];
         }
+        else version (PPC)
+        {
+            void*[19] regs = void;
+            asm pure nothrow @nogc
+            {
+                "stw r13, %0" : "=m" (regs[ 0]);
+                "stw r14, %0" : "=m" (regs[ 1]);
+                "stw r15, %0" : "=m" (regs[ 2]);
+                "stw r16, %0" : "=m" (regs[ 3]);
+                "stw r17, %0" : "=m" (regs[ 4]);
+                "stw r18, %0" : "=m" (regs[ 5]);
+                "stw r19, %0" : "=m" (regs[ 6]);
+                "stw r20, %0" : "=m" (regs[ 7]);
+                "stw r21, %0" : "=m" (regs[ 9]);
+                "stw r22, %0" : "=m" (regs[ 9]);
+                "stw r23, %0" : "=m" (regs[10]);
+                "stw r24, %0" : "=m" (regs[11]);
+                "stw r25, %0" : "=m" (regs[12]);
+                "stw r26, %0" : "=m" (regs[13]);
+                "stw r27, %0" : "=m" (regs[14]);
+                "stw r28, %0" : "=m" (regs[15]);
+                "stw r29, %0" : "=m" (regs[16]);
+                "stw r30, %0" : "=m" (regs[17]);
+                "stw r31, %0" : "=m" (regs[18]);
+            }
+            sp = cast(void*)&regs[0];
+        }
+        else version (PPC64)
+        {
+            void*[19] regs = void;
+            asm pure nothrow @nogc
+            {
+                "std r13, %0" : "=m" (regs[ 0]);
+                "std r14, %0" : "=m" (regs[ 1]);
+                "std r15, %0" : "=m" (regs[ 2]);
+                "std r16, %0" : "=m" (regs[ 3]);
+                "std r17, %0" : "=m" (regs[ 4]);
+                "std r18, %0" : "=m" (regs[ 5]);
+                "std r19, %0" : "=m" (regs[ 6]);
+                "std r20, %0" : "=m" (regs[ 7]);
+                "std r21, %0" : "=m" (regs[ 8]);
+                "std r22, %0" : "=m" (regs[ 9]);
+                "std r23, %0" : "=m" (regs[10]);
+                "std r24, %0" : "=m" (regs[11]);
+                "std r25, %0" : "=m" (regs[12]);
+                "std r26, %0" : "=m" (regs[13]);
+                "std r27, %0" : "=m" (regs[14]);
+                "std r28, %0" : "=m" (regs[15]);
+                "std r29, %0" : "=m" (regs[16]);
+                "std r30, %0" : "=m" (regs[17]);
+                "std r31, %0" : "=m" (regs[18]);
+            }
+            sp = cast(void*)&regs[0];
+        }
         else
         {
             __builtin_unwind_init();
@@ -1826,6 +1896,28 @@ private extern (D) bool suspend( Thread t ) nothrow @nogc
             t.m_reg[14] = state.lr;
             t.m_reg[15] = state.pc;
         }
+        else version (PPC)
+        {
+            ppc_thread_state_t    state = void;
+            mach_msg_type_number_t  count = PPC_THREAD_STATE_COUNT;
+
+            if ( thread_get_state( t.m_tmach, PPC_THREAD_STATE, &state, &count ) != KERN_SUCCESS )
+                onThreadError( "Unable to load thread state" );
+            if ( !t.m_lock )
+                t.m_curr.tstack = cast(void*) state.r[1];
+            t.m_reg[] = state.r[];
+        }
+        else version (PPC64)
+        {
+            ppc_thread_state64_t    state = void;
+            mach_msg_type_number_t  count = PPC_THREAD_STATE64_COUNT;
+
+            if ( thread_get_state( t.m_tmach, PPC_THREAD_STATE64, &state, &count ) != KERN_SUCCESS )
+                onThreadError( "Unable to load thread state" );
+            if ( !t.m_lock )
+                t.m_curr.tstack = cast(void*) state.r[1];
+            t.m_reg[] = state.r[];
+        }
         else
         {
             static assert(false, "Architecture not supported." );


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [gcc(refs/users/ibuclaw/heads/darwin)] D, Darwin, PPC : Implement thread interfaces.
@ 2021-03-07 17:02 Iain Buclaw
  0 siblings, 0 replies; 8+ messages in thread
From: Iain Buclaw @ 2021-03-07 17:02 UTC (permalink / raw)
  To: gcc-cvs

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

commit dd718cbcbe57939faf7efdd5869c609801ba1b4c
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Fri Dec 11 00:55:38 2020 +0000

    D, Darwin, PPC : Implement thread interfaces.
    
    This provides the implementation for the threads and fibres
    interfaces for PowerPC Darwin (32 and 64 bit).

Diff:
---
 libphobos/libdruntime/core/thread/fiber.d    | 45 +++++++++++++-
 libphobos/libdruntime/core/thread/osthread.d | 92 ++++++++++++++++++++++++++++
 2 files changed, 134 insertions(+), 3 deletions(-)

diff --git a/libphobos/libdruntime/core/thread/fiber.d b/libphobos/libdruntime/core/thread/fiber.d
index 1161914a8a2..ffd3968ef2c 100644
--- a/libphobos/libdruntime/core/thread/fiber.d
+++ b/libphobos/libdruntime/core/thread/fiber.d
@@ -69,7 +69,8 @@ private
     }
     else version (X86)
     {
-        version = AlignFiberStackTo16Byte;
+        version (OSX)
+            version = AlignFiberStackTo16Byte;
 
         version (CET)
         {
@@ -121,7 +122,12 @@ private
     }
     else version (PPC)
     {
-        version (Posix)
+        version (OSX)
+        {
+            version = AlignFiberStackTo16Byte;
+            version = AsmPPC_External_Darwin;
+        }
+        else version (Posix)
         {
             version = AsmPPC_Posix;
             version = AsmExternal;
@@ -129,8 +135,14 @@ private
     }
     else version (PPC64)
     {
-        version (Posix)
+        version (OSX)
+        {
+            version = AlignFiberStackTo16Byte;
+            version = AsmPPC_External_Darwin;
+        }
+        else version (Posix)
         {
+            version = AsmPPC64_Posix;
             version = AlignFiberStackTo16Byte;
         }
     }
@@ -175,6 +187,7 @@ private
         version (AsmX86_Posix)      {} else
         version (AsmX86_64_Windows) {} else
         version (AsmX86_64_Posix)   {} else
+        version (AsmPPC_External_Darwin) {} else
         version (AsmExternal)       {} else
         {
             // NOTE: The ucontext implementation requires architecture specific
@@ -231,6 +244,10 @@ private
       version (AArch64)
           extern (C) void fiber_trampoline() nothrow;
   }
+  else version (AsmPPC_External_Darwin)
+  {
+      extern (C) void fiber_switchContext( void** oldp, void* newp ) nothrow @nogc;
+  }
   else
     extern (C) void fiber_switchContext( void** oldp, void* newp ) nothrow @nogc
     {
@@ -1384,6 +1401,28 @@ private:
 
             assert( (cast(size_t) pstack & 0x0f) == 0 );
         }
+        else version (AsmPPC_External_Darwin)
+        {
+            version (StackGrowsDown) {}
+            else static assert(false, "PowerPC Darwin only supports decrementing stacks");
+
+            uint wsize = size_t.sizeof;
+
+            // linkage + regs + FPRs + VRs
+            uint space = 8 * wsize + 20 * wsize + 18 * 8 + 12 * 16;
+            (cast(ubyte*)pstack - space)[0 .. space] = 0;
+
+            pstack -= wsize * 6;
+            *cast(size_t*)pstack = cast(size_t) &fiber_entryPoint; // LR
+            pstack -= wsize * 22;
+
+            // On Darwin PPC64 pthread self is in R13 (which is reserved).
+            // At present, it is not safe to migrate fibres between threads, but if that
+            // changes, then updating the value of R13 will also need to be handled.
+            version (PPC64)
+              *cast(size_t*)(pstack + wsize) = cast(size_t) Thread.getThis().m_addr;
+            assert( (cast(size_t) pstack & 0x0f) == 0 );
+        }
         else version (AsmMIPS_O32_Posix)
         {
             version (StackGrowsDown) {}
diff --git a/libphobos/libdruntime/core/thread/osthread.d b/libphobos/libdruntime/core/thread/osthread.d
index 316ba92c391..2b29cdc4ea4 100644
--- a/libphobos/libdruntime/core/thread/osthread.d
+++ b/libphobos/libdruntime/core/thread/osthread.d
@@ -37,6 +37,11 @@ else version (TVOS)
     version = Darwin;
 else version (WatchOS)
     version = Darwin;
+version (Darwin)
+{
+    version (PPC) version = Darwin_AnyPPC;
+    version (PPC64) version = Darwin_AnyPPC;
+}
 
 version (Shared)
     version (GNU)
@@ -420,6 +425,17 @@ class Thread : ThreadBase
         {
             uint[16]        m_reg; // r0-r15
         }
+        else version (PPC)
+        {
+            // Make the assumption that we only care about non-fp and non-vr regs.
+            // ??? : it seems plausible that a valid address can be copied into a VR.
+            uint[32]        m_reg; //  r0-31
+        }
+        else version (PPC64)
+        {
+            // As above.
+            ulong[32]       m_reg; // r0-31
+        }
         else
         {
             static assert(false, "Architecture not supported." );
@@ -1429,6 +1445,60 @@ in (fn)
             }
             sp = cast(void*)&regs[0];
         }
+        else version (PPC)
+        {
+            void*[19] regs = void;
+            asm pure nothrow @nogc
+            {
+                "stw r13, %0" : "=m" (regs[ 0]);
+                "stw r14, %0" : "=m" (regs[ 1]);
+                "stw r15, %0" : "=m" (regs[ 2]);
+                "stw r16, %0" : "=m" (regs[ 3]);
+                "stw r17, %0" : "=m" (regs[ 4]);
+                "stw r18, %0" : "=m" (regs[ 5]);
+                "stw r19, %0" : "=m" (regs[ 6]);
+                "stw r20, %0" : "=m" (regs[ 7]);
+                "stw r21, %0" : "=m" (regs[ 9]);
+                "stw r22, %0" : "=m" (regs[ 9]);
+                "stw r23, %0" : "=m" (regs[10]);
+                "stw r24, %0" : "=m" (regs[11]);
+                "stw r25, %0" : "=m" (regs[12]);
+                "stw r26, %0" : "=m" (regs[13]);
+                "stw r27, %0" : "=m" (regs[14]);
+                "stw r28, %0" : "=m" (regs[15]);
+                "stw r29, %0" : "=m" (regs[16]);
+                "stw r30, %0" : "=m" (regs[17]);
+                "stw r31, %0" : "=m" (regs[18]);
+            }
+            sp = cast(void*)&regs[0];
+        }
+        else version (PPC64)
+        {
+            void*[19] regs = void;
+            asm pure nothrow @nogc
+            {
+                "std r13, %0" : "=m" (regs[ 0]);
+                "std r14, %0" : "=m" (regs[ 1]);
+                "std r15, %0" : "=m" (regs[ 2]);
+                "std r16, %0" : "=m" (regs[ 3]);
+                "std r17, %0" : "=m" (regs[ 4]);
+                "std r18, %0" : "=m" (regs[ 5]);
+                "std r19, %0" : "=m" (regs[ 6]);
+                "std r20, %0" : "=m" (regs[ 7]);
+                "std r21, %0" : "=m" (regs[ 8]);
+                "std r22, %0" : "=m" (regs[ 9]);
+                "std r23, %0" : "=m" (regs[10]);
+                "std r24, %0" : "=m" (regs[11]);
+                "std r25, %0" : "=m" (regs[12]);
+                "std r26, %0" : "=m" (regs[13]);
+                "std r27, %0" : "=m" (regs[14]);
+                "std r28, %0" : "=m" (regs[15]);
+                "std r29, %0" : "=m" (regs[16]);
+                "std r30, %0" : "=m" (regs[17]);
+                "std r31, %0" : "=m" (regs[18]);
+            }
+            sp = cast(void*)&regs[0];
+        }
         else
         {
             __builtin_unwind_init();
@@ -1826,6 +1896,28 @@ private extern (D) bool suspend( Thread t ) nothrow @nogc
             t.m_reg[14] = state.lr;
             t.m_reg[15] = state.pc;
         }
+        else version (PPC)
+        {
+            ppc_thread_state_t    state = void;
+            mach_msg_type_number_t  count = PPC_THREAD_STATE_COUNT;
+
+            if ( thread_get_state( t.m_tmach, PPC_THREAD_STATE, &state, &count ) != KERN_SUCCESS )
+                onThreadError( "Unable to load thread state" );
+            if ( !t.m_lock )
+                t.m_curr.tstack = cast(void*) state.r[1];
+            t.m_reg[] = state.r[];
+        }
+        else version (PPC64)
+        {
+            ppc_thread_state64_t    state = void;
+            mach_msg_type_number_t  count = PPC_THREAD_STATE64_COUNT;
+
+            if ( thread_get_state( t.m_tmach, PPC_THREAD_STATE64, &state, &count ) != KERN_SUCCESS )
+                onThreadError( "Unable to load thread state" );
+            if ( !t.m_lock )
+                t.m_curr.tstack = cast(void*) state.r[1];
+            t.m_reg[] = state.r[];
+        }
         else
         {
             static assert(false, "Architecture not supported." );


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [gcc(refs/users/ibuclaw/heads/darwin)] D, Darwin, PPC : Implement thread interfaces.
@ 2021-01-30 19:10 Iain Buclaw
  0 siblings, 0 replies; 8+ messages in thread
From: Iain Buclaw @ 2021-01-30 19:10 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:7b5f7c1ad8cf21d1a0a327b26bb41cb5368a9dff

commit 7b5f7c1ad8cf21d1a0a327b26bb41cb5368a9dff
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Fri Dec 11 00:55:38 2020 +0000

    D, Darwin, PPC : Implement thread interfaces.
    
    This provides the implementation for the threads and fibres
    interfaces for PowerPC Darwin (32 and 64 bit).

Diff:
---
 libphobos/libdruntime/core/thread/fiber.d    | 45 +++++++++++++-
 libphobos/libdruntime/core/thread/osthread.d | 92 ++++++++++++++++++++++++++++
 2 files changed, 134 insertions(+), 3 deletions(-)

diff --git a/libphobos/libdruntime/core/thread/fiber.d b/libphobos/libdruntime/core/thread/fiber.d
index 1161914a8a2..ffd3968ef2c 100644
--- a/libphobos/libdruntime/core/thread/fiber.d
+++ b/libphobos/libdruntime/core/thread/fiber.d
@@ -69,7 +69,8 @@ private
     }
     else version (X86)
     {
-        version = AlignFiberStackTo16Byte;
+        version (OSX)
+            version = AlignFiberStackTo16Byte;
 
         version (CET)
         {
@@ -121,7 +122,12 @@ private
     }
     else version (PPC)
     {
-        version (Posix)
+        version (OSX)
+        {
+            version = AlignFiberStackTo16Byte;
+            version = AsmPPC_External_Darwin;
+        }
+        else version (Posix)
         {
             version = AsmPPC_Posix;
             version = AsmExternal;
@@ -129,8 +135,14 @@ private
     }
     else version (PPC64)
     {
-        version (Posix)
+        version (OSX)
+        {
+            version = AlignFiberStackTo16Byte;
+            version = AsmPPC_External_Darwin;
+        }
+        else version (Posix)
         {
+            version = AsmPPC64_Posix;
             version = AlignFiberStackTo16Byte;
         }
     }
@@ -175,6 +187,7 @@ private
         version (AsmX86_Posix)      {} else
         version (AsmX86_64_Windows) {} else
         version (AsmX86_64_Posix)   {} else
+        version (AsmPPC_External_Darwin) {} else
         version (AsmExternal)       {} else
         {
             // NOTE: The ucontext implementation requires architecture specific
@@ -231,6 +244,10 @@ private
       version (AArch64)
           extern (C) void fiber_trampoline() nothrow;
   }
+  else version (AsmPPC_External_Darwin)
+  {
+      extern (C) void fiber_switchContext( void** oldp, void* newp ) nothrow @nogc;
+  }
   else
     extern (C) void fiber_switchContext( void** oldp, void* newp ) nothrow @nogc
     {
@@ -1384,6 +1401,28 @@ private:
 
             assert( (cast(size_t) pstack & 0x0f) == 0 );
         }
+        else version (AsmPPC_External_Darwin)
+        {
+            version (StackGrowsDown) {}
+            else static assert(false, "PowerPC Darwin only supports decrementing stacks");
+
+            uint wsize = size_t.sizeof;
+
+            // linkage + regs + FPRs + VRs
+            uint space = 8 * wsize + 20 * wsize + 18 * 8 + 12 * 16;
+            (cast(ubyte*)pstack - space)[0 .. space] = 0;
+
+            pstack -= wsize * 6;
+            *cast(size_t*)pstack = cast(size_t) &fiber_entryPoint; // LR
+            pstack -= wsize * 22;
+
+            // On Darwin PPC64 pthread self is in R13 (which is reserved).
+            // At present, it is not safe to migrate fibres between threads, but if that
+            // changes, then updating the value of R13 will also need to be handled.
+            version (PPC64)
+              *cast(size_t*)(pstack + wsize) = cast(size_t) Thread.getThis().m_addr;
+            assert( (cast(size_t) pstack & 0x0f) == 0 );
+        }
         else version (AsmMIPS_O32_Posix)
         {
             version (StackGrowsDown) {}
diff --git a/libphobos/libdruntime/core/thread/osthread.d b/libphobos/libdruntime/core/thread/osthread.d
index 1fb4af34414..a61b2d8389f 100644
--- a/libphobos/libdruntime/core/thread/osthread.d
+++ b/libphobos/libdruntime/core/thread/osthread.d
@@ -37,6 +37,11 @@ else version (TVOS)
     version = Darwin;
 else version (WatchOS)
     version = Darwin;
+version (Darwin)
+{
+    version (PPC) version = Darwin_AnyPPC;
+    version (PPC64) version = Darwin_AnyPPC;
+}
 
 version (Shared)
     version (GNU)
@@ -420,6 +425,17 @@ class Thread : ThreadBase
         {
             uint[16]        m_reg; // r0-r15
         }
+        else version (PPC)
+        {
+            // Make the assumption that we only care about non-fp and non-vr regs.
+            // ??? : it seems plausible that a valid address can be copied into a VR.
+            uint[32]        m_reg; //  r0-31
+        }
+        else version (PPC64)
+        {
+            // As above.
+            ulong[32]       m_reg; // r0-31
+        }
         else
         {
             static assert(false, "Architecture not supported." );
@@ -1429,6 +1445,60 @@ in (fn)
             }
             sp = cast(void*)&regs[0];
         }
+        else version (PPC)
+        {
+            void*[19] regs = void;
+            asm pure nothrow @nogc
+            {
+                "stw r13, %0" : "=m" (regs[ 0]);
+                "stw r14, %0" : "=m" (regs[ 1]);
+                "stw r15, %0" : "=m" (regs[ 2]);
+                "stw r16, %0" : "=m" (regs[ 3]);
+                "stw r17, %0" : "=m" (regs[ 4]);
+                "stw r18, %0" : "=m" (regs[ 5]);
+                "stw r19, %0" : "=m" (regs[ 6]);
+                "stw r20, %0" : "=m" (regs[ 7]);
+                "stw r21, %0" : "=m" (regs[ 9]);
+                "stw r22, %0" : "=m" (regs[ 9]);
+                "stw r23, %0" : "=m" (regs[10]);
+                "stw r24, %0" : "=m" (regs[11]);
+                "stw r25, %0" : "=m" (regs[12]);
+                "stw r26, %0" : "=m" (regs[13]);
+                "stw r27, %0" : "=m" (regs[14]);
+                "stw r28, %0" : "=m" (regs[15]);
+                "stw r29, %0" : "=m" (regs[16]);
+                "stw r30, %0" : "=m" (regs[17]);
+                "stw r31, %0" : "=m" (regs[18]);
+            }
+            sp = cast(void*)&regs[0];
+        }
+        else version (PPC64)
+        {
+            void*[19] regs = void;
+            asm pure nothrow @nogc
+            {
+                "std r13, %0" : "=m" (regs[ 0]);
+                "std r14, %0" : "=m" (regs[ 1]);
+                "std r15, %0" : "=m" (regs[ 2]);
+                "std r16, %0" : "=m" (regs[ 3]);
+                "std r17, %0" : "=m" (regs[ 4]);
+                "std r18, %0" : "=m" (regs[ 5]);
+                "std r19, %0" : "=m" (regs[ 6]);
+                "std r20, %0" : "=m" (regs[ 7]);
+                "std r21, %0" : "=m" (regs[ 8]);
+                "std r22, %0" : "=m" (regs[ 9]);
+                "std r23, %0" : "=m" (regs[10]);
+                "std r24, %0" : "=m" (regs[11]);
+                "std r25, %0" : "=m" (regs[12]);
+                "std r26, %0" : "=m" (regs[13]);
+                "std r27, %0" : "=m" (regs[14]);
+                "std r28, %0" : "=m" (regs[15]);
+                "std r29, %0" : "=m" (regs[16]);
+                "std r30, %0" : "=m" (regs[17]);
+                "std r31, %0" : "=m" (regs[18]);
+            }
+            sp = cast(void*)&regs[0];
+        }
         else
         {
             __builtin_unwind_init();
@@ -1834,6 +1904,28 @@ private extern (D) bool suspend( Thread t ) nothrow @nogc
             t.m_reg[14] = state.lr;
             t.m_reg[15] = state.pc;
         }
+        else version (PPC)
+        {
+            ppc_thread_state_t    state = void;
+            mach_msg_type_number_t  count = PPC_THREAD_STATE_COUNT;
+
+            if ( thread_get_state( t.m_tmach, PPC_THREAD_STATE, &state, &count ) != KERN_SUCCESS )
+                onThreadError( "Unable to load thread state" );
+            if ( !t.m_lock )
+                t.m_curr.tstack = cast(void*) state.r[1];
+            t.m_reg[] = state.r[];
+        }
+        else version (PPC64)
+        {
+            ppc_thread_state64_t    state = void;
+            mach_msg_type_number_t  count = PPC_THREAD_STATE64_COUNT;
+
+            if ( thread_get_state( t.m_tmach, PPC_THREAD_STATE64, &state, &count ) != KERN_SUCCESS )
+                onThreadError( "Unable to load thread state" );
+            if ( !t.m_lock )
+                t.m_curr.tstack = cast(void*) state.r[1];
+            t.m_reg[] = state.r[];
+        }
         else
         {
             static assert(false, "Architecture not supported." );


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [gcc(refs/users/ibuclaw/heads/darwin)] D, Darwin, PPC : Implement thread interfaces.
@ 2021-01-28 17:33 Iain Buclaw
  0 siblings, 0 replies; 8+ messages in thread
From: Iain Buclaw @ 2021-01-28 17:33 UTC (permalink / raw)
  To: gcc-cvs

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

commit cdfa8f519a7b028e5a5dffff9f347152f5c089a1
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Fri Dec 11 00:55:38 2020 +0000

    D, Darwin, PPC : Implement thread interfaces.
    
    This provides the implementation for the threads and fibres
    interfaces for PowerPC Darwin (32 and 64 bit).

Diff:
---
 libphobos/libdruntime/core/thread/fiber.d    | 45 +++++++++++++-
 libphobos/libdruntime/core/thread/osthread.d | 92 ++++++++++++++++++++++++++++
 2 files changed, 134 insertions(+), 3 deletions(-)

diff --git a/libphobos/libdruntime/core/thread/fiber.d b/libphobos/libdruntime/core/thread/fiber.d
index 1161914a8a2..ffd3968ef2c 100644
--- a/libphobos/libdruntime/core/thread/fiber.d
+++ b/libphobos/libdruntime/core/thread/fiber.d
@@ -69,7 +69,8 @@ private
     }
     else version (X86)
     {
-        version = AlignFiberStackTo16Byte;
+        version (OSX)
+            version = AlignFiberStackTo16Byte;
 
         version (CET)
         {
@@ -121,7 +122,12 @@ private
     }
     else version (PPC)
     {
-        version (Posix)
+        version (OSX)
+        {
+            version = AlignFiberStackTo16Byte;
+            version = AsmPPC_External_Darwin;
+        }
+        else version (Posix)
         {
             version = AsmPPC_Posix;
             version = AsmExternal;
@@ -129,8 +135,14 @@ private
     }
     else version (PPC64)
     {
-        version (Posix)
+        version (OSX)
+        {
+            version = AlignFiberStackTo16Byte;
+            version = AsmPPC_External_Darwin;
+        }
+        else version (Posix)
         {
+            version = AsmPPC64_Posix;
             version = AlignFiberStackTo16Byte;
         }
     }
@@ -175,6 +187,7 @@ private
         version (AsmX86_Posix)      {} else
         version (AsmX86_64_Windows) {} else
         version (AsmX86_64_Posix)   {} else
+        version (AsmPPC_External_Darwin) {} else
         version (AsmExternal)       {} else
         {
             // NOTE: The ucontext implementation requires architecture specific
@@ -231,6 +244,10 @@ private
       version (AArch64)
           extern (C) void fiber_trampoline() nothrow;
   }
+  else version (AsmPPC_External_Darwin)
+  {
+      extern (C) void fiber_switchContext( void** oldp, void* newp ) nothrow @nogc;
+  }
   else
     extern (C) void fiber_switchContext( void** oldp, void* newp ) nothrow @nogc
     {
@@ -1384,6 +1401,28 @@ private:
 
             assert( (cast(size_t) pstack & 0x0f) == 0 );
         }
+        else version (AsmPPC_External_Darwin)
+        {
+            version (StackGrowsDown) {}
+            else static assert(false, "PowerPC Darwin only supports decrementing stacks");
+
+            uint wsize = size_t.sizeof;
+
+            // linkage + regs + FPRs + VRs
+            uint space = 8 * wsize + 20 * wsize + 18 * 8 + 12 * 16;
+            (cast(ubyte*)pstack - space)[0 .. space] = 0;
+
+            pstack -= wsize * 6;
+            *cast(size_t*)pstack = cast(size_t) &fiber_entryPoint; // LR
+            pstack -= wsize * 22;
+
+            // On Darwin PPC64 pthread self is in R13 (which is reserved).
+            // At present, it is not safe to migrate fibres between threads, but if that
+            // changes, then updating the value of R13 will also need to be handled.
+            version (PPC64)
+              *cast(size_t*)(pstack + wsize) = cast(size_t) Thread.getThis().m_addr;
+            assert( (cast(size_t) pstack & 0x0f) == 0 );
+        }
         else version (AsmMIPS_O32_Posix)
         {
             version (StackGrowsDown) {}
diff --git a/libphobos/libdruntime/core/thread/osthread.d b/libphobos/libdruntime/core/thread/osthread.d
index 1fb4af34414..a61b2d8389f 100644
--- a/libphobos/libdruntime/core/thread/osthread.d
+++ b/libphobos/libdruntime/core/thread/osthread.d
@@ -37,6 +37,11 @@ else version (TVOS)
     version = Darwin;
 else version (WatchOS)
     version = Darwin;
+version (Darwin)
+{
+    version (PPC) version = Darwin_AnyPPC;
+    version (PPC64) version = Darwin_AnyPPC;
+}
 
 version (Shared)
     version (GNU)
@@ -420,6 +425,17 @@ class Thread : ThreadBase
         {
             uint[16]        m_reg; // r0-r15
         }
+        else version (PPC)
+        {
+            // Make the assumption that we only care about non-fp and non-vr regs.
+            // ??? : it seems plausible that a valid address can be copied into a VR.
+            uint[32]        m_reg; //  r0-31
+        }
+        else version (PPC64)
+        {
+            // As above.
+            ulong[32]       m_reg; // r0-31
+        }
         else
         {
             static assert(false, "Architecture not supported." );
@@ -1429,6 +1445,60 @@ in (fn)
             }
             sp = cast(void*)&regs[0];
         }
+        else version (PPC)
+        {
+            void*[19] regs = void;
+            asm pure nothrow @nogc
+            {
+                "stw r13, %0" : "=m" (regs[ 0]);
+                "stw r14, %0" : "=m" (regs[ 1]);
+                "stw r15, %0" : "=m" (regs[ 2]);
+                "stw r16, %0" : "=m" (regs[ 3]);
+                "stw r17, %0" : "=m" (regs[ 4]);
+                "stw r18, %0" : "=m" (regs[ 5]);
+                "stw r19, %0" : "=m" (regs[ 6]);
+                "stw r20, %0" : "=m" (regs[ 7]);
+                "stw r21, %0" : "=m" (regs[ 9]);
+                "stw r22, %0" : "=m" (regs[ 9]);
+                "stw r23, %0" : "=m" (regs[10]);
+                "stw r24, %0" : "=m" (regs[11]);
+                "stw r25, %0" : "=m" (regs[12]);
+                "stw r26, %0" : "=m" (regs[13]);
+                "stw r27, %0" : "=m" (regs[14]);
+                "stw r28, %0" : "=m" (regs[15]);
+                "stw r29, %0" : "=m" (regs[16]);
+                "stw r30, %0" : "=m" (regs[17]);
+                "stw r31, %0" : "=m" (regs[18]);
+            }
+            sp = cast(void*)&regs[0];
+        }
+        else version (PPC64)
+        {
+            void*[19] regs = void;
+            asm pure nothrow @nogc
+            {
+                "std r13, %0" : "=m" (regs[ 0]);
+                "std r14, %0" : "=m" (regs[ 1]);
+                "std r15, %0" : "=m" (regs[ 2]);
+                "std r16, %0" : "=m" (regs[ 3]);
+                "std r17, %0" : "=m" (regs[ 4]);
+                "std r18, %0" : "=m" (regs[ 5]);
+                "std r19, %0" : "=m" (regs[ 6]);
+                "std r20, %0" : "=m" (regs[ 7]);
+                "std r21, %0" : "=m" (regs[ 8]);
+                "std r22, %0" : "=m" (regs[ 9]);
+                "std r23, %0" : "=m" (regs[10]);
+                "std r24, %0" : "=m" (regs[11]);
+                "std r25, %0" : "=m" (regs[12]);
+                "std r26, %0" : "=m" (regs[13]);
+                "std r27, %0" : "=m" (regs[14]);
+                "std r28, %0" : "=m" (regs[15]);
+                "std r29, %0" : "=m" (regs[16]);
+                "std r30, %0" : "=m" (regs[17]);
+                "std r31, %0" : "=m" (regs[18]);
+            }
+            sp = cast(void*)&regs[0];
+        }
         else
         {
             __builtin_unwind_init();
@@ -1834,6 +1904,28 @@ private extern (D) bool suspend( Thread t ) nothrow @nogc
             t.m_reg[14] = state.lr;
             t.m_reg[15] = state.pc;
         }
+        else version (PPC)
+        {
+            ppc_thread_state_t    state = void;
+            mach_msg_type_number_t  count = PPC_THREAD_STATE_COUNT;
+
+            if ( thread_get_state( t.m_tmach, PPC_THREAD_STATE, &state, &count ) != KERN_SUCCESS )
+                onThreadError( "Unable to load thread state" );
+            if ( !t.m_lock )
+                t.m_curr.tstack = cast(void*) state.r[1];
+            t.m_reg[] = state.r[];
+        }
+        else version (PPC64)
+        {
+            ppc_thread_state64_t    state = void;
+            mach_msg_type_number_t  count = PPC_THREAD_STATE64_COUNT;
+
+            if ( thread_get_state( t.m_tmach, PPC_THREAD_STATE64, &state, &count ) != KERN_SUCCESS )
+                onThreadError( "Unable to load thread state" );
+            if ( !t.m_lock )
+                t.m_curr.tstack = cast(void*) state.r[1];
+            t.m_reg[] = state.r[];
+        }
         else
         {
             static assert(false, "Architecture not supported." );


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-09-17 14:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-19 18:06 [gcc(refs/users/ibuclaw/heads/darwin)] D, Darwin, PPC : Implement thread interfaces Iain Buclaw
  -- strict thread matches above, loose matches on Subject: below --
2021-09-17 14:34 Iain Buclaw
2021-04-10 17:02 Iain Buclaw
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:10 Iain Buclaw
2021-01-28 17:33 Iain Buclaw

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).