Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

[WIP][ltsmaster] Add support for z/Architecture aka SystemZ #158

Open
wants to merge 1 commit into
base: ldc-ltsmaster
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/core/thread.d
Original file line number Diff line number Diff line change
Expand Up @@ -2515,6 +2515,16 @@ else
sd $$22, 48($0);
sd $$23, 56($0)`, "r", regs.ptr);
}
else version (SystemZ)
{
import ldc.llvmasm;

// Callee-save registers, according to S/390 ELF Application
// Binary Interface Supplement, chapter 1, page 9.
size_t[9] regs = void;
__asm(`stm %r6, %r13, $0;
st %r15, 64+$0`, "=*m", regs.ptr);
}
else
{
static assert(false, "Architecture not supported.");
Expand Down Expand Up @@ -3262,6 +3272,10 @@ private void* getStackTop() nothrow
{
return __asm!(void *)("move $0, $$sp", "=r");
}
else version (SystemZ)
{
return __asm!(void *)("lr $0, %r15", "=r");
}
else
{
import ldc.intrinsics;
Expand Down
18 changes: 17 additions & 1 deletion src/rt/sections_elf_shared.d
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,10 @@ version(LDC)
extern(C) void* __tls_get_addr_opt(tls_index* ti);
alias __tls_get_addr = __tls_get_addr_opt;
}
else version(SystemZ)
{
extern(C) void* __tls_get_addr_internal(tls_index* ti);
}
else
extern(C) void* __tls_get_addr(tls_index* ti);
}
Expand Down Expand Up @@ -969,6 +973,8 @@ else version(MIPS32)
enum TLS_DTV_OFFSET = 0x8000;
else version(MIPS64)
enum TLS_DTV_OFFSET = 0x8000;
else version(SystemZ)
enum TLS_DTV_OFFSET = 0x;
else
static assert( false, "Platform not supported." );

Expand Down Expand Up @@ -1006,6 +1012,16 @@ void[] getTLSRange(size_t mod, size_t sz)

// base offset
auto ti = tls_index(mod, 0);
return (__tls_get_addr(&ti)-TLS_DTV_OFFSET)[0 .. sz];
version (SystemZ)
{
import ldc.llvmasm;
auto adr = cast(void *)__tls_get_addr_internal(&ti)
+ __asm!ulong("ear $0,%a0; sllg $0,$0,32; ear $0,%a1", "=r");
return adr[0 .. sz];
}
else
{
return (__tls_get_addr(&ti)-TLS_DTV_OFFSET)[0 .. sz];
}
}
}
13 changes: 12 additions & 1 deletion src/rt/sections_ldc.d
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ private
}

extern(C) void* __tls_get_addr(tls_index* ti);
extern(C) void* __tls_get_addr_internal(tls_index* ti);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you version this for SystemZ only?


/* The dynamic thread vector (DTV) pointers may point 0x8000 past the start of
* each TLS block. This is at least true for PowerPC and Mips platforms.
Expand All @@ -349,7 +350,17 @@ private
{
if (pdso._tlsMod == 0) return null;
auto ti = tls_index(pdso._tlsMod, 0);
return (__tls_get_addr(&ti)-TLS_DTV_OFFSET)[0 .. pdso._tlsSize];
version (SystemZ)
{
import ldc.llvmasm;
auto adr = cast(void *)__tls_get_addr_internal(&ti)
+ __asm!ulong("ear $0,%a0; sllg $0,$0,32; ear $0,%a1", "=r");
return adr[0 .. pdso._tlsSize];
}
else
{
return (__tls_get_addr(&ti)-TLS_DTV_OFFSET)[0 .. pdso._tlsSize];
}
}
}
}
Expand Down