Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

druntime: Add GNU_InlineAsm implementations #20735

Open
wants to merge 1 commit into
base: master
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
11 changes: 9 additions & 2 deletions druntime/src/core/sys/windows/dll.d
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ private bool isWindows8OrLater() nothrow @nogc
int dll_getRefCount( HINSTANCE hInstance ) nothrow @nogc
{
void** peb;
version (Win64)
version (D_InlineAsm_X86_64)
{
asm pure nothrow @nogc
{
Expand All @@ -411,14 +411,21 @@ int dll_getRefCount( HINSTANCE hInstance ) nothrow @nogc
mov peb, RAX;
}
}
else version (Win32)
else version (D_InlineAsm_X86)
{
asm pure nothrow @nogc
{
mov EAX,FS:[0x30];
mov peb, EAX;
}
}
else version (GNU_InlineAsm)
{
version (X86_64)
asm pure nothrow @nogc { "movq %%gs:0x60, %0;" : "=r" (peb); }
else version (X86)
asm pure nothrow @nogc { "movl %%fs:0x30, %0;" : "=r" (peb); }
}
dll_aux.LDR_MODULE *ldrMod = dll_aux.findLdrModule( hInstance, peb );
if ( !ldrMod )
return -2; // not in module list, bail out
Expand Down
15 changes: 13 additions & 2 deletions druntime/src/core/sys/windows/threadaux.d
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ struct thread_aux
// get linear address of TEB of current thread
static void** getTEB() nothrow @nogc
{
version (Win32)
version (D_InlineAsm_X86)
{
asm pure nothrow @nogc
{
Expand All @@ -172,7 +172,7 @@ struct thread_aux
ret;
}
}
else version (Win64)
else version (D_InlineAsm_X86_64)
{
asm pure nothrow @nogc
{
Expand All @@ -182,6 +182,17 @@ struct thread_aux
ret;
}
}
else version (GNU_InlineAsm)
{
void** teb;
version (X86)
asm pure nothrow @nogc { "movl %%fs:0x18, %0;" : "=r" (teb); }
else version (X86_64)
asm pure nothrow @nogc { "movq %%gs:0x30, %0;" : "=r" (teb); }
else
static assert(false);
return teb;
}
else
{
static assert(false);
Expand Down
13 changes: 13 additions & 0 deletions druntime/src/core/thread/osthread.d
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,19 @@ private extern(D) void* getStackBottom() nothrow @nogc
mov RAX, GS:[RAX];
ret;
}
else version (GNU_InlineAsm)
{
void *bottom;

version (X86)
asm pure nothrow @nogc { "movl %%fs:4, %0;" : "=r" (bottom); }
else version (X86_64)
asm pure nothrow @nogc { "movq %%gs:8, %0;" : "=r" (bottom); }
else
static assert(false, "Architecture not supported.");

return bottom;
}
else
static assert(false, "Architecture not supported.");
}
Expand Down
8 changes: 8 additions & 0 deletions druntime/src/rt/dmain2.d
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,14 @@ private extern (C) int _d_run_main2(char[][] args, size_t totalArgsLength, MainF
pop EAX;
}
}
else version (GNU_InlineAsm)
{
size_t fpu_cw;
asm { "fstcw %0" : "=m" (fpu_cw); }
fpu_cw |= 0b11_00_111111; // 11: use 64 bit extended-precision
// 111111: mask all FP exceptions
asm { "fldcw %0" : "=m" (fpu_cw); }
}
}

/* Create a copy of args[] on the stack to be used for main, so that rt_args()
Expand Down
Loading