Browse Source

+ added the changes from Pavel Ozerski after several modifications
to be able to create DLLs

pierre 27 years ago
parent
commit
8a0fb3c67e
4 changed files with 100 additions and 5 deletions
  1. 12 1
      rtl/win32/Makefile
  2. 43 4
      rtl/win32/syswin32.pp
  3. 31 0
      rtl/win32/wdllprt0.as
  4. 14 0
      rtl/win32/wprt0.as

+ 12 - 1
rtl/win32/Makefile

@@ -72,6 +72,7 @@ include $(CFG)/makefile.cfg
 
 # Define Win32 Units
 SYSTEMPPU=syswin32$(PPUEXT)
+LOADERS=wprt0 wdllprt0
 OBJECTS=strings dos \
 	windows objects \
 	cpu mmx getopts heaptrc objpas sysutils
@@ -137,6 +138,12 @@ clean :
 # Base Units (System, strings, os-dependent-base-unit)
 #
 
+wprt0$(OEXT) : wprt0.as
+	$(AS) -o wprt0$(OEXT) wprt0.as
+
+wdllprt0$(OEXT) : wdllprt0.as
+	$(AS) -o wdllprt0$(OEXT) wdllprt0.as
+
 $(SYSTEMPPU) : syswin32.pp win32.inc $(SYSDEPS)
 	$(COMPILER) -Us -Sg syswin32.pp $(REDIR)
 
@@ -386,7 +393,11 @@ include $(CFG)/makefile.def
 
 #
 # $Log$
-# Revision 1.12  1998-11-24 19:52:10  jonas
+# Revision 1.13  1998-11-30 09:16:57  pierre
+#   + added the changes from Pavel Ozerski after several modifications
+#     to be able to create DLLs
+#
+# Revision 1.12  1998/11/24 19:52:10  jonas
 #   + added warning about TABs
 #
 # Revision 1.11  1998/11/18 09:28:07  pierre

+ 43 - 4
rtl/win32/syswin32.pp

@@ -65,9 +65,13 @@ var
 { Win32 Info }
   startupinfo : tstartupinfo;
   hprevinst,
+  HInstance,
   MainInstance,
   cmdshow     : longint;
   IsLibrary,IsMultiThreaded,IsConsole : boolean;
+{* Changes made by Ozerski 26.10.1998}
+  DLLreason,DLLparam:longint;
+{* End Changes}
 
 implementation
 
@@ -623,12 +627,14 @@ procedure getdir(drivenr:byte;var dir:shortstring);
 
 var
   ModuleName : array[0..255] of char;
+
 function GetCommandFile:pchar;
 begin
   GetModuleFileName(0,@ModuleName,255);
   GetCommandFile:=@ModuleName;
 end;
 
+{* End changes}
 
 procedure setup_arguments;
 var
@@ -684,6 +690,7 @@ begin
 end;
 
 
+{$ifndef FPC_WIN32_DLL_SUPPORT}
 {$ASMMODE DIRECT}
 var
   fpucw : word;
@@ -705,6 +712,8 @@ begin
    ExitProcess(0);
 end;
 
+{$else FPC_WIN32_DLL_SUPPORT}
+
 {$ifdef dummy}
 Function SetUpStack : longint;
 { This routine does the following :                            }
@@ -724,14 +733,40 @@ end;
 {$endif}
 {$ASMMODE ATT}
 
+procedure Exe_entry;[public, alias : 'FPC_EXE_Entry'];
+  begin
+     IsLibrary:=false;
+     asm
+        call PASCALMAIN
+     end;
+     { if we pass here there was no error ! }
+     ExitProcess(0);
+  end;
+  
+procedure Dll_entry;[public, alias : 'FPC_DLL_Entry'];
+  begin
+     IsLibrary:=true;
+     case DLLreason of
+       1,2 : asm
+                call PASCALMAIN
+             end;
+       else
+          asm
+             call FPC_DO_EXIT
+          end;
+     end;
+  end;
+{$endif def FPC_WIN32_DLL_SUPPORT}
+  
 begin
 { get some helpful informations }
   GetStartupInfo(@startupinfo);
 { some misc Win32 stuff }
   hprevinst:=0;
-  MainInstance:=getmodulehandle(GetCommandFile);
-  IsLibrary:=MainInstance=0;
-  IsConsole:=true;
+  if not IsLibrary then
+    HInstance:=getmodulehandle(GetCommandFile);
+  MainInstance:=HInstance;
+  { No idea how to know this issue !! }
   IsMultithreaded:=false;
   cmdshow:=startupinfo.wshowwindow;
 { to test stack depth }
@@ -757,7 +792,11 @@ end.
 
 {
   $Log$
-  Revision 1.24  1998-11-16 15:48:54  peter
+  Revision 1.25  1998-11-30 09:16:58  pierre
+    + added the changes from Pavel Ozerski after several modifications
+      to be able to create DLLs
+
+  Revision 1.24  1998/11/16 15:48:54  peter
     * fixed longbool returns for api calls
 
   Revision 1.23  1998/11/16 14:14:58  pierre

+ 31 - 0
rtl/win32/wdllprt0.as

@@ -0,0 +1,31 @@
+//DLL Startup code for WIN32 port of FPK-Pascal 0.9.98
+//Written by P.Ozerski
+//16.10.1998
+     .text
+     .globl _mainCRTStartup
+_mainCRTStartup:
+     movl $1,U_SYSWIN32_ISCONSOLE
+     jmp .LDLL_Entry
+     .globl _WinMainCRTStartup
+_WinMainCRTStartup:
+     movl $0,U_SYSWIN32_ISCONSOLE
+.LDLL_Entry:
+     pushl    %ebp
+     movl     %esp,%ebp
+     pushl    %ebx
+     pushl    %esi
+     pushl    %edi
+     movl     8(%ebp),%edi
+     movl     %edi,U_SYSWIN32_HINSTANCE
+     movl     12(%ebp),%edi
+     movl     %edi,U_SYSWIN32_DLLREASON
+     movl     16(%ebp),%edi
+     movl     %edi,U_SYSWIN32_DLLPARAM
+     call     FPC_DLL_Entry
+     popl     %edi
+     popl     %esi
+     popl     %ebx
+     popl     %ebp
+     ret      $12
+
+

+ 14 - 0
rtl/win32/wprt0.as

@@ -0,0 +1,14 @@
+//Startup code for WIN32 port of FPK-Pascal 0.9.98
+//Written by P.Ozerski
+//1998
+// modified by Pierre Muller
+     .text
+     .GLOBL _mainCRTStartup
+_mainCRTStartup:
+     movl   $1,U_SYSWIN32_ISCONSOLE
+     jmp    FPC_EXE_Entry
+.GLOBL _WinMainCRTStartup
+_WinMainCRTStartup:
+     movl   $0,U_SYSWIN32_ISCONSOLE
+     jmp    FPC_EXE_Entry
+