Message ID | c35dc58e-444f-0809-67cc-113d6b4b29be@loongson.cn (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [001] feature: add support for loongarch | expand |
On Fri, May 24, 2024 at 10:47:23AM +0800, wuruilong wrote: > sparse compiles incorrectly on loongarch, the attached patch compiles > successfully after local testing. This patch has some relevance to Debian because currently sparse doesn't compile for loongson and so also the packages that depend on sparse cannot be built. I'd like to cherry-pick this patch, but would have a better feeling to do so if it was applied already. With my innocent knowledge the patch looks ok, but I don't feel very qualified. FTR: There is a Debian bug report (https://bugs.debian.org/1071605) with this patch. Best regards Uwe
On Fri, May 24, 2024 at 10:47:23AM +0800, wuruilong wrote: > +const struct target target_loongarch64 = { > + .mach = MACH_LOONGARCH64, > + .bitness = ARCH_LP64, > + > + .big_endian = 0, No need to initialize things to zero. > + .unsigned_char = 1, According to https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html "For all base ABI types of LoongArch, the char datatype is signed by default." Is the webpage wrong? > + .has_int128 = 1, > + > + .predefine = predefine_loongarch64, > +}; > diff --git a/target.c b/target.c > index 8ae22d74..0e075d59 100644 > --- a/target.c > +++ b/target.c > @@ -94,6 +94,7 @@ static const struct target *targets[] = { > [MACH_PPC64] = &target_ppc64, > [MACH_RISCV32] = &target_riscv32, > [MACH_RISCV64] = &target_riscv64, > + [MACH_LOONGARCH64] = &target_loongarch64, > [MACH_S390] = &target_s390, > [MACH_S390X] = &target_s390x, > [MACH_SH] = &target_sh, > @@ -112,29 +113,30 @@ enum machine target_parse(const char *name) > enum machine mach; > char bits; > } archs[] = { > - { "alpha", MACH_ALPHA, 64, }, > - { "aarch64", MACH_ARM64, 64, }, > - { "arm64", MACH_ARM64, 64, }, > - { "arm", MACH_ARM, 32, }, > - { "bfin", MACH_BFIN, 32, }, > - { "h8300", MACH_H8300, 32, }, > - { "i386", MACH_I386, 32, }, > - { "m68k", MACH_M68K, 32, }, > - { "microblaze", MACH_MICROBLAZE,32, }, > - { "mips", MACH_MIPS32, 0, }, > - { "nds32", MACH_NDS32, 32, }, > - { "nios2", MACH_NIOS2, 32, }, > - { "openrisc", MACH_OPENRISC, 32, }, > - { "powerpc", MACH_PPC32, 0, }, > - { "ppc", MACH_PPC32, 0, }, > - { "riscv", MACH_RISCV32, 0, }, > - { "s390x", MACH_S390X, 64, }, > - { "s390", MACH_S390, 32, }, > - { "sparc", MACH_SPARC32, 0, }, > - { "x86_64", MACH_X86_64, 64, }, > - { "x86-64", MACH_X86_64, 64, }, > - { "sh", MACH_SH, 32, }, > - { "xtensa", MACH_XTENSA, 32, }, > + { "alpha", MACH_ALPHA, 64, }, > + { "aarch64", MACH_ARM64, 64, }, > + { "arm64", MACH_ARM64, 64, }, > + { "arm", MACH_ARM, 32, }, > + { "bfin", MACH_BFIN, 32, }, > + { "h8300", MACH_H8300, 32, }, > + { "i386", MACH_I386, 32, }, > + { "loongarch64",MACH_LOONGARCH64,64, }, Add spaces after the commas, especially if we're going to re-indent the whole table anyway. regards, dan carpenter
Hello Dan, On 9/4/24 07:39, Dan Carpenter wrote: > On Fri, May 24, 2024 at 10:47:23AM +0800, wuruilong wrote: >> +const struct target target_loongarch64 = { >> + .mach = MACH_LOONGARCH64, >> + .bitness = ARCH_LP64, >> + >> + .big_endian = 0, > > No need to initialize things to zero. While your concern is technically correct, mentioning it explicitly for a human reader is still nice IMHO. Best regards Uwe
On Wed, Sep 04, 2024 at 11:21:45AM +0200, Uwe Kleine-König wrote: > Hello Dan, > > On 9/4/24 07:39, Dan Carpenter wrote: > > On Fri, May 24, 2024 at 10:47:23AM +0800, wuruilong wrote: > > > +const struct target target_loongarch64 = { > > > + .mach = MACH_LOONGARCH64, > > > + .bitness = ARCH_LP64, > > > + > > > + .big_endian = 0, > > > > No need to initialize things to zero. > > While your concern is technically correct, mentioning it explicitly for a > human reader is still nice IMHO. The only reason I mentioned any of this is because the unsigned_char thing is probably a bug. Otherwise, I don't go around nit-picking these types of things. I don't have strong feelings about this. regards, dan carpenter
From 474acf81ee8162f50c20f41a566510d84a1f828c Mon Sep 17 00:00:00 2001 From: wuruilong <wuruilong@loongson.cn> Date: Fri, 24 May 2024 02:23:46 +0000 Subject: [PATCH] Add support for loongarch Signed-off-by: wuruilong <wuruilong@loongson.cn> --- Makefile | 1 + machine.h | 3 +++ target-loongarch64.c | 21 +++++++++++++++++++ target.c | 48 +++++++++++++++++++++++--------------------- target.h | 1 + 5 files changed, 51 insertions(+), 23 deletions(-) create mode 100644 target-loongarch64.c diff --git a/Makefile b/Makefile index e172758b..315617f4 100644 --- a/Makefile +++ b/Makefile @@ -73,6 +73,7 @@ LIB_OBJS += target-arm64.o LIB_OBJS += target-bfin.o LIB_OBJS += target-default.o LIB_OBJS += target-h8300.o +LIB_OBJS += target-loongarch64.o LIB_OBJS += target-m68k.o LIB_OBJS += target-microblaze.o LIB_OBJS += target-mips.o diff --git a/machine.h b/machine.h index d05b5045..8be3aeed 100644 --- a/machine.h +++ b/machine.h @@ -42,6 +42,7 @@ enum machine { MACH_OPENRISC, MACH_SH, MACH_XTENSA, + MACH_LOONGARCH64, MACH_UNKNOWN }; @@ -55,6 +56,8 @@ enum machine { #define MACH_NATIVE MACH_X86_64 #elif defined(__i386__) || defined(__i386) #define MACH_NATIVE MACH_I386 +#elif defined(__loongarch__) +#define MACH_NATIVE MACH_LOONGARCH64 #elif defined(__mips64__) || (defined(__mips) && __mips == 64) #define MACH_NATIVE MACH_MIPS64 #elif defined(__mips__) || defined(__mips) diff --git a/target-loongarch64.c b/target-loongarch64.c new file mode 100644 index 00000000..34b4d3d9 --- /dev/null +++ b/target-loongarch64.c @@ -0,0 +1,21 @@ +#include "symbol.h" +#include "target.h" +#include "machine.h" + + + +static void predefine_loongarch64(const struct target *self) +{ + predefine("__loongarch__", 1, "64"); +} + +const struct target target_loongarch64 = { + .mach = MACH_LOONGARCH64, + .bitness = ARCH_LP64, + + .big_endian = 0, + .unsigned_char = 1, + .has_int128 = 1, + + .predefine = predefine_loongarch64, +}; diff --git a/target.c b/target.c index 8ae22d74..0e075d59 100644 --- a/target.c +++ b/target.c @@ -94,6 +94,7 @@ static const struct target *targets[] = { [MACH_PPC64] = &target_ppc64, [MACH_RISCV32] = &target_riscv32, [MACH_RISCV64] = &target_riscv64, + [MACH_LOONGARCH64] = &target_loongarch64, [MACH_S390] = &target_s390, [MACH_S390X] = &target_s390x, [MACH_SH] = &target_sh, @@ -112,29 +113,30 @@ enum machine target_parse(const char *name) enum machine mach; char bits; } archs[] = { - { "alpha", MACH_ALPHA, 64, }, - { "aarch64", MACH_ARM64, 64, }, - { "arm64", MACH_ARM64, 64, }, - { "arm", MACH_ARM, 32, }, - { "bfin", MACH_BFIN, 32, }, - { "h8300", MACH_H8300, 32, }, - { "i386", MACH_I386, 32, }, - { "m68k", MACH_M68K, 32, }, - { "microblaze", MACH_MICROBLAZE,32, }, - { "mips", MACH_MIPS32, 0, }, - { "nds32", MACH_NDS32, 32, }, - { "nios2", MACH_NIOS2, 32, }, - { "openrisc", MACH_OPENRISC, 32, }, - { "powerpc", MACH_PPC32, 0, }, - { "ppc", MACH_PPC32, 0, }, - { "riscv", MACH_RISCV32, 0, }, - { "s390x", MACH_S390X, 64, }, - { "s390", MACH_S390, 32, }, - { "sparc", MACH_SPARC32, 0, }, - { "x86_64", MACH_X86_64, 64, }, - { "x86-64", MACH_X86_64, 64, }, - { "sh", MACH_SH, 32, }, - { "xtensa", MACH_XTENSA, 32, }, + { "alpha", MACH_ALPHA, 64, }, + { "aarch64", MACH_ARM64, 64, }, + { "arm64", MACH_ARM64, 64, }, + { "arm", MACH_ARM, 32, }, + { "bfin", MACH_BFIN, 32, }, + { "h8300", MACH_H8300, 32, }, + { "i386", MACH_I386, 32, }, + { "loongarch64",MACH_LOONGARCH64,64, }, + { "m68k", MACH_M68K, 32, }, + { "microblaze", MACH_MICROBLAZE, 32, }, + { "mips", MACH_MIPS32, 0, }, + { "nds32", MACH_NDS32, 32, }, + { "nios2", MACH_NIOS2, 32, }, + { "openrisc", MACH_OPENRISC, 32, }, + { "powerpc", MACH_PPC32, 0, }, + { "ppc", MACH_PPC32, 0, }, + { "riscv", MACH_RISCV32, 0, }, + { "s390x", MACH_S390X, 64, }, + { "s390", MACH_S390, 32, }, + { "sparc", MACH_SPARC32, 0, }, + { "x86_64", MACH_X86_64, 64, }, + { "x86-64", MACH_X86_64, 64, }, + { "sh", MACH_SH, 32, }, + { "xtensa", MACH_XTENSA, 32, }, { NULL }, }; const struct arch *p; diff --git a/target.h b/target.h index 92b8af91..b24574ae 100644 --- a/target.h +++ b/target.h @@ -120,6 +120,7 @@ extern const struct target target_ppc32; extern const struct target target_ppc64; extern const struct target target_riscv32; extern const struct target target_riscv64; +extern const struct target target_loongarch64; extern const struct target target_s390; extern const struct target target_s390x; extern const struct target target_sh; -- 2.43.0