Browse Source

--- Merging r19162 into '.':
U rtl/x86_64/x86_64.inc
--- Merging r19201 into '.':
U rtl/win64/system.pp
U rtl/win/syswin.inc
U rtl/win32/system.pp
--- Merging r19234 into '.':
G rtl/win64/system.pp
G rtl/win32/system.pp
--- Merging r19460 into '.':
G rtl/win64/system.pp
--- Merging r19463 into '.':
U rtl/x86_64/math.inc
--- Merging r19465 into '.':
G rtl/x86_64/math.inc
--- Merging r19478 into '.':
G rtl/x86_64/math.inc
--- Merging r19501 into '.':
G rtl/win64/system.pp
--- Merging r19502 into '.':
G rtl/x86_64/x86_64.inc
--- Merging r19846 into '.':
U rtl/inc/genmath.inc
--- Merging r19881 into '.':
U rtl/win/sysos.inc
--- Merging r20366 into '.':
G rtl/win64/system.pp

# revisions: 19162,19201,19234,19460,19463,19465,19478,19501,19502,19846,19881,20366
r19162 | sergei | 2011-09-20 19:57:58 +0200 (Tue, 20 Sep 2011) | 4 lines
Changed paths:
M /trunk/rtl/x86_64/x86_64.inc

- removed register lists after pure assembler procedures
- removed {$ifdef FPC_HAS_RIP_RELATIVE}, it is obsolete because rip-releative referencing is supported in at least two releases by now.
+ added nostackframe to simple assembler procedures
* Inclocked, Declocked: do not duplicate entire procedures, Win64 and Linux versions differ in a single instruction.
r19201 | sergei | 2011-09-23 23:45:02 +0200 (Fri, 23 Sep 2011) | 2 lines
Changed paths:
M /trunk/rtl/win/syswin.inc
M /trunk/rtl/win32/system.pp
M /trunk/rtl/win64/system.pp

* Moved command line handling and randomize() to syswin.inc, so a single copy of code is used for both win32 and win64. This implies that apostrophe is no longer supported as quoting symbol in win64.
Win64 doesn't support it itself either.
r19234 | sergei | 2011-09-25 21:27:52 +0200 (Sun, 25 Sep 2011) | 2 lines
Changed paths:
M /trunk/rtl/win32/system.pp
M /trunk/rtl/win64/system.pp

- Removed SysResetFPU/SysInitFPU from win32/win64 system unit initialization. It is redundant here because it is called from fpc_initializeunits->fpc_cpuinit (on win64) or from fpc_cpucodeinit (on win32).
* Also declared hprevinst as a typed constant and removed its initialization from code.
r19460 | sergei | 2011-10-11 10:38:10 +0200 (Tue, 11 Oct 2011) | 3 lines
Changed paths:
M /trunk/rtl/win64/system.pp

- Win64, EXE_Entry: removed messing with gs:[0], it won't work anyway.
- Also don't modify rsp in the middle of procedure, x86_64 targets use fixed stack.
- Cleaned outdated FPC_HAS_RIP_RELATIVE and VER2_2 defines.
r19463 | sergei | 2011-10-11 11:08:09 +0200 (Tue, 11 Oct 2011) | 3 lines
Changed paths:
M /trunk/rtl/x86_64/math.inc

* Get8087CW: use fixed stack.
* Set8087CW: updated to i386 version, eliminates need of PIC code in assembler.
* GetSSECSR: updated similar to Get8087CW, it is somewhat shorter that way.
r19465 | sergei | 2011-10-11 12:34:52 +0200 (Tue, 11 Oct 2011) | 1 line
Changed paths:
M /trunk/rtl/x86_64/math.inc

* Get8087CW: Make sure that high bits of result are clear.
r19478 | sergei | 2011-10-13 10:19:09 +0200 (Thu, 13 Oct 2011) | 1 line
Changed paths:
M /trunk/rtl/x86_64/math.inc

* Use variables instead of direct indexing into stack, eliminates warnings at compilation.
r19501 | sergei | 2011-10-16 14:38:47 +0200 (Sun, 16 Oct 2011) | 2 lines
Changed paths:
M /trunk/rtl/win64/system.pp

* Made a stupid mistake in r19460: restoring rbp from rbp-relative reference will obviously crash. This went unnoticed however, because PASCALMAIN does not return and wrong code is never executed. Fixed by storing rbp in non-volatile register instead of local var.
r19502 | sergei | 2011-10-16 15:18:21 +0200 (Sun, 16 Oct 2011) | 3 lines
Changed paths:
M /trunk/rtl/x86_64/x86_64.inc

* Return values of get_caller_addr and get_caller_frame was undefined for nil argument.
Moreover, these function have nothing to do with assembler at all.
r19846 | sergei | 2011-12-13 21:21:22 +0100 (Tue, 13 Dec 2011) | 1 line
Changed paths:
M /trunk/rtl/inc/genmath.inc

* float_raise: Reduce amount of threadvar accesses, gains a bit more compact code. Functionality is not changed.
r19881 | sergei | 2011-12-22 03:17:02 +0100 (Thu, 22 Dec 2011) | 2 lines
Changed paths:
M /trunk/rtl/win/sysos.inc

* Split combined declarations of GetModuleHandle and GetModuleFileName into separate WinCE and non-WinCE versions. Using Pointer as 'common denominator' in combined declarations was making it impossible to use e.g. GetModuleHandle('literal') in System unit.
* Also fixed parameter and return types for these declarations.
r20366 | sergei | 2012-02-17 00:22:42 +0100 (Fri, 17 Feb 2012) | 1 line
Changed paths:
M /trunk/rtl/win64/system.pp

- win64: removed empty procedures remove_exception_handlers and fpc_cpucodeinit.

git-svn-id: branches/fixes_2_6@21459 -

marco 13 years ago
parent
commit
298bb8d037
7 changed files with 280 additions and 605 deletions
  1. 12 6
      rtl/inc/genmath.inc
  2. 14 5
      rtl/win/sysos.inc
  3. 148 0
      rtl/win/syswin.inc
  4. 2 153
      rtl/win32/system.pp
  5. 5 256
      rtl/win64/system.pp
  6. 43 46
      rtl/x86_64/math.inc
  7. 56 139
      rtl/x86_64/x86_64.inc

+ 12 - 6
rtl/inc/genmath.inc

@@ -100,21 +100,27 @@ should be simply `softfloat_exception_flags |= flags;'.
 -------------------------------------------------------------------------------
 -------------------------------------------------------------------------------
 *}
 *}
 procedure float_raise(i: shortint);
 procedure float_raise(i: shortint);
+var
+  pflags: pbyte;
+  unmasked_flags: byte;
 Begin
 Begin
-  softfloat_exception_flags := softfloat_exception_flags or i;
-  if ((softfloat_exception_flags and not(softfloat_exception_mask)) and float_flag_invalid) <> 0 then
+  { taking address of threadvar produces somewhat more compact code }
+  pflags := @softfloat_exception_flags;
+  pflags^ := pflags^ or i;
+  unmasked_flags := pflags^ and (not softfloat_exception_mask);
+  if (unmasked_flags and float_flag_invalid) <> 0 then
      HandleError(207)
      HandleError(207)
   else
   else
-  if ((softfloat_exception_flags and not(softfloat_exception_mask)) and float_flag_divbyzero) <> 0 then
+  if (unmasked_flags and float_flag_divbyzero) <> 0 then
      HandleError(200)
      HandleError(200)
   else
   else
-  if ((softfloat_exception_flags and not(softfloat_exception_mask)) and float_flag_overflow) <> 0 then
+  if (unmasked_flags and float_flag_overflow) <> 0 then
      HandleError(205)
      HandleError(205)
   else
   else
-  if ((softfloat_exception_flags and not(softfloat_exception_mask)) and float_flag_underflow) <> 0 then
+  if (unmasked_flags and float_flag_underflow) <> 0 then
      HandleError(206)
      HandleError(206)
   else
   else
-  if ((softfloat_exception_flags and not(softfloat_exception_mask)) and float_flag_inexact) <> 0 then
+  if (unmasked_flags and float_flag_inexact) <> 0 then
      HandleError(207);
      HandleError(207);
 end;
 end;
 
 

+ 14 - 5
rtl/win/sysos.inc

@@ -211,14 +211,23 @@ threadvar
 
 
   function Win32GetCurrentThreadId:DWORD;
   function Win32GetCurrentThreadId:DWORD;
     stdcall; external KernelDLL name 'GetCurrentThreadId';
     stdcall; external KernelDLL name 'GetCurrentThreadId';
-{$endif WINCE}
+  { module functions }
+  function GetModuleFileName(l1:THandle;p:PChar;l2:longint):longint;
+    stdcall;external KernelDLL name 'GetModuleFileNameA';
+
+  function GetModuleHandle(p : PChar) : THandle;
+    stdcall;external KernelDLL name 'GetModuleHandleA';
+
+{$else WINCE}
 
 
    { module functions }
    { module functions }
-   function GetModuleFileName(l1:longint;p:pointer;l2:longint):longint;
-     {$ifdef wince}cdecl{$else}stdcall{$endif};external KernelDLL name 'GetModuleFileName' + ApiSuffix;
-   function GetModuleHandle(p : pointer) : PtrUInt;
-     {$ifdef wince}cdecl{$else}stdcall{$endif};external KernelDLL name 'GetModuleHandle' + ApiSuffix;
+   function GetModuleFileName(l1:THandle;p:PWideChar;l2:longint):longint;
+     cdecl;external KernelDLL name 'GetModuleFileNameW';
 
 
+   function GetModuleHandle(p : PWideChar) : THandle;
+     cdecl;external KernelDLL name 'GetModuleHandleW';
+
+{$endif WINCE}
    { file functions }
    { file functions }
    function WriteFile(fh:thandle;buf:pointer;len:longint;var loaded:longint;
    function WriteFile(fh:thandle;buf:pointer;len:longint;var loaded:longint;
      overlap:pointer):longint;
      overlap:pointer):longint;

+ 148 - 0
rtl/win/syswin.inc

@@ -99,6 +99,154 @@ const
 
 
   MAXIMUM_SUPPORTED_EXTENSION             = 512;
   MAXIMUM_SUPPORTED_EXTENSION             = 512;
 
 
+  {*****************************************************************************
+                                Parameter Handling
+  *****************************************************************************}
+
+  procedure setup_arguments;
+  var
+    arglen,
+    count   : longint;
+    argstart,
+    pc,arg  : pchar;
+    quote   : Boolean;
+    argvlen : longint;
+    buf: array[0..259] of char;  // need MAX_PATH bytes, not 256!
+
+    procedure allocarg(idx,len:longint);
+      var
+        oldargvlen : longint;
+      begin
+        if idx>=argvlen then
+         begin
+           oldargvlen:=argvlen;
+           argvlen:=(idx+8) and (not 7);
+           sysreallocmem(argv,argvlen*sizeof(pointer));
+           fillchar(argv[oldargvlen],(argvlen-oldargvlen)*sizeof(pointer),0);
+         end;
+        { use realloc to reuse already existing memory }
+        { always allocate, even if length is zero, since }
+        { the arg. is still present!                     }
+        sysreallocmem(argv[idx],len+1);
+      end;
+
+  begin
+    { create commandline, it starts with the executed filename which is argv[0] }
+    { Win32 passes the command NOT via the args, but via getmodulefilename}
+    count:=0;
+    argv:=nil;
+    argvlen:=0;
+    ArgLen := GetModuleFileName(0, @buf[0], sizeof(buf));
+    buf[ArgLen] := #0; // be safe
+    allocarg(0,arglen);
+    move(buf,argv[0]^,arglen+1);
+    { Setup cmdline variable }
+    cmdline:=GetCommandLine;
+    { process arguments }
+    pc:=cmdline;
+  {$IfDef SYSTEM_DEBUG_STARTUP}
+    Writeln(stderr,'Win32 GetCommandLine is #',pc,'#');
+  {$EndIf }
+    while pc^<>#0 do
+     begin
+       { skip leading spaces }
+       while pc^ in [#1..#32] do
+        inc(pc);
+       if pc^=#0 then
+        break;
+       { calc argument length }
+       quote:=False;
+       argstart:=pc;
+       arglen:=0;
+       while (pc^<>#0) do
+        begin
+          case pc^ of
+            #1..#32 :
+              begin
+                if quote then
+                 inc(arglen)
+                else
+                 break;
+              end;
+            '"' :
+              if pc[1]<>'"' then
+                quote := not quote
+                else
+                inc(pc);
+            else
+              inc(arglen);
+          end;
+          inc(pc);
+        end;
+       { copy argument }
+       { Don't copy the first one, it is already there.}
+       If Count<>0 then
+        begin
+          allocarg(count,arglen);
+          quote:=False;
+          pc:=argstart;
+          arg:=argv[count];
+          while (pc^<>#0) do
+           begin
+             case pc^ of
+               #1..#32 :
+                 begin
+                   if quote then
+                    begin
+                      arg^:=pc^;
+                      inc(arg);
+                    end
+                   else
+                    break;
+                 end;
+               '"' :
+                 if pc[1]<>'"' then
+                   quote := not quote
+                    else
+                  inc(pc);
+               else
+                 begin
+                   arg^:=pc^;
+                   inc(arg);
+                 end;
+             end;
+             inc(pc);
+           end;
+          arg^:=#0;
+        end;
+   {$IfDef SYSTEM_DEBUG_STARTUP}
+       Writeln(stderr,'dos arg ',count,' #',arglen,'#',argv[count],'#');
+   {$EndIf SYSTEM_DEBUG_STARTUP}
+       inc(count);
+     end;
+    { get argc }
+    argc:=count;
+    { free unused memory, leaving a nil entry at the end }
+    sysreallocmem(argv,(count+1)*sizeof(pointer));
+    argv[count] := nil;
+  end;
+
+
+  function paramcount : longint;
+  begin
+    paramcount := argc - 1;
+  end;
+
+  function paramstr(l : longint) : string;
+  begin
+    if (l>=0) and (l<argc) then
+      paramstr:=strpas(argv[l])
+    else
+      paramstr:='';
+  end;
+
+
+  procedure randomize;
+  begin
+    randseed:=GetTickCount;
+  end;
+
+
 
 
 Const
 Const
    DLL_PROCESS_ATTACH = 1;
    DLL_PROCESS_ATTACH = 1;

+ 2 - 153
rtl/win32/system.pp

@@ -97,12 +97,13 @@ var
   argv : ppchar; public name 'operatingsystem_parameter_argv';
   argv : ppchar; public name 'operatingsystem_parameter_argv';
 { Win32 Info }
 { Win32 Info }
   startupinfo : tstartupinfo;
   startupinfo : tstartupinfo;
-  hprevinst,
   MainInstance,
   MainInstance,
   cmdshow     : longint;
   cmdshow     : longint;
   DLLreason : dword; public name 'operatingsystem_dllreason';
   DLLreason : dword; public name 'operatingsystem_dllreason';
   DLLparam : PtrInt; public name 'operatingsystem_dllparam';
   DLLparam : PtrInt; public name 'operatingsystem_dllparam';
   StartupConsoleMode : DWORD;
   StartupConsoleMode : DWORD;
+const
+  hprevinst: longint=0;
 
 
 type
 type
   TDLL_Entry_Hook = procedure (dllparam : PtrInt);
   TDLL_Entry_Hook = procedure (dllparam : PtrInt);
@@ -141,152 +142,6 @@ function SysReAllocStringLen(var bstr:pointer;psz: pointer;
 { include system independent routines }
 { include system independent routines }
 {$I system.inc}
 {$I system.inc}
 
 
-{*****************************************************************************
-                              Parameter Handling
-*****************************************************************************}
-
-procedure setup_arguments;
-var
-  arglen,
-  count   : longint;
-  argstart,
-  pc,arg  : pchar;
-  quote   : Boolean;
-  argvlen : longint;
-  buf: array[0..259] of char;  // need MAX_PATH bytes, not 256!
-
-  procedure allocarg(idx,len:longint);
-    var
-      oldargvlen : longint;
-    begin
-      if idx>=argvlen then
-       begin
-         oldargvlen:=argvlen;
-         argvlen:=(idx+8) and (not 7);
-         sysreallocmem(argv,argvlen*sizeof(pointer));
-         fillchar(argv[oldargvlen],(argvlen-oldargvlen)*sizeof(pointer),0);
-       end;
-      { use realloc to reuse already existing memory }
-      { always allocate, even if length is zero, since }
-      { the arg. is still present!                     }
-      sysreallocmem(argv[idx],len+1);
-    end;
-
-begin
-  { create commandline, it starts with the executed filename which is argv[0] }
-  { Win32 passes the command NOT via the args, but via getmodulefilename}
-  count:=0;
-  argv:=nil;
-  argvlen:=0;
-  ArgLen := GetModuleFileName(0, @buf[0], sizeof(buf));
-  buf[ArgLen] := #0; // be safe
-  allocarg(0,arglen);
-  move(buf,argv[0]^,arglen+1);
-  { Setup cmdline variable }
-  cmdline:=GetCommandLine;
-  { process arguments }
-  pc:=cmdline;
-{$IfDef SYSTEM_DEBUG_STARTUP}
-  Writeln(stderr,'Win32 GetCommandLine is #',pc,'#');
-{$EndIf }
-  while pc^<>#0 do
-   begin
-     { skip leading spaces }
-     while pc^ in [#1..#32] do
-      inc(pc);
-     if pc^=#0 then
-      break;
-     { calc argument length }
-     quote:=False;
-     argstart:=pc;
-     arglen:=0;
-     while (pc^<>#0) do
-      begin
-        case pc^ of
-          #1..#32 :
-            begin
-              if quote then
-               inc(arglen)
-              else
-               break;
-            end;
-          '"' :
-            if pc[1]<>'"' then
-              quote := not quote
-              else
-              inc(pc);
-          else
-            inc(arglen);
-        end;
-        inc(pc);
-      end;
-     { copy argument }
-     { Don't copy the first one, it is already there.}
-     If Count<>0 then
-      begin
-        allocarg(count,arglen);
-        quote:=False;
-        pc:=argstart;
-        arg:=argv[count];
-        while (pc^<>#0) do
-         begin
-           case pc^ of
-             #1..#32 :
-               begin
-                 if quote then
-                  begin
-                    arg^:=pc^;
-                    inc(arg);
-                  end
-                 else
-                  break;
-               end;
-             '"' :
-               if pc[1]<>'"' then
-                 quote := not quote
-                  else
-                inc(pc);
-             else
-               begin
-                 arg^:=pc^;
-                 inc(arg);
-               end;
-           end;
-           inc(pc);
-         end;
-        arg^:=#0;
-      end;
- {$IfDef SYSTEM_DEBUG_STARTUP}
-     Writeln(stderr,'dos arg ',count,' #',arglen,'#',argv[count],'#');
- {$EndIf SYSTEM_DEBUG_STARTUP}
-     inc(count);
-   end;
-  { get argc }
-  argc:=count;
-  { free unused memory, leaving a nil entry at the end }
-  sysreallocmem(argv,(count+1)*sizeof(pointer));
-  argv[count] := nil;
-end;
-
-
-function paramcount : longint;
-begin
-  paramcount := argc - 1;
-end;
-
-function paramstr(l : longint) : string;
-begin
-  if (l>=0) and (l<argc) then
-    paramstr:=strpas(argv[l])
-  else
-    paramstr:='';
-end;
-
-
-procedure randomize;
-begin
-  randseed:=GetTickCount;
-end;
 
 
 
 
 {*****************************************************************************
 {*****************************************************************************
@@ -796,13 +651,7 @@ function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
 begin
 begin
   { get some helpful informations }
   { get some helpful informations }
   GetStartupInfo(@startupinfo);
   GetStartupInfo(@startupinfo);
-
-  SysResetFPU;
-  if not(IsLibrary) then
-    SysInitFPU;
-
   { some misc Win32 stuff }
   { some misc Win32 stuff }
-  hprevinst:=0;
   if not IsLibrary then
   if not IsLibrary then
     SysInstance:=getmodulehandle(nil);
     SysInstance:=getmodulehandle(nil);
 
 

+ 5 - 256
rtl/win64/system.pp

@@ -93,11 +93,12 @@ var
 { Win32 Info }
 { Win32 Info }
   startupinfo : tstartupinfo;
   startupinfo : tstartupinfo;
   StartupConsoleMode : dword;
   StartupConsoleMode : dword;
-  hprevinst,
   MainInstance : qword;
   MainInstance : qword;
   cmdshow     : longint;
   cmdshow     : longint;
   DLLreason : dword;
   DLLreason : dword;
   DLLparam : PtrInt;
   DLLparam : PtrInt;
+const
+  hprevinst: qword=0;
 type
 type
   TDLL_Entry_Hook = procedure (dllparam : PtrInt);
   TDLL_Entry_Hook = procedure (dllparam : PtrInt);
 
 
@@ -134,224 +135,11 @@ function SysReAllocStringLen(var bstr:pointer;psz: pointer;
 { include system independent routines }
 { include system independent routines }
 {$I system.inc}
 {$I system.inc}
 
 
-{*****************************************************************************
-                              Parameter Handling
-*****************************************************************************}
-
-procedure setup_arguments;
-var
-  arglen,
-  count   : longint;
-  argstart,
-  pc,arg  : pchar;
-  quote   : char;
-  argvlen : longint;
-  buf: array[0..259] of char;  // need MAX_PATH bytes, not 256!
-
-  procedure allocarg(idx,len:longint);
-    var
-      oldargvlen : longint;
-    begin
-      if idx>=argvlen then
-       begin
-         oldargvlen:=argvlen;
-         argvlen:=(idx+8) and (not 7);
-         sysreallocmem(argv,argvlen*sizeof(pointer));
-         fillchar(argv[oldargvlen],(argvlen-oldargvlen)*sizeof(pointer),0);
-       end;
-      { use realloc to reuse already existing memory }
-      { always allocate, even if length is zero, since }
-      { the arg. is still present!                     }
-      sysreallocmem(argv[idx],len+1);
-    end;
-
-begin
-  { create commandline, it starts with the executed filename which is argv[0] }
-  { Win32 passes the command NOT via the args, but via getmodulefilename}
-  count:=0;
-  argv:=nil;
-  argvlen:=0;
-  ArgLen := GetModuleFileName(0, @buf[0], sizeof(buf));
-  buf[ArgLen] := #0; // be safe
-  allocarg(0,arglen);
-  move(buf,argv[0]^,arglen+1);
-  { Setup cmdline variable }
-  cmdline:=GetCommandLine;
-  { process arguments }
-  pc:=cmdline;
-{$IfDef SYSTEM_DEBUG_STARTUP}
-  Writeln(stderr,'Win32 GetCommandLine is #',pc,'#');
-{$EndIf }
-  while pc^<>#0 do
-   begin
-     { skip leading spaces }
-     while pc^ in [#1..#32] do
-      inc(pc);
-     if pc^=#0 then
-      break;
-     { calc argument length }
-     quote:=' ';
-     argstart:=pc;
-     arglen:=0;
-     while (pc^<>#0) do
-      begin
-        case pc^ of
-          #1..#32 :
-            begin
-              if quote<>' ' then
-               inc(arglen)
-              else
-               break;
-            end;
-          '"' :
-            begin
-              if quote<>'''' then
-               begin
-                 if pchar(pc+1)^<>'"' then
-                  begin
-                    if quote='"' then
-                     quote:=' '
-                    else
-                     quote:='"';
-                  end
-                 else
-                  inc(pc);
-               end
-              else
-               inc(arglen);
-            end;
-          '''' :
-            begin
-              if quote<>'"' then
-               begin
-                 if pchar(pc+1)^<>'''' then
-                  begin
-                    if quote=''''  then
-                     quote:=' '
-                    else
-                     quote:='''';
-                  end
-                 else
-                  inc(pc);
-               end
-              else
-               inc(arglen);
-            end;
-          else
-            inc(arglen);
-        end;
-        inc(pc);
-      end;
-     { copy argument }
-     { Don't copy the first one, it is already there.}
-     If Count<>0 then
-      begin
-        allocarg(count,arglen);
-        quote:=' ';
-        pc:=argstart;
-        arg:=argv[count];
-        while (pc^<>#0) do
-         begin
-           case pc^ of
-             #1..#32 :
-               begin
-                 if quote<>' ' then
-                  begin
-                    arg^:=pc^;
-                    inc(arg);
-                  end
-                 else
-                  break;
-               end;
-             '"' :
-                begin
-                 if quote<>'''' then
-                  begin
-                    if pchar(pc+1)^<>'"' then
-                     begin
-                       if quote='"' then
-                        quote:=' '
-                       else
-                        quote:='"';
-                     end
-                    else
-                     inc(pc);
-                  end
-                 else
-                  begin
-                    arg^:=pc^;
-                    inc(arg);
-                  end;
-               end;
-             '''' :
-               begin
-                 if quote<>'"' then
-                  begin
-                    if pchar(pc+1)^<>'''' then
-                     begin
-                       if quote=''''  then
-                        quote:=' '
-                       else
-                        quote:='''';
-                     end
-                    else
-                     inc(pc);
-                  end
-                 else
-                  begin
-                    arg^:=pc^;
-                    inc(arg);
-                  end;
-               end;
-             else
-               begin
-                 arg^:=pc^;
-                 inc(arg);
-               end;
-           end;
-           inc(pc);
-         end;
-        arg^:=#0;
-      end;
- {$IfDef SYSTEM_DEBUG_STARTUP}
-     Writeln(stderr,'dos arg ',count,' #',arglen,'#',argv[count],'#');
- {$EndIf SYSTEM_DEBUG_STARTUP}
-     inc(count);
-   end;
-  { get argc }
-  argc:=count;
-  { free unused memory, leaving a nil entry at the end }
-  sysreallocmem(argv,(count+1)*sizeof(pointer));
-  argv[count] := nil;
-end;
-
-
-function paramcount : longint;
-begin
-  paramcount := argc - 1;
-end;
-
-function paramstr(l : longint) : string;
-begin
-  if (l>=0) and (l<argc) then
-    paramstr:=strpas(argv[l])
-  else
-    paramstr:='';
-end;
-
-
-procedure randomize;
-begin
-  randseed:=GetTickCount;
-end;
-
-
 {*****************************************************************************
 {*****************************************************************************
                          System Dependent Exit code
                          System Dependent Exit code
 *****************************************************************************}
 *****************************************************************************}
 
 
 procedure install_exception_handlers;forward;
 procedure install_exception_handlers;forward;
-procedure remove_exception_handlers;forward;
 procedure PascalMain;stdcall;external name 'PASCALMAIN';
 procedure PascalMain;stdcall;external name 'PASCALMAIN';
 procedure fpc_do_exit;stdcall;external name 'FPC_DO_EXIT';
 procedure fpc_do_exit;stdcall;external name 'FPC_DO_EXIT';
 Procedure ExitDLL(Exitcode : longint); forward;
 Procedure ExitDLL(Exitcode : longint); forward;
@@ -373,7 +161,6 @@ begin
      { what about Input and Output ?? PM }
      { what about Input and Output ?? PM }
      { now handled, FPK }
      { now handled, FPK }
    end;
    end;
-  remove_exception_handlers;
 
 
   { call exitprocess, with cleanup as required }
   { call exitprocess, with cleanup as required }
   ExitProcess(exitcode);
   ExitProcess(exitcode);
@@ -400,22 +187,6 @@ procedure Exe_entry;[public,alias:'_FPC_EXE_Entry'];
      install_exception_handlers;
      install_exception_handlers;
      ExitCode:=0;
      ExitCode:=0;
      asm
      asm
-        { allocate space for an exception frame }
-        pushq $0
-        pushq %gs:(0)
-        { movl  %rsp,%gs:(0)
-          but don't insert it as it doesn't
-          point to anything yet
-          this will be used in signals unit }
-        movq %rsp,%rax
-{$ifdef FPC_HAS_RIP_RELATIVE}
-        movq %rax,System_exception_frame(%rip)
-{$else}
-        movq %rax,System_exception_frame
-{$endif}
-        { keep stack aligned }
-        pushq $0
-        pushq %rbp
         movq %rsp,%rax
         movq %rsp,%rax
         movq %rax,st
         movq %rax,st
      end;
      end;
@@ -423,16 +194,12 @@ procedure Exe_entry;[public,alias:'_FPC_EXE_Entry'];
      asm
      asm
         xorq %rax,%rax
         xorq %rax,%rax
         movw %ss,%ax
         movw %ss,%ax
-{$ifdef FPC_HAS_RIP_RELATIVE}
         movl %eax,_SS(%rip)
         movl %eax,_SS(%rip)
-{$else}
-        movl %eax,_SS
-{$endif}
+        movq %rbp,%rsi
         xorq %rbp,%rbp
         xorq %rbp,%rbp
         call PASCALMAIN
         call PASCALMAIN
-        popq %rbp
-        popq %rax
-     end;
+        movq %rsi,%rbp
+     end ['RSI','RBP'];     { <-- specifying RSI allows compiler to save/restore it properly }
      { if we pass here there was no error ! }
      { if we pass here there was no error ! }
      system_exit;
      system_exit;
   end;
   end;
@@ -784,16 +551,6 @@ procedure install_exception_handlers;
   end;
   end;
 
 
 
 
-procedure remove_exception_handlers;
-  begin
-  end;
-
-
-procedure fpc_cpucodeinit;
-  begin
-  end;
-
-
 procedure LinkIn(p1,p2,p3: Pointer); inline;
 procedure LinkIn(p1,p2,p3: Pointer); inline;
 begin
 begin
 end;
 end;
@@ -827,16 +584,12 @@ end;
 
 
 
 
 begin
 begin
-  SysResetFPU;
-  if not(IsLibrary) then
-    SysInitFPU;
   { pass dummy value }
   { pass dummy value }
   StackLength := CheckInitialStkLen($1000000);
   StackLength := CheckInitialStkLen($1000000);
   StackBottom := StackTop - StackLength;
   StackBottom := StackTop - StackLength;
   { get some helpful informations }
   { get some helpful informations }
   GetStartupInfo(@startupinfo);
   GetStartupInfo(@startupinfo);
   { some misc Win32 stuff }
   { some misc Win32 stuff }
-  hprevinst:=0;
   if not IsLibrary then
   if not IsLibrary then
     SysInstance:=getmodulehandle(nil);
     SysInstance:=getmodulehandle(nil);
   MainInstance:=SysInstance;
   MainInstance:=SysInstance;
@@ -844,8 +597,6 @@ begin
   { Setup heap }
   { Setup heap }
   InitHeap;
   InitHeap;
   SysInitExceptions;
   SysInitExceptions;
-  { setup fastmove stuff }
-  fpc_cpucodeinit;
   SysInitStdIO;
   SysInitStdIO;
   { Arguments }
   { Arguments }
   setup_arguments;
   setup_arguments;
@@ -858,9 +609,7 @@ begin
   errno:=0;
   errno:=0;
   initvariantmanager;
   initvariantmanager;
   initwidestringmanager;
   initwidestringmanager;
-{$ifndef VER2_2}
   initunicodestringmanager;
   initunicodestringmanager;
-{$endif VER2_2}
   InitWin32Widestrings;
   InitWin32Widestrings;
   DispCallByIDProc:=@DoDispCallByIDError;
   DispCallByIDProc:=@DoDispCallByIDError;
 end.
 end.

+ 43 - 46
rtl/x86_64/math.inc

@@ -17,7 +17,7 @@ label
   FPC_ABSMASK_DOUBLE,
   FPC_ABSMASK_DOUBLE,
   FPC_ABSMASK_SINGLE;
   FPC_ABSMASK_SINGLE;
 
 
-procedure dummyproc;assembler;
+procedure dummyproc;assembler;nostackframe;
   asm
   asm
   .data
   .data
     .balign 16
     .balign 16
@@ -36,30 +36,26 @@ FPC_ABSMASK_DOUBLE:
                             FPU Control word
                             FPU Control word
  ****************************************************************************}
  ****************************************************************************}
 
 
-    procedure Set8087CW(cw:word);assembler;
-      asm        
-        movw cw,%ax
-{$ifdef FPC_PIC}
-        movq default8087cw@GOTPCREL(%rip),%rdx
-        movw %ax,(%rdx)
-        fnclex
-        fldcw (%rdx)
-{$else FPC_PIC}
-        movw %ax,default8087cw{$ifdef FPC_HAS_RIP_RELATIVE}(%rip){$endif}
-        fnclex
-        fldcw default8087cw{$ifdef FPC_HAS_RIP_RELATIVE}(%rip){$endif}
-{$endif FPC_PIC}
+    procedure Set8087CW(cw:word);
+      begin
+         default8087cw:=cw;
+         asm
+           fnclex
+           fldcw cw
+         end;
       end;
       end;
 
 
 
 
     function Get8087CW:word;assembler;
     function Get8087CW:word;assembler;
+      var
+        tmp: word;
       asm
       asm
-        pushq $0
-        fnstcw (%rsp)
-        popq %rax
+        fnstcw tmp
+        movw   tmp,%ax
+        andl   $0xffff,%eax  { clears bits 32-63 }
       end;
       end;
-    
-    
+
+
     procedure SetSSECSR(w : dword);
     procedure SetSSECSR(w : dword);
       begin
       begin
         mxcsr:=w;
         mxcsr:=w;
@@ -67,16 +63,14 @@ FPC_ABSMASK_DOUBLE:
           ldmxcsr w
           ldmxcsr w
         end;
         end;
       end;
       end;
-    
-    
-    function GetSSECSR : dword;
+
+
+    function GetSSECSR : dword;assembler;
       var
       var
         _w : dword;
         _w : dword;
-      begin
-        asm
-          stmxcsr _w
-        end;
-        result:=_w;
+      asm
+        stmxcsr _w
+        movl    _w,%eax
       end;
       end;
 
 
 {****************************************************************************
 {****************************************************************************
@@ -160,20 +154,21 @@ FPC_ABSMASK_DOUBLE:
     {$ifndef FPC_SYSTEM_HAS_EXP}
     {$ifndef FPC_SYSTEM_HAS_EXP}
     {$define FPC_SYSTEM_HAS_EXP}
     {$define FPC_SYSTEM_HAS_EXP}
     function fpc_exp_real(d : ValReal) : ValReal;assembler;compilerproc;
     function fpc_exp_real(d : ValReal) : ValReal;assembler;compilerproc;
+       var
+         oldcw,newcw: word;
        asm
        asm
-            subq        $16,%rsp
             // comes from DJ GPP
             // comes from DJ GPP
             fldt        d
             fldt        d
             fldl2e
             fldl2e
             fmulp       %st,%st(1)
             fmulp       %st,%st(1)
-            fstcw       -2(%rbp)
-            fstcw       -4(%rbp)
-            andw        $0xf3ff,-4(%rbp)
-            orw         $0x0400,-4(%rbp)
-            fldcw       -4(%rbp)
+            fstcw       oldcw
+            fstcw       newcw
+            andw        $0xf3ff,newcw
+            orw         $0x0400,newcw
+            fldcw       newcw
             fld         %st(0)
             fld         %st(0)
             frndint
             frndint
-            fldcw       -2(%rbp)
+            fldcw       oldcw
             fxch        %st(1)
             fxch        %st(1)
             fsub        %st(1),%st
             fsub        %st(1),%st
             f2xm1
             f2xm1
@@ -188,14 +183,15 @@ FPC_ABSMASK_DOUBLE:
     {$ifndef FPC_SYSTEM_HAS_FRAC}
     {$ifndef FPC_SYSTEM_HAS_FRAC}
     {$define FPC_SYSTEM_HAS_FRAC}
     {$define FPC_SYSTEM_HAS_FRAC}
     function fpc_frac_real(d : ValReal) : ValReal;assembler;compilerproc;
     function fpc_frac_real(d : ValReal) : ValReal;assembler;compilerproc;
+      var
+        oldcw,newcw: word;
       asm
       asm
-            subq $16,%rsp
-            fnstcw -4(%rbp)
+            fnstcw oldcw
             fwait
             fwait
-            movw -4(%rbp),%cx
+            movw oldcw,%cx
             orw $0x0c3f,%cx
             orw $0x0c3f,%cx
-            movw %cx,-8(%rbp)
-            fldcw -8(%rbp)
+            movw %cx,newcw
+            fldcw newcw
             fwait
             fwait
             fldt d
             fldt d
             frndint
             frndint
@@ -203,7 +199,7 @@ FPC_ABSMASK_DOUBLE:
             fsub %st(1),%st
             fsub %st(1),%st
             fstp %st(1)
             fstp %st(1)
             fnclex
             fnclex
-            fldcw -4(%rbp)
+            fldcw oldcw
       end;
       end;
     {$endif FPC_SYSTEM_HAS_FRAC}
     {$endif FPC_SYSTEM_HAS_FRAC}
 
 
@@ -211,19 +207,20 @@ FPC_ABSMASK_DOUBLE:
     {$ifndef FPC_SYSTEM_HAS_INT}
     {$ifndef FPC_SYSTEM_HAS_INT}
     {$define FPC_SYSTEM_HAS_INT}
     {$define FPC_SYSTEM_HAS_INT}
     function fpc_int_real(d : ValReal) : ValReal;assembler;compilerproc;
     function fpc_int_real(d : ValReal) : ValReal;assembler;compilerproc;
+      var
+        oldcw,newcw: word;
       asm
       asm
-            subq $16,%rsp
-            fnstcw -4(%rbp)
+            fnstcw oldcw
             fwait
             fwait
-            movw -4(%rbp),%cx
+            movw oldcw,%cx
             orw $0x0c3f,%cx
             orw $0x0c3f,%cx
-            movw %cx,-8(%rbp)
-            fldcw -8(%rbp)
+            movw %cx,newcw
+            fldcw newcw
             fwait
             fwait
             fldt d
             fldt d
             frndint
             frndint
             fwait
             fwait
-            fldcw -4(%rbp)
+            fldcw oldcw
       end;
       end;
     {$endif FPC_SYSTEM_HAS_INT}
     {$endif FPC_SYSTEM_HAS_INT}
 
 

+ 56 - 139
rtl/x86_64/x86_64.inc

@@ -28,49 +28,33 @@
 Function Sptr : Pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif}
 Function Sptr : Pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif}
 asm
 asm
         movq    %rsp,%rax
         movq    %rsp,%rax
-end ['RAX'];
+end;
 
 
 {$IFNDEF INTERNAL_BACKTRACE}
 {$IFNDEF INTERNAL_BACKTRACE}
 {$define FPC_SYSTEM_HAS_GET_FRAME}
 {$define FPC_SYSTEM_HAS_GET_FRAME}
 function get_frame:pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif}
 function get_frame:pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif}
 asm
 asm
         movq    %rbp,%rax
         movq    %rbp,%rax
-end ['RAX'];
+end;
 {$ENDIF not INTERNAL_BACKTRACE}
 {$ENDIF not INTERNAL_BACKTRACE}
 
 
 
 
 {$define FPC_SYSTEM_HAS_GET_CALLER_ADDR}
 {$define FPC_SYSTEM_HAS_GET_CALLER_ADDR}
-function get_caller_addr(framebp:pointer):pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif}
-asm
-{$ifdef win64}
-        orq     %rcx,%rcx
-        jz      .Lg_a_null
-        movq    8(%rcx),%rax
-{$else win64}
-        { %rdi = framebp }
-        orq     %rdi,%rdi
-        jz      .Lg_a_null
-        movq    8(%rdi),%rax
-{$endif win64}
-.Lg_a_null:
-end ['RAX'];
+function get_caller_addr(framebp:pointer):pointer;{$ifdef SYSTEMINLINE}inline;{$endif}
+begin
+  get_caller_addr:=framebp;
+  if assigned(framebp) then
+    get_caller_addr:=PPointer(framebp)[1];
+end;
 
 
 
 
 {$define FPC_SYSTEM_HAS_GET_CALLER_FRAME}
 {$define FPC_SYSTEM_HAS_GET_CALLER_FRAME}
-function get_caller_frame(framebp:pointer):pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif}
-asm
-{$ifdef win64}
-        orq     %rcx,%rcx
-        jz      .Lg_a_null
-        movq    (%rcx),%rax
-{$else win64}
-        { %rdi = framebp }
-        orq     %rdi,%rdi
-        jz      .Lg_a_null
-        movq    (%rdi),%rax
-{$endif win64}
-.Lg_a_null:
-end ['RAX'];
+function get_caller_frame(framebp:pointer):pointer;{$ifdef SYSTEMINLINE}inline;{$endif}
+begin
+  get_caller_frame:=framebp;
+  if assigned(framebp) then
+    get_caller_frame:=PPointer(framebp)^;
+end;
 
 
 // The following assembler procedures are disabled for FreeBSD due to
 // The following assembler procedures are disabled for FreeBSD due to
 // multiple issues with its old GNU assembler (Mantis #19188).
 // multiple issues with its old GNU assembler (Mantis #19188).
@@ -635,175 +619,108 @@ end;
 
 
 {$endif freebsd}
 {$endif freebsd}
 
 
-{$asmmode att}
 {$define FPC_SYSTEM_HAS_DECLOCKED_LONGINT}
 {$define FPC_SYSTEM_HAS_DECLOCKED_LONGINT}
 { does a thread save inc/dec }
 { does a thread save inc/dec }
-function declocked(var l : longint) : boolean;assembler;
+function declocked(var l : longint) : boolean;assembler; nostackframe;
   asm
   asm
-{$ifdef win64}
-     {
-       l: %rcx
-     }
-     { this check should be done because a lock takes a lot }
-     { of time!                                             }
-     cmpb       $0,IsMultithread{$ifdef FPC_HAS_RIP_RELATIVE}(%rip){$endif}
-     jz         .Ldeclockednolock
-     lock
-     decl       (%rcx)
-     jmp        .Ldeclockedend
-.Ldeclockednolock:
-     decl       (%rcx)
-.Ldeclockedend:
-     setzb      %al
-{$else win64}
-     {
-       l: %rdi
-     }
      { this check should be done because a lock takes a lot }
      { this check should be done because a lock takes a lot }
      { of time!                                             }
      { of time!                                             }
 {$ifdef FPC_PIC}
 {$ifdef FPC_PIC}
      movq       IsMultithread@GOTPCREL(%rip),%rax
      movq       IsMultithread@GOTPCREL(%rip),%rax
      cmpb       $0,(%rax)
      cmpb       $0,(%rax)
 {$else FPC_PIC}
 {$else FPC_PIC}
-     cmpb       $0,IsMultithread{$ifdef FPC_HAS_RIP_RELATIVE}(%rip){$endif}
+     cmpb       $0,IsMultithread(%rip)
 {$endif FPC_PIC}
 {$endif FPC_PIC}
+{$ifndef win64}
+     mov        %rdi, %rcx
+{$endif win64}
      jz         .Ldeclockednolock
      jz         .Ldeclockednolock
      lock
      lock
-     decl       (%rdi)
+     decl       (%rcx)
      jmp        .Ldeclockedend
      jmp        .Ldeclockedend
 .Ldeclockednolock:
 .Ldeclockednolock:
-     decl       (%rdi)
+     decl       (%rcx)
 .Ldeclockedend:
 .Ldeclockedend:
      setzb      %al
      setzb      %al
-{$endif win64}
   end;
   end;
 
 
 
 
 {$define FPC_SYSTEM_HAS_DECLOCKED_INT64}
 {$define FPC_SYSTEM_HAS_DECLOCKED_INT64}
-function declocked(var l : int64) : boolean;assembler;
+function declocked(var l : int64) : boolean;assembler; nostackframe;
   asm
   asm
-{$ifdef win64}
-     {
-       l: %rcx
-     }
-     { this check should be done because a lock takes a lot }
-     { of time!                                             }
-     cmpb       $0,IsMultithread{$ifdef FPC_HAS_RIP_RELATIVE}(%rip){$endif}
-     jz         .Ldeclockednolock
-     lock
-     decq       (%rcx)
-     jmp        .Ldeclockedend
-.Ldeclockednolock:
-     decq       (%rcx)
-.Ldeclockedend:
-     setzb      %al
-{$else win64}
-     {
-       l: %rdi
-     }
      { this check should be done because a lock takes a lot }
      { this check should be done because a lock takes a lot }
      { of time!                                             }
      { of time!                                             }
 {$ifdef FPC_PIC}
 {$ifdef FPC_PIC}
      movq       IsMultithread@GOTPCREL(%rip),%rax
      movq       IsMultithread@GOTPCREL(%rip),%rax
      cmpb       $0,(%rax)
      cmpb       $0,(%rax)
 {$else FPC_PIC}
 {$else FPC_PIC}
-     cmpb       $0,IsMultithread{$ifdef FPC_HAS_RIP_RELATIVE}(%rip){$endif}
+     cmpb       $0,IsMultithread(%rip)
 {$endif FPC_PIC}
 {$endif FPC_PIC}
+{$ifndef win64}
+     mov        %rdi, %rcx
+{$endif win64}
      jz         .Ldeclockednolock
      jz         .Ldeclockednolock
      lock
      lock
-     decq       (%rdi)
+     decq       (%rcx)
      jmp        .Ldeclockedend
      jmp        .Ldeclockedend
 .Ldeclockednolock:
 .Ldeclockednolock:
-     decq       (%rdi)
+     decq       (%rcx)
 .Ldeclockedend:
 .Ldeclockedend:
      setzb      %al
      setzb      %al
-{$endif win64}
   end;
   end;
 
 
 
 
 {$define FPC_SYSTEM_HAS_INCLOCKED_LONGINT}
 {$define FPC_SYSTEM_HAS_INCLOCKED_LONGINT}
-procedure inclocked(var l : longint);assembler;
+procedure inclocked(var l : longint);assembler; nostackframe;
 
 
   asm
   asm
-{$ifdef win64}
-     {
-       l: %rcx
-     }
-     { this check should be done because a lock takes a lot }
-     { of time!                                             }
-     cmpb       $0,IsMultithread{$ifdef FPC_HAS_RIP_RELATIVE}(%rip){$endif}
-     jz         .Linclockednolock
-     lock
-     incl       (%rcx)
-     jmp        .Linclockedend
-.Linclockednolock:
-     incl       (%rcx)
-.Linclockedend:
-{$else win64}
-     {
-       l: %rdi
-     }
      { this check should be done because a lock takes a lot }
      { this check should be done because a lock takes a lot }
      { of time!                                             }
      { of time!                                             }
 {$ifdef FPC_PIC}
 {$ifdef FPC_PIC}
      movq       IsMultithread@GOTPCREL(%rip),%rax
      movq       IsMultithread@GOTPCREL(%rip),%rax
      cmpb       $0,(%rax)
      cmpb       $0,(%rax)
 {$else FPC_PIC}
 {$else FPC_PIC}
-     cmpb       $0,IsMultithread{$ifdef FPC_HAS_RIP_RELATIVE}(%rip){$endif}
+     cmpb       $0,IsMultithread(%rip)
 {$endif FPC_PIC}
 {$endif FPC_PIC}
+{$ifndef win64}
+     mov        %rdi, %rcx
+{$endif win64}
      jz         .Linclockednolock
      jz         .Linclockednolock
      lock
      lock
-     incl       (%rdi)
+     incl       (%rcx)
      jmp        .Linclockedend
      jmp        .Linclockedend
 .Linclockednolock:
 .Linclockednolock:
-     incl       (%rdi)
+     incl       (%rcx)
 .Linclockedend:
 .Linclockedend:
-{$endif win64}
   end;
   end;
 
 
 
 
 {$define FPC_SYSTEM_HAS_INCLOCKED_INT64}
 {$define FPC_SYSTEM_HAS_INCLOCKED_INT64}
-procedure inclocked(var l : int64);assembler;
+procedure inclocked(var l : int64);assembler; nostackframe;
 
 
   asm
   asm
-{$ifdef win64}
-     {
-       l: %rcx
-     }
-     { this check should be done because a lock takes a lot }
-     { of time!                                             }
-     cmpb       $0,IsMultithread{$ifdef FPC_HAS_RIP_RELATIVE}(%rip){$endif}
-     jz         .Linclockednolock
-     lock
-     incq       (%rcx)
-     jmp        .Linclockedend
-.Linclockednolock:
-     incq       (%rcx)
-.Linclockedend:
-{$else win64}
-     {
-       l: %rdi
-     }
      { this check should be done because a lock takes a lot }
      { this check should be done because a lock takes a lot }
      { of time!                                             }
      { of time!                                             }
 {$ifdef FPC_PIC}
 {$ifdef FPC_PIC}
      movq       IsMultithread@GOTPCREL(%rip),%rax
      movq       IsMultithread@GOTPCREL(%rip),%rax
      cmpb       $0,(%rax)
      cmpb       $0,(%rax)
 {$else FPC_PIC}
 {$else FPC_PIC}
-     cmpb       $0,IsMultithread{$ifdef FPC_HAS_RIP_RELATIVE}(%rip){$endif}
+     cmpb       $0,IsMultithread(%rip)
 {$endif FPC_PIC}
 {$endif FPC_PIC}
+{$ifndef win64}
+     mov        %rdi, %rcx
+{$endif win64}
      jz         .Linclockednolock
      jz         .Linclockednolock
      lock
      lock
-     incq       (%rdi)
+     incq       (%rcx)
      jmp        .Linclockedend
      jmp        .Linclockedend
 .Linclockednolock:
 .Linclockednolock:
-     incq       (%rdi)
+     incq       (%rcx)
 .Linclockedend:
 .Linclockedend:
-{$endif win64}
   end;
   end;
 
 
 
 
-function InterLockedDecrement (var Target: longint) : longint; assembler;
+function InterLockedDecrement (var Target: longint) : longint; assembler; nostackframe;
 asm
 asm
 {$ifdef win64}
 {$ifdef win64}
         movq    %rcx,%rax
         movq    %rcx,%rax
@@ -818,7 +735,7 @@ asm
 end;
 end;
 
 
 
 
-function InterLockedIncrement (var Target: longint) : longint; assembler;
+function InterLockedIncrement (var Target: longint) : longint; assembler; nostackframe;
 asm
 asm
 {$ifdef win64}
 {$ifdef win64}
         movq    %rcx,%rax
         movq    %rcx,%rax
@@ -833,7 +750,7 @@ asm
 end;
 end;
 
 
 
 
-function InterLockedExchange (var Target: longint;Source : longint) : longint; assembler;
+function InterLockedExchange (var Target: longint;Source : longint) : longint; assembler; nostackframe;
 asm
 asm
 {$ifdef win64}
 {$ifdef win64}
         xchgl   (%rcx),%edx
         xchgl   (%rcx),%edx
@@ -845,7 +762,7 @@ asm
 end;
 end;
 
 
 
 
-function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint; assembler;
+function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint; assembler; nostackframe;
 asm
 asm
 {$ifdef win64}
 {$ifdef win64}
         xchgq   %rcx,%rdx
         xchgq   %rcx,%rdx
@@ -861,7 +778,7 @@ asm
 end;
 end;
 
 
 
 
-function InterLockedCompareExchange(var Target: longint; NewValue, Comperand : longint): longint; assembler;
+function InterLockedCompareExchange(var Target: longint; NewValue, Comperand : longint): longint; assembler; nostackframe;
 asm
 asm
 {$ifdef win64}
 {$ifdef win64}
         movl            %r8d,%eax
         movl            %r8d,%eax
@@ -875,7 +792,7 @@ asm
 end;
 end;
 
 
 
 
-function InterLockedDecrement64 (var Target: int64) : int64; assembler;
+function InterLockedDecrement64 (var Target: int64) : int64; assembler; nostackframe;
 asm
 asm
 {$ifdef win64}
 {$ifdef win64}
         movq    %rcx,%rax
         movq    %rcx,%rax
@@ -890,7 +807,7 @@ asm
 end;
 end;
 
 
 
 
-function InterLockedIncrement64 (var Target: int64) : int64; assembler;
+function InterLockedIncrement64 (var Target: int64) : int64; assembler; nostackframe;
 asm
 asm
 {$ifdef win64}
 {$ifdef win64}
         movq    %rcx,%rax
         movq    %rcx,%rax
@@ -905,7 +822,7 @@ asm
 end;
 end;
 
 
 
 
-function InterLockedExchange64 (var Target: int64;Source : int64) : int64; assembler;
+function InterLockedExchange64 (var Target: int64;Source : int64) : int64; assembler; nostackframe;
 asm
 asm
 {$ifdef win64}
 {$ifdef win64}
         xchgq   (%rcx),%rdx
         xchgq   (%rcx),%rdx
@@ -917,7 +834,7 @@ asm
 end;
 end;
 
 
 
 
-function InterLockedExchangeAdd64 (var Target: int64;Source : int64) : int64; assembler;
+function InterLockedExchangeAdd64 (var Target: int64;Source : int64) : int64; assembler; nostackframe;
 asm
 asm
 {$ifdef win64}
 {$ifdef win64}
         xchgq   %rcx,%rdx
         xchgq   %rcx,%rdx
@@ -933,7 +850,7 @@ asm
 end;
 end;
 
 
 
 
-function InterLockedCompareExchange64(var Target: int64; NewValue, Comperand : int64): int64; assembler;
+function InterLockedCompareExchange64(var Target: int64; NewValue, Comperand : int64): int64; assembler; nostackframe;
 asm
 asm
 {$ifdef win64}
 {$ifdef win64}
         movq            %r8,%rax
         movq            %r8,%rax
@@ -1074,7 +991,7 @@ function SwapEndian(const AValue: Word): Word;{$ifdef SYSTEMINLINE}inline;{$endi
   end;
   end;
 
 
 
 
-function SwapEndian(const AValue: LongInt): LongInt; assembler;
+function SwapEndian(const AValue: LongInt): LongInt; assembler; nostackframe;
 asm
 asm
 {$ifdef win64}
 {$ifdef win64}
   movl %ecx, %eax
   movl %ecx, %eax
@@ -1085,7 +1002,7 @@ asm
 end;
 end;
 
 
 
 
-function SwapEndian(const AValue: DWord): DWord; assembler;
+function SwapEndian(const AValue: DWord): DWord; assembler; nostackframe;
 asm
 asm
 {$ifdef win64}
 {$ifdef win64}
   movl %ecx, %eax
   movl %ecx, %eax
@@ -1096,7 +1013,7 @@ asm
 end;
 end;
 
 
 
 
-function SwapEndian(const AValue: Int64): Int64; assembler;
+function SwapEndian(const AValue: Int64): Int64; assembler; nostackframe;
 asm
 asm
 {$ifdef win64}
 {$ifdef win64}
   movq %rcx, %rax
   movq %rcx, %rax
@@ -1107,7 +1024,7 @@ asm
 end;
 end;
 
 
 
 
-function SwapEndian(const AValue: QWord): QWord; assembler;
+function SwapEndian(const AValue: QWord): QWord; assembler; nostackframe;
 asm
 asm
 {$ifdef win64}
 {$ifdef win64}
   movq %rcx, %rax
   movq %rcx, %rax