diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt
index ba41fa4d9a489..9e053a5179e02 100644
--- a/src/mono/CMakeLists.txt
+++ b/src/mono/CMakeLists.txt
@@ -392,6 +392,8 @@ elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" OR CMAKE_SYSTEM_PROCESSOR STREQUAL
set(CMAKE_SYSTEM_PROCESSOR "x86")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64")
set(CMAKE_SYSTEM_PROCESSOR "arm64")
+elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "loongarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "LOONGARCH64")
+ set(CMAKE_SYSTEM_PROCESSOR "loongarch64")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "x64")
set(CMAKE_SYSTEM_PROCESSOR "x86_64")
endif()
@@ -404,6 +406,8 @@ elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
set(HOST_X86 1)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set(HOST_ARM64 1)
+elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "loongarch64")
+ set(HOST_LOONGARCH64 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
set(HOST_ARM 1)
# fixme: use separate defines for host/target
@@ -437,6 +441,8 @@ elseif(TARGET_ARCH STREQUAL "i686" OR TARGET_ARCH STREQUAL "i386" OR TARGET_ARCH
set(TARGET_ARCH "x86")
elseif(TARGET_ARCH STREQUAL "aarch64" OR TARGET_ARCH STREQUAL "ARM64")
set(TARGET_ARCH "arm64")
+elseif(TARGET_ARCH STREQUAL "loongarch64" OR TARGET_ARCH STREQUAL "LOONGARCH64")
+ set(TARGET_ARCH "loongarch64")
elseif(TARGET_ARCH STREQUAL "AMD64" OR TARGET_ARCH STREQUAL "x64")
set(TARGET_ARCH "x86_64")
endif()
@@ -463,6 +469,11 @@ elseif(TARGET_ARCH STREQUAL "arm64")
set(TARGET_SIZEOF_VOID_P 4)
set(MONO_ARCH_ILP32 1)
endif()
+elseif(TARGET_ARCH STREQUAL "loongarch64")
+ set(TARGET_LOONGARCH64 1)
+ set(MONO_ARCHITECTURE "\"loongarch64\"")
+ set(TARGET_SIZEOF_VOID_P 8)
+ set(SIZEOF_REGISTER 8)
elseif(TARGET_ARCH MATCHES "arm")
set(TARGET_ARM 1)
set(MONO_ARCHITECTURE "\"arm\"")
diff --git a/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj
index 9137c694aa4ab..28b8f7edbe8cc 100644
--- a/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj
+++ b/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj
@@ -62,6 +62,9 @@
$(DefineConstants);TARGET_ARM64
+
+ $(DefineConstants);TARGET_LOONGARCH64
+
$(DefineConstants);TARGET_RISCV64
diff --git a/src/mono/cmake/config.h.in b/src/mono/cmake/config.h.in
index 1fd699e761070..8212672406bea 100644
--- a/src/mono/cmake/config.h.in
+++ b/src/mono/cmake/config.h.in
@@ -588,6 +588,9 @@
/* ... */
#cmakedefine TARGET_ARM64 1
+/* ... */
+#cmakedefine TARGET_LOONGARCH64 1
+
/* ... */
#cmakedefine TARGET_POWERPC 1
@@ -618,6 +621,9 @@
/* ... */
#cmakedefine HOST_ARM64 1
+/* ... */
+#cmakedefine HOST_LOONGARCH64 1
+
/* ... */
#cmakedefine HOST_POWERPC 1
diff --git a/src/mono/mono.proj b/src/mono/mono.proj
index 14056eb3a7e24..2e840b83e89fe 100644
--- a/src/mono/mono.proj
+++ b/src/mono/mono.proj
@@ -454,6 +454,12 @@ JS_ENGINES = [NODE_JS]
<_MonoBuildEnv Include="TARGET_BUILD_ARCH=x86" />
+
+
+ <_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" />
+ <_MonoBuildEnv Include="TARGET_BUILD_ARCH=loongarch64" />
+
+
<_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" />
diff --git a/src/mono/mono/metadata/mono-config.c b/src/mono/mono/metadata/mono-config.c
index b2e4ca7dc2956..318382e56c2f0 100644
--- a/src/mono/mono/metadata/mono-config.c
+++ b/src/mono/mono/metadata/mono-config.c
@@ -79,6 +79,9 @@
#elif defined(__aarch64__) || defined(TARGET_ARM64)
#define CONFIG_CPU "armv8"
#define CONFIG_WORDSIZE "64"
+#elif defined(__loongarch64) || defined(TARGET_LOONGARCH64)
+#define CONFIG_CPU "loongarch64"
+#define CONFIG_WORDSIZE "64"
#elif defined (TARGET_RISCV32)
#define CONFIG_CPU "riscv32"
#define CONFIG_WORDSIZE "32"
diff --git a/src/mono/mono/metadata/object-offsets.h b/src/mono/mono/metadata/object-offsets.h
index 017ff752d7d2c..75715ac99ee4a 100644
--- a/src/mono/mono/metadata/object-offsets.h
+++ b/src/mono/mono/metadata/object-offsets.h
@@ -258,6 +258,13 @@ DECL_OFFSET(MonoLMF, pc)
DECL_OFFSET(MonoLMF, gregs)
DECL_OFFSET(MonoContext, gregs)
DECL_OFFSET(MonoContext, fregs)
+#elif defined(TARGET_LOONGARCH64)
+DECL_OFFSET(MonoLMF, pc)
+DECL_OFFSET(MonoLMF, gregs)
+DECL_OFFSET(MonoLMF, lmf_addr)
+DECL_OFFSET(MonoContext, pc)
+DECL_OFFSET(MonoContext, regs)
+DECL_OFFSET(MonoContext, fregs)
#endif
// Shared architecture offfsets
@@ -294,11 +301,11 @@ DECL_OFFSET(GSharedVtCallInfo, ret_marshal)
DECL_OFFSET(GSharedVtCallInfo, vret_slot)
#endif
-#if defined(TARGET_AMD64) || defined(TARGET_ARM64)
+#if defined(TARGET_AMD64) || defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64)
DECL_OFFSET(SeqPointInfo, ss_tramp_addr)
#endif
-#if defined(TARGET_AMD64) || defined(TARGET_ARM) || defined(TARGET_ARM64)
+#if defined(TARGET_AMD64) || defined(TARGET_ARM) || defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64)
DECL_OFFSET(SeqPointInfo, bp_addrs)
DECL_OFFSET(CallContext, gregs)
diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt
index b9bd9d426bc68..8a3f158a92bd7 100644
--- a/src/mono/mono/mini/CMakeLists.txt
+++ b/src/mono/mono/mini/CMakeLists.txt
@@ -167,6 +167,16 @@ set(arm64_sources
tramp-arm64-gsharedvt.c
cpu-arm64.h)
+set(loongarch64_sources
+ mini-loongarch64.c
+ mini-loongarch64.h
+ exceptions-loongarch64.c
+ tramp-loongarch64.c
+ mini-loongarch64-gsharedvt.c
+ mini-loongarch64-gsharedvt.h
+ tramp-loongarch64-gsharedvt.c
+ cpu-loongarch64.h)
+
set(arm_sources
mini-arm.c
mini-arm.h
@@ -209,6 +219,8 @@ elseif(TARGET_X86)
set(arch_sources ${x86_sources})
elseif(TARGET_ARM64)
set(arch_sources ${arm64_sources})
+elseif(TARGET_LOONGARCH64)
+set(arch_sources ${loongarch64_sources})
elseif(TARGET_ARM)
set(arch_sources ${arm_sources})
elseif(TARGET_RISCV64)
@@ -493,6 +505,13 @@ add_custom_command(
VERBATIM
)
+add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cpu-loongarch64.h
+ COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/genmdesc.py TARGET_LOONGARCH64 ${CMAKE_CURRENT_SOURCE_DIR} cpu-loongarch64.h loongarch64_desc ${CMAKE_CURRENT_SOURCE_DIR}/cpu-loongarch64.mdesc
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/genmdesc.py mini-ops.h ${CMAKE_CURRENT_SOURCE_DIR}/cpu-loongarch64.mdesc
+ VERBATIM
+)
+
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cpu-arm.h
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/genmdesc.py TARGET_ARM ${CMAKE_CURRENT_SOURCE_DIR} cpu-arm.h arm_cpu_desc ${CMAKE_CURRENT_SOURCE_DIR}/cpu-arm.mdesc
diff --git a/src/mono/mono/mini/mini-arch.h b/src/mono/mono/mini/mini-arch.h
index 5556f325c584e..e5740f64581a1 100644
--- a/src/mono/mono/mini/mini-arch.h
+++ b/src/mono/mono/mini/mini-arch.h
@@ -21,6 +21,8 @@
#include "mini-arm.h"
#elif defined(TARGET_ARM64)
#include "mini-arm64.h"
+#elif defined (TARGET_LOONGARCH64)
+#include "mini-loongarch64.h"
#elif defined (TARGET_RISCV)
#include "mini-riscv.h"
#elif TARGET_WASM
diff --git a/src/mono/mono/mini/mini-codegen.c b/src/mono/mono/mini/mini-codegen.c
index 210c1619f629b..680e33f30c6bc 100644
--- a/src/mono/mono/mini/mini-codegen.c
+++ b/src/mono/mono/mini/mini-codegen.c
@@ -1150,7 +1150,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) || defined (TARGET_RISCV)
+#if defined(TARGET_AMD64) || defined(TARGET_X86) || defined(TARGET_ARM) || defined(TARGET_ARM64) || defined (TARGET_RISCV) || defined (TARGET_LOONGARCH64)
/* Check that the table size is correct */
g_assert (MONO_ARCH_CPU_SPEC_IDX(MONO_ARCH_CPU_SPEC)[OP_LAST - OP_LOAD] == 0xffff);
for (i = OP_LOAD; i < OP_LAST; ++i) {
diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c
index e99e464fb8c85..44f87a0d0bb08 100644
--- a/src/mono/mono/mini/mini-runtime.c
+++ b/src/mono/mono/mini/mini-runtime.c
@@ -2041,6 +2041,8 @@ enum {
ELF_MACHINE = EM_ARM,
#elif HOST_ARM64
ELF_MACHINE = EM_AARCH64,
+#elif HOST_LOONGARCH64
+ ELF_MACHINE = EM_LOONGARCH,
#elif HOST_POWERPC64
ELF_MACHINE = EM_PPC64,
#elif HOST_S390X
diff --git a/src/mono/mono/sgen/sgen-archdep.h b/src/mono/mono/sgen/sgen-archdep.h
index 2cd86a122468f..a6c0132dffee6 100644
--- a/src/mono/mono/sgen/sgen-archdep.h
+++ b/src/mono/mono/sgen/sgen-archdep.h
@@ -59,6 +59,10 @@
#define REDZONE_SIZE (0)
+#elif defined (TARGET_LOONGARCH64)
+
+#define REDZONE_SIZE (0)
+
#elif defined (TARGET_WASM)
#define REDZONE_SIZE 0
diff --git a/src/mono/mono/utils/CMakeLists.txt b/src/mono/mono/utils/CMakeLists.txt
index e5bd089b8203c..bf30d0239b285 100644
--- a/src/mono/mono/utils/CMakeLists.txt
+++ b/src/mono/mono/utils/CMakeLists.txt
@@ -199,6 +199,8 @@ elseif(TARGET_AMD64 OR TARGET_X86)
set(utils_arch_sources "${utils_arch_sources};mono-hwcap-x86.c")
elseif(TARGET_ARM64)
set(utils_arch_sources "${utils_arch_sources};mono-hwcap-arm64.c")
+elseif(TARGET_LOONGARCH64)
+set(utils_arch_sources "${utils_arch_sources};mono-hwcap-loongarch64.c")
elseif(TARGET_ARM)
set(utils_arch_sources "${utils_arch_sources};mono-hwcap-arm.c")
elseif(TARGET_RISCV64)
diff --git a/src/mono/mono/utils/mono-hwcap-loongarch64.c b/src/mono/mono/utils/mono-hwcap-loongarch64.c
new file mode 100644
index 0000000000000..35cc77cf667ac
--- /dev/null
+++ b/src/mono/mono/utils/mono-hwcap-loongarch64.c
@@ -0,0 +1,16 @@
+/**
+ * \file
+ *
+ * Authors:
+ * Qiao Pengcheng (qiaopengcheng@loongson.cn), Liu An(liuan@loongson.cn)
+ *
+ * Copyright (c) 2021 Loongson Technology, Inc
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
+ */
+
+#include "mono/utils/mono-hwcap.h"
+
+void
+mono_hwcap_arch_init (void)
+{
+}
diff --git a/src/tests/issues.targets b/src/tests/issues.targets
index 5da277d04e87b..381d92ea811b3 100644
--- a/src/tests/issues.targets
+++ b/src/tests/issues.targets
@@ -2847,6 +2847,18 @@
+
+
+ needs triage
+
+
+ needs triage
+
+
+ needs triage
+
+
+
https://github.com/dotnet/runtime/issues/75756
diff --git a/src/tests/tracing/eventpipe/processinfo/processinfo.cs b/src/tests/tracing/eventpipe/processinfo/processinfo.cs
index 1a4b2f0dd4c7d..0e1e3fe0d46b9 100644
--- a/src/tests/tracing/eventpipe/processinfo/processinfo.cs
+++ b/src/tests/tracing/eventpipe/processinfo/processinfo.cs
@@ -224,6 +224,8 @@ public static void TestEntryPoint()
Architecture.X64 => "x64",
Architecture.Arm => "arm32",
Architecture.Arm64 => "arm64",
+ Architecture.LoongArch64 => "loongarch64",
+ Architecture.RiscV64 => "riscv64",
_ => "Unknown"
};
diff --git a/src/tests/tracing/eventpipe/processinfo2/processinfo2.cs b/src/tests/tracing/eventpipe/processinfo2/processinfo2.cs
index b93099bce3c73..fb25dc1c66adc 100644
--- a/src/tests/tracing/eventpipe/processinfo2/processinfo2.cs
+++ b/src/tests/tracing/eventpipe/processinfo2/processinfo2.cs
@@ -225,6 +225,8 @@ public static void TestEntryPoint()
Architecture.X64 => "x64",
Architecture.Arm => "arm32",
Architecture.Arm64 => "arm64",
+ Architecture.LoongArch64 => "loongarch64",
+ Architecture.RiscV64 => "riscv64",
_ => "Unknown"
};
diff --git a/src/tests/tracing/eventpipe/processinfo3/processinfo3.cs b/src/tests/tracing/eventpipe/processinfo3/processinfo3.cs
index fcdc474470fe9..095ceabfbfc70 100644
--- a/src/tests/tracing/eventpipe/processinfo3/processinfo3.cs
+++ b/src/tests/tracing/eventpipe/processinfo3/processinfo3.cs
@@ -233,6 +233,8 @@ public static void TestEntryPoint()
Architecture.X64 => "x64",
Architecture.Arm => "arm32",
Architecture.Arm64 => "arm64",
+ Architecture.LoongArch64 => "loongarch64",
+ Architecture.RiscV64 => "riscv64",
_ => "Unknown"
};