From nobody Fri Dec 19 18:46:47 2025 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 C214C2628C; Mon, 23 Jun 2025 21:16:10 +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=1750713372; cv=none; b=i3baRM5hIDflqPRMVALZ6akOpP8dQu7PO2Hk/p3eYEYlEA5tsARqPEI1MJbGCelSnof8e/VVwFI3A19SDJgB8sZ4SJUisgaoW8cE5ZuUJthDn+KbPPGinmTUYAKZACc7MfAGgduCnyVg/wKk0SQMXiR1HFsWxsmsYnEiDSVsNQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750713372; c=relaxed/simple; bh=JXT55h1kBuOnOzqPmpYxX1L2/iZn2J8XhrAQLZByMqA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MA+PX76WKnPvvC7lcL8elAXrJpMOi6OfuvUFHYCC08bBN1V5Eo7Ejgj29d8U/Rawzh/O6Wo+n3v7GrQoXZNGL70s9GshGLS+RzpDRC6SPSiH8Z1ku9paDmE9SHlM5dDLKTwcghwkCbQBiu173D1nSCxptVtViszJtUBn7MxW5VU= 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=WZofouo4; 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="WZofouo4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1750713368; bh=JXT55h1kBuOnOzqPmpYxX1L2/iZn2J8XhrAQLZByMqA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=WZofouo4A2DqrhUw/NzUbOORc1oZ1Cphg/szyquc7/xvEXDls6ZxwWlBncnHj1qQe gAO2pIpdJJF0R8l6Xk7Q9T3w5dKQkkWqZ//XCUXFTblTeCN86d2m6fQ37QUK5y89FX 5GVrH7BHmv1dMQjpz3pM+g9U5hhXVxtvSNOoK36M= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 23 Jun 2025 23:15:52 +0200 Subject: [PATCH v2 1/3] selftests/nolibc: fix EXTRACONFIG variables ordering 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: <20250623-nolibc-sh-v2-1-0f5b4b303025@weissschuh.net> References: <20250623-nolibc-sh-v2-0-0f5b4b303025@weissschuh.net> In-Reply-To: <20250623-nolibc-sh-v2-0-0f5b4b303025@weissschuh.net> To: Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Willy Tarreau , Shuah Khan Cc: linux-sh@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@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=1750713367; l=1123; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=JXT55h1kBuOnOzqPmpYxX1L2/iZn2J8XhrAQLZByMqA=; b=Ju5eduvCW7qTCKhvkS1NoIMcxHMmg5crbapxtIQIsSvPZMv49Y4FKGSIkeO6QotRGU2GcNKxf uzkdHSsYPXvA76PcHrxb6ua/ucMrX6E8OFmZfLbo0kLA+2n0+uUJAju X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The variable block got disordered at some point. Use the correct ordering. Signed-off-by: Thomas Wei=C3=9Fschuh Acked-by: Willy Tarreau Tested-by: John Paul Adrian Glaubitz --- tools/testing/selftests/nolibc/Makefile.nolibc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/nolibc/Makefile.nolibc b/tools/testing= /selftests/nolibc/Makefile.nolibc index 6d62f350d0c16405785a8aabc7f5741b82e55370..9e220a733d97f3f916c6aa38df2= 414781f17ef94 100644 --- a/tools/testing/selftests/nolibc/Makefile.nolibc +++ b/tools/testing/selftests/nolibc/Makefile.nolibc @@ -107,10 +107,10 @@ DEFCONFIG_sparc64 =3D sparc64_defconfig DEFCONFIG_m68k =3D virt_defconfig DEFCONFIG =3D $(DEFCONFIG_$(XARCH)) =20 -EXTRACONFIG_m68k =3D -e CONFIG_BLK_DEV_INITRD -EXTRACONFIG =3D $(EXTRACONFIG_$(XARCH)) EXTRACONFIG_arm =3D -e CONFIG_NAMESPACES EXTRACONFIG_armthumb =3D -e CONFIG_NAMESPACES +EXTRACONFIG_m68k =3D -e CONFIG_BLK_DEV_INITRD +EXTRACONFIG =3D $(EXTRACONFIG_$(XARCH)) =20 # optional tests to run (default =3D all) TEST =3D --=20 2.50.0 From nobody Fri Dec 19 18:46:47 2025 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 F28FE1F582A; Mon, 23 Jun 2025 21:16:10 +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=1750713372; cv=none; b=Pi3knc9VC/6nWf8mAAeFzvaeY7gvv1H7LXkOl7fYmL1eoJb8viigvm6kCds5+qrZCLROxuff1FcwNsBc2I8eXVYiQquVOqeH83R+GBzO7LZwCpLx8veYlVxcmbrcKVA1gDiIabf3He2UAEzG9ZaZJvYZWDTTrRLPdtGAoroxBqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750713372; c=relaxed/simple; bh=AXpmx56Br8rtCaljBJmjxSdc1RxM2udDj6+vnOU1qBw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FFBWnd9kXSsphVYWvm/HpGx9mi+ZoxYlPGvWcSrbKN1yl6Dbrv6aLW7+6wbh7X45WaZi+JaphxX5Se98lUlrsPIltj1EdxgdmI5coknE5EzI5BOHuCwR7E8clpgObIlXpkcEym2AgtN/VTJiUBUG7pb8IRSrTSRs97JVhbTiILY= 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=mKRm93PP; 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="mKRm93PP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1750713368; bh=AXpmx56Br8rtCaljBJmjxSdc1RxM2udDj6+vnOU1qBw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=mKRm93PPYvPOvKfQAmIedippTp885v9QdH8yvIlDSF6liDlpBb4ZAYsi6LPoXzJC0 VY4UiggyWaP15K9bQ6im5kSuzR8upPsMTpRMLntHpiChdWsYO29y+/MOv+FPgHkIBN l+5RJPU/B2ByJY0iVw3LdS/ySWUNKsKkxiyQlr8g= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 23 Jun 2025 23:15:53 +0200 Subject: [PATCH v2 2/3] selftests/nolibc: use file driver for QEMU serial 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: <20250623-nolibc-sh-v2-2-0f5b4b303025@weissschuh.net> References: <20250623-nolibc-sh-v2-0-0f5b4b303025@weissschuh.net> In-Reply-To: <20250623-nolibc-sh-v2-0-0f5b4b303025@weissschuh.net> To: Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Willy Tarreau , Shuah Khan Cc: linux-sh@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@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=1750713367; l=1768; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=AXpmx56Br8rtCaljBJmjxSdc1RxM2udDj6+vnOU1qBw=; b=KXimSMwxaQ4c7kUohn5zfomefBOacBntKx/adLUEEZP1MCRngmETrlOCLznK1D8O0pMBf/nFN 0oOjuxG/MeLDc6+E0ExBVZdwS5PB2emv87/sZS43npFVfwq5wMFBhQm X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= For the test implementation of the SuperH architecture a second serial serial port needs to be used. Unfortunately the currently used 'stdio' driver does not support multiple serial ports at the same time. Switch to the 'file' driver which does support multiple ports and is sufficient for the nolibc-test usecase. Signed-off-by: Thomas Wei=C3=9Fschuh Acked-by: Willy Tarreau Tested-by: John Paul Adrian Glaubitz --- tools/testing/selftests/nolibc/Makefile.nolibc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/nolibc/Makefile.nolibc b/tools/testing= /selftests/nolibc/Makefile.nolibc index 9e220a733d97f3f916c6aa38df2414781f17ef94..ba3b762cb103ee87aafecbd5e83= 8fc0e678b7b50 100644 --- a/tools/testing/selftests/nolibc/Makefile.nolibc +++ b/tools/testing/selftests/nolibc/Makefile.nolibc @@ -311,12 +311,12 @@ kernel-standalone: initramfs =20 # run the tests after building the kernel run: kernel initramfs.cpio - $(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(IMAGE)" = -initrd initramfs.cpio -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out" + $(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(IMAGE)" = -initrd initramfs.cpio -serial file:/dev/stdout $(QEMU_ARGS) > "$(CURDIR)/r= un.out" $(Q)$(REPORT) $(CURDIR)/run.out =20 # re-run the tests from an existing kernel rerun: - $(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(IMAGE)" = -initrd initramfs.cpio -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out" + $(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(IMAGE)" = -initrd initramfs.cpio -serial file:/dev/stdout $(QEMU_ARGS) > "$(CURDIR)/r= un.out" $(Q)$(REPORT) $(CURDIR)/run.out =20 # report with existing test log --=20 2.50.0 From nobody Fri Dec 19 18:46:47 2025 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 F286E1F3FF8; Mon, 23 Jun 2025 21:16:10 +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=1750713373; cv=none; b=jsYNZtX+3mYr2PURneP2v7yGbFgsrYZD/i81SPBE7E4qZtgohVDZvfBtEF/LoHSra6PxcOiaF54JyelAcLi9pXfIuMwWJraTMpDxbA1G/9NorHfsxHKxkri9n//6FQploo00wNJGVH+sJ6HjaQV4QcC3MbMpbiveglNLiz6SVV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750713373; c=relaxed/simple; bh=YpKOiuy7+fqEFDRa7/CBt4BroadQtFTU7CicTLWPDGE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kWjv4EzxHeNV/MN2mLiui6iQ3y1Q67Cg24eg9w+LOsb9pNUYVOOPkU3W0PF8lf5zhw5b+dM/r4k9QD6dMqTT3upxXGklm28zl89hPwmQpGTVJU7Oye26k8eIwXzA0766a33yR6fUWrp2TmOJYyw44RAlPHQJOxjygViO5A5CO9U= 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=DoE976Nf; 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="DoE976Nf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1750713368; bh=YpKOiuy7+fqEFDRa7/CBt4BroadQtFTU7CicTLWPDGE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=DoE976Nfz4kVeLHcG/ji1c9wlZUaW5CJBL2lTF3t6y7dBFhAZYPsqjrKiSeuTp6ja Hv3Hn/pndA+m0cEXoT0sVnxmlMJWEZ9hbmogAEFpU7SGnuAj/PxU6/jjPcivm7dRbC 4PnMl++xjRbfwTpIw7kn0HHJIoNJuY3Z6jUxrOrU= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 23 Jun 2025 23:15:54 +0200 Subject: [PATCH v2 3/3] tools/nolibc: add support for SuperH 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: <20250623-nolibc-sh-v2-3-0f5b4b303025@weissschuh.net> References: <20250623-nolibc-sh-v2-0-0f5b4b303025@weissschuh.net> In-Reply-To: <20250623-nolibc-sh-v2-0-0f5b4b303025@weissschuh.net> To: Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Willy Tarreau , Shuah Khan Cc: linux-sh@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@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=1750713367; l=13930; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=YpKOiuy7+fqEFDRa7/CBt4BroadQtFTU7CicTLWPDGE=; b=Fpi6WPw4V95ew/7knr+a/8HXPNqQ3QyXiJSXpDWuZfibIPUAaLxXM8Ljaf0/3cyUEUWztgsfR tusNO9+kxAJCPi1NQB01fAH0al8InP0WGKZ/lwQTE3xGLLruIa+qG2H X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Add support for SuperH/"sh" to nolibc. Only sh4 is tested for now. The startup code is special: __nolibc_entrypoint_epilogue() calls __builtin_unreachable() which emits a call to abort(). To make this work a function prologue is generated to set up a GOT pointer which corrupts "sp". __builtin_unreachable() is necessary for __attribute__((noreturn)). Also depending on compiler flags (for example -fPIC) even more prologue is generated. Work around this by defining a nested function in asm. Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D70216 Signed-off-by: Thomas Wei=C3=9Fschuh Acked-by: Willy Tarreau Tested-by: John Paul Adrian Glaubitz --- tools/include/nolibc/arch-sh.h | 162 +++++++++++++++++++++= ++++ tools/include/nolibc/arch.h | 2 + tools/testing/selftests/nolibc/Makefile.nolibc | 7 ++ tools/testing/selftests/nolibc/run-tests.sh | 3 +- 4 files changed, 173 insertions(+), 1 deletion(-) diff --git a/tools/include/nolibc/arch-sh.h b/tools/include/nolibc/arch-sh.h new file mode 100644 index 0000000000000000000000000000000000000000..1ad006cba0f627f663eea36b41b= c7399cca4addb --- /dev/null +++ b/tools/include/nolibc/arch-sh.h @@ -0,0 +1,162 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * SuperH specific definitions for NOLIBC + * Copyright (C) 2025 Thomas Wei=C3=9Fschuh + */ + +#ifndef _NOLIBC_ARCH_SH_H +#define _NOLIBC_ARCH_SH_H + +#include "compiler.h" +#include "crt.h" + +/* + * Syscalls for SuperH: + * - registers are 32bit wide + * - syscall number is passed in r3 + * - arguments are in r4, r5, r6, r7, r0, r1, r2 + * - the system call is performed by calling trapa #31 + * - syscall return value is in r0 + */ + +#define my_syscall0(num) = \ +({ = \ + register long _num __asm__ ("r3") =3D (num); \ + register long _ret __asm__ ("r0"); \ + \ + __asm__ volatile ( \ + "trapa #31" \ + : "+r"(_ret) \ + : "r"(_num) \ + : "memory", "cc" \ + ); \ + _ret; \ +}) + +#define my_syscall1(num, arg1) = \ +({ = \ + register long _num __asm__ ("r3") =3D (num); \ + register long _ret __asm__ ("r0"); \ + register long _arg1 __asm__ ("r4") =3D (long)(arg1); \ + \ + __asm__ volatile ( \ + "trapa #31" \ + : "=3Dr"(_ret) \ + : "r"(_num), "r"(_arg1) \ + : "memory", "cc" \ + ); \ + _ret; \ +}) + +#define my_syscall2(num, arg1, arg2) = \ +({ = \ + register long _num __asm__ ("r3") =3D (num); \ + register long _ret __asm__ ("r0"); \ + register long _arg1 __asm__ ("r4") =3D (long)(arg1); \ + register long _arg2 __asm__ ("r5") =3D (long)(arg2); \ + \ + __asm__ volatile ( \ + "trapa #31" \ + : "=3Dr"(_ret) \ + : "r"(_num), "r"(_arg1), "r"(_arg2) \ + : "memory", "cc" \ + ); \ + _ret; \ +}) + +#define my_syscall3(num, arg1, arg2, arg3) = \ +({ = \ + register long _num __asm__ ("r3") =3D (num); \ + register long _ret __asm__ ("r0"); \ + register long _arg1 __asm__ ("r4") =3D (long)(arg1); \ + register long _arg2 __asm__ ("r5") =3D (long)(arg2); \ + register long _arg3 __asm__ ("r6") =3D (long)(arg3); \ + \ + __asm__ volatile ( \ + "trapa #31" \ + : "=3Dr"(_ret) \ + : "r"(_num), "r"(_arg1), "r"(_arg2), "r"(_arg3) \ + : "memory", "cc" \ + ); \ + _ret; \ +}) + +#define my_syscall4(num, arg1, arg2, arg3, arg4) = \ +({ = \ + register long _num __asm__ ("r3") =3D (num); \ + register long _ret __asm__ ("r0"); \ + register long _arg1 __asm__ ("r4") =3D (long)(arg1); \ + register long _arg2 __asm__ ("r5") =3D (long)(arg2); \ + register long _arg3 __asm__ ("r6") =3D (long)(arg3); \ + register long _arg4 __asm__ ("r7") =3D (long)(arg4); \ + \ + __asm__ volatile ( \ + "trapa #31" \ + : "=3Dr"(_ret) \ + : "r"(_num), "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4) \ + : "memory", "cc" \ + ); \ + _ret; \ +}) + +#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) = \ +({ = \ + register long _num __asm__ ("r3") =3D (num); \ + register long _ret __asm__ ("r0"); \ + register long _arg1 __asm__ ("r4") =3D (long)(arg1); \ + register long _arg2 __asm__ ("r5") =3D (long)(arg2); \ + register long _arg3 __asm__ ("r6") =3D (long)(arg3); \ + register long _arg4 __asm__ ("r7") =3D (long)(arg4); \ + register long _arg5 __asm__ ("r0") =3D (long)(arg5); \ + \ + __asm__ volatile ( \ + "trapa #31" \ + : "=3Dr"(_ret) \ + : "r"(_num), "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), \ + "r"(_arg5) \ + : "memory", "cc" \ + ); \ + _ret; \ +}) + +#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) = \ +({ = \ + register long _num __asm__ ("r3") =3D (num); \ + register long _ret __asm__ ("r0"); \ + register long _arg1 __asm__ ("r4") =3D (long)(arg1); \ + register long _arg2 __asm__ ("r5") =3D (long)(arg2); \ + register long _arg3 __asm__ ("r6") =3D (long)(arg3); \ + register long _arg4 __asm__ ("r7") =3D (long)(arg4); \ + register long _arg5 __asm__ ("r0") =3D (long)(arg5); \ + register long _arg6 __asm__ ("r1") =3D (long)(arg6); \ + \ + __asm__ volatile ( \ + "trapa #31" \ + : "=3Dr"(_ret) \ + : "r"(_num), "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), \ + "r"(_arg5), "r"(_arg6) \ + : "memory", "cc" \ + ); \ + _ret; \ +}) + +/* startup code */ +void _start_wrapper(void); +void __attribute__((weak,noreturn)) __nolibc_entrypoint __no_stack_protect= or _start_wrapper(void) +{ + __asm__ volatile ( + ".global _start\n" /* The C function will have a prologue, = */ + ".type _start, @function\n" /* corrupting "sp" = */ + ".weak _start\n" + "_start:\n" + + "mov sp, r4\n" /* save argc pointer to r4, as arg1 of _sta= rt_c */ + "bsr _start_c\n" /* transfer to c runtime = */ + "nop\n" /* delay slot = */ + + ".size _start, .-_start\n" + ); + __nolibc_entrypoint_epilogue(); +} + +#endif /* _NOLIBC_ARCH_SH_H */ diff --git a/tools/include/nolibc/arch.h b/tools/include/nolibc/arch.h index 4ae57aaf9779610dfb63458416f147116d0a98e6..5a34bce2981eaec557bc3616c7e= f7b809a6dbf0b 100644 --- a/tools/include/nolibc/arch.h +++ b/tools/include/nolibc/arch.h @@ -35,6 +35,8 @@ #include "arch-sparc.h" #elif defined(__m68k__) #include "arch-m68k.h" +#elif defined(__sh__) +#include "arch-sh.h" #else #error Unsupported Architecture #endif diff --git a/tools/testing/selftests/nolibc/Makefile.nolibc b/tools/testing= /selftests/nolibc/Makefile.nolibc index ba3b762cb103ee87aafecbd5e838fc0e678b7b50..41c708419d761df5de9e7df97b2= f070396e8cbf3 100644 --- a/tools/testing/selftests/nolibc/Makefile.nolibc +++ b/tools/testing/selftests/nolibc/Makefile.nolibc @@ -58,6 +58,7 @@ ARCH_riscv64 =3D riscv ARCH_s390x =3D s390 ARCH_sparc32 =3D sparc ARCH_sparc64 =3D sparc +ARCH_sh4 =3D sh ARCH :=3D $(or $(ARCH_$(XARCH)),$(XARCH)) =20 # kernel image names by architecture @@ -81,6 +82,7 @@ IMAGE_loongarch =3D arch/loongarch/boot/vmlinuz.efi IMAGE_sparc32 =3D arch/sparc/boot/image IMAGE_sparc64 =3D arch/sparc/boot/image IMAGE_m68k =3D vmlinux +IMAGE_sh4 =3D arch/sh/boot/zImage IMAGE =3D $(objtree)/$(IMAGE_$(XARCH)) IMAGE_NAME =3D $(notdir $(IMAGE)) =20 @@ -105,11 +107,13 @@ DEFCONFIG_loongarch =3D defconfig DEFCONFIG_sparc32 =3D sparc32_defconfig DEFCONFIG_sparc64 =3D sparc64_defconfig DEFCONFIG_m68k =3D virt_defconfig +DEFCONFIG_sh4 =3D rts7751r2dplus_defconfig DEFCONFIG =3D $(DEFCONFIG_$(XARCH)) =20 EXTRACONFIG_arm =3D -e CONFIG_NAMESPACES EXTRACONFIG_armthumb =3D -e CONFIG_NAMESPACES EXTRACONFIG_m68k =3D -e CONFIG_BLK_DEV_INITRD +EXTRACONFIG_sh4 =3D -e CONFIG_BLK_DEV_INITRD -e CONFIG_CMDLINE_FROM_= BOOTLOADER EXTRACONFIG =3D $(EXTRACONFIG_$(XARCH)) =20 # optional tests to run (default =3D all) @@ -136,6 +140,7 @@ QEMU_ARCH_loongarch =3D loongarch64 QEMU_ARCH_sparc32 =3D sparc QEMU_ARCH_sparc64 =3D sparc64 QEMU_ARCH_m68k =3D m68k +QEMU_ARCH_sh4 =3D sh4 QEMU_ARCH =3D $(QEMU_ARCH_$(XARCH)) =20 QEMU_ARCH_USER_ppc64le =3D ppc64le @@ -169,6 +174,7 @@ QEMU_ARGS_loongarch =3D -M virt -append "console=3Dtty= S0,115200 panic=3D-1 $(TEST:%=3DN QEMU_ARGS_sparc32 =3D -M SS-5 -m 256M -append "console=3DttyS0,115200 p= anic=3D-1 $(TEST:%=3DNOLIBC_TEST=3D%)" QEMU_ARGS_sparc64 =3D -M sun4u -append "console=3DttyS0,115200 panic=3D= -1 $(TEST:%=3DNOLIBC_TEST=3D%)" QEMU_ARGS_m68k =3D -M virt -append "console=3DttyGF0,115200 panic=3D= -1 $(TEST:%=3DNOLIBC_TEST=3D%)" +QEMU_ARGS_sh4 =3D -M r2d -serial file:/dev/stdout -append "console= =3DttySC1,115200 panic=3D-1 $(TEST:%=3DNOLIBC_TEST=3D%)" QEMU_ARGS =3D -m 1G $(QEMU_ARGS_$(XARCH)) $(QEMU_ARGS_BIOS) $(Q= EMU_ARGS_EXTRA) =20 # OUTPUT is only set when run from the main makefile, otherwise @@ -192,6 +198,7 @@ CFLAGS_s390 =3D -m31 CFLAGS_mips32le =3D -EL -mabi=3D32 -fPIC CFLAGS_mips32be =3D -EB -mabi=3D32 CFLAGS_sparc32 =3D $(call cc-option,-m32) +CFLAGS_sh4 =3D -ml -m4 ifeq ($(origin XARCH),command line) CFLAGS_XARCH =3D $(CFLAGS_$(XARCH)) endif diff --git a/tools/testing/selftests/nolibc/run-tests.sh b/tools/testing/se= lftests/nolibc/run-tests.sh index 279fbd93ef70497868689b7f1e14ddc6c5c1a15f..c55d6d3c10bba5df7f7e6413eea= 496148a5fbf52 100755 --- a/tools/testing/selftests/nolibc/run-tests.sh +++ b/tools/testing/selftests/nolibc/run-tests.sh @@ -27,6 +27,7 @@ all_archs=3D( loongarch sparc32 sparc64 m68k + sh4 ) archs=3D"${all_archs[@]}" =20 @@ -187,7 +188,7 @@ test_arch() { echo "Unsupported configuration" return fi - if [ "$arch" =3D "m68k" ] && [ "$llvm" =3D "1" ]; then + if [ "$arch" =3D "m68k" -o "$arch" =3D "sh4" ] && [ "$llvm" =3D "1" ]; th= en echo "Unsupported configuration" return fi --=20 2.50.0