Skip to content

nall: add support for LoongArch architecture #1356

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

Open
wants to merge 1 commit into
base: master
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
2 changes: 2 additions & 0 deletions nall/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ else
machine := arm64
else ifneq ($(filter arm-% armv7-%,$(machine_str)),)
machine := arm32
else ifneq ($(filter loong64-% loongarch64-%,$(machine_str)),)
machine := loong64
else ifneq ($(filter powerpc64-% powerpc64le-%,$(machine_str)),)
machine := ppc64
else ifneq ($(filter riscv64-%,$(machine_str)),)
Expand Down
21 changes: 21 additions & 0 deletions nall/intrinsics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ namespace nall {
static constexpr bool amd64 = 0;
static constexpr bool arm64 = 0;
static constexpr bool arm32 = 0;
static constexpr bool loong64 = 0;
static constexpr bool ppc64 = 0;
static constexpr bool ppc32 = 0;
static constexpr bool rv64 = 0;
Expand All @@ -205,6 +206,7 @@ namespace nall {
static constexpr bool amd64 = 1;
static constexpr bool arm64 = 0;
static constexpr bool arm32 = 0;
static constexpr bool loong64 = 0;
static constexpr bool ppc64 = 0;
static constexpr bool ppc32 = 0;
static constexpr bool rv64 = 0;
Expand All @@ -220,6 +222,7 @@ namespace nall {
static constexpr bool amd64 = 0;
static constexpr bool arm64 = 1;
static constexpr bool arm32 = 0;
static constexpr bool loong64 = 0;
static constexpr bool ppc64 = 0;
static constexpr bool ppc32 = 0;
static constexpr bool rv64 = 0;
Expand All @@ -232,6 +235,20 @@ namespace nall {
static constexpr bool amd64 = 0;
static constexpr bool arm64 = 0;
static constexpr bool arm32 = 1;
static constexpr bool loong64 = 0;
static constexpr bool ppc64 = 0;
static constexpr bool ppc32 = 0;
static constexpr bool rv64 = 0;
static constexpr bool rv32 = 0;
};
#elif defined(__loongarch64)
#define ARCHITECTURE_LOONG64
struct Architecture {
static constexpr bool x86 = 0;
static constexpr bool amd64 = 0;
static constexpr bool arm64 = 0;
static constexpr bool arm32 = 0;
static constexpr bool loong64 = 1;
static constexpr bool ppc64 = 0;
static constexpr bool ppc32 = 0;
static constexpr bool rv64 = 0;
Expand All @@ -244,6 +261,7 @@ namespace nall {
static constexpr bool amd64 = 0;
static constexpr bool arm64 = 0;
static constexpr bool arm32 = 0;
static constexpr bool loong64 = 0;
static constexpr bool ppc64 = 1;
static constexpr bool ppc32 = 0;
static constexpr bool rv64 = 0;
Expand All @@ -256,6 +274,7 @@ namespace nall {
static constexpr bool amd64 = 0;
static constexpr bool arm64 = 0;
static constexpr bool arm32 = 0;
static constexpr bool loong64 = 0;
static constexpr bool ppc64 = 0;
static constexpr bool ppc32 = 1;
static constexpr bool rv64 = 0;
Expand All @@ -268,6 +287,7 @@ namespace nall {
static constexpr bool amd64 = 0;
static constexpr bool arm64 = 0;
static constexpr bool arm32 = 0;
static constexpr bool loong64 = 0;
static constexpr bool ppc64 = 0;
static constexpr bool ppc32 = 0;
static constexpr bool rv64 = 1;
Expand All @@ -280,6 +300,7 @@ namespace nall {
static constexpr bool amd64 = 0;
static constexpr bool arm64 = 0;
static constexpr bool arm32 = 0;
static constexpr bool loong64 = 0;
static constexpr bool ppc64 = 0;
static constexpr bool ppc32 = 0;
static constexpr bool rv64 = 0;
Expand Down
2 changes: 1 addition & 1 deletion nall/recompiler/generic/generic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#if defined(SLJIT)
namespace nall::recompiler {
struct generic {
static constexpr bool supported = Architecture::amd64 | Architecture::arm64 | Architecture::ppc64 | Architecture::rv64;
static constexpr bool supported = Architecture::amd64 | Architecture::arm64 | Architecture::loong64 | Architecture::ppc64 | Architecture::rv64;
Copy link
Member

Choose a reason for hiding this comment

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

Our recompiler backend (sljit) doesn't appear to support the longarch architecture, so you should not include it in this supported variable.

See https://zherczeg.github.io/sljit/

Copy link
Member

Choose a reason for hiding this comment

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

Although I see the mips64 backend might be compatible due to the fact longarch is derived from it; were you able to test a recompiler based system (n64, ps1)

Copy link
Contributor

Choose a reason for hiding this comment

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

Although inspired by MIPS (and RISC-V), LoongArch is not binary compatible. However, it seems like sljit has added a LoongArch backend, see https://github.com/zherczeg/sljit/blob/master/sljit_src/sljitNativeLOONGARCH_64.c. No idea how stable that backend is.


bump_allocator& allocator;
sljit_compiler* compiler = nullptr;
Expand Down