Skip to content

Commit

Permalink
druntime: Add GNU_InlineAsm implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuclaw committed Jan 19, 2025
1 parent 3e50cd8 commit ad947b5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
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 @@ -1530,6 +1530,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

0 comments on commit ad947b5

Please sign in to comment.