public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Iain D Sandoe <iains@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/iains/heads/d-for-darwin)] D, Darwin, PPC : Implement thread interfaces. Date: Mon, 21 Dec 2020 20:38:03 +0000 (GMT) [thread overview] Message-ID: <20201221203803.E0D383870895@sourceware.org> (raw) https://gcc.gnu.org/g:a9b0c26c5531e3029642b063ea6e346143a285cb commit a9b0c26c5531e3029642b063ea6e346143a285cb 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.d | 140 +++++++++++++++++++++++++++++++++++- 1 file changed, 137 insertions(+), 3 deletions(-) diff --git a/libphobos/libdruntime/core/thread.d b/libphobos/libdruntime/core/thread.d index 98b781eb945..9927430444d 100644 --- a/libphobos/libdruntime/core/thread.d +++ b/libphobos/libdruntime/core/thread.d @@ -26,6 +26,11 @@ else version (TVOS) version = Darwin; else version (WatchOS) version = Darwin; +version (Darwin) +{ + version (PPC) version = Darwin_AnyPPC; + version (PPC64) version = Darwin_AnyPPC; +} private { @@ -1669,6 +1674,17 @@ private: ulong[16] m_reg; // rdi,rsi,rbp,rsp,rbx,rdx,rcx,rax // r8,r9,r10,r11,r12,r13,r14,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." ); @@ -2468,6 +2484,63 @@ body regs[0] = cast(void*)®s[0]; fn (regs[0]); } + else version (PPC) + { + void*[20] regs = void; + asm pure nothrow @nogc + { + "stw r13, %0" : "=m" (regs[ 1]); + "stw r14, %0" : "=m" (regs[ 2]); + "stw r15, %0" : "=m" (regs[ 3]); + "stw r16, %0" : "=m" (regs[ 4]); + "stw r17, %0" : "=m" (regs[ 5]); + "stw r18, %0" : "=m" (regs[ 6]); + "stw r19, %0" : "=m" (regs[ 7]); + "stw r20, %0" : "=m" (regs[ 8]); + "stw r21, %0" : "=m" (regs[ 9]); + "stw r22, %0" : "=m" (regs[10]); + "stw r23, %0" : "=m" (regs[11]); + "stw r24, %0" : "=m" (regs[12]); + "stw r25, %0" : "=m" (regs[13]); + "stw r26, %0" : "=m" (regs[14]); + "stw r27, %0" : "=m" (regs[15]); + "stw r28, %0" : "=m" (regs[16]); + "stw r29, %0" : "=m" (regs[17]); + "stw r30, %0" : "=m" (regs[18]); + "stw r31, %0" : "=m" (regs[19]); + } + regs[0] = cast(void*)®s[0]; + fn(regs[0]); + } + else version (PPC64) + { + void*[20] regs = void; + asm pure nothrow @nogc + { + "std r13, %0" : "=m" (regs[ 1]); + "std r14, %0" : "=m" (regs[ 2]); + "std r15, %0" : "=m" (regs[ 3]); + "std r16, %0" : "=m" (regs[ 4]); + "std r17, %0" : "=m" (regs[ 5]); + "std r18, %0" : "=m" (regs[ 6]); + "std r19, %0" : "=m" (regs[ 7]); + "std r20, %0" : "=m" (regs[ 8]); + "std r21, %0" : "=m" (regs[ 9]); + "std r22, %0" : "=m" (regs[10]); + "std r23, %0" : "=m" (regs[11]); + "std r24, %0" : "=m" (regs[12]); + "std r25, %0" : "=m" (regs[13]); + "std r26, %0" : "=m" (regs[14]); + "std r27, %0" : "=m" (regs[15]); + "std r28, %0" : "=m" (regs[16]); + "std r29, %0" : "=m" (regs[17]); + "std r30, %0" : "=m" (regs[18]); + "std r31, %0" : "=m" (regs[19]); + } + regs[0] = cast(void*)®s[0]; + fn(regs[0]); + } + else static assert(false, "Darwin Architecture not supported."); } else { @@ -2695,6 +2768,28 @@ private bool suspend( Thread t ) nothrow t.m_reg[14] = state.r14; t.m_reg[15] = state.r15; } + 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." ); @@ -3639,7 +3734,8 @@ private } else version (X86) { - version = AlignFiberStackTo16Byte; + version (Darwin) + version = AlignFiberStackTo16Byte; version (CET) { @@ -3691,7 +3787,12 @@ private } else version (PPC) { - version (Posix) + version (Darwin) + { + version = AlignFiberStackTo16Byte; + version = AsmPPC_External_Darwin; + } + else version (Posix) { version = AsmPPC_Posix; version = AsmExternal; @@ -3699,9 +3800,15 @@ private } else version (PPC64) { - version (Posix) + version (Darwin) { version = AlignFiberStackTo16Byte; + version = AsmPPC_External_Darwin; + } + else version (Posix) + { + version = AsmPPC64_Posix; + version = AlignFiberStackTo16Byte; } } else version (MIPS_O32) @@ -3747,6 +3854,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 @@ -3826,6 +3934,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 { @@ -5051,6 +5163,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) {}
next reply other threads:[~2020-12-21 20:38 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-12-21 20:38 Iain D Sandoe [this message] -- strict thread matches above, loose matches on Subject: below -- 2021-10-18 15:54 Iain D Sandoe 2021-10-15 19:34 Iain D Sandoe 2021-10-13 8:31 Iain D Sandoe 2021-10-11 20:35 Iain D Sandoe 2021-01-11 21:27 Iain D Sandoe 2020-12-13 17:44 Iain D Sandoe
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=20201221203803.E0D383870895@sourceware.org \ --to=iains@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: linkBe 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).