Index: packages/regexpr/fpmake.pp
===================================================================
--- packages/regexpr/fpmake.pp	(revision 28349)
+++ packages/regexpr/fpmake.pp	(working copy)
@@ -17,7 +17,7 @@
     P.Directory:=ADirectory;
 {$endif ALLPACKAGES}
     P.Version:='2.7.1';
-    P.OSes:=P.OSes-[embedded];
+    P.OSes:=P.OSes-[embedded,uefi];
     P.Dependencies.Add('rtl-objpas');
     P.SourcePath.Add('src');
 
Index: packages/libgd/fpmake.pp
===================================================================
--- packages/libgd/fpmake.pp	(revision 28349)
+++ packages/libgd/fpmake.pp	(working copy)
@@ -18,7 +18,7 @@
 {$endif ALLPACKAGES}
     P.Version:='2.7.1';
     P.SourcePath.Add('src');
-    P.OSes := P.OSes - [embedded,nativent,msdos];
+    P.OSes := P.OSes - [embedded,nativent,msdos,uefi];
 
     T:=P.Targets.AddUnit('gd.pas');
 
Index: packages/sdl/fpmake.pp
===================================================================
--- packages/sdl/fpmake.pp	(revision 28349)
+++ packages/sdl/fpmake.pp	(working copy)
@@ -23,7 +23,7 @@
     P.Dependencies.Add('pthreads',AllUnixOSes);
     if Defaults.CPU=arm then
        P.OSes := P.OSes - [darwin];
-    P.OSes := P.OSes - [iphonesim,os2,emx,go32v2,watcom,nativent,embedded,android,amiga,msdos];
+    P.OSes := P.OSes - [iphonesim,os2,emx,go32v2,watcom,nativent,embedded,android,amiga,msdos,uefi];
 
     T:=P.Targets.AddUnit('logger.pas');
       with T.Dependencies do
Index: packages/fcl-res/fpmake.pp
===================================================================
--- packages/fcl-res/fpmake.pp	(revision 28349)
+++ packages/fcl-res/fpmake.pp	(working copy)
@@ -23,7 +23,7 @@
     P.Email := '';
     P.Description := 'Resource handling of Free Component Libraries (FCL), FPC''s OOP library.';
     P.NeedLibC:= false;
-    P.OSes:=AllOSes-[embedded];
+    P.OSes:=AllOSes-[embedded,uefi];
 
     P.SourcePath.Add('src');
     P.IncludePath.Add('src');
Index: packages/fcl-js/fpmake.pp
===================================================================
--- packages/fcl-js/fpmake.pp	(revision 28349)
+++ packages/fcl-js/fpmake.pp	(working copy)
@@ -22,7 +22,7 @@
     P.HomepageURL := 'www.freepascal.org';
     P.Email := 'michael@freepascal.org';
     P.Description := 'Javascript scanner/parser/syntax tree units';
-    P.OSes:=AllOSes-[embedded,msdos];
+    P.OSes:=AllOSes-[embedded,msdos,uefi];
 
     P.SourcePath.Add('src');
     P.IncludePath.Add('src');
Index: packages/hash/fpmake.pp
===================================================================
--- packages/hash/fpmake.pp	(revision 28349)
+++ packages/hash/fpmake.pp	(working copy)
@@ -23,7 +23,7 @@
     P.Email := '';
     P.Description := 'Several hash and cryptography algorithms (MD5,CRC,Linux crypt and NTLM1).';
     P.NeedLibC:= false;
-    P.OSes:=P.OSes-[embedded];
+    P.OSes:=P.OSes-[embedded,uefi];
     P.Dependencies.Add('rtl-objpas');
 
     P.Version:='2.7.1';
Index: packages/bzip2/fpmake.pp
===================================================================
--- packages/bzip2/fpmake.pp	(revision 28349)
+++ packages/bzip2/fpmake.pp	(working copy)
@@ -27,7 +27,7 @@
     P.Email := '';
     P.Description := 'BZip2 decompression unit.';
     P.NeedLibC:= true;
-    P.OSes := P.OSes - [embedded,nativent,msdos];
+    P.OSes := P.OSes - [embedded,nativent,msdos,uefi];
 
     P.SourcePath.Add('src');
     P.IncludePath.Add('src');
Index: packages/fcl-sdo/fpmake.pp
===================================================================
--- packages/fcl-sdo/fpmake.pp	(revision 28349)
+++ packages/fcl-sdo/fpmake.pp	(working copy)
@@ -24,7 +24,7 @@
     P.HomepageURL := 'www.freepascal.org';
     P.Email := 'inoussa12@gmail.com';
     P.Description := 'Free Pascal implementation of Service Data Objects';
-    P.OSes:=AllOSes-[embedded,msdos];
+    P.OSes:=AllOSes-[embedded,msdos,uefi];
 
     // P.NeedLibC:= false;
     P.SourcePath.Add('src/base');
Index: packages/fcl-sound/fpmake.pp
===================================================================
--- packages/fcl-sound/fpmake.pp	(revision 28349)
+++ packages/fcl-sound/fpmake.pp	(working copy)
@@ -25,7 +25,7 @@
     P.Email := '';
     P.Description := 'Sound loading, storing and conversion parts for the Free Component Libraries (FCL), FPC''s OOP library.';
     P.NeedLibC:= false;
-    P.OSes:=AllOSes-[embedded,msdos];
+    P.OSes:=AllOSes-[embedded,msdos,uefi];
 
     P.SourcePath.Add('src');
 
Index: packages/fpmkunit/fpmake.pp
===================================================================
--- packages/fpmkunit/fpmake.pp	(revision 28349)
+++ packages/fpmkunit/fpmake.pp	(working copy)
@@ -24,7 +24,7 @@
     P.Email := '';
     P.Description := 'Basic library of the fpmake/fppkg build system.';
     P.NeedLibC:= false;  // true for headers that indirectly link to libc?
-    P.OSes := P.OSes - [embedded,nativent,msdos];
+    P.OSes := P.OSes - [embedded,nativent,msdos,uefi];
 
     // All dependencies (including implicit) are listed
     // here to be able to update all requirements to
Index: packages/fpmkunit/src/fpmkunit.pp
===================================================================
--- packages/fpmkunit/src/fpmkunit.pp	(revision 28349)
+++ packages/fpmkunit/src/fpmkunit.pp	(working copy)
@@ -96,7 +96,7 @@
     amiga,atari, solaris, qnx, netware, openbsd,wdosx,
     palmos,macos,darwin,emx,watcom,morphos,netwlibc,
     win64,wince,gba,nds,embedded,symbian,haiku,iphonesim,
-    aix,java,android,nativent,msdos,wii
+    aix,java,android,nativent,msdos,wii,uefi
   );
   TOSes = Set of TOS;
 
@@ -193,7 +193,8 @@
     { android } ( false, true,  false, false, false, false, true,  false, false, false, false, true,  true , false),
     { nativent }( false, true,  false, false, false, false, false, false, false, false, false, false, false, false),
     { msdos }   ( false, false, false, false, false, false, false, false, false, false, false, false, false, true ),
-    { wii }     ( false, false, false, true , false, false, false, false, false, false, false, false, false, false )
+    { wii }     ( false, false, false, true , false, false, false, false, false, false, false, false, false, false),
+    { uefi }    ( false, true,  false, false, false, false, false, false, false, false, false, false, false, false)
   );
 
   // Useful
Index: packages/fcl-stl/fpmake.pp
===================================================================
--- packages/fcl-stl/fpmake.pp	(revision 28349)
+++ packages/fcl-stl/fpmake.pp	(working copy)
@@ -24,7 +24,7 @@
     P.Email := '';
     P.Description := 'Asynchonous event management of Free Component Libraries (FCL), FPC''s OOP library.';
     P.NeedLibC:= false;
-    P.OSes:=AllOSes-[embedded];
+    P.OSes:=AllOSes-[embedded,uefi];
 
     P.Options.Add('-S2h');
     P.SourcePath.Add('src');
Index: packages/fcl-base/fpmake.pp
===================================================================
--- packages/fcl-base/fpmake.pp	(revision 28349)
+++ packages/fcl-base/fpmake.pp	(working copy)
@@ -26,7 +26,7 @@
     P.Email := '';
     P.Description := 'Base library of Free Component Libraries(FCL), FPC''s OOP library.';
     P.NeedLibC:= false;
-    P.OSes:=AllOSes-[embedded,msdos];
+    P.OSes:=AllOSes-[embedded,msdos,uefi];
 
     P.SourcePath.Add('src');
     P.SourcePath.Add('src/$(OS)');
Index: packages/hermes/fpmake.pp
===================================================================
--- packages/hermes/fpmake.pp	(revision 28349)
+++ packages/hermes/fpmake.pp	(working copy)
@@ -24,7 +24,7 @@
     P.Email := '';
     P.Description := 'Library for pixel graphics conversion';
     P.NeedLibC := false;
-    P.OSes:=AllOSes-[embedded,msdos];
+    P.OSes:=AllOSes-[embedded,msdos,uefi];
 
     P.SourcePath.Add('src');
     P.IncludePath.Add('src');
Index: packages/fcl-db/fpmake.pp
===================================================================
--- packages/fcl-db/fpmake.pp	(revision 28349)
+++ packages/fcl-db/fpmake.pp	(working copy)
@@ -32,7 +32,7 @@
     P.Email := '';
     P.Description := 'Database library of Free Component Libraries(FCL), FPC''s OOP library.';
     P.NeedLibC:= false;
-    P.OSes:=AllOSes-[embedded,msdos];
+    P.OSes:=AllOSes-[embedded,msdos,uefi];
 
     P.Directory:=ADirectory;
     P.Version:='2.7.1';
Index: packages/fcl-json/fpmake.pp
===================================================================
--- packages/fcl-json/fpmake.pp	(revision 28349)
+++ packages/fcl-json/fpmake.pp	(working copy)
@@ -24,7 +24,7 @@
     P.Email := '';
     P.Description := 'Json interfacing, part of Free Component Libraries (FCL), FPC''s OOP library.';
     P.NeedLibC:= false;
-    P.OSes:=AllOSes-[embedded,msdos];
+    P.OSes:=AllOSes-[embedded,msdos,uefi];
 
     P.SourcePath.Add('src');
 
Index: packages/fcl-image/fpmake.pp
===================================================================
--- packages/fcl-image/fpmake.pp	(revision 28349)
+++ packages/fcl-image/fpmake.pp	(working copy)
@@ -27,7 +27,7 @@
     P.Email := '';
     P.Description := 'Image loading and conversion parts of Free Component Libraries (FCL), FPC''s OOP library.';
     P.NeedLibC:= false;
-    P.OSes := P.OSes - [embedded,nativent,msdos];
+    P.OSes := P.OSes - [embedded,nativent,msdos,uefi];
 
     P.SourcePath.Add('src');
     P.IncludePath.Add('src');
Index: packages/Makefile.fpc.fpcmake
===================================================================
--- packages/Makefile.fpc.fpcmake	(revision 28349)
+++ packages/Makefile.fpc.fpcmake	(working copy)
@@ -4,7 +4,7 @@
 #
 
 [target]
-dirs=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json fcl-js fcl-process unzip regexpr chm fcl-res fcl-stl libgd symbolic bzip2 hermes fppkg
+dirs=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json fcl-js fcl-process unzip regexpr chm fcl-res fcl-stl libgd symbolic hermes fppkg
 dirs_linux_i386=libc unixutil graph pxlib bzip2
 dirs_i386_linux=graph
 dirs_x86_64_linux=graph
@@ -67,6 +67,7 @@
 dirs_wii=libogcfpc
 dirs_arm_nds=libndsfpc
 
+
 [install]
 fpcpackage=y
 fpcsubdir=packages
Index: packages/chm/fpmake.pp
===================================================================
--- packages/chm/fpmake.pp	(revision 28349)
+++ packages/chm/fpmake.pp	(working copy)
@@ -25,7 +25,7 @@
     P.Email := '';
     P.Description := 'Standalone CHM reader and writer library';
     P.NeedLibC:= false;
-    P.OSes := P.OSes - [embedded,nativent,msdos];
+    P.OSes := P.OSes - [embedded,nativent,msdos,uefi];
 
     D:=P.Dependencies.Add('fcl-xml');
     D:=P.Dependencies.Add('fcl-base');
Index: packages/fcl-xml/fpmake.pp
===================================================================
--- packages/fcl-xml/fpmake.pp	(revision 28349)
+++ packages/fcl-xml/fpmake.pp	(working copy)
@@ -29,7 +29,7 @@
     P.Email := '';
     P.Description := 'XML and DOM parts of Free Component Libraries (FCL), FPC''s OOP library.';
     P.NeedLibC:= false;
-    P.OSes:=AllOSes-[embedded,msdos];
+    P.OSes:=AllOSes-[embedded,msdos,uefi];
 
     P.SourcePath.Add('src');
     P.IncludePath.Add('src');
Index: packages/fcl-fpcunit/fpmake.pp
===================================================================
--- packages/fcl-fpcunit/fpmake.pp	(revision 28349)
+++ packages/fcl-fpcunit/fpmake.pp	(working copy)
@@ -29,7 +29,7 @@
     P.Email := '';
     P.Description := 'Unit testing system inspired by JUnit of Free Component Libraries (FCL), FPC''s OOP library.';
     P.NeedLibC:= false;
-    P.OSes := P.OSes - [embedded,nativent,msdos];
+    P.OSes := P.OSes - [embedded,nativent,msdos,uefi];
 
     P.SourcePath.Add('src');
     P.IncludePath.Add('src');
Index: packages/fcl-process/fpmake.pp
===================================================================
--- packages/fcl-process/fpmake.pp	(revision 28349)
+++ packages/fcl-process/fpmake.pp	(working copy)
@@ -24,7 +24,7 @@
     P.Description := 'Process (execution) related parts of Free Component Libraries (FCL), FPC''s OOP library.';
     P.Options.Add('-S2h');
     P.NeedLibC:= false;
-    P.OSes:=AllOSes-[embedded,msdos];
+    P.OSes:=AllOSes-[embedded,msdos,uefi];
 
     P.SourcePath.Add('src');
     P.IncludePath.Add('src/unix',AllUnixOSes);
Index: packages/fcl-passrc/fpmake.pp
===================================================================
--- packages/fcl-passrc/fpmake.pp	(revision 28349)
+++ packages/fcl-passrc/fpmake.pp	(working copy)
@@ -24,7 +24,7 @@
     P.Email := '';
     P.Description := 'Pascal parsing parts of Free Component Libraries (FCL), FPC''s OOP library.';
     P.NeedLibC:= false;
-    P.OSes:=AllOSes-[embedded,msdos];
+    P.OSes:=AllOSes-[embedded,msdos,uefi];
 
     P.SourcePath.Add('src');
 
Index: packages/fppkg/fpmake.pp
===================================================================
--- packages/fppkg/fpmake.pp	(revision 28349)
+++ packages/fppkg/fpmake.pp	(working copy)
@@ -43,7 +43,7 @@
     P.Email := '';
     P.Description := 'Libraries to create fppkg package managers.';
     P.NeedLibC:= false;
-    P.OSes := P.OSes - [embedded,nativent,msdos];
+    P.OSes := P.OSes - [embedded,nativent,msdos,uefi];
 
     P.SourcePath.Add('src');
 
Index: packages/rtl-extra/Makefile.fpc.fpcmake
===================================================================
--- packages/rtl-extra/Makefile.fpc.fpcmake	(revision 28349)
+++ packages/rtl-extra/Makefile.fpc.fpcmake	(working copy)
@@ -18,6 +18,7 @@
 units_iphonesim=matrix ucomplex objects
 units_beos=matrix ucomplex objects
 units_haiku=matrix ucomplex objects
+units_uefi=
 
 units_go32v2=matrix ucomplex objects 
 units_watcom=ucomplex
Index: packages/unzip/fpmake.pp
===================================================================
--- packages/unzip/fpmake.pp	(revision 28349)
+++ packages/unzip/fpmake.pp	(working copy)
@@ -18,7 +18,7 @@
 {$endif ALLPACKAGES}
     P.Version:='2.7.1';
     P.SourcePath.Add('src');
-    P.OSes := P.OSes - [embedded,nativent,msdos];
+    P.OSes := P.OSes - [embedded,nativent,msdos,uefi];
 
     T:=P.Targets.AddUnit('unzip51g.pp');
       with T.Dependencies do
Index: packages/paszlib/fpmake.pp
===================================================================
--- packages/paszlib/fpmake.pp	(revision 28349)
+++ packages/paszlib/fpmake.pp	(working copy)
@@ -18,7 +18,7 @@
     P.Directory:=ADirectory;
 {$endif ALLPACKAGES}
     P.Version:='2.7.1';
-    P.OSes := P.OSes - [embedded,nativent,msdos];
+    P.OSes := P.OSes - [embedded,nativent,msdos,uefi];
 
     D:=P.Dependencies.Add('hash');
       D.Version:='2.7.1';
Index: packages/fcl-registry/fpmake.pp
===================================================================
--- packages/fcl-registry/fpmake.pp	(revision 28349)
+++ packages/fcl-registry/fpmake.pp	(working copy)
@@ -26,7 +26,7 @@
     P.Email := '';
     P.Description := 'Windows registry + emulation parts of Free Component Libraries (FCL), FPC''s OOP library.';
     P.NeedLibC:= false;
-    P.OSes:=AllOSes-[embedded,msdos];
+    P.OSes:=AllOSes-[embedded,msdos,uefi];
 
     P.SourcePath.Add('src');
     P.IncludePath.Add('src');
Index: utils/fpcm/fpcmmain.pp
===================================================================
--- utils/fpcm/fpcmmain.pp	(revision 28349)
+++ utils/fpcm/fpcmmain.pp	(working copy)
@@ -75,7 +75,7 @@
         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_nativent,o_iphonesim,
-        o_wii,o_aix,o_java,o_android,o_msdos
+        o_wii,o_aix,o_java,o_android,o_msdos,o_uefi
       );
 
       TTargetSet=array[tcpu,tos] of boolean;
@@ -98,7 +98,7 @@
         'amiga','atari','solaris', 'qnx', 'netware','openbsd','wdosx',
         'palmos','macos','darwin','emx','watcom','morphos','netwlibc',
         'win64','wince','gba','nds','embedded','symbian','nativent',
-        'iphonesim', 'wii', 'aix', 'java', 'android', 'msdos'
+        'iphonesim', 'wii', 'aix', 'java', 'android', 'msdos', 'uefi'
       );
 
       OSSuffix : array[TOS] of string=(
@@ -106,7 +106,7 @@
         '_amiga','_atari','_solaris', '_qnx', '_netware','_openbsd','_wdosx',
         '_palmos','_macos','_darwin','_emx','_watcom','_morphos','_netwlibc',
         '_win64','_wince','_gba','_nds','_embedded','_symbian','_nativent',
-        '_iphonesim','_wii','_aix','_java','_android','_msdos'
+        '_iphonesim','_wii','_aix','_java','_android','_msdos','_uefi'
       );
 
       { This table is kept OS,Cpu because it is easier to maintain (PFV) }
@@ -146,7 +146,8 @@
         { aix }     ( false, false, true,  false, false, false, true,  false, false, false, false, false, false, false,   false, false),
         { java }    ( false, false, false, false, false, false, false, false, false, false, false, false, false, false,   true,  false),
         { android } ( true,  false, false, false, false, true,  false, false, false, false, false, true,  false, false,   true,  false),
-        { msdos }   ( false, false, false, false, false, false, false, false, false, false, false, false, false, false,   false, true)
+        { msdos }   ( false, false, false, false, false, false, false, false, false, false, false, false, false, false,   false, true),
+        { uefi }    ( true,  false, false, false, false, false, false, false, false, false, false, false, false, false,   false, false)
       );
 
     type
Index: utils/fpcm/fpcmake.ini
===================================================================
--- utils/fpcm/fpcmake.ini	(revision 28349)
+++ utils/fpcm/fpcmake.ini	(working copy)
@@ -1109,6 +1109,11 @@
 SHORTSUFFIX=d16
 endif
 
+# UEFI
+ifeq ($(OS_TARGET),uefi)
+SHAREDLIBEXT=.efi
+SHORTSUFFIX=efi
+endif
 
 
 # For 8.3 limited OS's the short suffixes
Index: rtl/Makefile.fpc
===================================================================
--- rtl/Makefile.fpc	(revision 28349)
+++ rtl/Makefile.fpc	(working copy)
@@ -42,6 +42,7 @@
 dirs_mipsel_android=android
 dirs_jvm_android=android/jvm
 dirs_msdos=msdos
+dirs_uefi=uefi
 
 [install]
 fpcpackage=y
Index: rtl/uefi/tthread.inc
===================================================================
--- rtl/uefi/tthread.inc	(revision 0)
+++ rtl/uefi/tthread.inc	(revision 0)
@@ -0,0 +1,73 @@
+{
+    This file is part of the Free Component Library (FCL)
+    Copyright (c) 2014 by Olivier Coursière
+    
+    Based on nativeNT target by Sven Barth
+
+    Classes unit for UEFI
+
+    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.
+
+ **********************************************************************}
+
+{ Thread management routines }
+
+procedure TThread.SysCreate(CreateSuspended: Boolean;
+                            const StackSize: SizeUInt);
+begin
+
+end;
+
+
+procedure TThread.SysDestroy;
+begin
+
+end;
+
+procedure TThread.CallOnTerminate;
+begin
+  FOnTerminate(Self);
+end;
+
+procedure TThread.DoTerminate;
+begin
+  if Assigned(FOnTerminate) then
+    Synchronize(@CallOnTerminate);
+end;
+
+function TThread.GetPriority: TThreadPriority;
+begin
+  Result := tpNormal;
+end;
+
+procedure TThread.SetPriority(Value: TThreadPriority);
+begin
+end;
+
+
+procedure TThread.SetSuspended(Value: Boolean);
+begin
+end;
+
+procedure TThread.Suspend;
+begin
+end;
+
+procedure TThread.Resume;
+begin
+end;
+
+procedure TThread.Terminate;
+begin
+  FTerminated := True;
+end;
+
+function TThread.WaitFor: Integer;
+begin
+  Result := -1;
+end;
Index: rtl/uefi/Makefile.fpc
===================================================================
--- rtl/uefi/Makefile.fpc	(revision 0)
+++ rtl/uefi/Makefile.fpc	(revision 0)
@@ -0,0 +1,122 @@
+#
+#   Makefile.fpc for Free Pascal UEFI RTL
+#
+
+[package]
+main=rtl
+
+[target]
+loaders=
+#units=system objpas macpas iso7185 buildrtl lineinfo lnfodwrf
+units=system uuchar objpas iso7185 cpall buildrtl
+implicitunits= \
+      ctypes strings \
+#      heaptrc
+#      initc cmem dynlibs signals \
+#      dos \
+      rtlconsts sysconst sysutils math types \
+      typinfo fgl classes \
+      $(CPU_UNITS) charset getopts \
+#      sockets printer \
+#      keyboard
+#      sharemem exeinfo fpintres \
+      cp1250 cp1251 cp1252 cp1253 cp1254 cp1255 cp1256 cp1257 cp1258 \
+      cp437 cp646 cp850 cp856 cp866 cp874 cp8859_1 cp8859_5 cp8859_2 cp852
+
+# shared=$(DLLS)
+
+rsts=math typinfo classes sysconst
+
+[require]
+nortl=y
+
+[install]
+fpcpackage=y
+
+[default]
+fpcdir=../..
+target=uefi
+
+[compiler]
+includedir=$(INC) $(PROCINC)
+sourcedir=$(INC) $(PROCINC) $(COMMON)
+
+
+[prerules]
+RTL=..
+INC=$(RTL)/inc
+COMMON=$(RTL)/common
+PROCINC=$(RTL)/$(CPU_TARGET)
+
+UNITPREFIX=rtl
+SYSTEMUNIT=system
+
+CPU_UNITS=
+
+ifeq ($(ARCH),i386)
+CPU_UNITS=cpu mmx
+endif
+
+ifeq ($(ARCH),x86_64)
+CPU_UNITS=x86 cpu
+endif
+
+LOADERS=crt0
+
+ifneq ($(findstring 2.0.,$(FPC_VERSION)),)
+#LOADERS=wprt0 wdllprt0 gprt0 wcygprt0
+DLLS=
+else
+DLLS=fpcmemdll
+endif
+
+# Paths
+OBJPASDIR=$(RTL)/objpas
+
+[rules]
+.NOTPARALLEL:
+SYSTEMPPU=$(addsuffix $(PPUEXT),system)
+
+# Get the system independent include file names.
+# This will set the following variables :
+# SYSINCNAMES
+include $(INC)/makefile.inc
+SYSINCDEPS=$(addprefix $(INC)/,$(SYSINCNAMES))
+
+# Get the processor dependent include file names.
+# This will set the following variables :
+# CPUINCNAMES
+include $(PROCINC)/makefile.cpu
+SYSCPUDEPS=$(addprefix $(PROCINC)/,$(CPUINCNAMES))
+
+# Put system unit dependencies together.
+SYSDEPS=$(SYSINCDEPS) $(SYSCPUDEPS)
+
+
+#
+# Loaders
+#
+
+crt0$(OEXT) : $(CPU_TARGET)/crt0.as
+        $(AS) -o $(UNITTARGETDIRPREFIX)crt0$(OEXT) $(CPU_TARGET)/crt0.as
+
+#
+# Unit specific rules
+#
+
+system$(PPUEXT) : system.pp $(SYSDEPS)
+        $(COMPILER) -Us -Sg system.pp
+
+uuchar$(PPUEXT): $(SYSTEMUNIT)$(PPUEXT) $(INC)/uuchar.pp
+
+objpas$(PPUEXT): $(OBJPASDIR)/objpas.pp $(INC)/except.inc system$(PPUEXT)
+        $(COMPILER) -Fi$(OBJPASDIR) $(OBJPASDIR)/objpas.pp
+
+macpas$(PPUEXT) : $(INC)/macpas.pp objpas$(PPUEXT) buildrtl$(PPUEXT)
+        $(COMPILER) $(INC)/macpas.pp $(REDIR)
+
+buildrtl$(PPUEXT): buildrtl.pp system$(PPUEXT) objpas$(PPUEXT)
+        $(COMPILER) -Fi$(OBJPASDIR)/sysutils -Fi$(OBJPASDIR)/classes -Fu$(PROCINC) -I$(OBJPASDIR) -Fi$(DDKINC) -I$(INC) -Fu$(INC) -Fu$(OBJPASDIR) buildrtl
+
+cpall$(PPUEXT): $(RTL)/charmaps/cpall.pas system$(PPUEXT) objpas$(PPUEXT)
+        $(COMPILER) -Fu$(INC) -Fi$(RTL)/charmaps $(RTL)/charmaps/cpall.pas
Index: rtl/uefi/sysheap.inc
===================================================================
--- rtl/uefi/sysheap.inc	(revision 0)
+++ rtl/uefi/sysheap.inc	(revision 0)
@@ -0,0 +1,40 @@
+{
+    Basic UEFI definitions
+
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2014 by Olivier Coursière
+
+    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.
+
+ **********************************************************************}
+
+var
+  SysHeap: THandle = 0;
+
+procedure PrepareSysHeap;
+begin
+end;
+
+// default memory manager
+
+function SysOSAlloc(size: ptruint): pointer;
+begin
+  if SysHeap = 0 then
+    PrepareSysHeap;
+  SysOSAlloc := Pointer(0);
+//  SysOSAlloc := RtlAllocateHeap(SysHeap, 0, size);
+end;
+
+{$define HAS_SYSOSFREE}
+
+procedure SysOSFree(p: pointer; size: ptruint);
+begin
+  // if heap isn't set, then nothing was allocated
+//  if SysHeap <> 0 then
+//    RtlFreeHeap(SysHeap, 0, p);
+end;
Index: rtl/uefi/sysdir.inc
===================================================================
--- rtl/uefi/sysdir.inc	(revision 0)
+++ rtl/uefi/sysdir.inc	(revision 0)
@@ -0,0 +1,34 @@
+{
+    Basic UEFI definitions
+
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2014 by Olivier Coursière
+
+    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.
+
+ **********************************************************************}
+
+{*****************************************************************************
+                           Directory Handling
+*****************************************************************************}
+
+procedure do_MkDir(const s: UnicodeString);
+begin
+end;
+
+procedure do_RmDir(const s: UnicodeString);
+begin
+end;
+
+procedure do_ChDir(const s: UnicodeString);
+begin
+end;
+
+procedure do_GetDir(DriveNr: byte; var Dir: UnicodeString);
+begin
+end;
Index: rtl/uefi/sysfile.inc
===================================================================
--- rtl/uefi/sysfile.inc	(revision 0)
+++ rtl/uefi/sysfile.inc	(revision 0)
@@ -0,0 +1,66 @@
+{
+    Basic UEFI definitions
+
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2014 by Olivier Coursière
+
+    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.
+
+ **********************************************************************}
+
+{*****************************************************************************
+                          Low Level File Routines
+*****************************************************************************}
+
+function do_isdevice(handle:thandle):boolean;
+begin
+end;
+
+procedure do_close(h : thandle);
+begin
+end;
+
+procedure do_erase(p : pwidechar; pchangeable: boolean);
+begin
+end;
+
+procedure do_rename(p1,p2 : pwidechar; p1changeable, p2changeable: boolean);
+begin
+end;
+
+function do_write(h:thandle;addr:pointer;len : longint) : longint;
+begin
+end;
+
+function do_read(h: thandle; addr: pointer; len: longint): longint;
+begin
+end;
+
+function do_filepos(handle : thandle) : Int64;
+begin
+end;
+
+procedure do_seek(handle: thandle; pos: Int64);
+begin
+end;
+
+function do_seekend(handle:thandle):Int64;
+begin
+end;
+
+function do_filesize(handle : thandle) : Int64;
+begin
+end;
+
+procedure do_truncate (handle:thandle;pos:Int64);
+begin
+end;
+
+procedure do_open(var f;p:pwidechar;flags:longint; pchangeable: boolean);
+begin
+end;
Index: rtl/uefi/sysos.inc
===================================================================
--- rtl/uefi/sysos.inc	(revision 0)
+++ rtl/uefi/sysos.inc	(revision 0)
@@ -0,0 +1,14 @@
+{
+    Basic UEFI definitions
+
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2014 by Olivier Coursière
+
+    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.
+
+ **********************************************************************}
Index: rtl/uefi/rtldefs.inc
===================================================================
--- rtl/uefi/rtldefs.inc	(revision 0)
+++ rtl/uefi/rtldefs.inc	(revision 0)
@@ -0,0 +1,24 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2012 by Free Pascal development team
+
+    This file contains platform-specific defines that are used in
+    multiple RTL units.
+
+    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.
+
+ **********************************************************************}
+
+{ the single byte OS APIs always use UTF-8 }
+{ define FPCRTL_FILESYSTEM_UTF8}
+
+{ The OS supports a single byte file system operations API that we use }
+{ define FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
+
+{ The OS supports a two byte file system operations API that we use }
+{$define FPCRTL_FILESYSTEM_TWO_BYTE_API}
Index: rtl/uefi/classes.pp
===================================================================
--- rtl/uefi/classes.pp	(revision 0)
+++ rtl/uefi/classes.pp	(revision 0)
@@ -0,0 +1,47 @@
+{
+    This file is part of the Free Component Library (FCL)
+    Copyright (c) 2014 by Olivier Coursière
+    
+    Based on nativeNT target by Sven Barth
+
+    Classes unit for UEFI
+
+    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.
+
+ **********************************************************************}
+
+{$mode objfpc}
+
+unit Classes;
+
+{$INLINE ON}
+
+interface
+
+uses
+  sysutils,
+  types,
+  typinfo,
+{$ifdef FPC_TESTGENERICS}
+  fgl,
+{$endif}
+  rtlconsts;
+
+{$i classesh.inc}
+
+implementation
+
+{ OS - independent class implementations are in /inc directory. }
+{$i classes.inc}
+
+
+initialization
+  CommonInit;
+finalization
+  CommonCleanup;
+end.
Index: rtl/uefi/sysutils.pp
===================================================================
--- rtl/uefi/sysutils.pp	(revision 0)
+++ rtl/uefi/sysutils.pp	(revision 0)
@@ -0,0 +1,261 @@
+{
+    Sysutils unit for UEFI
+
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2014 by Olivier Coursière
+
+    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.
+
+ **********************************************************************}
+unit sysutils;
+
+interface
+
+{$MODE objfpc}
+{$MODESWITCH OUT}
+{ force ansistrings }
+{$H+}
+
+{$DEFINE HAS_SLEEP}
+
+{ TODO : check this for UEFI }
+{ used OS file system APIs use ansistring }
+{$define SYSUTILS_HAS_UNICODESTR_FILEUTIL_IMPL}
+{ OS has an ansistring/single byte environment variable API (actually it's
+  unicodestring, but that's not yet implemented) }
+{$define SYSUTILS_HAS_ANSISTR_ENVVAR_IMPL}
+
+{ Include platform independent interface part }
+{$i sysutilh.inc}
+
+implementation
+
+  uses
+    sysconst;
+
+{$DEFINE FPC_NOGENERICANSIROUTINES}
+
+{ Include platform independent implementation part }
+{$i sysutils.inc}
+
+{****************************************************************************
+                              File Functions
+****************************************************************************}
+
+function FileOpen(const FileName : UnicodeString; Mode : Integer) : THandle;
+begin
+end;
+
+
+function FileCreate(const FileName : UnicodeString) : THandle;
+begin
+end;
+
+
+function FileCreate(const FileName : UnicodeString; Rights: longint) : THandle;
+begin
+end;
+
+
+function FileCreate(const FileName : UnicodeString; ShareMode : longint; Rights: longint) : THandle;
+begin
+end;
+
+
+function FileRead(Handle : THandle; out Buffer; Count : longint) : Longint;
+begin
+end;
+
+
+function FileWrite(Handle : THandle; const Buffer; Count : Longint) : Longint;
+begin
+end;
+
+
+function FileSeek(Handle : THandle;FOffset,Origin : Longint) : Longint;
+begin
+end;
+
+
+function FileSeek(Handle : THandle; FOffset: Int64; Origin: Longint) : Int64;
+begin
+end;
+
+
+procedure FileClose(Handle : THandle);
+begin
+end;
+
+
+function FileTruncate(Handle : THandle;Size: Int64) : boolean;
+begin
+end;
+
+
+function FileAge(const FileName: UnicodeString): Longint;
+begin
+  { TODO }
+  Result := -1;
+end;
+
+
+function FileExists(const FileName: UnicodeString): Boolean;
+begin
+end;
+
+
+Procedure InternalFindClose(var Handle: THandle);
+begin
+end;
+
+
+Function InternalFindNext (Var Rslt : TAbstractSearchRec; var Name: UnicodeString) : Longint;
+begin
+end;
+
+
+Function InternalFindFirst (Const Path : UnicodeString; Attr : Longint; out Rslt : TAbstractSearchRec; var Name : UnicodeString) : Longint;
+begin
+end;
+
+
+function DirectoryExists(const Directory : UnicodeString) : Boolean;
+begin
+end;
+
+
+function FileGetDate(Handle: THandle): Longint;
+begin
+end;
+
+
+function FileSetDate(Handle: THandle;Age: Longint): Longint;
+begin
+end;
+
+
+function FileGetAttr(const FileName: UnicodeString): Longint;
+begin
+end;
+
+
+function FileSetAttr(const Filename: UnicodeString; Attr: LongInt): Longint;
+begin
+end;
+
+
+function DeleteFile(const FileName: UnicodeString): Boolean;
+begin
+end;
+
+
+function RenameFile(const OldName, NewName: UnicodeString): Boolean;
+begin
+end;
+
+
+{****************************************************************************
+                              Disk Functions
+****************************************************************************}
+
+function diskfree(drive: byte): int64;
+begin
+  { here the mount manager needs to be queried }
+  Result := -1;
+end;
+
+
+function disksize(drive: byte): int64;
+begin
+  { here the mount manager needs to be queried }
+  Result := -1;
+end;
+
+
+{****************************************************************************
+                              Time Functions
+****************************************************************************}
+
+
+procedure GetLocalTime(var SystemTime: TSystemTime);
+begin
+end;
+
+
+{****************************************************************************
+                              Misc Functions
+****************************************************************************}
+
+procedure sysbeep;
+begin
+  { empty }
+end;
+
+procedure InitInternational;
+begin
+  InitInternationalGeneric;
+end;
+
+
+{****************************************************************************
+                           Target Dependent
+****************************************************************************}
+
+function SysErrorMessage(ErrorCode: Integer): String;
+begin
+  Result := 'UEFI error code: 0x' + IntToHex(ErrorCode, 8);
+end;
+
+{****************************************************************************
+                              Initialization code
+****************************************************************************}
+
+function GetEnvironmentVariable(const EnvVar: String): String;
+begin
+  Result := '';
+end;
+
+function GetEnvironmentVariableCount: Integer;
+begin
+  Result := 0;
+end;
+
+function GetEnvironmentString(Index: Integer): {$ifdef FPC_RTL_UNICODE}UnicodeString{$else}AnsiString{$endif};
+begin
+  Result := '';
+end;
+
+function ExecuteProcess(const Path: AnsiString; const ComLine: AnsiString;
+  Flags: TExecuteFlags = []): Integer;
+begin
+  { TODO : implement }
+  Result := 0;
+end;
+
+function ExecuteProcess(const Path: AnsiString;
+  const ComLine: Array of AnsiString; Flags:TExecuteFlags = []): Integer;
+begin
+  Result := 0;
+end;
+
+procedure Sleep(Milliseconds: Cardinal);
+begin
+end;
+
+
+{****************************************************************************
+                              Initialization code
+****************************************************************************}
+
+initialization
+  InitExceptions;       { Initialize exceptions. OS independent }
+  InitInternational;    { Initialize internationalization settings }
+  OnBeep := @SysBeep;
+finalization
+  DoneExceptions;
+end.
Index: rtl/uefi/buildrtl.pp
===================================================================
--- rtl/uefi/buildrtl.pp	(revision 0)
+++ rtl/uefi/buildrtl.pp	(revision 0)
@@ -0,0 +1,19 @@
+unit buildrtl;
+
+  interface
+
+    uses
+      ctypes, strings,
+      rtlconsts, sysconst, sysutils, math, types,
+      typinfo, fgl, classes,
+{$ifdef cpui386}
+      mmx, cpu,
+{$endif}
+{$ifdef cpux86_64}
+      cpu,
+{$endif}
+      charset, cpall, getopts;
+
+  implementation
+
+end.
Index: rtl/uefi/sysosh.inc
===================================================================
--- rtl/uefi/sysosh.inc	(revision 0)
+++ rtl/uefi/sysosh.inc	(revision 0)
@@ -0,0 +1,33 @@
+{
+    Basic UEFI definitions
+
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2014 by Olivier Coursière
+
+    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.
+
+ **********************************************************************}
+ 
+{ Platform specific information }
+type
+  THandle = PtrUInt;
+  TThreadID=  THandle;
+  
+  { the fields of this record are os dependent  }
+  { and they shouldn't be used in a program     }
+  { only the type TCriticalSection is important }
+  PRTLCriticalSection = ^TRTLCriticalSection;
+  TRTLCriticalSection = packed record
+{    DebugInfo : pointer;
+    LockCount : longint;
+    RecursionCount : longint;
+    OwningThread : THandle;
+    LockSemaphore : THandle;
+    SpinCount : LongWord; // PtrUInt?
+}
+  end;
Index: rtl/uefi/system.pp
===================================================================
--- rtl/uefi/system.pp	(revision 0)
+++ rtl/uefi/system.pp	(revision 0)
@@ -0,0 +1,226 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2014 by Olivier Coursière
+
+    FPC Pascal system unit for UEFI target.
+
+    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.
+
+ **********************************************************************}
+unit System;
+ 
+interface
+
+{$define DISABLE_NO_THREAD_MANAGER}
+ 
+{ include system-independent routine headers }
+{$I systemh.inc}
+
+const
+ LineEnding = #13#10;
+ LFNSupport = true;
+ DirectorySeparator = '\';
+ DriveSeparator = ':';
+ ExtensionSeparator = '.';
+ PathSeparator = ';';
+ AllowDirectorySeparators : set of char = ['\'];
+ AllowDriveSeparators : set of char = [];
+
+var
+{ C compatible arguments }
+  argc: LongWord;
+  argvw: PPWideChar;
+  argv: PPChar;
+ 
+const
+{ Default filehandles }
+  UnusedHandle    : THandle = 0;
+  StdInputHandle  : THandle = 0;
+  StdOutputHandle : THandle = 0;
+  StdErrorHandle  : THandle = 0;
+
+{ FileNameCaseSensitive and FileNameCasePreserving are defined separately below!!! }
+ maxExitCode = High(ErrorCode);
+ MaxPathLen = High(Word);
+ AllFilesMask = '*';
+
+const
+  // UEFI is not case sensitive because of defaut FAT32 file system
+  FileNameCaseSensitive : boolean = false;
+  FileNameCasePreserving: boolean = true;
+  // todo: check whether this is really the case on UEFI...
+  CtrlZMarksEOF: boolean = true; (* #26 is considered as end of file *)
+
+  sLineBreak = LineEnding;
+  DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCRLF;
+
+{ Basic EFI definitions }
+
+{$IFDEF FPC}
+{$PACKRECORDS C}
+{$ENDIF}
+
+    const
+      EFI_SYSTEM_TABLE_SIGNATURE = $5453595320494249;      
+
+type
+  EFI_HANDLE = pointer;
+  EFI_EVENT = pointer;
+  EFI_STATUS = Cardinal;
+
+    type
+      EFI_INPUT_KEY = record
+          ScanCode : UINT16;
+          UnicodeChar : WideChar;
+        end;
+
+Type
+    PCHAR16  = ^WideChar;
+    PEFI_INPUT_KEY  = ^EFI_INPUT_KEY;
+    UINTN = Cardinal;
+    PUINTN  = ^UINTN;
+    P_SIMPLE_TEXT_OUTPUT_INTERFACE = ^_SIMPLE_TEXT_OUTPUT_INTERFACE;
+    P_SIMPLE_INPUT_INTERFACE  = ^_SIMPLE_INPUT_INTERFACE;
+
+
+      EFI_TEXT_RESET = function (This:P_SIMPLE_TEXT_OUTPUT_INTERFACE; ExtendedVerification:BOOLEAN):EFI_STATUS;cdecl;
+    {EFIAPI }    {IN }    {IN }
+      EFI_TEXT_OUTPUT_STRING = function (This:P_SIMPLE_TEXT_OUTPUT_INTERFACE; _String:PCHAR16):EFI_STATUS;cdecl;
+    {EFIAPI }    {IN }    {IN }
+      EFI_TEXT_TEST_STRING = function (This:P_SIMPLE_TEXT_OUTPUT_INTERFACE; _String:PCHAR16):EFI_STATUS;cdecl;
+    {EFIAPI }    {IN }    {IN }    {OUT }    {OUT }
+      EFI_TEXT_QUERY_MODE = function (This:P_SIMPLE_TEXT_OUTPUT_INTERFACE; ModeNumber:UINTN; Columns:PUINTN; Rows:PUINTN):EFI_STATUS;cdecl;
+    {EFIAPI }    {IN }    {IN }
+      EFI_TEXT_SET_MODE = function (This:P_SIMPLE_TEXT_OUTPUT_INTERFACE; ModeNumber:UINTN):EFI_STATUS;cdecl;
+    {EFIAPI }    {IN }    {IN }
+      EFI_TEXT_SET_ATTRIBUTE = function (This:P_SIMPLE_TEXT_OUTPUT_INTERFACE; Attribute:UINTN):EFI_STATUS;cdecl;
+
+      EFI_TEXT_CLEAR_SCREEN = function (This:P_SIMPLE_TEXT_OUTPUT_INTERFACE):EFI_STATUS;cdecl;
+    {EFIAPI }    {IN }    {IN }    {IN }
+      EFI_TEXT_SET_CURSOR_POSITION = function (This:P_SIMPLE_TEXT_OUTPUT_INTERFACE; Column:UINTN; Row:UINTN):EFI_STATUS;cdecl;
+    {EFIAPI }    {IN }    {IN }
+      EFI_TEXT_ENABLE_CURSOR = function (This:P_SIMPLE_TEXT_OUTPUT_INTERFACE; Enable:BOOLEAN):EFI_STATUS;cdecl;
+    { current settings }
+
+      SIMPLE_TEXT_OUTPUT_MODE = record
+          MaxMode : INT32;
+          Mode : INT32;
+          Attribute : INT32;
+          CursorColumn : INT32;
+          CursorRow : INT32;
+          CursorVisible : BOOLEAN;
+        end;
+    { Current mode }
+
+      _SIMPLE_TEXT_OUTPUT_INTERFACE = record
+          Reset : EFI_TEXT_RESET;
+          OutputString : EFI_TEXT_OUTPUT_STRING;
+          TestString : EFI_TEXT_TEST_STRING;
+          QueryMode : EFI_TEXT_QUERY_MODE;
+          SetMode : EFI_TEXT_SET_MODE;
+          SetAttribute : EFI_TEXT_SET_ATTRIBUTE;
+          ClearScreen : EFI_TEXT_CLEAR_SCREEN;
+          SetCursorPosition : EFI_TEXT_SET_CURSOR_POSITION;
+          EnableCursor : EFI_TEXT_ENABLE_CURSOR;
+          Mode : ^SIMPLE_TEXT_OUTPUT_MODE;
+        end;
+      SIMPLE_TEXT_OUTPUT_INTERFACE = _SIMPLE_TEXT_OUTPUT_INTERFACE;
+//    P_SIMPLE_TEXT_OUTPUT_INTERFACE  = ^_SIMPLE_TEXT_OUTPUT_INTERFACE;
+
+      EFI_INPUT_RESET = function (This:P_SIMPLE_INPUT_INTERFACE; ExtendedVerification:BOOLEAN):EFI_STATUS;cdecl;
+    {EFIAPI }    {IN }    {OUT }
+      EFI_INPUT_READ_KEY = function (This:P_SIMPLE_INPUT_INTERFACE; Key:PEFI_INPUT_KEY):EFI_STATUS;cdecl;
+
+      _SIMPLE_INPUT_INTERFACE = record
+          Reset : EFI_INPUT_RESET;
+          ReadKeyStroke : EFI_INPUT_READ_KEY;
+          WaitForKey : EFI_EVENT;
+        end;
+      SIMPLE_INPUT_INTERFACE = _SIMPLE_INPUT_INTERFACE;
+
+//    P_SIMPLE_INPUT_INTERFACE  = ^_SIMPLE_INPUT_INTERFACE;
+
+
+    type
+      _EFI_TABLE_HEARDER = record
+          Signature : UINT64;
+          Revision : UINT32;
+          HeaderSize : UINT32;
+          CRC32 : UINT32;
+          Reserved : UINT32;
+        end;
+      EFI_TABLE_HEADER = _EFI_TABLE_HEARDER;
+
+      _EFI_SYSTEM_TABLE = record
+          Hdr : EFI_TABLE_HEADER;
+          FirmwareVendor : ^WideChar;
+          FirmwareRevision : UINT32;
+          ConsoleInHandle : EFI_HANDLE;
+          ConIn : ^SIMPLE_INPUT_INTERFACE;
+          ConsoleOutHandle : EFI_HANDLE;
+          ConOut : ^SIMPLE_TEXT_OUTPUT_INTERFACE;
+          StandardErrorHandle : EFI_HANDLE;
+          StdErr : ^SIMPLE_TEXT_OUTPUT_INTERFACE;
+{          RuntimeServices : ^EFI_RUNTIME_SERVICES;
+          BootServices : ^EFI_BOOT_SERVICES;
+          NumberOfTableEntries : UINTN;
+          ConfigurationTable : ^EFI_CONFIGURATION_TABLE;}
+        end;
+      EFI_SYSTEM_TABLE = _EFI_SYSTEM_TABLE;
+      PEFI_SYSTEM_TABLE = ^EFI_SYSTEM_TABLE;
+
+var
+  SysTable : PEFI_SYSTEM_TABLE;
+  StdOutput : ^SIMPLE_TEXT_OUTPUT_INTERFACE;
+
+implementation
+
+{ include system independent routines }
+{$I system.inc}
+
+function paramcount : longint;
+begin
+  Result := 0;
+end;
+
+function paramstr(l : longint) : string;
+begin
+  Result := '';
+end;
+
+procedure randomize;
+begin
+end;
+
+
+{*****************************************************************************
+                         System Dependent Exit code
+*****************************************************************************}
+
+procedure PascalMain;stdcall;external name 'PASCALMAIN';
+
+Procedure system_exit;
+begin
+end;
+
+procedure SysInitStdIO;
+begin
+end;
+
+function GetProcessID: SizeUInt;
+begin
+  Result := 0;
+end;
+
+function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
+begin
+  result := stklen;
+end;
+
+begin
+end.
Index: rtl/nativent/Makefile.fpc
===================================================================
--- rtl/nativent/Makefile.fpc	(revision 28349)
+++ rtl/nativent/Makefile.fpc	(working copy)
@@ -115,7 +115,7 @@
 uuchar$(PPUEXT): $(SYSTEMUNIT)$(PPUEXT) $(INC)/uuchar.pp
 
 objpas$(PPUEXT): $(OBJPASDIR)/objpas.pp $(INC)/except.inc system$(PPUEXT)
-        $(COMPILER) -I$(OBJPASDIR) $(OBJPASDIR)/objpas.pp
+        $(COMPILER) -Fi$(OBJPASDIR) $(OBJPASDIR)/objpas.pp
 
 macpas$(PPUEXT) : $(INC)/macpas.pp objpas$(PPUEXT) buildrtl$(PPUEXT)
         $(COMPILER) $(INC)/macpas.pp $(REDIR)
Index: rtl/nativent/buildrtl.pp
===================================================================
--- rtl/nativent/buildrtl.pp	(revision 28349)
+++ rtl/nativent/buildrtl.pp	(working copy)
@@ -6,7 +6,7 @@
       ndk, ndkutils, ddk,
       ctypes, strings,
       rtlconsts, sysconst, sysutils, math, types,
-      strutils, typinfo, fgl, classes,
+      typinfo, fgl, classes,
 {$ifdef cpui386}
       mmx, cpu,
 {$endif}
Index: compiler/systems.inc
===================================================================
--- compiler/systems.inc	(revision 28349)
+++ compiler/systems.inc	(working copy)
@@ -162,7 +162,8 @@
              system_i8086_msdos,        { 79 }
              system_mipsel_android,     { 80 }
              system_mipseb_embedded,    { 81 }
-             system_mipsel_embedded     { 82 }
+             system_mipsel_embedded,    { 82 }
+             system_i386_uefi           { 83 } 
        );
 
      type
@@ -241,7 +242,8 @@
              ld_int_linux,
              ld_int_nativent,
              ld_int_netware,
-             ld_int_windows
+             ld_int_windows,
+             ld_int_uefi
        );
 
        tar = (ar_none
Index: compiler/msgtxt.inc
===================================================================
--- compiler/msgtxt.inc	(revision 28349)
+++ compiler/msgtxt.inc	(working copy)
@@ -1535,123 +1535,124 @@
   'P*2Tmorphos_MorphOS'#010+
   'S*2Tsolaris_Solaris'#010+
   'S*2Tlinux_Linux'#010+
-  '**1u<x>_Undefines the ','symbol <x>'#010+
+  '3*2Tuefi_UEFI'#010+
+  '**1u<x>_','Undefines the symbol <x>'#010+
   '**1U_Unit options:'#010+
   '**2Un_Do not check where the unit name matches the file name'#010+
   '**2Ur_Generate release unit files (never automatically recompiled)'#010+
   '**2Us_Compile a system unit'#010+
-  '**1v<x>_Be verbose. <x> is a combination of the follow','ing letters:'#010+
+  '**1v<x>_Be verbose. <x> is a combination',' of the following letters:'#010+
   '**2*_e : Show errors (default)       0 : Show nothing (except errors)'#010+
   '**2*_w : Show warnings               u : Show unit info'#010+
   '**2*_n : Show notes                  t : Show tried/used files'#010+
-  '**2*_h : Show hints                  c',' : Show conditionals'#010+
+  '**2*_h : Show hints     ','             c : Show conditionals'#010+
   '**2*_i : Show general info           d : Show debug info'#010+
   '**2*_l : Show linenumbers            r : Rhide/GCC compatibility mode'#010+
   '**2*_s : Show time stamps            q : Show message numbers'#010+
-  '**2*_a : Show everything      ','       x : Executable info (Win32 only'+
+  '**2*_a : Show ev','erything             x : Executable info (Win32 only'+
   ')'#010+
   '**2*_b : Write file names messages   p : Write tree.log with parse tre'+
   'e'#010+
   '**2*_    with full path              v : Write fpcdebug.txt with'#010+
-  '**2*_                                    lots of debugging info',#010+
+  '**2*_                                    lots of ','debugging info'#010+
   '**2*_m<x>,<y> : Do not show messages numbered <x> and <y>'#010+
   'F*1V<x>_Append '#039'-<x>'#039' to the used compiler binary name (e.g. f'+
   'or version)'#010+
   '**1W<x>_Target-specific options (targets)'#010+
   '3*2WA_Specify native type application (Windows)'#010+
-  '4*2WA_Specify nat','ive type application (Windows)'#010+
+  '4*2','WA_Specify native type application (Windows)'#010+
   'A*2WA_Specify native type application (Windows)'#010+
   '3*2Wb_Create a bundle instead of a library (Darwin)'#010+
   'P*2Wb_Create a bundle instead of a library (Darwin)'#010+
-  'p*2Wb_Create a bundle instead of a library (Darwin)'#010+
-  'A*2Wb','_Create a bundle instead of a library (Darwin)'#010+
+  'p*2Wb_Create a bundle instead of a library ','(Darwin)'#010+
+  'A*2Wb_Create a bundle instead of a library (Darwin)'#010+
   '4*2Wb_Create a bundle instead of a library (Darwin)'#010+
   '3*2WB_Create a relocatable image (Windows, Symbian)'#010+
   '3*2WBxxxx_Set image base to xxxx (Windows, Symbian)'#010+
-  '4*2WB_Create a relocatable image (Win','dows)'#010+
+  '4*2WB_Create a relocata','ble image (Windows)'#010+
   '4*2WBxxxx_Set image base to xxxx (Windows)'#010+
   'A*2WB_Create a relocatable image (Windows, Symbian)'#010+
   'A*2WBxxxx_Set image base to xxxx (Windows, Symbian)'#010+
   '3*2WC_Specify console type application (EMX, OS/2, Windows)'#010+
-  '4*2WC_Specify console type ','application (EMX, OS/2, Windows)'#010+
+  '4*2WC_Specify',' console type application (EMX, OS/2, Windows)'#010+
   'A*2WC_Specify console type application (Windows)'#010+
   'P*2WC_Specify console type application (Classic Mac OS)'#010+
   '3*2WD_Use DEFFILE to export functions of DLL or EXE (Windows)'#010+
-  '4*2WD_Use DEFFILE to export functions of',' DLL or EXE (Windows)'#010+
+  '4*2WD_Use DEFFILE to expor','t functions of DLL or EXE (Windows)'#010+
   'A*2WD_Use DEFFILE to export functions of DLL or EXE (Windows)'#010+
   '3*2We_Use external resources (Darwin)'#010+
   '4*2We_Use external resources (Darwin)'#010+
   'A*2We_Use external resources (Darwin)'#010+
-  'P*2We_Use external resources (Darwin)'#010+
-  'p*2W','e_Use external resources (Darwin)'#010+
+  'P*2We_Use external resources',' (Darwin)'#010+
+  'p*2We_Use external resources (Darwin)'#010+
   '3*2WF_Specify full-screen type application (EMX, OS/2)'#010+
   '3*2WG_Specify graphic type application (EMX, OS/2, Windows)'#010+
   '4*2WG_Specify graphic type application (EMX, OS/2, Windows)'#010+
-  'A*2WG_Specify graphic type appl','ication (Windows)'#010+
+  'A*2WG_Specify gra','phic type application (Windows)'#010+
   'P*2WG_Specify graphic type application (Classic Mac OS)'#010+
   '3*2Wi_Use internal resources (Darwin)'#010+
   '4*2Wi_Use internal resources (Darwin)'#010+
   'A*2Wi_Use internal resources (Darwin)'#010+
-  'P*2Wi_Use internal resources (Darwin)'#010+
-  'p*2Wi_Use inte','rnal resources (Darwin)'#010+
+  'P*2Wi_Use internal resources (Darwin)'#010,
+  'p*2Wi_Use internal resources (Darwin)'#010+
   '3*2WI_Turn on/off the usage of import sections (Windows)'#010+
   '4*2WI_Turn on/off the usage of import sections (Windows)'#010+
   'A*2WI_Turn on/off the usage of import sections (Windows)'#010+
   '8*2Wm<x>_Set memory model'#010+
-  '8*3WmTiny_Tiny memo','ry model'#010+
+  '8*3Wm','Tiny_Tiny memory model'#010+
   '8*3WmSmall_Small memory model (default)'#010+
   '8*3WmMedium_Medium memory model'#010+
   '8*3WmCompact_Compact memory model'#010+
   '8*3WmLarge_Large memory model'#010+
   '3*2WM<x>_Minimum Mac OS X deployment version: 10.4, 10.5.1, ... (Darwi'+
   'n)'#010+
-  '4*2WM<x>_Minimum Mac O','S X deployment version: 10.4, 10.5.1, ... (Dar'+
+  '4*2WM<x>','_Minimum Mac OS X deployment version: 10.4, 10.5.1, ... (Dar'+
   'win)'#010+
   'p*2WM<x>_Minimum Mac OS X deployment version: 10.4, 10.5.1, ... (Darwi'+
   'n)'#010+
   'P*2WM<x>_Minimum Mac OS X deployment version: 10.4, 10.5.1, ... (Darwi'+
   'n)'#010+
-  '3*2WN_Do not generate relocation code, need','ed for debugging (Windows'+
+  '3*2WN_Do not generate relocat','ion code, needed for debugging (Windows'+
   ')'#010+
   '4*2WN_Do not generate relocation code, needed for debugging (Windows)'#010+
   'A*2WN_Do not generate relocation code, needed for debugging (Windows)'#010+
-  'A*2Wpxxxx_Specify the controller type, see fpc -i for possible values'#010+
-  'V*2','Wpxxxx_Specify the controller type, see fpc -i for possible value'+
+  'A*2Wpxxxx_Specify the controller type, see fpc -i for possi','ble value'+
   's'#010+
+  'V*2Wpxxxx_Specify the controller type, see fpc -i for possible values'#010+
   '3*2WP<x>_Minimum iOS deployment version: 3.0, 5.0.1, ... (iphonesim)'#010+
   'A*2WP<x>_Minimum iOS deployment version: 3.0, 5.0.1, ... (Darwin)'#010+
-  '3*2WR_Generate relocation code (Window','s)'#010+
+  '3*2WR_Generate relocatio','n code (Windows)'#010+
   '4*2WR_Generate relocation code (Windows)'#010+
   'A*2WR_Generate relocation code (Windows)'#010+
   '8*2Wt<x>_Set the target executable format'#010+
   '8*3Wtexe_Create a DOS .EXE file (default)'#010+
-  '8*3Wtcom_Create a DOS .COM file (requires tiny memory model)'#010+
-  'P*2WT_Spec','ify MPW tool type application (Classic Mac OS)'#010+
+  '8*3Wtcom_Create a DOS .COM file (requires tiny memory mod','el)'#010+
+  'P*2WT_Specify MPW tool type application (Classic Mac OS)'#010+
   '**2WX_Enable executable stack (Linux)'#010+
   '**1X_Executable options:'#010+
   '**2Xc_Pass --shared/-dynamic to the linker (BeOS, Darwin, FreeBSD, Lin'+
   'ux)'#010+
-  '**2Xd_Do not search default library path (sometimes requ','ired for cro'+
+  '**2Xd_Do not search default library path (','sometimes required for cro'+
   'ss-compiling when not using -XR)'#010+
   '**2Xe_Use external linker'#010+
   '**2Xg_Create debuginfo in a separate file and add a debuglink section '+
   'to executable'#010+
   '**2XD_Try to link units dynamically      (defines FPC_LINK_DYNAMIC)'#010+
-  '**2Xi_Use interna','l linker'#010+
+  '**2','Xi_Use internal linker'#010+
   '**2Xm_Generate link map'#010+
   '**2XM<x>_Set the name of the '#039'main'#039' program routine (default i'+
   's '#039'main'#039')'#010+
   'F*2Xp<x>_First search for the compiler binary in the directory <x>'#010+
-  '**2XP<x>_Prepend the binutils names with the prefix <x>'#010+
-  '**2Xr<x>_Set',' the linker'#039's rlink-path to <x> (needed for cross co'+
-  'mpile, see the ld manual for more information) (BeOS, Linux)'#010+
+  '**2XP<x>_Prepend the binutils names with the prefix <x','>'#010+
+  '**2Xr<x>_Set the linker'#039's rlink-path to <x> (needed for cross comp'+
+  'ile, see the ld manual for more information) (BeOS, Linux)'#010+
   '**2XR<x>_Prepend <x> to all linker search paths (BeOS, Darwin, FreeBSD'+
   ', Linux, Mac OS, Solaris)'#010+
-  '**2Xs_Strip all symbols from ex','ecutable'#010+
+  '**2Xs_Strip all s','ymbols from executable'#010+
   '**2XS_Try to link units statically (default, defines FPC_LINK_STATIC)'#010+
   '**2Xt_Link with static libraries (-static is passed to linker)'#010+
   '**2XX_Try to smartlink units             (defines FPC_LINK_SMART)'#010+
   '**1*_'#010+
-  '**1?_Show this help'#010+
-  '**1h_S','hows this help without waiting'
+  '**1?_Show th','is help'#010+
+  '**1h_Shows this help without waiting'
 );
Index: compiler/i386/cputarg.pas
===================================================================
--- compiler/i386/cputarg.pas	(revision 28349)
+++ compiler/i386/cputarg.pas	(working copy)
@@ -86,6 +86,9 @@
     {$ifndef NOTARGETEMBEDDED}
       ,t_embed
     {$endif}
+    {$ifndef NOTTARGETUEFI}
+      ,t_uefi
+    {$endif NOTTARGETUEFI}
 
 {**************************************
              Assemblers
Index: compiler/msgidx.inc
===================================================================
--- compiler/msgidx.inc	(revision 28349)
+++ compiler/msgidx.inc	(working copy)
@@ -994,7 +994,7 @@
   option_info=11024;
   option_help_pages=11025;
 
-  MsgTxtSize = 72030;
+  MsgTxtSize = 72044;
 
   MsgIdxMax : array[1..20] of longint=(
     26,99,339,123,89,57,126,27,202,64,
Index: compiler/systems/t_uefi.pas
===================================================================
--- compiler/systems/t_uefi.pas	(revision 0)
+++ compiler/systems/t_uefi.pas	(revision 0)
@@ -0,0 +1,94 @@
+{
+    Copyright (c) 2014 by Olivier Coursière
+
+    This unit implements support import,export,link routines
+    for the uefi Target
+    Based on Sven Barth's t_nativent
+
+    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_uefi;
+
+{$i fpcdefs.inc}
+
+interface
+
+
+implementation
+
+  uses
+    SysUtils,
+    cutils,
+    ogbase,ogcoff,
+    globtype,globals,systems,verbose,
+    import,export,link,t_win,i_uefi;
+
+
+    type
+      TImportLibUEFI=class(TImportLibWin)
+      end;
+
+      TExportLibUEFI=class(TExportLibWin)
+      end;
+
+      TInternalLinkerUEFI = class(TInternalLinkerWin)
+        constructor create;override;
+        procedure ConcatEntryName; override;
+      end;
+
+{****************************************************************************
+                            TInternalLinkerUEFI
+****************************************************************************}
+
+    constructor TInternalLinkerUEFI.create;
+      begin
+        inherited create;
+        CExeoutput:=TPECoffexeoutput;
+        CObjInput:=TPECoffObjInput;
+      end;
+
+    procedure TInternalLinkerUEFI.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 EFI_MAIN')
+                else
+                  Concat('ENTRYNAME EFI_MAIN')
+              end
+                else
+                  Concat('ENTRYNAME PASCALMAIN');
+          end;
+      end;
+
+
+
+{*****************************************************************************
+                                     Initialize
+*****************************************************************************}
+
+initialization
+{$ifdef i386}
+  { UEFI }
+  RegisterLinker(ld_int_uefi,TInternalLinkerUEFI);
+  RegisterImport(system_i386_uefi,TImportLibUEFI);
+  RegisterExport(system_i386_uefi,TExportLibUEFI);
+  RegisterTarget(system_i386_uefi_info);
+{$endif i386}
+end.
Index: compiler/systems/t_win.pas
===================================================================
--- compiler/systems/t_win.pas	(revision 28349)
+++ compiler/systems/t_win.pas	(working copy)
@@ -1677,6 +1677,17 @@
         { wincegui=9 }
         if target_info.system in systems_wince then
           peoptheader.Subsystem:=9
+        else if target_info.system in [system_i386_uefi] then
+          begin
+        	case apptype of
+        	  app_efi_app :
+        	    peoptheader.Subsystem:=10;
+        	  app_efi_boot :
+        	    peoptheader.Subsystem:=11;
+        	  app_efi_run :
+        	    peoptheader.Subsystem:=12;
+        	end;
+          end
         else
           case apptype of
             app_native :
Index: compiler/systems/i_uefi.pas
===================================================================
--- compiler/systems/i_uefi.pas	(revision 0)
+++ compiler/systems/i_uefi.pas	(revision 0)
@@ -0,0 +1,107 @@
+{
+    Copyright (c) 2014 by Olivier Coursière
+
+    This unit implements support information structures for uefi,
+    Based on Sven Barth's i_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 uefi. }
+unit i_uefi;
+
+{$i fpcdefs.inc}
+
+  interface
+
+    uses
+       systems;
+
+    const
+       system_i386_uefi_info : tsysteminfo =
+          (
+            system       : system_i386_UEFI;
+            name         : 'UEFI for i386';
+            shortname    : 'UEFI';
+            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_generic_stackcheck{,tf_has_winlike_resources},tf_under_development,
+                            tf_dwarf_only_local_labels{,tf_pic_uses_got}];
+            cpu          : cpu_i386;
+            unit_env     : 'UEFIUNITS';
+            extradefines : 'UEFI,FPC_OS_UNICODE';
+            exeext       : '.exe';
+            defext       : '.def';
+            scriptext    : '.bat';
+            smartext     : '.sl';
+            unitext      : '.ppu';
+            unitlibext   : '.ppl';
+            asmext       : '.s';
+            objext       : '.o';
+            resext       : '.res';
+            resobjext    : '.or';
+            sharedlibext : '.efi';
+            staticlibext : '.a';
+            staticlibprefix : 'libp';
+            sharedlibprefix : '';
+            sharedClibext : '.efi';
+            staticClibext : '.a';
+            staticClibprefix : 'lib';
+            sharedClibprefix : '';
+            importlibprefix : 'libimp';
+            importlibext : '.a';
+            Cprefix      : '_';
+            newline      : #13#10;
+            dirsep       : '\';
+            assem        : as_i386_pecoff;
+            assemextern  : as_gas;
+            link         : ld_int_uefi;
+            linkextern   : ld_none;
+            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;
+            stackalign   : 4;
+            abi          : abi_default;
+          );
+
+  implementation
+  
+initialization
+{$ifdef CPUI386}
+  {$ifdef UEFI}
+    set_source_info(system_i386_uefi_info);
+  {$endif UEFI}
+{$endif CPUI386}
+end.
Index: compiler/msg/errore.msg
===================================================================
--- compiler/msg/errore.msg	(revision 28349)
+++ compiler/msg/errore.msg	(working copy)
@@ -3661,6 +3661,7 @@
 P*2Tmorphos_MorphOS
 S*2Tsolaris_Solaris
 S*2Tlinux_Linux
+3*2Tuefi_UEFI
 **1u<x>_Undefines the symbol <x>
 **1U_Unit options:
 **2Un_Do not check where the unit name matches the file name
Index: compiler/utils/ppuutils/ppudump.pp
===================================================================
--- compiler/utils/ppuutils/ppudump.pp	(revision 28349)
+++ compiler/utils/ppuutils/ppudump.pp	(working copy)
@@ -164,7 +164,8 @@
   { 79 }  'MSDOS-i8086',
   { 80 }  'Android-MIPSel',
   { 81 }  'Embedded-mipseb',
-  { 82 }  'Embedded-mipsel'
+  { 82 }  'Embedded-mipsel',
+  { 83 }  'UEFI'
   );
 
 const
Index: compiler/globtype.pas
===================================================================
--- compiler/globtype.pas	(revision 28349)
+++ compiler/globtype.pas	(working copy)
@@ -420,7 +420,11 @@
          app_arm7,      { for Nintendo DS target }
          app_arm9,      { for Nintendo DS target }
          app_bundle,    { dynamically loadable bundle, Darwin only }
-         app_com        { DOS .COM file }
+         app_com,       { DOS .COM file }
+         app_efi_app,   { EFI application (UEFI target) }
+         app_efi_boot,  { EFI boot driver (UEFI target) }
+         app_efi_run,   { EFI runtime driver (UEFI target) }
+         app_efi_rom    { EFI ROM (UEFI target) }
        );
 
        { interface types }
Index: compiler/options.pas
===================================================================
--- compiler/options.pas	(revision 28349)
+++ compiler/options.pas	(working copy)
@@ -1802,6 +1802,10 @@
                             else
                               SetApptype(app_native);
                           end
+                        else if target_info.system in [system_i386_uefi] then
+                          begin
+                            SetApptype(app_efi_app);
+                          end
                         else
                           IllegalPara(opt);
                       end;
Index: compiler/compiler.pas
===================================================================
--- compiler/compiler.pas	(revision 28349)
+++ compiler/compiler.pas	(working copy)
@@ -126,6 +126,9 @@
 {$ifdef aix}
   ,i_aix
 {$endif aix}
+{$ifdef uefi}
+  ,i_uefi
+{$endif uefi}
   ,globtype;
 
 function Compile(const cmd:TCmdStr):longint;
Index: compiler/ogcoff.pas
===================================================================
--- compiler/ogcoff.pas	(revision 28349)
+++ compiler/ogcoff.pas	(working copy)
@@ -319,6 +319,9 @@
        PE_SUBSYSTEM_WINDOWS_GUI    = 2;
        PE_SUBSYSTEM_WINDOWS_CUI    = 3;
        PE_SUBSYSTEM_WINDOWS_CE_GUI = 9;
+       PE_SUBSYSTEM_EFI_APP        = 10;
+       PE_SUBSYSTEM_EFI_BOOT       = 11;
+       PE_SUBSYSTEM_EFI_RUN        = 12;
 
        PE_FILE_RELOCS_STRIPPED         = $0001;
        PE_FILE_EXECUTABLE_IMAGE        = $0002;
@@ -2353,6 +2356,17 @@
             else
               if target_info.system in systems_wince then
                 peoptheader.Subsystem:=PE_SUBSYSTEM_WINDOWS_CE_GUI
+              else if target_info.system in [system_i386_uefi] then
+                begin
+                  case apptype of
+                    app_efi_app :
+        	          peoptheader.Subsystem:=PE_SUBSYSTEM_EFI_APP;
+        	        app_efi_boot :
+            	      peoptheader.Subsystem:=PE_SUBSYSTEM_EFI_BOOT;
+            	    app_efi_run :
+            	      peoptheader.Subsystem:=PE_SUBSYSTEM_EFI_RUN;
+        	      end;                
+                end
               else
                 if apptype=app_gui then
                   peoptheader.Subsystem:=PE_SUBSYSTEM_WINDOWS_GUI
@@ -2982,7 +2996,7 @@
             idtxt  : 'PECOFF';
             asmbin : '';
             asmcmd : '';
-            supported_targets : [system_i386_win32,system_i386_nativent];
+            supported_targets : [system_i386_win32,system_i386_nativent,system_i386_uefi];
             flags : [af_outputbinary,af_smartlink_sections];
             labelprefix : '.L';
             comment : '';
