Browse Source

* 64-bit FreeBSD port files

git-svn-id: trunk@7082 -
marco 18 năm trước cách đây
mục cha
commit
96ac89f6d5

+ 8 - 6
compiler/systems/i_bsd.pas

@@ -99,7 +99,9 @@ unit i_bsd;
             system       : system_x86_64_freebsd;
             system       : system_x86_64_freebsd;
             name         : 'FreeBSD for x86-64';
             name         : 'FreeBSD for x86-64';
             shortname    : 'FreeBSD';
             shortname    : 'FreeBSD';
-            flags        : [tf_needs_symbol_size,tf_pic_uses_got,tf_files_case_sensitive,tf_use_function_relative_addresses{,tf_smartlink_sections}];
+            flags        : [tf_needs_symbol_size,tf_needs_dwarf_cfi,{Linux: tf_library_needs_pic,}tf_needs_symbol_type,
+                            tf_files_case_sensitive,tf_use_function_relative_addresses
+                                {	tf_pic_uses_got,tf_smartlink_sections}];
             cpu          : cpu_x86_64;
             cpu          : cpu_x86_64;
             unit_env     : 'BSDUNITS';
             unit_env     : 'BSDUNITS';
             extradefines : 'UNIX;HASUNIX;BSD';
             extradefines : 'UNIX;HASUNIX;BSD';
@@ -124,13 +126,13 @@ unit i_bsd;
             Cprefix      : '';
             Cprefix      : '';
             newline      : #10;
             newline      : #10;
             dirsep       : '/';
             dirsep       : '/';
-            assem        : as_gas;
+            assem        : as_x86_64_elf64;
             assemextern  : as_gas;
             assemextern  : as_gas;
             link         : nil;
             link         : nil;
             linkextern   : nil;
             linkextern   : nil;
             ar           : ar_gnu_ar;
             ar           : ar_gnu_ar;
             res          : res_none;
             res          : res_none;
-            dbg          : dbg_stabs;
+            dbg          : dbg_dwarf2;            //dbg_stabs;
             script       : script_unix;
             script       : script_unix;
             endian       : endian_little;
             endian       : endian_little;
             alignment    :
             alignment    :
@@ -141,11 +143,11 @@ unit i_bsd;
                 constalignmin   : 0;
                 constalignmin   : 0;
                 constalignmax   : 8;
                 constalignmax   : 8;
                 varalignmin     : 0;
                 varalignmin     : 0;
-                varalignmax     : 8;
+                varalignmax     : 16;
                 localalignmin   : 4;
                 localalignmin   : 4;
-                localalignmax   : 8;
+                localalignmax   : 16;
                 recordalignmin  : 0;
                 recordalignmin  : 0;
-                recordalignmax  : 8;
+                recordalignmax  : 16;
                 maxCrecordalign : 8
                 maxCrecordalign : 8
               );
               );
             first_parm_offset : 16;
             first_parm_offset : 16;

+ 123 - 119
rtl/bsd/x86_64/syscall.inc

@@ -22,113 +22,135 @@
 - More 6 and 7 param dosyscall because of the __syscall problem
 - More 6 and 7 param dosyscall because of the __syscall problem
 }
 }
 
 
-{ASMMODE GAS}
+{$ASMMODE GAS}
 
 
-function fpsysCall(sysnr:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL0'];
+function fpsysCall(sysnr:TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS0'];
 
 
 asm
 asm
   movq sysnr, %rax        { Syscall number -> rax.  }
   movq sysnr, %rax        { Syscall number -> rax.  }
   syscall                 { Do the system call. }
   syscall                 { Do the system call. }
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
-  movq  %rax,%rcx
+ movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%r11
+{$else FPC_PIC}
   movq  fpc_threadvar_relocate_proc,%rax
   movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%r11
+{$endif FPC_PIC}
   testq %rax,%rax
   testq %rax,%rax
   jne   .LThread
   jne   .LThread
-  movq  %rcx,Errno+8
+  movl  %edx,8(%r11)
   jmp   .LNoThread
   jmp   .LNoThread
 .LThread:
 .LThread:
-  pushq %rcx
-  pushq Errno
+  pushq %rdx
+  movq  (%r11),%rdi
   call  *%rax
   call  *%rax
-  popq  %rcx
-  movq  %rcx,(%rax)
+  popq  %rdx
+  movl  %edx,(%rax)
 .LNoThread:
 .LNoThread:
   movq  $-1,%rax
   movq  $-1,%rax
-  movq  %rax,%rdx
 .LSyscOK:
 .LSyscOK:
 end;
 end;
 
 
-function fpsysCall(sysnr,param1 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL1'];
+function fpsysCall(sysnr,param1 : TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS1'];
 
 
 asm
 asm
   movq sysnr, %rax        { Syscall number -> rax.  }
   movq sysnr, %rax        { Syscall number -> rax.  }
   movq param1, %rdi         { shift arg1 - arg1. }
   movq param1, %rdi         { shift arg1 - arg1. }
   syscall                 { Do the system call. }
   syscall                 { Do the system call. }
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
-  movq  %rax,%rcx
+ movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%r11
+{$else FPC_PIC}
   movq  fpc_threadvar_relocate_proc,%rax
   movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%r11
+{$endif FPC_PIC}
   testq %rax,%rax
   testq %rax,%rax
   jne   .LThread
   jne   .LThread
-  movq  %rcx,Errno+8
+  movl  %edx,8(%r11)
   jmp   .LNoThread
   jmp   .LNoThread
 .LThread:
 .LThread:
-  pushq %rcx
-  pushq Errno
+  pushq %rdx
+  movq  (%r11),%rdi
   call  *%rax
   call  *%rax
-  popq  %rcx
-  movq  %rcx,(%rax)
+  popq  %rdx
+  movl  %edx,(%rax)
 .LNoThread:
 .LNoThread:
   movq  $-1,%rax
   movq  $-1,%rax
-  movq  %rax,%rdx
 .LSyscOK:
 .LSyscOK:
 end;
 end;
 
 
-function fpsysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL2'];
+function fpsysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS2'];
 
 
 asm
 asm
   movq sysnr, %rax        { Syscall number -> rax.  }
   movq sysnr, %rax        { Syscall number -> rax.  }
   movq param1, %rdi         { shift arg1 - arg2. }
   movq param1, %rdi         { shift arg1 - arg2. }
   movq param2, %rsi
   movq param2, %rsi
-  mov %rcx,%r10
   syscall                 { Do the system call. }
   syscall                 { Do the system call. }
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
-  movq  %rax,%rcx
+ movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%r11
+{$else FPC_PIC}
   movq  fpc_threadvar_relocate_proc,%rax
   movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%r11
+{$endif FPC_PIC}
   testq %rax,%rax
   testq %rax,%rax
   jne   .LThread
   jne   .LThread
-  movq  %rcx,Errno+8
+  movl  %edx,8(%r11)
   jmp   .LNoThread
   jmp   .LNoThread
 .LThread:
 .LThread:
-  pushq %rcx
-  pushq Errno
+  pushq %rdx
+  movq  (%r11),%rdi
   call  *%rax
   call  *%rax
-  popq  %rcx
-  movq  %rcx,(%rax)
+  popq  %rdx
+  movl  %edx,(%rax)
 .LNoThread:
 .LNoThread:
   movq  $-1,%rax
   movq  $-1,%rax
-  movq  %rax,%rdx
 .LSyscOK:
 .LSyscOK:
 end;
 end;
 
 
-function fpsysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL3'];
+function fpsysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS3'];
 
 
 asm
 asm
   movq sysnr, %rax        { Syscall number -> rax.  }
   movq sysnr, %rax        { Syscall number -> rax.  }
   movq param1, %rdi         { shift arg1 - arg3. }
   movq param1, %rdi         { shift arg1 - arg3. }
   movq param2, %rsi
   movq param2, %rsi
   movq param3, %rdx
   movq param3, %rdx
-  mov %rcx,%r10
   syscall                 { Do the system call. }
   syscall                 { Do the system call. }
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
-  movq  %rax,%rcx
+ movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%r11
+{$else FPC_PIC}
   movq  fpc_threadvar_relocate_proc,%rax
   movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%r11
+{$endif FPC_PIC}
   testq %rax,%rax
   testq %rax,%rax
   jne   .LThread
   jne   .LThread
-  movq  %rcx,Errno+8
+  movl  %edx,8(%r11)
   jmp   .LNoThread
   jmp   .LNoThread
 .LThread:
 .LThread:
-  pushq %rcx
-  pushq Errno
+  pushq %rdx
+  movq  (%r11),%rdi
   call  *%rax
   call  *%rax
-  popq  %rcx
-  movq  %rcx,(%rax)
+  popq  %rdx
+  movl  %edx,(%rax)
 .LNoThread:
 .LNoThread:
   movq  $-1,%rax
   movq  $-1,%rax
-  movq  %rax,%rdx
 .LSyscOK:
 .LSyscOK:
 end;
 end;
 
 
-function fpsysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL4'];
+function fpsysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS4'];
 
 
 asm
 asm
   movq sysnr, %rax        { Syscall number -> rax.  }
   movq sysnr, %rax        { Syscall number -> rax.  }
@@ -136,28 +158,33 @@ asm
   movq param2, %rsi
   movq param2, %rsi
   movq param3, %rdx
   movq param3, %rdx
   movq param4, %r10
   movq param4, %r10
-  mov %rcx,%r10
   syscall                 { Do the system call. }
   syscall                 { Do the system call. }
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
-  movq  %rax,%rcx
+ movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%r11
+{$else FPC_PIC}
   movq  fpc_threadvar_relocate_proc,%rax
   movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%r11
+{$endif FPC_PIC}
   testq %rax,%rax
   testq %rax,%rax
   jne   .LThread
   jne   .LThread
-  movq  %rcx,Errno+8
+  movl  %edx,8(%r11)
   jmp   .LNoThread
   jmp   .LNoThread
 .LThread:
 .LThread:
-  pushq %rcx
-  pushq Errno
+  pushq %rdx
+  movq  (%r11),%rdi
   call  *%rax
   call  *%rax
-  popq  %rcx
-  movq  %rcx,(%rax)
+  popq  %rdx
+  movl  %edx,(%rax)
 .LNoThread:
 .LNoThread:
   movq  $-1,%rax
   movq  $-1,%rax
-  movq  %rax,%rdx
 .LSyscOK:
 .LSyscOK:
 end;
 end;
 
 
-function fpsysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL5'];
+function fpsysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS5'];
 
 
 asm
 asm
   movq sysnr, %rax        { Syscall number -> rax.  }
   movq sysnr, %rax        { Syscall number -> rax.  }
@@ -166,29 +193,34 @@ asm
   movq param3, %rdx
   movq param3, %rdx
   movq param4, %r10
   movq param4, %r10
   movq param5, %r8
   movq param5, %r8
-  mov %rcx,%r10
   syscall                 { Do the system call. }
   syscall                 { Do the system call. }
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
-  movq  %rax,%rcx
+ movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%r11
+{$else FPC_PIC}
   movq  fpc_threadvar_relocate_proc,%rax
   movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%r11
+{$endif FPC_PIC}
   testq %rax,%rax
   testq %rax,%rax
   jne   .LThread
   jne   .LThread
-  movq  %rcx,Errno+8
+  movl  %edx,8(%r11)
   jmp   .LNoThread
   jmp   .LNoThread
 .LThread:
 .LThread:
-  pushq %rcx
-  pushq Errno
+  pushq %rdx
+  movq  (%r11),%rdi
   call  *%rax
   call  *%rax
-  popq  %rcx
-  movq  %rcx,(%rax)
+  popq  %rdx
+  movl  %edx,(%rax)
 .LNoThread:
 .LNoThread:
   movq  $-1,%rax
   movq  $-1,%rax
-  movq  %rax,%rdx
 .LSyscOK:
 .LSyscOK:
 end;
 end;
 
 
 
 
-function fpsysCall(sysnr,param1,param2,param3,param4,param5,param6 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL6'];
+function fpsysCall(sysnr,param1,param2,param3,param4,param5,param6 : TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS6'];
 
 
 asm
 asm
   movq sysnr, %rax        { Syscall number -> rax.  }
   movq sysnr, %rax        { Syscall number -> rax.  }
@@ -198,96 +230,68 @@ asm
   movq param4, %r10
   movq param4, %r10
   movq param5, %r8
   movq param5, %r8
   movq param6, %r9
   movq param6, %r9
-  mov %rcx,%r10
   syscall                 { Do the system call. }
   syscall                 { Do the system call. }
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
-  movq  %rax,%rcx
+
+ movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%r11
+{$else FPC_PIC}
   movq  fpc_threadvar_relocate_proc,%rax
   movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%r11
+{$endif FPC_PIC}
   testq %rax,%rax
   testq %rax,%rax
   jne   .LThread
   jne   .LThread
-  movq  %rcx,Errno+8
+  movl  %edx,8(%r11)
   jmp   .LNoThread
   jmp   .LNoThread
 .LThread:
 .LThread:
-  pushq %rcx
-  pushq Errno
+  pushq %rdx
+  movq  (%r11),%rdi
   call  *%rax
   call  *%rax
-  popq  %rcx
-  movq  %rcx,(%rax)
+  popq  %rdx
+  movl  %edx,(%rax)
 .LNoThread:
 .LNoThread:
   movq  $-1,%rax
   movq  $-1,%rax
-  movq  %rax,%rdx
 .LSyscOK:
 .LSyscOK:
-end;
 
 
-function fpsysCall(sysnr,param1,param2,param3,param4,param5,param6,param7 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL7'];
+end;
+//                    edi   esi   edx 	 ecx    r8      r9   stack
+function fp_sysCall(sysnr,param1,param2,param3,param4,param5,param6 : TSysParam):TSysResult; assembler;[public,alias:'FPC__DOSYS'];
 
 
 asm
 asm
-  mov param7,%rax
-  pushq %rax
-  movq sysnr, %rax        { Syscall number -> rax.  }
-  movq param1, %rdi         { shift arg1 - arg6. }
-  movq param2, %rsi
-  movq param3, %rdx
-  movq param4, %r10
-  movq param5, %r8
-  movq param6, %r9
-  mov %rcx,%r10
+  sub    $0x18,%rsp
+  movq   param6,%rax	// from caller stack to mine.	
+  movq   %rax,0x8(%rsp)
+  movl   $0, 0(%rsp)    // dummy or caller frame because ?
+  mov    $0xc6,%rax	// __syscall
+  mov    %rcx,%r10
   syscall                 { Do the system call. }
   syscall                 { Do the system call. }
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
-  movq  %rax,%rcx
+  movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%r11
+{$else FPC_PIC}
   movq  fpc_threadvar_relocate_proc,%rax
   movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%r11
+{$endif FPC_PIC}
   testq %rax,%rax
   testq %rax,%rax
   jne   .LThread
   jne   .LThread
-  movq  %rcx,Errno+8
+  movl  %edx,8(%r11)
   jmp   .LNoThread
   jmp   .LNoThread
 .LThread:
 .LThread:
-  pushq %rcx
-  pushq Errno
+  pushq %rdx
+  movq  (%r11),%rdi
   call  *%rax
   call  *%rax
-  popq  %rcx
-  movq  %rcx,(%rax)
+  popq  %rdx
+  movl  %edx,(%rax)
 .LNoThread:
 .LNoThread:
   movq  $-1,%rax
   movq  $-1,%rax
-  movq  %rax,%rdx
 .LSyscOK:
 .LSyscOK:
-  popq %rax
+  add    $0x18,%rsp
 end;
 end;
 
 
 
 
-procedure actualsyscall; assembler; {inline requires a dummy push IIRC}
-    asm
-     syscall
-     jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
-     movq  %rax,%rcx
-     movq  fpc_threadvar_relocate_proc,%rax
-     testq %rax,%rax
-     jne   .LThread
-     movq  %rcx,Errno+8
-     jmp   .LNoThread
-   .LThread:
-     pushq %rcx
-     pushq Errno
-     call  *%rax
-     popq  %rcx
-     movq  %rcx,(%rax)
-   .LNoThread:
-     movq  $-1,%rax
-     movq  %rax,%rdx
-   .LSyscOK:
-end;
-
-
-function fp_sysCall(sysnr,param1,param2,param3,param4,param5,param6,param7,Param8:TSysParam):TSysResult; assembler;assembler;[public,alias:'FPC_DOSYS8'];
-// Hmm, we have to do something different :)
-
-asm
-  movq param8,%rax
-  push %rax
-  movq param7,%rax
-  push %rax
-  movq $198,  %rax
-  mov %rcx,%r10
-  call actualsyscall
-  add $16,%rsp
-end;
-

+ 2 - 2
rtl/bsd/x86_64/syscallh.inc

@@ -39,9 +39,9 @@ function do_sysCall(sysnr,param1,param2,param3:TSysParam):TSysResult;oldfpccall;
 function do_sysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult;oldfpccall; external name 'FPC_DOSYS4';
 function do_sysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult;oldfpccall; external name 'FPC_DOSYS4';
 function do_sysCall(sysnr,param1,param2,param3,param4,param5:TSysParam):TSysResult; oldfpccall;  external name 'FPC_DOSYS5';
 function do_sysCall(sysnr,param1,param2,param3,param4,param5:TSysParam):TSysResult; oldfpccall;  external name 'FPC_DOSYS5';
 function do_sysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):int64;oldfpccall;  external name 'FPC_DOSYS6';
 function do_sysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):int64;oldfpccall;  external name 'FPC_DOSYS6';
-function do_sysCall(sysnr,param1,param2,param3,param4,param5,param6,param7:TSysParam):int64;oldfpccall;  external name 'FPC_DOSYS7';
+//function do_sysCall(sysnr,param1,param2,param3,param4,param5,param6,param7:TSysParam):int64;oldfpccall;  external name 'FPC_DOSYS7';
 
 
 // special
 // special
-function do__sysCall(sysnr,param1,param2,param3,param4,param5,param6,param7,Param8:TSysParam):TSysResult; oldfpccall;  external name 'FPC_DOSYS8';
+function do__sysCall(sysnr,param1,param2,param3,param4,param5,param6,param7,Param8:TSysParam):TSysResult; oldfpccall;  external name 'FPC__DOSYS';
 {$endif}
 {$endif}