From 663631eb50ba05c214ebae33ee02dbbe7fcfaceb Mon Sep 17 00:00:00 2001 From: Catty Steve <41934931+Catty2014@users.noreply.github.com> Date: Sat, 19 Sep 2026 14:41:38 +0800 Subject: [PATCH] Add LoongArch64 support (#428) * Add LoongArch64 support * Use refined preprocessor to determine loongarch64 --- include/bx/platform.h | 7 +++++++ scripts/toolchain.lua | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/bx/platform.h b/include/bx/platform.h index 1365f50..1a5291e 100644 --- a/include/bx/platform.h +++ b/include/bx/platform.h @@ -25,6 +25,7 @@ #define BX_CPU_JIT 0 #define BX_CPU_MIPS 0 #define BX_CPU_PPC 0 +#define BX_CPU_LOONGARCH64 0 #define BX_CPU_RISCV 0 #define BX_CPU_X86 0 @@ -108,6 +109,10 @@ # undef BX_CPU_RISCV # define BX_CPU_RISCV 1 # define BX_CACHE_LINE_SIZE 64 +#elif defined(__loongarch__) && (__loongarch_grlen == 64) +# undef BX_CPU_LOONGARCH64 +# define BX_CPU_LOONGARCH64 1 +# define BX_CACHE_LINE_SIZE 64 #elif defined(_M_IX86) \ || defined(_M_X64) \ || defined(__i386__) \ @@ -400,6 +405,8 @@ # define BX_CPU_NAME "MIPS" #elif BX_CPU_PPC # define BX_CPU_NAME "PowerPC" +#elif BX_CPU_LOONGARCH64 +# define BX_CPU_NAME "LoongArch64" #elif BX_CPU_RISCV # define BX_CPU_NAME "RISC-V" #elif BX_CPU_X86 diff --git a/scripts/toolchain.lua b/scripts/toolchain.lua index 1f4db40..cf93be2 100644 --- a/scripts/toolchain.lua +++ b/scripts/toolchain.lua @@ -78,6 +78,7 @@ function toolchain(_buildDir, _libDir) { "linux-ppc64le-gcc", "Linux (PPC64LE, GCC compiler)" }, { "linux-ppc64le-clang", "Linux (PPC64LE, Clang compiler)" }, { "linux-riscv64-gcc", "Linux (RISC-V 64, GCC compiler)" }, + { "linux-loongarch64-gcc", "Linux (LoongArch64, GCC compiler)" }, { "ios-arm64", "iOS - ARM64" }, { "ios-simulator", "iOS - Simulator" }, { "tvos-arm64", "tvOS - ARM64" }, @@ -341,6 +342,9 @@ function toolchain(_buildDir, _libDir) elseif "linux-riscv64-gcc" == _OPTIONS["gcc"] then location (path.join(_buildDir, "projects", _ACTION .. "-linux-riscv64-gcc")) + elseif "linux-loongarch64-gcc" == _OPTIONS["gcc"] then + location (path.join(_buildDir, "projects", _ACTION .. "-linux-loongarch64-gcc")) + elseif "mingw-gcc" == _OPTIONS["gcc"] then if not os.getenv("MINGW") then print("Set MINGW environment variable.") @@ -929,6 +933,20 @@ function toolchain(_buildDir, _libDir) "-Wl,--gc-sections", } + configuration { "linux-loongarch64*" } + buildoptions { + "-Wunused-value", + "-Wundef", + "-march=loongarch64" + } + links { + "rt", + "dl", + } + linkoptions { + "-Wl,--gc-sections", + } + configuration { "linux-ppc64le-gcc" } targetdir (path.join(_buildDir, "linux_ppc64le_gcc/bin")) objdir (path.join(_buildDir, "linux_ppc64le_gcc/obj")) @@ -944,6 +962,11 @@ function toolchain(_buildDir, _libDir) objdir (path.join(_buildDir, "linux_riscv64_gcc/obj")) libdirs { path.join(_libDir, "lib/linux_riscv64_gcc") } + configuration { "linux-loongarch64-gcc" } + targetdir (path.join(_buildDir, "linux_loongarch64_gcc/bin")) + objdir (path.join(_buildDir, "linux_loongarch64_gcc/obj")) + libdirs { path.join(_libDir, "lib/linux_loongarch64_gcc") } + configuration { "wasm2js" } targetdir (path.join(_buildDir, "wasm2js/bin")) objdir (path.join(_buildDir, "wasm2js/obj"))