Procházet zdrojové kódy

Merged revisions 5558,5671,5694 via svnmerge from
http://svn.freepascal.org/svn/fpc/trunk

........
r5558 | pierre | 2006-12-08 14:22:40 +0100 (Fri, 08 Dec 2006) | 5 lines

* fix compilation failure in 2.1 branch
reason is that cvar was .comm before and
is now .bss, you need to explicitly add public
to added the .globl that makes the assembler symbol
accessible in other objects.
........
r5671 | pierre | 2006-12-22 00:54:38 +0100 (Fri, 22 Dec 2006) | 4 lines

* in dpmi_longjmp, fix wrong parameter retrieving,
old code was based on assumption that parameters
are on stack. New code works in both cases.

........
r5694 | pierre | 2006-12-24 02:26:47 +0100 (Sun, 24 Dec 2006) | 3 lines

* try to correct the code for regcall convention.
* signal handlers need to have cdecl modifier to
be compatible with djgpp C code.
........

git-svn-id: branches/fixes_2_0@5859 -

pierre před 19 roky
rodič
revize
475a293588
5 změnil soubory, kde provedl 88 přidání a 41 odebrání
  1. 8 2
      ide/Makefile
  2. 6 0
      ide/compiler/Makefile
  3. 71 36
      rtl/go32v2/dpmiexcp.pp
  4. 1 1
      rtl/go32v2/emu387.pp
  5. 2 2
      rtl/go32v2/profile.pp

+ 8 - 2
ide/Makefile

@@ -2,7 +2,7 @@
 # Don't edit, this file is generated by FPCMake Version 2.0.0 [2005/12/07]
 #
 default: all
-MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-emx i386-watcom i386-netwlibc i386-wince m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos powerpc-linux powerpc-netbsd powerpc-macos powerpc-darwin powerpc-morphos sparc-linux sparc-netbsd sparc-solaris x86_64-linux x86_64-freebsd x86_64-win64 arm-linux arm-wince powerpc64-linux
+MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-emx i386-watcom i386-netwlibc i386-wince m68k-linux m68k-freebsd m68k-netbsd m68k-amiga
 BSDs = freebsd netbsd openbsd darwin
 UNIXs = linux $(BSDs) solaris qnx
 LIMIT83fs = go32v2 os2 emx watcom
@@ -1798,6 +1798,7 @@ override FPCOPT:=!FPCEXTCMD
 export FPCEXTCMD
 endif
 override COMPILER:=$(FPC) $(FPCOPT)
+PREEXECPPAS=echo Calling FPC with FPCOPT  "$(FPCOPT)"
 ifeq (,$(findstring -s ,$(COMPILER)))
 EXECPPAS=
 else
@@ -1842,15 +1843,19 @@ $(COMPILER_UNITTARGETDIR):
 $(COMPILER_TARGETDIR):
 	$(MKDIRTREE) $(COMPILER_TARGETDIR)
 %$(PPUEXT): %.pp
+	$(PREEXECPPAS)
 	$(COMPILER) $<
 	$(EXECPPAS)
 %$(PPUEXT): %.pas
+	$(PREEXECPPAS)
 	$(COMPILER) $<
 	$(EXECPPAS)
 %$(EXEEXT): %.pp
+	$(PREEXECPPAS)
 	$(COMPILER) $<
 	$(EXECPPAS)
 %$(EXEEXT): %.pas
+	$(PREEXECPPAS)
 	$(COMPILER) $<
 	$(EXECPPAS)
 %$(EXEEXT): %.lpr
@@ -2346,7 +2351,8 @@ compiler_makefiles:
 	$(MAKE) -C compiler makefiles
 compiler:
 	$(MAKE) -C compiler all
-.PHONY: compiler_all compiler_debug compiler_smart compiler_release compiler_units compiler_examples compiler_shared compiler_install compiler_sourceinstall compiler_exampleinstall compiler_distinstall compiler_zipinstall compiler_zipsourceinstall compiler_zipexampleinstall compiler_zipdistinstall compiler_clean compiler_distclean compiler_cleanall compiler_info compiler_makefiles compiler
+.PHONY: compiler_all compiler_debug compiler_smart compiler_release compiler_units compiler_examples compiler_shared compiler_install compiler_sourceinstall compiler_exampleinstall compiler_distinstall compiler_zipinstall compiler_zipsourceinstall
+.PHONY: compiler_zipexampleinstall compiler_zipdistinstall compiler_clean compiler_distclean compiler_cleanall compiler_info compiler_makefiles compiler
 endif
 debug: fpc_debug
 smart: fpc_smart

+ 6 - 0
ide/compiler/Makefile

@@ -1714,6 +1714,8 @@ ifdef ACROSSCOMPILE
 override FPCOPT+=$(CROSSOPT)
 endif
 override COMPILER:=$(FPC) $(FPCOPT)
+PREEXECPPAS=echo FPCOPT is "$FPCOPT"
+
 ifeq (,$(findstring -s ,$(COMPILER)))
 EXECPPAS=
 else
@@ -1750,15 +1752,19 @@ $(COMPILER_UNITTARGETDIR):
 $(COMPILER_TARGETDIR):
 	$(MKDIRTREE) $(COMPILER_TARGETDIR)
 %$(PPUEXT): %.pp
+        $(PREEXECPPAS)
 	$(COMPILER) $<
 	$(EXECPPAS)
 %$(PPUEXT): %.pas
+        $(PREEXECPPAS)
 	$(COMPILER) $<
 	$(EXECPPAS)
 %$(EXEEXT): %.pp
+        $(PREEXECPPAS)
 	$(COMPILER) $<
 	$(EXECPPAS)
 %$(EXEEXT): %.pas
+        $(PREEXECPPAS)
 	$(COMPILER) $<
 	$(EXECPPAS)
 %$(EXEEXT): %.lpr

+ 71 - 36
rtl/go32v2/dpmiexcp.pp

@@ -109,31 +109,31 @@ const
   SIG_SETMASK = 2;
   SIG_UNBLOCK = 3;
 
-function SIG_DFL( x: longint) : longint;
+function SIG_DFL( x: longint) : longint;cdecl;
 {$ifdef IN_SYSTEM}forward;{$endif IN_SYSTEM}
 {$ifndef CREATE_C_FUNCTIONS}
-external name '___djgpp_SIG_DFL';
+external name '__djgpp_SIG_DFL';
 {$endif CREATE_C_FUNCTIONS}
 
-function SIG_ERR( x: longint) : longint;
+function SIG_ERR( x: longint) : longint;cdecl;
 {$ifdef IN_SYSTEM}forward;{$endif IN_SYSTEM}
 {$ifndef CREATE_C_FUNCTIONS}
-external name '___djgpp_SIG_ERR';
+external name '__djgpp_SIG_ERR';
 {$endif CREATE_C_FUNCTIONS}
 
-function SIG_IGN( x: longint) : longint;
+function SIG_IGN( x: longint) : longint;cdecl;
 {$ifdef IN_SYSTEM}forward;{$endif IN_SYSTEM}
 {$ifndef CREATE_C_FUNCTIONS}
-external name '___djgpp_SIG_IGN';
+external name '__djgpp_SIG_IGN';
 {$endif CREATE_C_FUNCTIONS}
 
 type
-  SignalHandler  = function (v : longint) : longint;
+  SignalHandler  = function (v : longint) : longint;cdecl;
   PSignalHandler = ^SignalHandler; { to be compatible with linux.pp }
 
-function signal(sig : longint;func : SignalHandler) : SignalHandler;
+function signal(sig : longint;func : SignalHandler) : SignalHandler;cdecl;
 {$ifdef IN_SYSTEM}forward;{$endif IN_SYSTEM}
-function _raise(sig : longint) : longint;
+function _raise(sig : longint) : longint;cdecl;
 {$ifdef IN_SYSTEM}forward;{$endif IN_SYSTEM}
 
 { Exceptions }
@@ -149,13 +149,13 @@ type
     __fpu_state : array [0..108-1] of byte; {  for future use  }
   end;
 
-procedure djgpp_exception_toggle;
+procedure djgpp_exception_toggle;cdecl;
 {$ifdef IN_SYSTEM}forward;{$endif IN_SYSTEM}
 {$ifndef CREATE_C_FUNCTIONS}
 external name '___djgpp_exception_toggle';
 {$endif CREATE_C_FUNCTIONS}
 
-procedure djgpp_exception_setup;
+procedure djgpp_exception_setup;cdecl;
 {$ifdef IN_SYSTEM}forward;{$endif IN_SYSTEM}
 {$ifndef CREATE_C_FUNCTIONS}
 external name '___djgpp_exception_setup';
@@ -164,11 +164,11 @@ external name '___djgpp_exception_setup';
 function  djgpp_exception_state : pexception_state;
 {$ifdef IN_SYSTEM}forward;{$endif IN_SYSTEM}
 
-function  djgpp_set_ctrl_c(enable : boolean) : boolean;
+function  djgpp_set_ctrl_c(enable : boolean) : boolean;cdecl;
 {$ifdef IN_SYSTEM}forward;{$endif IN_SYSTEM}
 
 { Other }
-function dpmi_set_coprocessor_emulation(flag : longint) : longint;
+function dpmi_set_coprocessor_emulation(flag : longint) : longint;cdecl;
 {$ifdef IN_SYSTEM}forward;{$endif IN_SYSTEM}
 
 function __djgpp_set_sigint_key(new_key : longint) : longint;cdecl;
@@ -499,8 +499,9 @@ end;
 ****************************************************************************}
 
 {$ifdef CREATE_C_FUNCTIONS}
-function c_setjmp(var rec : dpmi_jmp_buf) : longint;[public, alias : '_setjmp'];
+function c_setjmp(var rec : dpmi_jmp_buf) : longint;cdecl;[public, alias : '_setjmp'];
   begin
+{$ifndef REGCALL}
   { here we need to be subtle :
     - we need to return with the arg still on the stack
     - but we also need to jmp to FPC_setjmp and not to call it
@@ -520,6 +521,27 @@ function c_setjmp(var rec : dpmi_jmp_buf) : longint;[public, alias : '_setjmp'];
         popl    %eax
         jmp     dpmi_setjmp
      end;
+{$ELSE REGCALL}
+    { this is easier with regcall convention
+      because dpmi_setjmp expects rec arg in $eax }
+     asm
+        movl     rec,%eax
+        movl    %ebp,%esp
+        popl    %ebp
+        pushl   %eax
+        { stack is now:
+           (%esp): saved eax
+          4(%esp): return addr
+          8(%esp): rec addr
+          we need just
+          (%esp): return addr }
+        movl    4(%esp),%eax
+        movl    %eax,8(%esp)
+        popl    %eax
+        addl    $4,%esp
+        jmp     dpmi_setjmp
+     end;
+{$ENDIF REGCALL}
   end;
 {$endif CREATE_C_FUNCTIONS}
 
@@ -535,16 +557,27 @@ begin
         movl    %ecx,8(%edi)
         movl    %edx,12(%edi)
         movl    %esi,16(%edi)
+{$ifndef REGCALL}
         { load edi }
         movl    -4(%ebp),%eax
+{$ELSE REGCALL}
+        { load edi }
+        movl    (%esp),%eax
+{$ENDIF REGCALL}
         { ... and store it }
         movl    %eax,20(%edi)
         { ebp ... }
         movl    (%ebp),%eax
         movl    %eax,24(%edi)
+{$ifndef REGCALL}
         { esp ... }
         movl    %esp,%eax
         addl    $12,%eax
+{$ELSE REGCALL}
+        { for esp, use ebp ... }
+        movl    %ebp,%eax
+        addl    $8,%eax
+{$ENDIF REGCALL}
         movl    %eax,28(%edi)
         { the return address }
         movl    4(%ebp),%eax
@@ -577,7 +610,7 @@ end;
 
 
 {$ifdef CREATE_C_FUNCTIONS}
-procedure c_longjmp(var  rec : dpmi_jmp_buf;return_value : longint);[public, alias : '_longjmp'];
+procedure c_longjmp(var  rec : dpmi_jmp_buf;return_value : longint);cdecl;[public, alias : '_longjmp'];
   begin
      dpmi_longjmp(rec,return_value);
      { never gets here !! so pascal stack convention is no problem }
@@ -591,11 +624,13 @@ begin
   if (exception_level>0) then
     dec(exception_level);
   asm
+        { copy from longjmp.S }
+        { Adapted to avoid being sensitive to
+          argument being on stack or in registers 2006-12-21 PM }
+        movl    rec,%edi    { get dpmi_jmp_buf }
+        movl    return_value,%eax    { store retval in j->eax }
         { restore compiler shit }
         popl    %ebp
-        { copy from longjmp.S }
-        movl    4(%esp),%edi    { get dpmi_jmp_buf }
-        movl    8(%esp),%eax    { store retval in j->eax }
         movl    %eax,0(%edi)
 
         movw    46(%edi),%fs
@@ -645,28 +680,28 @@ end;
 
 var
   signal_list : Array[0..SIGMAX] of SignalHandler;cvar;
-  {$ifndef CREATE_C_FUNCTIONS}external;{$endif}
+  {$ifndef CREATE_C_FUNCTIONS}external;{$else}public;{$endif}
 
 {$ifdef CREATE_C_FUNCTIONS}
-function SIG_ERR(x:longint):longint;[public,alias : '___djgpp_SIG_ERR'];
+function SIG_ERR(x:longint):longint;cdecl;[public,alias : '___djgpp_SIG_ERR'];
 begin
   SIG_ERR:=-1;
 end;
 
 
-function SIG_IGN(x:longint):longint;[public,alias : '___djgpp_SIG_IGN'];
+function SIG_IGN(x:longint):longint;cdecl;[public,alias : '___djgpp_SIG_IGN'];
 begin
   SIG_IGN:=-1;
 end;
 
 
-function SIG_DFL(x:longint):longint;[public,alias : '___djgpp_SIG_DFL'];
+function SIG_DFL(x:longint):longint;cdecl;[public,alias : '___djgpp_SIG_DFL'];
 begin
   SIG_DFL:=0;
 end;
 {$endif CREATE_C_FUNCTIONS}
 
-function signal(sig : longint;func : SignalHandler) : SignalHandler;
+function signal(sig : longint;func : SignalHandler) : SignalHandler;cdecl;
 var
   temp : SignalHandler;
 begin
@@ -713,7 +748,7 @@ begin
      errln('');
 end;
 
-function _raise(sig : longint) : longint;
+function _raise(sig : longint) : longint;cdecl;
 var
   temp : SignalHandler;
 begin
@@ -1009,7 +1044,7 @@ end;
 var
   _os_trueversion : word;external name '__os_trueversion';
 
-procedure djgpp_exception_processor;[public,alias : '___djgpp_exception_processor'];
+procedure djgpp_exception_processor;cdecl;[public,alias : '___djgpp_exception_processor'];
 var
   sig : longint;
 begin
@@ -1071,7 +1106,7 @@ var
   v2prt0_exceptions_on : longbool;external name '_v2prt0_exceptions_on';
 
 
-procedure djgpp_exception_toggle;
+procedure djgpp_exception_toggle;cdecl;
 [public,alias : '___djgpp_exception_toggle'];
 var
   _except : tseginfo;
@@ -1161,7 +1196,7 @@ begin
 end;
 {$endif CREATE_C_FUNCTIONS}
 
-function dpmi_set_coprocessor_emulation(flag : longint) : longint;
+function dpmi_set_coprocessor_emulation(flag : longint) : longint;cdecl;
 var
   res : longint;
 begin
@@ -1189,7 +1224,7 @@ var
 const
   STUBINFO_END = $54;
 
-procedure __maybe_fix_w2k_ntvdm_bug;[public,alias : '___maybe_fix_w2k_ntvdm_bug'];
+procedure __maybe_fix_w2k_ntvdm_bug;cdecl;[public,alias : '___maybe_fix_w2k_ntvdm_bug'];
 var
   psp_sel : word;
 begin
@@ -1221,13 +1256,13 @@ begin
 end;
 
 
-procedure dpmiexcp_exit{(status : longint)};[public,alias : 'excep_exit'];
+procedure dpmiexcp_exit{(status : longint)};cdecl;[public,alias : 'excep_exit'];
 { We need to restore hardware interrupt handlers even if somebody calls
   `_exit' directly, or else we crash the machine in nested programs.
   We only toggle the handlers if the original keyboard handler is intact
   (otherwise, they might have already toggled them). }
 begin
-{
+(*
 void __maybe_fix_w2k_ntvdm_bug(void)
   if (_osmajor == 5 && _get_dos_version(1) == 0x532) /* Windows NT, 2000 or XP? */
   {
@@ -1249,7 +1284,7 @@ void __maybe_fix_w2k_ntvdm_bug(void)
                   : "g" (_stubinfo->psp_selector) /* input */
                   : "ax", "bx" );                 /* regs */
   }
-}
+*)
   if (exceptions_on) then
     djgpp_exception_toggle;
   _exception_exit:=nil;
@@ -1264,14 +1299,14 @@ end;
   is already present in v2prt0.as  PM}
 
 { used by dos.pp for swap vectors }
-procedure dpmi_swap_in;[public,alias : 'swap_in'];
+procedure dpmi_swap_in;cdecl;[public,alias : 'swap_in'];
 begin
   if not (exceptions_on) then
    djgpp_exception_toggle;
 end;
 
 
-procedure dpmi_swap_out;[public,alias : 'swap_out'];
+procedure dpmi_swap_out;cdecl;[public,alias : 'swap_out'];
 begin
   if (exceptions_on) then
    djgpp_exception_toggle;
@@ -1389,7 +1424,7 @@ begin
 end;
 
 
-procedure djgpp_exception_setup;
+procedure djgpp_exception_setup;cdecl;
 [public,alias : '___djgpp_exception_setup'];
 var
   temp_kbd,
@@ -1463,7 +1498,7 @@ end;
 {$endif CREATE_C_FUNCTIONS}
 
 
-function djgpp_set_ctrl_c(enable : boolean) : boolean;
+function djgpp_set_ctrl_c(enable : boolean) : boolean;cdecl;
 begin
   djgpp_set_ctrl_c:=(djgpp_hwint_flags and 1)=0;
   if enable then
@@ -1515,7 +1550,7 @@ end.
 {$else IN_SYSTEM}
 const
   FPU_ControlWord : word = $1332;
-function HandleException(sig : longint) : longint;
+function HandleException(sig : longint) : longint;cdecl;
 var
   truesig : longint;
   ErrorOfSig : longint;

+ 1 - 1
rtl/go32v2/emu387.pp

@@ -67,7 +67,7 @@ begin
 end;
 
 
-function nofpsig( sig : longint) : longint;
+function nofpsig( sig : longint) : longint;cdecl;
 const
   last_eip : longint = 0;
 var

+ 2 - 2
rtl/go32v2/profile.pp

@@ -195,7 +195,7 @@ var
   doublecall,
   reload          : longint; {=0}
 
-function mcount_tick(x : longint) : longint;
+function mcount_tick(x : longint) : longint;cdecl;
 var
   bin : longint;
 begin
@@ -220,7 +220,7 @@ end;
 var
   ___djgpp_timer_countdown:longint;external name '___djgpp_timer_countdown';
 
-function timer(x : longint) : longint;
+function timer(x : longint) : longint;cdecl;
 begin
    if reload>0 then
     ___djgpp_timer_countdown:=RELOAD;