Skip to content

Commit

Permalink
[LoongArch64] coreclr/debug and part of inc directory. (#62886)
Browse files Browse the repository at this point in the history
* [LoongArch64] add coreclr-inc,gc, ToolBox directory. (#59561)

Co-authored-by: Loongson's .NET-teams

* [LoongArch64] move inc/switches.h to #62889.

* [LoongArch64] move some configure files from #62889.

* [LoongArch64] revert the modify when moved from #62889.

* [LoongArch64] moved the inc/stdmacros.h to #62885.

* [LoongArch64] moved inc/corinfo.h to #62885.

* [LoongArch64] modify the related files for compiling error.

* [LoongArch64] revert the `src/coreclr/gcinfo/CMakeLists.txt` to original.

* [LoongArch64] delete unused files on windows.

* [LoongArch64] add define IMAGE_FILE_MACHINE_LOONGARCH64.

* [LoongArch64] workround the compiling error for IMAGE_FILE_MACHINE_LOONGARCH64 on windows.

* [LoongArch64] workround the compiling error for SPMI_TARGET_ARCHITECTURE_LOONGARCH64 on windows.

* [LoongArch64] delete the memcpy for LoongArch64 and revert workround patches.

* [LoongArch64] exclude the gc, ToolBox and config files from this PR.

* [LoongArch64] amend code for compiling error on LoongArch64-machine.

* [LoongArch64] update the version of the `LICENSE description`.

* [LoongArch64] amend the code about debug.

* [LoongArch64] temp submit for fixing the windows compiling error.

* [LoongArch64] amend some LA's implements for CR.

Co-authored-by: qiaopengcheng <[email protected]>
  • Loading branch information
shushanhf and qiaopengcheng authored Apr 25, 2022
1 parent ba8ccea commit fc2f06e
Show file tree
Hide file tree
Showing 35 changed files with 1,107 additions and 95 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/binder/assemblybindercommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ BOOL AssemblyBinderCommon::IsValidArchitecture(PEKIND kArchitecture)
#elif defined(TARGET_ARM64)
peARM64;
#else
PORTABILITY_ASSERT("processArchitecture");
peMSIL;
#endif

return (kArchitecture == processArchitecture);
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/debug/createdump/datatarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ DumpDataTarget::GetMachineType(
*machine = IMAGE_FILE_MACHINE_ARM64;
#elif HOST_X86
*machine = IMAGE_FILE_MACHINE_I386;
#elif HOST_LOONGARCH64
*machine = IMAGE_FILE_MACHINE_LOONGARCH64;
#else
#error Unsupported architecture
#endif
Expand All @@ -79,7 +81,7 @@ HRESULT STDMETHODCALLTYPE
DumpDataTarget::GetPointerSize(
/* [out] */ ULONG32 *size)
{
#if defined(HOST_AMD64) || defined(HOST_ARM64)
#if defined(HOST_AMD64) || defined(HOST_ARM64) || defined(HOST_LOONGARCH64)
*size = 8;
#elif defined(HOST_ARM) || defined(HOST_X86)
*size = 4;
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/debug/createdump/dumpwriterelf.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#define ELF_ARCH EM_AARCH64
#elif defined(__arm__)
#define ELF_ARCH EM_ARM
#elif defined(__loongarch64)
#define ELF_ARCH EM_LOONGARCH
#endif

#define PH_HDR_CANARY 0xFFFF
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/debug/createdump/memoryregion.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if !defined(PAGE_SIZE) && (defined(__arm__) || defined(__aarch64__))
#if !defined(PAGE_SIZE) && (defined(__arm__) || defined(__aarch64__) || defined(__loongarch64))
#define PAGE_SIZE sysconf(_SC_PAGESIZE)
#endif

Expand Down
20 changes: 20 additions & 0 deletions src/coreclr/debug/createdump/threadinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,29 @@ class CrashInfo;
#define MCREG_Cpsr(mc) ((mc).pstate)
#endif

#if defined(__loongarch64)
// See src/coreclr/pal/src/include/pal/context.h
#define MCREG_Ra(mc) ((mc).gpr[1])
#define MCREG_Fp(mc) ((mc).gpr[22])
#define MCREG_Sp(mc) ((mc).gpr[3])
#define MCREG_Pc(mc) ((mc).pc)
#endif

#define FPREG_ErrorOffset(fpregs) *(DWORD*)&((fpregs).rip)
#define FPREG_ErrorSelector(fpregs) *(((WORD*)&((fpregs).rip)) + 2)
#define FPREG_DataOffset(fpregs) *(DWORD*)&((fpregs).rdp)
#define FPREG_DataSelector(fpregs) *(((WORD*)&((fpregs).rdp)) + 2)
#if defined(__arm__)
#define user_regs_struct user_regs
#define user_fpregs_struct user_fpregs
#elif defined(__loongarch64)
// struct user_regs_struct {} defined `/usr/include/loongarch64-linux-gnu/sys/user.h`

struct user_fpregs_struct
{
unsigned long long fpregs[32];
unsigned long fpscr;
} __attribute__((__packed__));
#endif

#if defined(__aarch64__)
Expand Down Expand Up @@ -130,6 +146,10 @@ class ThreadInfo
inline const uint64_t GetInstructionPointer() const { return MCREG_Pc(m_gpRegisters); }
inline const uint64_t GetStackPointer() const { return MCREG_Sp(m_gpRegisters); }
inline const uint64_t GetFramePointer() const { return MCREG_Fp(m_gpRegisters); }
#elif defined(__loongarch64)
inline const uint64_t GetInstructionPointer() const { return MCREG_Pc(m_gpRegisters); }
inline const uint64_t GetStackPointer() const { return MCREG_Sp(m_gpRegisters); }
inline const uint64_t GetFramePointer() const { return MCREG_Fp(m_gpRegisters); }
#elif defined(__arm__)
inline const uint64_t GetInstructionPointer() const { return m_gpRegisters.ARM_pc; }
inline const uint64_t GetStackPointer() const { return m_gpRegisters.ARM_sp; }
Expand Down
22 changes: 22 additions & 0 deletions src/coreclr/debug/createdump/threadinfounix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ ThreadInfo::Initialize()
TRACE("Thread %04x PC %08lx SP %08lx\n", m_tid, (unsigned long)m_gpRegisters.ARM_pc, (unsigned long)m_gpRegisters.ARM_sp);
#elif defined(__x86_64__)
TRACE("Thread %04x RIP %016llx RSP %016llx\n", m_tid, (unsigned long long)m_gpRegisters.rip, (unsigned long long)m_gpRegisters.rsp);
#elif defined(__loongarch64)
TRACE("Thread %04x PC %016llx SP %016llx\n", m_tid, (unsigned long long)m_gpRegisters.pc, (unsigned long long)m_gpRegisters.gpr[3]);
#else
#error "Unsupported architecture"
#endif
Expand Down Expand Up @@ -221,6 +223,26 @@ ThreadInfo::GetThreadContext(uint32_t flags, CONTEXT* context) const
memcpy(context->D, m_vfpRegisters.fpregs, sizeof(context->D));
#endif
}
#elif defined(__loongarch64)
if ((flags & CONTEXT_CONTROL) == CONTEXT_CONTROL)
{
context->Ra = MCREG_Ra(m_gpRegisters);
context->Sp = MCREG_Sp(m_gpRegisters);
context->Fp = MCREG_Fp(m_gpRegisters);
context->Pc = MCREG_Pc(m_gpRegisters);
}
if ((flags & CONTEXT_INTEGER) == CONTEXT_INTEGER)
{
context->Tp = m_gpRegisters.gpr[2];
memcpy(&context->A0, &m_gpRegisters.gpr[4], sizeof(context->A0)*(21 - 4 + 1));
memcpy(&context->S0, &m_gpRegisters.gpr[23], sizeof(context->S0)*9);
}
if ((flags & CONTEXT_FLOATING_POINT) == CONTEXT_FLOATING_POINT)
{
assert(sizeof(context->F) == sizeof(m_fpRegisters.fpregs));
memcpy(context->F, m_fpRegisters.fpregs, sizeof(context->F));
context->Fcsr = m_fpRegisters.fpscr;
}
#else
#error Platform not supported
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/debug/daccess/daccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5514,6 +5514,8 @@ ClrDataAccess::Initialize(void)
CorDebugPlatform hostPlatform = CORDB_PLATFORM_POSIX_ARM;
#elif defined(TARGET_ARM64)
CorDebugPlatform hostPlatform = CORDB_PLATFORM_POSIX_ARM64;
#elif defined(TARGET_LOONGARCH64)
CorDebugPlatform hostPlatform = CORDB_PLATFORM_POSIX_LOONGARCH64;
#else
#error Unknown Processor.
#endif
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/debug/daccess/loongarch64/primitives.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#include "stdafx.h"

#include "../../shared/loongarch64/primitives.cpp"
12 changes: 12 additions & 0 deletions src/coreclr/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,18 @@ ClrDataAccess::GetRegisterName(int regNum, unsigned int count, _Inout_updates_z_
{
W("eax"), W("ecx"), W("edx"), W("ebx"), W("esp"), W("ebp"), W("esi"), W("edi"),
};
#elif defined(TARGET_LOONGARCH64)
static const WCHAR *regs[] =
{
W("R0"), W("AT"), W("V0"), W("V1"),
W("A0"), W("A1"), W("A2"), W("A3"),
W("A4"), W("A5"), W("A6"), W("A7"),
W("T0"), W("T1"), W("T2"), W("T3"),
W("T8"), W("T9"), W("S0"), W("S1"),
W("S2"), W("S3"), W("S4"), W("S5"),
W("S6"), W("S7"), W("K0"), W("K1"),
W("GP"), W("SP"), W("FP"), W("RA")
};
#endif

// Caller frame registers are encoded as "-(reg+1)".
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/debug/dbgutil/elfreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,8 @@ Elf64_Ehdr::Elf64_Ehdr()
e_machine = EM_X86_64;
#elif defined(TARGET_ARM64)
e_machine = EM_AARCH64;
#elif defined(TARGET_LOONGARCH64)
e_machine = EM_LOONGARCH;
#endif
e_flags = 0;
e_version = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/debug/di/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ if(CLR_CMAKE_HOST_WIN32)
endif()
elseif(CLR_CMAKE_HOST_UNIX)

if(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64 OR CLR_CMAKE_TARGET_ARCH_ARM)
if(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64 OR CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_LOONGARCH64)
set(CORDBDI_SOURCES_ASM_FILE
${ARCH_SOURCES_DIR}/floatconversion.S
)
Expand Down
Loading

0 comments on commit fc2f06e

Please sign in to comment.