Pārlūkot izejas kodu

Add loongarch64 linux support to compiler

Jinyang He 2 gadi atpakaļ
vecāks
revīzija
3d2c96ebbf

+ 1 - 1
compiler/loongarch64/agcpugas.pas

@@ -203,7 +203,7 @@ unit agcpugas;
          idtxt  : 'AS';
          asmbin : 'as';
          asmcmd : '-o $OBJ $EXTRAOPT -mabi=lp64d $ASM';
-         supported_targets : [];
+         supported_targets : [system_loongarch64_linux];
          flags : [af_needar,af_smartlink_sections];
          labelprefix : '.L';
          labelmaxlen : -1;

+ 2 - 1
compiler/systems.inc

@@ -211,7 +211,8 @@
              system_aarch64_embedded,   { 116 }
              system_mips64_linux,       { 117 }
              system_mips64el_linux,     { 118 }
-             system_riscv32_freertos    { 119 }
+             system_riscv32_freertos,   { 119 }
+             system_loongarch64_linux   { 120 }
        );
 
      type

+ 6 - 2
compiler/systems.pas

@@ -262,7 +262,7 @@ interface
        systems_linux = [system_i386_linux,system_x86_64_linux,system_powerpc_linux,system_powerpc64_linux,
                        system_arm_linux,system_sparc_linux,system_sparc64_linux,system_m68k_linux,
                        system_x86_6432_linux,system_mipseb_linux,system_mipsel_linux,system_aarch64_linux,
-                       system_riscv32_linux,system_riscv64_linux,system_xtensa_linux];
+                       system_riscv32_linux,system_riscv64_linux,system_xtensa_linux,system_loongarch64_linux];
        systems_dragonfly = [system_x86_64_dragonfly];
        systems_freebsd = [system_aarch64_freebsd,
                           system_i386_freebsd,
@@ -398,7 +398,7 @@ interface
                                    system_riscv32_linux,system_riscv64_linux,
                                    system_aarch64_win64,
                                    system_z80_zxspectrum,system_z80_msxdos,
-                                   system_wasm32_wasi
+                                   system_wasm32_wasi,system_loongarch64_linux
                                   ]+systems_darwin+systems_amigalike;
 
        { all systems that use the PE+ header in the PE/COFF file
@@ -1204,6 +1204,10 @@ begin
 {$ifdef mips64el}
   default_target(system_mips64el_linux);
 {$endif mips64el}
+
+{$ifdef loongarch64}
+  default_target(system_loongarch64_linux);
+{$endif loongarch64}
 end;
 
 

+ 77 - 0
compiler/systems/i_linux.pas

@@ -1455,6 +1455,78 @@ unit i_linux;
             llvmdatalayout : 'e-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32-S64';
           );
 
+       system_loongarch64_linux_info : tsysteminfo =
+          (
+            system       : system_loongarch64_linux;
+            name         : 'Linux for LoongArch64';
+            shortname    : 'Linux';
+            flags        : [tf_needs_symbol_size,tf_library_needs_pic,tf_smartlink_sections,tf_needs_dwarf_cfi,
+                            tf_needs_symbol_type,tf_files_case_sensitive,
+                            tf_requires_proper_alignment,tf_has_winlike_resources,
+                            tf_supports_hidden_symbols,
+                            tf_safecall_exceptions
+                            ];
+            cpu          : cpu_loongarch64;
+            unit_env     : 'LINUXUNITS';
+            extradefines : 'UNIX;HASUNIX';
+            exeext       : '';
+            defext       : '.def';
+            scriptext    : '.sh';
+            smartext     : '.sl';
+            unitext      : '.ppu';
+            unitlibext   : '.ppl';
+            asmext       : '.s';
+            objext       : '.o';
+            resext       : '.res';
+            resobjext    : '.or';
+            sharedlibext : '.so';
+            staticlibext : '.a';
+            staticlibprefix : 'libp';
+            sharedlibprefix : 'lib';
+            sharedClibext : '.so';
+            staticClibext : '.a';
+            staticClibprefix : 'lib';
+            sharedClibprefix : 'lib';
+            importlibprefix : 'libimp';
+            importlibext : '.a';
+//            p_ext_support : false;
+            Cprefix      : '';
+            newline      : #10;
+            dirsep       : '/';
+            assem        : as_gas;
+            assemextern  : as_gas;
+            link         : ld_none;
+            linkextern   : ld_linux;
+            ar           : ar_gnu_ar;
+            res          : res_elf;
+            dbg          : dbg_dwarf3;
+            script       : script_unix;
+            endian       : endian_little;
+            alignment    :
+              (
+                procalign       : 8;
+                loopalign       : 4;
+                jumpalign       : 0;
+                jumpalignskipmax    : 0;
+                coalescealign   : 0;
+                coalescealignskipmax: 0;
+                constalignmin   : 4;
+                constalignmax   : 16;
+                varalignmin     : 4;
+                varalignmax     : 16;
+                localalignmin   : 8;
+                localalignmax   : 16;
+                recordalignmin  : 0;
+                recordalignmax  : 16;
+                maxCrecordalign : 16
+              );
+            first_parm_offset : 16;
+            stacksize    : 8*1024*1024;
+            stackalign   : 16;
+            abi : abi_default;
+            llvmdatalayout : 'E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f128:64:64-v128:128:128-n32:64';
+          );
+
   implementation
 
 initialization
@@ -1546,5 +1618,10 @@ initialization
     set_source_info(system_mips64el_linux_info);
   {$endif linux}
 {$endif CPUMIPS64EL}
+{$ifdef CPULOONGARCH64}
+  {$ifdef linux}
+    set_source_info(system_loongarch64_linux_info);
+  {$endif linux}
+{$endif CPULOONGARCH64}
 end.
 

+ 12 - 0
compiler/systems/t_linux.pas

@@ -210,6 +210,9 @@ begin
       LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib/riscv64-linux-gnu',true);
       LibrarySearchPath.AddLibraryPath(sysrootpath,'=/lib/riscv64-linux-gnu',true);
 {$endif riscv64}
+{$ifdef loongarch64}
+      LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib/loongarch64-linux-gnu',true);
+{$endif loongarch64}
     end;
 end;
 
@@ -275,6 +278,9 @@ const defdynlinker='/lib/ld-linux-aarch64.so.1';
   const defdynlinker='/lib/ld.so.1';
 {$endif xtensa}
 
+{$ifdef loongarch64}
+  const defdynlinker='/usr/lib64/ld-linux-loongarch-lp64d.so.1';
+{$endif loongarch64}
 
 procedure SetupDynlinker(out DynamicLinker:string;out libctype:TLibcType);
 begin
@@ -383,6 +389,7 @@ const
 {$ifdef riscv32}   platform_select='-m elf32lriscv';{$endif}
 {$ifdef riscv64}   platform_select='-m elf64lriscv';{$endif}
 {$ifdef xtensa}    platform_select='';{$endif}
+{$ifdef loongarch64}   platform_select='';{$endif}
 
 var
   platformopt: string;
@@ -1367,6 +1374,11 @@ initialization
   RegisterExport(system_xtensa_linux,texportliblinux);
   RegisterTarget(system_xtensa_linux_info);
 {$endif xtensa}
+{$ifdef loongarch64}
+  RegisterImport(system_loongarch64_linux,timportliblinux);
+  RegisterExport(system_loongarch64_linux,texportliblinux);
+  RegisterTarget(system_loongarch64_linux_info);
+{$endif loongarch64}
   RegisterRes(res_elf_info,TWinLikeResourceFile);
 end.
 

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

@@ -245,7 +245,8 @@ const
   { 116 } 'Embedded-aarch64',
   { 117 } 'Linux-MIPS64',
   { 118 } 'Linux-MIPS64el',
-  { 119 } 'FreeRTos-RiscV32'
+  { 119 } 'FreeRTos-RiscV32',
+  { 120 } 'Linux-LoongArch64'
   );
 
 const