Browse Source

* synchronized with trunk

git-svn-id: branches/z80@44623 -
nickysn 5 years ago
parent
commit
692ec2fcba

+ 3 - 0
.gitattributes

@@ -11216,6 +11216,9 @@ rtl/linux/x86_64/stat.inc svneol=native#text/plain
 rtl/linux/x86_64/syscall.inc svneol=native#text/plain
 rtl/linux/x86_64/syscallh.inc svneol=native#text/plain
 rtl/linux/x86_64/sysnr.inc svneol=native#text/plain
+rtl/linux/xtensa/sighndh.inc svneol=native#text/plain
+rtl/linux/xtensa/stat.inc svneol=native#text/plain
+rtl/linux/xtensa/syscallh.inc svneol=native#text/plain
 rtl/m68k/cpuh.inc svneol=native#text/plain
 rtl/m68k/int64p.inc svneol=native#text/plain
 rtl/m68k/lowmath.inc svneol=native#text/plain

+ 4 - 0
compiler/ncnv.pas

@@ -3529,7 +3529,11 @@ implementation
             (left.resultdef.size=resultdef.size) and
             (left.expectloc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CREGISTER]) then
            begin
+{$ifdef xtensa}
+             expectloc:=LOC_REGISTER;
+{$else xtensa}
              expectloc:=left.expectloc;
+{$endif xtensa}
              exit;
            end;
          { when converting 64bit int to C-ctyle boolean, first convert to an int32 and then }

+ 4 - 4
compiler/nmat.pas

@@ -1317,12 +1317,12 @@ implementation
            begin
              if (expectloc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CREGISTER]) then
                expectloc:=LOC_REGISTER;
-            { before loading it into flags we need to load it into
-              a register thus 1 register is need PM }
-{$ifdef cpuflags}
+             { xtensa has boolean registers which are treateed as flags but they
+               are not used for boolean expressions }
+{$if defined(cpuflags) and not(defined(xtensa))}
              if left.expectloc<>LOC_JUMP then
                expectloc:=LOC_FLAGS;
-{$endif def cpuflags}
+{$endif defined(cpuflags) and not(defined(xtensa)}
            end
          else
 {$ifdef SUPPORT_MMX}

+ 2 - 1
compiler/systems.inc

@@ -194,7 +194,8 @@
              system_x86_64_haiku,       { 102 }
              system_xtensa_embedded,    { 103 }
              system_xtensa_freertos,    { 104 }
-             system_z80_embedded        { 105 }
+             system_xtensa_linux,       { 105 }
+             system_z80_embedded        { 106 }
        );
 
      type

+ 1 - 1
compiler/systems.pas

@@ -257,7 +257,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_riscv32_linux,system_riscv64_linux,system_xtensa_linux];
        systems_dragonfly = [system_x86_64_dragonfly];
        systems_freebsd = [system_i386_freebsd,
                           system_x86_64_freebsd];

+ 76 - 0
compiler/systems/i_linux.pas

@@ -1243,6 +1243,76 @@ unit i_linux;
             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';
           );
 
+       system_xtensa_linux_info : tsysteminfo =
+          (
+            system       : system_xtensa_linux;
+            name         : 'Linux for Xtensa';
+            shortname    : 'Linux';
+            flags        : [tf_needs_symbol_size,tf_smartlink_sections,
+                            tf_needs_symbol_type,tf_files_case_sensitive,
+                            tf_requires_proper_alignment,tf_has_winlike_resources,
+                            tf_supports_hidden_symbols];
+            cpu          : cpu_xtensa;
+            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_dwarf2;
+            script       : script_unix;
+            endian       : endian_little;
+            alignment    :
+              (
+                procalign       : 4;
+                loopalign       : 4;
+                jumpalign       : 0;
+                jumpalignskipmax    : 0;
+                coalescealign   : 0;
+                coalescealignskipmax: 0;
+                constalignmin   : 0;
+                constalignmax   : 8;
+                varalignmin     : 0;
+                varalignmax     : 8;
+                localalignmin   : 4;
+                localalignmax   : 16;
+                recordalignmin  : 0;
+                recordalignmax  : 8;
+                maxCrecordalign : 8
+              );
+            first_parm_offset : 0;
+            stacksize    : 32*1024*1024;
+            stackalign   : 16;
+            abi : abi_xtensa_windowed;
+            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';
+          );
+
   implementation
 
 initialization
@@ -1319,4 +1389,10 @@ initialization
     set_source_info(system_riscv64_linux_info);
   {$endif linux}
 {$endif CPURISCV64}
+{$ifdef CPUXTENSA}
+  {$ifdef linux}
+    set_source_info(system_xtensa_linux_info);
+  {$endif linux}
+{$endif CPUXTENSA}
 end.
+

+ 12 - 0
compiler/systems/t_linux.pas

@@ -253,10 +253,15 @@ const defdynlinker='/lib/ld-linux-aarch64.so.1';
 {$ifdef riscv32}
   const defdynlinker='/lib32/ld.so.1';
 {$endif riscv32}
+
 {$ifdef riscv64}
   const defdynlinker='/lib/ld-linux-riscv64-lp64d.so.1';
 {$endif riscv64}
 
+{$ifdef xtensa}
+  const defdynlinker='/lib/ld.so.1';
+{$endif xtensa}
+
 
 procedure SetupDynlinker(out DynamicLinker:string;out libctype:TLibcType);
 begin
@@ -363,6 +368,7 @@ const
 {$endif}
 {$ifdef riscv32}   platform_select='-m elf32lriscv';{$endif}
 {$ifdef riscv64}   platform_select='-m elf64lriscv';{$endif}
+{$ifdef xtensa}    platform_select='';{$endif}
 
 var
   platformopt: string;
@@ -2029,5 +2035,11 @@ initialization
   RegisterExport(system_riscv64_linux,texportliblinux);
   RegisterTarget(system_riscv64_linux_info);
 {$endif riscv64}
+{$ifdef xtensa}
+  RegisterImport(system_xtensa_linux,timportliblinux);
+  RegisterExport(system_xtensa_linux,texportliblinux);
+  RegisterTarget(system_xtensa_linux_info);
+{$endif xtensa}
   RegisterRes(res_elf_info,TWinLikeResourceFile);
 end.
+

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

@@ -225,7 +225,8 @@ const
   { 102 } 'Haiku-x86-64',
   { 103 } 'Embedded-Xtensa',
   { 104 } 'FreeRTos-Xtensa',
-  { 105 } 'Embedded-Z80'
+  { 105 } 'Linux-Xtensa',
+  { 106 } 'Embedded-Z80'
   );
 
 const

+ 2 - 0
compiler/xtensa/cgcpu.pas

@@ -470,6 +470,8 @@ implementation
           a_op_const_reg_reg(list,OP_SHL,size,l1,src,dst)
         else if (op=OP_ADD) and (a>=-128) and (a<=127) then
           list.concat(taicpu.op_reg_reg_const(A_ADDI,dst,src,a))
+        else if (op=OP_SUB) and (a>=-127) and (a<=128) then
+          list.concat(taicpu.op_reg_reg_const(A_ADDI,dst,src,-a))
         else if (op=OP_SHL) and (a>=1) and (a<=31) then
           list.concat(taicpu.op_reg_reg_const(A_SLLI,dst,src,a))
         else if (op=OP_SHR) and (a>=0) and (a<=15) then

+ 9 - 1
compiler/xtensa/cputarg.pas

@@ -36,7 +36,15 @@ implementation
 **************************************}
 
     {$ifndef NOTARGETEMBEDDED}
-      ,t_embed,t_freertos
+      ,t_embed
+    {$endif}
+
+    {$ifndef NOTARGETFREERTOS}
+      ,t_freertos
+    {$endif}
+
+    {$ifndef NOTARGETLINUX}
+      ,t_linux
     {$endif}
 
 {**************************************

+ 47 - 0
compiler/xtensa/hlcgcpu.pas

@@ -48,6 +48,7 @@ implementation
     aasmbase,aasmtai,
     symconst,symsym,defutil,
     cpubase,aasmcpu,parabase,
+    procinfo,
     cgobj,cgcpu;
 
   procedure create_hlcodegen_cpu;
@@ -59,7 +60,53 @@ implementation
 
   procedure thlcgxtensa.g_intf_wrapper(list : TAsmList; procdef : tprocdef;
    const labelname : string; ioffset : longint);
+    var
+      make_global : boolean;
+      tmpref : treference;
+      l : TAsmLabel;
     begin
+      if not(procdef.proctypeoption in [potype_function,potype_procedure]) then
+        Internalerror(200006137);
+      if not assigned(procdef.struct) or
+         (procdef.procoptions*[po_classmethod, po_staticmethod,
+           po_methodpointer, po_interrupt, po_iocheck]<>[]) then
+        Internalerror(200006138);
+      if procdef.owner.symtabletype<>ObjectSymtable then
+        Internalerror(200109191);
+
+      make_global:=false;
+      if (not current_module.is_unit) or
+         create_smartlink or
+         (procdef.owner.defowner.owner.symtabletype=globalsymtable) then
+        make_global:=true;
+
+      if make_global then
+        list.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0,procdef))
+      else
+        list.concat(Tai_symbol.Createname_hidden(labelname,AT_FUNCTION,0,procdef));
+
+      { the wrapper might need aktlocaldata for the additional data to
+        load the constant }
+      current_procinfo:=cprocinfo.create(nil);
+
+      { set param1 interface to self  }
+      g_adjust_self_value(list,procdef,ioffset);
+
+      { case 4 }
+      if (po_virtualmethod in procdef.procoptions) and
+          not is_objectpascal_helper(procdef.struct) then
+        begin
+//          loadvmttor12;
+//          op_onr12methodaddr;
+        end
+      else
+        list.concat(taicpu.op_sym(A_CALL0,current_asmdata.RefAsmSymbol(procdef.mangledname,AT_FUNCTION)));
+      list.concatlist(current_procinfo.aktlocaldata);
+
+      current_procinfo.Free;
+      current_procinfo:=nil;
+
+      list.concat(Tai_symbol_end.Createname(labelname));
     end;
 
 

+ 7 - 7
compiler/xtensa/racpugas.pas

@@ -596,9 +596,10 @@ Unit racpugas;
               BuildReference(oper);
             end;
 
-          AS_HASH: { Constant expression  }
+          AS_MINUS,
+          AS_PLUS,
+          AS_INTNUM: { Constant expression  }
             Begin
-              Consume(AS_HASH);
               BuildConstantOperand(oper);
             end;
           AS_ID: { A constant expression, or a Variable ref.  }
@@ -841,14 +842,13 @@ Unit racpugas;
 
         actcondition:=C_None;
 
-        { first, handle B else BLS is read wrong }
-        if ((hs[1]='J') and (length(hs)=3)) then
+        if hs[1]='B' then
           begin
             for icond:=low(tasmcond) to high(tasmcond) do
               begin
-                if copy(hs,2,3)=uppercond2str[icond] then
+                if copy(hs,2,length(hs)-1)=uppercond2str[icond] then
                   begin
-                    actopcode:=A_J;
+                    actopcode:=A_Bcc;
                     actasmtoken:=AS_OPCODE;
                     actcondition:=icond;
                     is_asmopcode:=true;
@@ -856,7 +856,7 @@ Unit racpugas;
                   end;
               end;
           end;
-        maxlen:=min(length(hs),6);
+        maxlen:=min(length(hs),7);
         actopcode:=A_NONE;
         j2:=maxlen;
         hs2:=hs;

+ 3 - 1
compiler/xtensa/xtensaatt.inc

@@ -1,5 +1,5 @@
 (
-'none',
+'',
 'abs',
 'add',
 'add.s',
@@ -18,6 +18,7 @@
 'callx12',
 'entry',
 'extui',
+'ill',
 'l8ui',
 'l16si',
 'l16ui',
@@ -54,6 +55,7 @@
 'ssr',
 'sub',
 'sub.s',
+'syscall',
 'xor'
 );
 

+ 2 - 0
compiler/xtensa/xtensaop.inc

@@ -18,6 +18,7 @@ A_CALLX8,
 A_CALLX12,
 A_ENTRY,
 A_EXTUI,
+A_ILL,
 A_L8UI,
 A_L16SI,
 A_L16UI,
@@ -54,6 +55,7 @@ A_SSL,
 A_SSR,
 A_SUB,
 A_SUB_S,
+A_SYSCALL,
 A_XOR
 );
 

+ 46 - 0
rtl/linux/xtensa/sighndh.inc

@@ -0,0 +1,46 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1999-2000 by Jonas Maebe,
+    member of the Free Pascal development team.
+
+    TSigContext
+
+    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.
+
+ **********************************************************************}
+
+{$packrecords C}
+
+type
+  PSigContext = ^TSigContext;
+  TSigContext = record
+    sc_pc,
+    sc_ps,
+    sc_lbeg,
+    sc_lend,
+    sc_lcount,
+    sc_sar,
+    sc_acclo,
+    sc_acchi : culong;
+    sc_a : array[0..15] of culong;
+  end;
+
+  stack_t = record
+    ss_sp : pointer;
+    ss_flags : cint;
+    ss_size : size_t;
+  end;
+
+  pucontext = ^tucontext;
+  tucontext = record
+    uc_flags : culong;
+    uc_link : pucontext;
+    uc_stack : stack_t;
+    uc_mcontext : TSigContext;
+    uc_sigmask : tsigset;
+  end;

+ 46 - 0
rtl/linux/xtensa/stat.inc

@@ -0,0 +1,46 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1999-2000 by Jonas Maebe, (c) 2005 Thomas Schatzl,
+    members of the Free Pascal development team.
+
+    Contains the definition of the stat type for the Xtensa platform.
+
+    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.
+
+ **********************************************************************}
+
+{ This structure was adapted from
+
+    include/uapi/asm-generic/stat.h
+
+  in Linux 4.0. Note that the stat record is the same for direct
+  syscalls as for when linking to libc.
+}
+
+{$PACKRECORDS C}
+  stat = record
+      st_dev        : culonglong;
+      st_ino        : culonglong;
+      st_mode       : cuint;
+      st_nlink      : cuint;
+      st_uid        : cuint;
+      st_gid        : cuint;
+      st_rdev       : culonglong;
+      st_size       : clonglong;
+      st_blksize    : culong;
+      __unused2     : culong;
+      st_blocks     : culonglong;
+      st_atime      : cULong;
+      st_atime_nsec : cULong;
+      st_mtime      : cULong;
+      st_mtime_nsec : cULong;
+      st_ctime      : cULong;
+      st_ctime_nsec : cULong;
+      __unused4a    : cULong;
+      __unused5a    : cULong;
+  end;

+ 34 - 0
rtl/linux/xtensa/syscallh.inc

@@ -0,0 +1,34 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2002 Marco van de Voort
+    member of the Free Pascal development team.
+
+    Xtensa syscall headers for Linux
+
+    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.
+
+ **********************************************************************}
+
+Type
+  TSysResult = longint; // all platforms, cint=32-bit.
+                        // On platforms with off_t =64-bit, people should
+                        // use int64, and typecast all calls that don't
+                        // return off_t to cint.
+
+// I don't think this is going to work on several platforms
+// 64-bit machines don't have only 64-bit params.
+
+  TSysParam  = Longint;
+
+function Do_SysCall(sysnr:TSysParam):TSysResult;  external name 'FPC_SYSCALL0';
+function Do_SysCall(sysnr,param1:TSysParam):TSysResult; external name 'FPC_SYSCALL1';
+function Do_SysCall(sysnr,param1,param2:TSysParam):TSysResult;  external name 'FPC_SYSCALL2';
+function Do_SysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; external name 'FPC_SYSCALL3';
+function Do_SysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; external name 'FPC_SYSCALL4';
+function Do_SysCall(sysnr,param1,param2,param3,param4,param5:TSysParam):TSysResult;  external name 'FPC_SYSCALL5';
+function Do_SysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):TSysResult;  external name 'FPC_SYSCALL6';

+ 1 - 0
tests/webtbs/tw14315b.pp

@@ -1,3 +1,4 @@
+{ this test fails for x86_64-linux with r44578, reason not found yet }
 program Project1;
 
 {$mode objfpc}{$H+}

+ 1 - 1
utils/fpcm/revision.inc

@@ -1 +1 @@
-'2020-03-29 rev 44400'
+'2020-04-03 rev 44544'