Sfoglia il codice sorgente

--- Merging r20642 into '.':
U rtl/netbsd/i386/sighnd.inc
--- Merging r20689 into '.':
U rtl/netbsd/ptypes.inc
--- Merging r20710 into '.':
U rtl/openbsd/ptypes.inc
--- Merging r20711 into '.':
U rtl/openbsd/signal.inc
--- Merging r20712 into '.':
U rtl/openbsd/i386/sighnd.inc
--- Merging r20713 into '.':
A rtl/openbsd/x86_64
A rtl/openbsd/x86_64/bsyscall.inc
A rtl/openbsd/x86_64/sighnd.inc
A rtl/openbsd/x86_64/prt0.as
A rtl/openbsd/x86_64/crt0.s
A rtl/openbsd/x86_64/cprt0.as
A rtl/openbsd/x86_64/gprt0.as
--- Merging r20719 into '.':
U utils/fpcm/fpcmmain.pp
--- Merging r20738 into '.':
G rtl/netbsd/ptypes.inc

# revisions: 20642,20689,20710,20711,20712,20713,20719,20738
------------------------------------------------------------------------
r20642 | pierre | 2012-03-27 17:34:00 +0200 (Tue, 27 Mar 2012) | 1 line
Changed paths:
M /trunk/rtl/netbsd/i386/sighnd.inc

Avoid SEGV in signal handler as second parameter is only a code, not a pointer
------------------------------------------------------------------------
------------------------------------------------------------------------
r20689 | pierre | 2012-04-01 23:27:18 +0200 (Sun, 01 Apr 2012) | 1 line
Changed paths:
M /trunk/rtl/netbsd/ptypes.inc

* Fix pthread_mutexattr_t type according to /usr/include/pthread_types.h
------------------------------------------------------------------------
------------------------------------------------------------------------
r20710 | pierre | 2012-04-05 22:54:05 +0200 (Thu, 05 Apr 2012) | 1 line
Changed paths:
M /trunk/rtl/openbsd/ptypes.inc

* Fix ino_t and dev_t types for x86_64 cpu
------------------------------------------------------------------------
------------------------------------------------------------------------
r20711 | pierre | 2012-04-05 22:55:05 +0200 (Thu, 05 Apr 2012) | 1 line
Changed paths:
M /trunk/rtl/openbsd/signal.inc

+ Add x86_64 cpu sigcontext record
------------------------------------------------------------------------
------------------------------------------------------------------------
r20712 | pierre | 2012-04-05 22:56:15 +0200 (Thu, 05 Apr 2012) | 1 line
Changed paths:
M /trunk/rtl/openbsd/i386/sighnd.inc

* Don't try to read sininfo record
------------------------------------------------------------------------
------------------------------------------------------------------------
r20713 | pierre | 2012-04-05 23:01:47 +0200 (Thu, 05 Apr 2012) | 1 line
Changed paths:
A /trunk/rtl/openbsd/x86_64
A /trunk/rtl/openbsd/x86_64/bsyscall.inc
A /trunk/rtl/openbsd/x86_64/cprt0.as
A /trunk/rtl/openbsd/x86_64/crt0.s
A /trunk/rtl/openbsd/x86_64/gprt0.as
A /trunk/rtl/openbsd/x86_64/prt0.as
A /trunk/rtl/openbsd/x86_64/sighnd.inc

+ Initial implementation for openbsd x86_64 cpu specific rtl code
------------------------------------------------------------------------
------------------------------------------------------------------------
r20719 | pierre | 2012-04-05 23:12:30 +0200 (Thu, 05 Apr 2012) | 1 line
Changed paths:
M /trunk/utils/fpcm/fpcmmain.pp

+ Add x86_64 cpu support for openbsd target
------------------------------------------------------------------------
------------------------------------------------------------------------
r20738 | pierre | 2012-04-07 01:57:00 +0200 (Sat, 07 Apr 2012) | 1 line
Changed paths:
M /trunk/rtl/netbsd/ptypes.inc

ino_t is 64 bit for 32-bit system also for NetBSD
------------------------------------------------------------------------

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

marco 13 anni fa
parent
commit
90af016c9d

+ 6 - 0
.gitattributes

@@ -7897,6 +7897,12 @@ rtl/openbsd/unxconst.inc svneol=native#text/plain
 rtl/openbsd/unxfunc.inc svneol=native#text/plain
 rtl/openbsd/unxsockh.inc svneol=native#text/plain
 rtl/openbsd/unxsysc.inc svneol=native#text/plain
+rtl/openbsd/x86_64/bsyscall.inc svneol=native#text/plain
+rtl/openbsd/x86_64/cprt0.as svneol=native#text/plain
+rtl/openbsd/x86_64/crt0.s svneol=native#text/plain
+rtl/openbsd/x86_64/gprt0.as svneol=native#text/plain
+rtl/openbsd/x86_64/prt0.as svneol=native#text/plain
+rtl/openbsd/x86_64/sighnd.inc svneol=native#text/plain
 rtl/os2/Makefile svneol=native#text/plain
 rtl/os2/Makefile.fpc svneol=native#text/plain
 rtl/os2/classes.pp svneol=native#text/plain

+ 9 - 2
rtl/netbsd/i386/sighnd.inc

@@ -38,6 +38,7 @@ const
 procedure SignalToRunerror(Sig: longint;info : PSigInfo;SigContext: PSigContextRec); public name '_FPC_DEFAULTSIGHANDLER'; cdecl;
 
 var
+  code : ptruint;
   res,fpustate : word;
 begin
   res:=0;
@@ -49,14 +50,20 @@ begin
   end;
 {$endif cpui386}
 {$endif BSD}
+{$ifdef DEBUG}
+         Writeln(stderr,'Info is 0x',hexstr(ptruint(info),8));
+{$endif}
   case sig of
     SIGFPE :
           begin
     { this is not allways necessary but I don't know yet
       how to tell if it is or not PM }
           res:=200;
-          if assigned(info) then
-            fpustate:=info^._info.si_code
+          { In netbsd, the second parameter is a code, not a pointer to a siginfo structure
+            at least as long as we use sigaction14 }
+          code:=ptruint(info);
+          if code < high(fpustate) then
+            fpustate:=code
           else
             fpustate:=FPE_IntDiv;
 

+ 5 - 2
rtl/netbsd/ptypes.inc

@@ -33,7 +33,7 @@ type
     pGid     = ^gid_t;
     TIOCtlRequest = cuLong;
 
-    ino_t    = clong;           { used for file serial numbers }
+    ino_t    = cint64;          { used for file serial numbers }
     TIno     = ino_t;
     pIno     = ^ino_t;
 
@@ -150,7 +150,10 @@ type
    pthread_t            = pointer;
    pthread_attr_t       = pointer;
    pthread_mutex_t      = {$i pmutext.inc}
-   pthread_mutexattr_t  = pointer;
+   pthread_mutexattr_t = record
+     ptma_magic : cint;
+     ptma_private : pointer;
+   end;
    pthread_cond_t       = pointer;
    pthread_condattr_t   = pointer;
    pthread_key_t        = cint;

+ 19 - 3
rtl/openbsd/i386/sighnd.inc

@@ -15,10 +15,23 @@
 
 CONST FPU_ALL=$7F;
 
+{$ifdef cpui386}
 function getfpustate(sininfo:psiginfo):longint; {inline;}
 begin
-  getfpustate:=sininfo^.si_code;
+  if ptruint(sininfo)> high(word) then
+    getfpustate:=sininfo^.si_code
+  else
+    getfpustate:=word(ptruint(sininfo));
+end;
+
+function getaltfpustate(sigcontext:psigcontextrec):longint; {inline;}
+begin
+  if assigned(sigcontext) then
+    getaltfpustate:=sigcontext^.sc_fpustate^.en_sw 
+  else
+    getaltfpustate:=0;
 end;
+{$endif}
 
 procedure SignalToRunerror(Sig: longint;sininfo:psiginfo; SigContext: PSigContextRec); public name '_FPC_DEFAULTSIGHANDLER'; cdecl;
 
@@ -40,8 +53,11 @@ begin
     { this is not allways necessary but I don't know yet
       how to tell if it is or not PM }
           res:=200;
-          fpustate:=GetFPUState(sininfo);
-
+{$ifdef cpui386}
+          fpustate:=GetaltFPUState(sigcontext);
+{$else}
+          fpustate:=0;
+{$endif}
           if (FpuState and FPU_All) <> 0 then
             begin
               { first check the more precise options }

+ 2 - 2
rtl/openbsd/ptypes.inc

@@ -24,7 +24,7 @@
 
 type
 
-    dev_t    = cuint32;         { used for device numbers      }
+    dev_t    = cint32;          { used for device numbers      }
     TDev     = dev_t;
     pDev     = ^dev_t;
 
@@ -33,7 +33,7 @@ type
     pGid     = ^gid_t;
     TIOCtlRequest = cuLong;
 
-    ino_t    = clong;           { used for file serial numbers }
+    ino_t    = cuint32;         { used for file serial numbers }
     TIno     = ino_t;
     pIno     = ^ino_t;
 

+ 132 - 6
rtl/openbsd/signal.inc

@@ -80,10 +80,18 @@ type sigset_t = array[0..3] of cardinal;
 
     PSigContextRec = ^SigContextRec;
     psigcontext = ^sigcontextrec;
+{$ifdef cpui386}
+    PFpuState = ^TFpuState;
+{$endif def cpui386}
+{$ifdef cpux86_64}
+    PFpu64State = ^TFpu64State;
+{$endif def cpux86_64}
     SigContextRec = record
-       sc_mask      : sigset_t;          { signal mask to restore }
+{$ifdef cpui386}
+(*     sc_mask      : sigset_t;          { signal mask to restore }
        sc_onstack   : longint;              { sigstack state to restore }
-
+       I did not find those fields in OpenBSD
+       /usr/iclude/i386/signal.h header *)
        sc_gs        : longint;              { machine state (struct trapframe): }
        sc_fs        : longint;
        sc_es        : longint;
@@ -91,18 +99,55 @@ type sigset_t = array[0..3] of cardinal;
        sc_edi       : longint;
        sc_esi       : longint;
        sc_ebp       : longint;
-       sc_isp       : longint;
        sc_ebx       : longint;
        sc_edx       : longint;
        sc_ecx       : longint;
        sc_eax       : longint;
-       sc_trapno    : longint;
-       sc_err       : longint;
        sc_eip       : longint;
        sc_cs        : longint;
        sc_efl       : longint;
        sc_esp       : longint;
        sc_ss        : longint;
+       sc_onstack   : longint;
+       sc_mask      : longint;
+       sc_trapno    : longint;
+       sc_err       : longint;
+       sc_fpustate  : pfpustate;
+{$endif def cpui386}
+{$ifdef cpux86_64}
+	sc_rdi : clong;
+	sc_rsi : clong;
+        sc_rdx : clong;
+	sc_rcx : clong;
+	sc_r8  : clong;
+	sc_r9  : clong;
+	sc_r10 : clong;
+	sc_r11 : clong;
+	sc_r12 : clong;
+	sc_r13 : clong;
+	sc_r14 : clong;
+	sc_r15 : clong;
+	sc_rbp : clong;
+	sc_rbx : clong;
+	sc_rax : clong;
+	sc_gs  : clong;
+	sc_fs  : clong;
+	sc_es  : clong;
+	sc_ds  : clong;
+	sc_trapno : clong;
+	sc_err : clong;
+	sc_rip : clong;
+	sc_cs  : clong;
+	sc_rflags : clong;
+	sc_rsp : clong;
+	sc_ss  : clong;
+	sc_fpstate : PFpu64State;
+	sc_onstack : cint;
+	sc_mask : cint;
+{$endif def cpux86_64}
+     end;
+{$ifdef cpui386}
+     TFpuState = record
         {
          * XXX FPU state is 27 * 4 bytes h/w, 1 * 4 bytes s/w (probably not
          * needed here), or that + 16 * 4 bytes for emulators (probably all
@@ -117,11 +162,92 @@ type sigset_t = array[0..3] of cardinal;
        en_foo       : cardinal;     { floating operand offset }
        en_fos       : cardinal;     { floating operand segment selector }
        fpr_acc      : array[0..79] of char;
-       fpr_ex_sw    : cardinal;
+       fpr_ex_sw    : cardinal;     { status word of last exception }
+       fpr_ex_tw    : cardinal;     { tag word of last exception }
        fpr_pad      : array[0..63] of char;
        end;
+{$endif def cpui386}
+
+(*  From /usr/include/amd64/fpu.h header 
+/*
+ * amd64 only uses the extended save/restore format used
+ * by fxsave/fsrestore, to always deal with the SSE registers,
+ * which are part of the ABI to pass floating point values.
+ * Must be stored in memory on a 16-byte boundary.
+ */
+
+struct fxsave64 {
+	u_int16_t  fx_fcw;
+	u_int16_t  fx_fsw;
+	u_int8_t   fx_ftw;
+	u_int8_t   fx_unused1;
+	u_int16_t  fx_fop;
+	u_int64_t  fx_rip;
+	u_int64_t  fx_rdp;
+	u_int32_t  fx_mxcsr;
+	u_int32_t  fx_mxcsr_mask;
+	u_int64_t  fx_st[8][2];   /* 8 normal FP regs */
+	u_int64_t  fx_xmm[16][2]; /* 16 SSE2 registers */
+	u_int8_t   fx_unused3[96];
+} __packed;
+
+struct savefpu {
+	struct fxsave64 fp_fxsave;	/* see above */
+	u_int16_t fp_ex_sw;		/* saved status from last exception */
+	u_int16_t fp_ex_tw;		/* saved tag from last exception */
+}; *)
+{$ifdef cpux86_64}
+    TFpu64State = packed record
+	fx_fcw : cuint16;
+        fx_fsw : cuint16;
+        fx_ftw : cuint8;
+        fx_unused1 : cuint8;
+        fx_fop : cuint16;
+        fx_rip : cuint64;
+        fx_rdp : cuint64;
+        fx_mxcsr : cuint32;
+        fx_mxcsr_mask : cuint32;
+        fx_st : array[0..7] of array [0..1] of cuint64;
+        fx_xmm : array [0..15] of array [0..1] of cuint64;
+        fx_unusued3 : array [0..95] of cuint8;
+    end;
+{$endif def cpux86_64}
 
+(* From /usr/include/amd64/signal.h 
+  struct sigcontext {
+	/* plain match trapframe */
+   Sig64Context  = Record
+	long	sc_rdi;
+	long	sc_rsi;
+	long	sc_rdx;
+	long	sc_rcx;
+	long	sc_r8;
+	long	sc_r9;
+	long	sc_r10;
+	long	sc_r11;
+	long	sc_r12;
+	long	sc_r13;
+	long	sc_r14;
+	long	sc_r15;
+	long	sc_rbp;
+	long	sc_rbx;
+	long	sc_rax;
+	long	sc_gs;
+	long	sc_fs;
+	long	sc_es;
+	long	sc_ds;
+	long	sc_trapno;
+	long	sc_err;
+	long	sc_rip;
+	long	sc_cs;
+	long	sc_rflags;
+	long	sc_rsp;
+	long	sc_ss;
 
+	struct fxsave64 *sc_fpstate;
+	int	sc_onstack;
+	int	sc_mask;
+}; *)
   Sigval = Record
             Case Boolean OF
         { Members as suggested by Annex C of POSIX 1003.1b. }

+ 14 - 0
rtl/openbsd/x86_64/bsyscall.inc

@@ -0,0 +1,14 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2005 by Michael Van Canneyt,
+    member of the Free Pascal development team.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+

+ 236 - 0
rtl/openbsd/x86_64/cprt0.as

@@ -0,0 +1,236 @@
+	.file	"crt0.c"
+	.globl	__progname
+	.section	.rodata
+.LC0:
+	.string	""
+	.data
+	.align 8
+	.type	__progname, @object
+	.size	__progname, 8
+__progname:
+	.quad	.LC0
+#APP
+	 .text				
+	.align	8			
+	.globl	__start			
+	.globl	_start			
+_start:					
+__start:				
+	movq	%rbx,%r9		
+	movq	%rcx,%r8		
+	movq	%rdx,%rcx		
+	movq	(%rsp),%rdi		
+	leaq	16(%rsp,%rdi,8),%rdx	
+	leaq	8(%rsp),%rsi		
+	subq	$8,%rsp			
+	andq	$~15,%rsp		
+	addq	$8,%rsp			
+	jmp	___start		
+
+#NO_APP
+	.text
+	.globl	___start
+	.type	___start, @function
+___start:
+.LFB9:
+	pushq	%rbp
+.LCFI0:
+	movq	%rsp, %rbp
+.LCFI1:
+	subq	$64, %rsp
+.LCFI2:
+	movl	%edi, -20(%rbp)
+	movq	%rsi, -32(%rbp)
+	movq	%rdx, -40(%rbp)
+	movq	%rcx, -48(%rbp)
+	movq	%r8, -56(%rbp)
+	movq	%r9, -64(%rbp)
+	movq	-40(%rbp), %rax
+	movq	%rax, environ(%rip)
+	movq    %rax,operatingsystem_parameter_envp
+	movq	-32(%rbp), %rax
+	movq	(%rax), %rax
+	movq	%rax, -8(%rbp)
+	cmpq	$0, -8(%rbp)
+	je	.L2
+	movq	-8(%rbp), %rdi
+	movl	$47, %esi
+	call	_strrchr
+	movq	%rax, __progname(%rip)
+	movq	__progname(%rip), %rax
+	testq	%rax, %rax
+	jne	.L4
+	movq	-8(%rbp), %rax
+	movq	%rax, __progname(%rip)
+	jmp	.L6
+.L4:
+	movq	__progname(%rip), %rax
+	addq	$1, %rax
+	movq	%rax, __progname(%rip)
+.L6:
+	movq	$__progname_storage, -16(%rbp)
+	jmp	.L7
+.L8:
+	movq	__progname(%rip), %rcx
+	movzbl	(%rcx), %edx
+	movq	-16(%rbp), %rax
+	movb	%dl, (%rax)
+	addq	$1, -16(%rbp)
+	leaq	1(%rcx), %rax
+	movq	%rax, __progname(%rip)
+.L7:
+	movq	__progname(%rip), %rax
+	movzbl	(%rax), %eax
+	testb	%al, %al
+	je	.L9
+	movl	$__progname_storage+255, %eax
+	cmpq	%rax, -16(%rbp)
+	jb	.L8
+.L9:
+	movq	-16(%rbp), %rax
+	movb	$0, (%rax)
+	movq	$__progname_storage, __progname(%rip)
+.L2:
+	movl	$_mcleanup, %edi
+	call	atexit
+	movl	$_etext, %eax
+	movq	%rax, %rsi
+	movl	$_eprol, %eax
+	movq	%rax, %rdi
+	call	monstartup
+	movl	$0, %eax
+	call	__init
+	movq	environ(%rip), %rdx
+	movq	-32(%rbp), %rsi
+	movl	-20(%rbp), %edi
+	movq    %rdi,operatingsystem_parameter_argc
+	movq    %rsi,operatingsystem_parameter_argv
+	movl	$0, %eax
+	call	main
+	# movl	%eax, %edi
+	# call	exit
+	jmp _haltproc
+        .p2align 2,0x90
+
+.globl _haltproc
+.type _haltproc,@function
+
+_haltproc:
+           movq $1,%rax
+           movzwq operatingsystem_result,%rbx
+           pushq   %rbx
+           call .Lactualsyscall
+           addq  $8,%rsp
+           jmp   _haltproc
+
+.Lactualsyscall:
+         int $0x80
+         jb .LErrorcode
+         xor %rbx,%rbx
+         ret
+.LErrorcode:
+         movq  %rax,%rbx
+         movq  $-1,%rax
+.LFE9:
+	.size	___start, .-___start
+	.type	_strrchr, @function
+_strrchr:
+.LFB10:
+	pushq	%rbp
+.LCFI3:
+	movq	%rsp, %rbp
+.LCFI4:
+	movq	%rdi, -24(%rbp)
+	movb	%sil, -25(%rbp)
+	movq	$0, -8(%rbp)
+.L13:
+	movq	-24(%rbp), %rdx
+	movzbl	(%rdx), %eax
+	cmpb	-25(%rbp), %al
+	jne	.L14
+	movq	-24(%rbp), %rax
+	movq	%rax, -8(%rbp)
+.L14:
+	movq	-24(%rbp), %rdx
+	movzbl	(%rdx), %eax
+	testb	%al, %al
+	jne	.L16
+	movq	-8(%rbp), %rax
+	movq	%rax, -16(%rbp)
+	jmp	.L12
+.L16:
+	addq	$1, -24(%rbp)
+	jmp	.L13
+.L12:
+	movq	-16(%rbp), %rax
+	leave
+	ret
+.LFE10:
+	.size	_strrchr, .-_strrchr
+#APP
+	  .text
+	_eprol:
+#NO_APP
+	.comm	environ,8,8
+	.comm	__progname_storage,256,32
+        .comm   operatingsystem_parameter_envp,8,8
+        .comm   operatingsystem_parameter_argc,8,8
+        .comm   operatingsystem_parameter_argv,8,8
+	.section	.eh_frame,"a",@progbits
+.Lframe1:
+	.long	.LECIE1-.LSCIE1
+.LSCIE1:
+	.long	0x0
+	.byte	0x1
+	.string	"zR"
+	.uleb128 0x1
+	.sleb128 -8
+	.byte	0x10
+	.uleb128 0x1
+	.byte	0x3
+	.byte	0xc
+	.uleb128 0x7
+	.uleb128 0x8
+	.byte	0x90
+	.uleb128 0x1
+	.align 8
+.LECIE1:
+.LSFDE1:
+	.long	.LEFDE1-.LASFDE1
+.LASFDE1:
+	.long	.LASFDE1-.Lframe1
+	.long	.LFB9
+	.long	.LFE9-.LFB9
+	.uleb128 0x0
+	.byte	0x4
+	.long	.LCFI0-.LFB9
+	.byte	0xe
+	.uleb128 0x10
+	.byte	0x86
+	.uleb128 0x2
+	.byte	0x4
+	.long	.LCFI1-.LCFI0
+	.byte	0xd
+	.uleb128 0x6
+	.align 8
+.LEFDE1:
+.LSFDE3:
+	.long	.LEFDE3-.LASFDE3
+.LASFDE3:
+	.long	.LASFDE3-.Lframe1
+	.long	.LFB10
+	.long	.LFE10-.LFB10
+	.uleb128 0x0
+	.byte	0x4
+	.long	.LCFI3-.LFB10
+	.byte	0xe
+	.uleb128 0x10
+	.byte	0x86
+	.uleb128 0x2
+	.byte	0x4
+	.long	.LCFI4-.LCFI3
+	.byte	0xd
+	.uleb128 0x6
+	.align 8
+.LEFDE3:
+	.ident	"GCC: (GNU) 4.2.1 20070719 "

+ 192 - 0
rtl/openbsd/x86_64/crt0.s

@@ -0,0 +1,192 @@
+	.file	"crt0.c"
+	.globl	__progname
+	.section	.rodata
+.LC0:
+	.string	""
+	.data
+	.align 8
+	.type	__progname, @object
+	.size	__progname, 8
+__progname:
+	.quad	.LC0
+#APP
+	 .text				;	.align	8			;	.globl	__start			;	.globl	_start			;_start:					;__start:				;	movq	%rbx,%r9		;	movq	%rcx,%r8		;	movq	%rdx,%rcx		;	movq	(%rsp),%rdi		;	leaq	16(%rsp,%rdi,8),%rdx	;	leaq	8(%rsp),%rsi		;	subq	$8,%rsp			;	andq	$~15,%rsp		;	addq	$8,%rsp			;	jmp	___start		;
+#NO_APP
+	.text
+	.globl	___start
+	.type	___start, @function
+___start:
+.LFB9:
+	pushq	%rbp
+.LCFI0:
+	movq	%rsp, %rbp
+.LCFI1:
+	subq	$64, %rsp
+.LCFI2:
+	movl	%edi, -20(%rbp)
+	movq	%rsi, -32(%rbp)
+	movq	%rdx, -40(%rbp)
+	movq	%rcx, -48(%rbp)
+	movq	%r8, -56(%rbp)
+	movq	%r9, -64(%rbp)
+	movq	-40(%rbp), %rax
+	movq	%rax, environ(%rip)
+	movq	-32(%rbp), %rax
+	movq	(%rax), %rax
+	movq	%rax, -8(%rbp)
+	cmpq	$0, -8(%rbp)
+	je	.L2
+	movq	-8(%rbp), %rdi
+	movl	$47, %esi
+	call	_strrchr
+	movq	%rax, __progname(%rip)
+	movq	__progname(%rip), %rax
+	testq	%rax, %rax
+	jne	.L4
+	movq	-8(%rbp), %rax
+	movq	%rax, __progname(%rip)
+	jmp	.L6
+.L4:
+	movq	__progname(%rip), %rax
+	addq	$1, %rax
+	movq	%rax, __progname(%rip)
+.L6:
+	movq	$__progname_storage, -16(%rbp)
+	jmp	.L7
+.L8:
+	movq	__progname(%rip), %rcx
+	movzbl	(%rcx), %edx
+	movq	-16(%rbp), %rax
+	movb	%dl, (%rax)
+	addq	$1, -16(%rbp)
+	leaq	1(%rcx), %rax
+	movq	%rax, __progname(%rip)
+.L7:
+	movq	__progname(%rip), %rax
+	movzbl	(%rax), %eax
+	testb	%al, %al
+	je	.L9
+	movl	$__progname_storage+255, %eax
+	cmpq	%rax, -16(%rbp)
+	jb	.L8
+.L9:
+	movq	-16(%rbp), %rax
+	movb	$0, (%rax)
+	movq	$__progname_storage, __progname(%rip)
+.L2:
+	movl	$_mcleanup, %edi
+	call	atexit
+	movl	$_etext, %eax
+	movq	%rax, %rsi
+	movl	$_eprol, %eax
+	movq	%rax, %rdi
+	call	monstartup
+	movl	$0, %eax
+	call	__init
+	movq	environ(%rip), %rdx
+	movq	-32(%rbp), %rsi
+	movl	-20(%rbp), %edi
+	movl	$0, %eax
+	call	main
+	movl	%eax, %edi
+	call	exit
+.LFE9:
+	.size	___start, .-___start
+	.type	_strrchr, @function
+_strrchr:
+.LFB10:
+	pushq	%rbp
+.LCFI3:
+	movq	%rsp, %rbp
+.LCFI4:
+	movq	%rdi, -24(%rbp)
+	movb	%sil, -25(%rbp)
+	movq	$0, -8(%rbp)
+.L13:
+	movq	-24(%rbp), %rdx
+	movzbl	(%rdx), %eax
+	cmpb	-25(%rbp), %al
+	jne	.L14
+	movq	-24(%rbp), %rax
+	movq	%rax, -8(%rbp)
+.L14:
+	movq	-24(%rbp), %rdx
+	movzbl	(%rdx), %eax
+	testb	%al, %al
+	jne	.L16
+	movq	-8(%rbp), %rax
+	movq	%rax, -16(%rbp)
+	jmp	.L12
+.L16:
+	addq	$1, -24(%rbp)
+	jmp	.L13
+.L12:
+	movq	-16(%rbp), %rax
+	leave
+	ret
+.LFE10:
+	.size	_strrchr, .-_strrchr
+#APP
+	  .text
+	_eprol:
+#NO_APP
+	.comm	environ,8,8
+	.comm	__progname_storage,256,32
+	.section	.eh_frame,"a",@progbits
+.Lframe1:
+	.long	.LECIE1-.LSCIE1
+.LSCIE1:
+	.long	0x0
+	.byte	0x1
+	.string	"zR"
+	.uleb128 0x1
+	.sleb128 -8
+	.byte	0x10
+	.uleb128 0x1
+	.byte	0x3
+	.byte	0xc
+	.uleb128 0x7
+	.uleb128 0x8
+	.byte	0x90
+	.uleb128 0x1
+	.align 8
+.LECIE1:
+.LSFDE1:
+	.long	.LEFDE1-.LASFDE1
+.LASFDE1:
+	.long	.LASFDE1-.Lframe1
+	.long	.LFB9
+	.long	.LFE9-.LFB9
+	.uleb128 0x0
+	.byte	0x4
+	.long	.LCFI0-.LFB9
+	.byte	0xe
+	.uleb128 0x10
+	.byte	0x86
+	.uleb128 0x2
+	.byte	0x4
+	.long	.LCFI1-.LCFI0
+	.byte	0xd
+	.uleb128 0x6
+	.align 8
+.LEFDE1:
+.LSFDE3:
+	.long	.LEFDE3-.LASFDE3
+.LASFDE3:
+	.long	.LASFDE3-.Lframe1
+	.long	.LFB10
+	.long	.LFE10-.LFB10
+	.uleb128 0x0
+	.byte	0x4
+	.long	.LCFI3-.LFB10
+	.byte	0xe
+	.uleb128 0x10
+	.byte	0x86
+	.uleb128 0x2
+	.byte	0x4
+	.long	.LCFI4-.LCFI3
+	.byte	0xd
+	.uleb128 0x6
+	.align 8
+.LEFDE3:
+	.ident	"GCC: (GNU) 4.2.1 20070719 "

+ 236 - 0
rtl/openbsd/x86_64/gprt0.as

@@ -0,0 +1,236 @@
+	.file	"crt0.c"
+	.globl	__progname
+	.section	.rodata
+.LC0:
+	.string	""
+	.data
+	.align 8
+	.type	__progname, @object
+	.size	__progname, 8
+__progname:
+	.quad	.LC0
+#APP
+	 .text				
+	.align	8			
+	.globl	__start			
+	.globl	_start			
+_start:					
+__start:				
+	movq	%rbx,%r9		
+	movq	%rcx,%r8		
+	movq	%rdx,%rcx		
+	movq	(%rsp),%rdi		
+	leaq	16(%rsp,%rdi,8),%rdx	
+	leaq	8(%rsp),%rsi		
+	subq	$8,%rsp			
+	andq	$~15,%rsp		
+	addq	$8,%rsp			
+	jmp	___start		
+
+#NO_APP
+	.text
+	.globl	___start
+	.type	___start, @function
+___start:
+.LFB9:
+	pushq	%rbp
+.LCFI0:
+	movq	%rsp, %rbp
+.LCFI1:
+	subq	$64, %rsp
+.LCFI2:
+	movl	%edi, -20(%rbp)
+	movq	%rsi, -32(%rbp)
+	movq	%rdx, -40(%rbp)
+	movq	%rcx, -48(%rbp)
+	movq	%r8, -56(%rbp)
+	movq	%r9, -64(%rbp)
+	movq	-40(%rbp), %rax
+	movq	%rax, environ(%rip)
+	movq    %rax,operatingsystem_parameter_envp
+	movq	-32(%rbp), %rax
+	movq	(%rax), %rax
+	movq	%rax, -8(%rbp)
+	cmpq	$0, -8(%rbp)
+	je	.L2
+	movq	-8(%rbp), %rdi
+	movl	$47, %esi
+	call	_strrchr
+	movq	%rax, __progname(%rip)
+	movq	__progname(%rip), %rax
+	testq	%rax, %rax
+	jne	.L4
+	movq	-8(%rbp), %rax
+	movq	%rax, __progname(%rip)
+	jmp	.L6
+.L4:
+	movq	__progname(%rip), %rax
+	addq	$1, %rax
+	movq	%rax, __progname(%rip)
+.L6:
+	movq	$__progname_storage, -16(%rbp)
+	jmp	.L7
+.L8:
+	movq	__progname(%rip), %rcx
+	movzbl	(%rcx), %edx
+	movq	-16(%rbp), %rax
+	movb	%dl, (%rax)
+	addq	$1, -16(%rbp)
+	leaq	1(%rcx), %rax
+	movq	%rax, __progname(%rip)
+.L7:
+	movq	__progname(%rip), %rax
+	movzbl	(%rax), %eax
+	testb	%al, %al
+	je	.L9
+	movl	$__progname_storage+255, %eax
+	cmpq	%rax, -16(%rbp)
+	jb	.L8
+.L9:
+	movq	-16(%rbp), %rax
+	movb	$0, (%rax)
+	movq	$__progname_storage, __progname(%rip)
+.L2:
+	movl	$_mcleanup, %edi
+	call	atexit
+	movl	$_etext, %eax
+	movq	%rax, %rsi
+	movl	$_eprol, %eax
+	movq	%rax, %rdi
+	call	monstartup
+	movl	$0, %eax
+	call	__init
+	movq	environ(%rip), %rdx
+	movq	-32(%rbp), %rsi
+	movl	-20(%rbp), %edi
+	movq    %rdi,operatingsystem_parameter_argc
+	movq    %rsi,operatingsystem_parameter_argv
+	movl	$0, %eax
+	call	main
+	# movl	%eax, %edi
+	# call	exit
+	jmp _haltproc
+        .p2align 2,0x90
+
+.globl _haltproc
+.type _haltproc,@function
+
+_haltproc:
+           movq $1,%rax
+           movzwq operatingsystem_result,%rbx
+           pushq   %rbx
+           call .Lactualsyscall
+           addq  $8,%rsp
+           jmp   _haltproc
+
+.Lactualsyscall:
+         int $0x80
+         jb .LErrorcode
+         xor %rbx,%rbx
+         ret
+.LErrorcode:
+         movq  %rax,%rbx
+         movq  $-1,%rax
+.LFE9:
+	.size	___start, .-___start
+	.type	_strrchr, @function
+_strrchr:
+.LFB10:
+	pushq	%rbp
+.LCFI3:
+	movq	%rsp, %rbp
+.LCFI4:
+	movq	%rdi, -24(%rbp)
+	movb	%sil, -25(%rbp)
+	movq	$0, -8(%rbp)
+.L13:
+	movq	-24(%rbp), %rdx
+	movzbl	(%rdx), %eax
+	cmpb	-25(%rbp), %al
+	jne	.L14
+	movq	-24(%rbp), %rax
+	movq	%rax, -8(%rbp)
+.L14:
+	movq	-24(%rbp), %rdx
+	movzbl	(%rdx), %eax
+	testb	%al, %al
+	jne	.L16
+	movq	-8(%rbp), %rax
+	movq	%rax, -16(%rbp)
+	jmp	.L12
+.L16:
+	addq	$1, -24(%rbp)
+	jmp	.L13
+.L12:
+	movq	-16(%rbp), %rax
+	leave
+	ret
+.LFE10:
+	.size	_strrchr, .-_strrchr
+#APP
+	  .text
+	_eprol:
+#NO_APP
+	.comm	environ,8,8
+	.comm	__progname_storage,256,32
+        .comm   operatingsystem_parameter_envp,8,8
+        .comm   operatingsystem_parameter_argc,8,8
+        .comm   operatingsystem_parameter_argv,8,8
+	.section	.eh_frame,"a",@progbits
+.Lframe1:
+	.long	.LECIE1-.LSCIE1
+.LSCIE1:
+	.long	0x0
+	.byte	0x1
+	.string	"zR"
+	.uleb128 0x1
+	.sleb128 -8
+	.byte	0x10
+	.uleb128 0x1
+	.byte	0x3
+	.byte	0xc
+	.uleb128 0x7
+	.uleb128 0x8
+	.byte	0x90
+	.uleb128 0x1
+	.align 8
+.LECIE1:
+.LSFDE1:
+	.long	.LEFDE1-.LASFDE1
+.LASFDE1:
+	.long	.LASFDE1-.Lframe1
+	.long	.LFB9
+	.long	.LFE9-.LFB9
+	.uleb128 0x0
+	.byte	0x4
+	.long	.LCFI0-.LFB9
+	.byte	0xe
+	.uleb128 0x10
+	.byte	0x86
+	.uleb128 0x2
+	.byte	0x4
+	.long	.LCFI1-.LCFI0
+	.byte	0xd
+	.uleb128 0x6
+	.align 8
+.LEFDE1:
+.LSFDE3:
+	.long	.LEFDE3-.LASFDE3
+.LASFDE3:
+	.long	.LASFDE3-.Lframe1
+	.long	.LFB10
+	.long	.LFE10-.LFB10
+	.uleb128 0x0
+	.byte	0x4
+	.long	.LCFI3-.LFB10
+	.byte	0xe
+	.uleb128 0x10
+	.byte	0x86
+	.uleb128 0x2
+	.byte	0x4
+	.long	.LCFI4-.LCFI3
+	.byte	0xd
+	.uleb128 0x6
+	.align 8
+.LEFDE3:
+	.ident	"GCC: (GNU) 4.2.1 20070719 "

+ 236 - 0
rtl/openbsd/x86_64/prt0.as

@@ -0,0 +1,236 @@
+	.file	"crt0.c"
+	.globl	__progname
+	.section	.rodata
+.LC0:
+	.string	""
+	.data
+	.align 8
+	.type	__progname, @object
+	.size	__progname, 8
+__progname:
+	.quad	.LC0
+#APP
+	 .text				
+	.align	8			
+	.globl	__start			
+	.globl	_start			
+_start:					
+__start:				
+	movq	%rbx,%r9		
+	movq	%rcx,%r8		
+	movq	%rdx,%rcx		
+	movq	(%rsp),%rdi		
+	leaq	16(%rsp,%rdi,8),%rdx	
+	leaq	8(%rsp),%rsi		
+	subq	$8,%rsp			
+	andq	$~15,%rsp		
+	addq	$8,%rsp			
+	jmp	___start		
+
+#NO_APP
+	.text
+	.globl	___start
+	.type	___start, @function
+___start:
+.LFB9:
+	pushq	%rbp
+.LCFI0:
+	movq	%rsp, %rbp
+.LCFI1:
+	subq	$64, %rsp
+.LCFI2:
+	movl	%edi, -20(%rbp)
+	movq	%rsi, -32(%rbp)
+	movq	%rdx, -40(%rbp)
+	movq	%rcx, -48(%rbp)
+	movq	%r8, -56(%rbp)
+	movq	%r9, -64(%rbp)
+	movq	-40(%rbp), %rax
+	movq	%rax, environ(%rip)
+	movq    %rax,operatingsystem_parameter_envp
+	movq	-32(%rbp), %rax
+	movq	(%rax), %rax
+	movq	%rax, -8(%rbp)
+	cmpq	$0, -8(%rbp)
+	je	.L2
+	movq	-8(%rbp), %rdi
+	movl	$47, %esi
+	call	_strrchr
+	movq	%rax, __progname(%rip)
+	movq	__progname(%rip), %rax
+	testq	%rax, %rax
+	jne	.L4
+	movq	-8(%rbp), %rax
+	movq	%rax, __progname(%rip)
+	jmp	.L6
+.L4:
+	movq	__progname(%rip), %rax
+	addq	$1, %rax
+	movq	%rax, __progname(%rip)
+.L6:
+	movq	$__progname_storage, -16(%rbp)
+	jmp	.L7
+.L8:
+	movq	__progname(%rip), %rcx
+	movzbl	(%rcx), %edx
+	movq	-16(%rbp), %rax
+	movb	%dl, (%rax)
+	addq	$1, -16(%rbp)
+	leaq	1(%rcx), %rax
+	movq	%rax, __progname(%rip)
+.L7:
+	movq	__progname(%rip), %rax
+	movzbl	(%rax), %eax
+	testb	%al, %al
+	je	.L9
+	movl	$__progname_storage+255, %eax
+	cmpq	%rax, -16(%rbp)
+	jb	.L8
+.L9:
+	movq	-16(%rbp), %rax
+	movb	$0, (%rax)
+	movq	$__progname_storage, __progname(%rip)
+.L2:
+	# movl	$_mcleanup, %edi
+	# call	atexit
+	# movl	$_etext, %eax
+	# movq	%rax, %rsi
+	# movl	$_eprol, %eax
+	# movq	%rax, %rdi
+	# call	monstartup
+	# movl	$0, %eax
+	# call	__init
+	movq	environ(%rip), %rdx
+	movq	-32(%rbp), %rsi
+	movl	-20(%rbp), %edi
+	movq    %rdi,operatingsystem_parameter_argc
+	movq    %rsi,operatingsystem_parameter_argv
+	movl	$0, %eax
+	call	main
+	# movl	%eax, %edi
+	# call	exit
+	jmp _haltproc
+        .p2align 2,0x90
+
+.globl _haltproc
+.type _haltproc,@function
+
+_haltproc:
+           movq $1,%rax
+           movzwq operatingsystem_result,%rbx
+           pushq   %rbx
+           call .Lactualsyscall
+           addq  $8,%rsp
+           jmp   _haltproc
+
+.Lactualsyscall:
+         int $0x80
+         jb .LErrorcode
+         xor %rbx,%rbx
+         ret
+.LErrorcode:
+         movq  %rax,%rbx
+         movq  $-1,%rax
+.LFE9:
+	.size	___start, .-___start
+	.type	_strrchr, @function
+_strrchr:
+.LFB10:
+	pushq	%rbp
+.LCFI3:
+	movq	%rsp, %rbp
+.LCFI4:
+	movq	%rdi, -24(%rbp)
+	movb	%sil, -25(%rbp)
+	movq	$0, -8(%rbp)
+.L13:
+	movq	-24(%rbp), %rdx
+	movzbl	(%rdx), %eax
+	cmpb	-25(%rbp), %al
+	jne	.L14
+	movq	-24(%rbp), %rax
+	movq	%rax, -8(%rbp)
+.L14:
+	movq	-24(%rbp), %rdx
+	movzbl	(%rdx), %eax
+	testb	%al, %al
+	jne	.L16
+	movq	-8(%rbp), %rax
+	movq	%rax, -16(%rbp)
+	jmp	.L12
+.L16:
+	addq	$1, -24(%rbp)
+	jmp	.L13
+.L12:
+	movq	-16(%rbp), %rax
+	leave
+	ret
+.LFE10:
+	.size	_strrchr, .-_strrchr
+#APP
+	  .text
+	_eprol:
+#NO_APP
+	.comm	environ,8,8
+	.comm	__progname_storage,256,32
+        .comm   operatingsystem_parameter_envp,8,8
+        .comm   operatingsystem_parameter_argc,8,8
+        .comm   operatingsystem_parameter_argv,8,8
+	.section	.eh_frame,"a",@progbits
+.Lframe1:
+	.long	.LECIE1-.LSCIE1
+.LSCIE1:
+	.long	0x0
+	.byte	0x1
+	.string	"zR"
+	.uleb128 0x1
+	.sleb128 -8
+	.byte	0x10
+	.uleb128 0x1
+	.byte	0x3
+	.byte	0xc
+	.uleb128 0x7
+	.uleb128 0x8
+	.byte	0x90
+	.uleb128 0x1
+	.align 8
+.LECIE1:
+.LSFDE1:
+	.long	.LEFDE1-.LASFDE1
+.LASFDE1:
+	.long	.LASFDE1-.Lframe1
+	.long	.LFB9
+	.long	.LFE9-.LFB9
+	.uleb128 0x0
+	.byte	0x4
+	.long	.LCFI0-.LFB9
+	.byte	0xe
+	.uleb128 0x10
+	.byte	0x86
+	.uleb128 0x2
+	.byte	0x4
+	.long	.LCFI1-.LCFI0
+	.byte	0xd
+	.uleb128 0x6
+	.align 8
+.LEFDE1:
+.LSFDE3:
+	.long	.LEFDE3-.LASFDE3
+.LASFDE3:
+	.long	.LASFDE3-.Lframe1
+	.long	.LFB10
+	.long	.LFE10-.LFB10
+	.uleb128 0x0
+	.byte	0x4
+	.long	.LCFI3-.LFB10
+	.byte	0xe
+	.uleb128 0x10
+	.byte	0x86
+	.uleb128 0x2
+	.byte	0x4
+	.long	.LCFI4-.LCFI3
+	.byte	0xd
+	.uleb128 0x6
+	.align 8
+.LEFDE3:
+	.ident	"GCC: (GNU) 4.2.1 20070719 "

+ 100 - 0
rtl/openbsd/x86_64/sighnd.inc

@@ -0,0 +1,100 @@
+{
+   This file is part of the Free Pascal run time library.
+   (c) 2000-2003 by Marco van de Voort
+   member of the Free Pascal development team.
+
+   See the file COPYING.FPC, included in this distribution,
+   for details about the copyright.
+
+   Signalhandler for FreeBSD/i386
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY;without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+}
+
+CONST FPU_ALL=$7F;
+
+{$ifdef cpui386}
+function getfpustate(sininfo:psiginfo):longint; {inline;}
+begin
+  if ptruint(sininfo)> high(word) then
+    getfpustate:=sininfo^.si_code
+  else
+    getfpustate:=word(ptruint(sininfo));
+end;
+
+function getaltfpustate(sigcontext:psigcontextrec):longint; {inline;}
+begin
+  if assigned(sigcontext) then
+    getaltfpustate:=sigcontext^.sc_fpustate^.en_sw 
+  else
+    getaltfpustate:=0;
+end;
+{$endif}
+
+procedure SignalToRunerror(Sig: longint;sininfo:psiginfo; SigContext: PSigContextRec); public name '_FPC_DEFAULTSIGHANDLER'; cdecl;
+
+var
+  res,fpustate : word;
+begin
+  res:=0;
+{$ifdef BSD}
+{$ifdef cpui386}
+  fpustate:=0;
+  asm
+    fnstsw fpustate
+  end;
+{$endif cpui386}
+{$endif BSD}
+  case sig of
+    SIGFPE :
+          begin
+    { this is not allways necessary but I don't know yet
+      how to tell if it is or not PM }
+          res:=200;
+{$ifdef cpui386}
+          fpustate:=GetaltFPUState(sigcontext);
+{$else}
+          fpustate:=0;
+{$endif}
+          if (FpuState and FPU_All) <> 0 then
+            begin
+              { first check the more precise options }
+              if (FpuState and FPU_DivisionByZero)<>0 then
+                res:=200
+              else if (FpuState and FPU_Overflow)<>0 then
+                res:=205
+              else if (FpuState and FPU_Underflow)<>0 then
+                res:=206
+              else if (FpuState and FPU_Denormal)<>0 then
+                res:=216
+              else if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow))<>0 then
+                res:=207
+              else if (FpuState and FPU_Invalid)<>0 then
+                res:=216
+              else
+                res:=207;  {'Coprocessor Error'}
+            end;
+          SysResetFPU;
+        end;
+    SIGILL,
+    SIGBUS,
+    SIGSEGV :
+        res:=216;
+    SIGINT:
+        res:=217;
+    SIGQUIT:
+        res:=233;
+  end;
+  reenable_signal(sig);
+{ give runtime error at the position where the signal was raised }
+  if res<>0 then
+   begin
+{$ifdef cpux86_64}
+      HandleErrorAddrFrame(res,pointer(SigContext^.sc_rip),pointer(SigContext^.sc_rbp));
+{$endif}
+   end;
+end;
+
+

+ 1 - 1
utils/fpcm/fpcmmain.pp

@@ -121,7 +121,7 @@ interface
         { solaris } ( true,  false, false, true,  true,  false, false, false, false, false, false, false, false, false),
         { qnx }     ( true,  false, false, false, false, false, false, false, false, false, false, false, false, false),
         { netware } ( true,  false, false, false, false, false, false, false, false, false, false, false, false, false),
-        { openbsd } ( true,  true,  false, false, false, false, false, false, false, false, false, false, false, false),
+        { openbsd } ( true,  true,  false, false, true,  false, false, false, false, false, false, false, false, false),
         { wdosx }   ( true,  false, false, false, false, false, false, false, false, false, false, false, false, false),
         { palmos }  ( false, true,  false, false, false, true,  false, false, false, false, false, false, false, false),
         { macos }   ( false, false, true,  false, false, false, false, false, false, false, false, false, false, false),