mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-16 01:41:18 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
722ef8f64f | ||
|
|
1e5b4df5b8 |
No files matched your search
@@ -22,6 +22,7 @@
|
||||
/data/lldb @lewurm @vargaz
|
||||
|
||||
/docs @luhenry @marek-safar
|
||||
/docs/riscv.md @alexrp
|
||||
/docs/sources/mono-api-profiler.html @alexrp
|
||||
|
||||
/external @marek-safar @luhenry
|
||||
@@ -64,6 +65,8 @@
|
||||
|
||||
/mono @luhenry
|
||||
|
||||
/mono/arch/riscv @alexrp
|
||||
|
||||
/mono/btls @baulig
|
||||
/mono/dis @lambdageek @vargaz
|
||||
/mono/eglib @kumpera @vargaz @luhenry
|
||||
@@ -82,6 +85,7 @@
|
||||
/mono/mini/*cfgdump* @lewurm
|
||||
/mono/mini/*exceptions* @lewurm
|
||||
/mono/mini/*ppc* @lewurm
|
||||
/mono/mini/*riscv* @alexrp
|
||||
/mono/mini/*type-check* @lewurm
|
||||
/mono/mini/interp/* @lewurm @BrzVlad
|
||||
/mono/mini/*profiler* @alexrp
|
||||
|
||||
+129
-2
@@ -287,6 +287,10 @@ case "$host" in
|
||||
# https://bugzilla.novell.com/show_bug.cgi?id=504411
|
||||
disable_munmap=yes
|
||||
;;
|
||||
riscv*)
|
||||
support_boehm=no
|
||||
with_gc=sgen
|
||||
;;
|
||||
esac
|
||||
with_sgen_default_concurrent=yes
|
||||
;;
|
||||
@@ -4064,6 +4068,24 @@ case "$host" in
|
||||
BTLS_PLATFORM=s390x
|
||||
CFLAGS="$CFLAGS -mbackchain -D__USE_STRING_INLINES"
|
||||
;;
|
||||
riscv32-*)
|
||||
TARGET=RISCV32
|
||||
ACCESS_UNALIGNED=no
|
||||
AOT_SUPPORTED=no
|
||||
BTLS_SUPPORTED=yes
|
||||
BTLS_PLATFORM=riscv32
|
||||
arch_target=riscv32
|
||||
boehm_supported=false
|
||||
;;
|
||||
riscv64*)
|
||||
TARGET=RISCV64
|
||||
ACCESS_UNALIGNED=no
|
||||
AOT_SUPPORTED=no
|
||||
BTLS_SUPPORTED=yes
|
||||
BTLS_PLATFORM=riscv64
|
||||
arch_target=riscv64
|
||||
boehm_supported=false
|
||||
;;
|
||||
esac
|
||||
|
||||
HOST=$TARGET
|
||||
@@ -4143,6 +4165,22 @@ if test "x$host" != "x$target"; then
|
||||
aarch64-*)
|
||||
TARGET=ARM64
|
||||
;;
|
||||
riscv32*)
|
||||
TARGET=RISCV32
|
||||
AC_DEFINE([TARGET_RISCV], [1], [Target is RISC-V])
|
||||
AC_DEFINE([TARGET_RISCV32], [1], [Target is 32-bit RISC-V])
|
||||
arch_target=riscv32
|
||||
target_mach=no
|
||||
with_tls=pthread
|
||||
;;
|
||||
riscv64*)
|
||||
TARGET=RISCV64
|
||||
AC_DEFINE([TARGET_RISCV], [1], [Target is RISC-V])
|
||||
AC_DEFINE([TARGET_RISCV64], [1], [Target is 64-bit RISC-V])
|
||||
arch_target=riscv64
|
||||
target_mach=no
|
||||
with_tls=pthread
|
||||
;;
|
||||
*)
|
||||
AC_MSG_ERROR([Cross compiling is not supported for target $target])
|
||||
esac
|
||||
@@ -4201,6 +4239,14 @@ SPARC)
|
||||
SPARC64)
|
||||
AC_DEFINE(TARGET_SPARC64, 1, [...])
|
||||
;;
|
||||
RISCV32)
|
||||
AC_DEFINE([TARGET_RISCV], [1], [Target is RISC-V])
|
||||
AC_DEFINE([TARGET_RISCV32], [1], [Target is 32-bit RISC-V])
|
||||
;;
|
||||
RISCV64)
|
||||
AC_DEFINE([TARGET_RISCV], [1], [Target is RISC-V])
|
||||
AC_DEFINE([TARGET_RISCV64], [1], [Target is 64-bit RISC-V])
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$HOST" in
|
||||
@@ -4238,6 +4284,14 @@ SPARC)
|
||||
SPARC64)
|
||||
AC_DEFINE(HOST_SPARC64, 1, [...])
|
||||
;;
|
||||
RISCV32)
|
||||
AC_DEFINE([HOST_RISCV], [1], [Host is RISC-V])
|
||||
AC_DEFINE([HOST_RISCV32], [1], [Host is 32-bit RISC-V])
|
||||
;;
|
||||
RISCV64)
|
||||
AC_DEFINE([HOST_RISCV], [1], [Host is RISC-V])
|
||||
AC_DEFINE([HOST_RISCV64], [1], [Host is 64-bit RISC-V])
|
||||
;;
|
||||
esac
|
||||
|
||||
MONO_ARCH_GSHAREDVT_SUPPORTED=0
|
||||
@@ -4293,7 +4347,7 @@ fi
|
||||
dnl Use GCC atomic ops if they work on the target.
|
||||
if test x$GCC = "xyes"; then
|
||||
case $TARGET in
|
||||
X86 | AMD64 | ARM | ARM64 | POWERPC | POWERPC64 | MIPS | S390X | SPARC | SPARC64)
|
||||
X86 | AMD64 | ARM | ARM64 | POWERPC | POWERPC64 | MIPS | S390X | SPARC | SPARC64 | RISCV32 | RISCV64)
|
||||
AC_DEFINE(USE_GCC_ATOMIC_OPS, 1, [...])
|
||||
;;
|
||||
esac
|
||||
@@ -4495,7 +4549,7 @@ case $host in
|
||||
esac
|
||||
|
||||
case $target in
|
||||
arm*-darwin*|aarch64*-*)
|
||||
arm*-darwin*|aarch64*-*|riscv*)
|
||||
CFLAGS="$CFLAGS -U_FORTIFY_SOURCE"
|
||||
;;
|
||||
i*86-*-darwin*)
|
||||
@@ -4869,6 +4923,66 @@ if test ${TARGET} = ARM; then
|
||||
fi
|
||||
fi
|
||||
|
||||
if test ${TARGET} = RISCV32 -o ${TARGET} = RISCV64; then
|
||||
AC_ARG_WITH([riscv-fpabi], [ --with-riscv-fpabi=auto,double,soft Select RISC-V floating point ABI (auto)], [fpabi=$withval], [fpabi=double])
|
||||
|
||||
AC_MSG_CHECKING([which RISC-V floating point ABI to use])
|
||||
|
||||
if test x$fpabi = xauto; then
|
||||
AC_TRY_COMPILE([], [
|
||||
#ifdef __riscv_float_abi_double
|
||||
#error "double"
|
||||
#endif
|
||||
], [
|
||||
], [
|
||||
fpabi=double
|
||||
])
|
||||
fi
|
||||
|
||||
if test x$fpabi = xauto; then
|
||||
AC_TRY_COMPILE([], [
|
||||
#ifdef __riscv_float_abi_single
|
||||
#error "single"
|
||||
#endif
|
||||
], [
|
||||
], [
|
||||
fpabi=single
|
||||
])
|
||||
fi
|
||||
|
||||
if test x$fpabi = xauto; then
|
||||
AC_TRY_COMPILE([], [
|
||||
#ifdef __riscv_float_abi_soft
|
||||
#error "soft"
|
||||
#endif
|
||||
], [
|
||||
], [
|
||||
fpabi=soft
|
||||
])
|
||||
fi
|
||||
|
||||
case $fpabi in
|
||||
double)
|
||||
AC_DEFINE([RISCV_FPABI_DOUBLE], [1], [RISC-V FPABI is double-precision])
|
||||
AC_MSG_RESULT([double-precision])
|
||||
;;
|
||||
single)
|
||||
AC_DEFINE([RISCV_FPABI_SINGLE], [1], [RISC-V FPABI is single-precision])
|
||||
AC_MSG_ERROR([single-precision, not supported])
|
||||
;;
|
||||
soft)
|
||||
AC_DEFINE([RISCV_FPABI_SOFT], [1], [RISC-V FPABI is soft float])
|
||||
AC_MSG_RESULT([soft float])
|
||||
;;
|
||||
auto)
|
||||
AC_MSG_ERROR([unknown])
|
||||
;;
|
||||
*)
|
||||
AC_MSG_ERROR([invalid option: $fpabi])
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if test ${TARGET} = unknown; then
|
||||
CPPFLAGS="$CPPFLAGS -DNO_PORT"
|
||||
AC_MSG_WARN("mono has not been ported to $host: some things may not work.")
|
||||
@@ -5188,6 +5302,12 @@ if test "x$enable_btls" = "xyes"; then
|
||||
android-x64)
|
||||
BTLS_CMAKE_ARGS="-DANDROID_ABI=\"x86_64\" -DANDROID_NATIVE_API_LEVEL=21"
|
||||
;;
|
||||
riscv32)
|
||||
btls_arch=riscv32
|
||||
;;
|
||||
riscv64)
|
||||
btls_arch=riscv64
|
||||
;;
|
||||
*)
|
||||
AC_MSG_ERROR(Invalid BTLS platform)
|
||||
esac
|
||||
@@ -5244,11 +5364,17 @@ AM_CONDITIONAL(POWERPC64, test x$TARGET = xPOWERPC64)
|
||||
AM_CONDITIONAL(ARM, test x$TARGET = xARM)
|
||||
AM_CONDITIONAL(ARM64, test x$TARGET = xARM64)
|
||||
AM_CONDITIONAL(S390X, test x$TARGET = xS390X)
|
||||
AM_CONDITIONAL([RISCV], [test x$TARGET = xRISCV32 -o x$TARGET = xRISCV64])
|
||||
AM_CONDITIONAL([RISCV32], [test x$TARGET = xRISCV32])
|
||||
AM_CONDITIONAL([RISCV64], [test x$TARGET = xRISCV64])
|
||||
AM_CONDITIONAL(WASM, test x$TARGET = xWASM)
|
||||
AM_CONDITIONAL(HOST_X86, test x$HOST = xX86)
|
||||
AM_CONDITIONAL(HOST_AMD64, test x$HOST = xAMD64)
|
||||
AM_CONDITIONAL(HOST_ARM, test x$HOST = xARM)
|
||||
AM_CONDITIONAL(HOST_ARM64, test x$HOST = xARM64)
|
||||
AM_CONDITIONAL([HOST_RISCV], [test x$HOST = xRISCV32 -o x$HOST = xRISCV64])
|
||||
AM_CONDITIONAL([HOST_RISCV32], [test x$HOST = xRISCV32])
|
||||
AM_CONDITIONAL([HOST_RISCV64], [test x$HOST = xRISCV64])
|
||||
AM_CONDITIONAL(HOST_WASM, test x$HOST = xWASM)
|
||||
|
||||
AM_CONDITIONAL(CROSS_COMPILE, test "x$host" != "x$target")
|
||||
@@ -5510,6 +5636,7 @@ mono/arch/s390x/Makefile
|
||||
mono/arch/arm/Makefile
|
||||
mono/arch/arm64/Makefile
|
||||
mono/arch/mips/Makefile
|
||||
mono/arch/riscv/Makefile
|
||||
mono/sgen/Makefile
|
||||
mono/tests/Makefile
|
||||
mono/tests/assembly-load-reference/Makefile
|
||||
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
# Mono RISC-V Port
|
||||
|
||||
These are some useful links and notes pertaining to the RISC-V port of Mono.
|
||||
|
||||
## Useful RISC-V documents
|
||||
|
||||
* [RISC-V User-Level ISA Specification](https://riscv.org/specifications/)
|
||||
* [RISC-V Privileged ISA Specification](https://riscv.org/specifications/privileged-isa/)
|
||||
* [RISC-V Debug Specification Standard](https://github.com/riscv/riscv-debug-spec/blob/master/riscv-debug-spec.pdf)
|
||||
* [RISC-V Assembly Programmer's Manual](https://github.com/riscv/riscv-asm-manual/blob/master/riscv-asm.md)
|
||||
* [RISC-V ELF psABI Specification](https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md)
|
||||
|
||||
## Useful RISC-V repositories
|
||||
|
||||
* [RISC-V Organization](https://github.com/riscv)
|
||||
* [RISC-V Linux](https://github.com/riscv/riscv-linux)
|
||||
* [RISC-V LLD](https://github.com/riscv/riscv-lld)
|
||||
* [RISC-V Tools](https://github.com/riscv/riscv-tools)
|
||||
* [RISC-V GNU Toolchain](https://github.com/riscv/riscv-gnu-toolchain)
|
||||
* [RISC-V Binutils](https://github.com/riscv/riscv-binutils-gdb)
|
||||
* [RISC-V GCC](https://github.com/riscv/riscv-gcc)
|
||||
* [RISC-V Glibc](https://github.com/riscv/riscv-glibc)
|
||||
* [RISC-V Newlib](https://github.com/riscv/riscv-newlib)
|
||||
* [RISC-V QEMU](https://github.com/riscv/riscv-qemu)
|
||||
* [RISC-V Opcodes](https://github.com/riscv/riscv-opcodes)
|
||||
* [RISC-V Tests](https://github.com/riscv/riscv-tests)
|
||||
* [lowRISC Organization](https://github.com/lowrisc)
|
||||
* [RISC-V LLVM](https://github.com/lowrisc/riscv-llvm)
|
||||
|
||||
## Setting up a cross environment
|
||||
|
||||
Setting up a cross environment with a Linux toolchain and QEMU is quite easy.
|
||||
|
||||
First, add these to your `.bashrc` (or some other script that you run):
|
||||
|
||||
```bash
|
||||
export RISCV=$HOME/riscv
|
||||
export PATH=$RISCV/bin:$PATH
|
||||
export QEMU_LD_PREFIX=$RISCV/sysroot
|
||||
```
|
||||
|
||||
Install some dependencies needed to build the toolchain:
|
||||
|
||||
```console
|
||||
# apt install sudo apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev libusb-1.0-0-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev device-tree-compiler pkg-config libexpat-dev
|
||||
```
|
||||
|
||||
Now you can build the toolchain:
|
||||
|
||||
```console
|
||||
$ git clone --recursive [email protected]:riscv/riscv-tools.git
|
||||
$ cd riscv-tools
|
||||
$ ./build.sh
|
||||
$ cd riscv-gnu-toolchain
|
||||
$ ./configure --prefix=$RISCV --enable-multilib
|
||||
$ make linux
|
||||
$ cd ../..
|
||||
$ git clone --recursive [email protected]:riscv/riscv-qemu.git
|
||||
$ cd riscv-qemu
|
||||
$ mkdir build
|
||||
$ cd build
|
||||
$ ../configure --prefix=$RISCV --disable-werror
|
||||
$ make
|
||||
$ make install
|
||||
```
|
||||
|
||||
## Building Mono with a cross toolchain
|
||||
|
||||
Building Mono is quite straightforward:
|
||||
|
||||
```console
|
||||
$ ./autogen.sh --prefix=$RISCV/sysroot --host=riscv64-unknown-linux-gnu
|
||||
$ make
|
||||
$ make install
|
||||
```
|
||||
|
||||
You can set `CFLAGS` as appropriate to change the RISC-V options, such as which
|
||||
standard extensions and ABI to use. For example, to use the 64-bit soft float
|
||||
ABI:
|
||||
|
||||
```console
|
||||
$ CFLAGS="-mabi=lp64" ./autogen.sh --prefix=$RISCV/sysroot --host=riscv64-unknown-linux-gnu
|
||||
```
|
||||
|
||||
Note that, since this is a cross build, the `mcs` directory won't be built. You
|
||||
will have to build the managed libraries and tools through a native build of
|
||||
Mono and copy them into `$RISCV/sysroot`.
|
||||
|
||||
You can run Mono with QEMU like this:
|
||||
|
||||
```console
|
||||
$ qemu-riscv64 $RISCV/sysroot/bin/mono hello.exe
|
||||
```
|
||||
|
||||
## Things to be done
|
||||
|
||||
In no particular order:
|
||||
|
||||
* Complete the soft float port.
|
||||
* Complete the 32-bit port.
|
||||
* Add unwind info to trampolines.
|
||||
* Implement AOT support.
|
||||
* Implement interpreter support.
|
||||
* Implement LLVM support.
|
||||
* Implement SDB support.
|
||||
* Implement `dyn_call` support.
|
||||
* Ensure all runtime tests pass.
|
||||
* Ensure all corlib tests pass.
|
||||
* Set up CI on Jenkins.
|
||||
@@ -1,6 +1,6 @@
|
||||
include $(top_srcdir)/mk/common.mk
|
||||
|
||||
DIST_SUBDIRS = x86 ppc sparc arm arm64 s390x amd64 mips
|
||||
DIST_SUBDIRS = x86 ppc sparc arm arm64 s390x amd64 mips riscv
|
||||
|
||||
AM_CPPFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir)
|
||||
|
||||
@@ -9,4 +9,6 @@ if ARM
|
||||
SUBDIRS = arm
|
||||
endif
|
||||
|
||||
|
||||
if RISCV
|
||||
SUBDIRS = riscv
|
||||
endif
|
||||
@@ -6812,7 +6812,7 @@ mono_icall_is_64bit_os (void)
|
||||
struct utsname name;
|
||||
|
||||
if (uname (&name) >= 0) {
|
||||
return strcmp (name.machine, "x86_64") == 0 || strncmp (name.machine, "aarch64", 7) == 0 || strncmp (name.machine, "ppc64", 5) == 0;
|
||||
return strcmp (name.machine, "x86_64") == 0 || strncmp (name.machine, "aarch64", 7) == 0 || strncmp (name.machine, "ppc64", 5) == 0 || strncmp (name.machine, "riscv64", 7) == 0;
|
||||
}
|
||||
#endif
|
||||
return FALSE;
|
||||
|
||||
@@ -34,6 +34,10 @@ dump_arch (void)
|
||||
g_print ("#ifdef TARGET_ARM\n");
|
||||
#elif defined (TARGET_ARM64)
|
||||
g_print ("#ifdef TARGET_ARM64\n");
|
||||
#elif defined (TARGET_RISCV32)
|
||||
g_print ("#ifdef TARGET_RISCV32\n");
|
||||
#elif defined (TARGET_RISCV64)
|
||||
g_print ("#ifdef TARGET_RISCV64\n");
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
@@ -84,6 +84,12 @@
|
||||
#elif defined(mips) || defined(__mips) || defined(_mips)
|
||||
#define CONFIG_CPU "mips"
|
||||
#define CONFIG_WORDSIZE "32"
|
||||
#elif defined (TARGET_RISCV32)
|
||||
#define CONFIG_CPU "riscv32"
|
||||
#define CONFIG_WORDSIZE "32"
|
||||
#elif defined (TARGET_RISCV64)
|
||||
#define CONFIG_CPU "riscv64"
|
||||
#define CONFIG_WORDSIZE "64"
|
||||
#elif defined(TARGET_WASM)
|
||||
#define CONFIG_CPU "wasm"
|
||||
#define CONFIG_WORDSIZE "32"
|
||||
|
||||
@@ -700,7 +700,7 @@ sgen_client_binary_protocol_collection_end_stats (long long major_scan, long lon
|
||||
*
|
||||
* TODO: Query the JIT instead of this ifdef hack.
|
||||
*/
|
||||
#if defined (TARGET_X86) || defined (TARGET_AMD64) || (defined (TARGET_ARM) && defined (HAVE_ARMV7)) || defined (TARGET_ARM64)
|
||||
#if defined (TARGET_X86) || defined (TARGET_AMD64) || (defined (TARGET_ARM) && defined (HAVE_ARMV7)) || defined (TARGET_ARM64) || defined (TARGET_RISCV)
|
||||
#define MANAGED_ALLOCATOR_CAN_USE_CRITICAL_REGION
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -364,6 +364,12 @@ s390x_sources = \
|
||||
exceptions-s390x.c \
|
||||
tramp-s390x.c
|
||||
|
||||
riscv_sources = \
|
||||
mini-riscv.c \
|
||||
mini-riscv.h \
|
||||
exceptions-riscv.c \
|
||||
tramp-riscv.c
|
||||
|
||||
darwin_sources = \
|
||||
mini-darwin.c
|
||||
|
||||
@@ -627,6 +633,20 @@ arch_define=__s390__
|
||||
target_define=TARGET_S390X
|
||||
endif
|
||||
|
||||
if RISCV32
|
||||
arch_sources = $(riscv_sources)
|
||||
arch_built = cpu-riscv32.h
|
||||
arch_define = __riscv
|
||||
target_define = TARGET_RISCV32
|
||||
endif
|
||||
|
||||
if RISCV64
|
||||
arch_sources = $(riscv_sources)
|
||||
arch_built = cpu-riscv64.h
|
||||
arch_define = __riscv
|
||||
target_define = TARGET_RISCV64
|
||||
endif
|
||||
|
||||
if HOST_WIN32
|
||||
os_sources = $(windows_sources)
|
||||
monobin_platform_ldflags=
|
||||
@@ -774,6 +794,12 @@ cpu-s390x.h: mini-ops.h cpu-s390x.md
|
||||
cpu-mips.h: mini-ops.h cpu-mips.md
|
||||
$(GENMDESC_PRG) cpu-mips.h mips_desc $(srcdir)/cpu-mips.md
|
||||
|
||||
cpu-riscv32.h: cpu-riscv32.md
|
||||
$(GENMDESC_PRG) cpu-riscv32.h riscv32_cpu_desc $(srcdir)/cpu-riscv32.md
|
||||
|
||||
cpu-riscv64.h: cpu-riscv64.md
|
||||
$(GENMDESC_PRG) cpu-riscv64.h riscv64_cpu_desc $(srcdir)/cpu-riscv64.md
|
||||
|
||||
testi: mono test.exe
|
||||
$(MINI_RUNTIME) -v -v --ncompile 1 --compile Test:$(mtest) test.exe
|
||||
|
||||
@@ -957,6 +983,7 @@ EXTRA_DIST = TestDriver.cs \
|
||||
$(mips_sources) cpu-mips.md \
|
||||
$(sparc_sources) cpu-sparc.md \
|
||||
$(s390x_sources) cpu-s390x.md \
|
||||
$(riscv_sources) cpu-riscv32.md cpu-riscv64.md \
|
||||
$(windows_sources) \
|
||||
$(darwin_sources) Info.plist \
|
||||
$(posix_sources) \
|
||||
|
||||
@@ -962,7 +962,7 @@ emit_code_bytes (MonoAotCompile *acfg, const guint8* buf, int size)
|
||||
|
||||
/* ARCHITECTURE SPECIFIC CODE */
|
||||
|
||||
#if defined(TARGET_X86) || defined(TARGET_AMD64) || defined(TARGET_ARM) || defined(TARGET_POWERPC) || defined(TARGET_ARM64)
|
||||
#if defined(TARGET_X86) || defined(TARGET_AMD64) || defined(TARGET_ARM) || defined(TARGET_POWERPC) || defined(TARGET_ARM64) || defined (TARGET_RISCV)
|
||||
#define EMIT_DWARF_INFO 1
|
||||
#endif
|
||||
|
||||
@@ -1062,6 +1062,14 @@ arch_emit_unwind_info_sections (MonoAotCompile *acfg, const char *function_start
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef TARGET_RISCV32
|
||||
#define AOT_TARGET_STR "RISCV32"
|
||||
#endif
|
||||
|
||||
#ifdef TARGET_RISCV64
|
||||
#define AOT_TARGET_STR "RISCV64"
|
||||
#endif
|
||||
|
||||
#ifdef TARGET_X86
|
||||
#ifdef TARGET_WIN32
|
||||
#define AOT_TARGET_STR "X86 (WIN32)"
|
||||
@@ -1143,6 +1151,32 @@ arch_init (MonoAotCompile *acfg)
|
||||
acfg->need_pt_gnu_stack = TRUE;
|
||||
#endif
|
||||
|
||||
#ifdef TARGET_RISCV
|
||||
if (acfg->aot_opts.mtriple)
|
||||
mono_arch_set_target (acfg->aot_opts.mtriple);
|
||||
|
||||
#ifdef TARGET_RISCV64
|
||||
|
||||
g_string_append (acfg->as_args, " -march=rv64i ");
|
||||
#ifdef RISCV_FPABI_DOUBLE
|
||||
g_string_append (acfg->as_args, " -mabi=lp64d");
|
||||
#else
|
||||
g_string_append (acfg->as_args, " -mabi=lp64");
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
g_string_append (acfg->as_args, " -march=rv32i ");
|
||||
#ifdef RISCV_FPABI_DOUBLE
|
||||
g_string_append (acfg->as_args, " -mabi=ilp32d ");
|
||||
#else
|
||||
g_string_append (acfg->as_args, " -mabi=ilp32 ");
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef MONOTOUCH
|
||||
acfg->global_symbols = TRUE;
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# Licensed to the .NET Foundation under one or more agreements.
|
||||
# The .NET Foundation licenses this file to you under the MIT license.
|
||||
# See the LICENSE file in the project root for more information.
|
||||
#
|
||||
# RISC-V RV32 Machine Description
|
||||
#
|
||||
# This file describes various properties of Mini instructions for RV32 and is
|
||||
# read by genmdesc.py to generate a C header file used by various parts of the
|
||||
# JIT.
|
||||
#
|
||||
# Lines are of the form:
|
||||
#
|
||||
# <name>: len:<length> [dest:<rspec>] [src1:<rspec>] [src2:<rspec>] [src3:<rspec>] [clob:<cspec>]
|
||||
#
|
||||
# Here, <name> is the name of the instruction as specified in mini-ops.h.
|
||||
# length is the maximum number of bytes that could be needed to generate native
|
||||
# code for the instruction. dest, src1, src2, and src3 specify output and input
|
||||
# registers needed by the instruction. <rspec> can be one of:
|
||||
#
|
||||
# a a0
|
||||
# i any integer register
|
||||
# b any integer register (used as a pointer)
|
||||
# f any float register (a0..a1 pair in soft float)
|
||||
# l a0..a1 pair
|
||||
#
|
||||
# clob specifies which registers are clobbered (i.e. overwritten with garbage)
|
||||
# by the instruction. <cspec> can be one of:
|
||||
#
|
||||
# a a0
|
||||
# c all caller-saved registers
|
||||
@@ -0,0 +1,29 @@
|
||||
# Licensed to the .NET Foundation under one or more agreements.
|
||||
# The .NET Foundation licenses this file to you under the MIT license.
|
||||
# See the LICENSE file in the project root for more information.
|
||||
#
|
||||
# RISC-V RV64 Machine Description
|
||||
#
|
||||
# This file describes various properties of Mini instructions for RV64 and is
|
||||
# read by genmdesc.py to generate a C header file used by various parts of the
|
||||
# JIT.
|
||||
#
|
||||
# Lines are of the form:
|
||||
#
|
||||
# <name>: len:<length> [dest:<rspec>] [src1:<rspec>] [src2:<rspec>] [src3:<rspec>] [clob:<cspec>]
|
||||
#
|
||||
# Here, <name> is the name of the instruction as specified in mini-ops.h.
|
||||
# length is the maximum number of bytes that could be needed to generate native
|
||||
# code for the instruction. dest, src1, src2, and src3 specify output and input
|
||||
# registers needed by the instruction. <rspec> can be one of:
|
||||
#
|
||||
# a a0
|
||||
# i any integer register
|
||||
# b any integer register (used as a pointer)
|
||||
# f any float register (a0 in soft float)
|
||||
#
|
||||
# clob specifies which registers are clobbered (i.e. overwritten with garbage)
|
||||
# by the instruction. <cspec> can be one of:
|
||||
#
|
||||
# a a0
|
||||
# c all caller-saved registers
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Licensed to the .NET Foundation under one or more agreements.
|
||||
* The .NET Foundation licenses this file to you under the MIT license.
|
||||
* See the LICENSE file in the project root for more information.
|
||||
*/
|
||||
|
||||
#include "mini-runtime.h"
|
||||
|
||||
#include <mono/metadata/abi-details.h>
|
||||
#include <mono/utils/mono-sigcontext.h>
|
||||
|
||||
#ifndef DISABLE_JIT
|
||||
|
||||
gpointer
|
||||
mono_arch_get_restore_context (MonoTrampInfo **info, gboolean aot)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_get_throw_exception (MonoTrampInfo **info, gboolean aot)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_get_rethrow_exception (MonoTrampInfo **info, gboolean aot)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_get_throw_corlib_exception (MonoTrampInfo **info, gboolean aot)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
gpointer
|
||||
mono_arch_get_restore_context (MonoTrampInfo **info, gboolean aot)
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot)
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot)
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_get_throw_exception (MonoTrampInfo **info, gboolean aot)
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_get_rethrow_exception (MonoTrampInfo **info, gboolean aot)
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_get_throw_corlib_exception (MonoTrampInfo **info, gboolean aot)
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void
|
||||
mono_arch_exceptions_init (void)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mono_arch_unwind_frame (MonoDomain *domain, MonoJitTlsData *jit_tls, MonoJitInfo *ji,
|
||||
MonoContext *ctx, MonoContext *new_ctx, MonoLMF **lmf,
|
||||
mgreg_t **save_locations, StackFrameInfo *frame)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
handle_signal_exception (gpointer obj)
|
||||
{
|
||||
MonoJitTlsData *jit_tls = mono_tls_get_jit_tls ();
|
||||
MonoContext ctx = jit_tls->ex_ctx;
|
||||
|
||||
mono_handle_exception (&ctx, obj);
|
||||
mono_restore_context (&ctx);
|
||||
}
|
||||
|
||||
gboolean
|
||||
mono_arch_handle_exception (void *ctx, gpointer obj)
|
||||
{
|
||||
MonoJitTlsData *jit_tls = mono_tls_get_jit_tls ();
|
||||
|
||||
mono_sigctx_to_monoctx (ctx, &jit_tls->ex_ctx);
|
||||
|
||||
// Call handle_signal_exception () on the normal stack.
|
||||
UCONTEXT_GREGS (ctx) [RISCV_A0] = (long) obj;
|
||||
UCONTEXT_REG_PC (ctx) = (long) handle_signal_exception;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_ip_from_context (void *sigctx)
|
||||
{
|
||||
return (gpointer) UCONTEXT_REG_PC (sigctx);
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_setup_async_callback (MonoContext *ctx, void (*async_cb)(void *fun), gpointer user_data)
|
||||
{
|
||||
// Allocate a stack frame and redirect PC.
|
||||
MONO_CONTEXT_SET_SP (ctx, (mgreg_t) MONO_CONTEXT_GET_SP (ctx) - 32);
|
||||
|
||||
mono_arch_setup_resume_sighandler_ctx (ctx, async_cb);
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_setup_resume_sighandler_ctx (MonoContext *ctx, gpointer func)
|
||||
{
|
||||
MONO_CONTEXT_SET_IP (ctx, func);
|
||||
}
|
||||
|
||||
/*
|
||||
void
|
||||
mono_arch_undo_ip_adjustment (MonoContext *ctx)
|
||||
{
|
||||
MONO_CONTEXT_SET_IP (ctx, (guint8 *) MONO_CONTEXT_GET_IP (ctx) + 1);
|
||||
}
|
||||
*/
|
||||
@@ -26,6 +26,9 @@ allowed_defines = { "TARGET_X86" : 1,
|
||||
"TARGET_SPARC" : 1,
|
||||
"TARGET_S390X" : 1,
|
||||
"TARGET_MIPS" : 1,
|
||||
"TARGET_RISCV" : 1,
|
||||
"TARGET_RISCV32" : 1,
|
||||
"TARGET_RISCV64" : 1,
|
||||
"TARGET_WASM" : 1
|
||||
}
|
||||
|
||||
|
||||
@@ -257,6 +257,10 @@ mono_disassemble_code (MonoCompile *cfg, guint8 *code, int size, char *id)
|
||||
#define AS_CMD "as -arch ppc64"
|
||||
#elif defined(__powerpc64__)
|
||||
#define AS_CMD "as -mppc64"
|
||||
#elif defined (TARGET_RISCV64)
|
||||
#define AS_CMD "as -march=rv64ima"
|
||||
#elif defined (TARGET_RISCV32)
|
||||
#define AS_CMD "as -march=rv32ima"
|
||||
#else
|
||||
#define AS_CMD "as"
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#include "mini-arm64.h"
|
||||
#elif defined(__mips__)
|
||||
#include "mini-mips.h"
|
||||
#elif defined (TARGET_RISCV)
|
||||
#include "mini-riscv.h"
|
||||
#elif TARGET_WASM
|
||||
#include "mini-wasm.h"
|
||||
#else
|
||||
|
||||
@@ -1148,7 +1148,7 @@ mono_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
|
||||
desc_to_fixed_reg_inited = TRUE;
|
||||
|
||||
/* Validate the cpu description against the info in mini-ops.h */
|
||||
#if defined(TARGET_AMD64) || defined(TARGET_X86) || defined(TARGET_ARM) || defined(TARGET_ARM64)
|
||||
#if defined(TARGET_AMD64) || defined(TARGET_X86) || defined(TARGET_ARM) || defined(TARGET_ARM64) || defined (TARGET_RISCV)
|
||||
for (i = OP_LOAD; i < OP_LAST; ++i) {
|
||||
const char *ispec;
|
||||
|
||||
|
||||
@@ -408,6 +408,11 @@ encode_frame_reg (int frame_reg)
|
||||
return 0;
|
||||
else if (frame_reg == S390_FP)
|
||||
return 1;
|
||||
#elif defined (TARGET_RISCV)
|
||||
if (frame_reg == RISCV_SP)
|
||||
return 0;
|
||||
else if (frame_reg == RISCV_FP)
|
||||
return 1;
|
||||
#else
|
||||
NOT_IMPLEMENTED;
|
||||
#endif
|
||||
@@ -438,6 +443,11 @@ decode_frame_reg (int encoded)
|
||||
return S390_SP;
|
||||
else if (encoded == 1)
|
||||
return S390_FP;
|
||||
#elif defined (TARGET_RISCV)
|
||||
if (encoded == 0)
|
||||
return RISCV_SP;
|
||||
else if (encoded == 1)
|
||||
return RISCV_FP;
|
||||
#else
|
||||
NOT_IMPLEMENTED;
|
||||
#endif
|
||||
@@ -469,6 +479,11 @@ static int callee_saved_regs [] = {
|
||||
ppc_r29, ppc_r30, ppc_r31 };
|
||||
#elif defined(TARGET_POWERPC)
|
||||
static int callee_saved_regs [] = { ppc_r6, ppc_r7, ppc_r8, ppc_r9, ppc_r10, ppc_r11, ppc_r12, ppc_r13, ppc_r14 };
|
||||
#elif defined (TARGET_RISCV)
|
||||
static int callee_saved_regs [] = {
|
||||
RISCV_S0, RISCV_S1, RISCV_S2, RISCV_S3, RISCV_S4, RISCV_S5,
|
||||
RISCV_S6, RISCV_S7, RISCV_S8, RISCV_S9, RISCV_S10, RISCV_S11,
|
||||
};
|
||||
#endif
|
||||
|
||||
static guint32
|
||||
@@ -721,6 +736,11 @@ get_frame_pointer (MonoContext *ctx, int frame_reg)
|
||||
return (mgreg_t)MONO_CONTEXT_GET_SP (ctx);
|
||||
else if (frame_reg == S390_FP)
|
||||
return (mgreg_t)MONO_CONTEXT_GET_BP (ctx);
|
||||
#elif defined (TARGET_RISCV)
|
||||
if (frame_reg == RISCV_SP)
|
||||
return MONO_CONTEXT_GET_SP (ctx);
|
||||
else if (frame_reg == RISCV_FP)
|
||||
return MONO_CONTEXT_GET_BP (ctx);
|
||||
#endif
|
||||
g_assert_not_reached ();
|
||||
return 0;
|
||||
|
||||
@@ -0,0 +1,691 @@
|
||||
/*
|
||||
* Licensed to the .NET Foundation under one or more agreements.
|
||||
* The .NET Foundation licenses this file to you under the MIT license.
|
||||
* See the LICENSE file in the project root for more information.
|
||||
*/
|
||||
|
||||
#include <mono/utils/mono-hwcap.h>
|
||||
|
||||
#include "mini-runtime.h"
|
||||
|
||||
#ifdef TARGET_RISCV64
|
||||
#include "cpu-riscv64.h"
|
||||
#else
|
||||
#include "cpu-riscv32.h"
|
||||
#endif
|
||||
|
||||
static gboolean riscv_stdext_a, riscv_stdext_b, riscv_stdext_c,
|
||||
riscv_stdext_d, riscv_stdext_f, riscv_stdext_j,
|
||||
riscv_stdext_l, riscv_stdext_m, riscv_stdext_n,
|
||||
riscv_stdext_p, riscv_stdext_q, riscv_stdext_t,
|
||||
riscv_stdext_v;
|
||||
|
||||
void
|
||||
mono_arch_cpu_init (void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_init (void)
|
||||
{
|
||||
riscv_stdext_a = mono_hwcap_riscv_has_stdext_a;
|
||||
riscv_stdext_c = mono_hwcap_riscv_has_stdext_c;
|
||||
riscv_stdext_d = mono_hwcap_riscv_has_stdext_d;
|
||||
riscv_stdext_f = mono_hwcap_riscv_has_stdext_f;
|
||||
riscv_stdext_m = mono_hwcap_riscv_has_stdext_m;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_finish_init (void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_register_lowlevel_calls (void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_cleanup (void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_set_target (char *mtriple)
|
||||
{
|
||||
// riscv{32,64}[extensions]-[<vendor>-]<system>-<abi>
|
||||
|
||||
size_t len = strlen (MONO_RISCV_ARCHITECTURE);
|
||||
|
||||
if (!strncmp (mtriple, MONO_RISCV_ARCHITECTURE, len)) {
|
||||
mtriple += len;
|
||||
|
||||
for (;;) {
|
||||
char c = *mtriple;
|
||||
|
||||
if (!c || c == '-')
|
||||
break;
|
||||
|
||||
// ISA manual says upper and lower case are both OK.
|
||||
switch (c) {
|
||||
case 'A':
|
||||
case 'a':
|
||||
riscv_stdext_a = TRUE;
|
||||
break;
|
||||
case 'B':
|
||||
case 'b':
|
||||
riscv_stdext_b = TRUE;
|
||||
break;
|
||||
case 'C':
|
||||
case 'c':
|
||||
riscv_stdext_c = TRUE;
|
||||
break;
|
||||
case 'D':
|
||||
case 'd':
|
||||
riscv_stdext_d = TRUE;
|
||||
break;
|
||||
case 'F':
|
||||
case 'f':
|
||||
riscv_stdext_f = TRUE;
|
||||
break;
|
||||
case 'J':
|
||||
case 'j':
|
||||
riscv_stdext_j = TRUE;
|
||||
break;
|
||||
case 'L':
|
||||
case 'l':
|
||||
riscv_stdext_l = TRUE;
|
||||
break;
|
||||
case 'M':
|
||||
case 'm':
|
||||
riscv_stdext_m = TRUE;
|
||||
break;
|
||||
case 'N':
|
||||
case 'n':
|
||||
riscv_stdext_n = TRUE;
|
||||
break;
|
||||
case 'P':
|
||||
case 'p':
|
||||
riscv_stdext_p = TRUE;
|
||||
break;
|
||||
case 'Q':
|
||||
case 'q':
|
||||
riscv_stdext_q = TRUE;
|
||||
break;
|
||||
case 'T':
|
||||
case 't':
|
||||
riscv_stdext_t = TRUE;
|
||||
break;
|
||||
case 'V':
|
||||
case 'v':
|
||||
riscv_stdext_v = TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
mtriple++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
guint32
|
||||
mono_arch_cpu_optimizations (guint32 *exclude_mask)
|
||||
{
|
||||
*exclude_mask = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
guint32
|
||||
mono_arch_cpu_enumerate_simd_versions (void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mono_arch_have_fast_tls (void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mono_arch_opcode_supported (int opcode)
|
||||
{
|
||||
switch (opcode) {
|
||||
case OP_ATOMIC_ADD_I4:
|
||||
case OP_ATOMIC_EXCHANGE_I4:
|
||||
case OP_ATOMIC_CAS_I4:
|
||||
case OP_ATOMIC_LOAD_I1:
|
||||
case OP_ATOMIC_LOAD_I2:
|
||||
case OP_ATOMIC_LOAD_I4:
|
||||
case OP_ATOMIC_LOAD_U1:
|
||||
case OP_ATOMIC_LOAD_U2:
|
||||
case OP_ATOMIC_LOAD_U4:
|
||||
case OP_ATOMIC_STORE_I1:
|
||||
case OP_ATOMIC_STORE_I2:
|
||||
case OP_ATOMIC_STORE_I4:
|
||||
case OP_ATOMIC_STORE_U1:
|
||||
case OP_ATOMIC_STORE_U2:
|
||||
case OP_ATOMIC_STORE_U4:
|
||||
#ifdef TARGET_RISCV64
|
||||
case OP_ATOMIC_ADD_I8:
|
||||
case OP_ATOMIC_EXCHANGE_I8:
|
||||
case OP_ATOMIC_CAS_I8:
|
||||
case OP_ATOMIC_LOAD_I8:
|
||||
case OP_ATOMIC_LOAD_U8:
|
||||
case OP_ATOMIC_STORE_I8:
|
||||
case OP_ATOMIC_STORE_U8:
|
||||
#endif
|
||||
return riscv_stdext_a;
|
||||
case OP_ATOMIC_LOAD_R4:
|
||||
case OP_ATOMIC_STORE_R4:
|
||||
#ifdef TARGET_RISCV64
|
||||
case OP_ATOMIC_LOAD_R8:
|
||||
case OP_ATOMIC_STORE_R8:
|
||||
#endif
|
||||
return riscv_stdext_a && riscv_stdext_d;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
mono_arch_regname (int reg)
|
||||
{
|
||||
static const char *names [RISCV_N_GREGS] = {
|
||||
"zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2",
|
||||
"s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5",
|
||||
"a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7",
|
||||
"s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6",
|
||||
};
|
||||
|
||||
if (reg >= 0 && reg < G_N_ELEMENTS (names))
|
||||
return names [reg];
|
||||
|
||||
return "x?";
|
||||
}
|
||||
|
||||
const char*
|
||||
mono_arch_fregname (int reg)
|
||||
{
|
||||
static const char *names [RISCV_N_FREGS] = {
|
||||
"ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7",
|
||||
"fs0", "fs1", "fa0", "fa1", "fa2", "fa3", "fa4", "fa5",
|
||||
"fa6", "fa7", "fs2", "fs3", "fs4", "fs5", "fs6", "fs7",
|
||||
"fs8", "fs9", "fs10", "fs11", "ft8", "ft9", "ft10", "ft11",
|
||||
};
|
||||
|
||||
if (reg >= 0 && reg < G_N_ELEMENTS (names))
|
||||
return names [reg];
|
||||
|
||||
return "f?";
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_get_this_arg_from_call (mgreg_t *regs, guint8 *code)
|
||||
{
|
||||
return (gpointer) regs [RISCV_A0];
|
||||
}
|
||||
|
||||
MonoMethod *
|
||||
mono_arch_find_imt_method (mgreg_t *regs, guint8 *code)
|
||||
{
|
||||
return (MonoMethod *) regs [MONO_ARCH_IMT_REG];
|
||||
}
|
||||
|
||||
MonoVTable *
|
||||
mono_arch_find_static_call_vtable (mgreg_t *regs, guint8 *code)
|
||||
{
|
||||
return (MonoVTable *) regs [MONO_ARCH_VTABLE_REG];
|
||||
}
|
||||
|
||||
mgreg_t
|
||||
mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
|
||||
{
|
||||
return ctx->gregs [reg];
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_context_set_int_reg (MonoContext *ctx, int reg, mgreg_t val)
|
||||
{
|
||||
ctx->gregs [reg] = val;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_flush_register_windows (void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_flush_icache (guint8 *code, gint size)
|
||||
{
|
||||
#ifndef MONO_CROSS_COMPILE
|
||||
__builtin___clear_cache (code, code + size);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_set_native_call_context (CallContext *ccontext, gpointer frame,
|
||||
MonoMethodSignature *sig)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_get_native_call_context (CallContext *ccontext, gpointer frame,
|
||||
MonoMethodSignature *sig)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
MonoDynCallInfo *
|
||||
mono_arch_dyn_call_prepare (MonoMethodSignature *sig)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_dyn_call_free (MonoDynCallInfo *info)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
int
|
||||
mono_arch_dyn_call_get_buf_size (MonoDynCallInfo *info)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_start_dyn_call (MonoDynCallInfo *info, gpointer **args, guint8 *ret,
|
||||
guint8 *buf)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_finish_dyn_call (MonoDynCallInfo *info, guint8 *buf)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
int
|
||||
mono_arch_get_argument_info (MonoMethodSignature *csig, int param_count,
|
||||
MonoJitArgumentInfo *arg_info)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_patch_code_new (MonoCompile *cfg, MonoDomain *domain, guint8 *code,
|
||||
MonoJumpInfo *ji, gpointer target)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
#ifndef DISABLE_JIT
|
||||
|
||||
#ifdef MONO_ARCH_SOFT_FLOAT_FALLBACK
|
||||
|
||||
gboolean
|
||||
mono_arch_is_soft_float (void)
|
||||
{
|
||||
return !riscv_stdext_d;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
gboolean
|
||||
mono_arch_opcode_needs_emulation (MonoCompile *cfg, int opcode)
|
||||
{
|
||||
switch (opcode) {
|
||||
case OP_IDIV:
|
||||
case OP_IDIV_UN:
|
||||
case OP_IREM:
|
||||
case OP_IREM_UN:
|
||||
#ifdef TARGET_RISCV64
|
||||
case OP_LDIV:
|
||||
case OP_LDIV_UN:
|
||||
case OP_LREM:
|
||||
case OP_LREM_UN:
|
||||
#endif
|
||||
return !riscv_stdext_m;
|
||||
default:
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
mono_arch_tail_call_supported (MonoCompile *cfg, MonoMethodSignature *caller_sig,
|
||||
MonoMethodSignature *callee_sig)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mono_arch_is_inst_imm (int opcode, int imm_opcode, gint64 imm)
|
||||
{
|
||||
// TODO: Make a proper decision based on opcode.
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GList *
|
||||
mono_arch_get_allocatable_int_vars (MonoCompile *cfg)
|
||||
{
|
||||
GList *vars = NULL;
|
||||
|
||||
for (guint i = 0; i < cfg->num_varinfo; i++) {
|
||||
MonoInst *ins = cfg->varinfo [i];
|
||||
MonoMethodVar *vmv = MONO_VARINFO (cfg, i);
|
||||
|
||||
if (vmv->range.first_use.abs_pos >= vmv->range.last_use.abs_pos)
|
||||
continue;
|
||||
|
||||
if ((ins->flags & (MONO_INST_IS_DEAD | MONO_INST_VOLATILE | MONO_INST_INDIRECT)) ||
|
||||
(ins->opcode != OP_LOCAL && ins->opcode != OP_ARG))
|
||||
continue;
|
||||
|
||||
if (!mono_is_regsize_var (ins->inst_vtype))
|
||||
continue;
|
||||
|
||||
vars = g_list_prepend (vars, vmv);
|
||||
}
|
||||
|
||||
vars = mono_varlist_sort (cfg, vars, 0);
|
||||
|
||||
return vars;
|
||||
}
|
||||
|
||||
GList *
|
||||
mono_arch_get_global_int_regs (MonoCompile *cfg)
|
||||
{
|
||||
GList *regs = NULL;
|
||||
|
||||
for (int i = RISCV_S0; i <= RISCV_S11; i++)
|
||||
regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
|
||||
|
||||
return regs;
|
||||
}
|
||||
|
||||
guint32
|
||||
mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
|
||||
{
|
||||
return cfg->varinfo [vmv->idx]->opcode == OP_ARG ? 1 : 2;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_LLVM
|
||||
|
||||
LLVMCallInfo*
|
||||
mono_arch_get_llvm_call_info (MonoCompile *cfg, MonoMethodSignature *sig)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void
|
||||
mono_arch_create_vars (MonoCompile *cfg)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
MonoInst *
|
||||
mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod,
|
||||
MonoMethodSignature *fsig, MonoInst **args)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_decompose_long_opts (MonoCompile *cfg, MonoInst *long_ins)
|
||||
{
|
||||
#ifdef TARGET_RISCV32
|
||||
NOT_IMPLEMENTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_allocate_vars (MonoCompile *cfg)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
|
||||
{
|
||||
}
|
||||
|
||||
// Uses at most 8 bytes on RV32I and 16 bytes on RV64I.
|
||||
guint8 *
|
||||
mono_riscv_emit_imm (guint8 *code, int rd, gsize imm)
|
||||
{
|
||||
#ifdef TARGET_RISCV64
|
||||
if (RISCV_VALID_I_IMM (imm)) {
|
||||
riscv_addi (code, rd, RISCV_ZERO, imm);
|
||||
return code;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is not pretty, but RV64I doesn't make it easy to load constants.
|
||||
* Need to figure out something better.
|
||||
*/
|
||||
riscv_jal (code, rd, sizeof (guint64));
|
||||
*(guint64 *) code = imm;
|
||||
code += sizeof (guint64);
|
||||
riscv_ld (code, rd, rd, 0);
|
||||
#else
|
||||
if (RISCV_VALID_I_IMM (imm)) {
|
||||
riscv_addi (code, rd, RISCV_ZERO, imm);
|
||||
return code;
|
||||
}
|
||||
|
||||
riscv_lui (code, rd, RISCV_BITS (imm, 12, 20));
|
||||
|
||||
if (!RISCV_VALID_U_IMM (imm))
|
||||
riscv_ori (code, rd, rd, RISCV_BITS (imm, 0, 12));
|
||||
#endif
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
// Uses at most 16 bytes on RV32I and 24 bytes on RV64I.
|
||||
guint8 *
|
||||
mono_riscv_emit_load (guint8 *code, int rd, int rs1, gint32 imm)
|
||||
{
|
||||
if (RISCV_VALID_I_IMM (imm)) {
|
||||
#ifdef TARGET_RISCV64
|
||||
riscv_ld (code, rd, rs1, imm);
|
||||
#else
|
||||
riscv_lw (code, rd, rs1, imm);
|
||||
#endif
|
||||
} else {
|
||||
code = mono_riscv_emit_imm (code, rd, imm);
|
||||
riscv_add (code, rd, rs1, rd);
|
||||
#ifdef TARGET_RISCV64
|
||||
riscv_ld (code, rd, rd, 0);
|
||||
#else
|
||||
riscv_lw (code, rd, rd, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
// May clobber t1. Uses at most 16 bytes on RV32I and 24 bytes on RV64I.
|
||||
guint8 *
|
||||
mono_riscv_emit_store (guint8 *code, int rs1, int rs2, gint32 imm)
|
||||
{
|
||||
if (RISCV_VALID_S_IMM (imm)) {
|
||||
#ifdef TARGET_RISCV64
|
||||
riscv_sd (code, rs1, rs2, imm);
|
||||
#else
|
||||
riscv_sw (code, rs1, rs2, imm);
|
||||
#endif
|
||||
} else {
|
||||
code = mono_riscv_emit_imm (code, RISCV_T1, imm);
|
||||
riscv_add (code, RISCV_T1, rs2, RISCV_T1);
|
||||
#ifdef TARGET_RISCV64
|
||||
riscv_sd (code, rs1, RISCV_T1, 0);
|
||||
#else
|
||||
riscv_sw (code, rs1, RISCV_T1, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void *
|
||||
mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
|
||||
gboolean enable_arguments)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *
|
||||
mono_arch_instrument_epilog (MonoCompile *cfg, void *func, void *p,
|
||||
gboolean enable_arguments)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
guint8 *
|
||||
mono_arch_emit_prolog (MonoCompile *cfg)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_emit_epilog (MonoCompile *cfg)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_emit_exceptions (MonoCompile *cfg)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
guint32
|
||||
mono_arch_get_patch_offset (guint8 *code)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
GSList *
|
||||
mono_arch_get_trampolines (gboolean aot)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void
|
||||
mono_arch_set_breakpoint (MonoJitInfo *ji, guint8 *ip)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_clear_breakpoint (MonoJitInfo *ji, guint8 *ip)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_start_single_stepping (void)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_stop_single_stepping (void)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mono_arch_is_single_step_event (void *info, void *sigctx)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mono_arch_is_breakpoint_event (void *info, void *sigctx)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_skip_breakpoint (MonoContext *ctx, MonoJitInfo *ji)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_skip_single_step (MonoContext *ctx)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_get_seq_point_info (MonoDomain *domain, guint8 *code)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* Licensed to the .NET Foundation under one or more agreements.
|
||||
* The .NET Foundation licenses this file to you under the MIT license.
|
||||
* See the LICENSE file in the project root for more information.
|
||||
*/
|
||||
|
||||
#ifndef __MONO_MINI_RISCV_H__
|
||||
#define __MONO_MINI_RISCV_H__
|
||||
|
||||
#include <mono/arch/riscv/riscv-codegen.h>
|
||||
|
||||
#ifdef TARGET_RISCV64
|
||||
#define MONO_RISCV_ARCHITECTURE "riscv64"
|
||||
#else
|
||||
#define MONO_RISCV_ARCHITECTURE "riscv32"
|
||||
#endif
|
||||
|
||||
#if defined (RISCV_FPABI_SOFT)
|
||||
#define MONO_ARCH_SOFT_FLOAT_FALLBACK
|
||||
#define RISCV_FP_MODEL "soft-fp"
|
||||
#elif defined (RISCV_FPABI_DOUBLE)
|
||||
#define RISCV_FP_MODEL "double-fp"
|
||||
#elif defined (RISCV_FPABI_SINGLE)
|
||||
#define RISCV_FP_MODEL "single-fp"
|
||||
#error "The single-precision RISC-V hard float ABI is not currently supported."
|
||||
#else
|
||||
#error "Unknown RISC-V FPABI. This is probably a bug in configure.ac."
|
||||
#endif
|
||||
|
||||
#define MONO_ARCH_ARCHITECTURE MONO_RISCV_ARCHITECTURE "," RISCV_FP_MODEL
|
||||
|
||||
#ifdef TARGET_RISCV64
|
||||
#define MONO_ARCH_CPU_SPEC mono_riscv64_cpu_desc
|
||||
#else
|
||||
#define MONO_ARCH_CPU_SPEC mono_riscv32_cpu_desc
|
||||
#endif
|
||||
|
||||
#define MONO_MAX_IREGS (RISCV_N_GREGS)
|
||||
#define MONO_MAX_FREGS (RISCV_N_FREGS)
|
||||
|
||||
/*
|
||||
* Register usage conventions:
|
||||
*
|
||||
* - a0..a7 and fa0..fa7 are argument/return registers.
|
||||
* - s0..11 and fs0..fs11 are callee-saved registers.
|
||||
* - a0..a1 are used as fixed registers (for the 'a' spec, soft float, and
|
||||
* longs on 32-bit, as appropriate).
|
||||
* - t0..t1, ra, and ft0..ft2 are used as scratch registers and can't be
|
||||
* allocated by the register allocator.
|
||||
* - t2 is used as the RGCTX/IMT register and can't be allocated by the
|
||||
* register allocator.
|
||||
* - a0 is used as the VTable register for lazy fetch trampolines.
|
||||
* - sp, fp, gp, and tp are all reserved by the ABI and can't be allocated by
|
||||
* the register allocator.
|
||||
* - x0 is hard-wired to zero and can't be allocated by the register allocator.
|
||||
*/
|
||||
|
||||
#define MONO_ARCH_CALLEE_REGS (0b11110000000000111111110000000000)
|
||||
#define MONO_ARCH_CALLEE_SAVED_REGS (0b00001111111111000000001100000000)
|
||||
|
||||
#ifdef RISCV_FPABI_SOFT
|
||||
|
||||
#define MONO_ARCH_CALLEE_FREGS (0b11111111111111111111111111111000)
|
||||
#define MONO_ARCH_CALLEE_SAVED_FREGS (0b00000000000000000000000000000000)
|
||||
|
||||
#else
|
||||
|
||||
#define MONO_ARCH_CALLEE_FREGS (0b11110000000000111111110011111000)
|
||||
#define MONO_ARCH_CALLEE_SAVED_FREGS (0b00001111111111000000001100000000)
|
||||
|
||||
#endif
|
||||
|
||||
#define MONO_ARCH_INST_SREG2_MASK(ins) \
|
||||
(0)
|
||||
#define MONO_ARCH_INST_IS_FLOAT(desc) \
|
||||
(!mono_arch_is_soft_float () && (desc) == 'f')
|
||||
|
||||
#ifdef TARGET_RISCV64
|
||||
|
||||
#define MONO_ARCH_INST_FIXED_REG(desc) \
|
||||
((desc) == 'a' || (mono_arch_is_soft_float () && (desc) == 'f') ? RISCV_A0 : -1)
|
||||
#define MONO_ARCH_INST_IS_REGPAIR(desc) \
|
||||
(FALSE)
|
||||
#define MONO_ARCH_INST_REGPAIR_REG2(desc, hreg1) \
|
||||
(-1)
|
||||
|
||||
#else
|
||||
|
||||
#define MONO_ARCH_INST_FIXED_REG(desc) \
|
||||
((desc) == 'a' || (desc) == 'l' || (mono_arch_is_soft_float () && (desc) == 'f') ? RISCV_A0 : -1)
|
||||
#define MONO_ARCH_INST_IS_REGPAIR(desc) \
|
||||
((desc) == 'l' || (mono_arch_is_soft_float () && (desc) == 'f'))
|
||||
#define MONO_ARCH_INST_REGPAIR_REG2(desc, hreg1) \
|
||||
(RISCV_A1)
|
||||
|
||||
#endif
|
||||
|
||||
#define MONO_ARCH_RGCTX_REG (RISCV_T2)
|
||||
#define MONO_ARCH_IMT_REG (RISCV_T2)
|
||||
#define MONO_ARCH_VTABLE_REG (RISCV_A0)
|
||||
|
||||
#define MONO_ARCH_USE_FPSTACK (FALSE)
|
||||
|
||||
#define MONO_ARCH_FRAME_ALIGNMENT (16)
|
||||
#define MONO_ARCH_CODE_ALIGNMENT (32)
|
||||
|
||||
#define MONO_ARCH_EMULATE_MUL_DIV (1)
|
||||
#define MONO_ARCH_EMULATE_FREM (1)
|
||||
|
||||
#ifdef TARGET_RISCV64
|
||||
|
||||
#define MONO_ARCH_NO_EMULATE_LONG_SHIFT_OPS (1)
|
||||
|
||||
#endif
|
||||
|
||||
#define MONO_ARCH_EMULATE_CONV_R8_UN (1)
|
||||
#define MONO_ARCH_EMULATE_FCONV_TO_I8 (1)
|
||||
#define MONO_ARCH_EMULATE_LCONV_TO_R8 (1)
|
||||
#define MONO_ARCH_EMULATE_LCONV_TO_R4 (1)
|
||||
#define MONO_ARCH_EMULATE_LCONV_TO_R8_UN (1)
|
||||
|
||||
#define MONO_ARCH_NEED_DIV_CHECK (1)
|
||||
|
||||
#define MONO_ARCH_HAVE_OP_TAIL_CALL (1)
|
||||
#define MONO_ARCH_HAVE_OP_GENERIC_CLASS_INIT (1)
|
||||
#define MONO_ARCH_HAVE_CARD_TABLE_WBARRIER (1)
|
||||
|
||||
#define MONO_ARCH_HAVE_GENERALIZED_IMT_TRAMPOLINE (1)
|
||||
#define MONO_ARCH_HAVE_GENERAL_RGCTX_LAZY_FETCH_TRAMPOLINE (1)
|
||||
#define MONO_ARCH_HAVE_SDB_TRAMPOLINES (1)
|
||||
#define MONO_ARCH_HAVE_INTERP_PINVOKE_TRAMP (1)
|
||||
#define MONO_ARCH_HAVE_FULL_AOT_TRAMPOLINES (1)
|
||||
|
||||
#define MONO_ARCH_USE_SIGACTION (1)
|
||||
#define MONO_ARCH_HAVE_SIGCTX_TO_MONOCTX (1)
|
||||
|
||||
#define MONO_ARCH_HAVE_CONTEXT_SET_INT_REG (1)
|
||||
#define MONO_ARCH_HAVE_DECOMPOSE_LONG_OPTS (1)
|
||||
#define MONO_ARCH_HAVE_DECOMPOSE_OPTS (1)
|
||||
#define MONO_ARCH_HAVE_EXCEPTIONS_INIT (1)
|
||||
#define MONO_ARCH_HAVE_GET_TRAMPOLINES (1)
|
||||
#define MONO_ARCH_HAVE_OPCODE_NEEDS_EMULATION (1)
|
||||
#define MONO_ARCH_HAVE_PATCH_CODE_NEW (1)
|
||||
#define MONO_ARCH_HAVE_SETUP_ASYNC_CALLBACK (1)
|
||||
#define MONO_ARCH_HAVE_SETUP_RESUME_FROM_SIGNAL_HANDLER_CTX (1)
|
||||
|
||||
#define MONO_ARCH_GSHARED_SUPPORTED (1)
|
||||
//#define MONO_ARCH_INTERPRETER_SUPPORTED (1)
|
||||
//#define MONO_ARCH_AOT_SUPPORTED (1)
|
||||
//#define MONO_ARCH_LLVM_SUPPORTED (1)
|
||||
//#define MONO_ARCH_SOFT_DEBUG_SUPPORTED (1)
|
||||
|
||||
typedef struct {
|
||||
} MonoCompileArch;
|
||||
|
||||
#define MONO_CONTEXT_SET_LLVM_EXC_REG(ctx, exc) \
|
||||
do { \
|
||||
(ctx)->gregs [RISCV_A0] = (mgreg_t) exc; \
|
||||
} while (0)
|
||||
|
||||
#define MONO_INIT_CONTEXT_FROM_FUNC(ctx, func) \
|
||||
do { \
|
||||
MONO_CONTEXT_SET_IP ((ctx), (func)); \
|
||||
MONO_CONTEXT_SET_SP ((ctx), __builtin_frame_address (0)); \
|
||||
MONO_CONTEXT_SET_BP ((ctx), __builtin_frame_address (0)); \
|
||||
} while (0)
|
||||
|
||||
struct MonoLMF {
|
||||
// If the second-lowest bit of this field is set, this is a MonoLMFExt.
|
||||
gpointer previous_lmf;
|
||||
gpointer lmf_addr;
|
||||
mgreg_t pc;
|
||||
mgreg_t sp;
|
||||
mgreg_t ra;
|
||||
mgreg_t gregs [RISCV_N_GSREGS]; // s0..s11
|
||||
double fregs [RISCV_N_FSREGS]; // fs0..fs11
|
||||
};
|
||||
|
||||
#define MONO_ARCH_INIT_TOP_LMF_ENTRY(lmf)
|
||||
|
||||
typedef struct {
|
||||
} CallContext;
|
||||
|
||||
enum {
|
||||
MONO_R_RISCV_IMM = 1,
|
||||
MONO_R_RISCV_B = 2,
|
||||
MONO_R_RISCV_BEQ = 3,
|
||||
MONO_R_RISCV_BNE = 4,
|
||||
MONO_R_RISCV_BLT = 5,
|
||||
MONO_R_RISCV_BGE = 6,
|
||||
MONO_R_RISCV_BLTU = 7,
|
||||
MONO_R_RISCV_BGEU = 8,
|
||||
};
|
||||
|
||||
__attribute__ ((warn_unused_result)) guint8 *
|
||||
mono_riscv_emit_imm (guint8 *code, int rd, gsize imm);
|
||||
|
||||
__attribute__ ((warn_unused_result)) guint8 *
|
||||
mono_riscv_emit_load (guint8 *code, int rd, int rs1, gint32 imm);
|
||||
|
||||
__attribute__ ((warn_unused_result)) guint8 *
|
||||
mono_riscv_emit_store (guint8 *code, int rs1, int rs2, gint32 imm);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,293 @@
|
||||
/*
|
||||
* Licensed to the .NET Foundation under one or more agreements.
|
||||
* The .NET Foundation licenses this file to you under the MIT license.
|
||||
* See the LICENSE file in the project root for more information.
|
||||
*/
|
||||
|
||||
#include "mini-runtime.h"
|
||||
|
||||
#include <mono/metadata/abi-details.h>
|
||||
|
||||
void
|
||||
mono_arch_patch_callsite (guint8 *method_start, guint8 *code_ptr, guint8 *addr)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void
|
||||
mono_arch_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *addr)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
guint8 *
|
||||
mono_arch_get_call_target (guint8 *code)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
guint32
|
||||
mono_arch_get_plt_info_offset (guint8 *plt_entry, mgreg_t *regs, guint8 *code)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
GSList *
|
||||
mono_arch_get_delegate_invoke_impls (void)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_target)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_get_delegate_virtual_invoke_impl (MonoMethodSignature *sig,
|
||||
MonoMethod *method, int offset,
|
||||
gboolean load_imt_reg)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifndef DISABLE_JIT
|
||||
|
||||
guchar *
|
||||
mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInfo **info,
|
||||
gboolean aot)
|
||||
{
|
||||
if (aot)
|
||||
NOT_IMPLEMENTED;
|
||||
|
||||
guint8 *buf = mono_global_codeman_reserve (1024), *code = buf;
|
||||
|
||||
if (info) {
|
||||
char *name = mono_get_generic_trampoline_name (tramp_type);
|
||||
*info = mono_tramp_info_create (name, buf, code - buf, NULL, NULL);
|
||||
g_free (name);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type,
|
||||
MonoDomain *domain, guint32 *code_len)
|
||||
{
|
||||
guint8 *buf = mono_domain_code_reserve (domain, 64), *code = buf;
|
||||
guint8 *tramp = mono_get_trampoline_code (tramp_type);
|
||||
|
||||
// Pass the argument in scratch t0.
|
||||
code = mono_riscv_emit_imm (code, RISCV_T0, (gsize) arg1);
|
||||
code = mono_riscv_emit_imm (code, RISCV_T1, (gsize) tramp);
|
||||
riscv_jalr (code, RISCV_ZERO, RISCV_T1, 0);
|
||||
|
||||
mono_arch_flush_icache (buf, code - buf);
|
||||
|
||||
if (code_len)
|
||||
*code_len = code - buf;
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_get_unbox_trampoline (MonoMethod *m, gpointer addr)
|
||||
{
|
||||
guint8 *buf = mono_domain_code_reserve (mono_domain_get (), 64), *code = buf;
|
||||
|
||||
// Pass the argument in a0.
|
||||
code = mono_riscv_emit_imm (code, RISCV_A0, sizeof (MonoObject));
|
||||
code = mono_riscv_emit_imm (code, RISCV_T0, (gsize) addr);
|
||||
riscv_jalr (code, RISCV_ZERO, RISCV_T0, 0);
|
||||
|
||||
mono_arch_flush_icache (buf, code - buf);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_build_imt_trampoline (MonoVTable *vtable, MonoDomain *domain,
|
||||
MonoIMTCheckItem **imt_entries, int count,
|
||||
gpointer fail_tramp)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_get_static_rgctx_trampoline (gpointer arg, gpointer addr)
|
||||
{
|
||||
guint8 *buf = mono_domain_code_reserve (mono_domain_get (), 64), *code = buf;
|
||||
|
||||
// Pass the argument in the RGCTX register.
|
||||
code = mono_riscv_emit_imm (code, MONO_ARCH_RGCTX_REG, (gsize) arg);
|
||||
code = mono_riscv_emit_imm (code, RISCV_T0, (gsize) addr);
|
||||
riscv_jalr (code, RISCV_ZERO, RISCV_T0, 0);
|
||||
|
||||
mono_arch_flush_icache (buf, code - buf);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info,
|
||||
gboolean aot)
|
||||
{
|
||||
if (aot)
|
||||
NOT_IMPLEMENTED;
|
||||
|
||||
gboolean is_mrgctx = MONO_RGCTX_SLOT_IS_MRGCTX (slot);
|
||||
int index = MONO_RGCTX_SLOT_INDEX (slot);
|
||||
|
||||
if (is_mrgctx)
|
||||
index += MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT / sizeof (gpointer);
|
||||
|
||||
int depth;
|
||||
|
||||
for (depth = 0; ; depth++) {
|
||||
int size = mono_class_rgctx_get_array_size (depth, is_mrgctx);
|
||||
|
||||
if (index < size - 1)
|
||||
break;
|
||||
|
||||
index -= size - 1;
|
||||
}
|
||||
|
||||
guint8 *buf = mono_global_codeman_reserve (128 * depth), *code = buf;
|
||||
guint8 **null_jumps = g_malloc0 (sizeof (guint8 *) * (depth + 2));
|
||||
|
||||
if (!is_mrgctx) {
|
||||
} else
|
||||
riscv_addi (code, RISCV_T1, RISCV_A0, 0);
|
||||
|
||||
mono_arch_flush_icache (buf, code - buf);
|
||||
|
||||
if (info) {
|
||||
char *name = mono_get_rgctx_fetch_trampoline_name (slot);
|
||||
*info = mono_tramp_info_create (name, buf, code - buf, NULL, NULL);
|
||||
g_free (name);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_create_general_rgctx_lazy_fetch_trampoline (MonoTrampInfo **info, gboolean aot)
|
||||
{
|
||||
if (aot)
|
||||
NOT_IMPLEMENTED;
|
||||
|
||||
guint8 *buf = mono_global_codeman_reserve (64), *code = buf;
|
||||
|
||||
/*
|
||||
* The RGCTX register holds a pointer to a <slot, trampoline address> pair.
|
||||
* Load the trampoline address and branch to it. a0 holds the actual
|
||||
* (M)RGCTX or VTable.
|
||||
*/
|
||||
code = mono_riscv_emit_load (code, RISCV_T0, MONO_ARCH_RGCTX_REG, sizeof (gpointer));
|
||||
riscv_jalr (code, RISCV_ZERO, RISCV_T0, 0);
|
||||
|
||||
mono_arch_flush_icache (buf, code - buf);
|
||||
|
||||
if (info)
|
||||
*info = mono_tramp_info_create ("rgctx_fetch_trampoline_general", buf, code - buf, NULL, NULL);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
guint8 *
|
||||
mono_arch_create_sdb_trampoline (gboolean single_step, MonoTrampInfo **info, gboolean aot)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
gpointer
|
||||
mono_arch_get_interp_to_native_trampoline (MonoTrampInfo **info)
|
||||
{
|
||||
NOT_IMPLEMENTED;
|
||||
return NULL;
|
||||
}
|
||||
*/
|
||||
|
||||
#else
|
||||
|
||||
guchar *
|
||||
mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInfo **info,
|
||||
gboolean aot)
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type,
|
||||
MonoDomain *domain, guint32 *code_len)
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_get_unbox_trampoline (MonoMethod *m, gpointer addr)
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_build_imt_trampoline (MonoVTable *vtable, MonoDomain *domain,
|
||||
MonoIMTCheckItem **imt_entries, int count,
|
||||
gpointer fail_tramp)
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_get_static_rgctx_trampoline (gpointer arg, gpointer addr)
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info,
|
||||
gboolean aot)
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
mono_arch_create_general_rgctx_lazy_fetch_trampoline (MonoTrampInfo **info, gboolean aot)
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
guint8 *
|
||||
mono_arch_create_sdb_trampoline (gboolean single_step, MonoTrampInfo **info, gboolean aot)
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
gpointer
|
||||
mono_arch_get_interp_to_native_trampoline (MonoTrampInfo **info)
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
return NULL;
|
||||
}
|
||||
*/
|
||||
|
||||
#endif
|
||||
@@ -113,6 +113,26 @@ static int map_hw_reg_to_dwarf_reg [32] = {
|
||||
#define NUM_DWARF_REGS 32
|
||||
#define DWARF_DATA_ALIGN (-(gint32)sizeof (mgreg_t))
|
||||
#define DWARF_PC_REG (mono_hw_reg_to_dwarf_reg (mips_ra))
|
||||
#elif defined(TARGET_RISCV)
|
||||
|
||||
/*
|
||||
* These values have not currently been formalized in the RISC-V psABI. See
|
||||
* instead gcc/config/riscv/riscv.h in the GCC source tree.
|
||||
*/
|
||||
|
||||
#define NUM_DWARF_REGS (RISCV_N_GREGS + RISCV_N_FREGS)
|
||||
#define DWARF_DATA_ALIGN (-4)
|
||||
#define DWARF_PC_REG (mono_hw_reg_to_dwarf_reg (RISCV_RA))
|
||||
|
||||
static int map_hw_reg_to_dwarf_reg [NUM_DWARF_REGS] = {
|
||||
// x0..x31
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
||||
// f0..f31
|
||||
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
|
||||
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
|
||||
};
|
||||
|
||||
#else
|
||||
static int map_hw_reg_to_dwarf_reg [16];
|
||||
#define NUM_DWARF_REGS 16
|
||||
|
||||
@@ -65,6 +65,10 @@
|
||||
|
||||
#define REDZONE_SIZE 0
|
||||
|
||||
#elif defined (TARGET_RISCV)
|
||||
|
||||
#define REDZONE_SIZE (0)
|
||||
|
||||
#elif defined (TARGET_WASM)
|
||||
|
||||
#define REDZONE_SIZE 0
|
||||
|
||||
@@ -524,9 +524,9 @@ static inline int
|
||||
find_card_offset (mword card)
|
||||
{
|
||||
/*XXX Use assembly as this generates some pretty bad code */
|
||||
#if (defined(__i386__) || defined(__arm__)) && defined(__GNUC__)
|
||||
#if (defined(__i386__) || defined(__arm__) || (defined (__riscv) && __riscv_xlen == 32)) && defined(__GNUC__)
|
||||
return (__builtin_ffs (card) - 1) / 8;
|
||||
#elif (defined(__x86_64__) || defined(__aarch64__)) && defined(__GNUC__)
|
||||
#elif (defined(__x86_64__) || defined(__aarch64__) || (defined (__riscv) && __riscv_xlen == 64)) && defined(__GNUC__)
|
||||
return (__builtin_ffsll (card) - 1) / 8;
|
||||
#elif defined(__s390x__)
|
||||
return (__builtin_ffsll (GUINT64_TO_LE(card)) - 1) / 8;
|
||||
|
||||
@@ -290,6 +290,10 @@ if S390X
|
||||
arch_sources += mono-hwcap-s390x.c
|
||||
endif
|
||||
|
||||
if RISCV
|
||||
arch_sources += mono-hwcap-riscv.c
|
||||
endif
|
||||
|
||||
if HOST_WASM
|
||||
arch_sources += mono-hwcap-wasm.c
|
||||
endif
|
||||
|
||||
@@ -566,4 +566,34 @@ mono_monoctx_to_sigctx (MonoContext *mctx, void *sigctx)
|
||||
g_error ("MonoContext not supported");
|
||||
}
|
||||
|
||||
#elif ((defined (HOST_RISCV) || defined (HOST_RISCV64)) && !defined (MONO_CROSS_COMPILE)) || defined (TARGET_RISCV)
|
||||
|
||||
#include <mono/utils/mono-context.h>
|
||||
|
||||
void
|
||||
mono_sigctx_to_monoctx (void *sigctx, MonoContext *mctx)
|
||||
{
|
||||
#ifdef MONO_CROSS_COMPILE
|
||||
g_assert_not_reached ();
|
||||
#else
|
||||
ucontext_t *uctx = sigctx;
|
||||
|
||||
memcpy (&mctx->gregs, &uctx->uc_mcontext.gregs, sizeof (mgreg_t) * G_N_ELEMENTS (mctx->gregs));
|
||||
memcpy (&mctx->fregs, &uctx->uc_mcontext.fpregs, sizeof (double) * G_N_ELEMENTS (mctx->fregs));
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
mono_monoctx_to_sigctx (MonoContext *mctx, void *sigctx)
|
||||
{
|
||||
#ifdef MONO_CROSS_COMPILE
|
||||
g_assert_not_reached ();
|
||||
#else
|
||||
ucontext_t *uctx = sigctx;
|
||||
|
||||
memcpy (&uctx->uc_mcontext.gregs, &mctx->gregs, sizeof (mgreg_t) * G_N_ELEMENTS (mctx->gregs));
|
||||
memcpy (&uctx->uc_mcontext.fpregs, &mctx->fregs, sizeof (double) * G_N_ELEMENTS (mctx->fregs));
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* #if defined(__i386__) */
|
||||
@@ -892,6 +892,119 @@ typedef struct ucontext MonoContext;
|
||||
: "memory" \
|
||||
)
|
||||
|
||||
#elif (defined (HOST_RISCV) && !defined (MONO_CROSS_COMPILE)) || defined (TARGET_RISCV)
|
||||
|
||||
#include <mono/arch/riscv/riscv-codegen.h>
|
||||
|
||||
typedef struct {
|
||||
mgreg_t gregs [RISCV_N_GREGS]; // [0] contains pc since x0 is hard-wired to zero anyway.
|
||||
double fregs [RISCV_N_FREGS * 2 + 2]; // [32] contains fcsr (32 bits), the rest is for quad-precision values (currently unused).
|
||||
} MonoContext;
|
||||
|
||||
#define MONO_CONTEXT_SET_IP(ctx, ip) do { (ctx)->gregs [RISCV_ZERO] = (mgreg_t) (ip); } while (0)
|
||||
#define MONO_CONTEXT_SET_BP(ctx, bp) do { (ctx)->gregs [RISCV_FP] = (mgreg_t) (bp); } while (0)
|
||||
#define MONO_CONTEXT_SET_SP(ctx, sp) do { (ctx)->gregs [RISCV_SP] = (mgreg_t) (sp); } while (0)
|
||||
|
||||
#define MONO_CONTEXT_GET_IP(ctx) ((gpointer) ((ctx)->gregs [RISCV_ZERO]))
|
||||
#define MONO_CONTEXT_GET_BP(ctx) ((gpointer) ((ctx)->gregs [RISCV_FP]))
|
||||
#define MONO_CONTEXT_GET_SP(ctx) ((gpointer) ((ctx)->gregs [RISCV_SP]))
|
||||
|
||||
#ifdef TARGET_RISCV64
|
||||
#define _RISCV_STR "sd"
|
||||
#define _RISCV_SZ "8"
|
||||
#else
|
||||
#define _RISCV_STR "sw"
|
||||
#define _RISCV_SZ "4"
|
||||
#endif
|
||||
|
||||
#define MONO_CONTEXT_GET_CURRENT(ctx) \
|
||||
do { \
|
||||
__asm__ __volatile__ ( \
|
||||
_RISCV_STR " x1, " _RISCV_SZ "*1(%0)\n" \
|
||||
_RISCV_STR " x2, " _RISCV_SZ "*2(%0)\n" \
|
||||
_RISCV_STR " x3, " _RISCV_SZ "*3(%0)\n" \
|
||||
_RISCV_STR " x4, " _RISCV_SZ "*4(%0)\n" \
|
||||
_RISCV_STR " x5, " _RISCV_SZ "*5(%0)\n" \
|
||||
_RISCV_STR " x6, " _RISCV_SZ "*6(%0)\n" \
|
||||
_RISCV_STR " x7, " _RISCV_SZ "*7(%0)\n" \
|
||||
_RISCV_STR " x8, " _RISCV_SZ "*8(%0)\n" \
|
||||
_RISCV_STR " x9, " _RISCV_SZ "*9(%0)\n" \
|
||||
_RISCV_STR " x10, " _RISCV_SZ "*10(%0)\n" \
|
||||
_RISCV_STR " x11, " _RISCV_SZ "*11(%0)\n" \
|
||||
_RISCV_STR " x12, " _RISCV_SZ "*12(%0)\n" \
|
||||
_RISCV_STR " x13, " _RISCV_SZ "*13(%0)\n" \
|
||||
_RISCV_STR " x14, " _RISCV_SZ "*14(%0)\n" \
|
||||
_RISCV_STR " x15, " _RISCV_SZ "*15(%0)\n" \
|
||||
_RISCV_STR " x16, " _RISCV_SZ "*16(%0)\n" \
|
||||
_RISCV_STR " x17, " _RISCV_SZ "*17(%0)\n" \
|
||||
_RISCV_STR " x18, " _RISCV_SZ "*18(%0)\n" \
|
||||
_RISCV_STR " x19, " _RISCV_SZ "*19(%0)\n" \
|
||||
_RISCV_STR " x20, " _RISCV_SZ "*20(%0)\n" \
|
||||
_RISCV_STR " x21, " _RISCV_SZ "*21(%0)\n" \
|
||||
_RISCV_STR " x22, " _RISCV_SZ "*22(%0)\n" \
|
||||
_RISCV_STR " x23, " _RISCV_SZ "*23(%0)\n" \
|
||||
_RISCV_STR " x24, " _RISCV_SZ "*24(%0)\n" \
|
||||
_RISCV_STR " x25, " _RISCV_SZ "*25(%0)\n" \
|
||||
_RISCV_STR " x26, " _RISCV_SZ "*26(%0)\n" \
|
||||
_RISCV_STR " x27, " _RISCV_SZ "*27(%0)\n" \
|
||||
_RISCV_STR " x28, " _RISCV_SZ "*28(%0)\n" \
|
||||
_RISCV_STR " x29, " _RISCV_SZ "*29(%0)\n" \
|
||||
_RISCV_STR " x30, " _RISCV_SZ "*30(%0)\n" \
|
||||
_RISCV_STR " x31, " _RISCV_SZ "*31(%0)\n" \
|
||||
: \
|
||||
: "r" (&(ctx).gregs) \
|
||||
: "memory" \
|
||||
); \
|
||||
__asm__ __volatile__ ( \
|
||||
"frcsr t0\n" \
|
||||
"fsd f0, 8*0(%0)\n" \
|
||||
"fsd f1, 8*1(%0)\n" \
|
||||
"fsd f2, 8*2(%0)\n" \
|
||||
"fsd f3, 8*3(%0)\n" \
|
||||
"fsd f4, 8*4(%0)\n" \
|
||||
"fsd f5, 8*5(%0)\n" \
|
||||
"fsd f6, 8*6(%0)\n" \
|
||||
"fsd f7, 8*7(%0)\n" \
|
||||
"fsd f8, 8*8(%0)\n" \
|
||||
"fsd f9, 8*9(%0)\n" \
|
||||
"fsd f10, 8*10(%0)\n" \
|
||||
"fsd f11, 8*11(%0)\n" \
|
||||
"fsd f12, 8*12(%0)\n" \
|
||||
"fsd f13, 8*13(%0)\n" \
|
||||
"fsd f14, 8*14(%0)\n" \
|
||||
"fsd f15, 8*15(%0)\n" \
|
||||
"fsd f16, 8*16(%0)\n" \
|
||||
"fsd f17, 8*17(%0)\n" \
|
||||
"fsd f18, 8*18(%0)\n" \
|
||||
"fsd f19, 8*19(%0)\n" \
|
||||
"fsd f20, 8*20(%0)\n" \
|
||||
"fsd f21, 8*21(%0)\n" \
|
||||
"fsd f22, 8*22(%0)\n" \
|
||||
"fsd f23, 8*23(%0)\n" \
|
||||
"fsd f24, 8*24(%0)\n" \
|
||||
"fsd f25, 8*25(%0)\n" \
|
||||
"fsd f26, 8*26(%0)\n" \
|
||||
"fsd f27, 8*27(%0)\n" \
|
||||
"fsd f28, 8*28(%0)\n" \
|
||||
"fsd f29, 8*29(%0)\n" \
|
||||
"fsd f30, 8*30(%0)\n" \
|
||||
"fsd f31, 8*31(%0)\n" \
|
||||
"sw t0, 8*32(%0)\n" \
|
||||
: \
|
||||
: "r" (&(ctx).fregs) \
|
||||
: "t0", "memory" \
|
||||
); \
|
||||
__asm__ __volatile__ ( \
|
||||
"auipc t0, 0\n" \
|
||||
_RISCV_STR " t0, (%0)\n" \
|
||||
: \
|
||||
: "r" (&(ctx).gregs [0]) \
|
||||
: "t0", "memory" \
|
||||
); \
|
||||
} while (0)
|
||||
|
||||
#define MONO_ARCH_HAS_MONO_CONTEXT (1)
|
||||
|
||||
#else
|
||||
|
||||
#error "Implement mono-context for the current arch"
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Licensed to the .NET Foundation under one or more agreements.
|
||||
* The .NET Foundation licenses this file to you under the MIT license.
|
||||
* See the LICENSE file in the project root for more information.
|
||||
*/
|
||||
|
||||
#include <mono/utils/mono-hwcap.h>
|
||||
|
||||
#include <sys/auxv.h>
|
||||
|
||||
void
|
||||
mono_hwcap_arch_init (void)
|
||||
{
|
||||
// See arch/riscv/include/uapi/asm/hwcap.h in the kernel source tree.
|
||||
|
||||
unsigned long hwcap;
|
||||
|
||||
if ((hwcap = getauxval (AT_HWCAP))) {
|
||||
// COMPAT_HWCAP_ISA_A
|
||||
if (hwcap & (1 << ('A' - 'A')))
|
||||
mono_hwcap_riscv_has_stdext_a = TRUE;
|
||||
|
||||
// COMPAT_HWCAP_ISA_C
|
||||
if (hwcap & (1 << ('C' - 'A')))
|
||||
mono_hwcap_riscv_has_stdext_c = TRUE;
|
||||
|
||||
// COMPAT_HWCAP_ISA_D
|
||||
if (hwcap & (1 << ('D' - 'A')))
|
||||
mono_hwcap_riscv_has_stdext_d = TRUE;
|
||||
|
||||
// COMPAT_HWCAP_ISA_F
|
||||
if (hwcap & (1 << ('F' - 'A')))
|
||||
mono_hwcap_riscv_has_stdext_f = TRUE;
|
||||
|
||||
// Why does COMPAT_HWCAP_ISA_I even exist...?
|
||||
|
||||
// COMPAT_HWCAP_ISA_M
|
||||
if (hwcap & (1 << ('M' - 'A')))
|
||||
mono_hwcap_riscv_has_stdext_m = TRUE;
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,22 @@ MONO_HWCAP_VAR(ppc_is_isa_64)
|
||||
MONO_HWCAP_VAR(ppc_has_move_fpr_gpr)
|
||||
MONO_HWCAP_VAR(ppc_has_multiple_ls_units)
|
||||
|
||||
#elif defined (TARGET_RISCV)
|
||||
|
||||
MONO_HWCAP_VAR(riscv_has_stdext_a)
|
||||
MONO_HWCAP_VAR(riscv_has_stdext_b)
|
||||
MONO_HWCAP_VAR(riscv_has_stdext_c)
|
||||
MONO_HWCAP_VAR(riscv_has_stdext_d)
|
||||
MONO_HWCAP_VAR(riscv_has_stdext_f)
|
||||
MONO_HWCAP_VAR(riscv_has_stdext_j)
|
||||
MONO_HWCAP_VAR(riscv_has_stdext_l)
|
||||
MONO_HWCAP_VAR(riscv_has_stdext_m)
|
||||
MONO_HWCAP_VAR(riscv_has_stdext_n)
|
||||
MONO_HWCAP_VAR(riscv_has_stdext_p)
|
||||
MONO_HWCAP_VAR(riscv_has_stdext_q)
|
||||
MONO_HWCAP_VAR(riscv_has_stdext_t)
|
||||
MONO_HWCAP_VAR(riscv_has_stdext_v)
|
||||
|
||||
#elif defined (TARGET_S390X)
|
||||
|
||||
MONO_HWCAP_VAR(s390x_has_fpe)
|
||||
|
||||
@@ -533,4 +533,26 @@ typedef struct ucontext
|
||||
# define UCONTEXT_GREGS(ctx) (((ucontext_t *)(ctx))->uc_mcontext.gregs)
|
||||
#endif
|
||||
|
||||
#elif defined (TARGET_RISCV)
|
||||
|
||||
#if defined(MONO_CROSS_COMPILE)
|
||||
|
||||
#define UCONTEXT_GREGS(ctx) (NULL)
|
||||
#define UCONTEXT_FREGS(ctx) (NULL)
|
||||
#define UCONTEXT_REG_PC(ctx) (NULL)
|
||||
#define UCONTEXT_REG_BP(ctx) (NULL)
|
||||
#define UCONTEXT_REG_SP(ctx) (NULL)
|
||||
|
||||
#else
|
||||
|
||||
#include <ucontext.h>
|
||||
|
||||
#define UCONTEXT_GREGS(ctx) (((ucontext_t *) (ctx))->uc_mcontext.gregs)
|
||||
#define UCONTEXT_FREGS(ctx) (((ucontext_t *) (ctx))->uc_mcontext.fpregs)
|
||||
#define UCONTEXT_REG_PC(ctx) (UCONTEXT_GREGS ((ctx)) [REG_PC])
|
||||
#define UCONTEXT_REG_BP(ctx) (UCONTEXT_GREGS ((ctx)) [REG_S0])
|
||||
#define UCONTEXT_REG_SP(ctx) (UCONTEXT_GREGS ((ctx)) [REG_SP])
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -152,6 +152,21 @@
|
||||
: "=r" (foo) : : "1"); \
|
||||
offset = foo; } while (0)
|
||||
# endif
|
||||
|
||||
#elif defined (TARGET_RISCV) && !defined (PIC)
|
||||
|
||||
#define MONO_THREAD_VAR_OFFSET(var, offset) \
|
||||
do { \
|
||||
guint32 temp; \
|
||||
__asm__ ( \
|
||||
"lui %0, %%tprel_hi(" #var ")\n" \
|
||||
"add %0, %0, tp, %%tprel_add(" #var ")\n" \
|
||||
"addi %0, %0, %%tprel_lo(" #var ")\n" \
|
||||
: "=r" (temp) \
|
||||
); \
|
||||
offset = temp; \
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
|
||||
#define MONO_THREAD_VAR_OFFSET(var,offset) (offset) = -1
|
||||
|
||||
Reference in new issue
Block a user