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] coreclr/debug and part of inc directory. #62886

Merged
merged 32 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
47d106f
Merge pull request #1 from dotnet/main
shushanhf Apr 27, 2021
411b59e
Merge branch 'dotnet:main' into master
shushanhf Oct 25, 2021
7eed4eb
Merge branch 'dotnet:main' into master
shushanhf Dec 6, 2021
0d7c9e4
Merge branch 'dotnet:main' into master
shushanhf Dec 10, 2021
2c534c5
Merge branch 'dotnet:main' into master
shushanhf Dec 14, 2021
6e14d76
Merge branch 'dotnet:main' into master
shushanhf Dec 15, 2021
359875d
Merge branch 'dotnet:main' into master
shushanhf Dec 15, 2021
192b095
Merge branch 'dotnet:main' into main
shushanhf Dec 16, 2021
46ebed3
[LoongArch64] add coreclr-inc,gc, ToolBox directory. (#59561)
shushanhf Dec 15, 2021
e6bada0
[LoongArch64] move inc/switches.h to #62889.
Dec 18, 2021
50bc181
[LoongArch64] move some configure files from #62889.
Dec 18, 2021
49104b3
[LoongArch64] revert the modify when moved from #62889.
Dec 18, 2021
d3e0468
[LoongArch64] moved the inc/stdmacros.h to #62885.
Dec 20, 2021
e1d82f9
[LoongArch64] moved inc/corinfo.h to #62885.
Dec 20, 2021
9c211b9
[LoongArch64] modify the related files for compiling error.
shushanhf Dec 21, 2021
7fc185f
[LoongArch64] revert the `src/coreclr/gcinfo/CMakeLists.txt` to origi…
shushanhf Dec 21, 2021
b859a4f
[LoongArch64] delete unused files on windows.
shushanhf Dec 21, 2021
3e89670
[LoongArch64] add define IMAGE_FILE_MACHINE_LOONGARCH64.
shushanhf Dec 21, 2021
f0618ea
[LoongArch64] workround the compiling error for IMAGE_FILE_MACHINE_LO…
shushanhf Dec 21, 2021
054033f
[LoongArch64] workround the compiling error for SPMI_TARGET_ARCHITECT…
Dec 21, 2021
b7cb02b
[LoongArch64] delete the memcpy for LoongArch64 and revert workround …
Dec 22, 2021
72919c1
[LoongArch64] exclude the gc, ToolBox and config files from this PR.
Dec 22, 2021
c806a8f
[LoongArch64] amend code for compiling error on LoongArch64-machine.
shushanhf Jan 14, 2022
f829e9a
[LoongArch64] update the version of the `LICENSE description`.
Jan 19, 2022
81b9deb
Merge branch 'main' into main_loongarch64_3
shushanhf Feb 23, 2022
650ab6a
Merge branch 'main' into main_loongarch64_3
shushanhf Feb 24, 2022
2136701
[LoongArch64] amend the code about debug.
shushanhf Feb 24, 2022
e058faa
[LoongArch64] temp submit for fixing the windows compiling error.
shushanhf Feb 24, 2022
27e1419
Merge branch 'main' into main_loongarch64_3
shushanhf Feb 25, 2022
7c0fe05
Merge branch 'main' into main_loongarch64_3
shushanhf Apr 12, 2022
c2694ff
Merge branch 'main' into main_loongarch64_3
shushanhf Apr 22, 2022
c8fb52a
[LoongArch64] amend some LA's implements for CR.
shushanhf Apr 24, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,11 @@ void CompileResult::applyRelocs(unsigned char* block1, ULONG blocksize1, void* o
}
}

if (targetArch == SPMI_TARGET_ARCHITECTURE_LOONGARCH64)
{
assert(!"FIXME: Not Implements on loongarch64");
}

if (IsSpmiTarget64Bit())
{
if (relocType == IMAGE_REL_BASED_DIR64)
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/ToolBox/superpmi/superpmi-shared/spmiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ static SPMI_TARGET_ARCHITECTURE SpmiTargetArchitecture = SPMI_TARGET_ARCHITECTUR
static SPMI_TARGET_ARCHITECTURE SpmiTargetArchitecture = SPMI_TARGET_ARCHITECTURE_ARM;
#elif defined(TARGET_ARM64)
static SPMI_TARGET_ARCHITECTURE SpmiTargetArchitecture = SPMI_TARGET_ARCHITECTURE_ARM64;
#elif defined(TARGET_LOONGARCH64)
static SPMI_TARGET_ARCHITECTURE SpmiTargetArchitecture = SPMI_TARGET_ARCHITECTURE_LOONGARCH64;
#else
#error Unsupported architecture
#endif
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/ToolBox/superpmi/superpmi-shared/spmiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ enum SPMI_TARGET_ARCHITECTURE
SPMI_TARGET_ARCHITECTURE_X86,
SPMI_TARGET_ARCHITECTURE_AMD64,
SPMI_TARGET_ARCHITECTURE_ARM64,
SPMI_TARGET_ARCHITECTURE_ARM
SPMI_TARGET_ARCHITECTURE_ARM,
SPMI_TARGET_ARCHITECTURE_LOONGARCH64
};

SPMI_TARGET_ARCHITECTURE GetSpmiTargetArchitecture();
void SetSpmiTargetArchitecture(SPMI_TARGET_ARCHITECTURE spmiTargetArchitecture);

inline bool IsSpmiTarget64Bit()
{
return (GetSpmiTargetArchitecture() == SPMI_TARGET_ARCHITECTURE_AMD64) || (GetSpmiTargetArchitecture() == SPMI_TARGET_ARCHITECTURE_ARM64);
return (GetSpmiTargetArchitecture() == SPMI_TARGET_ARCHITECTURE_AMD64) || (GetSpmiTargetArchitecture() == SPMI_TARGET_ARCHITECTURE_ARM64) || (GetSpmiTargetArchitecture() == SPMI_TARGET_ARCHITECTURE_LOONGARCH64);
}

inline size_t SpmiTargetPointerSize()
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/ToolBox/superpmi/superpmi/jitinstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@ JitInstance::Result JitInstance::CompileMethod(MethodContext* MethodToCompile, i
matchesTargetArch = (targetArch == SPMI_TARGET_ARCHITECTURE_ARM64);
break;

case IMAGE_FILE_MACHINE_LOONGARCH64:
matchesTargetArch = (targetArch == SPMI_TARGET_ARCHITECTURE_LOONGARCH64);
break;

default:
LogError("Unknown target architecture");
break;
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/ToolBox/superpmi/superpmi/superpmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ void SetSuperPmiTargetArchitecture(const char* targetArchitecture)
{
SetSpmiTargetArchitecture(SPMI_TARGET_ARCHITECTURE_ARM64);
}
else if (0 == _stricmp(targetArchitecture, "loongarch64"))
{
SetSpmiTargetArchitecture(SPMI_TARGET_ARCHITECTURE_LOONGARCH64);
}
else
{
LogError("Illegal target architecture '%s'", targetArchitecture);
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/binder/assemblybindercommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ namespace BINDER_SPACE
*PeKind = peARM64;
else if (dwImageType == IMAGE_FILE_MACHINE_AMD64)
*PeKind = peAMD64;
else if (dwImageType == IMAGE_FILE_MACHINE_LOONGARCH64)
*PeKind = peLOONGARCH64;
else
{
// We don't support other architectures
Expand Down Expand Up @@ -1447,6 +1449,8 @@ BOOL AssemblyBinderCommon::IsValidArchitecture(PEKIND kArchitecture)
peARM;
#elif defined(TARGET_ARM64)
peARM64;
#elif defined(TARGET_LOONGARCH64)
peLOONGARCH64;
#else
PORTABILITY_ASSERT("processArchitecture");
#endif
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/binder/inc/bindertypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ typedef enum __PEKIND
peAMD64 = 0x00000004,
peARM = 0x00000005,
peARM64 = 0x00000006,
peLOONGARCH64 = 0x00000007,
peInvalid = 0xffffffff,
} PEKIND;

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 @@ -65,6 +65,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 @@ -75,7 +77,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
24 changes: 24 additions & 0 deletions src/coreclr/debug/createdump/threadinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,33 @@ class CrashInfo;
#define MCREG_Cpsr(mc) ((mc).pstate)
#endif

#if defined(__loongarch64)
// See src/pal/src/include/pal/context.h
#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)
//usr/include/loongarch64-linux-gnu/sys/user.h
//struct user_regs_struct
//{
// unsigned long long gpr[32];
// unsigned long long pc;
//} __attribute__((__packed__));

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

#if defined(__aarch64__)
Expand Down Expand Up @@ -130,6 +150,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
5 changes: 5 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,9 @@ ThreadInfo::GetThreadContext(uint32_t flags, CONTEXT* context) const
memcpy(context->D, m_vfpRegisters.fpregs, sizeof(context->D));
#endif
}
#elif defined(__loongarch64)
assert(!"Unimplemented yet on Loongarch64!");
#pragma message("Unimplemented yet on Loongarch64.")
#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 @@ -5517,6 +5517,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
11 changes: 11 additions & 0 deletions src/coreclr/debug/daccess/loongarch64/primitives.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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.

// Copyright (c) Loongson Technology. All rights reserved.

//

#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, __out_z __inout_e
{
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 @@ -555,6 +555,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
152 changes: 152 additions & 0 deletions src/coreclr/debug/di/loongarch64/cordbregisterset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// 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.

// Copyright (c) Loongson Technology. All rights reserved.

//*****************************************************************************
// File: CordbRegisterSet.cpp
//

//
//*****************************************************************************
#include "primitives.h"


HRESULT CordbRegisterSet::GetRegistersAvailable(ULONG64* pAvailable)
{
assert(!"unimplemented on LOONGARCH yet");
FAIL_IF_NEUTERED(this);
VALIDATE_POINTER_TO_OBJECT(pAvailable, ULONG64 *);

*pAvailable = SETBITULONG64(REGISTER_LOONGARCH64_PC)
| SETBITULONG64(REGISTER_LOONGARCH64_SP)
#if 0
| SETBITULONG64(REGISTER_LOONGARCH64_X0)
| SETBITULONG64(REGISTER_LOONGARCH64_X1)
| SETBITULONG64(REGISTER_LOONGARCH64_X2)
| SETBITULONG64(REGISTER_LOONGARCH64_X3)
| SETBITULONG64(REGISTER_LOONGARCH64_X4)
| SETBITULONG64(REGISTER_LOONGARCH64_X5)
| SETBITULONG64(REGISTER_LOONGARCH64_X6)
| SETBITULONG64(REGISTER_LOONGARCH64_X7)
| SETBITULONG64(REGISTER_LOONGARCH64_X8)
| SETBITULONG64(REGISTER_LOONGARCH64_X9)
| SETBITULONG64(REGISTER_LOONGARCH64_X10)
| SETBITULONG64(REGISTER_LOONGARCH64_X11)
| SETBITULONG64(REGISTER_LOONGARCH64_X12)
| SETBITULONG64(REGISTER_LOONGARCH64_X13)
| SETBITULONG64(REGISTER_LOONGARCH64_X14)
| SETBITULONG64(REGISTER_LOONGARCH64_X15)
| SETBITULONG64(REGISTER_LOONGARCH64_X16)
| SETBITULONG64(REGISTER_LOONGARCH64_X17)
| SETBITULONG64(REGISTER_LOONGARCH64_X18)
| SETBITULONG64(REGISTER_LOONGARCH64_X19)
| SETBITULONG64(REGISTER_LOONGARCH64_X20)
| SETBITULONG64(REGISTER_LOONGARCH64_X21)
| SETBITULONG64(REGISTER_LOONGARCH64_X22)
| SETBITULONG64(REGISTER_LOONGARCH64_X23)
| SETBITULONG64(REGISTER_LOONGARCH64_X24)
| SETBITULONG64(REGISTER_LOONGARCH64_X25)
| SETBITULONG64(REGISTER_LOONGARCH64_X26)
| SETBITULONG64(REGISTER_LOONGARCH64_X27)
| SETBITULONG64(REGISTER_LOONGARCH64_X28)
#endif
| SETBITULONG64(REGISTER_LOONGARCH64_FP)
| SETBITULONG64(REGISTER_LOONGARCH64_RA);

return S_OK;
}

HRESULT CordbRegisterSet::GetRegisters(ULONG64 mask, ULONG32 regCount,
CORDB_REGISTER regBuffer[])
{
assert(!"unimplemented on LOONGARCH yet");
PUBLIC_REENTRANT_API_ENTRY(this);
FAIL_IF_NEUTERED(this);
ATT_REQUIRE_STOPPED_MAY_FAIL(GetProcess());

UINT iRegister = 0;

VALIDATE_POINTER_TO_OBJECT_ARRAY(regBuffer, CORDB_REGISTER, regCount, true, true);

// @LOONGARCH64TODO: floating point support
#if 0
for (int i = REGISTER_LOONGARCH64_PC;
i <= REGISTER_LOONGARCH64_LR && iRegister < regCount;
i++)
{
if (mask & SETBITULONG64(i))
{
if ((i >= REGISTER_LOONGARCH64_X0) && (i <= REGISTER_LOONGARCH64_X28))
{
regBuffer[iRegister++] = m_rd->X[i - REGISTER_LOONGARCH64_X0];
continue;
}

switch (i)
{
case REGISTER_LOONGARCH64_PC:
regBuffer[iRegister++] = m_rd->PC; break;
case REGISTER_LOONGARCH64_SP:
regBuffer[iRegister++] = m_rd->SP; break;
case REGISTER_LOONGARCH64_FP:
regBuffer[iRegister++] = m_rd->FP; break;
default:
_ASSERTE(false); break;
}
}
}
#endif
_ASSERTE (iRegister <= regCount);
return S_OK;
}


HRESULT CordbRegisterSet::GetRegistersAvailable(ULONG32 regCount,
BYTE pAvailable[])
{
FAIL_IF_NEUTERED(this);
VALIDATE_POINTER_TO_OBJECT_ARRAY(pAvailable, CORDB_REGISTER, regCount, true, true);

// Defer to adapter for v1.0 interface
return GetRegistersAvailableAdapter(regCount, pAvailable);
}


HRESULT CordbRegisterSet::GetRegisters(ULONG32 maskCount, BYTE mask[],
ULONG32 regCount, CORDB_REGISTER regBuffer[])
{
FAIL_IF_NEUTERED(this);
VALIDATE_POINTER_TO_OBJECT_ARRAY(regBuffer, CORDB_REGISTER, regCount, true, true);

// Defer to adapter for v1.0 interface
return GetRegistersAdapter(maskCount, mask, regCount, regBuffer);
}


// This is just a convenience function to convert a regdisplay into a Context.
// Since a context has more info than a regdisplay, the conversion isn't perfect
// and the context can't be fully accurate.
void CordbRegisterSet::InternalCopyRDToContext(DT_CONTEXT *pInputContext)
{ INTERNAL_SYNC_API_ENTRY(GetProcess());
_ASSERTE(pInputContext);
assert(!"unimplemented on LOONGARCH yet");

if ((pInputContext->ContextFlags & DT_CONTEXT_INTEGER) == DT_CONTEXT_INTEGER)
{
#if 0
for (int i = 0 ; i < 29 ; ++i)
{
pInputContext->X[i] = m_rd->X[i];
}
#endif
}

if ((pInputContext->ContextFlags & DT_CONTEXT_CONTROL) == DT_CONTEXT_CONTROL)
{
pInputContext->SP = m_rd->SP;
pInputContext->PC = m_rd->PC;
pInputContext->FP = m_rd->FP;
}
}
Loading