View Issue Details

IDProjectCategoryView StatusLast Update
0014886FPCCompilerpublic2010-01-08 09:28
ReporterSven Barth Assigned ToFlorian  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Fixed in Version2.6.0 
Summary0014886: New target: Native NT user- and kernelmode
DescriptionSome months ago (April) I asked on the fpc-pascal mailing list whether Native NT as a new target is welcomed... well... I finally reached a state where I can publish the changes ;)

This are only the changes for the compiler; I will add the RTL in an extra issue in a couple of minutes :)

Targetname: nativent
Supported platforms: i386 (for now)
Supported apptypes: default and native (the last one to activate kernel mode)
Supported linkers: internal only

To Do:
* add msfastcall calling convention (only then the kernel mode code will be really useful)
* (maybe) add a apptype "kernel" to replace "native" for this target (might be used for Linux, too)
* (maybe) move most of TInternalLinkerWin functionality in a base class (TInternalLinkerPE?) to ease sharing of code between Win32/64, NativeNT, Interix (also on my list :) ) and usermade additional subsystems


If you want me to improve/correct anything in this patch, please don't hesitate to tell me!
Additional InformationNow some statements, why I changed some parts in the compiler as I did:

* in systems.pas I added "systems_nativent" for all Native NT systems. For now this only contains the i386 one, but I'd like to add x86_64, ARM and PowerPC as well (the latter two are only ReactOS ones)
* in t_win.pas I moved the writing of the entry name in a extra method "ConcatEntryName", because NativeNT shares all code besides this and the sysinit name with the Windows linker (that's why I suggested a base class above)
* in ogcoff.pas I added the flag PE_SCN_MEM_NOT_PAGED to all PE sections, because this was a source of "PAGE_FAULT_IN_NON_PAGED_AREA"-Bluescreens during driver-startup
TagsNo tags attached.
Fixed in Revision14565
FPCOldBugId
FPCTarget
Attached Files

Relationships

related to 0014887 closedFlorian New RTL: Native NT user- and kernelmode 

Activities

2009-10-24 14:13

 

nativent-compiler.patch (20,328 bytes)   
Index: compiler/compiler.pas
===================================================================
--- compiler/compiler.pas	(revision 13936)
+++ compiler/compiler.pas	(working copy)
@@ -110,6 +110,9 @@
 {$ifdef symbian}
   ,i_symbian
 {$endif symbian}
+{$ifdef nativent}
+  ,i_nativent
+{$endif nativent}
   ,globtype;
 
 function Compile(const cmd:string):longint;
Index: compiler/i386/cputarg.pas
===================================================================
--- compiler/i386/cputarg.pas	(revision 13936)
+++ compiler/i386/cputarg.pas	(working copy)
@@ -77,6 +77,9 @@
     {$ifndef NOTARGETSYMBIAN}
       ,t_symbian
     {$endif}
+    {$ifndef NOTARGETNATIVENT}
+      ,t_nativent
+    {$endif}
 
 {**************************************
              Assemblers
Index: compiler/ogcoff.pas
===================================================================
--- compiler/ogcoff.pas	(revision 13936)
+++ compiler/ogcoff.pas	(working copy)
@@ -333,6 +333,7 @@
        COFF_STYP_DATA   = $0040;
        COFF_STYP_BSS    = $0080;
 
+       PE_SUBSYSTEM_NATIVE         = 1;
        PE_SUBSYSTEM_WINDOWS_GUI    = 2;
        PE_SUBSYSTEM_WINDOWS_CUI    = 3;
        PE_SUBSYSTEM_WINDOWS_CE_GUI = 9;
@@ -2071,7 +2072,13 @@
             sechdr.nrelocs:=0;
             sechdr.relocpos:=0;
             if win32 then
-              sechdr.flags:=peencodesechdrflags(SecOptions,SecAlign)
+              begin
+                if (target_info.system in systems_nativent) and
+                   (apptype = app_native) then
+                  sechdr.flags:=peencodesechdrflags(SecOptions,SecAlign) or PE_SCN_MEM_NOT_PAGED
+                else
+                  sechdr.flags:=peencodesechdrflags(SecOptions,SecAlign);
+              end
             else
               sechdr.flags:=djencodesechdrflags(SecOptions);
             FWriter.write(sechdr,sizeof(sechdr));
@@ -2289,13 +2296,18 @@
             peoptheader.SizeOfImage:=Align(CurrMemPos,SectionMemAlign);
             peoptheader.SizeOfHeaders:=textExeSec.DataPos;
             peoptheader.CheckSum:=0;
-            if target_info.system in system_wince then
-              peoptheader.Subsystem:=PE_SUBSYSTEM_WINDOWS_CE_GUI
+            if (target_info.system in systems_nativent) and (not IsSharedLibrary or (apptype = app_native)) then
+              { Although I did not really test this, it seems that Subsystem is
+                not checked in DLLs except for maybe drivers}
+              peoptheader.Subsystem:=PE_SUBSYSTEM_NATIVE
             else
-              if apptype=app_gui then
-                peoptheader.Subsystem:=PE_SUBSYSTEM_WINDOWS_GUI
+              if target_info.system in system_wince then
+                peoptheader.Subsystem:=PE_SUBSYSTEM_WINDOWS_CE_GUI
               else
-                peoptheader.Subsystem:=PE_SUBSYSTEM_WINDOWS_CUI;
+                if apptype=app_gui then
+                  peoptheader.Subsystem:=PE_SUBSYSTEM_WINDOWS_GUI
+                else
+                  peoptheader.Subsystem:=PE_SUBSYSTEM_WINDOWS_CUI;
             peoptheader.DllCharacteristics:=0;
             peoptheader.SizeOfStackReserve:=stacksize;
             peoptheader.SizeOfStackCommit:=$1000;
@@ -2893,7 +2905,7 @@
             idtxt  : 'PECOFF';
             asmbin : '';
             asmcmd : '';
-            supported_targets : [system_i386_win32];
+            supported_targets : [system_i386_win32,system_i386_nativent];
             flags : [af_outputbinary,af_smartlink_sections];
             labelprefix : '.L';
             comment : '';
Index: compiler/pdecsub.pas
===================================================================
--- compiler/pdecsub.pas	(revision 13936)
+++ compiler/pdecsub.pas	(working copy)
@@ -2245,7 +2245,7 @@
 *)
                 if assigned(pd.import_name) then
                   begin
-                    if target_info.system in (system_all_windows +
+                    if target_info.system in (system_all_windows + systems_nativent +
                                        [system_i386_emx, system_i386_os2]) then
                    { cprefix is not used in DLL imports under Windows or OS/2 }
                       result:=pd.import_name^
Index: compiler/scandir.pas
===================================================================
--- compiler/scandir.pas	(revision 13936)
+++ compiler/scandir.pas	(working copy)
@@ -233,7 +233,7 @@
       begin
         if not (target_info.system in system_all_windows + [system_i386_os2,
                                        system_i386_emx, system_powerpc_macos,
-                                       system_arm_nds]) then
+                                       system_arm_nds] + systems_nativent) then
           begin
             if m_delphi in current_settings.modeswitches then
               Message(scan_n_app_type_not_support)
@@ -252,7 +252,7 @@
                    apptype:=app_gui
                  else if hs='CONSOLE' then
                    apptype:=app_cui
-                 else if (hs='NATIVE') and (target_info.system in system_windows) then
+                 else if (hs='NATIVE') and (target_info.system in system_windows + systems_nativent) then
                    apptype:=app_native
                  else if (hs='FS') and (target_info.system in [system_i386_os2,
                                                              system_i386_emx]) then
Index: compiler/systems.pas
===================================================================
--- compiler/systems.pas	(revision 13936)
+++ compiler/systems.pas	(working copy)
@@ -145,7 +145,8 @@
              system_x86_64_darwin,      { 61 }
              system_avr_embedded,       { 62 }
              system_i386_haiku,         { 63 }
-             system_arm_darwin          { 64 }
+             system_arm_darwin,         { 64 }
+             system_i386_nativent       { 65 }
        );
 
      type
@@ -411,6 +412,9 @@
                            system_mips_embedded,system_arm_embedded,
                            system_powerpc64_embedded];
 
+       { all native NT systems }
+       systems_nativent = [system_i386_nativent];
+
        { all systems supporting exports from programs or units }
        system_unit_program_exports = [system_i386_win32,
                                          system_i386_wdosx,
@@ -423,7 +427,7 @@
        { all systems for which weak linking has been tested/is supported }
        system_weak_linking = systems_darwin;
 
-       system_internal_sysinit = [system_i386_linux,system_i386_win32];
+       system_internal_sysinit = [system_i386_linux,system_i386_win32] + systems_nativent;
 
        system_embedded = [system_i386_embedded,system_m68k_embedded,system_alpha_embedded,
              system_powerpc_embedded,system_sparc_embedded,system_vm_embedded,
Index: compiler/systems/i_nativent.pas
===================================================================
--- compiler/systems/i_nativent.pas	(revision 0)
+++ compiler/systems/i_nativent.pas	(revision 0)
@@ -0,0 +1,106 @@
+{
+    Copyright (c) 2009 by Sven Barth
+
+    This unit implements support information structures for nativent
+    Based on Peter Vreman's i_win
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    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.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ ****************************************************************************
+}
+{ This unit implements support information structures for nativent. }
+unit i_nativent;
+
+{$i fpcdefs.inc}
+
+  interface
+
+    uses
+       systems;
+
+    const
+       system_i386_nativent_info : tsysteminfo =
+          (
+            system       : system_i386_NATIVENT;
+            name         : 'Native NT for i386';
+            shortname    : 'NativeNT';
+            flags        : [tf_files_case_aware,tf_use_function_relative_addresses,tf_smartlink_library
+                            ,tf_smartlink_sections{,tf_section_threadvars}{,tf_needs_dwarf_cfi},
+                            tf_winlikewidestring,tf_no_pic_supported,
+                            tf_no_generic_stackcheck{,tf_has_winlike_resources},tf_under_development,
+                            tf_dwarf_only_local_labels];
+            cpu          : cpu_i386;
+            unit_env     : 'NTUNITS';
+            extradefines : 'NATIVENT,UNICODE';
+            exeext       : '.exe';
+            defext       : '.def';
+            scriptext    : '.bat';
+            smartext     : '.sl';
+            unitext      : '.ppu';
+            unitlibext   : '.ppl';
+            asmext       : '.s';
+            objext       : '.o';
+            resext       : '.res';
+            resobjext    : '.or';
+            sharedlibext : '.dll';
+            staticlibext : '.a';
+            staticlibprefix : 'libp';
+            sharedlibprefix : '';
+            sharedClibext : '.dll';
+            staticClibext : '.a';
+            staticClibprefix : 'lib';
+            sharedClibprefix : '';
+            importlibprefix : 'libimp';
+            importlibext : '.a';
+            Cprefix      : '_';
+            newline      : #13#10;
+            dirsep       : '\';
+            assem        : as_i386_pecoff;
+            assemextern  : as_gas;
+            link         : nil;
+            linkextern   : nil;
+            ar           : ar_gnu_ar;
+            res          : res_gnu_windres;
+            dbg          : dbg_stabs;
+            script       : script_dos;
+            endian       : endian_little;
+            alignment    :
+              (
+                procalign       : 16;
+                loopalign       : 4;
+                jumpalign       : 0;
+                constalignmin   : 0;
+                constalignmax   : 16;
+                varalignmin     : 0;
+                varalignmax     : 16;
+                localalignmin   : 4;
+                localalignmax   : 8;
+                recordalignmin  : 0;
+                recordalignmax  : 4;
+                maxCrecordalign : 16
+              );
+            first_parm_offset : 8;
+            stacksize    : 16*1024*1024;
+            abi          : abi_default;
+          );
+
+  implementation
+
+initialization
+{$ifdef CPU86}
+  {$ifdef NATIVENT}
+    set_source_info(system_i386_nativent_info);
+  {$endif NATIVENT}
+{$endif CPU86}
+end.
Index: compiler/systems/t_nativent.pas
===================================================================
--- compiler/systems/t_nativent.pas	(revision 0)
+++ compiler/systems/t_nativent.pas	(revision 0)
@@ -0,0 +1,101 @@
+{
+    Copyright (c) 2009 by Sven Barth
+
+    This unit implements support import,export,link routines
+    for the Native NT Target
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    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.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ ****************************************************************************
+}
+unit t_nativent;
+
+{$i fpcdefs.inc}
+
+interface
+
+
+implementation
+
+  uses
+    SysUtils,
+    cutils,
+    ogbase,ogcoff,
+    globtype,globals,systems,verbose,
+    import,export,link,t_win,i_nativent;
+
+
+    type
+      TImportLibNativeNT=class(TImportLibWin)
+      end;
+
+      TExportLibNativeNT=class(TExportLibWin)
+      end;
+
+      TInternalLinkerNativeNT = class(TInternalLinkerWin)
+        constructor create;override;
+        procedure InitSysInitUnitName;override;
+        procedure ConcatEntryName; override;
+      end;
+
+{****************************************************************************
+                            TInternalLinkerNativeNT
+****************************************************************************}
+
+    constructor TInternalLinkerNativeNT.create;
+      begin
+        inherited create;
+        CExeoutput:=TPECoffexeoutput;
+        CObjInput:=TPECoffObjInput;
+      end;
+
+    procedure TInternalLinkerNativeNT.InitSysInitUnitName;
+      begin
+        if target_info.system in systems_nativent then
+          SysInitUnit := 'sysinit';
+      end;
+
+    procedure TInternalLinkerNativeNT.ConcatEntryName;
+      begin
+        with LinkScript do
+          begin
+            if IsSharedLibrary then
+              begin
+                // for now we use {$apptype native} for kernel mode code
+                if apptype=app_native then
+                  Concat('ENTRYNAME _NtDriverEntry')
+                else
+                  Concat('ENTRYNAME _DLLMainStartup')
+              end
+                else
+                  Concat('ENTRYNAME _NtProcessStartup');
+          end;
+      end;
+
+
+
+{*****************************************************************************
+                                     Initialize
+*****************************************************************************}
+
+initialization
+{$ifdef i386}
+  { NativeNT }
+  RegisterInternalLinker(system_i386_nativent_info,TInternalLinkerNativeNT);
+  RegisterImport(system_i386_nativent,TImportLibNativeNT);
+  RegisterExport(system_i386_nativent,TExportLibNativeNT);
+//  RegisterRes(res_gnu_windres_info,TWinLikeResourceFile);
+  RegisterTarget(system_i386_nativent_info);
+{$endif i386}
+end.
Index: compiler/systems/t_win.pas
===================================================================
--- compiler/systems/t_win.pas	(revision 13936)
+++ compiler/systems/t_win.pas	(working copy)
@@ -68,6 +68,7 @@
         constructor create;override;
         procedure DefaultLinkScript;override;
         procedure InitSysInitUnitName;override;
+        procedure ConcatEntryName; virtual;
       end;
 
       TExternalLinkerWin=class(texternallinker)
@@ -958,20 +959,8 @@
                   Comment(V_Error,'Import library not found for '+S);
               end;
             if IsSharedLibrary then
-              begin
-                Concat('ISSHAREDLIBRARY');
-                if apptype=app_gui then
-                  Concat('ENTRYNAME _DLLWinMainCRTStartup')
-                else
-                  Concat('ENTRYNAME _DLLMainCRTStartup');
-              end
-            else
-              begin
-                if apptype=app_gui then
-                  Concat('ENTRYNAME _WinMainCRTStartup')
-                else
-                  Concat('ENTRYNAME _mainCRTStartup');
-              end;
+              Concat('ISSHAREDLIBRARY');
+            ConcatEntryName;
             if not ImageBaseSetExplicity then
               begin
                 if IsSharedLibrary then
@@ -1062,7 +1051,29 @@
           GlobalInitSysInitUnitName(self);
       end;
 
+    procedure TInternalLinkerWin.ConcatEntryName;
+      begin
+        with LinkScript do
+          begin
+            if IsSharedLibrary then
+              begin
+                Concat('ISSHAREDLIBRARY');
+                if apptype=app_gui then
+                  Concat('ENTRYNAME _DLLWinMainCRTStartup')
+                else
+                  Concat('ENTRYNAME _DLLMainCRTStartup');
+              end
+            else
+              begin
+                if apptype=app_gui then
+                  Concat('ENTRYNAME _WinMainCRTStartup')
+                else
+                  Concat('ENTRYNAME _mainCRTStartup');
+              end;
+          end;
+      end;
 
+
 {****************************************************************************
                               TExternalLinkerWin
 ****************************************************************************}
Index: compiler/x86/agx86att.pas
===================================================================
--- compiler/x86/agx86att.pas	(revision 13936)
+++ compiler/x86/agx86att.pas	(working copy)
@@ -319,7 +319,8 @@
             asmcmd : '--32 -o $OBJ $ASM';
             supported_targets : [system_i386_GO32V2,system_i386_linux,system_i386_Win32,system_i386_freebsd,system_i386_solaris,system_i386_beos,
                                 system_i386_netbsd,system_i386_Netware,system_i386_qnx,system_i386_wdosx,system_i386_openbsd,
-                                system_i386_netwlibc,system_i386_wince,system_i386_embedded,system_i386_symbian,system_i386_haiku,system_x86_6432_linux];
+                                system_i386_netwlibc,system_i386_wince,system_i386_embedded,system_i386_symbian,system_i386_haiku,system_x86_6432_linux,
+                                system_i386_nativent];
             flags : [af_allowdirect,af_needar,af_smartlink_sections,af_supports_dwarf];
             labelprefix : '.L';
             comment : '# ';
Index: utils/fpcm/fpcmake.ini
===================================================================
--- utils/fpcm/fpcmake.ini	(revision 13936)
+++ utils/fpcm/fpcmake.ini	(working copy)
@@ -966,6 +966,12 @@
 SHORTSUFFIX=symbian
 endif
 
+# NativeNT
+ifeq ($(OS_TARGET),NativeNT)
+SHAREDLIBEXT=.dll
+SHORTSUFFIX=nativent
+endif
+
 else
 # long version for 1.0.x - target specific extensions
 
Index: utils/fpcm/fpcmmain.pp
===================================================================
--- utils/fpcm/fpcmmain.pp	(revision 13936)
+++ utils/fpcm/fpcmmain.pp	(working copy)
@@ -70,7 +70,7 @@
         o_linux,o_go32v2,o_win32,o_os2,o_freebsd,o_beos,o_haiku,o_netbsd,
         o_amiga,o_atari, o_solaris, o_qnx, o_netware, o_openbsd,o_wdosx,
         o_palmos,o_macos,o_darwin,o_emx,o_watcom,o_morphos,o_netwlibc,
-        o_win64,o_wince,o_gba,o_nds,o_embedded,o_symbian
+        o_win64,o_wince,o_gba,o_nds,o_embedded,o_symbian,o_nativent
       );
 
       TTargetSet=array[tcpu,tos] of boolean;
@@ -92,14 +92,14 @@
         'linux','go32v2','win32','os2','freebsd','beos','haiku','netbsd',
         'amiga','atari','solaris', 'qnx', 'netware','openbsd','wdosx',
         'palmos','macos','darwin','emx','watcom','morphos','netwlibc',
-        'win64','wince','gba','nds','embedded','symbian'
+        'win64','wince','gba','nds','embedded','symbian','nativent'
       );
 
       OSSuffix : array[TOS] of string=(
         '_linux','_go32v2','_win32','_os2','_freebsd','_beos','_haiku','_netbsd',
         '_amiga','_atari','_solaris', '_qnx', '_netware','_openbsd','_wdosx',
         '_palmos','_macos','_darwin','_emx','_watcom','_morphos','_netwlibc',
-        '_win64','_wince','_gba','_nds','_embedded','_symbian'
+        '_win64','_wince','_gba','_nds','_embedded','_symbian','_nativent'
       );
 
       { This table is kept OS,Cpu because it is easier to maintain (PFV) }
@@ -132,7 +132,8 @@
         { gba    }  ( false, false, false, false, false, true,  false, false, false),
         { nds    }  ( false, false, false, false, false, true,  false, false, false),
         { embedded }( true,  true,  true,  true,  true,  true,  true,  true,  true ),
-        { symbian } ( true,  false, false, false, false, true,  false, false, false)
+        { symbian } ( true,  false, false, false, false, true,  false, false, false),
+        { nativent }( true,  false, false, false, false, false, false, false, false)
       );
 
     type
nativent-compiler.patch (20,328 bytes)   

2009-12-09 21:36

 

nativent-compiler-2.patch (20,594 bytes)   
Index: compiler/compiler.pas
===================================================================
--- compiler/compiler.pas	(revision 14375)
+++ compiler/compiler.pas	(working copy)
@@ -110,6 +110,9 @@
 {$ifdef symbian}
   ,i_symbian
 {$endif symbian}
+{$ifdef nativent}
+  ,i_nativent
+{$endif nativent}
   ,globtype;
 
 function Compile(const cmd:string):longint;
Index: compiler/i386/cputarg.pas
===================================================================
--- compiler/i386/cputarg.pas	(revision 14375)
+++ compiler/i386/cputarg.pas	(working copy)
@@ -77,6 +77,9 @@
     {$ifndef NOTARGETSYMBIAN}
       ,t_symbian
     {$endif}
+    {$ifndef NOTARGETNATIVENT}
+      ,t_nativent
+    {$endif}
 
 {**************************************
              Assemblers
Index: compiler/ogcoff.pas
===================================================================
--- compiler/ogcoff.pas	(revision 14375)
+++ compiler/ogcoff.pas	(working copy)
@@ -333,6 +333,7 @@
        COFF_STYP_DATA   = $0040;
        COFF_STYP_BSS    = $0080;
 
+       PE_SUBSYSTEM_NATIVE         = 1;
        PE_SUBSYSTEM_WINDOWS_GUI    = 2;
        PE_SUBSYSTEM_WINDOWS_CUI    = 3;
        PE_SUBSYSTEM_WINDOWS_CE_GUI = 9;
@@ -2084,7 +2085,13 @@
             sechdr.nrelocs:=0;
             sechdr.relocpos:=0;
             if win32 then
-              sechdr.flags:=peencodesechdrflags(SecOptions,SecAlign)
+              begin
+                if (target_info.system in systems_nativent) and
+                   (apptype = app_native) then
+                  sechdr.flags:=peencodesechdrflags(SecOptions,SecAlign) or PE_SCN_MEM_NOT_PAGED
+                else
+                  sechdr.flags:=peencodesechdrflags(SecOptions,SecAlign);
+              end
             else
               sechdr.flags:=djencodesechdrflags(SecOptions);
             FWriter.write(sechdr,sizeof(sechdr));
@@ -2302,13 +2309,18 @@
             peoptheader.SizeOfImage:=Align(CurrMemPos,SectionMemAlign);
             peoptheader.SizeOfHeaders:=textExeSec.DataPos;
             peoptheader.CheckSum:=0;
-            if target_info.system in system_wince then
-              peoptheader.Subsystem:=PE_SUBSYSTEM_WINDOWS_CE_GUI
+            if (target_info.system in systems_nativent) and (not IsSharedLibrary or (apptype = app_native)) then
+              { Although I did not really test this, it seems that Subsystem is
+                not checked in DLLs except for maybe drivers}
+              peoptheader.Subsystem:=PE_SUBSYSTEM_NATIVE
             else
-              if apptype=app_gui then
-                peoptheader.Subsystem:=PE_SUBSYSTEM_WINDOWS_GUI
+              if target_info.system in system_wince then
+                peoptheader.Subsystem:=PE_SUBSYSTEM_WINDOWS_CE_GUI
               else
-                peoptheader.Subsystem:=PE_SUBSYSTEM_WINDOWS_CUI;
+                if apptype=app_gui then
+                  peoptheader.Subsystem:=PE_SUBSYSTEM_WINDOWS_GUI
+                else
+                  peoptheader.Subsystem:=PE_SUBSYSTEM_WINDOWS_CUI;
             peoptheader.DllCharacteristics:=0;
             peoptheader.SizeOfStackReserve:=stacksize;
             peoptheader.SizeOfStackCommit:=$1000;
@@ -2906,7 +2918,7 @@
             idtxt  : 'PECOFF';
             asmbin : '';
             asmcmd : '';
-            supported_targets : [system_i386_win32];
+            supported_targets : [system_i386_win32,system_i386_nativent];
             flags : [af_outputbinary,af_smartlink_sections];
             labelprefix : '.L';
             comment : '';
Index: compiler/options.pas
===================================================================
--- compiler/options.pas	(revision 14375)
+++ compiler/options.pas	(working copy)
@@ -2224,7 +2224,10 @@
     system_arm_gba:
       target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
     system_arm_nds:
-      target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs]
+      target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
+    system_i386_nativent:
+      // until these features are implemented, they are disabled in the compiler
+      target_unsup_features:=[f_threading,f_processes,f_fileio,f_textio,f_consoleio,f_commandargs,f_stackcheck];
     else
       target_unsup_features:=[];
   end;
Index: compiler/pdecsub.pas
===================================================================
--- compiler/pdecsub.pas	(revision 14375)
+++ compiler/pdecsub.pas	(working copy)
@@ -2372,7 +2372,7 @@
 *)
                 if assigned(pd.import_name) then
                   begin
-                    if target_info.system in (system_all_windows +
+                    if target_info.system in (system_all_windows + systems_nativent +
                                        [system_i386_emx, system_i386_os2]) then
                    { cprefix is not used in DLL imports under Windows or OS/2 }
                       result:=pd.import_name^
Index: compiler/scandir.pas
===================================================================
--- compiler/scandir.pas	(revision 14375)
+++ compiler/scandir.pas	(working copy)
@@ -233,7 +233,7 @@
       begin
         if not (target_info.system in system_all_windows + [system_i386_os2,
                                        system_i386_emx, system_powerpc_macos,
-                                       system_arm_nds]) then
+                                       system_arm_nds] + systems_nativent) then
           begin
             if m_delphi in current_settings.modeswitches then
               Message(scan_n_app_type_not_support)
@@ -252,7 +252,7 @@
                    apptype:=app_gui
                  else if hs='CONSOLE' then
                    apptype:=app_cui
-                 else if (hs='NATIVE') and (target_info.system in system_windows) then
+                 else if (hs='NATIVE') and (target_info.system in system_windows + systems_nativent) then
                    apptype:=app_native
                  else if (hs='FS') and (target_info.system in [system_i386_os2,
                                                              system_i386_emx]) then
Index: compiler/systems.pas
===================================================================
--- compiler/systems.pas	(revision 14375)
+++ compiler/systems.pas	(working copy)
@@ -149,7 +149,8 @@
              system_arm_darwin,         { 64 }
              system_x86_64_solaris,     { 65 }
              system_mips_linux,         { 66 }
-             system_mipsel_linux        { 67 }
+             system_mipsel_linux,       { 67 }
+             system_i386_nativent       { 68 }
        );
 
      type
@@ -449,6 +450,9 @@
        { all symbian systems }
        systems_symbian = [system_i386_symbian,system_arm_symbian];
 
+       { all native nt systems }
+       systems_nativent = [system_i386_nativent];
+
        cpu2str : array[TSystemCpu] of string[10] =
             ('','i386','m68k','alpha','powerpc','sparc','vm','ia64','x86_64',
              'mips','arm', 'powerpc64', 'avr', 'mipsel');
Index: compiler/systems/i_nativent.pas
===================================================================
--- compiler/systems/i_nativent.pas	(revision 0)
+++ compiler/systems/i_nativent.pas	(revision 0)
@@ -0,0 +1,106 @@
+{
+    Copyright (c) 2009 by Sven Barth
+
+    This unit implements support information structures for nativent
+    Based on Peter Vreman's i_win
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    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.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ ****************************************************************************
+}
+{ This unit implements support information structures for nativent. }
+unit i_nativent;
+
+{$i fpcdefs.inc}
+
+  interface
+
+    uses
+       systems;
+
+    const
+       system_i386_nativent_info : tsysteminfo =
+          (
+            system       : system_i386_NATIVENT;
+            name         : 'Native NT for i386';
+            shortname    : 'NativeNT';
+            flags        : [tf_files_case_aware,tf_use_function_relative_addresses,tf_smartlink_library
+                            ,tf_smartlink_sections{,tf_section_threadvars}{,tf_needs_dwarf_cfi},
+                            tf_no_pic_supported,
+                            tf_no_generic_stackcheck{,tf_has_winlike_resources},tf_under_development,
+                            tf_dwarf_only_local_labels];
+            cpu          : cpu_i386;
+            unit_env     : 'NTUNITS';
+            extradefines : 'NATIVENT,UNICODE';
+            exeext       : '.exe';
+            defext       : '.def';
+            scriptext    : '.bat';
+            smartext     : '.sl';
+            unitext      : '.ppu';
+            unitlibext   : '.ppl';
+            asmext       : '.s';
+            objext       : '.o';
+            resext       : '.res';
+            resobjext    : '.or';
+            sharedlibext : '.dll';
+            staticlibext : '.a';
+            staticlibprefix : 'libp';
+            sharedlibprefix : '';
+            sharedClibext : '.dll';
+            staticClibext : '.a';
+            staticClibprefix : 'lib';
+            sharedClibprefix : '';
+            importlibprefix : 'libimp';
+            importlibext : '.a';
+            Cprefix      : '_';
+            newline      : #13#10;
+            dirsep       : '\';
+            assem        : as_i386_pecoff;
+            assemextern  : as_gas;
+            link         : nil;
+            linkextern   : nil;
+            ar           : ar_gnu_ar;
+            res          : res_gnu_windres;
+            dbg          : dbg_stabs;
+            script       : script_dos;
+            endian       : endian_little;
+            alignment    :
+              (
+                procalign       : 16;
+                loopalign       : 4;
+                jumpalign       : 0;
+                constalignmin   : 0;
+                constalignmax   : 16;
+                varalignmin     : 0;
+                varalignmax     : 16;
+                localalignmin   : 4;
+                localalignmax   : 8;
+                recordalignmin  : 0;
+                recordalignmax  : 4;
+                maxCrecordalign : 16
+              );
+            first_parm_offset : 8;
+            stacksize    : 16*1024*1024;
+            abi          : abi_default;
+          );
+
+  implementation
+
+initialization
+{$ifdef CPU86}
+  {$ifdef NATIVENT}
+    set_source_info(system_i386_nativent_info);
+  {$endif NATIVENT}
+{$endif CPU86}
+end.
Index: compiler/systems/t_nativent.pas
===================================================================
--- compiler/systems/t_nativent.pas	(revision 0)
+++ compiler/systems/t_nativent.pas	(revision 0)
@@ -0,0 +1,94 @@
+{
+    Copyright (c) 2009 by Sven Barth
+
+    This unit implements support import,export,link routines
+    for the Native NT Target
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    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.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ ****************************************************************************
+}
+unit t_nativent;
+
+{$i fpcdefs.inc}
+
+interface
+
+
+implementation
+
+  uses
+    SysUtils,
+    cutils,
+    ogbase,ogcoff,
+    globtype,globals,systems,verbose,
+    import,export,link,t_win,i_nativent;
+
+
+    type
+      TImportLibNativeNT=class(TImportLibWin)
+      end;
+
+      TExportLibNativeNT=class(TExportLibWin)
+      end;
+
+      TInternalLinkerNativeNT = class(TInternalLinkerWin)
+        constructor create;override;
+        procedure ConcatEntryName; override;
+      end;
+
+{****************************************************************************
+                            TInternalLinkerNativeNT
+****************************************************************************}
+
+    constructor TInternalLinkerNativeNT.create;
+      begin
+        inherited create;
+        CExeoutput:=TPECoffexeoutput;
+        CObjInput:=TPECoffObjInput;
+      end;
+
+    procedure TInternalLinkerNativeNT.ConcatEntryName;
+      begin
+        with LinkScript do
+          begin
+            if IsSharedLibrary then
+              begin
+                // for now we use {$apptype native} for kernel mode code
+                if apptype=app_native then
+                  Concat('ENTRYNAME _NtDriverEntry')
+                else
+                  Concat('ENTRYNAME _DLLMainStartup')
+              end
+                else
+                  Concat('ENTRYNAME _NtProcessStartup');
+          end;
+      end;
+
+
+
+{*****************************************************************************
+                                     Initialize
+*****************************************************************************}
+
+initialization
+{$ifdef i386}
+  { NativeNT }
+  RegisterInternalLinker(system_i386_nativent_info,TInternalLinkerNativeNT);
+  RegisterImport(system_i386_nativent,TImportLibNativeNT);
+  RegisterExport(system_i386_nativent,TExportLibNativeNT);
+//  RegisterRes(res_gnu_windres_info,TWinLikeResourceFile);
+  RegisterTarget(system_i386_nativent_info);
+{$endif i386}
+end.
Index: compiler/systems/t_win.pas
===================================================================
--- compiler/systems/t_win.pas	(revision 14375)
+++ compiler/systems/t_win.pas	(working copy)
@@ -68,6 +68,7 @@
         constructor create;override;
         procedure DefaultLinkScript;override;
         procedure InitSysInitUnitName;override;
+        procedure ConcatEntryName; virtual;
       end;
 
       TExternalLinkerWin=class(texternallinker)
@@ -958,20 +959,8 @@
                   Comment(V_Error,'Import library not found for '+S);
               end;
             if IsSharedLibrary then
-              begin
-                Concat('ISSHAREDLIBRARY');
-                if apptype=app_gui then
-                  Concat('ENTRYNAME _DLLWinMainCRTStartup')
-                else
-                  Concat('ENTRYNAME _DLLMainCRTStartup');
-              end
-            else
-              begin
-                if apptype=app_gui then
-                  Concat('ENTRYNAME _WinMainCRTStartup')
-                else
-                  Concat('ENTRYNAME _mainCRTStartup');
-              end;
+              Concat('ISSHAREDLIBRARY');
+            ConcatEntryName;
             if not ImageBaseSetExplicity then
               begin
                 if IsSharedLibrary then
@@ -1062,7 +1051,29 @@
           GlobalInitSysInitUnitName(self);
       end;
 
+    procedure TInternalLinkerWin.ConcatEntryName;
+      begin
+        with LinkScript do
+          begin
+            if IsSharedLibrary then
+              begin
+                Concat('ISSHAREDLIBRARY');
+                if apptype=app_gui then
+                  Concat('ENTRYNAME _DLLWinMainCRTStartup')
+                else
+                  Concat('ENTRYNAME _DLLMainCRTStartup');
+              end
+            else
+              begin
+                if apptype=app_gui then
+                  Concat('ENTRYNAME _WinMainCRTStartup')
+                else
+                  Concat('ENTRYNAME _mainCRTStartup');
+              end;
+          end;
+      end;
 
+
 {****************************************************************************
                               TExternalLinkerWin
 ****************************************************************************}
Index: compiler/x86/agx86att.pas
===================================================================
--- compiler/x86/agx86att.pas	(revision 14375)
+++ compiler/x86/agx86att.pas	(working copy)
@@ -339,7 +339,8 @@
             asmcmd : '--32 -o $OBJ $ASM';
             supported_targets : [system_i386_GO32V2,system_i386_linux,system_i386_Win32,system_i386_freebsd,system_i386_solaris,system_i386_beos,
                                 system_i386_netbsd,system_i386_Netware,system_i386_qnx,system_i386_wdosx,system_i386_openbsd,
-                                system_i386_netwlibc,system_i386_wince,system_i386_embedded,system_i386_symbian,system_i386_haiku,system_x86_6432_linux];
+                                system_i386_netwlibc,system_i386_wince,system_i386_embedded,system_i386_symbian,system_i386_haiku,system_x86_6432_linux,
+                                system_i386_nativent];
             flags : [af_allowdirect,af_needar,af_smartlink_sections,af_supports_dwarf];
             labelprefix : '.L';
             comment : '# ';
Index: utils/fpcm/fpcmake.ini
===================================================================
--- utils/fpcm/fpcmake.ini	(revision 14375)
+++ utils/fpcm/fpcmake.ini	(working copy)
@@ -966,6 +966,12 @@
 SHORTSUFFIX=symbian
 endif
 
+# NativeNT
+ifeq ($(OS_TARGET),NativeNT)
+SHAREDLIBEXT=.dll
+SHORTSUFFIX=nativent
+endif
+
 else
 # long version for 1.0.x - target specific extensions
 
Index: utils/fpcm/fpcmmain.pp
===================================================================
--- utils/fpcm/fpcmmain.pp	(revision 14375)
+++ utils/fpcm/fpcmmain.pp	(working copy)
@@ -70,7 +70,7 @@
         o_linux,o_go32v2,o_win32,o_os2,o_freebsd,o_beos,o_haiku,o_netbsd,
         o_amiga,o_atari, o_solaris, o_qnx, o_netware, o_openbsd,o_wdosx,
         o_palmos,o_macos,o_darwin,o_emx,o_watcom,o_morphos,o_netwlibc,
-        o_win64,o_wince,o_gba,o_nds,o_embedded,o_symbian
+        o_win64,o_wince,o_gba,o_nds,o_embedded,o_symbian,o_nativent
       );
 
       TTargetSet=array[tcpu,tos] of boolean;
@@ -92,14 +92,14 @@
         'linux','go32v2','win32','os2','freebsd','beos','haiku','netbsd',
         'amiga','atari','solaris', 'qnx', 'netware','openbsd','wdosx',
         'palmos','macos','darwin','emx','watcom','morphos','netwlibc',
-        'win64','wince','gba','nds','embedded','symbian'
+        'win64','wince','gba','nds','embedded','symbian','nativent'
       );
 
       OSSuffix : array[TOS] of string=(
         '_linux','_go32v2','_win32','_os2','_freebsd','_beos','_haiku','_netbsd',
         '_amiga','_atari','_solaris', '_qnx', '_netware','_openbsd','_wdosx',
         '_palmos','_macos','_darwin','_emx','_watcom','_morphos','_netwlibc',
-        '_win64','_wince','_gba','_nds','_embedded','_symbian'
+        '_win64','_wince','_gba','_nds','_embedded','_symbian','_nativent'
       );
 
       { This table is kept OS,Cpu because it is easier to maintain (PFV) }
@@ -132,7 +132,8 @@
         { gba    }  ( false, false, false, false, false, true,  false, false, false, false, false, false, false, false),
         { nds    }  ( false, false, false, false, false, true,  false, false, false, false, false, false, false, false),
         { embedded }( true,  true,  true,  true,  true,  true,  true,  true,  true , false, false, false, false, false),
-        { symbian } ( true,  false, false, false, false, true,  false, false, false, false, false, false, false, false)
+        { symbian } ( true,  false, false, false, false, true,  false, false, false, false, false, false, false, false),
+        { nativent }( true,  false, false, false, false, false, false, false, false, false, false, false, false, false)
       );
 
     type
nativent-compiler-2.patch (20,594 bytes)   

Sven Barth

2009-12-09 21:37

manager   ~0032862

After the additions of the new MIPS targets and my continued development on this target (no, I haven't given up the C++ classes) I thought it was time for a new version of this patch.

Significant change: I disabled the non implemented features (threading and IO) in the compiler, so I was able to remove the defines in the system unit.Significant change: I disabled the non implemented features (threading and IO) in the compiler, so I was able to remove the defines in the system unit.

If you have any reasons to not commit this patch, please tell me.

Florian

2009-12-09 21:59

administrator   ~0032864

Only a matter of time :(

Sven Barth

2009-12-13 20:55

manager   ~0033052

So it's only the usual problem (not meant in a negative way - I know this very well ;) ). So I'll happily continue coding. But can someone at least add a relationship between these two reports (the other one is 0014887), please?

By the way: I finished a wiki entry for this target (see http://wiki.freepascal.org/Target_NativeNT ) and added it to the platform list. :D

Florian

2010-01-07 18:42

administrator   ~0033499

Thanks, applied.

Sven Barth

2010-01-08 09:28

manager   ~0033507

Thank you for applying.

I'll talk back to you at the mailing list about the change I mentioned in the issue description.

Issue History

Date Modified Username Field Change
2009-10-24 14:13 Sven Barth New Issue
2009-10-24 14:13 Sven Barth File Added: nativent-compiler.patch
2009-12-09 21:36 Sven Barth File Added: nativent-compiler-2.patch
2009-12-09 21:37 Sven Barth Note Added: 0032862
2009-12-09 21:59 Florian Note Added: 0032864
2009-12-13 20:55 Sven Barth Note Added: 0033052
2009-12-13 21:20 Marco van de Voort Relationship added related to 0014887
2010-01-07 18:42 Florian Fixed in Revision => 14565
2010-01-07 18:42 Florian Status new => resolved
2010-01-07 18:42 Florian Fixed in Version => 2.5.1
2010-01-07 18:42 Florian Resolution open => fixed
2010-01-07 18:42 Florian Assigned To => Florian
2010-01-07 18:42 Florian Note Added: 0033499
2010-01-08 09:28 Sven Barth Status resolved => closed
2010-01-08 09:28 Sven Barth Note Added: 0033507