Browse Source

--- Merging r20287 into '.':
U rtl/netbsd/i386/prt0.as
--- Merging r20297 into '.':
A rtl/netbsd/pthread.inc
--- Merging r20329 into '.':
U rtl/netbsd/signal.inc
--- Merging r20330 into '.':
G rtl/netbsd/signal.inc
--- Merging r20332 into '.':
U rtl/netbsd/i386/sighnd.inc

# revisions: 20287,20297,20329,20330,20332
------------------------------------------------------------------------
r20287 | pierre | 2012-02-09 18:31:43 +0100 (Thu, 09 Feb 2012) | 1 line
Changed paths:
M /trunk/rtl/netbsd/i386/prt0.as

+ Add CPREFIX macro to allow transition from '_' prefix to ''
------------------------------------------------------------------------
------------------------------------------------------------------------
r20297 | pierre | 2012-02-10 01:23:50 +0100 (Fri, 10 Feb 2012) | 1 line
Changed paths:
A /trunk/rtl/netbsd/pthread.inc

New file adapted from Darwin
------------------------------------------------------------------------
------------------------------------------------------------------------
r20329 | pierre | 2012-02-12 20:21:00 +0100 (Sun, 12 Feb 2012) | 1 line
Changed paths:
M /trunk/rtl/netbsd/signal.inc

+ Add missing PSigContext type
------------------------------------------------------------------------
------------------------------------------------------------------------
r20330 | pierre | 2012-02-12 20:53:27 +0100 (Sun, 12 Feb 2012) | 1 line
Changed paths:
M /trunk/rtl/netbsd/signal.inc

* Fix SigActionHandler for fcl-extra
------------------------------------------------------------------------
------------------------------------------------------------------------
r20332 | pierre | 2012-02-12 23:55:23 +0100 (Sun, 12 Feb 2012) | 1 line
Changed paths:
M /trunk/rtl/netbsd/i386/sighnd.inc

* Fix code for SIGFPE and adapt to SignalHandler procedure type change
------------------------------------------------------------------------

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

marco 13 years ago
parent
commit
cf93a6f223
5 changed files with 178 additions and 42 deletions
  1. 1 0
      .gitattributes
  2. 17 6
      rtl/netbsd/i386/prt0.as
  3. 33 17
      rtl/netbsd/i386/sighnd.inc
  4. 86 0
      rtl/netbsd/pthread.inc
  5. 41 19
      rtl/netbsd/signal.inc

+ 1 - 0
.gitattributes

@@ -7647,6 +7647,7 @@ rtl/netbsd/powerpc/bsyscall.inc svneol=native#text/plain
 rtl/netbsd/powerpc/cprt0.as svneol=native#text/plain
 rtl/netbsd/powerpc/cprt0.as svneol=native#text/plain
 rtl/netbsd/powerpc/prt0.as svneol=native#text/plain
 rtl/netbsd/powerpc/prt0.as svneol=native#text/plain
 rtl/netbsd/powerpc/sighnd.inc svneol=native#text/plain
 rtl/netbsd/powerpc/sighnd.inc svneol=native#text/plain
+rtl/netbsd/pthread.inc svneol=native#text/plain
 rtl/netbsd/ptypes.inc svneol=native#text/plain
 rtl/netbsd/ptypes.inc svneol=native#text/plain
 rtl/netbsd/signal.inc svneol=native#text/plain
 rtl/netbsd/signal.inc svneol=native#text/plain
 rtl/netbsd/syscalls.inc svneol=native#text/plain
 rtl/netbsd/syscalls.inc svneol=native#text/plain

+ 17 - 6
rtl/netbsd/i386/prt0.as

@@ -40,7 +40,11 @@ __progname:
 __ps_strings:
 __ps_strings:
 	.long 0
 	.long 0
 	.align 4
 	.align 4
+.ifdef CPREFIX
 ___fpucw:
 ___fpucw:
+.else
+__fpucw:
+.endif
         .long   0x1332
         .long   0x1332
 
 
         .globl  ___fpc_brk_addr         /* heap management */
         .globl  ___fpc_brk_addr         /* heap management */
@@ -131,12 +135,19 @@ ___start:
 
 
         finit                           /* initialize fpu */
         finit                           /* initialize fpu */
         fwait
         fwait
+ .ifdef CPREFIX
         fldcw   ___fpucw
         fldcw   ___fpucw
-
+ .else
+        fldcw   __fpucw
+ .endif
         xorl    %ebp,%ebp
         xorl    %ebp,%ebp
 
 
+.ifdef CPREFIX
 	call _main
 	call _main
-	pushl %eax
+.else
+	call main
+.endif
+pushl %eax
 	jmp  _haltproc
 	jmp  _haltproc
 
 
 .p2align 2,0x90
 .p2align 2,0x90
@@ -175,8 +186,8 @@ _actualsyscall:
 .ascii "NetBSD\0\0"
 .ascii "NetBSD\0\0"
 .long 199905
 .long 199905
 
 
-        .comm environ,4
-        .comm operatingsystem_parameter_envp,4
-        .comm operatingsystem_parameter_argc,4
-        .comm operatingsystem_parameter_argv,4
+        .comm environ,4,4
+        .comm operatingsystem_parameter_envp,4,4
+        .comm operatingsystem_parameter_argc,4,4
+        .comm operatingsystem_parameter_argv,4,4
 
 

+ 33 - 17
rtl/netbsd/i386/sighnd.inc

@@ -13,13 +13,29 @@
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 }
 }
 
 
-CONST FPU_ALL=$7F;
+{
+/* SIGFPE */
+#define	FPE_INTDIV	1	/* Integer divide by zero		*/
+#define	FPE_INTOVF	2	/* Integer overflow			*/
+#define	FPE_FLTDIV	3	/* Floating point divide by zero	*/
+#define	FPE_FLTOVF	4	/* Floating point overflow		*/
+#define	FPE_FLTUND	5	/* Floating point underflow		*/
+#define	FPE_FLTRES	6	/* Floating point inexact result	*/
+#define	FPE_FLTINV	7	/* Invalid Floating point operation	*/
+#define	FPE_FLTSUB	8	/* Subscript out of range		*/
+}
 
 
-function getfpustate(const Sigcontext:sigcontextRec):longint; {inline;}
-begin
-  getfpustate:=0;
-end;
-procedure SignalToRunerror(Sig: longint;code:longint; var SigContext: SigContextRec); public name '_FPC_DEFAULTSIGHANDLER'; cdecl;
+const
+  FPE_IntDiv = 1;
+  FPE_IntOvf = 2;
+  FPE_FltDiv = 3;
+  FPE_FltOvf = 4;
+  FPE_FltUnd = 5;
+  FPE_FltRes = 6;
+  FPE_FltInv = 7;
+  FPE_FltSub = 8;
+
+procedure SignalToRunerror(Sig: longint;info : PSigInfo;SigContext: PSigContextRec); public name '_FPC_DEFAULTSIGHANDLER'; cdecl;
 
 
 var
 var
   res,fpustate : word;
   res,fpustate : word;
@@ -39,22 +55,22 @@ begin
     { this is not allways necessary but I don't know yet
     { this is not allways necessary but I don't know yet
       how to tell if it is or not PM }
       how to tell if it is or not PM }
           res:=200;
           res:=200;
-          fpustate:=GetFPUState(SigContext);
+          fpustate:=info^._info.si_code;
 
 
-          if (FpuState and FPU_All) <> 0 then
-            begin
+          { if (FpuState and FPU_All) <> 0 then }
+           begin
               { first check the more precise options }
               { first check the more precise options }
-              if (FpuState and FPU_DivisionByZero)<>0 then
+              if FpuState = FPE_IntDiv then
                 res:=200
                 res:=200
-              else if (FpuState and FPU_Overflow)<>0 then
+              else if (FpuState = FPE_IntOvf) or (FpuState = FPE_FltOvf) then
                 res:=205
                 res:=205
-              else if (FpuState and FPU_Underflow)<>0 then
+              else if FpuState = FPE_FltUnd then
                 res:=206
                 res:=206
-              else if (FpuState and FPU_Denormal)<>0 then
-                res:=216
-              else if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow))<>0 then
+              { else if FpuState and FPU_Denormal)<>0 then
+                res:=216 }
+              else if FpuState = FPE_FltSub then
                 res:=207
                 res:=207
-              else if (FpuState and FPU_Invalid)<>0 then
+             else if FpuState = FPE_FltInv then
                 res:=216
                 res:=216
               else
               else
                 res:=207;  {'Coprocessor Error'}
                 res:=207;  {'Coprocessor Error'}
@@ -75,7 +91,7 @@ begin
   if res<>0 then
   if res<>0 then
    begin
    begin
 {$ifdef cpui386}
 {$ifdef cpui386}
-      HandleErrorAddrFrame(res,pointer(SigContext.sc_eip),pointer(SigContext.sc_ebp));
+      HandleErrorAddrFrame(res,pointer(SigContext^.sc_eip),pointer(SigContext^.sc_ebp));
 {$endif}
 {$endif}
    end;
    end;
 end;
 end;

+ 86 - 0
rtl/netbsd/pthread.inc

@@ -0,0 +1,86 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1999-2000 by Peter Vreman
+    member of the Free Pascal development team.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This file contains a pthread.h headerconversion,
+    and should contain an interface to the threading library to be
+    used by systhrd, preferably in a somewhat compatible notation
+    (compared to the other OSes).
+
+    As a start, I simply used libc_r
+
+    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 PTHREAD_EXPLICIT_SCHED       = 0;
+      PTHREAD_CREATE_DETACHED      = 1;
+      PTHREAD_SCOPE_PROCESS        = 0;
+      SEM_FAILED                   = -1;
+
+ TYPE
+    ppthread_t           = ^pthread_t;
+    ppthread_key_t       = ^pthread_key_t;
+    ppthread_mutex_t     = ^pthread_mutex_t;
+    ppthread_attr_t      = ^pthread_attr_t;
+    __destr_func_t       = procedure (p :pointer);cdecl;
+    __startroutine_t     = function (p :pointer):pointer;cdecl;
+    ppthread_mutexattr_t = ^pthread_mutexattr_t;
+    ppthread_cond_t      = ^pthread_cond_t;
+    ppthread_condattr_t  = ^pthread_condattr_t;
+
+    sem_t       = cint;
+    psem_t          = ^sem_t;
+    TSemaphore  = sem_t;
+    PSemaphore  = ^TSemaphore;
+
+function  pthread_getspecific      (t : pthread_key_t):pointer; cdecl; external 'c';
+function  pthread_setspecific      (t : pthread_key_t;p:pointer):cint; cdecl; external 'c';
+function  pthread_key_create       (p : ppthread_key_t;f: __destr_func_t):cint; cdecl;external 'c';
+function  pthread_attr_init           (p : ppthread_attr_t):cint; cdecl; external 'c';
+function  pthread_attr_setinheritsched(p : ppthread_attr_t;i:cint):cint; cdecl; external 'c';
+function  pthread_attr_setscope      (p : ppthread_attr_t;i:cint):cint;cdecl;external 'c';
+function  pthread_attr_setdetachstate (p : ppthread_attr_t;i:cint):cint;cdecl;external 'c';
+function  pthread_attr_setstacksize(p: ppthread_attr_t; stacksize: size_t):cint;cdecl;external 'c';
+
+function  pthread_create ( p: ppthread_t;attr : ppthread_attr_t;f:__startroutine_t;arg:pointer):cint;cdecl;external 'c';
+procedure pthread_exit  ( p: pointer); cdecl;external 'c';
+function  pthread_self:pthread_t; cdecl;external 'c';
+function  pthread_mutex_init (p:ppthread_mutex_t;o:ppthread_mutexattr_t):cint; cdecl;external 'c';
+function  pthread_mutex_destroy (p:ppthread_mutex_t):cint; cdecl;external 'c';
+function  pthread_mutex_lock    (p:ppthread_mutex_t):cint; cdecl;external 'c';
+function  pthread_mutex_trylock (p:ppthread_mutex_t):cint; cdecl;external 'c';
+function  pthread_mutex_unlock  (p:ppthread_mutex_t):cint; cdecl;external 'c';
+function  pthread_cancel(_para1:pthread_t):cint;cdecl;external 'c';
+function  pthread_detach(_para1:pthread_t):cint;cdecl;external 'c';
+function  pthread_join(_para1:pthread_t; _para2:Ppointer):cint;cdecl;external 'c';
+function  pthread_cond_destroy(_para1:Ppthread_cond_t):cint;cdecl;external 'c' name 'pthread_cond_destroy';
+function  pthread_cond_init(_para1:Ppthread_cond_t;_para2:Ppthread_condattr_t):cint;cdecl;external  'c' name 'pthread_cond_init';
+function  pthread_cond_signal(_para1:Ppthread_cond_t):cint;cdecl;external 'c' name 'pthread_cond_signal';
+function  pthread_cond_broadcast(_para1:Ppthread_cond_t):cint;cdecl;external 'c' name 'pthread_cond_broadcast';
+function  pthread_cond_wait(_para1:Ppthread_cond_t;_para2:Ppthread_mutex_t):cint;cdecl;external 'c' name 'pthread_cond_wait';
+function pthread_kill(__thread:pthread_t; __signo:cint):cint;cdecl;external 'c';
+function pthread_sigmask(how: cint; nset: psigset; oset: psigset): cint; cdecl; external 'c';
+
+// not yet implemented in Mac OS X 10.4.8!
+function sem_init(__sem:Psem_t; __pshared:cint;__value:cuint):cint;cdecl; external 'c' name 'sem_init';
+function sem_open(name: pchar; oflag: cint): Psem_t; cdecl; varargs; external 'c' name 'sem_open';
+function sem_destroy(__sem:Psem_t):cint;cdecl;external 'c' name 'sem_destroy';
+function sem_close(__sem:Psem_t):cint;cdecl;external 'c'  name 'sem_close';
+function sem_unlink(__name:Pchar):cint;cdecl;external 'c' name 'sem_unlink';
+function sem_wait(__sem:Psem_t):cint;cdecl;external 'c'  name 'sem_wait';
+function sem_trywait(__sem:Psem_t):cint;cdecl;external 'c'  name 'sem_trywait';
+function sem_post(__sem:Psem_t):cint;cdecl;external 'c'  name 'sem_post';
+function sem_getvalue(__sem:Psem_t; __sval:Pcint):cint;cdecl;external 'c'  name 'sem_getvalue';
+
+function pthread_mutexattr_init(_para1:Ppthread_mutexattr_t):cint;cdecl;external 'c' name 'pthread_mutexattr_init';
+function pthread_mutexattr_destroy(_para1:Ppthread_mutexattr_t):cint;cdecl;external 'c' name 'pthread_mutexattr_destroy';
+function pthread_mutexattr_gettype(_para1:Ppthread_mutexattr_t; _para2:Pcint):cint;cdecl;external 'c' name 'pthread_mutexattr_gettype';
+function pthread_mutexattr_settype(_para1:Ppthread_mutexattr_t; _para2:cint):cint;cdecl;external 'c' name 'pthread_mutexattr_settype';
+function pthread_cond_timedwait(__cond:ppthread_cond_t; __mutex:ppthread_mutex_t; __abstime:ptimespec):cint; cdecl;external 'c' name 'pthread_cond_timedwait';

+ 41 - 19
rtl/netbsd/signal.inc

@@ -135,30 +135,60 @@ type
 type sigset_t = array[0..3] of cardinal;
 type sigset_t = array[0..3] of cardinal;
 
 
     PSigContextRec = ^SigContextRec;
     PSigContextRec = ^SigContextRec;
+    PSigContext = ^SigContextRec;
+{
+struct sigcontext {
+	int	sc_gs;
+	int	sc_fs;
+	int	sc_es;
+	int	sc_ds;
+	int	sc_edi;
+	int	sc_esi;
+	int	sc_ebp;
+	int	sc_ebx;
+	int	sc_edx;
+	int	sc_ecx;
+	int	sc_eax;
+	/* XXX */
+	int	sc_eip;
+	int	sc_cs;
+	int	sc_eflags;
+	int	sc_esp;
+	int	sc_ss;
+
+	int	sc_onstack;		/* sigstack state to restore */
+	int	__sc_mask13;		/* signal mask to restore (old style) */
+
+	int	sc_trapno;		/* XXX should be above */
+	int	sc_err;
+
+	sigset_t sc_mask;		/* signal mask to restore (new style) */
+};
+}
     SigContextRec = record
     SigContextRec = record
-       sc_mask      : sigset_t;          { signal mask to restore }
-       sc_onstack   : longint;              { sigstack state to restore }
-
-       sc_gs        : longint;              { machine state (struct trapframe): }
+       sc_gs        : longint;   { machine state (struct trapframe): }
        sc_fs        : longint;
        sc_fs        : longint;
        sc_es        : longint;
        sc_es        : longint;
        sc_ds        : longint;
        sc_ds        : longint;
        sc_edi       : longint;
        sc_edi       : longint;
        sc_esi       : longint;
        sc_esi       : longint;
        sc_ebp       : longint;
        sc_ebp       : longint;
-       sc_isp       : longint;
        sc_ebx       : longint;
        sc_ebx       : longint;
        sc_edx       : longint;
        sc_edx       : longint;
        sc_ecx       : longint;
        sc_ecx       : longint;
        sc_eax       : longint;
        sc_eax       : longint;
-       sc_trapno    : longint;
-       sc_err       : longint;
        sc_eip       : longint;
        sc_eip       : longint;
        sc_cs        : longint;
        sc_cs        : longint;
        sc_efl       : longint;
        sc_efl       : longint;
        sc_esp       : longint;
        sc_esp       : longint;
        sc_ss        : longint;
        sc_ss        : longint;
-        {
+       sc_onstack   : longint;
+       __sc_mask13  : longint;
+       sc_trapno    : longint;
+       sc_err       : longint;
+       sc_mask      : sigset_t;
+ 
+(*           {
          * XXX FPU state is 27 * 4 bytes h/w, 1 * 4 bytes s/w (probably not
          * 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
          * needed here), or that + 16 * 4 bytes for emulators (probably all
          * needed here).  The "spare" bytes are mostly not spare.
          * needed here).  The "spare" bytes are mostly not spare.
@@ -173,7 +203,7 @@ type sigset_t = array[0..3] of cardinal;
        en_fos       : cardinal;     { floating operand segment selector }
        en_fos       : cardinal;     { floating operand segment selector }
        fpr_acc      : array[0..79] of char;
        fpr_acc      : array[0..79] of char;
        fpr_ex_sw    : cardinal;
        fpr_ex_sw    : cardinal;
-       fpr_pad      : array[0..63] of char;
+       fpr_pad      : array[0..63] of char; *)
        end;
        end;
 
 
   SignalHandler   = Procedure(Sig : Longint);cdecl;
   SignalHandler   = Procedure(Sig : Longint);cdecl;
@@ -181,16 +211,8 @@ type sigset_t = array[0..3] of cardinal;
   SignalRestorer  = Procedure;cdecl;
   SignalRestorer  = Procedure;cdecl;
   PSignalRestorer = ^SignalRestorer;
   PSignalRestorer = ^SignalRestorer;
 
 
-{$ifdef powerpc}
-  SigactionHandler =  procedure(Sig: Longint); cdecl;
-{$else}
-{$define BSDHandler}
-{$ifdef BSDHandler}
-  SigActionHandler  = procedure(Sig: Longint; code:longint;var SigContext: SigContextRec);cdecl;
-{$else}
-  SigActionHandler  = procedure(Sig: Longint; var sininfo:tsiginfo_t;var SigContext: SigContextRec);cdecl;
-{$endif}
-{$endif}
+  sigActionHandler = procedure(Sig: Longint; sininfo:psiginfo; SigContext: PSigContext);cdecl;
+
 
 
   Sigset=sigset_t;
   Sigset=sigset_t;
   TSigset=sigset_t;
   TSigset=sigset_t;