From 00c09535b6e3501d0ee993a1b7c8f19150d76209 Mon Sep 17 00:00:00 2001 From: Zhang Wenlong Date: Wed, 8 Dec 2021 17:39:46 +0800 Subject: [PATCH] Introduce basic loongarch64 support Signed-off-by: Zhang Wenlong --- Makefile | 8 ++++++++ ld.hugetlbfs | 4 ++-- sys-elf64-loongarch.S | 24 ++++++++++++++++++++++++ tests/icache-hygiene.c | 2 +- 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 sys-elf64-loongarch.S diff --git a/Makefile b/Makefile index 8b73523..88dbf77 100644 --- a/Makefile +++ b/Makefile @@ -117,6 +117,13 @@ ELF64 = elf_riscv64 TMPLIB64 = lib64 CUSTOM_LDSCRIPTS = no else +ifeq ($(ARCH),loongarch64) +CC64 = $(CC) +ELF64 = elf64-loongarch +TMPLIB64 = lib64 +TMPLIB32 = lib +CUSTOM_LDSCRIPTS = no +else $(error "Unrecognized architecture ($(ARCH))") endif endif @@ -130,6 +137,7 @@ endif endif endif endif +endif ifdef CC32 OBJDIRS += obj32 diff --git a/ld.hugetlbfs b/ld.hugetlbfs index 5e4e497..0157114 100755 --- a/ld.hugetlbfs +++ b/ld.hugetlbfs @@ -117,7 +117,7 @@ elf64ppc|elf64lppc) fi ;; elf_i386|elf_x86_64) HPAGE_SIZE=$((4*$MB)) SLICE_SIZE=$HPAGE_SIZE ;; elf_s390|elf64_s390) HPAGE_SIZE=$((1*$MB)) SLICE_SIZE=$HPAGE_SIZE ;; -armelf*_linux_eabi|aarch64elf*|aarch64linux*) +armelf*_linux_eabi|aarch64elf*|aarch64linux*|elf64loongarch) hpage_kb=$(cat /proc/meminfo | grep Hugepagesize: | awk '{print $2}') HPAGE_SIZE=$((hpage_kb * 1024)) SLICE_SIZE=$HPAGE_SIZE ;; @@ -130,7 +130,7 @@ if [ "$HTLB_ALIGN" == "slice" ]; then # targeting the ARM platform one needs to explicitly set the text segment offset # otherwise it will be NULL. case "$EMU" in - armelf*_linux_eabi|aarch64elf*|aarch64linux*) + armelf*_linux_eabi|aarch64elf*|aarch64linux*|elf64loongarch) printf -v TEXTADDR "%x" "$SLICE_SIZE" HTLBOPTS="$HTLBOPTS -Ttext-segment=$TEXTADDR" ;; elf_i386) HTLBOPTS="$HTLBOPTS -Ttext-segment=0x08000000" ;; diff --git a/sys-elf64-loongarch.S b/sys-elf64-loongarch.S new file mode 100644 index 0000000..24c5f05 --- /dev/null +++ b/sys-elf64-loongarch.S @@ -0,0 +1,24 @@ +/* + * libhugetlbfs - direct system call for loongarch64 + * + * Author(s): Zhang Wenlong + */ + + + .text + + .globl direct_syscall + +direct_syscall: + move $a0,$ra + move $a1,$a0 + move $a2,$a1 + move $a3,$a2 + move $a4,$a6 + move $a5,$a4 + move $fp,$a5 + syscall 0 + jr $ra +#if defined(__linux__) && defined(__ELF__) + .section .note.GNU-stack,"",%progbits +#endif diff --git a/tests/icache-hygiene.c b/tests/icache-hygiene.c index 394d900..0013900 100644 --- a/tests/icache-hygiene.c +++ b/tests/icache-hygiene.c @@ -88,7 +88,7 @@ static void sig_handler(int signum, siginfo_t *si, void *uc) { #if defined(__powerpc__) || defined(__powerpc64__) || defined(__ia64__) || \ defined(__s390__) || defined(__s390x__) || defined(__sparc__) || \ - defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64) + defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64) || defined(__loongarch__) /* On powerpc, ia64, s390 and Aarch64, 0 bytes are an illegal * instruction, so, if the icache is cleared properly, we SIGILL * as soon as we jump into the cleared page */