Browse Source

* fixed x86-64 assembler problems

florian 21 years ago
parent
commit
25960b979c
6 changed files with 164 additions and 184 deletions
  1. 5 2
      rtl/linux/ossysc.inc
  2. 5 2
      rtl/linux/ostypes.inc
  3. 125 159
      rtl/linux/x86_64/syscall.inc
  4. 6 4
      rtl/linux/x86_64/syscallh.inc
  5. 14 11
      rtl/x86_64/math.inc
  6. 9 6
      rtl/x86_64/x86_64.inc

+ 5 - 2
rtl/linux/ossysc.inc

@@ -16,6 +16,7 @@
  ****************************************************************************
 }
 
+{$I syscallh.inc}
 {$I ostypes.inc}
 
 {$ifdef FPC_USE_LIBC}
@@ -33,7 +34,6 @@
                      --- Main:The System Call Self ---
 *****************************************************************************}
 
-{$I syscallh.inc}
 {$I syscall.inc}
 {$I sysnr.inc}
 {$I bunxmacr.inc}
@@ -479,7 +479,10 @@ end;
 
 {
  $Log$
- Revision 1.15  2004-02-05 01:16:12  florian
+ Revision 1.16  2004-02-06 15:58:21  florian
+   * fixed x86-64 assembler problems
+
+ Revision 1.15  2004/02/05 01:16:12  florian
    + completed x86-64/linux system unit
 
  Revision 1.14  2004/01/31 16:25:48  florian

+ 5 - 2
rtl/linux/ostypes.inc

@@ -39,7 +39,7 @@ Type
                  reg3,
                  reg4,
                  reg5,
-                 reg6   : longint;
+                 reg6   : TSysParam;
                 end;
   PSysCallRegs= ^SysCallRegs;
   TSysCallRegs= SysCallRegs;
@@ -62,7 +62,10 @@ Const   // generated by statmacr.c
 
 {
  $Log$
- Revision 1.5  2003-09-27 13:45:58  peter
+ Revision 1.6  2004-02-06 15:58:21  florian
+   * fixed x86-64 assembler problems
+
+ Revision 1.5  2003/09/27 13:45:58  peter
    * fpnanosleep exported in baseunix
    * fpnanosleep has pointer arguments to be C compliant
 

+ 125 - 159
rtl/linux/x86_64/syscall.inc

@@ -22,195 +22,170 @@
 function FpSysCall(sysnr:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL0'];
 
 asm
-{ load the registers... }
-  movl  sysnr,%eax
-  int   $0x80
-  testl %eax,%eax
-  jns   .LSyscOK
-  negl  %eax
-{$ifdef VER1_0}
-  movl  %eax,Errno
-{$else}
-  movl  %eax,%edx
-  movl  FPC_THREADVAR_RELOCATE,%eax
-  testl %eax,%eax
+  movq sysnr, %rax        { Syscall number -> rax.  }
+  movq %rsi, %rdi         { shift arg1 - arg5. }
+  movq %rdx, %rsi
+  movq %rcx, %rdx
+  movq %r8, %r10
+  movq %r9, %r8
+  syscall                 { Do the system call. }
+  cmpq $-4095, %rax       { Check %rax for error.  }
+  jnae .LSyscOK           { Jump to error handler if error.  }  
+  negq  %rax
+  movq  %rax,%rdx
+  movq  FPC_THREADVAR_RELOCATE,%rax
+  testq %rax,%rax
   jne   .LThread
-  movl  %edx,Errno+4
+  movq  %rdx,Errno+4
   jmp   .LNoThread
 .LThread:
-  pushl %edx
-  pushl Errno
-  call  *%eax
-  popl  %edx
-  movl  %edx,(%eax)
+  pushq %rdx
+  pushq Errno
+  call  *%rax
+  popq  %rdx
+  movq  %rdx,(%rax)
 .LNoThread:
-  movl  $-1,%eax
-{$endif}
+  movq  $-1,%rax
 .LSyscOK:
 end;
 
 function FpSysCall(sysnr,param1 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL1'];
 
 asm
-{ load the registers... }
-  movl sysnr,%eax
-  movl param1,%ebx
-  int $0x80
-  testl %eax,%eax
-  jns   .LSyscOK
-  negl  %eax
-{$ifdef VER1_0}
-  movl  %eax,Errno
-{$else}
-  movl  %eax,%edx
-  movl  FPC_THREADVAR_RELOCATE,%eax
-  testl %eax,%eax
+  movq sysnr, %rax        { Syscall number -> rax.  }
+  movq param1, %rdi         { shift arg1 - arg5. }
+  syscall                 { Do the system call. }
+  cmpq $-4095, %rax       { Check %rax for error.  }
+  jnae .LSyscOK           { Jump to error handler if error.  }  
+  negq  %rax
+  movq  %rax,%rdx
+  movq  FPC_THREADVAR_RELOCATE,%rax
+  testq %rax,%rax
   jne   .LThread
-  movl  %edx,Errno+4
+  movq  %rdx,Errno+4
   jmp   .LNoThread
 .LThread:
-  pushl %edx
-  pushl Errno
-  call  *%eax
-  popl  %edx
-  movl  %edx,(%eax)
+  pushq %rdx
+  pushq Errno
+  call  *%rax
+  popq  %rdx
+  movq  %rdx,(%rax)
 .LNoThread:
-  movl  $-1,%eax
-{$endif}
+  movq  $-1,%rax
 .LSyscOK:
 end;
 
 function FpSysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL2'];
 
 asm
-{ load the registers... }
-  movl sysnr,%eax
-  movl param1,%ebx
-  movl param2,%ecx
-  int $0x80
-  testl %eax,%eax
-  jns   .LSyscOK
-  negl  %eax
-{$ifdef VER1_0}
-  movl  %eax,Errno
-{$else}
-  movl  %eax,%edx
-  movl  FPC_THREADVAR_RELOCATE,%eax
-  testl %eax,%eax
+  movq sysnr, %rax        { Syscall number -> rax.  }
+  movq param1, %rdi         { shift arg1 - arg5. }
+  movq param2, %rsi
+  syscall                 { Do the system call. }
+  cmpq $-4095, %rax       { Check %rax for error.  }
+  jnae .LSyscOK           { Jump to error handler if error.  }  
+  negq  %rax
+  movq  %rax,%rdx
+  movq  FPC_THREADVAR_RELOCATE,%rax
+  testq %rax,%rax
   jne   .LThread
-  movl  %edx,Errno+4
+  movq  %rdx,Errno+4
   jmp   .LNoThread
 .LThread:
-  pushl %edx
-  pushl Errno
-  call  *%eax
-  popl  %edx
-  movl  %edx,(%eax)
+  pushq %rdx
+  pushq Errno
+  call  *%rax
+  popq  %rdx
+  movq  %rdx,(%rax)
 .LNoThread:
-  movl  $-1,%eax
-{$endif}
+  movq  $-1,%rax
 .LSyscOK:
 end;
 
 function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL3'];
 
 asm
-{ load the registers... }
-  movl sysnr,%eax
-  movl param1,%ebx
-  movl param2,%ecx
-  movl param3,%edx
-  int $0x80
-  testl %eax,%eax
-  jns   .LSyscOK
-  negl  %eax
-{$ifdef VER1_0}
-  movl  %eax,Errno
-{$else}
-  movl  %eax,%edx
-  movl  FPC_THREADVAR_RELOCATE,%eax
-  testl %eax,%eax
+  movq sysnr, %rax        { Syscall number -> rax.  }
+  movq param1, %rdi         { shift arg1 - arg5. }
+  movq param2, %rsi
+  movq param3, %rdx
+  syscall                 { Do the system call. }
+  cmpq $-4095, %rax       { Check %rax for error.  }
+  jnae .LSyscOK           { Jump to error handler if error.  }  
+  negq  %rax
+  movq  %rax,%rdx
+  movq  FPC_THREADVAR_RELOCATE,%rax
+  testq %rax,%rax
   jne   .LThread
-  movl  %edx,Errno+4
+  movq  %rdx,Errno+4
   jmp   .LNoThread
 .LThread:
-  pushl %edx
-  pushl Errno
-  call  *%eax
-  popl  %edx
-  movl  %edx,(%eax)
+  pushq %rdx
+  pushq Errno
+  call  *%rax
+  popq  %rdx
+  movq  %rdx,(%rax)
 .LNoThread:
-  movl  $-1,%eax
-{$endif}
+  movq  $-1,%rax
 .LSyscOK:
 end;
 
 function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL4'];
 
 asm
-{ load the registers... }
-  movl sysnr,%eax
-  movl param1,%ebx
-  movl param2,%ecx
-  movl param3,%edx
-  movl param4,%esi
-  int $0x80
-  testl %eax,%eax
-  jns   .LSyscOK
-  negl  %eax
-{$ifdef VER1_0}
-  movl  %eax,Errno
-{$else}
-  movl  %eax,%edx
-  movl  FPC_THREADVAR_RELOCATE,%eax
-  testl %eax,%eax
+  movq sysnr, %rax        { Syscall number -> rax.  }
+  movq param1, %rdi         { shift arg1 - arg5. }
+  movq param2, %rsi
+  movq param3, %rdx
+  movq param4, %r10
+  syscall                 { Do the system call. }
+  cmpq $-4095, %rax       { Check %rax for error.  }
+  jnae .LSyscOK           { Jump to error handler if error.  }  
+  negq  %rax
+  movq  %rax,%rdx
+  movq  FPC_THREADVAR_RELOCATE,%rax
+  testq %rax,%rax
   jne   .LThread
-  movl  %edx,Errno+4
+  movq  %rdx,Errno+4
   jmp   .LNoThread
 .LThread:
-  pushl %edx
-  pushl Errno
-  call  *%eax
-  popl  %edx
-  movl  %edx,(%eax)
+  pushq %rdx
+  pushq Errno
+  call  *%rax
+  popq  %rdx
+  movq  %rdx,(%rax)
 .LNoThread:
-  movl  $-1,%eax
-{$endif}
+  movq  $-1,%rax
 .LSyscOK:
 end;
 
 function FpSysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL5'];
 
 asm
-{ load the registers... }
-  movl sysnr,%eax
-  movl param1,%ebx
-  movl param2,%ecx
-  movl param3,%edx
-  movl param4,%esi
-  movl param5,%edi
-  int $0x80
-  testl %eax,%eax
-  jns   .LSyscOK
-  negl  %eax
-{$ifdef VER1_0}
-  movl  %eax,Errno
-{$else}
-  movl  %eax,%edx
-  movl  FPC_THREADVAR_RELOCATE,%eax
-  testl %eax,%eax
+  movq sysnr, %rax        { Syscall number -> rax.  }
+  movq param1, %rdi         { shift arg1 - arg5. }
+  movq param2, %rsi
+  movq param3, %rdx
+  movq param4, %r10
+  movq param5, %r8
+  syscall                 { Do the system call. }
+  cmpq $-4095, %rax       { Check %rax for error.  }
+  jnae .LSyscOK           { Jump to error handler if error.  }  
+  negq  %rax
+  movq  %rax,%rdx
+  movq  FPC_THREADVAR_RELOCATE,%rax
+  testq %rax,%rax
   jne   .LThread
-  movl  %edx,Errno+4
+  movq  %rdx,Errno+4
   jmp   .LNoThread
 .LThread:
-  pushl %edx
-  pushl Errno
-  call  *%eax
-  popl  %edx
-  movl  %edx,(%eax)
+  pushq %rdx
+  pushq Errno
+  call  *%rax
+  popq  %rdx
+  movq  %rdx,(%rax)
 .LNoThread:
-  movl  $-1,%eax
-{$endif}
+  movq  $-1,%rax
 .LSyscOK:
 end;
 
@@ -268,27 +243,16 @@ Procedure FpSysCall( callnr:TSysParam;var regs : SysCallregs );assembler;
 }
 {$define fpc_syscall_ok}
 asm
-{ load the registers... }
-  movl 12(%ebp),%eax
-  movl 4(%eax),%ebx
-  movl 8(%eax),%ecx
-  movl 12(%eax),%edx
-  movl 16(%eax),%esi
-  movl 20(%eax),%edi
-{ set the call number }
-  movl 8(%ebp),%eax
-{ Go ! }
-  int $0x80
-{ Put back the registers... }
-  pushl %eax
-  movl 12(%ebp),%eax
-  movl %edi,20(%eax)
-  movl %esi,16(%eax)
-  movl %edx,12(%eax)
-  movl %ecx,8(%eax)
-  movl %ebx,4(%eax)
-  popl %ebx
-  movl %ebx,(%eax)
+  pushq %rdi
+  movq sysnr, %rax        { Syscall number -> rax.  }
+  movq 8(%rdi),%rsi       { load paras }
+  movq 16(%rdi),%rdx
+  movq 24(%rdi),%r10
+  movq 32(%rdi),%r8
+  movq (%rdi),%rdi
+  syscall                 { Do the system call. }
+  popq %rdi
+  movq %rax,(%rdi)
 end;
 
 {$ASMMODE DEFAULT}
@@ -301,7 +265,7 @@ Function SysCall( callnr:longint;var regs : SysCallregs ):longint;
 }
 begin
   FpSysCall(callnr,regs);
-  if regs.reg1<0 then
+  if regs.reg1>=$fffffffffffff001 then
    begin
 {$IFDEF SYSCALL_DEBUG}
      If DoSysCallDebug then
@@ -340,10 +304,12 @@ end;
 
 {
   $Log$
-  Revision 1.2  2004-02-05 01:16:12  florian
+  Revision 1.3  2004-02-06 15:58:21  florian
+    * fixed x86-64 assembler problems
+
+  Revision 1.2  2004/02/05 01:16:12  florian
     + completed x86-64/linux system unit
 
   Revision 1.1  2003/04/30 22:11:06  florian
     + for a lot of x86-64 dependend files mostly dummies added
 }
-

+ 6 - 4
rtl/linux/x86_64/syscallh.inc

@@ -22,8 +22,7 @@
 
 }
 
-Type
-
+type
   TSysResult = int64;   // all platforms, cint=32-bit.
                         // On platforms with off_t =64-bit, people should
                         // use int64, and typecast all calls that don't
@@ -46,7 +45,10 @@ function Do_SysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):T
 
 {
   $Log$
-  Revision 1.2  2003-05-01 08:05:23  florian
+  Revision 1.3  2004-02-06 15:58:21  florian
+    * fixed x86-64 assembler problems
+
+  Revision 1.2  2003/05/01 08:05:23  florian
     * started to make the rtl 64 bit save by introducing SizeInt and SizeUInt (similar to size_t of C)
 
   Revision 1.1  2003/04/30 22:11:06  florian
@@ -76,4 +78,4 @@ function Do_SysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):T
    * Updates for new errno scheme.
 
 
-}
+}

+ 14 - 11
rtl/x86_64/math.inc

@@ -28,9 +28,9 @@
 
     function Get8087CW:word;assembler;
     asm
-      pushl $0
+      pushq $0
       fnstcw (%rsp)
-      popl %eax
+      popq %rax
     end;
 
 {****************************************************************************
@@ -91,13 +91,13 @@
     {$define FPC_SYSTEM_HAS_FRAC}
     function frac(d : extended) : extended;assembler;[internconst:in_const_frac];
       asm
-            subl $16,%esp
-            fnstcw -4(%ebp)
+            subq $16,%rsp
+            fnstcw -4(%rbp)
             fwait
-            movw -4(%ebp),%cx
+            movw -4(%rbp),%cx
             orw $0x0c3f,%cx
-            movw %cx,-8(%ebp)
-            fldcw -8(%ebp)
+            movw %cx,-8(%rbp)
+            fldcw -8(%rbp)
             fwait
             fldt d
             frndint
@@ -105,14 +105,14 @@
             fsub %st(1),%st
             fstp %st(1)
             fclex
-            fldcw -4(%ebp)
+            fldcw -4(%rbp)
       end ['ECX'];
 
 
     {$define FPC_SYSTEM_HAS_INT}
     function int(d : extended) : extended;assembler;[internconst:in_const_int];
       asm
-            subl $16,%rsp
+            subq $16,%rsp
             fnstcw -4(%rbp)
             fwait
             movw -4(%rbp),%cx
@@ -198,9 +198,12 @@
 
 {
   $Log$
-  Revision 1.2  2004-02-05 01:16:12  florian
+  Revision 1.3  2004-02-06 15:58:21  florian
+    * fixed x86-64 assembler problems
+
+  Revision 1.2  2004/02/05 01:16:12  florian
     + completed x86-64/linux system unit
 
   Revision 1.1  2003/04/30 22:11:06  florian
     + for a lot of x86-64 dependend files mostly dummies added
-}
+}

+ 9 - 6
rtl/x86_64/x86_64.inc

@@ -33,7 +33,7 @@ end;
 {$define FPC_SYSTEM_HAS_SPTR}
 Function Sptr : Pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif}
 asm
-        movl    %rsp,%rax
+        movq    %rsp,%rax
 end ['RAX'];
 
 
@@ -61,11 +61,11 @@ end ['RAX'];
 function get_caller_frame(framebp:pointer):pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif}
 asm
 {$ifndef REGCALL}
-        movl    framebp,%rax
+        movq    framebp,%rax
 {$endif}
-        orl     %rax,%rax
+        orq     %rax,%rax
         jz      .Lgnf_null
-        movl    (%rax),%rax
+        movq    (%rax),%rax
 .Lgnf_null:
 end ['RAX'];
 {$define FPC_SYSTEM_HAS_MOVE}
@@ -300,7 +300,10 @@ const
 
 {
   $Log$
-  Revision 1.5  2004-02-05 01:16:12  florian
+  Revision 1.6  2004-02-06 15:58:21  florian
+    * fixed x86-64 assembler problems
+
+  Revision 1.5  2004/02/05 01:16:12  florian
     + completed x86-64/linux system unit
 
   Revision 1.4  2004/01/20 12:52:18  florian
@@ -314,4 +317,4 @@ const
 
   Revision 1.1  2003/01/06 19:40:18  florian
     + initial revision
-}
+}