summaryrefslogtreecommitdiff
path: root/rtl/linux
diff options
context:
space:
mode:
authorflorian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2>2018-09-26 19:49:08 +0000
committerflorian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2>2018-09-26 19:49:08 +0000
commit844935a6ffbca5d7ae4758de3aa4ef8496543f3a (patch)
tree4cc43a6480f3e1a1702fda012b2da986a015a0b3 /rtl/linux
parentacb2f648fb97fdc281287b6cdb3d0ca2a537ae7a (diff)
downloadfpc-844935a6ffbca5d7ae4758de3aa4ef8496543f3a.tar.gz
Merged riscv_new branch
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@39813 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'rtl/linux')
-rw-r--r--rtl/linux/Makefile109
-rw-r--r--rtl/linux/Makefile.fpc11
-rw-r--r--rtl/linux/osdefs.inc11
-rw-r--r--rtl/linux/ossysc.inc6
-rw-r--r--rtl/linux/ostypes.inc2
-rw-r--r--rtl/linux/riscv32/bsyscall.inc1
-rw-r--r--rtl/linux/riscv32/cprt0.as139
-rw-r--r--rtl/linux/riscv32/dllprt0.as80
-rw-r--r--rtl/linux/riscv32/gprt0.as118
-rw-r--r--rtl/linux/riscv32/prt0.as85
-rw-r--r--rtl/linux/riscv32/sighnd.inc44
-rw-r--r--rtl/linux/riscv32/sighndh.inc47
-rw-r--r--rtl/linux/riscv32/stat.inc72
-rw-r--r--rtl/linux/riscv32/syscall.inc141
-rw-r--r--rtl/linux/riscv32/syscallh.inc35
-rw-r--r--rtl/linux/riscv32/sysnr.inc1
-rw-r--r--rtl/linux/riscv64/bsyscall.inc1
-rw-r--r--rtl/linux/riscv64/cprt0.as142
-rw-r--r--rtl/linux/riscv64/dllprt0.as76
-rw-r--r--rtl/linux/riscv64/gprt0.as162
-rw-r--r--rtl/linux/riscv64/prt0.as85
-rw-r--r--rtl/linux/riscv64/sighnd.inc44
-rw-r--r--rtl/linux/riscv64/sighndh.inc47
-rw-r--r--rtl/linux/riscv64/stat.inc72
-rw-r--r--rtl/linux/riscv64/syscall.inc155
-rw-r--r--rtl/linux/riscv64/syscallh.inc35
-rw-r--r--rtl/linux/riscv64/sysnr.inc1
-rw-r--r--rtl/linux/system.pp6
-rw-r--r--rtl/linux/termios.inc530
29 files changed, 2253 insertions, 5 deletions
diff --git a/rtl/linux/Makefile b/rtl/linux/Makefile
index cbfa477252..fb0beb2fb9 100644
--- a/rtl/linux/Makefile
+++ b/rtl/linux/Makefile
@@ -1,8 +1,8 @@
#
-# Don't edit, this file is generated by FPCMake Version 2.0.0
+# Don't edit, this file is generated by FPCMake Version 2.0.0 [2018-07-20 rev 39474]
#
default: all
-MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian i386-nativent i386-iphonesim i386-android i386-aros m68k-linux m68k-netbsd m68k-amiga m68k-atari m68k-palmos m68k-macos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded powerpc-wii powerpc-aix sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-netbsd x86_64-solaris x86_64-openbsd x86_64-darwin x86_64-win64 x86_64-embedded x86_64-iphonesim x86_64-aros x86_64-dragonfly arm-linux arm-netbsd arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian arm-android arm-aros powerpc64-linux powerpc64-darwin powerpc64-embedded powerpc64-aix avr-embedded armeb-linux armeb-embedded mips-linux mipsel-linux mipsel-embedded mipsel-android jvm-java jvm-android i8086-embedded i8086-msdos i8086-win16 aarch64-linux aarch64-darwin wasm-wasm sparc64-linux
+MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian i386-nativent i386-iphonesim i386-android i386-aros m68k-linux m68k-netbsd m68k-amiga m68k-atari m68k-palmos m68k-macos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded powerpc-wii powerpc-aix sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-netbsd x86_64-solaris x86_64-openbsd x86_64-darwin x86_64-win64 x86_64-embedded x86_64-iphonesim x86_64-aros x86_64-dragonfly arm-linux arm-netbsd arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian arm-android arm-aros powerpc64-linux powerpc64-darwin powerpc64-embedded powerpc64-aix avr-embedded armeb-linux armeb-embedded mips-linux mipsel-linux mipsel-embedded mipsel-android jvm-java jvm-android i8086-embedded i8086-msdos i8086-win16 aarch64-linux aarch64-darwin wasm-wasm sparc64-linux riscv32-linux riscv32-embedded riscv64-linux riscv64-embedded
BSDs = freebsd netbsd openbsd darwin dragonfly
UNIXs = linux $(BSDs) solaris qnx haiku aix
LIMIT83fs = go32v2 os2 emx watcom msdos win16 atari
@@ -360,6 +360,9 @@ ifeq ($(ARCH),sparc64)
override LOADERS=
SYSINIT_UNITS=si_prc si_c si_g si_dll
endif
+ifeq ($(ARCH),riscv64)
+override LOADERS=prt0 cprt0 dllprt0
+endif
ifeq ($(ARCH),mipsel)
override FPCOPT+=-Ur
endif
@@ -633,6 +636,18 @@ endif
ifeq ($(FULL_TARGET),sparc64-linux)
override TARGET_UNITS+=$(SYSTEMUNIT) fpintres $(SYSINIT_UNITS) uuchar unixtype ctypes baseunix strings objpas macpas iso7185 extpas syscall unixutil heaptrc lineinfo lnfodwrf termio unix linux initc cmem $(CPU_UNITS) linuxvcs sysutils typinfo math charset cpall character unixcp getopts errors dl dynlibs types sysconst fpwidestring cthreads classes fgl rtlconsts dos cwstring fpcylix softfpu sfpux80 ufloatx80 sfpu128 ufloat128
endif
+ifeq ($(FULL_TARGET),riscv32-linux)
+override TARGET_UNITS+=$(SYSTEMUNIT) fpintres $(SYSINIT_UNITS) uuchar unixtype ctypes baseunix strings objpas macpas iso7185 extpas syscall unixutil heaptrc lineinfo lnfodwrf termio unix linux initc cmem $(CPU_UNITS) linuxvcs sysutils typinfo math charset cpall character unixcp getopts errors dl dynlibs types sysconst fpwidestring cthreads classes fgl rtlconsts dos cwstring fpcylix softfpu sfpux80 ufloatx80 sfpu128 ufloat128
+endif
+ifeq ($(FULL_TARGET),riscv32-embedded)
+override TARGET_UNITS+=$(SYSTEMUNIT) fpintres $(SYSINIT_UNITS) uuchar unixtype ctypes baseunix strings objpas macpas iso7185 extpas syscall unixutil heaptrc lineinfo lnfodwrf termio unix linux initc cmem $(CPU_UNITS) linuxvcs sysutils typinfo math charset cpall character unixcp getopts errors dl dynlibs types sysconst fpwidestring cthreads classes fgl rtlconsts dos cwstring fpcylix softfpu sfpux80 ufloatx80 sfpu128 ufloat128
+endif
+ifeq ($(FULL_TARGET),riscv64-linux)
+override TARGET_UNITS+=$(SYSTEMUNIT) fpintres $(SYSINIT_UNITS) uuchar unixtype ctypes baseunix strings objpas macpas iso7185 extpas syscall unixutil heaptrc lineinfo lnfodwrf termio unix linux initc cmem $(CPU_UNITS) linuxvcs sysutils typinfo math charset cpall character unixcp getopts errors dl dynlibs types sysconst fpwidestring cthreads classes fgl rtlconsts dos cwstring fpcylix softfpu sfpux80 ufloatx80 sfpu128 ufloat128
+endif
+ifeq ($(FULL_TARGET),riscv64-embedded)
+override TARGET_UNITS+=$(SYSTEMUNIT) fpintres $(SYSINIT_UNITS) uuchar unixtype ctypes baseunix strings objpas macpas iso7185 extpas syscall unixutil heaptrc lineinfo lnfodwrf termio unix linux initc cmem $(CPU_UNITS) linuxvcs sysutils typinfo math charset cpall character unixcp getopts errors dl dynlibs types sysconst fpwidestring cthreads classes fgl rtlconsts dos cwstring fpcylix softfpu sfpux80 ufloatx80 sfpu128 ufloat128
+endif
ifeq ($(FULL_TARGET),i386-linux)
override TARGET_IMPLICITUNITS+=exeinfo cp1250 cp1251 cp1252 cp1253 cp1254 cp1255 cp1256 cp1257 cp1258 cp437 cp646 cp737 cp775 cp850 cp852 cp855 cp856 cp857 cp860 cp861 cp862 cp863 cp864 cp865 cp866 cp869 cp874 cp3021 cp8859_1 cp8859_2 cp8859_3 cp8859_4 cp8859_5 cp8859_6 cp8859_7 cp8859_8 cp8859_9 cp8859_10 cp8859_11 cp8859_13 cp8859_14 cp8859_15 cp8859_16 cpkoi8_r cpkoi8_u unicodedata unicodenumtable
endif
@@ -888,6 +903,18 @@ endif
ifeq ($(FULL_TARGET),sparc64-linux)
override TARGET_IMPLICITUNITS+=exeinfo cp1250 cp1251 cp1252 cp1253 cp1254 cp1255 cp1256 cp1257 cp1258 cp437 cp646 cp737 cp775 cp850 cp852 cp855 cp856 cp857 cp860 cp861 cp862 cp863 cp864 cp865 cp866 cp869 cp874 cp3021 cp8859_1 cp8859_2 cp8859_3 cp8859_4 cp8859_5 cp8859_6 cp8859_7 cp8859_8 cp8859_9 cp8859_10 cp8859_11 cp8859_13 cp8859_14 cp8859_15 cp8859_16 cpkoi8_r cpkoi8_u unicodedata unicodenumtable
endif
+ifeq ($(FULL_TARGET),riscv32-linux)
+override TARGET_IMPLICITUNITS+=exeinfo cp1250 cp1251 cp1252 cp1253 cp1254 cp1255 cp1256 cp1257 cp1258 cp437 cp646 cp737 cp775 cp850 cp852 cp855 cp856 cp857 cp860 cp861 cp862 cp863 cp864 cp865 cp866 cp869 cp874 cp3021 cp8859_1 cp8859_2 cp8859_3 cp8859_4 cp8859_5 cp8859_6 cp8859_7 cp8859_8 cp8859_9 cp8859_10 cp8859_11 cp8859_13 cp8859_14 cp8859_15 cp8859_16 cpkoi8_r cpkoi8_u unicodedata unicodenumtable
+endif
+ifeq ($(FULL_TARGET),riscv32-embedded)
+override TARGET_IMPLICITUNITS+=exeinfo cp1250 cp1251 cp1252 cp1253 cp1254 cp1255 cp1256 cp1257 cp1258 cp437 cp646 cp737 cp775 cp850 cp852 cp855 cp856 cp857 cp860 cp861 cp862 cp863 cp864 cp865 cp866 cp869 cp874 cp3021 cp8859_1 cp8859_2 cp8859_3 cp8859_4 cp8859_5 cp8859_6 cp8859_7 cp8859_8 cp8859_9 cp8859_10 cp8859_11 cp8859_13 cp8859_14 cp8859_15 cp8859_16 cpkoi8_r cpkoi8_u unicodedata unicodenumtable
+endif
+ifeq ($(FULL_TARGET),riscv64-linux)
+override TARGET_IMPLICITUNITS+=exeinfo cp1250 cp1251 cp1252 cp1253 cp1254 cp1255 cp1256 cp1257 cp1258 cp437 cp646 cp737 cp775 cp850 cp852 cp855 cp856 cp857 cp860 cp861 cp862 cp863 cp864 cp865 cp866 cp869 cp874 cp3021 cp8859_1 cp8859_2 cp8859_3 cp8859_4 cp8859_5 cp8859_6 cp8859_7 cp8859_8 cp8859_9 cp8859_10 cp8859_11 cp8859_13 cp8859_14 cp8859_15 cp8859_16 cpkoi8_r cpkoi8_u unicodedata unicodenumtable
+endif
+ifeq ($(FULL_TARGET),riscv64-embedded)
+override TARGET_IMPLICITUNITS+=exeinfo cp1250 cp1251 cp1252 cp1253 cp1254 cp1255 cp1256 cp1257 cp1258 cp437 cp646 cp737 cp775 cp850 cp852 cp855 cp856 cp857 cp860 cp861 cp862 cp863 cp864 cp865 cp866 cp869 cp874 cp3021 cp8859_1 cp8859_2 cp8859_3 cp8859_4 cp8859_5 cp8859_6 cp8859_7 cp8859_8 cp8859_9 cp8859_10 cp8859_11 cp8859_13 cp8859_14 cp8859_15 cp8859_16 cpkoi8_r cpkoi8_u unicodedata unicodenumtable
+endif
ifeq ($(FULL_TARGET),i386-linux)
override TARGET_LOADERS+=$(LOADERS)
endif
@@ -1143,6 +1170,18 @@ endif
ifeq ($(FULL_TARGET),sparc64-linux)
override TARGET_LOADERS+=$(LOADERS)
endif
+ifeq ($(FULL_TARGET),riscv32-linux)
+override TARGET_LOADERS+=$(LOADERS)
+endif
+ifeq ($(FULL_TARGET),riscv32-embedded)
+override TARGET_LOADERS+=$(LOADERS)
+endif
+ifeq ($(FULL_TARGET),riscv64-linux)
+override TARGET_LOADERS+=$(LOADERS)
+endif
+ifeq ($(FULL_TARGET),riscv64-embedded)
+override TARGET_LOADERS+=$(LOADERS)
+endif
ifeq ($(FULL_TARGET),i386-linux)
override TARGET_RSTS+=math typinfo sysconst rtlconsts
endif
@@ -1398,6 +1437,18 @@ endif
ifeq ($(FULL_TARGET),sparc64-linux)
override TARGET_RSTS+=math typinfo sysconst rtlconsts
endif
+ifeq ($(FULL_TARGET),riscv32-linux)
+override TARGET_RSTS+=math typinfo sysconst rtlconsts
+endif
+ifeq ($(FULL_TARGET),riscv32-embedded)
+override TARGET_RSTS+=math typinfo sysconst rtlconsts
+endif
+ifeq ($(FULL_TARGET),riscv64-linux)
+override TARGET_RSTS+=math typinfo sysconst rtlconsts
+endif
+ifeq ($(FULL_TARGET),riscv64-embedded)
+override TARGET_RSTS+=math typinfo sysconst rtlconsts
+endif
ifeq ($(FULL_TARGET),i386-linux)
override CLEAN_UNITS+=syslinux linux
endif
@@ -1653,6 +1704,18 @@ endif
ifeq ($(FULL_TARGET),sparc64-linux)
override CLEAN_UNITS+=syslinux linux
endif
+ifeq ($(FULL_TARGET),riscv32-linux)
+override CLEAN_UNITS+=syslinux linux
+endif
+ifeq ($(FULL_TARGET),riscv32-embedded)
+override CLEAN_UNITS+=syslinux linux
+endif
+ifeq ($(FULL_TARGET),riscv64-linux)
+override CLEAN_UNITS+=syslinux linux
+endif
+ifeq ($(FULL_TARGET),riscv64-embedded)
+override CLEAN_UNITS+=syslinux linux
+endif
override INSTALL_FPCPACKAGE=y
ifeq ($(FULL_TARGET),i386-linux)
override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC) $(UNIXINC) $(ARCH)
@@ -1909,6 +1972,18 @@ endif
ifeq ($(FULL_TARGET),sparc64-linux)
override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC) $(UNIXINC) $(ARCH)
endif
+ifeq ($(FULL_TARGET),riscv32-linux)
+override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC) $(UNIXINC) $(ARCH)
+endif
+ifeq ($(FULL_TARGET),riscv32-embedded)
+override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC) $(UNIXINC) $(ARCH)
+endif
+ifeq ($(FULL_TARGET),riscv64-linux)
+override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC) $(UNIXINC) $(ARCH)
+endif
+ifeq ($(FULL_TARGET),riscv64-embedded)
+override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC) $(UNIXINC) $(ARCH)
+endif
ifeq ($(FULL_TARGET),i386-linux)
override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(UNIXINC) $(ARCH) $(COMMON)
endif
@@ -2164,6 +2239,18 @@ endif
ifeq ($(FULL_TARGET),sparc64-linux)
override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(UNIXINC) $(ARCH) $(COMMON)
endif
+ifeq ($(FULL_TARGET),riscv32-linux)
+override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(UNIXINC) $(ARCH) $(COMMON)
+endif
+ifeq ($(FULL_TARGET),riscv32-embedded)
+override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(UNIXINC) $(ARCH) $(COMMON)
+endif
+ifeq ($(FULL_TARGET),riscv64-linux)
+override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(UNIXINC) $(ARCH) $(COMMON)
+endif
+ifeq ($(FULL_TARGET),riscv64-embedded)
+override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(UNIXINC) $(ARCH) $(COMMON)
+endif
ifeq ($(FULL_TARGET),i386-linux)
override COMPILER_TARGETDIR+=.
endif
@@ -2419,6 +2506,18 @@ endif
ifeq ($(FULL_TARGET),sparc64-linux)
override COMPILER_TARGETDIR+=.
endif
+ifeq ($(FULL_TARGET),riscv32-linux)
+override COMPILER_TARGETDIR+=.
+endif
+ifeq ($(FULL_TARGET),riscv32-embedded)
+override COMPILER_TARGETDIR+=.
+endif
+ifeq ($(FULL_TARGET),riscv64-linux)
+override COMPILER_TARGETDIR+=.
+endif
+ifeq ($(FULL_TARGET),riscv64-embedded)
+override COMPILER_TARGETDIR+=.
+endif
override SHARED_LIBUNITS=$(SYSTEMUNIT) objpas strings dos unix baseunix unixtype unixutil sysutils typinfo math $(CPU_UNITS) getopts errors classes fgl sysconst rtlconsts types
ifdef REQUIRE_UNITSDIR
override UNITSDIR+=$(REQUIRE_UNITSDIR)
@@ -3700,6 +3799,12 @@ ifeq ($(ARCH),sparc64)
SYSNRINC=sparcgen/sysnr.inc
ASSHAREDOPT=-KPIC
endif
+ifeq ($(ARCH),riscv32)
+ ASTARGET=-march=rv32imafdc
+endif
+ifeq ($(ARCH),riscv64)
+ ASTARGET=-march=rv64imafdc
+endif
ifeq ($(ARCH),arm)
ifeq ($(SUBARCH),armv6m)
ASTARGET+=-mthumb --def __thumb__=1
diff --git a/rtl/linux/Makefile.fpc b/rtl/linux/Makefile.fpc
index d3dbbecc03..835bd8018a 100644
--- a/rtl/linux/Makefile.fpc
+++ b/rtl/linux/Makefile.fpc
@@ -90,6 +90,10 @@ override LOADERS=
SYSINIT_UNITS=si_prc si_c si_g si_dll
endif
+ifeq ($(ARCH),riscv64)
+override LOADERS=prt0 cprt0 dllprt0
+endif
+
# mipsel reuses mips files by including so some file names exist
# twice, this causes the compiler to find sometimes wrong files and it tries
# to recompile rtl units. To prevent this, compile always as release PPUs, this
@@ -196,6 +200,13 @@ ifeq ($(ARCH),sparc64)
ASSHAREDOPT=-KPIC
endif
+ifeq ($(ARCH),riscv32)
+ ASTARGET=-march=rv32imafdc
+endif
+ifeq ($(ARCH),riscv64)
+ ASTARGET=-march=rv64imafdc
+endif
+
ifeq ($(ARCH),arm)
ifeq ($(SUBARCH),armv6m)
ASTARGET+=-mthumb --def __thumb__=1
diff --git a/rtl/linux/osdefs.inc b/rtl/linux/osdefs.inc
index 5460d9a8af..932a483228 100644
--- a/rtl/linux/osdefs.inc
+++ b/rtl/linux/osdefs.inc
@@ -88,12 +88,23 @@
{$ifdef cpuaarch64}
{$define generic_linux_syscalls}
{$undef usestime}
+ {$define userenameat}
{$endif cpuaarch64}
{$ifdef cpusparc64}
{$define FPC_USEGETTIMEOFDAY}
{$endif cpusparc64}
+{$ifdef cpuriscv32}
+ {$define generic_linux_syscalls}
+ {$undef usestime}
+{$endif cpuriscv32}
+
+{$ifdef cpuriscv64}
+ {$define generic_linux_syscalls}
+ {$undef usestime}
+{$endif cpuriscv64}
+
{$ifdef android}
{$define generic_linux_syscalls}
{$undef usestime}
diff --git a/rtl/linux/ossysc.inc b/rtl/linux/ossysc.inc
index 3edc485011..d924b9aa8f 100644
--- a/rtl/linux/ossysc.inc
+++ b/rtl/linux/ossysc.inc
@@ -100,7 +100,11 @@ function Fprename(old : pchar; newpath: pchar): cint; [public, alias : 'FPC_SYSC
begin
{$if defined(generic_linux_syscalls)}
- Fprename:=do_syscall(syscall_nr_renameat,AT_FDCWD,TSysParam(old),AT_FDCWD,TSysParam(newpath));
+ {$if defined(userenameat)}
+ Fprename:=do_syscall(syscall_nr_renameat,AT_FDCWD,TSysParam(old),AT_FDCWD,TSysParam(newpath));
+ {$else}
+ Fprename:=do_syscall(syscall_nr_renameat2,AT_FDCWD,TSysParam(old),AT_FDCWD,TSysParam(newpath),0);
+ {$endif}
{$else}
Fprename:=do_syscall(syscall_nr_rename,TSysParam(old),TSysParam(newpath));
{$endif}
diff --git a/rtl/linux/ostypes.inc b/rtl/linux/ostypes.inc
index a43f7e0acf..4244e7ce71 100644
--- a/rtl/linux/ostypes.inc
+++ b/rtl/linux/ostypes.inc
@@ -296,7 +296,7 @@ CONST
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)}
+{$if defined(cpuarm) or defined(cpualpha) or defined(cpublackfin) or defined(cpum68k) or defined(aarch64) or defined(riscv32) or defined(riscv64)}
O_LARGEFILE = $20000;
{$endif}
{$if defined(cpusparc) or defined(cpusparc64)}
diff --git a/rtl/linux/riscv32/bsyscall.inc b/rtl/linux/riscv32/bsyscall.inc
new file mode 100644
index 0000000000..c690ebeb2c
--- /dev/null
+++ b/rtl/linux/riscv32/bsyscall.inc
@@ -0,0 +1 @@
+{ nothing }
diff --git a/rtl/linux/riscv32/cprt0.as b/rtl/linux/riscv32/cprt0.as
new file mode 100644
index 0000000000..5b9474e9c3
--- /dev/null
+++ b/rtl/linux/riscv32/cprt0.as
@@ -0,0 +1,139 @@
+/* Startup code for ARM & ELF
+ Copyright (C) 1995, 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ MA 02110-1301, USA. */
+
+/* This is the canonical entry point, usually the first thing in the text
+ segment.
+
+ Note that the code in the .init section has already been run.
+ This includes _init and _libc_init
+
+
+ At this entry point, most registers' values are unspecified, except:
+
+ a1 Contains a function pointer to be registered with `atexit'.
+ This is how the dynamic linker arranges to have DT_FINI
+ functions called for shared libraries that have been loaded
+ before this code runs.
+
+ sp The stack contains the arguments and environment:
+ 0(sp) argc
+ 4(sp) argv[0]
+ ...
+ (4*argc)(sp) NULL
+ (4*(argc+1))(sp) envp[0]
+ ...
+ NULL
+*/
+
+ .text
+ .globl _start
+ .type _start,function
+_start:
+ /* Clear the frame pointer since this is the outermost frame. */
+ mov fp, #0
+ ldmia sp!, {a2}
+
+ /* Pop argc off the stack and save a pointer to argv */
+ ldr ip,=operatingsystem_parameter_argc
+ ldr a3,=operatingsystem_parameter_argv
+ str a2,[ip]
+
+ /* calc envp */
+ add a4,a2,#1
+ add a4,sp,a4,LSL #2
+ ldr ip,=operatingsystem_parameter_envp
+
+ str sp,[a3]
+ str a4,[ip]
+
+ /* Save initial stackpointer */
+ ldr ip,=__stkptr
+ str sp,[ip]
+
+ /* Fetch address of fini */
+ ldr ip, =_fini
+
+ /* argc already loaded to a2*/
+
+ /* load argv */
+ mov a3, sp
+
+ /* Push stack limit */
+ str a3, [sp, #-4]!
+
+ /* Push rtld_fini */
+ str a1, [sp, #-4]!
+
+ /* Set up the other arguments in registers */
+ ldr a1, =PASCALMAIN
+ ldr a4, =_init
+
+ /* Push fini */
+ str ip, [sp, #-4]!
+
+ /* __libc_start_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
+
+ /* Let the libc call main and exit with its return code. */
+ bl __libc_start_main
+
+ /* should never get here....*/
+ bl abort
+
+ .globl _haltproc
+ .type _haltproc,function
+_haltproc:
+ ldr r0,=operatingsystem_result
+ ldrb r0,[r0]
+ swi 0x900001
+ b _haltproc
+
+ /* Define a symbol for the first piece of initialized data. */
+ .data
+ .globl __data_start
+__data_start:
+ .long 0
+ .weak data_start
+ data_start = __data_start
+
+.bss
+ .comm __stkptr,4
+
+ .comm operatingsystem_parameter_envp,4
+ .comm operatingsystem_parameter_argc,4
+ .comm operatingsystem_parameter_argv,4
+
+ .section ".comment"
+ .byte 0
+ .ascii "generated by FPC http://www.freepascal.org\0"
+
+/* We need this stuff to make gdb behave itself, otherwise
+ gdb will chokes with SIGILL when trying to debug apps.
+*/
+ .section ".note.ABI-tag", "a"
+ .align 4
+ .long 1f - 0f
+ .long 3f - 2f
+ .long 1
+0: .asciz "GNU"
+1: .align 4
+2: .long 0
+ .long 2,0,0
+3: .align 4
+
+.section .note.GNU-stack,"",%progbits
diff --git a/rtl/linux/riscv32/dllprt0.as b/rtl/linux/riscv32/dllprt0.as
new file mode 100644
index 0000000000..a7b7ee585d
--- /dev/null
+++ b/rtl/linux/riscv32/dllprt0.as
@@ -0,0 +1,80 @@
+/*
+ * This file is part of the Free Pascal run time library.
+ * Copyright (c) 2011 by Thomas Schatzl,
+ * member of the Free Pascal development team.
+ *
+ * Startup code for shared libraries, ARM version.
+ *
+ * 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.
+ */
+
+.file "dllprt0.as"
+.text
+ .globl _startlib
+ .type _startlib,function
+_startlib:
+ .globl FPC_SHARED_LIB_START
+ .type FPC_SHARED_LIB_START,function
+FPC_SHARED_LIB_START:
+ sw x1, -4(x2)
+ sw x8, -8(x2)
+ addi x8, x2, 0
+ addi x2, x2, -8
+
+ /* a1 contains argc, a2 contains argv and a3 contains envp */
+ lui x15, %hi(operatingsystem_parameter_argc)
+ addi x15,x15,%lo(operatingsystem_parameter_argc)
+ sw a1, (x15)
+
+ lui x15, %hi(operatingsystem_parameter_argv)
+ addi x15,x15,%lo(operatingsystem_parameter_argv)
+ sw a2, (x15)
+
+ lui x15, %hi(operatingsystem_parameter_envp)
+ addi x15,x15,%lo(operatingsystem_parameter_envp)
+ sw a3, (x15)
+
+ /* save initial stackpointer */
+ lui x15, %hi(__stklen)
+ addi x15,x15,%lo(__stklen)
+ sw x2, (x15)
+
+ /* call main and exit normally */
+ jal x1, PASCALMAIN
+ lw x8, -8(x8)
+ lw x1, -4(x8)
+
+ jalr x0, x1
+
+ .globl _haltproc
+ .type _haltproc,function
+_haltproc:
+ /* reload exitcode */
+ lui x10, %hi(operatingsystem_result)
+ addi x10,x10,%lo(operatingsystem_result)
+ addi x17, x0, 248
+ scall
+ jal x0, _haltproc
+
+.data
+
+ .type operatingsystem_parameters,object
+ .size operatingsystem_parameters,12
+operatingsystem_parameters:
+ .skip 3*4
+ .global operatingsystem_parameter_envp
+ .global operatingsystem_parameter_argc
+ .global operatingsystem_parameter_argv
+ .set operatingsystem_parameter_envp,operatingsystem_parameters+0
+ .set operatingsystem_parameter_argc,operatingsystem_parameters+4
+ .set operatingsystem_parameter_argv,operatingsystem_parameters+8
+
+.bss
+
+ .comm __stkptr,4
+
diff --git a/rtl/linux/riscv32/gprt0.as b/rtl/linux/riscv32/gprt0.as
new file mode 100644
index 0000000000..d7d6337e55
--- /dev/null
+++ b/rtl/linux/riscv32/gprt0.as
@@ -0,0 +1,118 @@
+/*
+ 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
+
+ .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:main_stub
+ ldr x0,[x0,#:got_lo12:main_stub]
+ adrp x3,:got:_init_dummy
+ ldr x3,[x3,#:got_lo12:_init_dummy]
+ adrp x4,:got:_fini_dummy
+ ldr x4,[x4,#:got_lo12:_fini_dummy]
+ bl __libc_start_main
+
+ /* This should never happen */
+ b abort
+
+ .globl _init_dummy
+ .type _init_dummy,#function
+_init_dummy:
+ ret
+
+ .globl _fini_dummy
+ .type _fini_dummy,#function
+_fini_dummy:
+ ret
+
+ .globl main_stub
+ .type main_stub,#function
+main_stub:
+ stp x29,x30,[sp,#-16]!
+
+ /* Save initial stackpointer */
+ mov x0,sp
+ adrp x1,:got:__stkptr
+ ldr x1,[x1,#:got_lo12:__stkptr]
+ str x0,[x1]
+
+ /* Initialize gmon */
+ adrp x0,:got:_start
+ ldr x0,[x0,#:got_lo12:_start]
+ adrp x1,:got:_etext
+ ldr x1,[x1,#:got_lo12:_etext]
+ bl __monstartup
+ adrp x0,:got:_mcleanup
+ ldr x0,[x0,#:got_lo12:_mcleanup]
+ bl atexit
+
+ /* Start the program */
+ bl PASCALMAIN
+ b abort
+
+ .globl _haltproc
+ .type _haltproc,#function
+_haltproc:
+ /* Return to libc */
+ adrp x1,:got:__stkptr
+ ldr x1,[x1,#:got_lo12:__stkptr]
+ ldr x1,[x1]
+ mov sp,x1
+ ldp x29,x30,[sp],#16
+ ret
+
+ /* 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/riscv32/prt0.as b/rtl/linux/riscv32/prt0.as
new file mode 100644
index 0000000000..18f568521f
--- /dev/null
+++ b/rtl/linux/riscv32/prt0.as
@@ -0,0 +1,85 @@
+/*
+ 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:
+ lui x5,%hi(__dl_fini)
+ addi x5,x5,%lo(__dl_fini)
+ sw x10, (x5)
+ jal x0, _start
+
+ .globl _start
+ .type _start, function
+_start:
+ /* Initialise FP to zero */
+ addi x2,x0,0
+
+ /* Get argc, argv, envp */
+ lw x5,(x2)
+ addi x6,x2,8
+ addi x7,x5,1
+ slli x7,x7,3
+ add x7,x6,x7
+
+ /* Save argc, argv, envp, and initial stack pointer */
+ lui x8,%hi(operatingsystem_parameter_argc)
+ addi x8,x8,%lo(operatingsystem_parameter_argc)
+ sw x5,(x8)
+ lui x8,%hi(operatingsystem_parameter_argv)
+ addi x8,x8,%lo(operatingsystem_parameter_argv)
+ sw x6,(x8)
+ lui x8,%hi(operatingsystem_parameter_envp)
+ addi x8,x8,%lo(operatingsystem_parameter_envp)
+ sw x7,(x8)
+ lui x5,%hi(__stkptr)
+ addi x5,x8,%lo(__stkptr)
+ addi x6, x2, 0
+ sw x6,(x5)
+
+ /* Call main */
+ jal x1, PASCALMAIN
+
+ .globl _haltproc
+ .type _haltproc,function
+_haltproc:
+ lui x10,%hi(__dl_fini)
+ addi x10,x10,%lo(__dl_fini)
+ lw x10,(x10)
+ beq x10,x0,.Lexit
+ jalr x1,x10
+.Lexit:
+ lui x10,%hi(operatingsystem_result)
+ addi x10,x10,%lo(operatingsystem_result)
+ lw x10,(x10)
+ addi x17, x0, 94
+ scall
+ jal x0, _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/riscv32/sighnd.inc b/rtl/linux/riscv32/sighnd.inc
new file mode 100644
index 0000000000..011b63a960
--- /dev/null
+++ b/rtl/linux/riscv32/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/riscv32/sighndh.inc b/rtl/linux/riscv32/sighndh.inc
new file mode 100644
index 0000000000..8fa6a35ebd
--- /dev/null
+++ b/rtl/linux/riscv32/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/riscv32/stat.inc b/rtl/linux/riscv32/stat.inc
new file mode 100644
index 0000000000..6d69441361
--- /dev/null
+++ b/rtl/linux/riscv32/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/riscv32/syscall.inc b/rtl/linux/riscv32/syscall.inc
new file mode 100644
index 0000000000..a7ecca5d8c
--- /dev/null
+++ b/rtl/linux/riscv32/syscall.inc
@@ -0,0 +1,141 @@
+{
+ 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
+ addi x17, sysnr, 0
+ scall
+ bge x10,x0,.Ldone
+ sw x1, -4(x2)
+ addi x2, x2, -4
+ sub x10, x0, x10
+ jal x1, seterrno
+ addi x2, x2, 4
+ lw x1, -4(x2)
+ addi x10,x0, -1
+.Ldone:
+end;
+
+function FpSysCall(sysnr,param1:TSysParam):TSysResult;
+assembler; nostackframe; [public,alias:'FPC_SYSCALL1'];
+asm
+ addi x17, sysnr, 0
+ addi x10, x11, 0
+ scall
+ bge x10,x0,.Ldone
+ sw x1, -4(x2)
+ addi x2, x2, -4
+ sub x10, x0, x10
+ jal x1, seterrno
+ addi x2, x2, 4
+ lw x1, -4(x2)
+ addi x10,x0, -1
+.Ldone:
+end;
+
+function FpSysCall(sysnr,param1,param2:TSysParam):TSysResult;
+assembler; nostackframe; [public,alias:'FPC_SYSCALL2'];
+asm
+ addi x17, sysnr, 0
+ addi x10, x11, 0
+ addi x11, x12, 0
+ scall
+ bge x10,x0,.Ldone
+ sw x1, -4(x2)
+ addi x2, x2, -4
+ sub x10, x0, x10
+ jal x1, seterrno
+ addi x2, x2, 4
+ lw x1, -4(x2)
+ addi x10,x0, -1
+.Ldone:
+end;
+
+function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult;
+assembler; nostackframe; [public,alias:'FPC_SYSCALL3'];
+asm
+ addi x17, sysnr, 0
+ addi x10, x11, 0
+ addi x11, x12, 0
+ addi x12, x13, 0
+ scall
+ bge x10,x0,.Ldone
+ sw x1, -4(x2)
+ addi x2, x2, -4
+ sub x10, x0, x10
+ jal x1, seterrno
+ addi x2, x2, 4
+ lw x1, -4(x2)
+ addi x10,x0, -1
+.Ldone:
+end;
+
+function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult;
+assembler; nostackframe; [public,alias:'FPC_SYSCALL4'];
+asm
+ addi x17, sysnr, 0
+ addi x10, x11, 0
+ addi x11, x12, 0
+ addi x12, x13, 0
+ addi x13, x14, 0
+ scall
+ bge x10,x0,.Ldone
+ sw x1, -4(x2)
+ addi x2, x2, -4
+ sub x10, x0, x10
+ jal x1, seterrno
+ addi x2, x2, 4
+ lw x1, -4(x2)
+ addi x10,x0, -1
+.Ldone:
+end;
+
+function FpSysCall(sysnr,param1,param2,param3,param4,param5:TSysParam):TSysResult;
+assembler; nostackframe; [public,alias:'FPC_SYSCALL5'];
+asm
+ addi x17, sysnr, 0
+ addi x10, x11, 0
+ addi x11, x12, 0
+ addi x12, x13, 0
+ addi x13, x14, 0
+ addi x14, x15, 0
+ scall
+ bge x10,x0,.Ldone
+ sw x1, -4(x2)
+ addi x2, x2, -4
+ sub x10, x0, x10
+ jal x1, seterrno
+ addi x2, x2, 4
+ lw x1, -4(x2)
+ addi x10,x0, -1
+.Ldone:
+end;
+
+function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):TSysResult;
+assembler; nostackframe; [public,alias:'FPC_SYSCALL6'];
+asm
+ addi x17, sysnr, 0
+ addi x10, x11, 0
+ addi x11, x12, 0
+ addi x12, x13, 0
+ addi x13, x14, 0
+ addi x14, x15, 0
+ addi x15, x16, 0
+ scall
+ bge x10,x0,.Ldone
+ sw x1, -4(x2)
+ addi x2, x2, -4
+ sub x10, x0, x10
+ jal x1, seterrno
+ addi x2, x2, 4
+ lw x1, -4(x2)
+ addi x10,x0, -1
+.Ldone:
+end;
diff --git a/rtl/linux/riscv32/syscallh.inc b/rtl/linux/riscv32/syscallh.inc
new file mode 100644
index 0000000000..ea0768dd7f
--- /dev/null
+++ b/rtl/linux/riscv32/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 = longint;
+ 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';
diff --git a/rtl/linux/riscv32/sysnr.inc b/rtl/linux/riscv32/sysnr.inc
new file mode 100644
index 0000000000..3763caa818
--- /dev/null
+++ b/rtl/linux/riscv32/sysnr.inc
@@ -0,0 +1 @@
+{$i ../sysnr-gen.inc}
diff --git a/rtl/linux/riscv64/bsyscall.inc b/rtl/linux/riscv64/bsyscall.inc
new file mode 100644
index 0000000000..c690ebeb2c
--- /dev/null
+++ b/rtl/linux/riscv64/bsyscall.inc
@@ -0,0 +1 @@
+{ nothing }
diff --git a/rtl/linux/riscv64/cprt0.as b/rtl/linux/riscv64/cprt0.as
new file mode 100644
index 0000000000..17f520f896
--- /dev/null
+++ b/rtl/linux/riscv64/cprt0.as
@@ -0,0 +1,142 @@
+/* Startup code for ARM & ELF
+ Copyright (C) 1995, 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ MA 02110-1301, USA. */
+
+/* This is the canonical entry point, usually the first thing in the text
+ segment.
+
+ Note that the code in the .init section has already been run.
+ This includes _init and _libc_init
+
+
+ At this entry point, most registers' values are unspecified, except:
+
+ a0 Contains a function pointer to be registered with `atexit'.
+ This is how the dynamic linker arranges to have DT_FINI
+ functions called for shared libraries that have been loaded
+ before this code runs.
+
+ sp The stack contains the arguments and environment:
+ 0(sp) argc
+ 8(sp) argv[0]
+ ...
+ (8*argc)(sp) NULL
+ (8*(argc+1))(sp) envp[0]
+ ...
+ NULL
+*/
+
+ .text
+ .globl _start
+ .type _start,function
+_start:
+ .option push
+ .option norelax
+1:auipc gp, %pcrel_hi(__global_pointer$)
+ addi gp, gp, %pcrel_lo(1b)
+ .option pop
+
+ /* Store rtld_fini in a5 */
+ addi a5, a0, 0
+
+ /* Clear the frame pointer since this is the outermost frame. */
+ addi x8, x0, 0
+
+ /* Pop argc off the stack, and save argc, argv and envp */
+ ld a1, 0(sp)
+ addi a2, sp, 8
+ addi a4, a1, 1
+ slli a4, a4, 3
+ add a4, a2, a4
+
+1:auipc x8,%pcrel_hi(operatingsystem_parameter_argc)
+ sw a1,%pcrel_lo(1b)(x8)
+1:auipc x8,%pcrel_hi(operatingsystem_parameter_argv)
+ sd a2,%pcrel_lo(1b)(x8)
+1:auipc x8,%pcrel_hi(operatingsystem_parameter_envp)
+ sd a4,%pcrel_lo(1b)(x8)
+
+ /* Save initial stackpointer */
+1:auipc x8,%pcrel_hi(__stkptr)
+ sd sp,%pcrel_lo(1b)(x8)
+
+ /* Fetch address of fini */
+1:auipc x8,%pcrel_hi(__libc_csu_fini)
+ addi a4,x8,%pcrel_lo(1b)
+
+ addi a6, sp, 0
+
+ /* Set up the other arguments in registers */
+1:auipc x8,%pcrel_hi(PASCALMAIN)
+ addi a0, x8, %pcrel_lo(1b)
+1:auipc x8,%pcrel_hi(__libc_csu_init)
+ addi a3, x8, %pcrel_lo(1b)
+
+ /* __libc_start_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
+
+ /* Let the libc call main and exit with its return code. */
+1:auipc x8,%pcrel_hi(__libc_start_main)
+ jalr ra, x8, %pcrel_lo(1b)
+
+ /* should never get here....*/
+1:auipc x8,%pcrel_hi(abort)
+ jalr ra, x8, %pcrel_lo(1b)
+
+ .globl _haltproc
+ .type _haltproc,function
+_haltproc:
+1:auipc x8,%pcrel_hi(operatingsystem_result)
+ lbu x1,%pcrel_lo(1b)(x8)
+ addi x17, x0, 94
+ ecall
+ jal x0, _haltproc
+
+ /* Define a symbol for the first piece of initialized data. */
+ .data
+ .globl __data_start
+__data_start:
+ .long 0
+ .weak data_start
+ data_start = __data_start
+
+.bss
+ .comm __stkptr,8
+
+ .comm operatingsystem_parameter_envp,8
+ .comm operatingsystem_parameter_argc,4
+ .comm operatingsystem_parameter_argv,8
+
+ .section ".comment"
+ .byte 0
+ .ascii "generated by FPC http://www.freepascal.org\0"
+
+/* We need this stuff to make gdb behave itself, otherwise
+ gdb will chokes with SIGILL when trying to debug apps.
+*/
+ .section ".note.ABI-tag", "a"
+ .align 4
+ .long 1f - 0f
+ .long 3f - 2f
+ .long 1
+0: .asciz "GNU"
+1: .align 4
+2: .long 0
+ .long 2,0,0
+3: .align 4
+
+.section .note.GNU-stack,"",%progbits
diff --git a/rtl/linux/riscv64/dllprt0.as b/rtl/linux/riscv64/dllprt0.as
new file mode 100644
index 0000000000..9c0cc1cccd
--- /dev/null
+++ b/rtl/linux/riscv64/dllprt0.as
@@ -0,0 +1,76 @@
+/*
+ * This file is part of the Free Pascal run time library.
+ * Copyright (c) 2011 by Thomas Schatzl,
+ * member of the Free Pascal development team.
+ *
+ * Startup code for shared libraries, ARM version.
+ *
+ * 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.
+ */
+
+.file "dllprt0.as"
+.text
+ .globl _startlib
+ .type _startlib,function
+_startlib:
+ .globl FPC_SHARED_LIB_START
+ .type FPC_SHARED_LIB_START,function
+FPC_SHARED_LIB_START:
+ addi sp, sp, -16
+ sd ra, 8(sp)
+ sd x8, 0(sp)
+ addi x8, sp, 16
+
+ /* a0 contains argc, a1 contains argv and a2 contains envp */
+1:auipc x8,%pcrel_hi(operatingsystem_parameter_argc)
+ sw a0,%pcrel_lo(1b)(x8)
+1:auipc x8,%pcrel_hi(operatingsystem_parameter_argv)
+ sd a1,%pcrel_lo(1b)(x8)
+1:auipc x8,%pcrel_hi(operatingsystem_parameter_envp)
+ sd a2,%pcrel_lo(1b)(x8)
+
+ /* save initial stackpointer */
+1:auipc x8,%pcrel_hi(__stklen)
+ sd sp,%pcrel_lo(1b)(x8)
+
+ /* call main and exit normally */
+1:auipc x8,%pcrel_hi(PASCALMAIN)
+ jalr ra, x8, %pcrel_lo(1b)
+
+ ld x8, 0(x8)
+ ld ra, 8(x8)
+ addi sp, sp, 16
+
+ jalr x0, ra
+
+ .globl _haltproc
+ .type _haltproc,function
+_haltproc:
+1:auipc x8,%pcrel_hi(operatingsystem_result)
+ lbu x1,%pcrel_lo(1b)(x8)
+ addi x17, x0, 94
+ ecall
+ jal x0, _haltproc
+
+.data
+
+ .type operatingsystem_parameters,object
+ .size operatingsystem_parameters, 24
+operatingsystem_parameters:
+ .skip 3 * 8
+ .global operatingsystem_parameter_argc
+ .global operatingsystem_parameter_argv
+ .global operatingsystem_parameter_envp
+ .set operatingsystem_parameter_argc, operatingsystem_parameters+0
+ .set operatingsystem_parameter_argv, operatingsystem_parameters+8
+ .set operatingsystem_parameter_envp, operatingsystem_parameters+16
+
+.bss
+
+ .comm __stkptr,8
+
diff --git a/rtl/linux/riscv64/gprt0.as b/rtl/linux/riscv64/gprt0.as
new file mode 100644
index 0000000000..592c9c9b96
--- /dev/null
+++ b/rtl/linux/riscv64/gprt0.as
@@ -0,0 +1,162 @@
+/* Startup code for ARM & ELF
+ Copyright (C) 1995, 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ MA 02110-1301, USA. */
+
+/* This is the canonical entry point, usually the first thing in the text
+ segment.
+
+ Note that the code in the .init section has already been run.
+ This includes _init and _libc_init
+
+
+ At this entry point, most registers' values are unspecified, except:
+
+ a1 Contains a function pointer to be registered with `atexit'.
+ This is how the dynamic linker arranges to have DT_FINI
+ functions called for shared libraries that have been loaded
+ before this code runs.
+
+ sp The stack contains the arguments and environment:
+ 0(sp) argc
+ 4(sp) argv[0]
+ ...
+ (4*argc)(sp) NULL
+ (4*(argc+1))(sp) envp[0]
+ ...
+ NULL
+*/
+
+ .text
+ .globl _start
+ .type _start,#function
+_start:
+ /* Clear the frame pointer since this is the outermost frame. */
+ addi x8, x0, 0
+ ld a2, (sp)
+ addi sp, sp, 4
+
+ /* Pop argc off the stack and save a pointer to argv */
+ la x5, operatingsystem_parameter_argc
+ la x6,operatingsystem_parameter_argv
+ sd a2, (x5)
+
+ /* calc envp */
+ addi a4,a2,1
+ slli a4,a4,3
+ add a4,sp,a4
+ la x5, operatingsystem_parameter_envp
+
+ sd sp,(a3)
+ sd a4,(x5)
+
+ /* Save initial stackpointer */
+ la x5,__stkptr
+ sd sp, (x5)
+
+ /* Initialize gmon */
+ mov r2,#1
+ ldr r1,=_etext
+ ldr r0,=_start
+ bl __monstartup
+ ldr r0,=_mcleanup
+ bl atexit
+
+ /* argc already loaded to a2*/
+ ldr ip, =operatingsystem_parameter_argc
+ ldr a2,[ip]
+
+ /* Fetch address of fini */
+ ldr ip, =_fini
+
+ /* load argv */
+ mov a3, sp
+
+ /* Push stack limit */
+ str a3, [sp, #-4]!
+
+ /* Push rtld_fini */
+ str a1, [sp, #-4]!
+
+ /* Set up the other arguments in registers */
+ ldr a1, =PASCALMAIN
+ ldr a4, =_init
+
+ /* Push fini */
+ str ip, [sp, #-4]!
+
+ /* __libc_start_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
+
+ /* Let the libc call main and exit with its return code. */
+ bl __libc_start_main
+
+ /* should never get here....*/
+ bl abort
+
+ .globl _haltproc
+ .type _haltproc,#function
+_haltproc:
+ ldr r0,=operatingsystem_result
+ ldrb r0,[r0]
+ swi 0x900001
+ b _haltproc
+
+ .globl _haltproc_eabi
+ .type _haltproc_eabi,#function
+_haltproc_eabi:
+ bl exit /* libc exit */
+
+ ldr r0,=operatingsystem_result
+ ldrb r0,[r0]
+ mov r7,#248
+ swi 0x0
+ b _haltproc_eabi
+
+ /* Define a symbol for the first piece of initialized data. */
+ .data
+ .globl __data_start
+__data_start:
+ .long 0
+ .weak data_start
+ data_start = __data_start
+
+.bss
+ .comm __stkptr,4
+
+ .comm operatingsystem_parameter_envp,4
+ .comm operatingsystem_parameter_argc,4
+ .comm operatingsystem_parameter_argv,4
+
+ .section ".comment"
+ .byte 0
+ .ascii "generated by FPC http://www.freepascal.org\0"
+
+/* We need this stuff to make gdb behave itself, otherwise
+ gdb will chokes with SIGILL when trying to debug apps.
+*/
+ .section ".note.ABI-tag", "a"
+ .align 4
+ .long 1f - 0f
+ .long 3f - 2f
+ .long 1
+0: .asciz "GNU"
+1: .align 4
+2: .long 0
+ .long 2,0,0
+3: .align 4
+
+.section .note.GNU-stack,"",%progbits
diff --git a/rtl/linux/riscv64/prt0.as b/rtl/linux/riscv64/prt0.as
new file mode 100644
index 0000000000..e58feb3469
--- /dev/null
+++ b/rtl/linux/riscv64/prt0.as
@@ -0,0 +1,85 @@
+/*
+ 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:
+1:
+ auipc x5,%pcrel_hi(__dl_fini)
+ sd x10, %pcrel_lo(1b)(x5)
+ jal x0, _start
+
+ .globl _start
+ .type _start, function
+_start:
+ .option push
+ .option norelax
+1: auipc gp, %pcrel_hi(__bss_start+0x800)
+ addi gp, gp, %pcrel_lo(1b)
+ .option pop
+
+ /* Get argc, argv, envp */
+ ld x5,(x2)
+ addi x6,x2,8
+ addi x7,x5,1
+ slli x7,x7,3
+ add x7,x6,x7
+
+ /* Save argc, argv, envp, and initial stack pointer */
+1:auipc x8,%pcrel_hi(operatingsystem_parameter_argc)
+ sw x5,%pcrel_lo(1b)(x8)
+1:auipc x8,%pcrel_hi(operatingsystem_parameter_argv)
+ sd x6,%pcrel_lo(1b)(x8)
+1:auipc x8,%pcrel_hi(operatingsystem_parameter_envp)
+ sd x7,%pcrel_lo(1b)(x8)
+1:auipc x5,%pcrel_hi(__stkptr)
+ addi x6, x2, 0
+ sd x6,%pcrel_lo(1b)(x5)
+
+ /* Initialise FP to zero */
+ addi x8,x0,0
+
+ /* Call main */
+ jal x1, PASCALMAIN
+
+ .globl _haltproc
+ .type _haltproc,function
+_haltproc:
+1:auipc x10,%pcrel_hi(__dl_fini)
+ ld x10,%pcrel_lo(1b)(x10)
+ beq x10,x0,.Lexit
+ jalr x1,x10
+.Lexit:
+1:auipc x10,%pcrel_hi(operatingsystem_result)
+ ld x10,%pcrel_lo(1b)(x10)
+ addi x17, x0, 94
+ ecall
+ jal x0, _haltproc
+
+ /* Define a symbol for the first piece of initialized data. */
+ .data
+ .align 4
+ .globl __data_start
+__data_start:
+ .quad 0
+ .weak data_start
+ data_start = __data_start
+
+ .bss
+ .align 4
+
+ .comm __dl_fini,8
+ .comm __stkptr,8
+
+ .comm operatingsystem_parameter_envp,8
+ .comm operatingsystem_parameter_argc,4
+ .comm operatingsystem_parameter_argv,8
+
+ .section .note.GNU-stack,"",%progbits
diff --git a/rtl/linux/riscv64/sighnd.inc b/rtl/linux/riscv64/sighnd.inc
new file mode 100644
index 0000000000..011b63a960
--- /dev/null
+++ b/rtl/linux/riscv64/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/riscv64/sighndh.inc b/rtl/linux/riscv64/sighndh.inc
new file mode 100644
index 0000000000..8fa6a35ebd
--- /dev/null
+++ b/rtl/linux/riscv64/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/riscv64/stat.inc b/rtl/linux/riscv64/stat.inc
new file mode 100644
index 0000000000..6d69441361
--- /dev/null
+++ b/rtl/linux/riscv64/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/riscv64/syscall.inc b/rtl/linux/riscv64/syscall.inc
new file mode 100644
index 0000000000..6abf3ac807
--- /dev/null
+++ b/rtl/linux/riscv64/syscall.inc
@@ -0,0 +1,155 @@
+{
+ 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
+ addi x17, sysnr, 0
+ ecall
+ bge x10,x0,.Ldone
+ sd x1, -8(x2)
+ addi x2, x2, -8
+ sub x10, x0, x10
+.Ll1:
+ auipc x1, %pcrel_hi(seterrno)
+ jalr x1, x1, %pcrel_lo(.Ll1)
+ addi x2, x2, 8
+ ld x1, -8(x2)
+ addi x10,x0, -1
+.Ldone:
+end;
+
+function FpSysCall(sysnr,param1:TSysParam):TSysResult;
+assembler; nostackframe; [public,alias:'FPC_SYSCALL1'];
+asm
+ addi x17, sysnr, 0
+ addi x10, x11, 0
+ ecall
+ bge x10,x0,.Ldone
+ sd x1, -8(x2)
+ addi x2, x2, -8
+ sub x10, x0, x10
+.Ll1:
+ auipc x1, %pcrel_hi(seterrno)
+ jalr x1, x1, %pcrel_lo(.Ll1)
+ addi x2, x2, 8
+ ld x1, -8(x2)
+ addi x10,x0, -1
+.Ldone:
+end;
+
+function FpSysCall(sysnr,param1,param2:TSysParam):TSysResult;
+assembler; nostackframe; [public,alias:'FPC_SYSCALL2'];
+asm
+ addi x17, sysnr, 0
+ addi x10, x11, 0
+ addi x11, x12, 0
+ ecall
+ bge x10,x0,.Ldone
+ sd x1, -8(x2)
+ addi x2, x2, -8
+ sub x10, x0, x10
+.Ll1:
+ auipc x1, %pcrel_hi(seterrno)
+ jalr x1, x1, %pcrel_lo(.Ll1)
+ addi x2, x2, 8
+ ld x1, -8(x2)
+ addi x10,x0, -1
+.Ldone:
+end;
+
+function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult;
+assembler; nostackframe; [public,alias:'FPC_SYSCALL3'];
+asm
+ addi x17, sysnr, 0
+ addi x10, x11, 0
+ addi x11, x12, 0
+ addi x12, x13, 0
+ ecall
+ bge x10,x0,.Ldone
+ sd x1, -8(x2)
+ addi x2, x2, -8
+ sub x10, x0, x10
+.Ll1:
+ auipc x1, %pcrel_hi(seterrno)
+ jalr x1, x1, %pcrel_lo(.Ll1)
+ addi x2, x2, 8
+ ld x1, -8(x2)
+ addi x10,x0, -1
+.Ldone:
+end;
+
+function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult;
+assembler; nostackframe; [public,alias:'FPC_SYSCALL4'];
+asm
+ addi x17, sysnr, 0
+ addi x10, x11, 0
+ addi x11, x12, 0
+ addi x12, x13, 0
+ addi x13, x14, 0
+ ecall
+ bge x10,x0,.Ldone
+ sd x1, -8(x2)
+ addi x2, x2, -8
+ sub x10, x0, x10
+.Ll1:
+ auipc x1, %pcrel_hi(seterrno)
+ jalr x1, x1, %pcrel_lo(.Ll1)
+ addi x2, x2, 8
+ ld x1, -8(x2)
+ addi x10,x0, -1
+.Ldone:
+end;
+
+function FpSysCall(sysnr,param1,param2,param3,param4,param5:TSysParam):TSysResult;
+assembler; nostackframe; [public,alias:'FPC_SYSCALL5'];
+asm
+ addi x17, sysnr, 0
+ addi x10, x11, 0
+ addi x11, x12, 0
+ addi x12, x13, 0
+ addi x13, x14, 0
+ addi x14, x15, 0
+ ecall
+ bge x10,x0,.Ldone
+ sd x1, -8(x2)
+ addi x2, x2, -8
+ sub x10, x0, x10
+.Ll1:
+ auipc x1, %pcrel_hi(seterrno)
+ jalr x1, x1, %pcrel_lo(.Ll1)
+ addi x2, x2, 8
+ ld x1, -8(x2)
+ addi x10,x0, -1
+.Ldone:
+end;
+
+function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):TSysResult;
+assembler; nostackframe; [public,alias:'FPC_SYSCALL6'];
+asm
+ addi x17, sysnr, 0
+ addi x10, x11, 0
+ addi x11, x12, 0
+ addi x12, x13, 0
+ addi x13, x14, 0
+ addi x14, x15, 0
+ addi x15, x16, 0
+ ecall
+ bge x10,x0,.Ldone
+ sd x1, -8(x2)
+ addi x2, x2, -8
+ sub x10, x0, x10
+.Ll1:
+ auipc x1, %pcrel_hi(seterrno)
+ jalr x1, x1, %pcrel_lo(.Ll1)
+ addi x2, x2, 8
+ ld x1, -8(x2)
+ addi x10,x0, -1
+.Ldone:
+end;
diff --git a/rtl/linux/riscv64/syscallh.inc b/rtl/linux/riscv64/syscallh.inc
new file mode 100644
index 0000000000..6961a190ca
--- /dev/null
+++ b/rtl/linux/riscv64/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/riscv64/sysnr.inc b/rtl/linux/riscv64/sysnr.inc
new file mode 100644
index 0000000000..3763caa818
--- /dev/null
+++ b/rtl/linux/riscv64/sysnr.inc
@@ -0,0 +1 @@
+{$i ../sysnr-gen.inc}
diff --git a/rtl/linux/system.pp b/rtl/linux/system.pp
index a6dc519a03..9c68cec6f7 100644
--- a/rtl/linux/system.pp
+++ b/rtl/linux/system.pp
@@ -45,7 +45,7 @@ const
function get_cmdline:Pchar; deprecated 'use paramstr' ;
property cmdline:Pchar read get_cmdline;
-{$if defined(CPUARM) or defined(CPUM68K) or (defined(CPUSPARC) and defined(VER2_6))}
+{$if defined(CPURISCV32) or defined(CPURISCV64) or defined(CPUARM) or defined(CPUM68K) or (defined(CPUSPARC) and defined(VER2_6))}
{$define FPC_LOAD_SOFTFPU}
{$endif}
@@ -65,6 +65,8 @@ property cmdline:Pchar read get_cmdline;
{$undef fpc_softfpu_interface}
{$endif FPC_LOAD_SOFTFPU}
+{$endif defined(CPURISCV32) or defined(CPURISCV64) or defined(CPUARM) or defined(CPUM68K) or (defined(CPUSPARC) and defined(VER2_6))}
+
{$ifdef android}
{$I sysandroidh.inc}
{$endif android}
@@ -85,6 +87,7 @@ const
procedure OsSetupEntryInformation(constref info: TEntryInformation); forward;
{$endif FPC_HAS_INDIRECT_ENTRY_INFORMATION}
+{$if defined(CPURISCV32) or defined(CPURISCV64) or defined(CPUARM) or defined(CPUM68K) or (defined(CPUSPARC) and defined(VER2_6))}
{$ifdef FPC_LOAD_SOFTFPU}
{$define fpc_softfpu_implementation}
@@ -108,6 +111,7 @@ procedure OsSetupEntryInformation(constref info: TEntryInformation); forward;
{$define FPC_SYSTEM_HAS_extractFloat32Sign}
{$endif FPC_LOAD_SOFTFPU}
+{$endif defined(CPURISCV32) or defined(CPURISCV64) or defined(CPUARM) or defined(CPUM68K) or (defined(CPUSPARC) and defined(VER2_6))}
{$I system.inc}
diff --git a/rtl/linux/termios.inc b/rtl/linux/termios.inc
index 8bc408362e..0e0d5abbc4 100644
--- a/rtl/linux/termios.inc
+++ b/rtl/linux/termios.inc
@@ -556,6 +556,536 @@ Const
{$endif cpupowerpc}
+{$ifdef cpuriscv32}
+
+{ 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 cpuriscv32}
+
+{$ifdef cpuriscv64}
+
+{ 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 cpuriscv64}
+
{$ifdef cpui386}
{ For Terminal handling }
TCGETS = $5401;