From nobody Mon Sep 28 02:15:47 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1785138414; cv=none; d=zohomail.com; s=zohoarc; b=HOSkru/bInC7TGAzQH/w1EN+XxHncsEUz08LFhV+YYOQkiS45+lt+LmJoaNKEp6L5feoAAmBbDbYUMd6xrmUa7A7m/J4oiRTxUqLFc/331+Ce5UWMshYSGL+1blKIoPpL095CSkpFW6pm0KnXpYHDMa2r0xCLjViFlW8A5ldz28= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785138414; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2B4vRCYvN1k/6vZ49p509MJyqGmWpNAjeeP8YdsTSTk=; b=jaZ19eRHVZjRJm+PU2zHIrCk+8dzPL6/RRNVz52fX7A1TbyL893UhIdi+G3A9RC/3dCscF1x/8JhyWMKOq5zncTpzmxM9AzBDKQbbt/veTyjCbeZ51CtvxH+Q5OcqFq+uOzgyfq5AzQaS4hK5sZhMYnCXCKM8nZfBVUQTXEPy3k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1785138413330179.2773201907885; Mon, 27 Jul 2026 00:46:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1woG2p-0005ki-O1; Mon, 27 Jul 2026 03:46:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1woG2d-0005iZ-5B for qemu-devel@nongnu.org; Mon, 27 Jul 2026 03:46:28 -0400 Received: from forward103a.mail.yandex.net ([178.154.239.86]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1woG2a-0008W3-VO for qemu-devel@nongnu.org; Mon, 27 Jul 2026 03:46:26 -0400 Received: from mail-nwsmtp-smtp-production-main-95.vla.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-95.vla.yp-c.yandex.net [IPv6:2a02:6b8:c15:340d:0:640:ad51:0]) by forward103a.mail.yandex.net (postfix) with ESMTPS id 1A8E28111B; Mon, 27 Jul 2026 10:46:19 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-95.vla.yp-c.yandex.net (smtp) with ESMTPSA id EkWbDKvd4a60-60H9QhEp; Mon, 27 Jul 2026 10:46:18 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maquefel.me; s=mail; t=1785138378; bh=2B4vRCYvN1k/6vZ49p509MJyqGmWpNAjeeP8YdsTSTk=; h=Cc:In-Reply-To:Message-Id:To:Date:References:From:Subject; b=lLF8Uun40ncTLw3V3wLKCVZUJv5xtv+19aNgjA1KvNRAaoxZgvM57hYlaFYSAKeJY a8W3jZKGUcuuFFCmdtt2Aksp9Me1VxB8RgxSMl5ZP+KP+R56zAFzMx+gyHbqjrmcCJ kGg7xNXxLMMpSqpeoed7o79Fz0GCKr9zeM6lMCQs= Authentication-Results: mail-nwsmtp-smtp-production-main-95.vla.yp-c.yandex.net; dkim=pass header.i=@maquefel.me From: Nikita Shubin Date: Mon, 27 Jul 2026 10:46:19 +0300 Subject: =?utf-8?q?=5BPATCH_v2_1/2=5D_semihosting/arm-compat-semi=3A_Fix_?= =?utf-8?q?auto=E2=80=91strlen_detection_for_32=E2=80=91bit_targets?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260727-fix-sign-extended-32-bit-addresses-v2-1-6d6a01efed8a@maquefel.me> References: <20260727-fix-sign-extended-32-bit-addresses-v2-0-6d6a01efed8a@maquefel.me> In-Reply-To: <20260727-fix-sign-extended-32-bit-addresses-v2-0-6d6a01efed8a@maquefel.me> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Paolo Bonzini , Alistair Francis , Nikita Shubin X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1785138386; l=1607; i=nikita.shubin@maquefel.me; s=20230718; h=from:subject:message-id; bh=BzZSeICm8AayHgBINKwHmwSve//k0o/u7SDe2GO5JJg=; b=5kgZRZDQp3E3Hy/3hIPwV0bgw0jbYJmgK2bx+QG0RljUQvx3wGoNMxtAVlsj7s4J2mSETq1Qo 7nvWhdXQMuWDtbdgTH0B+M45bxAbkAPw4cT9T4jv7p4dripnMSK4jVg X-Developer-Key: i=nikita.shubin@maquefel.me; a=ed25519; pk=vqf5YIUJ7BJv3EJFaNNxWZgGuMgDH6rwufTLflwU9ac= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.86; envelope-from=nikita.shubin@maquefel.me; helo=forward103a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @maquefel.me) X-ZM-MESSAGEID: 1785138417940158500 The switch from target_ulong to uint64_t broke the mechanism of passing -1 (0xffffffff) in arg2 to signal validate_strlen() to compute the string length automatically. For 32=E2=80=91bit semihosting, detect when arg2 is 0xffffffff and replace it with 0xffffffffffffffff. This causes an overflow to zero, restoring the original behavior of automatic length calculation. Fixes: 6dfbf9b6cfe ("semihosting/arm-compat-semi: replace target_ulong") Signed-off-by: Nikita Shubin Acked-by: Alex Benn=C3=A9e --- semihosting/arm-compat-semi.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 5e5f181b90..682349bd51 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -442,6 +442,17 @@ void do_common_semihosting(CPUState *cs) } } else { unlock_user(s, arg0, 0); + /* + * Due to the switch from target_ulong to uint64_t, passing -1 + * as arg2 is no longer possible. + * For 32=E2=80=91bit targets, if arg2 =3D=3D 0xffffffff, set = it + * to 0xffffffffffffffff to trigger overflow so zero strlen + * is passed to validate_strlen(). + */ + if (!is_64bit_semihosting(env) && arg2 =3D=3D (uint32_t)-1) { + arg2 =3D -1; + } + semihost_sys_open(cs, common_semi_cb, arg0, arg2 + 1, gdb_open_modeflags[arg1], 0644); break; --=20 2.52.0 From nobody Mon Sep 28 02:15:47 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1785138428; cv=none; d=zohomail.com; s=zohoarc; b=JrkyMzBqUZEAufBkYlDamw24fqwQOkrLbO9ZdO0tYLWjTMloAuKJSoCyKHfS7zSHgDeXMUQncXJ9CUYM/vjoa/5u0rdHBU8uMw0iiO6mT1df3vXhVGoMLaBVFXBfNCIZPRJwPe0LFRdfaUU5Mm7YVp+KKnZRLey4t5dWW1v7L74= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785138428; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cMbHw4pzvEBKCnXgdnTqO/T7pGUylIp6OYpnQapwn9E=; b=YVLeXslej9FxH1z6ngN3R6wsDerAg5Hv3DBKCCWqhLDd8WNOULt+6Sne5N99uXtSOD9u3l7lQTye01CVJxrecWjuRZUpNiyDZ/UuesC4s9tEt3XQUcn890dIaCZ0YBZCOgC7Ob27TLIKpCqAc9MTUYYHkoYDrPBZy0NKPpnStCM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1785138427150888.2073383775994; Mon, 27 Jul 2026 00:47:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1woG2k-0005jQ-On; Mon, 27 Jul 2026 03:46:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1woG2d-0005ia-89 for qemu-devel@nongnu.org; Mon, 27 Jul 2026 03:46:28 -0400 Received: from forward101a.mail.yandex.net ([178.154.239.84]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1woG2a-0008WF-VU for qemu-devel@nongnu.org; Mon, 27 Jul 2026 03:46:27 -0400 Received: from mail-nwsmtp-smtp-production-main-95.vla.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-95.vla.yp-c.yandex.net [IPv6:2a02:6b8:c15:340d:0:640:ad51:0]) by forward101a.mail.yandex.net (postfix) with ESMTPS id 874C581354; Mon, 27 Jul 2026 10:46:20 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-95.vla.yp-c.yandex.net (smtp) with ESMTPSA id EkWbDKvd4a60-3Dj9bU6Z; Mon, 27 Jul 2026 10:46:19 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maquefel.me; s=mail; t=1785138380; bh=cMbHw4pzvEBKCnXgdnTqO/T7pGUylIp6OYpnQapwn9E=; h=Cc:In-Reply-To:Message-Id:To:Date:References:From:Subject; b=hZwoHzryFRh0iO1N32JJipVICbg/Eq3BPQTC6VekLCg7mG3pc5PN18Z3OQNZqawEq ZKdGJuFnAIpJtogMt/6SZOkax0wUVPjTeJ1x9Pu9Z08NqrEVMLSi2udnxEmSr/BgXc nK0KpbXg4kJLE3sQKLDdod2XjkMzzoPAIrmz7eP4= Authentication-Results: mail-nwsmtp-smtp-production-main-95.vla.yp-c.yandex.net; dkim=pass header.i=@maquefel.me From: Nikita Shubin Date: Mon, 27 Jul 2026 10:46:20 +0300 Subject: [PATCH v2 2/2] tests/tcg/riscv32: Add RISC-V 32-bit semihosting test MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260727-fix-sign-extended-32-bit-addresses-v2-2-6d6a01efed8a@maquefel.me> References: <20260727-fix-sign-extended-32-bit-addresses-v2-0-6d6a01efed8a@maquefel.me> In-Reply-To: <20260727-fix-sign-extended-32-bit-addresses-v2-0-6d6a01efed8a@maquefel.me> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Paolo Bonzini , Alistair Francis , Nikita Shubin X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1785138386; l=5487; i=nikita.shubin@maquefel.me; s=20230718; h=from:subject:message-id; bh=ZnVD92lOi/fe9m39gvTMkikGxOwkymi2O8bIVEe8d2g=; b=ObxnJVKXT50R0QkZ0JJ8aKYk8EAUJXiBoQLHqMGp2WE9lbMf85xQFL61acrP1mEPDe8OW7jBS xM8XrzepBevCNXG87L7xl+zlTO7qDus3oiRr95Sk2FDjn14p2j8W51f X-Developer-Key: i=nikita.shubin@maquefel.me; a=ed25519; pk=vqf5YIUJ7BJv3EJFaNNxWZgGuMgDH6rwufTLflwU9ac= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.84; envelope-from=nikita.shubin@maquefel.me; helo=forward101a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @maquefel.me) X-ZM-MESSAGEID: 1785138430995158500 Extend the TCG test infrastructure to support 32-bit RISC-V (riscv32) system tests. - configure: Add riscv32 to probe_target_compiler() using the same container (debian-all-test-cross) as riscv64, with cross prefix riscv64-linux-gnu- (the compiler can generate 32-bit code with -march=3Drv32imafdch -mabi=3Dilp32d). - tests/tcg/riscv32/: New directory with: * Makefile.softmmu-target =E2=80=93 build rules for 32-bit softmmu tests * semihost.ld =E2=80=93 linker script (same as riscv64, RAM at 0x80000000) * test-semihosting-open.S =E2=80=93 test for SYS_OPEN with auto length (-= 1) The semihosting test validates the fix for sign-extended 32-bit pointers when running riscv32 guests on qemu-system-riscv32. CFLAGS and LDFLAGS are explicitly set for rv32imafdch/ilp32d ABI, and LDFLAGS includes -melf32lriscv to produce 32-bit ELF. Signed-off-by: Nikita Shubin Reviewed-by: Alistair Francis --- configure | 6 +++- tests/tcg/riscv32/Makefile.softmmu-target | 30 +++++++++++++++++ tests/tcg/riscv32/semihost.ld | 24 +++++++++++++ tests/tcg/riscv32/test-semihosting-open.S | 56 +++++++++++++++++++++++++++= ++++ 4 files changed, 115 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 6ddfe4b534..d346e40e10 100755 --- a/configure +++ b/configure @@ -1405,7 +1405,7 @@ probe_target_compiler() { mips) container_hosts=3Dx86_64 ;; ppc) container_hosts=3Dx86_64 ;; ppc64|ppc64le) container_hosts=3Dx86_64 ;; - riscv64) container_hosts=3Dx86_64 ;; + riscv32|riscv64) container_hosts=3Dx86_64 ;; s390x) container_hosts=3Dx86_64 ;; sh4) container_hosts=3Dx86_64 ;; sparc64) container_hosts=3Dx86_64 ;; @@ -1424,6 +1424,10 @@ probe_target_compiler() { container_image=3Ddebian-all-test-cross container_cross_prefix=3Daarch64-linux-gnu- ;; + riscv32) + container_image=3Ddebian-all-test-cross + container_cross_prefix=3Driscv64-linux-gnu- + ;; alpha|hppa|m68k|mips|mipsel|riscv64|sh4|sparc64) container_image=3Ddebian-all-test-cross ;; diff --git a/tests/tcg/riscv32/Makefile.softmmu-target b/tests/tcg/riscv32/= Makefile.softmmu-target new file mode 100644 index 0000000000..eff5b000f0 --- /dev/null +++ b/tests/tcg/riscv32/Makefile.softmmu-target @@ -0,0 +1,30 @@ +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# RISC-V 32-bit system tests +# + +TEST_SRC =3D $(SRC_PATH)/tests/tcg/riscv32 +VPATH +=3D $(TEST_SRC) + +LINK_SCRIPT =3D $(TEST_SRC)/semihost.ld +LDFLAGS =3D -T $(LINK_SCRIPT) +CFLAGS +=3D -g -Og + +%.o: %.S + $(CC) $(CFLAGS) $< -Wa,--noexecstack -c -o $@ +%: %.o $(LINK_SCRIPT) + $(LD) $(LDFLAGS) $< -o $@ + +QEMU_OPTS +=3D -M virt -display none -semihosting -device loader,file=3D +# provide flags for riscv32 as we are using riscv64-linux-gnu- +CFLAGS +=3D -march=3Drv32imafdch -mabi=3Dilp32d +LDFLAGS +=3D -melf32lriscv + +EXTRA_RUNS +=3D run-semihosting-open +run-semihosting-open: test-semihosting-open + $(call run-test, $<, \ + $(QEMU) $(QEMU_OPTS)$<) + +# We don't currently support the multiarch system tests +undefine MULTIARCH_TESTS \ No newline at end of file diff --git a/tests/tcg/riscv32/semihost.ld b/tests/tcg/riscv32/semihost.ld new file mode 100644 index 0000000000..ff3b786481 --- /dev/null +++ b/tests/tcg/riscv32/semihost.ld @@ -0,0 +1,24 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + */ +ENTRY(_start) + +SECTIONS +{ + /* virt machine, RAM starts at 2gb */ + . =3D 0x80000000; + .text : { + *(.text) + } + .rodata : { + *(.rodata) + } + /* align r/w section to next 2mb */ + . =3D ALIGN(1 << 21); + .data : { + *(.data) + } + .bss : { + *(.bss) + } +} diff --git a/tests/tcg/riscv32/test-semihosting-open.S b/tests/tcg/riscv32/= test-semihosting-open.S new file mode 100644 index 0000000000..acbb31c558 --- /dev/null +++ b/tests/tcg/riscv32/test-semihosting-open.S @@ -0,0 +1,56 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + */ +.option norvc +.text +.global _start +_start: + # Argument block for SYS_OPEN (each arg is 4 bytes in RV32) + la a1, open_args + la t0, test_filename + sw t0, 0(a1) # arg0: pointer to filename + li t0, 4 # arg1: "w" (write, create, truncate) + sw t0, 4(a1) + li t0, -1 # arg2: auto length (-1 =3D 0xffffffff) + sw t0, 8(a1) + + # SYS_OPEN semihosting call + li a0, 0x01 + .balign 16 + slli zero, zero, 0x1f + ebreak + srai zero, zero, 0x7 + + # Check result: a0 should be a valid file descriptor (not -1) + li t0, -1 + beq a0, t0, fail + + # Success + li a0, 0 + j exit + +fail: + li a0, 1 + +exit: + # Extended semihosting exit + la a1, semiargs + li t0, 0x20026 # ADP_Stopped_ApplicationExit + sw t0, 0(a1) + sw a0, 4(a1) + li a0, 0x20 # TARGET_SYS_EXIT_EXTENDED + .balign 16 + slli zero, zero, 0x1f + ebreak + srai zero, zero, 0x7 + + j . + +.data +.balign 16 +test_filename: + .string "testfile.txt" +open_args: + .space 12 # 3 * 4 bytes +semiargs: + .space 8 # 2 * 4 bytes --=20 2.52.0