From nobody Thu Nov 28 19:47:11 2024 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C6BC768E1; Sun, 29 Sep 2024 21:47:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727646471; cv=none; b=ml7AkzG+ojCZM3RbrCGlDpnYBgoOwocTtKGHQ2Ls3ByZjMVWR0SfS8nXhRVKoXcKwXOuviNuJYWRTJJomUmZy9Wd32FtOz/VDKn5x16beUpiLkewYbLk6ANV/yG88aMspW3z1w/KiTrNqYV4NUHan2ys9kjalFQZ02YU+MGG9lc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727646471; c=relaxed/simple; bh=kt49PtAybWU6qeBrvK9KHknH5KAfe1qC7aTKAetqLQU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=k9tHMMArFOgIULOJmdnePlhJJOB0NxFpfFsaXzAuWadI8lRYYw2Jfqsjrl4BwWC+xtAW1D2D/m0TVmydJgZmSf/BtodII73xcEw6GtAk4y9z+4JKReqPReb0Xm2BS9sqM5hrB3am7av1YOfHbSWnYxRYBwbTVDhvLbh8Xy5f6Yg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=lqi3T4Ro; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="lqi3T4Ro" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1727646464; bh=kt49PtAybWU6qeBrvK9KHknH5KAfe1qC7aTKAetqLQU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lqi3T4Rof3pcEBQn9Txflv6Rl8qZ3R7I2czIVsAYeNyosxPBt5I2bBK/XCFzeT1q9 zczc8gkoWcllZj0oz2mlWIZ5j/cgvp+AtRG7GNI8xKaGww2vFnr0pMntTiJZR+lAfV hPxXOSQIrVcXKi6D1msI1LUh8slGmJVpf3X9namM= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 29 Sep 2024 23:47:39 +0200 Subject: [PATCH 4/5] tools/nolibc: add csky support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240929-nolibc-csky-v1-4-bb28031a73b0@weissschuh.net> References: <20240929-nolibc-csky-v1-0-bb28031a73b0@weissschuh.net> In-Reply-To: <20240929-nolibc-csky-v1-0-bb28031a73b0@weissschuh.net> To: Guo Ren , Willy Tarreau , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-csky@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1727646464; l=14066; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=kt49PtAybWU6qeBrvK9KHknH5KAfe1qC7aTKAetqLQU=; b=28wJKP4GSe3f4ZHO5k7yeetugZfYRZKOlRHphSaay8uGd/N2oOkRWCtCmQCbCT7Mo4ZcbJgKu sOCfW3ALEZXAGJJGSuSm8o2EHpTlJ318zEWDaBhAm5S8zUFnZWs/aKQ X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Add support for the C-SKY architecture, which is very similar to LoongArch. Only v2 ABI is supported. Optimizations are disabled as the compiler[0] seems to misoptimize the code, especially the r4 register gets clobbered. Compile the initramfs directly into the kernel, as qemu does not support passing the initrd via OF. There is no qemu mainline support for qemu. Testing was done with commit 1f172a2c7cd5c2e7 of the downstream csky qemu [= 1]. Some tiny changes were necessary on top [2]. [0] gcc 13.2.0 and 14.2.0 from kernel.org crosstools [1] https://github.com/XUANTIE-RV/qemu/ [2] diff --git a/target/csky/cpu-param.h b/target/csky/cpu-param.h index 80554cc0fc03..9181b602a26f 100644 --- a/target/csky/cpu-param.h +++ b/target/csky/cpu-param.h @@ -24,11 +24,7 @@ #define TARGET_PAGE_BITS 12 #define TARGET_PHYS_ADDR_SPACE_BITS 32 -#ifdef CONFIG_USER_ONLY -#define TARGET_VIRT_ADDR_SPACE_BITS 30 -#else #define TARGET_VIRT_ADDR_SPACE_BITS 32 -#endif #define TCG_GUEST_DEFAULT_MO (0) #endif diff --git a/target/csky/op_vdsp2.c b/target/csky/op_vdsp2.c index a9985a03be33..d953f5ea94fe 100644 --- a/target/csky/op_vdsp2.c +++ b/target/csky/op_vdsp2.c @@ -4784,7 +4784,7 @@ void VDSP2_HELPER(vmulae)(CPUCSKYState *env, uint32_t= insn) wid =3D ((insn >> 20) & 0x1) | ((insn >> 24) & 0x2); lng =3D 8 * pow(2, wid); - cnt =3D 128 / lng; + cnt =3D 64 / lng; sign =3D (insn >> CSKY_VDSP2_SIGN_SHI) & CSKY_VDSP2_SIGN_MASK; rx =3D (insn >> CSKY_VDSP2_VREG_SHI_VRX) & CSKY_VDSP2_VREG_MASK; ry =3D (insn >> CSKY_VDSP2_VREG_SHI_VRY) & CSKY_VDSP2_VREG_MASK; Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/include/nolibc/arch-csky.h | 161 ++++++++++++++++++++++++++++= ++++ tools/include/nolibc/arch.h | 2 + tools/testing/selftests/nolibc/Makefile | 8 ++ 3 files changed, 171 insertions(+) diff --git a/tools/include/nolibc/arch-csky.h b/tools/include/nolibc/arch-c= sky.h new file mode 100644 index 0000000000000000000000000000000000000000..158e5499375c22a6572321337ba= 4e2b8162d0d65 --- /dev/null +++ b/tools/include/nolibc/arch-csky.h @@ -0,0 +1,161 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * C-SKY specific definitions for NOLIBC + * Copyright (C) 2023 Loongson Technology Corporation Limited + * Copyright (C) 2024 Thomas Wei=C3=9Fschuh + */ + +#ifndef _NOLIBC_ARCH_CSKY_H +#define _NOLIBC_ARCH_CSKY_H + +#include "compiler.h" +#include "crt.h" + +#if __csky__ !=3D 2 +#error Unsupported csky ABI +#endif + +/* Syscalls for C-SKY : + * - stack is 8-byte aligned + * - syscall number is passed in r7 + * - arguments are in r0, r1, r2, r3, r4, r5 + * - the system call is performed by calling "trap 0" + * - syscall return comes in r0 + * - the arguments are cast to long and assigned into the target + * registers which are then simply passed as registers to the asm code, + * so that we don't have to experience issues with register constraint= s. + */ + +#define _NOLIBC_SYSCALL_CLOBBERLIST \ + "memory", "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9" + +#define my_syscall0(num) = \ +({ = \ + register long _num __asm__ ("r7") =3D (num); \ + register long _arg1 __asm__ ("r0"); \ + \ + __asm__ volatile ( \ + "trap 0\n" \ + : "=3Dr"(_arg1) \ + : "r"(_num) \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ + ); \ + _arg1; \ +}) + +#define my_syscall1(num, arg1) = \ +({ = \ + register long _num __asm__ ("r7") =3D (num); \ + register long _arg1 __asm__ ("r0") =3D (long)(arg1); \ + \ + __asm__ volatile ( \ + "trap 0\n" \ + : "+r"(_arg1) \ + : "r"(_num) \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ + ); \ + _arg1; \ +}) + +#define my_syscall2(num, arg1, arg2) = \ +({ = \ + register long _num __asm__ ("r7") =3D (num); \ + register long _arg1 __asm__ ("r0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("r1") =3D (long)(arg2); \ + \ + __asm__ volatile ( \ + "trap 0\n" \ + : "+r"(_arg1) \ + : "r"(_arg2), \ + "r"(_num) \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ + ); \ + _arg1; \ +}) + +#define my_syscall3(num, arg1, arg2, arg3) = \ +({ = \ + register long _num __asm__ ("r7") =3D (num); \ + register long _arg1 __asm__ ("r0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("r1") =3D (long)(arg2); \ + register long _arg3 __asm__ ("r2") =3D (long)(arg3); \ + \ + __asm__ volatile ( \ + "trap 0\n" \ + : "+r"(_arg1) \ + : "r"(_arg2), "r"(_arg3), \ + "r"(_num) \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ + ); \ + _arg1; \ +}) + +#define my_syscall4(num, arg1, arg2, arg3, arg4) = \ +({ = \ + register long _num __asm__ ("r7") =3D (num); \ + register long _arg1 __asm__ ("r0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("r1") =3D (long)(arg2); \ + register long _arg3 __asm__ ("r2") =3D (long)(arg3); \ + register long _arg4 __asm__ ("r3") =3D (long)(arg4); \ + \ + __asm__ volatile ( \ + "trap 0\n" \ + : "+r"(_arg1) \ + : "r"(_arg2), "r"(_arg3), "r"(_arg4), \ + "r"(_num) \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ + ); \ + _arg1; \ +}) + +#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) = \ +({ = \ + register long _num __asm__ ("r7") =3D (num); \ + register long _arg1 __asm__ ("r0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("r1") =3D (long)(arg2); \ + register long _arg3 __asm__ ("r2") =3D (long)(arg3); \ + register long _arg4 __asm__ ("r3") =3D (long)(arg4); \ + register long _arg5 __asm__ ("r4") =3D (long)(arg5); \ + \ + __asm__ volatile ( \ + "trap 0\n" \ + : "+r"(_arg1) \ + : "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \ + "r"(_num) \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ + ); \ + _arg1; \ +}) + +#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) = \ +({ = \ + register long _num __asm__ ("r7") =3D (num); \ + register long _arg1 __asm__ ("r0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("r1") =3D (long)(arg2); \ + register long _arg3 __asm__ ("r2") =3D (long)(arg3); \ + register long _arg4 __asm__ ("r3") =3D (long)(arg4); \ + register long _arg5 __asm__ ("r4") =3D (long)(arg5); \ + register long _arg6 __asm__ ("r5") =3D (long)(arg6); \ + \ + __asm__ volatile ( \ + "trap 0\n" \ + : "+r"(_arg1) \ + : "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), "r"(_arg6), \ + "r"(_num) \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ + ); \ + _arg1; \ +}) + +/* startup code */ +void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protec= tor _start(void) +{ + __asm__ volatile ( + "mov r0, sp\n" /* save stack pointer to r0, as arg1 of _st= art_c */ + "andni sp, sp, 8\n" /* sp must be 8-byte aligned in the callee = */ + "jbsr _start_c\n" /* transfer to c runtime = */ + ); + __nolibc_entrypoint_epilogue(); +} + +#endif /* _NOLIBC_ARCH_CSKY_H */ diff --git a/tools/include/nolibc/arch.h b/tools/include/nolibc/arch.h index c8f4e5d3add9eb5b8a438900c084dc0449fcfbd6..71cdf1eedb2045b9abd22146c72= ee891765ad553 100644 --- a/tools/include/nolibc/arch.h +++ b/tools/include/nolibc/arch.h @@ -33,6 +33,8 @@ #include "arch-s390.h" #elif defined(__loongarch__) #include "arch-loongarch.h" +#elif defined(__csky__) +#include "arch-csky.h" #else #error Unsupported Architecture #endif diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selfte= sts/nolibc/Makefile index e8278924cf28f17144044e69724df1d4fde141a3..2f51d8ea45f1c0658584f27553a= 9c8e1ecf428a9 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -67,6 +67,7 @@ IMAGE_ppc64le =3D arch/powerpc/boot/zImage IMAGE_riscv =3D arch/riscv/boot/Image IMAGE_s390 =3D arch/s390/boot/bzImage IMAGE_loongarch =3D arch/loongarch/boot/vmlinuz.efi +IMAGE_csky =3D arch/csky/boot/Image IMAGE =3D $(objtree)/$(IMAGE_$(XARCH)) IMAGE_NAME =3D $(notdir $(IMAGE)) =20 @@ -84,9 +85,11 @@ DEFCONFIG_ppc64le =3D powernv_defconfig DEFCONFIG_riscv =3D defconfig DEFCONFIG_s390 =3D defconfig DEFCONFIG_loongarch =3D defconfig +DEFCONFIG_csky =3D defconfig DEFCONFIG =3D $(DEFCONFIG_$(XARCH)) =20 EXTRACONFIG_mips32be =3D -d CONFIG_CPU_LITTLE_ENDIAN -e CONFIG_CPU_BIG_END= IAN +EXTRACONFIG_csky =3D -e CONFIG_BLK_DEV_INITRD -e CONFIG_VIRT_DRIVERS -= e CONFIG_CSKY_EXIT EXTRACONFIG =3D $(EXTRACONFIG_$(XARCH)) =20 # optional tests to run (default =3D all) @@ -106,6 +109,7 @@ QEMU_ARCH_ppc64le =3D ppc64 QEMU_ARCH_riscv =3D riscv64 QEMU_ARCH_s390 =3D s390x QEMU_ARCH_loongarch =3D loongarch64 +QEMU_ARCH_csky =3D cskyv2 QEMU_ARCH =3D $(QEMU_ARCH_$(XARCH)) =20 QEMU_ARCH_USER_ppc64le =3D ppc64le @@ -132,8 +136,11 @@ QEMU_ARGS_ppc64le =3D -M powernv -append "console= =3Dhvc0 panic=3D-1 $(TEST:%=3DNOLIBC QEMU_ARGS_riscv =3D -M virt -append "console=3DttyS0 panic=3D-1 $(TES= T:%=3DNOLIBC_TEST=3D%)" QEMU_ARGS_s390 =3D -M s390-ccw-virtio -m 1G -append "console=3DttyS0= panic=3D-1 $(TEST:%=3DNOLIBC_TEST=3D%)" QEMU_ARGS_loongarch =3D -M virt -append "console=3DttyS0,115200 panic=3D-= 1 $(TEST:%=3DNOLIBC_TEST=3D%)" +QEMU_ARGS_csky =3D -M virt -append "console=3DttyS0,115200 panic=3D-= 1 $(TEST:%=3DNOLIBC_TEST=3D%)" QEMU_ARGS =3D $(QEMU_ARGS_$(XARCH)) $(QEMU_ARGS_BIOS) $(QEMU_AR= GS_EXTRA) =20 +QEMU_RUN_STANDALONE_csky =3D 1 + # OUTPUT is only set when run from the main makefile, otherwise # it defaults to this nolibc directory. OUTPUT ?=3D $(CURDIR)/ @@ -151,6 +158,7 @@ CFLAGS_ppc64le =3D -m64 -mlittle-endian -mno-vsx $(call= cc-option,-mabi=3Delfv2) CFLAGS_s390 =3D -m64 CFLAGS_mips32le =3D -EL -mabi=3D32 -fPIC CFLAGS_mips32be =3D -EB -mabi=3D32 +CFLAGS_csky =3D -O0 CFLAGS_STACKPROTECTOR ?=3D $(call cc-option,-mstack-protector-guard=3Dglob= al $(call cc-option,-fstack-protector-all)) CFLAGS ?=3D -Os -fno-ident -fno-asynchronous-unwind-tables -std=3Dc89 -W = -Wall -Wextra \ $(call cc-option,-fno-stack-protector) \ --=20 2.46.2