Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LoongArch64-mono] Part-5:Add loongarch support in some files for LoongArch64 #103398

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add

runtime/src/mono/mono.proj

Lines 457 to 461 in 4f9cd4d

<!-- riscv64 Linux cross build options -->
<ItemGroup Condition="'$(MonoCrossDir)' != '' and '$(TargetArchitecture)' == 'riscv64'">
<_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" />
<_MonoBuildEnv Include="TARGET_BUILD_ARCH=riscv64" />
</ItemGroup>
to enable LA64 mono cross-build.

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()
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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\"")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<PropertyGroup Condition="'$(Platform)' == 'arm64'">
<DefineConstants>$(DefineConstants);TARGET_ARM64</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)' == 'loongarch64'">
<DefineConstants>$(DefineConstants);TARGET_LOONGARCH64</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)' == 'riscv64'">
<DefineConstants>$(DefineConstants);TARGET_RISCV64</DefineConstants>
</PropertyGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/mono/cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,9 @@
/* ... */
#cmakedefine TARGET_ARM64 1

/* ... */
#cmakedefine TARGET_LOONGARCH64 1

/* ... */
#cmakedefine TARGET_POWERPC 1

Expand Down Expand Up @@ -618,6 +621,9 @@
/* ... */
#cmakedefine HOST_ARM64 1

/* ... */
#cmakedefine HOST_LOONGARCH64 1

/* ... */
#cmakedefine HOST_POWERPC 1

Expand Down
6 changes: 6 additions & 0 deletions src/mono/mono.proj
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,12 @@ JS_ENGINES = [NODE_JS]
<_MonoBuildEnv Include="TARGET_BUILD_ARCH=x86" />
</ItemGroup>

<!-- loongarch64 Linux cross build options -->
<ItemGroup Condition="'$(MonoCrossDir)' != '' and '$(TargetArchitecture)' == 'loongarch64'">
<_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" />
<_MonoBuildEnv Include="TARGET_BUILD_ARCH=loongarch64" />
</ItemGroup>

<!-- riscv64 Linux cross build options -->
<ItemGroup Condition="'$(MonoCrossDir)' != '' and '$(TargetArchitecture)' == 'riscv64'">
<_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" />
Expand Down
3 changes: 3 additions & 0 deletions src/mono/mono/metadata/mono-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 9 additions & 2 deletions src/mono/mono/metadata/object-offsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions src/mono/mono/mini/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/mono/mono/mini/mini-arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/mini-codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions src/mono/mono/mini/mini-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/mono/mono/sgen/sgen-archdep.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@

#define REDZONE_SIZE (0)

#elif defined (TARGET_LOONGARCH64)

#define REDZONE_SIZE (0)

#elif defined (TARGET_WASM)

#define REDZONE_SIZE 0
Expand Down
2 changes: 2 additions & 0 deletions src/mono/mono/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions src/mono/mono/utils/mono-hwcap-loongarch64.c
Original file line number Diff line number Diff line change
@@ -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)
{
}
12 changes: 12 additions & 0 deletions src/tests/issues.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2847,6 +2847,18 @@
</ExcludeList>
</ItemGroup>

<ItemGroup Condition=" '$(RuntimeFlavor)' == 'mono' and '$(TargetArchitecture)' == 'loongarch64' and '$(TargetsWindows)' != 'true' " >
<ExcludeList Include = "$(XunitTestBinBase)/JIT/Regression/VS-ia64-JIT/M00/b108366/b108366/**">
<Issue>needs triage</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/JIT/Methodical/tailcall/test_mutual_rec_d/**">
<Issue>needs triage</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/JIT/Methodical/tailcall/test_mutual_rec_r/**">
<Issue>needs triage</Issue>
</ExcludeList>
</ItemGroup>

<ItemGroup Condition="'$(TargetArchitecture)' == 'wasm' or '$(TargetsAppleMobile)' == 'true'">
<ExcludeList Include="$(XunitTestBinBase)/baseservices/finalization/CriticalFinalizer/**">
<Issue>https://github.com/dotnet/runtime/issues/75756</Issue>
Expand Down
2 changes: 2 additions & 0 deletions src/tests/tracing/eventpipe/processinfo/processinfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ public static void TestEntryPoint()
Architecture.X64 => "x64",
Architecture.Arm => "arm32",
Architecture.Arm64 => "arm64",
Architecture.LoongArch64 => "loongarch64",
lawn123 marked this conversation as resolved.
Show resolved Hide resolved
Architecture.RiscV64 => "riscv64",
_ => "Unknown"
};

Expand Down
2 changes: 2 additions & 0 deletions src/tests/tracing/eventpipe/processinfo2/processinfo2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ public static void TestEntryPoint()
Architecture.X64 => "x64",
Architecture.Arm => "arm32",
Architecture.Arm64 => "arm64",
Architecture.LoongArch64 => "loongarch64",
lawn123 marked this conversation as resolved.
Show resolved Hide resolved
Architecture.RiscV64 => "riscv64",
_ => "Unknown"
};

Expand Down
2 changes: 2 additions & 0 deletions src/tests/tracing/eventpipe/processinfo3/processinfo3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ public static void TestEntryPoint()
Architecture.X64 => "x64",
Architecture.Arm => "arm32",
Architecture.Arm64 => "arm64",
Architecture.LoongArch64 => "loongarch64",
lawn123 marked this conversation as resolved.
Show resolved Hide resolved
Architecture.RiscV64 => "riscv64",
_ => "Unknown"
};

Expand Down
Loading