[fpc-devel] aarch64-linux: PATCH: add aarch64-linux to rtl/

Edmund Grimley Evans edmund.grimley.evans at gmail.com
Sat May 23 00:04:30 CEST 2015


This patch includes most of the hard work in porting FPC to
aarch64-linux: getting the assembler start-up code roughly right,
getting the sizes and layouts of various structs correct, coping with
system calls that no longer exist (see dup2/dup3, for example), ...

Linux arm64 takes its system call numbers from
include/uapi/asm-generic/unistd.h, which according to a quick grep of
the kernel source is currently used for these architectures: arc,
arm64, c6x, hexagon, metag, nios2, openrisc, score, tile, unicore32. I
would guess that arm64 is the first of these to appear in FPC so I've
put the "generic" syscall numbers in rtl/linux/sysnr-gen.inc and I've
used generic_linux_syscalls as the condition for alternatives that
would presumably be applicable to any of those architectures.

With this patch you should be able to get as far as building
compiler/ppca64, either cross-building on a supported system or
building natively on Linux arm64.


diff --git a/rtl/linux/aarch64/bsyscall.inc b/rtl/linux/aarch64/bsyscall.inc
new file mode 100644
index 0000000..c690ebe
--- /dev/null
+++ b/rtl/linux/aarch64/bsyscall.inc
@@ -0,0 +1 @@
+{ nothing }
diff --git a/rtl/linux/aarch64/cprt0.as b/rtl/linux/aarch64/cprt0.as
new file mode 100644
index 0000000..fe41556
--- /dev/null
+++ b/rtl/linux/aarch64/cprt0.as
@@ -0,0 +1,91 @@
+/*
+   Start-up code for Free Pascal Compiler when linking with C library.
+
+   Written by Edmund Grimley Evans in 2015 and released into the public domain.
+*/
+
+	.text
+	.align 2
+
+	.globl _start
+	.type  _start,#function
+_start:
+	/* Initialise FP to zero */
+	mov	x29,#0
+
+	/* This is rtld_fini */
+	mov	x5,x0
+
+	/* Get argc, argv, envp */
+	ldr	x1,[sp]
+	add	x2,sp,#8
+	add	x11,x1,#1
+	add	x11,x2,x11,lsl #3
+
+	/* Save argc, argv, envp, and initial stack pointer */
+	adrp	x10,:got:operatingsystem_parameter_argc
+	ldr	x10,[x10,#:got_lo12:operatingsystem_parameter_argc]
+	str	x1,[x10]
+	adrp	x10,:got:operatingsystem_parameter_argv
+	ldr	x10,[x10,#:got_lo12:operatingsystem_parameter_argv]
+	str	x2,[x10]
+	adrp	x10,:got:operatingsystem_parameter_envp
+	ldr	x10,[x10,#:got_lo12:operatingsystem_parameter_envp]
+	str	x11,[x10]
+	adrp	x10,:got:__stkptr
+	ldr	x10,[x10,#:got_lo12:__stkptr]
+	mov	x6,sp
+	str	x6,[x10]
+
+	/* __libc_start_main(main, argc, argv,
+	                     init, fini, rtld_fini, stack_end) */
+	adrp	x0,:got:PASCALMAIN
+	ldr	x0,[x0,#:got_lo12:PASCALMAIN]
+	adrp	x3,:got:__libc_csu_init
+	ldr	x3,[x3,#:got_lo12:__libc_csu_init]
+	adrp	x4,:got:__libc_csu_fini
+	ldr	x4,[x4,#:got_lo12:__libc_csu_fini]
+	bl	__libc_start_main
+
+	/* This should never happen */
+	b	abort
+
+	.globl	_init
+	.type	_init,#function
+_init:
+	ret
+
+	.globl	_fini
+	.type	_fini,#function
+_fini:
+	ret
+
+	.globl	_haltproc
+	.type	_haltproc,#function
+_haltproc:
+	adrp	x0,:got:operatingsystem_result
+	ldr	x0,[x0,#:got_lo12:operatingsystem_result]
+	ldr	w0,[x0]
+	mov	w8,#94 // syscall_nr_exit_group
+	svc	#0
+	b	_haltproc
+
+	/* Define a symbol for the first piece of initialized data. */
+	.data
+	.align 3
+	.globl __data_start
+__data_start:
+	.long 0
+	.weak data_start
+	data_start = __data_start
+
+	.bss
+	.align 3
+
+	.comm __stkptr,8
+
+	.comm operatingsystem_parameter_envp,8
+	.comm operatingsystem_parameter_argc,8
+	.comm operatingsystem_parameter_argv,8
+
+	.section .note.GNU-stack,"",%progbits
diff --git a/rtl/linux/aarch64/dllprt0.as b/rtl/linux/aarch64/dllprt0.as
new file mode 100644
index 0000000..e91b758
--- /dev/null
+++ b/rtl/linux/aarch64/dllprt0.as
@@ -0,0 +1,72 @@
+/*
+   Start-up code for Free Pascal Compiler in a shared library,
+   not linking with C library.
+
+   Written by Edmund Grimley Evans in 2015 and released into the public domain.
+*/
+
+	.text
+	.align 2
+
+	.globl	_startlib
+	.type	_startlib,#function
+_startlib:
+	.globl	FPC_SHARED_LIB_START
+	.type	FPC_SHARED_LIB_START,#function
+FPC_SHARED_LIB_START:
+	stp	x29,x30,[sp,#-16]!
+
+	/* Save argc, argv and envp */
+	adrp	x9,:got:operatingsystem_parameter_argc
+	ldr	x9,[x9,#:got_lo12:operatingsystem_parameter_argc]
+	str	x0,[x9]
+	adrp	x9,:got:operatingsystem_parameter_argv
+	ldr	x9,[x9,#:got_lo12:operatingsystem_parameter_argv]
+	str	x1,[x9]
+	adrp	x9,:got:operatingsystem_parameter_envp
+	ldr	x9,[x9,#:got_lo12:operatingsystem_parameter_envp]
+	str	x2,[x9]
+
+	/* Save initial stackpointer */
+	adrp	x9,:got:__stkptr
+	ldr	x9,[x9,#:got_lo12:__stkptr]
+	mov	x10,sp
+	str	x10,[x9]
+
+	/* Call main */
+	bl	PASCALMAIN
+
+	/* Return */
+	ldp	x29,x30,[sp],#16
+	ret
+
+	.globl	_haltproc
+	.type	_haltproc,#function
+_haltproc:
+	adrp	x0,:got:operatingsystem_result
+	ldr	x0,[x0,#:got_lo12:operatingsystem_result]
+	ldr	w0,[x0]
+	mov	w8,#94 // syscall_nr_exit_group
+	svc	#0
+	b	_haltproc
+
+	/* Define a symbol for the first piece of initialized data. */
+	.data
+	.align 3
+	.globl __data_start
+__data_start:
+	.long 0
+	.weak data_start
+	data_start = __data_start
+
+	.bss
+	.align 3
+
+	.comm __dl_fini,8
+	.comm __stkptr,8
+
+	.comm operatingsystem_parameter_envp,8
+	.comm operatingsystem_parameter_argc,8
+	.comm operatingsystem_parameter_argv,8
+
+	.section .note.GNU-stack,"",%progbits
diff --git a/rtl/linux/aarch64/gprt0.as b/rtl/linux/aarch64/gprt0.as
new file mode 100644
index 0000000..e3a1b59
--- /dev/null
+++ b/rtl/linux/aarch64/gprt0.as
@@ -0,0 +1,10 @@
+/*
+   Start-up code for Free Pascal Compiler when linking with C library
+   with profiling support.
+
+   Written by Edmund Grimley Evans in 2015 and released into the public domain.
+*/
+
+	.text
+	.align 2
+	b	xx_aarch64_gprt0_unimplemented
diff --git a/rtl/linux/aarch64/prt0.as b/rtl/linux/aarch64/prt0.as
new file mode 100644
index 0000000..277d309
--- /dev/null
+++ b/rtl/linux/aarch64/prt0.as
@@ -0,0 +1,77 @@
+/*
+   Start-up code for Free Pascal Compiler, not in a shared library,
+   not linking with C library.
+
+   Written by Edmund Grimley Evans in 2015 and released into the public domain.
+*/
+
+	.text
+	.align 2
+
+	.globl _dynamic_start
+	.type  _dynamic_start,#function
+_dynamic_start:
+	ldr	x10,=__dl_fini
+	str	x0,[x10]
+	b	_start
+
+	.globl	_start
+	.type	_start,#function
+_start:
+	/* Initialise FP to zero */
+	mov	x29,#0
+
+	/* Get argc, argv, envp */
+	ldr	x1,[sp]
+	add	x2,sp,#8
+	add	x11,x1,#1
+	add	x11,x2,x11,lsl #3
+
+	/* Save argc, argv, envp, and initial stack pointer */
+	ldr	x10,=operatingsystem_parameter_argc
+	str	x1,[x10]
+	ldr	x10,=operatingsystem_parameter_argv
+	str	x2,[x10]
+	ldr	x10,=operatingsystem_parameter_envp
+	str	x11,[x10]
+	ldr	x10,=__stkptr
+	mov	x6,sp
+	str	x6,[x10]
+
+	/* Call main */
+	bl	PASCALMAIN
+
+	.globl	_haltproc
+	.type	_haltproc,#function
+_haltproc:
+	ldr	x10,=__dl_fini
+	ldr	x0,[x10]
+	cbz	x0,.Lexit
+	blr	x0
+.Lexit:
+	ldr	x10,=operatingsystem_result
+	ldr	w0,[x10]
+	mov	w8,#94 // syscall_nr_exit_group
+	svc	#0
+	b	_haltproc
+
+	/* Define a symbol for the first piece of initialized data. */
+	.data
+	.align 3
+	.globl __data_start
+__data_start:
+	.long 0
+	.weak data_start
+	data_start = __data_start
+
+	.bss
+	.align 3
+
+	.comm __dl_fini,8
+	.comm __stkptr,8
+
+	.comm operatingsystem_parameter_envp,8
+	.comm operatingsystem_parameter_argc,8
+	.comm operatingsystem_parameter_argv,8
+
+	.section .note.GNU-stack,"",%progbits
diff --git a/rtl/linux/aarch64/sighnd.inc b/rtl/linux/aarch64/sighnd.inc
new file mode 100644
index 0000000..011b63a
--- /dev/null
+++ b/rtl/linux/aarch64/sighnd.inc
@@ -0,0 +1,44 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1999-2000 by Michael Van Canneyt,
+    member of the Free Pascal development team.
+
+    Signal handler is arch dependant due to processor to language
+    exception conversion.
+
+    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.
+
+ **********************************************************************}
+
+procedure SignalToRunerror(Sig: longint; SigInfo: PSigInfo; UContext: PUContext); public name '_FPC_DEFAULTSIGHANDLER'; cdecl;
+
+var
+  res : word;
+begin
+  res:=0;
+  case sig of
+    SIGFPE:
+        res:=207;
+    SIGILL:
+        res:=216;
+    SIGSEGV :
+        res:=216;
+    SIGBUS:
+        res:=214;
+    SIGINT:
+        res:=217;
+    SIGQUIT:
+        res:=233;
+  end;
+  reenable_signal(sig);
+  { give runtime error at the position where the signal was raised }
+  if res<>0 then
+    HandleErrorAddrFrame(res,
+      pointer(uContext^.uc_mcontext.pc),
+      pointer(uContext^.uc_mcontext.regs[29]));
+end;
diff --git a/rtl/linux/aarch64/sighndh.inc b/rtl/linux/aarch64/sighndh.inc
new file mode 100644
index 0000000..8fa6a35
--- /dev/null
+++ b/rtl/linux/aarch64/sighndh.inc
@@ -0,0 +1,47 @@
+{
+    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 and associated structures.
+
+    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
+    fault_address : cULong;
+    regs : array[0..30] of cULong;
+    sp : cULong;
+    pc : cULong;
+    pstate : cULong;
+    __pad : cULong;
+    { The following field should be 16-byte-aligned. Currently the
+      directive for specifying alignment is buggy, so the preceding
+      field was added so that the record has the right size. }
+    __reserved : array[0..4095] of cUChar;
+  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 : sigset_t;
+  end;
diff --git a/rtl/linux/aarch64/stat.inc b/rtl/linux/aarch64/stat.inc
new file mode 100644
index 0000000..6d69441
--- /dev/null
+++ b/rtl/linux/aarch64/stat.inc
@@ -0,0 +1,72 @@
+{
+    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 PowerPC64 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
+    case integer of
+    0 : (
+      st_dev        : cULong;
+      st_ino        : cULong;
+      st_mode       : cUInt;
+      st_nlink      : cUInt;
+      st_uid        : cUInt;
+      st_gid        : cUInt;
+      st_rdev       : cULong;
+      __pad1a       : cULong;
+      st_size       : cLong;
+      st_blksize    : cInt;
+      __pad2a       : cInt;
+      st_blocks     : cLong;
+      st_atime      : cLong;
+      st_atime_nsec : cULong;
+      st_mtime      : cLong;
+      st_mtime_nsec : cULong;
+      st_ctime      : cLong;
+      st_ctime_nsec : cULong;
+      __unused4a    : cUInt;
+      __unused5a    : cUInt;
+      );
+    1 : (
+      dev           : cULong deprecated;
+      ino           : cULong deprecated;
+      mode          : cUInt deprecated;
+      nlink         : cUInt deprecated;
+      uid           : cUInt deprecated;
+      gid           : cUInt deprecated;
+      rdev          : cULong deprecated;
+      __pad1b       : cULong deprecated;
+      size          : cLong deprecated;
+      blksize       : cInt deprecated;
+      __pad2b       : cInt deprecated;
+      blocks        : cLong deprecated;
+      atime         : cLong deprecated;
+      atime_nsec    : cULong deprecated;
+      mtime         : cLong deprecated;
+      mtime_nsec    : cULong deprecated;
+      ctime         : cLong deprecated;
+      ctime_nsec    : cULong deprecated;
+      __unused4b    : cUInt deprecated;
+      __unused5b    : cUInt deprecated;
+      );
+  end;
diff --git a/rtl/linux/aarch64/syscall.inc b/rtl/linux/aarch64/syscall.inc
new file mode 100644
index 0000000..5001aa6
--- /dev/null
+++ b/rtl/linux/aarch64/syscall.inc
@@ -0,0 +1,127 @@
+{
+  This file is part of the Free Pascal run time library.
+
+  Perform syscall with 0..6 arguments.
+  If syscall return value is negative, negate it, set errno, and return -1.
+
+  Written by Edmund Grimley Evans in 2015 and released into the public domain.
+}
+
+function FpSysCall(sysnr:TSysParam):TSysResult;
+assembler; nostackframe; [public,alias:'FPC_SYSCALL0'];
+asm
+  mov w8,w0
+  svc #0
+  tbz x0,#63,.Ldone
+  str x30,[sp,#-16]!
+  neg x0,x0
+  bl seterrno
+  ldr x30,[sp],#16
+  mov x0,#-1
+.Ldone:
+end;
+
+function FpSysCall(sysnr,param1:TSysParam):TSysResult;
+assembler; nostackframe; [public,alias:'FPC_SYSCALL1'];
+asm
+  mov w8,w0
+  mov x0,x1
+  svc #0
+  tbz x0,#63,.Ldone
+  str x30,[sp,#-16]!
+  neg x0,x0
+  bl seterrno
+  ldr x30,[sp],#16
+  mov x0,#-1
+.Ldone:
+end;
+
+function FpSysCall(sysnr,param1,param2:TSysParam):TSysResult;
+assembler; nostackframe; [public,alias:'FPC_SYSCALL2'];
+asm
+  mov w8,w0
+  mov x0,x1
+  mov x1,x2
+  svc #0
+  tbz x0,#63,.Ldone
+  str x30,[sp,#-16]!
+  neg x0,x0
+  bl seterrno
+  ldr x30,[sp],#16
+  mov x0,#-1
+.Ldone:
+end;
+
+function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult;
+assembler; nostackframe; [public,alias:'FPC_SYSCALL3'];
+asm
+  mov w8,w0
+  mov x0,x1
+  mov x1,x2
+  mov x2,x3
+  svc #0
+  tbz x0,#63,.Ldone
+  str x30,[sp,#-16]!
+  neg x0,x0
+  bl seterrno
+  ldr x30,[sp],#16
+  mov x0,#-1
+.Ldone:
+end;
+
+function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult;
+assembler; nostackframe; [public,alias:'FPC_SYSCALL4'];
+asm
+  mov w8,w0
+  mov x0,x1
+  mov x1,x2
+  mov x2,x3
+  mov x3,x4
+  svc #0
+  tbz x0,#63,.Ldone
+  str x30,[sp,#-16]!
+  neg x0,x0
+  bl seterrno
+  ldr x30,[sp],#16
+  mov x0,#-1
+.Ldone:
+end;
+
+function FpSysCall(sysnr,param1,param2,param3,param4,param5:TSysParam):TSysResult;
+assembler; nostackframe; [public,alias:'FPC_SYSCALL5'];
+asm
+  mov w8,w0
+  mov x0,x1
+  mov x1,x2
+  mov x2,x3
+  mov x3,x4
+  mov x4,x5
+  svc #0
+  tbz x0,#63,.Ldone
+  str x30,[sp,#-16]!
+  neg x0,x0
+  bl seterrno
+  ldr x30,[sp],#16
+  mov x0,#-1
+.Ldone:
+end;
+
+function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):TSysResult;
+assembler; nostackframe; [public,alias:'FPC_SYSCALL6'];
+asm
+  mov w8,w0
+  mov x0,x1
+  mov x1,x2
+  mov x2,x3
+  mov x3,x4
+  mov x4,x5
+  mov x5,x6
+  svc #0
+  tbz x0,#63,.Ldone
+  str x30,[sp,#-16]!
+  neg x0,x0
+  bl seterrno
+  ldr x30,[sp],#16
+  mov x0,#-1
+.Ldone:
+end;
diff --git a/rtl/linux/aarch64/syscallh.inc b/rtl/linux/aarch64/syscallh.inc
new file mode 100644
index 0000000..6961a19
--- /dev/null
+++ b/rtl/linux/aarch64/syscallh.inc
@@ -0,0 +1,35 @@
+{
+    Copyright (c) 2002 by Marco van de Voort
+
+    Header for syscalls in system unit.
+
+    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., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301, USA.
+
+ ****************************************************************************
+
+}
+
+Type
+  TSysResult = Int64;
+  TSysParam  = Int64;
+
+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';
diff --git a/rtl/linux/aarch64/sysnr.inc b/rtl/linux/aarch64/sysnr.inc
new file mode 100644
index 0000000..3763caa
--- /dev/null
+++ b/rtl/linux/aarch64/sysnr.inc
@@ -0,0 +1 @@
+{$i ../sysnr-gen.inc}
diff --git a/rtl/linux/bunxsysc.inc b/rtl/linux/bunxsysc.inc
index afd68b7..270d4f1 100644
--- a/rtl/linux/bunxsysc.inc
+++ b/rtl/linux/bunxsysc.inc
@@ -297,7 +297,11 @@ end;
 function fpgetpgrp : pid_t;
 
 begin
+{$if defined(generic_linux_syscalls)}
+ fpgetpgrp:=do_syscall(syscall_nr_getpgid,0);
+{$else}
  fpgetpgrp:=do_syscall(syscall_nr_getpgrp);
+{$endif}
 end;
 
 function fpsetsid : pid_t;
@@ -327,29 +331,59 @@ Function fplink(existing:pchar;newone:pchar):cint;
   In effect, new will be the same file as old.
 }
 begin
+{$if defined(generic_linux_syscalls)}
+  fpLink:=Do_Syscall(syscall_nr_linkat,AT_FDCWD,TSysParam(existing),AT_FDCWD,TSysParam(newone),0);
+{$else}
   fpLink:=Do_Syscall(syscall_nr_link,TSysParam(existing),TSysParam(newone));
+{$endif}
 end;
 
 Function fpmkfifo(path:pchar;mode:mode_t):cint;
 
 begin
 
+{$if defined(generic_linux_syscalls)}
+fpmkfifo:=do_syscall(syscall_nr_mknodat,AT_FDCWD,TSysParam(path),TSysParam(mode or S_IFIFO),TSysParam(0));
+{$else}
 fpmkfifo:=do_syscall(syscall_nr_mknod,TSysParam(path),TSysParam(mode or S_IFIFO),TSysParam(0));
+{$endif}
 end;
 
 Function fpchmod(path:pchar;mode:mode_t):cint;
 
 begin
+{$if defined(generic_linux_syscalls)}
+  fpchmod:=do_syscall(syscall_nr_fchmodat,AT_FDCWD,TSysParam(path),TSysParam(mode),0);
+{$else}
   fpchmod:=do_syscall(syscall_nr_chmod,TSysParam(path),TSysParam(mode));
+{$endif}
 end;
 
 Function fpchown(path:pchar;owner:uid_t;group:gid_t):cint;
 
 begin
+{$if defined(generic_linux_syscalls)}
+  fpChOwn:=do_syscall(syscall_nr_fchownat,AT_FDCWD,TSysParam(path),TSysParam(owner),TSysParam(group),0);
+{$else}
   fpChOwn:=do_syscall(syscall_nr_chown,TSysParam(path),TSysParam(owner),TSysParam(group));
+{$endif}
 end;
 
-{$ifndef NO_SYSCALL_UTIME}
+{$if defined(generic_linux_syscalls)}
+
+Function fpUtime(path:pchar;times:putimbuf):cint;
+var
+  tsa: Array[0..1] of timespec;
+begin
+  tsa[0].tv_sec := times^.actime;
+  tsa[0].tv_nsec := 0;
+  tsa[1].tv_sec := times^.modtime;
+  tsa[1].tv_nsec := 0;
+  fputime:=do_syscall(syscall_nr_utimensat,AT_FDCWD,TSysParam(path),
+                      TSysParam(@tsa),0);
+end;
+
+{$elseif not defined(NO_SYSCALL_UTIME)}
 
 Function fpUtime(path:pchar;times:putimbuf):cint;
 
@@ -377,7 +411,11 @@ end;
 Function fppipe(var fildes : tfildes):cint;
 
 begin
+{$if defined(generic_linux_syscalls)}
+ fppipe:=do_syscall(syscall_nr_pipe2,TSysParam(@fildes),0);
+{$else}
  fppipe:=do_syscall(syscall_nr_pipe,TSysParam(@fildes));
+{$endif}
 end;
 {$endif FPC_BASEUNIX_HAS_FPPIPE}
 
@@ -422,6 +460,18 @@ Function fpSelect(N:cint;readfds,writefds,exceptfds:pfdSet;TimeOut:PTimeVal):cin
   Select checks whether the file descriptor sets in readfs/writefs/exceptfs
   have changed.
 }
+{$if defined(generic_linux_syscalls)}
+
+var ts : timespec;
+begin
+  ts.tv_sec := timeout^.tv_sec;
+  ts.tv_nsec := timeout^.tv_usec * 1000;
+  fpSelect:=do_syscall(syscall_nr_pselect6,n,
+                       tsysparam(readfds),tsysparam(writefds),
+                       tsysparam(exceptfds),tsysparam(@ts),0);
+end;
+
+{$else}
 
 begin
 {$ifdef cpux86_64}
@@ -436,10 +486,22 @@ begin
 {$endif bunxfunc_fpselect_implemented}
 end;
 
+{$endif}
+
 function fpPoll(fds: ppollfd; nfds: cuint; timeout: clong): cint;
+{$if defined(generic_linux_syscalls)}
+var ts : timespec;
+begin
+  ts.tv_sec := timeout div 1000;
+  ts.tv_nsec := (timeout mod 1000) * 1000000;
+  fpPoll:=do_syscall(syscall_nr_ppoll,tsysparam(fds),tsysparam(nfds),
+                     tsysparam(@ts),0);
+end;
+{$else}
 begin
   fpPoll:=do_syscall(syscall_nr_poll,tsysparam(fds),tsysparam(nfds),tsysparam(timeout));
 end;
+{$endif}
 
 Function fpLstat(path:pchar;Info:pstat):cint;
 {
@@ -447,6 +509,9 @@ Function fpLstat(path:pchar;Info:pstat):cint;
 }
 
 begin
+{$if defined(generic_linux_syscalls)}
+ fpLStat:=do_syscall(syscall_nr_fstatat,AT_FDCWD,TSysParam(path),TSysParam(info),0)
+{$else}
  fpLStat:=do_syscall(
 {$ifdef cpu64}
     syscall_nr_lstat,
@@ -454,6 +519,7 @@ begin
     syscall_nr_lstat64,
 {$endif}
     TSysParam(path),TSysParam(info));
+{$endif}
 end;
 
 
@@ -465,12 +531,12 @@ function fpNice(N:cint):cint;
 Doesn't exist in BSD. Linux emu uses setpriority in a construct as below:
 }
 
-{$ifdef cpux86_64}
+{$if defined(generic_linux_syscalls) or defined(cpux86_64)}
 var
   oldprio : cint;
 {$endif}
 begin
-{$ifdef cpux86_64}
+{$if defined(generic_linux_syscalls) or defined(cpux86_64)}
   oldprio:=fpGetPriority(Prio_Process,0);
   fpNice:=fpSetPriority(Prio_Process,0,oldprio+N);
   if fpNice=0 then
@@ -536,7 +602,11 @@ Function fpSymlink(oldname,newname:pchar):cint;
 }
 
 begin
+{$if defined(generic_linux_syscalls)}
+  fpsymlink:=do_syscall(syscall_nr_symlinkat,TSysParam(oldname),AT_FDCWD,TSysParam(newname));
+{$else}
   fpsymlink:=do_syscall(syscall_nr_symlink,TSysParam(oldname),TSysParam(newname));
+{$endif}
 end;
 
 function Fppread(fd: cint; buf: pchar; nbytes : size_t; offset:Toff): ssize_t; [public, alias : 'FPC_SYSC_PREAD'];
diff --git a/rtl/linux/linux.pp b/rtl/linux/linux.pp
index d9f4f51..4f4333f 100644
--- a/rtl/linux/linux.pp
+++ b/rtl/linux/linux.pp
@@ -17,6 +17,8 @@
 **********************************************************************}
 unit Linux;
 
+{$i osdefs.inc}
+
 {$packrecords c}
 {$ifdef FPC_USE_LIBC} 
  {$linklib rt} // for clock* functions
@@ -527,7 +529,11 @@ end;
 
 function epoll_create(size: cint): cint;
 begin
+{$if defined(generic_linux_syscalls)}
+  epoll_create := do_syscall(syscall_nr_epoll_create1,0)
+{$else}
   epoll_create := do_syscall(syscall_nr_epoll_create,tsysparam(size));
+{$endif}
 end;
 
 function epoll_ctl(epfd, op, fd: cint; event: pepoll_event): cint;
@@ -538,8 +544,13 @@ end;
 
 function epoll_wait(epfd: cint; events: pepoll_event; maxevents, timeout: cint): cint;
 begin
+{$if defined(generic_linux_syscalls)}
+  epoll_wait := do_syscall(syscall_nr_epoll_pwait, tsysparam(epfd),
+    tsysparam(events), tsysparam(maxevents), tsysparam(timeout),0);
+{$else}
   epoll_wait := do_syscall(syscall_nr_epoll_wait, tsysparam(epfd),
     tsysparam(events), tsysparam(maxevents), tsysparam(timeout));
+{$endif}
 end;
 
 function capget(header:Puser_cap_header;data:Puser_cap_data):cint;
@@ -695,7 +706,11 @@ end;
 function inotify_init1(flags:cint):cint;
 
 begin
+{$if defined(generic_linux_syscalls)}
+  inotify_init1:=do_SysCall(syscall_nr_inotify_init1,tsysparam(flags));
+{$else}
   inotify_init1:=do_SysCall(syscall_nr_inotify_init,tsysparam(flags));
+{$endif}
 end;
 
 function inotify_add_watch(fd:cint; name:Pchar; mask:cuint32):cint;
diff --git a/rtl/linux/oldlinux.pp b/rtl/linux/oldlinux.pp
index 1a87825..5fd0891 100644
--- a/rtl/linux/oldlinux.pp
+++ b/rtl/linux/oldlinux.pp
@@ -1924,9 +1924,16 @@ Function Sys_Mkdir(Filename:pchar;mode:longint):longint;
 var
   regs : SysCallregs;
 begin
+{$if defined(generic_linux_syscalls)}
+  regs.reg2:=AT_FDCWD;
+  regs.reg3:=longint(filename);
+  regs.reg4:=mode;
+  Sys_MkDir:=SysCall(SysCall_nr_mkdirat,regs);
+{$else}
   regs.reg2:=longint(filename);
   regs.reg3:=mode;
   Sys_MkDir:=SysCall(SysCall_nr_mkdir,regs);
+{$endif}
 end;
 
 
@@ -1935,8 +1942,15 @@ Function Sys_Rmdir(Filename:pchar):longint;
 var
   regs : SysCallregs;
 begin
+{$if defined(generic_linux_syscalls)}
+  regs.reg2:=AT_FDCWD;
+  regs.reg3:=longint(filename);
+  regs.reg4:=AT_REMOVEDIR;
+  Sys_Rmdir:=SysCall(SysCall_nr_unlinkat,regs);
+{$else}
   regs.reg2:=longint(filename);
   Sys_Rmdir:=SysCall(SysCall_nr_rmdir,regs);
+{$endif}
 end;
 
 
@@ -2744,7 +2758,18 @@ var
 begin
   sr.reg2:=oldfile;
   sr.reg3:=newfile;
+{$if defined(generic_linux_syscalls)}
+  sr.reg4:=0;
+  if oldfile<>newfile then
+    SysCall(Syscall_nr_dup3,sr)
+  else
+    begin
+      sr.reg3:=F_GetFd;
+      SysCall(Syscall_nr_fcntl,sr);
+    end;
+{$else}
   SysCall(Syscall_nr_dup2,sr);
+{$endif}
   linuxerror:=errno;
   Dup2:=(LinuxError=0);
 end;
@@ -2782,7 +2807,12 @@ var
   regs : SysCallregs;
 begin
   regs.reg2:=longint(@pip);
+{$if defined(generic_linux_syscalls)}
+  regs.reg3:=0;
+  SysCall(SysCall_nr_pipe2,regs);
+{$else}
   SysCall(SysCall_nr_pipe,regs);
+{$endif}
   pipe_in:=pip[1];
   pipe_out:=pip[2];
   linuxerror:=errno;
diff --git a/rtl/linux/osdefs.inc b/rtl/linux/osdefs.inc
index cfb86fa..a8da1dd 100644
--- a/rtl/linux/osdefs.inc
+++ b/rtl/linux/osdefs.inc
@@ -85,3 +85,7 @@
   {$endif FPC_ABI_EABI}
 {$endif cpuarm}
 
+{$ifdef cpuaarch64}
+  {$define generic_linux_syscalls}
+  {$undef usestime}
+{$endif cpuaarch64}
diff --git a/rtl/linux/ossysc.inc b/rtl/linux/ossysc.inc
index cac057c..fb5dcbf 100644
--- a/rtl/linux/ossysc.inc
+++ b/rtl/linux/ossysc.inc
@@ -20,7 +20,7 @@
 *****************************************************************************}
 
 function Fptime(tloc:pTime_t): Time_t; [public, alias : 'FPC_SYSC_TIME'];
-{$ifdef FPC_USEGETTIMEOFDAY}
+{$if defined(generic_linux_syscalls) or defined(FPC_USEGETTIMEOFDAY)}
 VAR tv     : timeval;
     tz     : timezone;
     retval : longint;
@@ -49,7 +49,11 @@ end;
 function Fpopen(path: pchar; flags : cint; mode: mode_t):cint; [public, alias : 'FPC_SYSC_OPEN'];
 
 Begin
+{$if defined(generic_linux_syscalls)}
+ Fpopen:=do_syscall(syscall_nr_openat,AT_FDCWD,TSysParam(path),TSysParam(flags or O_LARGEFILE),TSysParam(mode));
+{$else}
  Fpopen:=do_syscall(syscall_nr_open,TSysParam(path),TSysParam(flags or O_LARGEFILE),TSysParam(mode));
+{$endif}
 End;
 
 function Fpclose(fd : cint): cint; [public, alias : 'FPC_SYSC_CLOSE'];
@@ -98,20 +102,32 @@ end;
 function Fpunlink(path: pchar): cint; [public, alias : 'FPC_SYSC_UNLINK'];
 
 begin
+{$if defined(generic_linux_syscalls)}
+  Fpunlink:=do_syscall(syscall_nr_unlinkat,AT_FDCWD,TSysParam(path),0);
+{$else}
   Fpunlink:=do_syscall(syscall_nr_unlink,TSysParam(path));
+{$endif}
 end;
 
 function Fprename(old : pchar; newpath: pchar): cint; [public, alias : 'FPC_SYSC_RENAME'];
 
 begin
+{$if defined(generic_linux_syscalls)}
+  Fprename:=do_syscall(syscall_nr_renameat,AT_FDCWD,TSysParam(old),AT_FDCWD,TSysParam(newpath));
+{$else}
   Fprename:=do_syscall(syscall_nr_rename,TSysParam(old),TSysParam(newpath));
+{$endif}
 end;
 
 function Fpstat(path: pchar; var buf: stat):cint; [public, alias : 'FPC_SYSC_STAT'];
 
 begin
 {$if defined(cpu64)}
-  Fpstat:=do_syscall(syscall_nr_stat,TSysParam(path),TSysParam(@buf));
+  {$if defined(generic_linux_syscalls)}
+    Fpstat:=do_syscall(syscall_nr_fstatat,AT_FDCWD,TSysParam(path),TSysParam(@buf),0);
+  {$else}
+    Fpstat:=do_syscall(syscall_nr_stat,TSysParam(path),TSysParam(@buf));
+  {$endif}
 {$else}
   Fpstat:=do_syscall(syscall_nr_stat64,TSysParam(path),TSysParam(@buf));
 {$endif}
@@ -130,13 +146,21 @@ end;
 function Fpmkdir(path : pchar; mode: mode_t):cint; [public, alias : 'FPC_SYSC_MKDIR'];
 
 begin
+{$if defined(generic_linux_syscalls)}
+  Fpmkdir:=do_syscall(syscall_nr_mkdirat,AT_FDCWD,TSysParam(path),TSysParam(mode));
+{$else}
   Fpmkdir:=do_syscall(syscall_nr_mkdir,TSysParam(path),TSysParam(mode));
+{$endif}
 end;
 
 function Fprmdir(path : pchar): cint;  [public, alias : 'FPC_SYSC_RMDIR'];
 
 begin
+{$if defined(generic_linux_syscalls)}
+ Fprmdir:=do_syscall(syscall_nr_unlinkat,AT_FDCWD,TSysParam(path),AT_REMOVEDIR);
+{$else}
  Fprmdir:=do_syscall(syscall_nr_rmdir,TSysParam(path));
+{$endif}
 end;
 
 function Fpopendir(dirname : pchar): pdir;  [public, alias : 'FPC_SYSC_OPENDIR'];
@@ -363,7 +387,11 @@ function Fpfstat(fd : cint; var sb : stat): cint;  [public, alias : 'FPC_SYSC_FS
 
 begin
 {$if defined(cpu64)}
-  FpFStat:=do_SysCall(syscall_nr_fstat,TSysParam(fd),TSysParam(@sb));
+  {$if defined(generic_linux_syscalls)}
+    FpFStat:=do_SysCall(syscall_nr_fstat,TSysParam(fd),TSysParam(@sb));
+  {$else}
+    FpFStat:=do_SysCall(syscall_nr_fstat,TSysParam(fd),TSysParam(@sb));
+  {$endif}
 {$else}
   FpFStat:=do_SysCall(syscall_nr_fstat64,TSysParam(fd),TSysParam(@sb));
 {$endif}
@@ -380,9 +408,14 @@ function Fpfork : pid_t;  [public, alias : 'FPC_SYSC_FORK'];
   A negative value indicates that an error has occurred, the error is returned in
   LinuxError.
 }
-
+var
+  pid : Int64;
 Begin
+{$if defined(generic_linux_syscalls)}
+ Fpfork:=Do_syscall(syscall_nr_clone,clone_flags_fork,0,0,0,TSysParam(@pid));
+{$else}
  Fpfork:=Do_syscall(SysCall_nr_fork);
+{$endif}
 End;
 {$endif FPC_SYSTEM_HAS_FPFORK}
 
@@ -425,7 +458,7 @@ function Fpwaitpid(pid : pid_t; stat_loc : pcint; options: cint): pid_t; [public
 }
 
 begin
-{$ifdef WAIT4}
+{$if defined(generic_linux_syscalls) or defined(WAIT4)}
  FpWaitPID:=do_syscall(syscall_nr_Wait4,PID,TSysParam(Stat_loc),options,0);
 {$else WAIT4}
  FpWaitPID:=do_syscall(syscall_nr_WaitPID,PID,TSysParam(Stat_loc),options);
@@ -447,7 +480,11 @@ function Fpaccess(pathname : pchar; amode : cint): cint; [public, alias : 'FPC_S
 }
 
 begin
+{$if defined(generic_linux_syscalls)}
+ FpAccess:=do_syscall(syscall_nr_faccessat,AT_FDCWD,TSysParam(pathname),amode,0);
+{$else}
  FpAccess:=do_syscall(syscall_nr_access,TSysParam(pathname),amode);
+{$endif}
 end;
 
 (* overloaded
@@ -481,7 +518,16 @@ end;
 Function FpDup2(fildes,fildes2:cint):cint; [public, alias : 'FPC_SYSC_DUP2'];
 
 begin
+{$if defined(generic_linux_syscalls)}
+ if fildes<>fildes2 then
+   Fpdup2:=do_syscall(syscall_nr_dup3,TSysParam(fildes),TSysParam(fildes2),0)
+ else if do_syscall(syscall_nr_fcntl,TSysParam(fildes),1)<>-1 then
+   Fpdup2:=fildes2
+ else
+   Fpdup2:=-1;
+{$else}
  Fpdup2:=do_syscall(syscall_nr_dup2,TSysParam(fildes),TSysParam(fildes2));
+{$endif}
 end;
 
 
@@ -572,7 +618,11 @@ end;
 Function FpReadLink(name,linkname:pchar;maxlen:size_t):cint;  [public, alias : 'FPC_SYSC_READLINK'];
 
 begin
+{$if defined(generic_linux_syscalls)}
+  Fpreadlink:=do_syscall(syscall_nr_readlinkat,AT_FDCWD,TSysParam(name),TSysParam(linkname),maxlen);
+{$else}
   Fpreadlink:=do_syscall(syscall_nr_readlink, TSysParam(name),TSysParam(linkname),maxlen);
+{$endif}
 end;
 
 
diff --git a/rtl/linux/ostypes.inc b/rtl/linux/ostypes.inc
index c8afeca..907f12a 100644
--- a/rtl/linux/ostypes.inc
+++ b/rtl/linux/ostypes.inc
@@ -290,7 +290,12 @@ CONST
 {$endif not cpumips}
 {$endif not cpusparc}
 
-{$if defined(cpuarm) or defined(cpualpha) or defined(cpublackfin) or defined(cpum68k)}
+    AT_FDCWD = -100;
+    AT_REMOVEDIR = $200;
+    clone_flags_fork = $01200011;
+      { SIGCHLD | CLONE_CHILD_CLEARTID | CLONE_CHILD_SETTID }
+
+{$if defined(cpuarm) or defined(cpualpha) or defined(cpublackfin) or defined(cpum68k) or defined(aarch64)}
     O_LARGEFILE =   $20000;
 {$endif}
 {$if defined(cpusparc) or defined(cpusparc64)}
diff --git a/rtl/linux/pmutext.inc b/rtl/linux/pmutext.inc
index 8303332..d762603 100644
--- a/rtl/linux/pmutext.inc
+++ b/rtl/linux/pmutext.inc
@@ -19,10 +19,12 @@
   from the system unit interface; macro's have to be on at this point
   because they're use to propagate the MUTEXTYPENAME here }
 
-{$ifdef CPUMIPS}
+{$if defined(CPUMIPS) or defined(cpuaarch64)}
 {$define USE_PTHREAD_SIZEOF}
 
-{$ifdef CPU64}
+{$if defined(cpuaarch64)}
+  {$define __SIZEOF_PTHREAD_MUTEX_T := 48}
+{$elseif defined(CPU64)}
   {$define __SIZEOF_PTHREAD_MUTEX_T := 40}
 {$else CPU64}
   {$define __SIZEOF_PTHREAD_MUTEX_T := 24}
diff --git a/rtl/linux/ptypes.inc b/rtl/linux/ptypes.inc
index 9600464..82a8e7c5 100644
--- a/rtl/linux/ptypes.inc
+++ b/rtl/linux/ptypes.inc
@@ -30,9 +30,19 @@ and all three 32-bit systems returned completely identical types too
 introduction)
 }
 
-{$ifdef CPUMIPS}
+{$if defined(CPUMIPS) or defined(cpuaarch64)}
 {$define USE_PTHREAD_SIZEOF}
-{$ifdef CPU64}
+{$if defined(cpuaarch64)}
+const
+  __SIZEOF_PTHREAD_ATTR_T = 64;
+  __SIZEOF_PTHREAD_MUTEXATTR_T = 8;
+  __SIZEOF_PTHREAD_COND_T = 48;
+  __SIZEOF_PTHREAD_CONDATTR_T = 8;
+  __SIZEOF_PTHREAD_RWLOCK_T = 56;
+  __SIZEOF_PTHREAD_RWLOCKATTR_T = 8;
+  __SIZEOF_PTHREAD_BARRIER_T = 32;
+  __SIZEOF_PTHREAD_BARRIERATTR_T = 8;
+{$elseif defined(CPU64)}
 const
   __SIZEOF_PTHREAD_ATTR_T = 56;
   __SIZEOF_PTHREAD_MUTEXATTR_T = 4;
@@ -53,7 +63,7 @@ const
   __SIZEOF_PTHREAD_BARRIER_T = 20;
   __SIZEOF_PTHREAD_BARRIERATTR_T = 4;
 {$endif CPU32}
-{$endif MIPS}
+{$endif}
 
 {$I ctypes.inc}
 {$packrecords c}
diff --git a/rtl/linux/sysnr-gen.inc b/rtl/linux/sysnr-gen.inc
new file mode 100644
index 0000000..3525861
--- /dev/null
+++ b/rtl/linux/sysnr-gen.inc
@@ -0,0 +1,277 @@
+
+{
+  System call numbers taken from include/uapi/asm-generic/unistd.h
+  in a 4.0 Linux kernel. They are therefore architecture-independent,
+  though only the newest architectures use this generic list.
+}
+
+Const
+        syscall_nr_io_setup                     = 0;
+        syscall_nr_io_destroy                   = 1;
+        syscall_nr_io_submit                    = 2;
+        syscall_nr_io_cancel                    = 3;
+        syscall_nr_io_getevents                 = 4;
+        syscall_nr_setxattr                     = 5;
+        syscall_nr_lsetxattr                    = 6;
+        syscall_nr_fsetxattr                    = 7;
+        syscall_nr_getxattr                     = 8;
+        syscall_nr_lgetxattr                    = 9;
+        syscall_nr_fgetxattr                    = 10;
+        syscall_nr_listxattr                    = 11;
+        syscall_nr_llistxattr                   = 12;
+        syscall_nr_flistxattr                   = 13;
+        syscall_nr_removexattr                  = 14;
+        syscall_nr_lremovexattr                 = 15;
+        syscall_nr_fremovexattr                 = 16;
+        syscall_nr_getcwd                       = 17;
+        syscall_nr_lookup_dcookie               = 18;
+        syscall_nr_eventfd2                     = 19;
+        syscall_nr_epoll_create1                = 20;
+        syscall_nr_epoll_ctl                    = 21;
+        syscall_nr_epoll_pwait                  = 22;
+        syscall_nr_dup                          = 23;
+        syscall_nr_dup3                         = 24;
+        syscall_nr_fcntl                        = 25;
+        syscall_nr_inotify_init1                = 26;
+        syscall_nr_inotify_add_watch            = 27;
+        syscall_nr_inotify_rm_watch             = 28;
+        syscall_nr_ioctl                        = 29;
+        syscall_nr_ioprio_set                   = 30;
+        syscall_nr_ioprio_get                   = 31;
+        syscall_nr_flock                        = 32;
+        syscall_nr_mknodat                      = 33;
+        syscall_nr_mkdirat                      = 34;
+        syscall_nr_unlinkat                     = 35;
+        syscall_nr_symlinkat                    = 36;
+        syscall_nr_linkat                       = 37;
+        syscall_nr_renameat                     = 38;
+        syscall_nr_umount2                      = 39;
+        syscall_nr_mount                        = 40;
+        syscall_nr_pivot_root                   = 41;
+        syscall_nr_nfsservctl                   = 42;
+        syscall_nr_statfs                       = 43;
+        syscall_nr_fstatfs                      = 44;
+        syscall_nr_truncate                     = 45;
+        syscall_nr_ftruncate                    = 46;
+        syscall_nr_fallocate                    = 47;
+        syscall_nr_faccessat                    = 48;
+        syscall_nr_chdir                        = 49;
+        syscall_nr_fchdir                       = 50;
+        syscall_nr_chroot                       = 51;
+        syscall_nr_fchmod                       = 52;
+        syscall_nr_fchmodat                     = 53;
+        syscall_nr_fchownat                     = 54;
+        syscall_nr_fchown                       = 55;
+        syscall_nr_openat                       = 56;
+        syscall_nr_close                        = 57;
+        syscall_nr_vhangup                      = 58;
+        syscall_nr_pipe2                        = 59;
+        syscall_nr_quotactl                     = 60;
+        syscall_nr_getdents64                   = 61;
+        syscall_nr_lseek                        = 62;
+        syscall_nr_read                         = 63;
+        syscall_nr_write                        = 64;
+        syscall_nr_readv                        = 65;
+        syscall_nr_writev                       = 66;
+        syscall_nr_pread64                      = 67;
+        syscall_nr_pwrite64                     = 68;
+        syscall_nr_preadv                       = 69;
+        syscall_nr_pwritev                      = 70;
+        syscall_nr_sendfile                     = 71;
+        syscall_nr_pselect6                     = 72;
+        syscall_nr_ppoll                        = 73;
+        syscall_nr_signalfd4                    = 74;
+        syscall_nr_vmsplice                     = 75;
+        syscall_nr_splice                       = 76;
+        syscall_nr_tee                          = 77;
+        syscall_nr_readlinkat                   = 78;
+        syscall_nr_fstatat                      = 79;
+        syscall_nr_fstat                        = 80;
+        syscall_nr_sync                         = 81;
+        syscall_nr_fsync                        = 82;
+        syscall_nr_fdatasync                    = 83;
+        syscall_nr_sync_file_range              = 84;
+        syscall_nr_timerfd_create               = 85;
+        syscall_nr_timerfd_settime              = 86;
+        syscall_nr_timerfd_gettime              = 87;
+        syscall_nr_utimensat                    = 88;
+        syscall_nr_acct                         = 89;
+        syscall_nr_capget                       = 90;
+        syscall_nr_capset                       = 91;
+        syscall_nr_personality                  = 92;
+        syscall_nr_exit                         = 93;
+        syscall_nr_exit_group                   = 94;
+        syscall_nr_waitid                       = 95;
+        syscall_nr_set_tid_address              = 96;
+        syscall_nr_unshare                      = 97;
+        syscall_nr_futex                        = 98;
+        syscall_nr_set_robust_list              = 99;
+        syscall_nr_get_robust_list              = 100;
+        syscall_nr_nanosleep                    = 101;
+        syscall_nr_getitimer                    = 102;
+        syscall_nr_setitimer                    = 103;
+        syscall_nr_kexec_load                   = 104;
+        syscall_nr_init_module                  = 105;
+        syscall_nr_delete_module                = 106;
+        syscall_nr_timer_create                 = 107;
+        syscall_nr_timer_gettime                = 108;
+        syscall_nr_timer_getoverrun             = 109;
+        syscall_nr_timer_settime                = 110;
+        syscall_nr_timer_delete                 = 111;
+        syscall_nr_clock_settime                = 112;
+        syscall_nr_clock_gettime                = 113;
+        syscall_nr_clock_getres                 = 114;
+        syscall_nr_clock_nanosleep              = 115;
+        syscall_nr_syslog                       = 116;
+        syscall_nr_ptrace                       = 117;
+        syscall_nr_sched_setparam               = 118;
+        syscall_nr_sched_setscheduler           = 119;
+        syscall_nr_sched_getscheduler           = 120;
+        syscall_nr_sched_getparam               = 121;
+        syscall_nr_sched_setaffinity            = 122;
+        syscall_nr_sched_getaffinity            = 123;
+        syscall_nr_sched_yield                  = 124;
+        syscall_nr_sched_get_priority_max       = 125;
+        syscall_nr_sched_get_priority_min       = 126;
+        syscall_nr_sched_rr_get_interval        = 127;
+        syscall_nr_restart_syscall              = 128;
+        syscall_nr_kill                         = 129;
+        syscall_nr_tkill                        = 130;
+        syscall_nr_tgkill                       = 131;
+        syscall_nr_sigaltstack                  = 132;
+        syscall_nr_rt_sigsuspend                = 133;
+        syscall_nr_rt_sigaction                 = 134;
+        syscall_nr_rt_sigprocmask               = 135;
+        syscall_nr_rt_sigpending                = 136;
+        syscall_nr_rt_sigtimedwait              = 137;
+        syscall_nr_rt_sigqueueinfo              = 138;
+        syscall_nr_rt_sigreturn                 = 139;
+        syscall_nr_setpriority                  = 140;
+        syscall_nr_getpriority                  = 141;
+        syscall_nr_reboot                       = 142;
+        syscall_nr_setregid                     = 143;
+        syscall_nr_setgid                       = 144;
+        syscall_nr_setreuid                     = 145;
+        syscall_nr_setuid                       = 146;
+        syscall_nr_setresuid                    = 147;
+        syscall_nr_getresuid                    = 148;
+        syscall_nr_setresgid                    = 149;
+        syscall_nr_getresgid                    = 150;
+        syscall_nr_setfsuid                     = 151;
+        syscall_nr_setfsgid                     = 152;
+        syscall_nr_times                        = 153;
+        syscall_nr_setpgid                      = 154;
+        syscall_nr_getpgid                      = 155;
+        syscall_nr_getsid                       = 156;
+        syscall_nr_setsid                       = 157;
+        syscall_nr_getgroups                    = 158;
+        syscall_nr_setgroups                    = 159;
+        syscall_nr_uname                        = 160;
+        syscall_nr_sethostname                  = 161;
+        syscall_nr_setdomainname                = 162;
+        syscall_nr_getrlimit                    = 163;
+        syscall_nr_setrlimit                    = 164;
+        syscall_nr_getrusage                    = 165;
+        syscall_nr_umask                        = 166;
+        syscall_nr_prctl                        = 167;
+        syscall_nr_getcpu                       = 168;
+        syscall_nr_gettimeofday                 = 169;
+        syscall_nr_settimeofday                 = 170;
+        syscall_nr_adjtimex                     = 171;
+        syscall_nr_getpid                       = 172;
+        syscall_nr_getppid                      = 173;
+        syscall_nr_getuid                       = 174;
+        syscall_nr_geteuid                      = 175;
+        syscall_nr_getgid                       = 176;
+        syscall_nr_getegid                      = 177;
+        syscall_nr_gettid                       = 178;
+        syscall_nr_sysinfo                      = 179;
+        syscall_nr_mq_open                      = 180;
+        syscall_nr_mq_unlink                    = 181;
+        syscall_nr_mq_timedsend                 = 182;
+        syscall_nr_mq_timedreceive              = 183;
+        syscall_nr_mq_notify                    = 184;
+        syscall_nr_mq_getsetattr                = 185;
+        syscall_nr_msgget                       = 186;
+        syscall_nr_msgctl                       = 187;
+        syscall_nr_msgrcv                       = 188;
+        syscall_nr_msgsnd                       = 189;
+        syscall_nr_semget                       = 190;
+        syscall_nr_semctl                       = 191;
+        syscall_nr_semtimedop                   = 192;
+        syscall_nr_semop                        = 193;
+        syscall_nr_shmget                       = 194;
+        syscall_nr_shmctl                       = 195;
+        syscall_nr_shmat                        = 196;
+        syscall_nr_shmdt                        = 197;
+        syscall_nr_socket                       = 198;
+        syscall_nr_socketpair                   = 199;
+        syscall_nr_bind                         = 200;
+        syscall_nr_listen                       = 201;
+        syscall_nr_accept                       = 202;
+        syscall_nr_connect                      = 203;
+        syscall_nr_getsockname                  = 204;
+        syscall_nr_getpeername                  = 205;
+        syscall_nr_sendto                       = 206;
+        syscall_nr_recvfrom                     = 207;
+        syscall_nr_setsockopt                   = 208;
+        syscall_nr_getsockopt                   = 209;
+        syscall_nr_shutdown                     = 210;
+        syscall_nr_sendmsg                      = 211;
+        syscall_nr_recvmsg                      = 212;
+        syscall_nr_readahead                    = 213;
+        syscall_nr_brk                          = 214;
+        syscall_nr_munmap                       = 215;
+        syscall_nr_mremap                       = 216;
+        syscall_nr_add_key                      = 217;
+        syscall_nr_request_key                  = 218;
+        syscall_nr_keyctl                       = 219;
+        syscall_nr_clone                        = 220;
+        syscall_nr_execve                       = 221;
+        syscall_nr_mmap                         = 222;
+        syscall_nr_fadvise64                    = 223;
+        syscall_nr_swapon                       = 224;
+        syscall_nr_swapoff                      = 225;
+        syscall_nr_mprotect                     = 226;
+        syscall_nr_msync                        = 227;
+        syscall_nr_mlock                        = 228;
+        syscall_nr_munlock                      = 229;
+        syscall_nr_mlockall                     = 230;
+        syscall_nr_munlockall                   = 231;
+        syscall_nr_mincore                      = 232;
+        syscall_nr_madvise                      = 233;
+        syscall_nr_remap_file_pages             = 234;
+        syscall_nr_mbind                        = 235;
+        syscall_nr_get_mempolicy                = 236;
+        syscall_nr_set_mempolicy                = 237;
+        syscall_nr_migrate_pages                = 238;
+        syscall_nr_move_pages                   = 239;
+        syscall_nr_rt_tgsigqueueinfo            = 240;
+        syscall_nr_perf_event_open              = 241;
+        syscall_nr_accept4                      = 242;
+        syscall_nr_recvmmsg                     = 243;
+        syscall_nr_arch_specific_syscall        = 244;
+
+        syscall_nr_wait4                        = 260;
+        syscall_nr_prlimit64                    = 261;
+        syscall_nr_fanotify_init                = 262;
+        syscall_nr_fanotify_mark                = 263;
+        syscall_nr_name_to_handle_at            = 264;
+        syscall_nr_open_by_handle_at            = 265;
+        syscall_nr_clock_adjtime                = 266;
+        syscall_nr_syncfs                       = 267;
+        syscall_nr_setns                        = 268;
+        syscall_nr_sendmmsg                     = 269;
+        syscall_nr_process_vm_readv             = 270;
+        syscall_nr_process_vm_writev            = 271;
+        syscall_nr_kcmp                         = 272;
+        syscall_nr_finit_module                 = 273;
+        syscall_nr_sched_setattr                = 274;
+        syscall_nr_sched_getattr                = 275;
+        syscall_nr_renameat2                    = 276;
+        syscall_nr_seccomp                      = 277;
+        syscall_nr_getrandom                    = 278;
+        syscall_nr_memfd_create                 = 279;
+        syscall_nr_bpf                          = 280;
+        syscall_nr_execveat                     = 281;
+        syscall_nr_syscalls                     = 282;
diff --git a/rtl/linux/termios.inc b/rtl/linux/termios.inc
index 78cfb03..7554839 100644
--- a/rtl/linux/termios.inc
+++ b/rtl/linux/termios.inc
@@ -22,6 +22,271 @@ Const
   NCCS = 32;
   NCC = 8;
 
+{$ifdef cpuaarch64}
+
+{ from Linux 4.0, include/uapi/asm-generic/ioctls.h }
+
+  { For Terminal handling }
+  TCGETS          = $5401;
+  TCSETS          = $5402;
+  TCSETSW         = $5403;
+  TCSETSF         = $5404;
+  TCGETA          = $5405;
+  TCSETA          = $5406;
+  TCSETAW         = $5407;
+  TCSETAF         = $5408;
+  TCSBRK          = $5409;
+  TCXONC          = $540A;
+  TCFLSH          = $540B;
+  TIOCEXCL        = $540C;
+  TIOCNXCL        = $540D;
+  TIOCSCTTY       = $540E;
+  TIOCGPGRP       = $540F;
+  TIOCSPGRP       = $5410;
+  TIOCOUTQ        = $5411;
+  TIOCSTI         = $5412;
+  TIOCGWINSZ      = $5413;
+  TIOCSWINSZ      = $5414;
+  TIOCMGET        = $5415;
+  TIOCMBIS        = $5416;
+  TIOCMBIC        = $5417;
+  TIOCMSET        = $5418;
+  TIOCGSOFTCAR    = $5419;
+  TIOCSSOFTCAR    = $541A;
+  FIONREAD        = $541B;
+  TIOCINQ         = FIONREAD;
+  TIOCLINUX       = $541C;
+  TIOCCONS        = $541D;
+  TIOCGSERIAL     = $541E;
+  TIOCSSERIAL     = $541F;
+  TIOCPKT         = $5420;
+  FIONBIO         = $5421;
+  TIOCNOTTY       = $5422;
+  TIOCSETD        = $5423;
+  TIOCGETD        = $5424;
+  TCSBRKP         = $5425;
+
+  TIOCSBRK        = $5427;
+  TIOCCBRK        = $5428;
+  TIOCGSID        = $5429;
+
+  TIOCGRS485      = $542E;
+  TIOCSRS485      = $542F;
+
+  TCGETX          = $5432;
+  TCSETX          = $5433;
+  TCSETXF         = $5434;
+  TCSETXW         = $5435;
+  TIOCVHANGUP     = $5437;
+
+  FIONCLEX        = $5450;
+  FIOCLEX         = $5451;
+  FIOASYNC        = $5452;
+  TIOCSERCONFIG   = $5453;
+  TIOCSERGWILD    = $5454;
+  TIOCSERSWILD    = $5455;
+  TIOCGLCKTRMIOS  = $5456;
+  TIOCSLCKTRMIOS  = $5457;
+  TIOCSERGSTRUCT  = $5458;
+  TIOCSERGETLSR   = $5459;
+  TIOCSERGETMULTI = $545A;
+  TIOCSERSETMULTI = $545B;
+  TIOCMIWAIT      = $545C;
+  TIOCGICOUNT     = $545D;
+
+  FIOQSIZE        = $5460;
+
+  TIOCPKT_DATA       = 0;
+  TIOCPKT_FLUSHREAD  = 1;
+  TIOCPKT_FLUSHWRITE = 2;
+  TIOCPKT_STOP       = 4;
+  TIOCPKT_START      = 8;
+  TIOCPKT_NOSTOP     = 16;
+  TIOCPKT_DOSTOP     = 32;
+  TIOCPKT_IOCTL      = 64;
+
+  TIOCSER_TEMT       = $01;
+
+{ from Linux 4.0, include/uapi/asm-generic/termbits.h }
+
+  { c_cc characters }
+  VINTR    = 0;
+  VQUIT    = 1;
+  VERASE   = 2;
+  VKILL    = 3;
+  VEOF     = 4;
+  VTIME    = 5;
+  VMIN     = 6;
+  VSWTC    = 7;
+  VSTART   = 8;
+  VSTOP    = 9;
+  VSUSP    = 10;
+  VEOL     = 11;
+  VREPRINT = 12;
+  VDISCARD = 13;
+  VWERASE  = 14;
+  VLNEXT   = 15;
+  VEOL2    = 16;
+
+  { c_iflag bits }
+  IGNBRK  = &0000001;
+  BRKINT  = &0000002;
+  IGNPAR  = &0000004;
+  PARMRK  = &0000010;
+  INPCK   = &0000020;
+  ISTRIP  = &0000040;
+  INLCR   = &0000100;
+  IGNCR   = &0000200;
+  ICRNL   = &0000400;
+  IUCLC   = &0001000;
+  IXON    = &0002000;
+  IXANY   = &0004000;
+  IXOFF   = &0010000;
+  IMAXBEL = &0020000;
+  IUTF8   = &0040000;
+
+  { c_oflag bits }
+  OPOST  = &0000001;
+  OLCUC  = &0000002;
+  ONLCR  = &0000004;
+  OCRNL  = &0000010;
+  ONOCR  = &0000020;
+  ONLRET = &0000040;
+  OFILL  = &0000100;
+  OFDEL  = &0000200;
+  NLDLY  = &0000400;
+  NL0    = &0000000;
+  NL1    = &0000400;
+  CRDLY  = &0003000;
+  CR0    = &0000000;
+  CR1    = &0001000;
+  CR2    = &0002000;
+  CR3    = &0003000;
+  TABDLY = &0014000;
+  TAB0   = &0000000;
+  TAB1   = &0004000;
+  TAB2   = &0010000;
+  TAB3   = &0014000;
+  XTABS  = &0014000;
+  BSDLY  = &0020000;
+  BS0    = &0000000;
+  BS1    = &0020000;
+  VTDLY  = &0040000;
+  VT0    = &0000000;
+  VT1    = &0040000;
+  FFDLY  = &0100000;
+  FF0    = &0000000;
+  FF1    = &0100000;
+
+  { c_cflag bits }
+  CBAUD    = &0010017;
+  B0       = &0000000;
+  B50      = &0000001;
+  B75      = &0000002;
+  B110     = &0000003;
+  B134     = &0000004;
+  B150     = &0000005;
+  B200     = &0000006;
+  B300     = &0000007;
+  B600     = &0000010;
+  B1200    = &0000011;
+  B1800    = &0000012;
+  B2400    = &0000013;
+  B4800    = &0000014;
+  B9600    = &0000015;
+  B19200   = &0000016;
+  B38400   = &0000017;
+  EXTA     = B19200;
+  EXTB     = B38400;
+  CSIZE    = &0000060;
+  CS5      = &0000000;
+  CS6      = &0000020;
+  CS7      = &0000040;
+  CS8      = &0000060;
+  CSTOPB   = &0000100;
+  CREAD    = &0000200;
+  PARENB   = &0000400;
+  PARODD   = &0001000;
+  HUPCL    = &0002000;
+  CLOCAL   = &0004000;
+  CBAUDEX  = &0010000;
+  BOTHER   = &0010000;
+  B57600   = &0010001;
+  B115200  = &0010002;
+  B230400  = &0010003;
+  B460800  = &0010004;
+  B500000  = &0010005;
+  B576000  = &0010006;
+  B921600  = &0010007;
+  B1000000 = &0010010;
+  B1152000 = &0010011;
+  B1500000 = &0010012;
+  B2000000 = &0010013;
+  B2500000 = &0010014;
+  B3000000 = &0010015;
+  B3500000 = &0010016;
+  B4000000 = &0010017;
+
+  CIBAUD   = &002003600000;
+  CMSPAR   = &010000000000;
+  CRTSCTS  = &020000000000;
+
+  IBSHIFT  = 16;
+
+  { c_lflag bits }
+  ISIG    = &0000001;
+  ICANON  = &0000002;
+  XCASE   = &0000004;
+  ECHO    = &0000010;
+  ECHOE   = &0000020;
+  ECHOK   = &0000040;
+  ECHONL  = &0000100;
+  NOFLSH  = &0000200;
+  TOSTOP  = &0000400;
+  ECHOCTL = &0001000;
+  ECHOPRT = &0002000;
+  ECHOKE  = &0004000;
+  FLUSHO  = &0010000;
+  PENDIN  = &0040000;
+  IEXTEN  = &0100000;
+  EXTPROC = &0200000;
+
+  { TCFlow }
+  TCOOFF = 0;
+  TCOON  = 1;
+  TCIOFF = 2;
+  TCION  = 3;
+
+  { TCFlush }
+  TCIFLUSH  = 0;
+  TCOFLUSH  = 1;
+  TCIOFLUSH = 2;
+
+  { TCSetAttr }
+  TCSANOW   = 0;
+  TCSADRAIN = 1;
+  TCSAFLUSH = 2;
+
+{ from Linux 4.0, include/uapi/asm-generic/termios.h }
+
+  { c_line bits }
+  TIOCM_LE   = $001;
+  TIOCM_DTR  = $002;
+  TIOCM_RTS  = $004;
+  TIOCM_ST   = $008;
+  TIOCM_SR   = $010;
+  TIOCM_CTS  = $020;
+  TIOCM_CAR  = $040;
+  TIOCM_RNG  = $080;
+  TIOCM_DSR  = $100;
+  TIOCM_CD   = TIOCM_CAR;
+  TIOCM_RI   = TIOCM_RNG;
+  TIOCM_OUT1 = $2000;
+  TIOCM_OUT2 = $4000;
+  TIOCM_LOOP = $8000;
+
+{$endif cpuaarch64}
+
 {$ifdef cpupowerpc}
   TCGETS            = $402c7413;
   TCSETS            = $802c7414;



More information about the fpc-devel mailing list