Browse Source

+ Declare UEFI target in the compiler

git-svn-id: branches/olivier/uefi@36054 -
olivier 8 years ago
parent
commit
e89f532467

+ 2 - 0
.gitattributes

@@ -731,6 +731,7 @@ compiler/systems/i_os2.pas svneol=native#text/plain
 compiler/systems/i_palmos.pas svneol=native#text/plain
 compiler/systems/i_sunos.pas svneol=native#text/plain
 compiler/systems/i_symbian.pas svneol=native#text/plain
+compiler/systems/i_uefi.pas svneol=native#text/plain
 compiler/systems/i_watcom.pas svneol=native#text/plain
 compiler/systems/i_wdosx.pas svneol=native#text/plain
 compiler/systems/i_wii.pas svneol=native#text/plain
@@ -762,6 +763,7 @@ compiler/systems/t_os2.pas svneol=native#text/plain
 compiler/systems/t_palmos.pas svneol=native#text/plain
 compiler/systems/t_sunos.pas svneol=native#text/plain
 compiler/systems/t_symbian.pas svneol=native#text/plain
+compiler/systems/t_uefi.pas svneol=native#text/plain
 compiler/systems/t_watcom.pas svneol=native#text/plain
 compiler/systems/t_wdosx.pas svneol=native#text/plain
 compiler/systems/t_wii.pas svneol=native#text/plain

+ 3 - 0
compiler/compiler.pas

@@ -132,6 +132,9 @@ uses
 {$ifdef aix}
   ,i_aix
 {$endif aix}
+{$ifdef uefi}
+  ,i_uefi
+{$endif uefi}
   ,globtype;
 
 function Compile(const cmd:TCmdStr):longint;

+ 3 - 0
compiler/i386/cputarg.pas

@@ -89,6 +89,9 @@ implementation
     {$ifndef NOTARGETAROS}
       ,t_aros
     {$endif}
+    {$ifndef NOTTARGETUEFI}
+      ,t_uefi
+    {$endif NOTTARGETUEFI}
 
 {**************************************
              Assemblers

+ 1 - 0
compiler/msg/errore.msg

@@ -3955,6 +3955,7 @@ p*2Tlinux_Linux
 S*2Tsolaris_Solaris
 S*2Tlinux_Linux
 V*2Tembedded_Embedded
+3*2Tuefi_UEFI
 **1u<x>_Undefines the symbol <x>
 **1U_Unit options:
 **2Un_Do not check where the unit name matches the file name

+ 1 - 1
compiler/ogcoff.pas

@@ -3217,7 +3217,7 @@ const pemagic : array[0..3] of byte = (
             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 : '';

+ 4 - 2
compiler/systems.inc

@@ -175,7 +175,8 @@
              system_i8086_win16,        { 89 }
              system_i8086_embedded,     { 90 }
              system_arm_aros,           { 91 }
-             system_wasm_wasm32         { 92 }
+             system_wasm_wasm32,        { 92 }
+             system_i386_uefi           { 93 }
        );
 
      type
@@ -265,7 +266,8 @@
              ld_int_nativent,
              ld_int_netware,
              ld_int_windows,
-             ld_int_msdos
+             ld_int_msdos,
+             ld_int_uefi
        );
 
        tar = (ar_none

+ 189 - 0
compiler/systems/i_uefi.pas

@@ -0,0 +1,189 @@
+{
+    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       : '.efi';
+            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   : 16;
+            abi          : abi_default;
+            { note: default LLVM stack alignment is 16 bytes for this target }
+            { TODO : check this... Took from Haiku, but should probably come from Windows ? }
+            llvmdatalayout : 'e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S32';
+          );
+
+(*       system_x64_uefi64_info : tsysteminfo =
+          (
+            system       : system_x86_64_uefi64;
+            name         : 'UEFI for x86_64';
+            shortname    : 'uefi64';
+            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_x86_64;
+            unit_env     : 'UEFIUNITS';
+            extradefines : 'UEFI64,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_x86_64_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       : 8;
+                jumpalign       : 0;
+                constalignmin   : 0;
+                constalignmax   : 16;
+                varalignmin     : 0;
+                varalignmax     : 16;
+                localalignmin   : 8;
+                localalignmax   : 16;
+                recordalignmin  : 0;
+                recordalignmax  : 8;
+                maxCrecordalign : 16
+              );
+            first_parm_offset : 16;
+            stacksize    : 16*1024*1024;
+            stackalign   : 16;
+            abi          : abi_default;
+            { note: default LLVM stack alignment is 16 bytes for this target }
+            { TODO : check this... Took from Haiku, but should probably come from Windows ? }
+            llvmdatalayout : 'e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S32';
+          );*)
+
+  implementation
+  
+initialization
+{$ifdef CPUI386}
+//  WriteLn('CPUI386 defined');
+  {$ifdef UEFI}
+//    WriteLn('UEFI defined');
+    set_source_info(system_i386_uefi_info);
+  {$endif UEFI}
+{$endif CPUI386}
+{$ifdef CPUX86_64}
+{ $ifdef x86_64}
+//  WriteLn('CPUX86_64 defined');
+  {$ifdef UEFI64}
+//    WriteLn('UEFI64 defined');
+    set_source_info(system_x64_uefi64_info);
+  {$endif UEFI}
+{$endif CPUX86_64}
+
+end.

+ 104 - 0
compiler/systems/t_uefi.pas

@@ -0,0 +1,104 @@
+{
+    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
+  RegisterLinker(ld_int_uefi,TInternalLinkerUEFI);
+{$ifdef i386}
+  { UEFI }
+//  WriteLn('32 UEFI');
+  RegisterImport(system_i386_uefi,TImportLibUEFI);
+  RegisterExport(system_i386_uefi,TExportLibUEFI);
+  RegisterTarget(system_i386_uefi_info);
+{$endif i386}
+{$ifdef x86_64}
+{ $ifdef UEFI64}
+  { UEFI }
+//  WriteLn('64 UEFI');
+  RegisterImport(system_x86_64_uefi64,TImportLibUEFI);
+  RegisterExport(system_x86_64_uefi64,TExportLibUEFI);
+  RegisterTarget(system_x64_uefi64_info);
+{ $endif}
+{$endif x86_64}
+end.

+ 2 - 1
compiler/utils/ppuutils/ppudump.pp

@@ -177,7 +177,8 @@ const
   { 89 }  'Win16',
   { 90 }  'Embedded-i8086',
   { 91 }  'AROS-arm',
-  { 92 }  'WebAssembly-wasm'
+  { 92 }  'WebAssembly-wasm',
+  { 93 }  'UEFI-i386'
   );
 
 const