From nobody Sun May 5 13:47:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1606340365; cv=none; d=zohomail.com; s=zohoarc; b=X2gE+ZfMLy/IG1XRjJheWs94UEAgdF50G+66p2i0XnVGDwF161zjAPCNfPefm8bXLCHYTZttt4+eLC6tI5EN030CxSsPJY/Z/PqyuZxhWRwSkPgRpDldXCnglivvre9OnZ4jmKr3Uq1Dp9SyORcJr9b7osWIaMBdiSgxlGmr7iM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606340365; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=7taXbx/UyHGrzPRMAEPOWyi8xiRwRkp7ynKNAjnaM4A=; b=PNbliCwOID2ZIB2caQ2ViemHM7NQjXh9QXinn3lWXenBlR5rrzpTrVkYyxaGXw9MHtPcp5NJS+GFw2XYpk8Ygee9scMy1M+DVyQMOBB4Oec3JgD7PgzZJDIKCsOfzZOME8nIQvqzHsk03yHGPFvsn4MuDexoJKlPmUTxxBWE/Ng= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1606340365716877.6274038814155; Wed, 25 Nov 2020 13:39:25 -0800 (PST) Received: from localhost ([::1]:43128 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ki2VY-0004Xx-KN for importer@patchew.org; Wed, 25 Nov 2020 16:39:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ki2St-0002GV-7Z; Wed, 25 Nov 2020 16:36:39 -0500 Received: from home.keithp.com ([63.227.221.253]:36982 helo=elaine.keithp.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ki2Sp-0001Ba-Dy; Wed, 25 Nov 2020 16:36:39 -0500 Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 238413F2E28A; Wed, 25 Nov 2020 13:36:33 -0800 (PST) Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id MjbXJGeWx0Cg; Wed, 25 Nov 2020 13:36:32 -0800 (PST) Received: from keithp.com (koto.keithp.com [10.0.0.2]) by elaine.keithp.com (Postfix) with ESMTPSA id 9C2873F2E287; Wed, 25 Nov 2020 13:36:31 -0800 (PST) Received: by keithp.com (Postfix, from userid 1000) id 8C00E15821B9; Wed, 25 Nov 2020 13:36:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1606340193; bh=DRJ6/DHicq2mSvhQCrjSykm8dwPaSFkW7Nr657PAZLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ltRYGmdQMPo0ekJr9k9RKUdwE4pwasHuOvPS9Mnn28p0aMe+1Wkop5sJ7UzZq2sU0 6m9FTSYfqI6tpJKnhylr0/4KNcwYsDBi2qVQ0a7agoHnsdfvdhkzIhpyn+3CIb5+V+ /BilTgxQQf/fuAf9FVzSIdIlTm1bqLknpzhSjwdkWCUkH+3hMvZTOCZZ/sU9lbVona l0wkKq1/LUVo8DOvTcgFDlAr4NPSo8RbmXC+9GdRUJkoT0L027sa32XdCh2FhlTwO3 wqnkU9yoeJR5MywK0jz1Y3RffW7QIP4AinjOowqjaqOcIEb+lZ6SbFo3HSeXF1kJIk RfrNwCpXkQg2Q== X-Virus-Scanned: Debian amavisd-new at keithp.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1606340191; bh=DRJ6/DHicq2mSvhQCrjSykm8dwPaSFkW7Nr657PAZLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y9kBG99nG6Rbnwzm8WG13EVYOhkZdQJPQazbHLV3vw+d4KZUPz+XBIp21dA4RAGoX gIILxSocTLZv+rvpMzmWEAL+uZvEVcFoInevg7gw4zkuSGVt3s0nhC8qkc90qIzO+m Vlku7qN16pqXwCItbQT2JWJi0VyldYrzN7N1giC/Ru2qzMhktRsB5l0CQQ03yQojmR 2D0XXqsnaYCiOdGuglsC6tC8T14PW/fuf62bmP8CbnuPioPQ+SF/QOlF0bL79Ou1rs 0xX1llKukjq6KcRLVdy9TehJnLBbv2NEhAQ9AOYPBR6D9zHZIFnOjCrR34iOkQPdI/ T46+7oN3wSeQA== To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alistair Francis , Bastian Koppelmann , Laurent Vivier , Palmer Dabbelt , Peter Maydell , qemu-arm@nongnu.org, qemu-riscv@nongnu.org, Sagar Karandikar , Keith Packard , Alistair Francis Subject: [PATCH 1/8] semihosting: Move ARM semihosting code to shared directories [v3] Date: Wed, 25 Nov 2020 13:36:10 -0800 Message-Id: <20201125213617.2496935-2-keithp@keithp.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201125213617.2496935-1-keithp@keithp.com> References: <20201125213617.2496935-1-keithp@keithp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=63.227.221.253; envelope-from=keithp@keithp.com; helo=elaine.keithp.com 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Keith Packard From: Keith Packard via X-ZohoMail-DKIM: fail (found 2 invalid signatures) Content-Type: text/plain; charset="utf-8" This commit renames two files which provide ARM semihosting support so that they can be shared by other architectures: 1. target/arm/arm-semi.c -> hw/semihosting/common-semi.c 2. linux-user/arm/semihost.c -> linux-user/semihost.c The build system was modified use a new config variable, CONFIG_ARM_COMPATIBLE_SEMIHOSTING, which has been added to the ARM softmmu and linux-user default configs. The contents of the source files has not been changed in this patch. Signed-off-by: Keith Packard Reviewed-by: Alistair Francis ---- v2 Place common-semi.c name in arm_ss, just as arm-semi.c was v3 Create CONFIG_ARM_COMPATIBLE_SEMIHOSTING and assign in arm config files --- default-configs/devices/arm-softmmu.mak | 1 + default-configs/targets/aarch64-linux-user.mak | 1 + default-configs/targets/arm-linux-user.mak | 1 + hw/semihosting/Kconfig | 3 +++ target/arm/arm-semi.c =3D> hw/semihosting/common-semi.c | 0 hw/semihosting/meson.build | 3 +++ linux-user/arm/meson.build | 3 --- linux-user/meson.build | 1 + linux-user/{arm =3D> }/semihost.c | 0 target/arm/meson.build | 2 -- 10 files changed, 10 insertions(+), 5 deletions(-) rename target/arm/arm-semi.c =3D> hw/semihosting/common-semi.c (100%) rename linux-user/{arm =3D> }/semihost.c (100%) diff --git a/default-configs/devices/arm-softmmu.mak b/default-configs/devi= ces/arm-softmmu.mak index 08a32123b4..0500156a0c 100644 --- a/default-configs/devices/arm-softmmu.mak +++ b/default-configs/devices/arm-softmmu.mak @@ -42,4 +42,5 @@ CONFIG_FSL_IMX25=3Dy CONFIG_FSL_IMX7=3Dy CONFIG_FSL_IMX6UL=3Dy CONFIG_SEMIHOSTING=3Dy +CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy CONFIG_ALLWINNER_H3=3Dy diff --git a/default-configs/targets/aarch64-linux-user.mak b/default-confi= gs/targets/aarch64-linux-user.mak index 163c9209f4..4713253709 100644 --- a/default-configs/targets/aarch64-linux-user.mak +++ b/default-configs/targets/aarch64-linux-user.mak @@ -2,3 +2,4 @@ TARGET_ARCH=3Daarch64 TARGET_BASE_ARCH=3Darm TARGET_XML_FILES=3D gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-x= ml/arm-core.xml gdb-xml/arm-vfp.xml gdb-xml/arm-vfp3.xml gdb-xml/arm-neon.x= ml gdb-xml/arm-m-profile.xml TARGET_HAS_BFLT=3Dy +CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy diff --git a/default-configs/targets/arm-linux-user.mak b/default-configs/t= argets/arm-linux-user.mak index c7cd872e86..e741ffd4d3 100644 --- a/default-configs/targets/arm-linux-user.mak +++ b/default-configs/targets/arm-linux-user.mak @@ -3,3 +3,4 @@ TARGET_SYSTBL_ABI=3Dcommon,oabi TARGET_SYSTBL=3Dsyscall.tbl TARGET_XML_FILES=3D gdb-xml/arm-core.xml gdb-xml/arm-vfp.xml gdb-xml/arm-v= fp3.xml gdb-xml/arm-neon.xml gdb-xml/arm-m-profile.xml TARGET_HAS_BFLT=3Dy +CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy diff --git a/hw/semihosting/Kconfig b/hw/semihosting/Kconfig index efe0a30734..4c30dc6b16 100644 --- a/hw/semihosting/Kconfig +++ b/hw/semihosting/Kconfig @@ -1,3 +1,6 @@ =20 config SEMIHOSTING bool + +config ARM_COMPATIBLE_SEMIHOSTING + bool diff --git a/target/arm/arm-semi.c b/hw/semihosting/common-semi.c similarity index 100% rename from target/arm/arm-semi.c rename to hw/semihosting/common-semi.c diff --git a/hw/semihosting/meson.build b/hw/semihosting/meson.build index f40ac574c4..5b4a170270 100644 --- a/hw/semihosting/meson.build +++ b/hw/semihosting/meson.build @@ -2,3 +2,6 @@ specific_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( 'config.c', 'console.c', )) + +specific_ss.add(when: ['CONFIG_ARM_COMPATIBLE_SEMIHOSTING'], + if_true: files('common-semi.c')) diff --git a/linux-user/arm/meson.build b/linux-user/arm/meson.build index 432984b58e..5a93c925cf 100644 --- a/linux-user/arm/meson.build +++ b/linux-user/arm/meson.build @@ -1,6 +1,3 @@ -linux_user_ss.add(when: 'TARGET_AARCH64', if_true: files('semihost.c')) -linux_user_ss.add(when: 'TARGET_ARM', if_true: files('semihost.c')) - subdir('nwfpe') =20 syscall_nr_generators +=3D { diff --git a/linux-user/meson.build b/linux-user/meson.build index 2b94e4ba24..7fe28d659e 100644 --- a/linux-user/meson.build +++ b/linux-user/meson.build @@ -16,6 +16,7 @@ linux_user_ss.add(rt) =20 linux_user_ss.add(when: 'TARGET_HAS_BFLT', if_true: files('flatload.c')) linux_user_ss.add(when: 'TARGET_I386', if_true: files('vm86.c')) +linux_user_ss.add(when: 'CONFIG_ARM_COMPATIBLE_SEMIHOSTING', if_true: file= s('semihost.c')) =20 =20 syscall_nr_generators =3D {} diff --git a/linux-user/arm/semihost.c b/linux-user/semihost.c similarity index 100% rename from linux-user/arm/semihost.c rename to linux-user/semihost.c diff --git a/target/arm/meson.build b/target/arm/meson.build index f5de2a77b8..15b936c101 100644 --- a/target/arm/meson.build +++ b/target/arm/meson.build @@ -32,8 +32,6 @@ arm_ss.add(files( )) arm_ss.add(zlib) =20 -arm_ss.add(when: 'CONFIG_TCG', if_true: files('arm-semi.c')) - arm_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c', 'kvm64.c'), if_fals= e: files('kvm-stub.c')) =20 arm_ss.add(when: 'TARGET_AARCH64', if_true: files( --=20 2.29.2 From nobody Sun May 5 13:47:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1606340346; cv=none; d=zohomail.com; s=zohoarc; b=NXNkjIk9RRq4ixb8gNaG8qXnyVi0B5khpF0Gokb3ncYzC2a1UT/Xq7sYJsVDWaNKMA5ovQ9tpJCNbiT+Y4YU6or7XxpVCWdvyMcLhx9B3T8mqdpL3Wf+NatDoUg61f7o7/6i8xQaNsFPHl0bYLY5L/+4jGgZy8sMbnL+dv4aVTU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606340346; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=zYhbLoFHvffR+zeu8G5I1P0w44KomuuPVnWs9fBrE7w=; b=RuAhauvL15MVEBOrUGD0Kskg+tzlnnVSi96OsRy0h2Rp3fJxonltx69M+LhVBZTu4Fpv8G+6Y4icciOKo8Ei4lgGmVMhSo71Z5dQDs6mJH+XgjKON8Ug7I4MTVyyt4k6U0Knz7H2l6gkaoEmNq1v4UljK5d4QdEtDlUTK571bAE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1606340346667187.43636970190425; Wed, 25 Nov 2020 13:39:06 -0800 (PST) Received: from localhost ([::1]:42570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ki2VE-0004KM-6J for importer@patchew.org; Wed, 25 Nov 2020 16:39:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37082) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ki2St-0002Gd-HY; Wed, 25 Nov 2020 16:36:39 -0500 Received: from home.keithp.com ([63.227.221.253]:36946 helo=elaine.keithp.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ki2Sp-0001BV-CX; Wed, 25 Nov 2020 16:36:39 -0500 Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 547CD3F2E28F; Wed, 25 Nov 2020 13:36:32 -0800 (PST) Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id EmjlyenEMZAv; Wed, 25 Nov 2020 13:36:31 -0800 (PST) Received: from keithp.com (koto.keithp.com [10.0.0.2]) by elaine.keithp.com (Postfix) with ESMTPSA id AB6E33F2E289; Wed, 25 Nov 2020 13:36:31 -0800 (PST) Received: by keithp.com (Postfix, from userid 1000) id 927C815821C2; Wed, 25 Nov 2020 13:36:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1606340192; bh=AFbLQR6RWzoVFFYqQ1dFFvDajaGN0na/ckFbaz80Lac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WCrSzS9qRIXQPZcmQAXf3LP2dBHW0rWVc8K7LWJdfqBAs/dV222rMn4JYDkgoAC0K UEnqOiCricwuG8pqPTF+cg/GH4U3fJLW8osLTx7Wdd7s2IRfom4ODRdJzM5cJpatC7 Vyy//Wmz3xE01MjfYIwnLAmsSRjrE+ERVCdxYRMnO2qnAxdGuVvsEoJ9qT9cT2V7+k tkW6r/Nb/PjxGTkuL8Xp9vXuIRkLbwOT3bAzdNjGkvnEmnMhTbt5ggDwf/AzlxQ8cO 7S3I5kTHQSArGR4yvCIgL/uwrDxlO5Qb75+EPgQEvLNiTGDOJfZ8NF9yxA8yn5OUg/ UeL/C3lR0cELg== X-Virus-Scanned: Debian amavisd-new at keithp.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1606340191; bh=AFbLQR6RWzoVFFYqQ1dFFvDajaGN0na/ckFbaz80Lac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qhRDK/euNVBriu8en1H1ua1P2dCIAejONlaH6voI9I1yCtaMPyd45LW2IKtScgIBw SgPmHXiX2UhaX/lGTOvbqhDnuzK8Z6WTclbJE0bNZT2OT5Z1EeXmNwcv98zO3lFcD0 6PxIO5ITMFORaUpF6CxiFhEnfvwgl4Fq2P7d8gel2Ps+houM2y2jXItdu12pm4KJkP HGyK8f9LMfgjFhe/iUSoxaZWDdWNdMkdrvuqHqtX7X3b1+CRwLFoIW8hBuUPh6ITxQ 0akx6FqFkQJY/DX++MrDrKPClAMCj+wAidjtfIxS/cwsng2Fz8OjIPTe2APdYu3MyN z4G1aAqr8DH0A== To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alistair Francis , Bastian Koppelmann , Laurent Vivier , Palmer Dabbelt , Peter Maydell , qemu-arm@nongnu.org, qemu-riscv@nongnu.org, Sagar Karandikar , Keith Packard , Alistair Francis Subject: [PATCH 2/8] semihosting: Change common-semi API to be architecture-independent Date: Wed, 25 Nov 2020 13:36:11 -0800 Message-Id: <20201125213617.2496935-3-keithp@keithp.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201125213617.2496935-1-keithp@keithp.com> References: <20201125213617.2496935-1-keithp@keithp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=63.227.221.253; envelope-from=keithp@keithp.com; helo=elaine.keithp.com 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Keith Packard From: Keith Packard via X-ZohoMail-DKIM: fail (found 2 invalid signatures) The public API is now defined in hw/semihosting/common-semi.h. do_common_semihosting takes CPUState * instead of CPUARMState *. All internal functions have been renamed common_semi_ instead of arm_semi_ or arm_. Aside from the API change, there are no functional changes in this patch. Signed-off-by: Keith Packard Reviewed-by: Alistair Francis --- hw/semihosting/common-semi.c | 16 ++++++++++------ hw/semihosting/common-semi.h | 36 +++++++++++++++++++++++++++++++++++ linux-user/aarch64/cpu_loop.c | 3 ++- linux-user/arm/cpu_loop.c | 3 ++- target/arm/cpu.h | 8 -------- target/arm/helper.c | 5 +++-- target/arm/m_helper.c | 7 ++++++- 7 files changed, 59 insertions(+), 19 deletions(-) create mode 100644 hw/semihosting/common-semi.h diff --git a/hw/semihosting/common-semi.c b/hw/semihosting/common-semi.c index c892e0e674..cafbe579c7 100644 --- a/hw/semihosting/common-semi.c +++ b/hw/semihosting/common-semi.c @@ -1,10 +1,14 @@ /* - * Arm "Angel" semihosting syscalls + * Semihosting support for systems modeled on the Arm "Angel" + * semihosting syscalls design. * * Copyright (c) 2005, 2007 CodeSourcery. * Copyright (c) 2019 Linaro * Written by Paul Brook. * + * Copyright =C2=A9 2020 by Keith Packard + * Adapted for systems other than ARM, including RISC-V, by Keith Packard + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -372,12 +376,12 @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_= syscall_complete_cb cb, * do anything with its return value, because it is not necessarily * the result of the syscall, but could just be the old value of X0. * The only thing safe to do with this is that the callers of - * do_arm_semihosting() will write it straight back into X0. + * do_common_semihosting() will write it straight back into X0. * (In linux-user mode, the callback will have happened before * gdb_do_syscallv() returns.) * * We should tidy this up so neither this function nor - * do_arm_semihosting() return a value, so the mistake of + * do_common_semihosting() return a value, so the mistake of * doing something with the return value is not possible to make. */ =20 @@ -674,10 +678,10 @@ static const GuestFDFunctions guestfd_fns[] =3D { * leave the register unchanged. We use 0xdeadbeef as the return value * when there isn't a defined return value for the call. */ -target_ulong do_arm_semihosting(CPUARMState *env) +target_ulong do_common_semihosting(CPUState *cs) { - ARMCPU *cpu =3D env_archcpu(env); - CPUState *cs =3D env_cpu(env); + ARMCPU *cpu =3D ARM_CPU(cs); + CPUARMState *env =3D &cpu->env; target_ulong args; target_ulong arg0, arg1, arg2, arg3; char * s; diff --git a/hw/semihosting/common-semi.h b/hw/semihosting/common-semi.h new file mode 100644 index 0000000000..bc53e92c79 --- /dev/null +++ b/hw/semihosting/common-semi.h @@ -0,0 +1,36 @@ +/* + * Semihosting support for systems modeled on the Arm "Angel" + * semihosting syscalls design. + * + * Copyright (c) 2005, 2007 CodeSourcery. + * Copyright (c) 2019 Linaro + * Written by Paul Brook. + * + * Copyright =C2=A9 2020 by Keith Packard + * Adapted for systems other than ARM, including RISC-V, by Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * + * ARM Semihosting is documented in: + * Semihosting for AArch32 and AArch64 Release 2.0 + * https://static.docs.arm.com/100863/0200/semihosting.pdf + * + */ + +#ifndef COMMON_SEMI_H +#define COMMON_SEMI_H + +target_ulong do_common_semihosting(CPUState *cs); + +#endif /* COMMON_SEMI_H */ diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index bbe9fefca8..42b9c15f53 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -22,6 +22,7 @@ #include "qemu.h" #include "cpu_loop-common.h" #include "qemu/guest-random.h" +#include "hw/semihosting/common-semi.h" =20 #define get_user_code_u32(x, gaddr, env) \ ({ abi_long __r =3D get_user_u32((x), (gaddr)); \ @@ -129,7 +130,7 @@ void cpu_loop(CPUARMState *env) queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); break; case EXCP_SEMIHOST: - env->xregs[0] =3D do_arm_semihosting(env); + env->xregs[0] =3D do_common_semihosting(cs); env->pc +=3D 4; break; case EXCP_YIELD: diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c index 3d272b56ef..cadfb7fa43 100644 --- a/linux-user/arm/cpu_loop.c +++ b/linux-user/arm/cpu_loop.c @@ -22,6 +22,7 @@ #include "qemu.h" #include "elf.h" #include "cpu_loop-common.h" +#include "hw/semihosting/common-semi.h" =20 #define get_user_code_u32(x, gaddr, env) \ ({ abi_long __r =3D get_user_u32((x), (gaddr)); \ @@ -421,7 +422,7 @@ void cpu_loop(CPUARMState *env) } break; case EXCP_SEMIHOST: - env->regs[0] =3D do_arm_semihosting(env); + env->regs[0] =3D do_common_semihosting(cs); env->regs[15] +=3D env->thumb ? 2 : 4; break; case EXCP_INTERRUPT: diff --git a/target/arm/cpu.h b/target/arm/cpu.h index e5514c8286..55f3b7d3e1 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -1068,14 +1068,6 @@ static inline void aarch64_sve_change_el(CPUARMState= *env, int o, static inline void aarch64_add_sve_properties(Object *obj) { } #endif =20 -#if !defined(CONFIG_TCG) -static inline target_ulong do_arm_semihosting(CPUARMState *env) -{ - g_assert_not_reached(); -} -#else -target_ulong do_arm_semihosting(CPUARMState *env); -#endif void aarch64_sync_32_to_64(CPUARMState *env); void aarch64_sync_64_to_32(CPUARMState *env); =20 diff --git a/target/arm/helper.c b/target/arm/helper.c index 38cd35c049..a5e94f1e33 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -34,6 +34,7 @@ #ifdef CONFIG_TCG #include "arm_ldst.h" #include "exec/cpu_ldst.h" +#include "hw/semihosting/common-semi.h" #endif =20 #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */ @@ -9879,13 +9880,13 @@ static void handle_semihosting(CPUState *cs) qemu_log_mask(CPU_LOG_INT, "...handling as semihosting call 0x%" PRIx64 "\n", env->xregs[0]); - env->xregs[0] =3D do_arm_semihosting(env); + env->xregs[0] =3D do_common_semihosting(cs); env->pc +=3D 4; } else { qemu_log_mask(CPU_LOG_INT, "...handling as semihosting call 0x%x\n", env->regs[0]); - env->regs[0] =3D do_arm_semihosting(env); + env->regs[0] =3D do_common_semihosting(cs); env->regs[15] +=3D env->thumb ? 2 : 4; } } diff --git a/target/arm/m_helper.c b/target/arm/m_helper.c index aad01ea012..610ca032a7 100644 --- a/target/arm/m_helper.c +++ b/target/arm/m_helper.c @@ -31,6 +31,7 @@ #ifdef CONFIG_TCG #include "arm_ldst.h" #include "exec/cpu_ldst.h" +#include "hw/semihosting/common-semi.h" #endif =20 static void v7m_msr_xpsr(CPUARMState *env, uint32_t mask, @@ -2188,7 +2189,11 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) qemu_log_mask(CPU_LOG_INT, "...handling as semihosting call 0x%x\n", env->regs[0]); - env->regs[0] =3D do_arm_semihosting(env); +#ifdef CONFIG_TCG + env->regs[0] =3D do_common_semihosting(cs); +#else + g_assert_not_reached(); +#endif env->regs[15] +=3D env->thumb ? 2 : 4; return; case EXCP_BKPT: --=20 2.29.2 From nobody Sun May 5 13:47:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1606340390; cv=none; d=zohomail.com; s=zohoarc; b=L2XytHlT2MFVXTs+7CHtfRv303rr+tWDloT7EOMtFh4NB5fppSUqTWXS+N2rTSWKz6KEN13Tpz3pHSqUkYq/xHX3ifmpbazkC+PSV37gHjiWJIXpCRqaYCejU2ggCeFRMoXsfr8qp74dNhg6J+/7tcO5NrcIuLYEQD/WZR47oRQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606340390; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=L5TjQ18IOIoCzBDTqow86Rim9dAIXr5ah/+P9BNm2RA=; b=acsZpmXVyVpnxnqiGqFwasdAvARhGlxTEiMAdbQ210E3nvSW0qwyg/E2lbVVlP96LcU3/GjmQnX4kP+s3gG8wSAloQwutbyssmJNK0IOmRUlrFtc93HHjC5QyCEhObWJOxbRyHAlOlZY/kuVEpmAE54TIyKwVmv/feJxVUr0H9Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1606340390074983.3091717943574; Wed, 25 Nov 2020 13:39:50 -0800 (PST) Received: from localhost ([::1]:43728 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ki2Vw-0004oT-Ta for importer@patchew.org; Wed, 25 Nov 2020 16:39:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37106) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ki2Su-0002IC-OW; Wed, 25 Nov 2020 16:36:40 -0500 Received: from home.keithp.com ([63.227.221.253]:36966 helo=elaine.keithp.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ki2Sp-0001BX-DJ; Wed, 25 Nov 2020 16:36:40 -0500 Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id AABDE3F2E289; Wed, 25 Nov 2020 13:36:32 -0800 (PST) Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 79cJlgFUYwvL; Wed, 25 Nov 2020 13:36:31 -0800 (PST) Received: from keithp.com (koto.keithp.com [10.0.0.2]) by elaine.keithp.com (Postfix) with ESMTPSA id AF2B93F2E28A; Wed, 25 Nov 2020 13:36:31 -0800 (PST) Received: by keithp.com (Postfix, from userid 1000) id 9747615821C3; Wed, 25 Nov 2020 13:36:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1606340192; bh=ZcXlwa7XIz0/oZo3qNYopXkAok8zNwIqAvRbvnXi2fU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KkBPZhIUlmvxjuJ3HMbOkZdwLroF4rORHxZFpVOFWpMJmDbgJPV2qrBoItR2YooFD M9nKUP8U50Fvb27oQYU2H3AEiwDiCpv7ci8o8Fw+ot93jDhy/H9Y3tQxSS+UoDpeAQ jgnt29RE846M6E1db4/rJC170/8t2ZCLZxVzgKRimLlBdGB6d1meqwJ/zwuFQEDKx3 hN0hB4/7nqtUGytEUlH3kEarlYqb7wN3h7qsvEcmxcYlIqa7Y6EeTX4dUzfHbCDU9u 5mWkZ2eyZ4JEI0XtEHKEmYf5O6Aix80Gir/Oq8Mhl/WOmcHmT139MURasaAwEf/Aom +ncbP2nAHnZHQ== X-Virus-Scanned: Debian amavisd-new at keithp.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1606340191; bh=ZcXlwa7XIz0/oZo3qNYopXkAok8zNwIqAvRbvnXi2fU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mCu/ba8ITinglcLxPc2IWF/sv/+35OBbmhNofZ0zAbFAFUWEZkp/cafbRi9GSND2t MnqDvtuibbX4TCOH++LL8ZlfkHqfdmW/7/QYjev7SzayH5Q4pEeZVWfuh0R8smMCQu +LeX37N4Ra0FNWshodRKNzXCRIN3vk1e3nNf5+dTRlbR6QFPpC7O/Y/FNHDdTMIcd6 r6oy3uS8PCfsCdWsKT/5wROBG3b2XtEmCbr8naKpRlzoPskTzwFRbJqc0AO6gtzYwu dDAn2RONeKRdjlA/804mwSwmembIuH8KUUyViVt5WgkMfPbRoiHZH/hucd3HPObmok 86oHc8vQSIWMQ== To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alistair Francis , Bastian Koppelmann , Laurent Vivier , Palmer Dabbelt , Peter Maydell , qemu-arm@nongnu.org, qemu-riscv@nongnu.org, Sagar Karandikar , Keith Packard , Alistair Francis Subject: [PATCH 3/8] semihosting: Change internal common-semi interfaces to use CPUState * [v2] Date: Wed, 25 Nov 2020 13:36:12 -0800 Message-Id: <20201125213617.2496935-4-keithp@keithp.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201125213617.2496935-1-keithp@keithp.com> References: <20201125213617.2496935-1-keithp@keithp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=63.227.221.253; envelope-from=keithp@keithp.com; helo=elaine.keithp.com 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Keith Packard From: Keith Packard via X-ZohoMail-DKIM: fail (found 2 invalid signatures) Content-Type: text/plain; charset="utf-8" This makes all of the internal interfaces architecture-independent and renames the internal functions to use the 'common_semi' prefix instead of 'arm' or 'arm_semi'. To do this, some new architecture-specific internal helper functions were created: static inline target_ulong common_semi_arg(CPUState *cs, int argno) Returns the argno'th semihosting argument, where argno can be either 0 or 1. static inline void common_semi_set_ret(CPUState *cs, target_ulong ret) Sets the semihosting return value. static inline bool common_semi_sys_exit_extended(CPUState *cs, int nr) This detects whether the specified semihosting call, which is either TARGET_SYS_EXIT or TARGET_SYS_EXIT_EXTENDED should be executed using the TARGET_SYS_EXIT_EXTENDED semantics. static inline target_ulong common_semi_rambase(CPUState *cs) Returns the base of RAM region used for heap and stack. This is used to construct plausible values for the SYS_HEAPINFO call. In addition, several existing functions have been changed to flag areas of code which are architecture specific: static target_ulong common_semi_flen_buf(CPUState *cs) Returns the current stack pointer minus 64, which is where a stat structure will be placed on the stack #define GET_ARG(n) This fetches arguments from the semihosting command's argument block. The address of this is available implicitly through the local 'args' variable. This is *mostly* architecture independent, but does depend on the current ABI's notion of the size of a 'long' parameter, which may need run-time checks (as it does on AARCH64) #define SET_ARG(n, val) This mirrors GET_ARG and stores data back into the argument block. Signed-off-by: Keith Packard Reviewed-by: Alistair Francis ---- v2: Add common_semi_rambase hook to get memory address for SYS_HEAPINFO call. --- hw/semihosting/common-semi.c | 350 ++++++++++++++++++----------------- 1 file changed, 185 insertions(+), 165 deletions(-) diff --git a/hw/semihosting/common-semi.c b/hw/semihosting/common-semi.c index cafbe579c7..27bdfd0e83 100644 --- a/hw/semihosting/common-semi.c +++ b/hw/semihosting/common-semi.c @@ -32,15 +32,15 @@ #include "cpu.h" #include "hw/semihosting/semihost.h" #include "hw/semihosting/console.h" +#include "hw/semihosting/common-semi.h" #include "qemu/log.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" =20 -#define ARM_ANGEL_HEAP_SIZE (128 * 1024 * 1024) +#define COMMON_SEMI_HEAP_SIZE (128 * 1024 * 1024) #else #include "exec/gdbstub.h" #include "qemu/cutils.h" -#include "hw/arm/boot.h" #endif =20 #define TARGET_SYS_OPEN 0x01 @@ -133,6 +133,50 @@ typedef struct GuestFD { =20 static GArray *guestfd_array; =20 +#ifdef TARGET_ARM +static inline target_ulong +common_semi_arg(CPUState *cs, int argno) +{ + ARMCPU *cpu =3D ARM_CPU(cs); + CPUARMState *env =3D &cpu->env; + if (is_a64(env)) { + return env->xregs[argno]; + } else { + return env->regs[argno]; + } +} + +static inline void +common_semi_set_ret(CPUState *cs, target_ulong ret) +{ + ARMCPU *cpu =3D ARM_CPU(cs); + CPUARMState *env =3D &cpu->env; + if (is_a64(env)) { + env->xregs[0] =3D ret; + } else { + env->regs[0] =3D ret; + } +} + +static inline bool +common_semi_sys_exit_extended(CPUState *cs, int nr) +{ + return (nr =3D=3D TARGET_SYS_EXIT_EXTENDED || is_a64(cs->env_ptr)); +} + +#ifndef CONFIG_USER_ONLY +#include "hw/arm/boot.h" +static inline target_ulong +common_semi_rambase(CPUState *cs) +{ + CPUArchState *env =3D cs->env_ptr; + const struct arm_boot_info *info =3D env->boot_info; + return info->loader_start; +} +#endif + +#endif /* TARGET_ARM */ + /* * Allocate a new guest file descriptor and return it; if we * couldn't allocate a new fd then return -1. @@ -238,11 +282,10 @@ static target_ulong syscall_err; #include "exec/softmmu-semi.h" #endif =20 -static inline uint32_t set_swi_errno(CPUARMState *env, uint32_t code) +static inline uint32_t set_swi_errno(CPUState *cs, uint32_t code) { if (code =3D=3D (uint32_t)-1) { #ifdef CONFIG_USER_ONLY - CPUState *cs =3D env_cpu(env); TaskState *ts =3D cs->opaque; =20 ts->swi_errno =3D errno; @@ -253,10 +296,9 @@ static inline uint32_t set_swi_errno(CPUARMState *env,= uint32_t code) return code; } =20 -static inline uint32_t get_swi_errno(CPUARMState *env) +static inline uint32_t get_swi_errno(CPUState *cs) { #ifdef CONFIG_USER_ONLY - CPUState *cs =3D env_cpu(env); TaskState *ts =3D cs->opaque; =20 return ts->swi_errno; @@ -265,24 +307,22 @@ static inline uint32_t get_swi_errno(CPUARMState *env) #endif } =20 -static target_ulong arm_semi_syscall_len; +static target_ulong common_semi_syscall_len; =20 -static void arm_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong er= r) { - ARMCPU *cpu =3D ARM_CPU(cs); - CPUARMState *env =3D &cpu->env; - target_ulong reg0 =3D is_a64(env) ? env->xregs[0] : env->regs[0]; + target_ulong reg0 =3D common_semi_arg(cs, 0); =20 if (ret =3D=3D (target_ulong)-1) { errno =3D err; - set_swi_errno(env, -1); + set_swi_errno(cs, -1); reg0 =3D ret; } else { /* Fixup syscalls that use nonstardard return conventions. */ switch (reg0) { case TARGET_SYS_WRITE: case TARGET_SYS_READ: - reg0 =3D arm_semi_syscall_len - ret; + reg0 =3D common_semi_syscall_len - ret; break; case TARGET_SYS_SEEK: reg0 =3D 0; @@ -292,77 +332,66 @@ static void arm_semi_cb(CPUState *cs, target_ulong re= t, target_ulong err) break; } } - if (is_a64(env)) { - env->xregs[0] =3D reg0; - } else { - env->regs[0] =3D reg0; - } + common_semi_set_ret(cs, reg0); } =20 -static target_ulong arm_flen_buf(ARMCPU *cpu) +static target_ulong common_semi_flen_buf(CPUState *cs) { + target_ulong sp; +#ifdef TARGET_ARM /* Return an address in target memory of 64 bytes where the remote * gdb should write its stat struct. (The format of this structure * is defined by GDB's remote protocol and is not target-specific.) * We put this on the guest's stack just below SP. */ + ARMCPU *cpu =3D ARM_CPU(cs); CPUARMState *env =3D &cpu->env; - target_ulong sp; =20 if (is_a64(env)) { sp =3D env->xregs[31]; } else { sp =3D env->regs[13]; } +#endif =20 return sp - 64; } =20 -static void arm_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong = err) +static void +common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) { - ARMCPU *cpu =3D ARM_CPU(cs); - CPUARMState *env =3D &cpu->env; /* The size is always stored in big-endian order, extract the value. We assume the size always fit in 32 bits. */ uint32_t size; - cpu_memory_rw_debug(cs, arm_flen_buf(cpu) + 32, (uint8_t *)&size, 4, 0= ); + cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + 32, + (uint8_t *)&size, 4, 0); size =3D be32_to_cpu(size); - if (is_a64(env)) { - env->xregs[0] =3D size; - } else { - env->regs[0] =3D size; - } + common_semi_set_ret(cs, size); errno =3D err; - set_swi_errno(env, -1); + set_swi_errno(cs, -1); } =20 -static int arm_semi_open_guestfd; +static int common_semi_open_guestfd; =20 -static void arm_semi_open_cb(CPUState *cs, target_ulong ret, target_ulong = err) +static void +common_semi_open_cb(CPUState *cs, target_ulong ret, target_ulong err) { - ARMCPU *cpu =3D ARM_CPU(cs); - CPUARMState *env =3D &cpu->env; if (ret =3D=3D (target_ulong)-1) { errno =3D err; - set_swi_errno(env, -1); - dealloc_guestfd(arm_semi_open_guestfd); + set_swi_errno(cs, -1); + dealloc_guestfd(common_semi_open_guestfd); } else { - associate_guestfd(arm_semi_open_guestfd, ret); - ret =3D arm_semi_open_guestfd; - } - - if (is_a64(env)) { - env->xregs[0] =3D ret; - } else { - env->regs[0] =3D ret; + associate_guestfd(common_semi_open_guestfd, ret); + ret =3D common_semi_open_guestfd; } + common_semi_set_ret(cs, ret); } =20 -static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_syscall_complete_cb c= b, - const char *fmt, ...) +static target_ulong +common_semi_gdb_syscall(CPUState *cs, gdb_syscall_complete_cb cb, + const char *fmt, ...) { va_list va; - CPUARMState *env =3D &cpu->env; =20 va_start(va, fmt); gdb_do_syscallv(cb, fmt, va); @@ -385,7 +414,7 @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_sy= scall_complete_cb cb, * doing something with the return value is not possible to make. */ =20 - return is_a64(env) ? env->xregs[0] : env->regs[0]; + return common_semi_arg(cs, 0); } =20 /* @@ -394,20 +423,18 @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_= syscall_complete_cb cb, * do the work and return the required return value for the guest, * setting the guest errno if appropriate. */ -typedef uint32_t sys_closefn(ARMCPU *cpu, GuestFD *gf); -typedef uint32_t sys_writefn(ARMCPU *cpu, GuestFD *gf, +typedef uint32_t sys_closefn(CPUState *cs, GuestFD *gf); +typedef uint32_t sys_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len); -typedef uint32_t sys_readfn(ARMCPU *cpu, GuestFD *gf, +typedef uint32_t sys_readfn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len); -typedef uint32_t sys_isattyfn(ARMCPU *cpu, GuestFD *gf); -typedef uint32_t sys_seekfn(ARMCPU *cpu, GuestFD *gf, +typedef uint32_t sys_isattyfn(CPUState *cs, GuestFD *gf); +typedef uint32_t sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); -typedef uint32_t sys_flenfn(ARMCPU *cpu, GuestFD *gf); +typedef uint32_t sys_flenfn(CPUState *cs, GuestFD *gf); =20 -static uint32_t host_closefn(ARMCPU *cpu, GuestFD *gf) +static uint32_t host_closefn(CPUState *cs, GuestFD *gf) { - CPUARMState *env =3D &cpu->env; - /* * Only close the underlying host fd if it's one we opened on behalf * of the guest in SYS_OPEN. @@ -417,20 +444,21 @@ static uint32_t host_closefn(ARMCPU *cpu, GuestFD *gf) gf->hostfd =3D=3D STDERR_FILENO) { return 0; } - return set_swi_errno(env, close(gf->hostfd)); + return set_swi_errno(cs, close(gf->hostfd)); } =20 -static uint32_t host_writefn(ARMCPU *cpu, GuestFD *gf, +static uint32_t host_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { + CPUArchState *env =3D cs->env_ptr; uint32_t ret; - CPUARMState *env =3D &cpu->env; char *s =3D lock_user(VERIFY_READ, buf, len, 1); + (void) env; /* Used in arm softmmu lock_user implicitly */ if (!s) { /* Return bytes not written on error */ return len; } - ret =3D set_swi_errno(env, write(gf->hostfd, s, len)); + ret =3D set_swi_errno(cs, write(gf->hostfd, s, len)); unlock_user(s, buf, 0); if (ret =3D=3D (uint32_t)-1) { ret =3D 0; @@ -439,18 +467,19 @@ static uint32_t host_writefn(ARMCPU *cpu, GuestFD *gf, return len - ret; } =20 -static uint32_t host_readfn(ARMCPU *cpu, GuestFD *gf, +static uint32_t host_readfn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { + CPUArchState *env =3D cs->env_ptr; uint32_t ret; - CPUARMState *env =3D &cpu->env; char *s =3D lock_user(VERIFY_WRITE, buf, len, 0); + (void) env; /* Used in arm softmmu lock_user implicitly */ if (!s) { /* return bytes not read */ return len; } do { - ret =3D set_swi_errno(env, read(gf->hostfd, s, len)); + ret =3D set_swi_errno(cs, read(gf->hostfd, s, len)); } while (ret =3D=3D -1 && errno =3D=3D EINTR); unlock_user(s, buf, len); if (ret =3D=3D (uint32_t)-1) { @@ -460,68 +489,66 @@ static uint32_t host_readfn(ARMCPU *cpu, GuestFD *gf, return len - ret; } =20 -static uint32_t host_isattyfn(ARMCPU *cpu, GuestFD *gf) +static uint32_t host_isattyfn(CPUState *cs, GuestFD *gf) { return isatty(gf->hostfd); } =20 -static uint32_t host_seekfn(ARMCPU *cpu, GuestFD *gf, target_ulong offset) +static uint32_t host_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) { - CPUARMState *env =3D &cpu->env; - uint32_t ret =3D set_swi_errno(env, lseek(gf->hostfd, offset, SEEK_SET= )); + uint32_t ret =3D set_swi_errno(cs, lseek(gf->hostfd, offset, SEEK_SET)= ); if (ret =3D=3D (uint32_t)-1) { return -1; } return 0; } =20 -static uint32_t host_flenfn(ARMCPU *cpu, GuestFD *gf) +static uint32_t host_flenfn(CPUState *cs, GuestFD *gf) { - CPUARMState *env =3D &cpu->env; struct stat buf; - uint32_t ret =3D set_swi_errno(env, fstat(gf->hostfd, &buf)); + uint32_t ret =3D set_swi_errno(cs, fstat(gf->hostfd, &buf)); if (ret =3D=3D (uint32_t)-1) { return -1; } return buf.st_size; } =20 -static uint32_t gdb_closefn(ARMCPU *cpu, GuestFD *gf) +static uint32_t gdb_closefn(CPUState *cs, GuestFD *gf) { - return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd); + return common_semi_gdb_syscall(cs, common_semi_cb, "close,%x", gf->hos= tfd); } =20 -static uint32_t gdb_writefn(ARMCPU *cpu, GuestFD *gf, +static uint32_t gdb_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { - arm_semi_syscall_len =3D len; - return arm_gdb_syscall(cpu, arm_semi_cb, "write,%x,%x,%x", - gf->hostfd, buf, len); + common_semi_syscall_len =3D len; + return common_semi_gdb_syscall(cs, common_semi_cb, "write,%x,%x,%x", + gf->hostfd, buf, len); } =20 -static uint32_t gdb_readfn(ARMCPU *cpu, GuestFD *gf, +static uint32_t gdb_readfn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { - arm_semi_syscall_len =3D len; - return arm_gdb_syscall(cpu, arm_semi_cb, "read,%x,%x,%x", - gf->hostfd, buf, len); + common_semi_syscall_len =3D len; + return common_semi_gdb_syscall(cs, common_semi_cb, "read,%x,%x,%x", + gf->hostfd, buf, len); } =20 -static uint32_t gdb_isattyfn(ARMCPU *cpu, GuestFD *gf) +static uint32_t gdb_isattyfn(CPUState *cs, GuestFD *gf) { - return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->hostfd); + return common_semi_gdb_syscall(cs, common_semi_cb, "isatty,%x", gf->ho= stfd); } =20 -static uint32_t gdb_seekfn(ARMCPU *cpu, GuestFD *gf, target_ulong offset) +static uint32_t gdb_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) { - return arm_gdb_syscall(cpu, arm_semi_cb, "lseek,%x,%x,0", - gf->hostfd, offset); + return common_semi_gdb_syscall(cs, common_semi_cb, "lseek,%x,%x,0", + gf->hostfd, offset); } =20 -static uint32_t gdb_flenfn(ARMCPU *cpu, GuestFD *gf) +static uint32_t gdb_flenfn(CPUState *cs, GuestFD *gf) { - return arm_gdb_syscall(cpu, arm_semi_flen_cb, "fstat,%x,%x", - gf->hostfd, arm_flen_buf(cpu)); + return common_semi_gdb_syscall(cs, common_semi_flen_cb, "fstat,%x,%x", + gf->hostfd, common_semi_flen_buf(cs)); } =20 #define SHFB_MAGIC_0 0x53 @@ -550,31 +577,29 @@ static void init_featurefile_guestfd(int guestfd) gf->featurefile_offset =3D 0; } =20 -static uint32_t featurefile_closefn(ARMCPU *cpu, GuestFD *gf) +static uint32_t featurefile_closefn(CPUState *cs, GuestFD *gf) { /* Nothing to do */ return 0; } =20 -static uint32_t featurefile_writefn(ARMCPU *cpu, GuestFD *gf, +static uint32_t featurefile_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { /* This fd can never be open for writing */ - CPUARMState *env =3D &cpu->env; =20 errno =3D EBADF; - return set_swi_errno(env, -1); + return set_swi_errno(cs, -1); } =20 -static uint32_t featurefile_readfn(ARMCPU *cpu, GuestFD *gf, +static uint32_t featurefile_readfn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { + CPUArchState *env =3D cs->env_ptr; uint32_t i; -#ifndef CONFIG_USER_ONLY - CPUARMState *env =3D &cpu->env; -#endif char *s; =20 + (void) env; /* Used in arm softmmu lock_user implicitly */ s =3D lock_user(VERIFY_WRITE, buf, len, 0); if (!s) { return len; @@ -594,19 +619,19 @@ static uint32_t featurefile_readfn(ARMCPU *cpu, Guest= FD *gf, return len - i; } =20 -static uint32_t featurefile_isattyfn(ARMCPU *cpu, GuestFD *gf) +static uint32_t featurefile_isattyfn(CPUState *cs, GuestFD *gf) { return 0; } =20 -static uint32_t featurefile_seekfn(ARMCPU *cpu, GuestFD *gf, +static uint32_t featurefile_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) { gf->featurefile_offset =3D offset; return 0; } =20 -static uint32_t featurefile_flenfn(ARMCPU *cpu, GuestFD *gf) +static uint32_t featurefile_flenfn(CPUState *cs, GuestFD *gf) { return sizeof(featurefile_data); } @@ -650,16 +675,17 @@ static const GuestFDFunctions guestfd_fns[] =3D { /* Read the input value from the argument block; fail the semihosting * call if the memory read fails. */ +#ifdef TARGET_ARM #define GET_ARG(n) do { \ if (is_a64(env)) { \ if (get_user_u64(arg ## n, args + (n) * 8)) { \ errno =3D EFAULT; \ - return set_swi_errno(env, -1); \ + return set_swi_errno(cs, -1); \ } \ } else { \ if (get_user_u32(arg ## n, args + (n) * 4)) { \ errno =3D EFAULT; \ - return set_swi_errno(env, -1); \ + return set_swi_errno(cs, -1); \ } \ } \ } while (0) @@ -668,6 +694,7 @@ static const GuestFDFunctions guestfd_fns[] =3D { (is_a64(env) ? \ put_user_u64(val, args + (n) * 8) : \ put_user_u32(val, args + (n) * 4)) +#endif =20 /* * Do a semihosting call. @@ -680,8 +707,7 @@ static const GuestFDFunctions guestfd_fns[] =3D { */ target_ulong do_common_semihosting(CPUState *cs) { - ARMCPU *cpu =3D ARM_CPU(cs); - CPUARMState *env =3D &cpu->env; + CPUArchState *env =3D cs->env_ptr; target_ulong args; target_ulong arg0, arg1, arg2, arg3; char * s; @@ -690,14 +716,9 @@ target_ulong do_common_semihosting(CPUState *cs) uint32_t len; GuestFD *gf; =20 - if (is_a64(env)) { - /* Note that the syscall number is in W0, not X0 */ - nr =3D env->xregs[0] & 0xffffffffU; - args =3D env->xregs[1]; - } else { - nr =3D env->regs[0]; - args =3D env->regs[1]; - } + (void) env; /* Used implicitly by arm lock_user macro */ + nr =3D common_semi_arg(cs, 0) & 0xffffffffU; + args =3D common_semi_arg(cs, 1); =20 switch (nr) { case TARGET_SYS_OPEN: @@ -710,19 +731,19 @@ target_ulong do_common_semihosting(CPUState *cs) s =3D lock_user_string(arg0); if (!s) { errno =3D EFAULT; - return set_swi_errno(env, -1); + return set_swi_errno(cs, -1); } if (arg1 >=3D 12) { unlock_user(s, arg0, 0); errno =3D EINVAL; - return set_swi_errno(env, -1); + return set_swi_errno(cs, -1); } =20 guestfd =3D alloc_guestfd(); if (guestfd < 0) { unlock_user(s, arg0, 0); errno =3D EMFILE; - return set_swi_errno(env, -1); + return set_swi_errno(cs, -1); } =20 if (strcmp(s, ":tt") =3D=3D 0) { @@ -751,18 +772,19 @@ target_ulong do_common_semihosting(CPUState *cs) if (arg1 !=3D 0 && arg1 !=3D 1) { dealloc_guestfd(guestfd); errno =3D EACCES; - return set_swi_errno(env, -1); + return set_swi_errno(cs, -1); } init_featurefile_guestfd(guestfd); return guestfd; } =20 if (use_gdb_syscalls()) { - arm_semi_open_guestfd =3D guestfd; - ret =3D arm_gdb_syscall(cpu, arm_semi_open_cb, "open,%s,%x,1a4= ", arg0, - (int)arg2 + 1, gdb_open_modeflags[arg1]); + common_semi_open_guestfd =3D guestfd; + ret =3D common_semi_gdb_syscall(cs, common_semi_open_cb, + "open,%s,%x,1a4", arg0, (int)arg= 2 + 1, + gdb_open_modeflags[arg1]); } else { - ret =3D set_swi_errno(env, open(s, open_modeflags[arg1], 0644)= ); + ret =3D set_swi_errno(cs, open(s, open_modeflags[arg1], 0644)); if (ret =3D=3D (uint32_t)-1) { dealloc_guestfd(guestfd); } else { @@ -779,17 +801,17 @@ target_ulong do_common_semihosting(CPUState *cs) gf =3D get_guestfd(arg0); if (!gf) { errno =3D EBADF; - return set_swi_errno(env, -1); + return set_swi_errno(cs, -1); } =20 - ret =3D guestfd_fns[gf->type].closefn(cpu, gf); + ret =3D guestfd_fns[gf->type].closefn(cs, gf); dealloc_guestfd(arg0); return ret; case TARGET_SYS_WRITEC: - qemu_semihosting_console_outc(env, args); + qemu_semihosting_console_outc(cs->env_ptr, args); return 0xdeadbeef; case TARGET_SYS_WRITE0: - return qemu_semihosting_console_outs(env, args); + return qemu_semihosting_console_outs(cs->env_ptr, args); case TARGET_SYS_WRITE: GET_ARG(0); GET_ARG(1); @@ -799,10 +821,10 @@ target_ulong do_common_semihosting(CPUState *cs) gf =3D get_guestfd(arg0); if (!gf) { errno =3D EBADF; - return set_swi_errno(env, -1); + return set_swi_errno(cs, -1); } =20 - return guestfd_fns[gf->type].writefn(cpu, gf, arg1, len); + return guestfd_fns[gf->type].writefn(cs, gf, arg1, len); case TARGET_SYS_READ: GET_ARG(0); GET_ARG(1); @@ -812,22 +834,22 @@ target_ulong do_common_semihosting(CPUState *cs) gf =3D get_guestfd(arg0); if (!gf) { errno =3D EBADF; - return set_swi_errno(env, -1); + return set_swi_errno(cs, -1); } =20 - return guestfd_fns[gf->type].readfn(cpu, gf, arg1, len); + return guestfd_fns[gf->type].readfn(cs, gf, arg1, len); case TARGET_SYS_READC: - return qemu_semihosting_console_inc(env); + return qemu_semihosting_console_inc(cs->env_ptr); case TARGET_SYS_ISTTY: GET_ARG(0); =20 gf =3D get_guestfd(arg0); if (!gf) { errno =3D EBADF; - return set_swi_errno(env, -1); + return set_swi_errno(cs, -1); } =20 - return guestfd_fns[gf->type].isattyfn(cpu, gf); + return guestfd_fns[gf->type].isattyfn(cs, gf); case TARGET_SYS_SEEK: GET_ARG(0); GET_ARG(1); @@ -835,20 +857,20 @@ target_ulong do_common_semihosting(CPUState *cs) gf =3D get_guestfd(arg0); if (!gf) { errno =3D EBADF; - return set_swi_errno(env, -1); + return set_swi_errno(cs, -1); } =20 - return guestfd_fns[gf->type].seekfn(cpu, gf, arg1); + return guestfd_fns[gf->type].seekfn(cs, gf, arg1); case TARGET_SYS_FLEN: GET_ARG(0); =20 gf =3D get_guestfd(arg0); if (!gf) { errno =3D EBADF; - return set_swi_errno(env, -1); + return set_swi_errno(cs, -1); } =20 - return guestfd_fns[gf->type].flenfn(cpu, gf); + return guestfd_fns[gf->type].flenfn(cs, gf); case TARGET_SYS_TMPNAM: qemu_log_mask(LOG_UNIMP, "%s: SYS_TMPNAM not implemented", __func_= _); return -1; @@ -856,15 +878,15 @@ target_ulong do_common_semihosting(CPUState *cs) GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - ret =3D arm_gdb_syscall(cpu, arm_semi_cb, "unlink,%s", - arg0, (int)arg1 + 1); + ret =3D common_semi_gdb_syscall(cs, common_semi_cb, "unlink,%s= ", + arg0, (int)arg1 + 1); } else { s =3D lock_user_string(arg0); if (!s) { errno =3D EFAULT; - return set_swi_errno(env, -1); + return set_swi_errno(cs, -1); } - ret =3D set_swi_errno(env, remove(s)); + ret =3D set_swi_errno(cs, remove(s)); unlock_user(s, arg0, 0); } return ret; @@ -874,17 +896,18 @@ target_ulong do_common_semihosting(CPUState *cs) GET_ARG(2); GET_ARG(3); if (use_gdb_syscalls()) { - return arm_gdb_syscall(cpu, arm_semi_cb, "rename,%s,%s", - arg0, (int)arg1 + 1, arg2, (int)arg3 + = 1); + return common_semi_gdb_syscall(cs, common_semi_cb, "rename,%s,= %s", + arg0, (int)arg1 + 1, arg2, + (int)arg3 + 1); } else { char *s2; s =3D lock_user_string(arg0); s2 =3D lock_user_string(arg2); if (!s || !s2) { errno =3D EFAULT; - ret =3D set_swi_errno(env, -1); + ret =3D set_swi_errno(cs, -1); } else { - ret =3D set_swi_errno(env, rename(s, s2)); + ret =3D set_swi_errno(cs, rename(s, s2)); } if (s2) unlock_user(s2, arg2, 0); @@ -895,25 +918,25 @@ target_ulong do_common_semihosting(CPUState *cs) case TARGET_SYS_CLOCK: return clock() / (CLOCKS_PER_SEC / 100); case TARGET_SYS_TIME: - return set_swi_errno(env, time(NULL)); + return set_swi_errno(cs, time(NULL)); case TARGET_SYS_SYSTEM: GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - return arm_gdb_syscall(cpu, arm_semi_cb, "system,%s", - arg0, (int)arg1 + 1); + return common_semi_gdb_syscall(cs, common_semi_cb, "system,%s", + arg0, (int)arg1 + 1); } else { s =3D lock_user_string(arg0); if (!s) { errno =3D EFAULT; - return set_swi_errno(env, -1); + return set_swi_errno(cs, -1); } - ret =3D set_swi_errno(env, system(s)); + ret =3D set_swi_errno(cs, system(s)); unlock_user(s, arg0, 0); return ret; } case TARGET_SYS_ERRNO: - return get_swi_errno(env); + return get_swi_errno(cs); case TARGET_SYS_GET_CMDLINE: { /* Build a command-line from the original argv. @@ -965,21 +988,21 @@ target_ulong do_common_semihosting(CPUState *cs) if (output_size > input_size) { /* Not enough space to store command-line arguments. */ errno =3D E2BIG; - return set_swi_errno(env, -1); + return set_swi_errno(cs, -1); } =20 /* Adjust the command-line length. */ if (SET_ARG(1, output_size - 1)) { /* Couldn't write back to argument block */ errno =3D EFAULT; - return set_swi_errno(env, -1); + return set_swi_errno(cs, -1); } =20 /* Lock the buffer on the ARM side. */ output_buffer =3D lock_user(VERIFY_WRITE, arg0, output_size, 0= ); if (!output_buffer) { errno =3D EFAULT; - return set_swi_errno(env, -1); + return set_swi_errno(cs, -1); } =20 /* Copy the command-line arguments. */ @@ -995,7 +1018,7 @@ target_ulong do_common_semihosting(CPUState *cs) if (copy_from_user(output_buffer, ts->info->arg_start, output_size)) { errno =3D EFAULT; - status =3D set_swi_errno(env, -1); + status =3D set_swi_errno(cs, -1); goto out; } =20 @@ -1020,8 +1043,7 @@ target_ulong do_common_semihosting(CPUState *cs) #ifdef CONFIG_USER_ONLY TaskState *ts =3D cs->opaque; #else - const struct arm_boot_info *info =3D env->boot_info; - target_ulong rambase =3D info->loader_start; + target_ulong rambase =3D common_semi_rambase(cs); #endif =20 GET_ARG(0); @@ -1035,7 +1057,7 @@ target_ulong do_common_semihosting(CPUState *cs) abi_ulong ret; =20 ts->heap_base =3D do_brk(0); - limit =3D ts->heap_base + ARM_ANGEL_HEAP_SIZE; + limit =3D ts->heap_base + COMMON_SEMI_HEAP_SIZE; /* Try a big heap, and reduce the size if that fails. */ for (;;) { ret =3D do_brk(limit); @@ -1063,23 +1085,19 @@ target_ulong do_common_semihosting(CPUState *cs) for (i =3D 0; i < ARRAY_SIZE(retvals); i++) { bool fail; =20 - if (is_a64(env)) { - fail =3D put_user_u64(retvals[i], arg0 + i * 8); - } else { - fail =3D put_user_u32(retvals[i], arg0 + i * 4); - } + fail =3D SET_ARG(i, retvals[i]); =20 if (fail) { /* Couldn't write back to argument block */ errno =3D EFAULT; - return set_swi_errno(env, -1); + return set_swi_errno(cs, -1); } } return 0; } case TARGET_SYS_EXIT: case TARGET_SYS_EXIT_EXTENDED: - if (nr =3D=3D TARGET_SYS_EXIT_EXTENDED || is_a64(env)) { + if (common_semi_sys_exit_extended(cs, nr)) { /* * The A64 version of SYS_EXIT takes a parameter block, * so the application-exit type can return a subcode which @@ -1104,7 +1122,7 @@ target_ulong do_common_semihosting(CPUState *cs) */ ret =3D (args =3D=3D ADP_Stopped_ApplicationExit) ? 0 : 1; } - gdb_exit(env, ret); + gdb_exit(cs->env_ptr, ret); exit(ret); case TARGET_SYS_SYNCCACHE: /* @@ -1112,9 +1130,11 @@ target_ulong do_common_semihosting(CPUState *cs) * virtual address range. This is a nop for us since we don't * implement caches. This is only present on A64. */ - if (is_a64(env)) { +#ifdef TARGET_ARM + if (is_a64(cs->env_ptr)) { return 0; } +#endif /* fall through -- invalid for A32/T32 */ default: fprintf(stderr, "qemu: Unsupported SemiHosting SWI 0x%02x\n", nr); --=20 2.29.2 From nobody Sun May 5 13:47:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1606340679; cv=none; d=zohomail.com; s=zohoarc; b=JquJw7Hm/bU/uXNoHBQBNhoV9wDW+V13VNCx9bKdbMZahRzkEvf1eCOt1blVQjDwO9A63NpgH8KpOe26U43kWirYZtGuGL7fFHuyXa/ashit+DrKhoWzh/REPz1K1Hho8QMJWSTBebbuw0hZiL3ZU39UytK1gT9ftEdP/6dvuaw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606340679; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=vGYL+yzMLYVHJC3s8eX4nzNsiu+mJjDkko6IjwYkb1A=; b=AaQlO1m+AW6PhKSLWKt+h6VRgBaCzdGEqB7dlxv24hZOgNCuwflCE9HRXHwzLI+g8sN7NC5bq4ytf53150Af5gISxWFnFOOX5tpAf63yN4SOmA43W3vlakkK/9upqkrK7Be/AsbrjB9fIHVFz6sWkiSeujprLqe1FcZe2qGclbQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160634067987891.35091812156679; Wed, 25 Nov 2020 13:44:39 -0800 (PST) Received: from localhost ([::1]:33542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ki2ac-0003n5-JO for importer@patchew.org; Wed, 25 Nov 2020 16:44:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37128) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ki2Sw-0002Kc-2O; Wed, 25 Nov 2020 16:36:45 -0500 Received: from home.keithp.com ([63.227.221.253]:37062 helo=elaine.keithp.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ki2St-0001Cz-AN; Wed, 25 Nov 2020 16:36:41 -0500 Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 959963F2E291; Wed, 25 Nov 2020 13:36:33 -0800 (PST) Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id vPNEEQmJ2HBk; Wed, 25 Nov 2020 13:36:33 -0800 (PST) Received: from keithp.com (koto.keithp.com [10.0.0.2]) by elaine.keithp.com (Postfix) with ESMTPSA id BAC323F2E28B; Wed, 25 Nov 2020 13:36:31 -0800 (PST) Received: by keithp.com (Postfix, from userid 1000) id 9CC4115821C4; Wed, 25 Nov 2020 13:36:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1606340193; bh=J0co6Q1vvgc8Jd0e8SYQj/3vWhrlTCZVfePzl9fHZPs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YL6SMk4Tx+GNfe1/7NISeGih86kPAnHHKLyNGDkffUDURhh6jKVzFmTccYW8t6Xok tVnDcT2XwFSJ2940afIaZoZa69VPhaJoTl5coVJkoJBNSSEImP9TG7gTrxXTGUPpPr cTwxNLk/Ya7+KbVMIQ7SpHLqrN47GRHLiXM2BVMUt5TZTebGGqAX+6UK/0dokKpjPn g410F2SsGqPgQHqa6I2SpQR3KXS6FlzZAC+02OZsx1TROms3c0oCT+QO/9KVHUjqp1 Hv4TI83IFhKnI4MIZpUSLMyOr+yo3bxN1xdjyN7kG3qsAVPMdZko1uI67OA2o22w8U J1GuqSOp92zGw== X-Virus-Scanned: Debian amavisd-new at keithp.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1606340191; bh=J0co6Q1vvgc8Jd0e8SYQj/3vWhrlTCZVfePzl9fHZPs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AybZBxEdusU8xZeG2JNQSQPKtFwQCEt12ZT8pVigybZVDBIx6AGD5wqgPO8TuASEK wUy/i9mXJx9UIsDt1Y3ldIvKkO+ZH2DygPHIU/z/h2XbAxD/u7SpkDcl3rb9F1n8BZ NiDtlKMrssVg7bgZtOF7nySvVa68eEhFoBjb0adFJkdNpayqH2bK4+wyxuPLI2GTc3 /dXhnzI34ApKoezKVwY+d9/oU/B4fdZHt+K7I5p0fo2YVy9LnXQyVTLGlCmWN7axv2 szYqCqqgWILwrezbJopw889KvhEqKan4BQ6YIeRy79eukofAJRD8ywmVDJLsf2fB09 7Jsi37+B3uPoA== To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alistair Francis , Bastian Koppelmann , Laurent Vivier , Palmer Dabbelt , Peter Maydell , qemu-arm@nongnu.org, qemu-riscv@nongnu.org, Sagar Karandikar , Keith Packard Subject: [PATCH 4/8] semihosting: Support SYS_HEAPINFO when env->boot_info is not set Date: Wed, 25 Nov 2020 13:36:13 -0800 Message-Id: <20201125213617.2496935-5-keithp@keithp.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201125213617.2496935-1-keithp@keithp.com> References: <20201125213617.2496935-1-keithp@keithp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=63.227.221.253; envelope-from=keithp@keithp.com; helo=elaine.keithp.com 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Keith Packard From: Keith Packard via X-ZohoMail-DKIM: fail (found 2 invalid signatures) Content-Type: text/plain; charset="utf-8" env->boot_info is only set in some ARM startup paths, so we cannot rely on it to support the SYS_HEAPINFO semihosting function. When not available, fallback to finding a RAM memory region containing the current stack and use the base of that. Signed-off-by: Keith Packard --- hw/semihosting/common-semi.c | 42 +++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/hw/semihosting/common-semi.c b/hw/semihosting/common-semi.c index 27bdfd0e83..ddfa448cc2 100644 --- a/hw/semihosting/common-semi.c +++ b/hw/semihosting/common-semi.c @@ -133,6 +133,35 @@ typedef struct GuestFD { =20 static GArray *guestfd_array; =20 +#ifndef CONFIG_USER_ONLY +#include "exec/address-spaces.h" +/* + * Find the base of a RAM region containing the specified address + */ +static inline hwaddr +common_semi_find_region_base(hwaddr addr) +{ + MemoryRegion *subregion; + + /* + * Find the chunk of R/W memory containing the address. This is + * used for the SYS_HEAPINFO semihosting call, which should + * probably be using information from the loaded application. + */ + QTAILQ_FOREACH(subregion, &get_system_memory()->subregions, + subregions_link) { + if (subregion->ram && !subregion->readonly) { + Int128 top128 =3D int128_add(int128_make64(subregion->addr), + subregion->size); + if (subregion->addr <=3D addr && int128_lt(addr, top128)) { + return subregion->addr; + } + } + } + return 0; +} +#endif + #ifdef TARGET_ARM static inline target_ulong common_semi_arg(CPUState *cs, int argno) @@ -171,7 +200,18 @@ common_semi_rambase(CPUState *cs) { CPUArchState *env =3D cs->env_ptr; const struct arm_boot_info *info =3D env->boot_info; - return info->loader_start; + target_ulong sp; + + if (info) { + return info->loader_start; + } + + if (is_a64(env)) { + sp =3D env->xregs[31]; + } else { + sp =3D env->regs[13]; + } + return common_semi_find_region_base(sp); } #endif =20 --=20 2.29.2 From nobody Sun May 5 13:47:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1606340535; cv=none; d=zohomail.com; s=zohoarc; b=PlbP1ILzclEGOeKPAVHq3M+DxjEGEaj4xvq4MGyRSTT/RAhNo6PqXY1MvaOI9y7Na4r90ZQMKLI9beOix5bH2uwvFJUlKdmenJmVxSrYenX3hVp9rf6q3Uzc9wY9eLz82lupi8j2Ifw9w2Jbb3BPKOeHArGo7AWMTizwkK5Vf6I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606340535; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=vcIJCnbyQs8Zv74P1WMeiJkH03zhuMF7RO38jpcDiOs=; b=WfBmR3mrjI9+YmvwFhov4NUUxHE8DzVl8IiBm0Zt5fPkSWrVT+tsaBINMsq/Peae4jVS8oBKBm89MI5eWfPNR4fr2UwAk9xhY/szYD6+anKW+T4Szw6lV0xYjVRofl+dqSOmVb+his/6vltv7D0gbBFt+pb5ah+xTSe4/M1oz/I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1606340535336219.87268336262161; Wed, 25 Nov 2020 13:42:15 -0800 (PST) Received: from localhost ([::1]:51604 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ki2YI-00085f-4a for importer@patchew.org; Wed, 25 Nov 2020 16:42:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37102) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ki2Su-0002HN-5I; Wed, 25 Nov 2020 16:36:40 -0500 Received: from home.keithp.com ([63.227.221.253]:36996 helo=elaine.keithp.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ki2Sq-0001Bf-52; Wed, 25 Nov 2020 16:36:39 -0500 Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 89F463F2E287; Wed, 25 Nov 2020 13:36:33 -0800 (PST) Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id qw-sEiOuqp2k; Wed, 25 Nov 2020 13:36:32 -0800 (PST) Received: from keithp.com (koto.keithp.com [10.0.0.2]) by elaine.keithp.com (Postfix) with ESMTPSA id BD7F33F2E28C; Wed, 25 Nov 2020 13:36:31 -0800 (PST) Received: by keithp.com (Postfix, from userid 1000) id A4CB615821C5; Wed, 25 Nov 2020 13:36:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1606340193; bh=ucNKh77OzVLNS+gUqg/sKa8VObA3ffyFcmQtQOpJAL0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rhFnNMVkhEJOQ/G1NT7POTePOprhKNysFFopmn+K1uIu70lqsZmimvMpXQ/RzXcYX hJUUsWGNSPRQr2iCAs7D6ZC9EdCqjE5mdjAS69FOX289AFupI4h06HUczU8dXmLSJi fxtAZI3vMEdnC7Z1nMrQRkQ5n3ZwDD4e5M2KMuEEvP31Ww8/ZXQWACrDizzIHTSZhv Gbuvk9InfLVjSFkiGDcGQwTXvWEWbWK1DIkOdfKka8CPweoJr4J7wPwzoiaFEmmnl1 Hr2P71Oc+NteyCzDv5Z8yJngHdTPPQxew1b4yPdtdNHyZRKfIxx8rPjKN2pRtdHnrl QQCpe1al1eMHQ== X-Virus-Scanned: Debian amavisd-new at keithp.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1606340191; bh=ucNKh77OzVLNS+gUqg/sKa8VObA3ffyFcmQtQOpJAL0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SsPwryINOiFi5KhyzLlUW7ZS+i3LsWCB3FW6Sb7Wp5j8FgjUoQRqSC0k2ntQpJyCN ze38eGyHEmsOB2kVDUrXpvnm6JKw2rdiwZGCfn5iNrmSADL1PeKHFlsvr1WoEhORHa RIN0f6CAQsJkkplX7dkJhEbUEZMBPAymljLAchRtHlTSClgt4guAPqMc7PpeR5jkxx 2/dCEAbRWBoHWahf6bxtSj1SiAXqicy9YwZOqm54bJfQKt3J0kfHJrMl93V5aYk3ua NZs9PgNG5duwCp0c810jO1ykOyc7uosA6tZEU1kPuEin5NlVRRlCYm78H1sAc/xZXz DxLxX5hXZ3oDQ== To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alistair Francis , Bastian Koppelmann , Laurent Vivier , Palmer Dabbelt , Peter Maydell , qemu-arm@nongnu.org, qemu-riscv@nongnu.org, Sagar Karandikar , Keith Packard Subject: [PATCH 5/8] riscv: Add semihosting support [v13] Date: Wed, 25 Nov 2020 13:36:14 -0800 Message-Id: <20201125213617.2496935-6-keithp@keithp.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201125213617.2496935-1-keithp@keithp.com> References: <20201125213617.2496935-1-keithp@keithp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=63.227.221.253; envelope-from=keithp@keithp.com; helo=elaine.keithp.com 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Keith Packard From: Keith Packard via X-ZohoMail-DKIM: fail (found 2 invalid signatures) Content-Type: text/plain; charset="utf-8" Adapt the arm semihosting support code for RISCV. This implementation is based on the standard for RISC-V semihosting version 0.2 as documented in https://github.com/riscv/riscv-semihosting-spec/releases/tag/0.2 Signed-off-by: Keith Packard Reviewed-by: Keith Packard --- v2: Update PC after exception is handled to follow change in the ARM version for SYS_READC v3: Disallow semihosting in user mode; report a regular breakpoint in that case. v4: Fix errors reported by checkpatch v5: Reference current RISC-V semihosting specification v6: Add support for semihosting in riscv64-linux-user and riscv32-linux-user v7: Add meson build support v8: Fix errors reported by checkpatch that crept in. v9: Changes suggested by Alistair Francis : Don't add me to the MAINTAINERS file. Remove duplicate #include in target/riscv/cpu.h Reference RISC-V semihosting spec in target/riscv/riscv-semi.c v10: Use common semihosting implementation instead of a separate copy. Make sure addresses of the three breakpoint-signaling instructions all lie within the same page. Change suggested by Richard Henderson v11: Use CONFIG_ARM_COMPATIBLE_SEMIHOSTING v12: Fix bug in SYS_EXIT support on rv64 v13: Add common_semi_rambase implementation. This locates the memory region containing the stack and uses the base of that. Fix SET_ARG and GET_ARG on rv64 targets to operate on 64-bit values rather than 32-bit. Put_user_ual/get_user_ual are confusingly defined by softmmu-semi.h as being equivalent to put_user_u32/get_user_u32. --- default-configs/devices/riscv32-softmmu.mak | 2 + default-configs/devices/riscv64-softmmu.mak | 2 + .../targets/riscv32-linux-user.mak | 1 + .../targets/riscv64-linux-user.mak | 1 + hw/semihosting/common-semi.c | 82 ++++++++++++++++++- hw/semihosting/common-semi.h | 5 +- linux-user/qemu.h | 4 +- linux-user/semihost.c | 8 +- qemu-options.hx | 10 ++- target/riscv/cpu_bits.h | 1 + target/riscv/cpu_helper.c | 10 +++ .../riscv/insn_trans/trans_privileged.c.inc | 37 ++++++++- target/riscv/translate.c | 11 +++ 13 files changed, 162 insertions(+), 12 deletions(-) diff --git a/default-configs/devices/riscv32-softmmu.mak b/default-configs/= devices/riscv32-softmmu.mak index 94a236c9c2..d847bd5692 100644 --- a/default-configs/devices/riscv32-softmmu.mak +++ b/default-configs/devices/riscv32-softmmu.mak @@ -3,6 +3,8 @@ # Uncomment the following lines to disable these optional devices: # #CONFIG_PCI_DEVICES=3Dn +CONFIG_SEMIHOSTING=3Dy +CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy =20 # Boards: # diff --git a/default-configs/devices/riscv64-softmmu.mak b/default-configs/= devices/riscv64-softmmu.mak index 76b6195648..d5eec75f05 100644 --- a/default-configs/devices/riscv64-softmmu.mak +++ b/default-configs/devices/riscv64-softmmu.mak @@ -3,6 +3,8 @@ # Uncomment the following lines to disable these optional devices: # #CONFIG_PCI_DEVICES=3Dn +CONFIG_SEMIHOSTING=3Dy +CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy =20 # Boards: # diff --git a/default-configs/targets/riscv32-linux-user.mak b/default-confi= gs/targets/riscv32-linux-user.mak index dfb259e8aa..6a9d1b1bc1 100644 --- a/default-configs/targets/riscv32-linux-user.mak +++ b/default-configs/targets/riscv32-linux-user.mak @@ -2,3 +2,4 @@ TARGET_ARCH=3Driscv32 TARGET_BASE_ARCH=3Driscv TARGET_ABI_DIR=3Driscv TARGET_XML_FILES=3D gdb-xml/riscv-32bit-cpu.xml gdb-xml/riscv-32bit-fpu.xm= l gdb-xml/riscv-64bit-fpu.xml gdb-xml/riscv-32bit-csr.xml gdb-xml/riscv-32b= it-virtual.xml +CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy diff --git a/default-configs/targets/riscv64-linux-user.mak b/default-confi= gs/targets/riscv64-linux-user.mak index b13895f3b0..0a92849a1b 100644 --- a/default-configs/targets/riscv64-linux-user.mak +++ b/default-configs/targets/riscv64-linux-user.mak @@ -2,3 +2,4 @@ TARGET_ARCH=3Driscv64 TARGET_BASE_ARCH=3Driscv TARGET_ABI_DIR=3Driscv TARGET_XML_FILES=3D gdb-xml/riscv-64bit-cpu.xml gdb-xml/riscv-32bit-fpu.xm= l gdb-xml/riscv-64bit-fpu.xml gdb-xml/riscv-64bit-csr.xml gdb-xml/riscv-64b= it-virtual.xml +CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy diff --git a/hw/semihosting/common-semi.c b/hw/semihosting/common-semi.c index ddfa448cc2..2b6a3fd9fd 100644 --- a/hw/semihosting/common-semi.c +++ b/hw/semihosting/common-semi.c @@ -1,6 +1,6 @@ /* * Semihosting support for systems modeled on the Arm "Angel" - * semihosting syscalls design. + * semihosting syscalls design. This includes Arm and RISC-V processors * * Copyright (c) 2005, 2007 CodeSourcery. * Copyright (c) 2019 Linaro @@ -25,6 +25,10 @@ * ARM Semihosting is documented in: * Semihosting for AArch32 and AArch64 Release 2.0 * https://static.docs.arm.com/100863/0200/semihosting.pdf + * + * RISC-V Semihosting is documented in: + * RISC-V Semihosting + * https://github.com/riscv/riscv-semihosting-spec/blob/main/riscv-sem= ihosting-spec.adoc */ =20 #include "qemu/osdep.h" @@ -217,6 +221,42 @@ common_semi_rambase(CPUState *cs) =20 #endif /* TARGET_ARM */ =20 +#ifdef TARGET_RISCV +static inline target_ulong +common_semi_arg(CPUState *cs, int argno) +{ + RISCVCPU *cpu =3D RISCV_CPU(cs); + CPURISCVState *env =3D &cpu->env; + return env->gpr[xA0 + argno]; +} + +static inline void +common_semi_set_ret(CPUState *cs, target_ulong ret) +{ + RISCVCPU *cpu =3D RISCV_CPU(cs); + CPURISCVState *env =3D &cpu->env; + env->gpr[xA0] =3D ret; +} + +static inline bool +common_semi_sys_exit_extended(CPUState *cs, int nr) +{ + return (nr =3D=3D TARGET_SYS_EXIT_EXTENDED || sizeof(target_ulong) =3D= =3D 8); +} + +#ifndef CONFIG_USER_ONLY + +static inline target_ulong +common_semi_rambase(CPUState *cs) +{ + RISCVCPU *cpu =3D RISCV_CPU(cs); + CPURISCVState *env =3D &cpu->env; + return common_semi_find_region_base(env->gpr[xSP]); +} +#endif + +#endif + /* * Allocate a new guest file descriptor and return it; if we * couldn't allocate a new fd then return -1. @@ -393,6 +433,12 @@ static target_ulong common_semi_flen_buf(CPUState *cs) sp =3D env->regs[13]; } #endif +#ifdef TARGET_RISCV + RISCVCPU *cpu =3D RISCV_CPU(cs); + CPURISCVState *env =3D &cpu->env; + + sp =3D env->gpr[xSP]; +#endif =20 return sp - 64; } @@ -736,6 +782,37 @@ static const GuestFDFunctions guestfd_fns[] =3D { put_user_u32(val, args + (n) * 4)) #endif =20 +#ifdef TARGET_RISCV + +/* + * get_user_ual is defined as get_user_u32 in softmmu-semi.h, + * we need a macro that fetches a target_ulong + */ +#define get_user_utl(arg, p) \ + ((sizeof(target_ulong) =3D=3D 8) ? \ + get_user_u64(arg, p) : \ + get_user_u32(arg, p)) + +/* + * put_user_ual is defined as put_user_u32 in softmmu-semi.h, + * we need a macro that stores a target_ulong + */ +#define put_user_utl(arg, p) \ + ((sizeof(target_ulong) =3D=3D 8) ? \ + put_user_u64(arg, p) : \ + put_user_u32(arg, p)) + +#define GET_ARG(n) do { \ + if (get_user_utl(arg ## n, args + (n) * sizeof(target_ulong))) { \ + errno =3D EFAULT; \ + return set_swi_errno(cs, -1); \ + } \ + } while (0) + +#define SET_ARG(n, val) \ + put_user_utl(val, args + (n) * sizeof(target_ulong)) +#endif + /* * Do a semihosting call. * @@ -1174,6 +1251,9 @@ target_ulong do_common_semihosting(CPUState *cs) if (is_a64(cs->env_ptr)) { return 0; } +#endif +#ifdef TARGET_RISCV + return 0; #endif /* fall through -- invalid for A32/T32 */ default: diff --git a/hw/semihosting/common-semi.h b/hw/semihosting/common-semi.h index bc53e92c79..0bfab1c669 100644 --- a/hw/semihosting/common-semi.h +++ b/hw/semihosting/common-semi.h @@ -1,6 +1,6 @@ /* * Semihosting support for systems modeled on the Arm "Angel" - * semihosting syscalls design. + * semihosting syscalls design. This includes Arm and RISC-V processors * * Copyright (c) 2005, 2007 CodeSourcery. * Copyright (c) 2019 Linaro @@ -26,6 +26,9 @@ * Semihosting for AArch32 and AArch64 Release 2.0 * https://static.docs.arm.com/100863/0200/semihosting.pdf * + * RISC-V Semihosting is documented in: + * RISC-V Semihosting + * https://github.com/riscv/riscv-semihosting-spec/blob/main/riscv-sem= ihosting-spec.adoc */ =20 #ifndef COMMON_SEMI_H diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 534753ca12..17aa992165 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -109,6 +109,8 @@ typedef struct TaskState { /* FPA state */ FPA11 fpa; # endif +#endif +#if defined(TARGET_ARM) || defined(TARGET_RISCV) int swi_errno; #endif #if defined(TARGET_I386) && !defined(TARGET_X86_64) @@ -122,7 +124,7 @@ typedef struct TaskState { #ifdef TARGET_M68K abi_ulong tp_value; #endif -#if defined(TARGET_ARM) || defined(TARGET_M68K) +#if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_RISCV) /* Extra fields for semihosted binaries. */ abi_ulong heap_base; abi_ulong heap_limit; diff --git a/linux-user/semihost.c b/linux-user/semihost.c index a1f0f6050e..c0015ee7f6 100644 --- a/linux-user/semihost.c +++ b/linux-user/semihost.c @@ -1,11 +1,11 @@ /* - * ARM Semihosting Console Support + * ARM Compatible Semihosting Console Support. * * Copyright (c) 2019 Linaro Ltd * - * Currently ARM is unique in having support for semihosting support - * in linux-user. So for now we implement the common console API but - * just for arm linux-user. + * Currently ARM and RISC-V are unique in having support for + * semihosting support in linux-user. So for now we implement the + * common console API but just for arm and risc-v linux-user. * * SPDX-License-Identifier: GPL-2.0-or-later */ diff --git a/qemu-options.hx b/qemu-options.hx index 104632ea34..22b4d704b6 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4186,10 +4186,10 @@ ERST DEF("semihosting", 0, QEMU_OPTION_semihosting, "-semihosting semihosting mode\n", QEMU_ARCH_ARM | QEMU_ARCH_M68K | QEMU_ARCH_XTENSA | QEMU_ARCH_LM32 | - QEMU_ARCH_MIPS | QEMU_ARCH_NIOS2) + QEMU_ARCH_MIPS | QEMU_ARCH_NIOS2 | QEMU_ARCH_RISCV) SRST ``-semihosting`` - Enable semihosting mode (ARM, M68K, Xtensa, MIPS, Nios II only). + Enable semihosting mode (ARM, M68K, Xtensa, MIPS, Nios II, RISC-V only= ). =20 Note that this allows guest direct access to the host filesystem, so should only be used with a trusted guest OS. @@ -4201,10 +4201,10 @@ DEF("semihosting-config", HAS_ARG, QEMU_OPTION_semi= hosting_config, "-semihosting-config [enable=3Don|off][,target=3Dnative|gdb|auto][,cha= rdev=3Did][,arg=3Dstr[,...]]\n" \ " semihosting configuration\n", QEMU_ARCH_ARM | QEMU_ARCH_M68K | QEMU_ARCH_XTENSA | QEMU_ARCH_LM32 | -QEMU_ARCH_MIPS | QEMU_ARCH_NIOS2) +QEMU_ARCH_MIPS | QEMU_ARCH_NIOS2 | QEMU_ARCH_RISCV) SRST ``-semihosting-config [enable=3Don|off][,target=3Dnative|gdb|auto][,charde= v=3Did][,arg=3Dstr[,...]]`` - Enable and configure semihosting (ARM, M68K, Xtensa, MIPS, Nios II + Enable and configure semihosting (ARM, M68K, Xtensa, MIPS, Nios II, RI= SC-V only). =20 Note that this allows guest direct access to the host filesystem, so @@ -4219,6 +4219,8 @@ SRST open/read/write/seek/select. Tensilica baremetal libc for ISS and linux platform "sim" use this interface. =20 + On RISC-V this implements the standard semihosting API, version 0.2. + ``target=3Dnative|gdb|auto`` Defines where the semihosting calls will be addressed, to QEMU (``native``) or to GDB (``gdb``). The default is ``auto``, which diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 24b24c69c5..f0d3d1c07e 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -544,6 +544,7 @@ #define RISCV_EXCP_INST_PAGE_FAULT 0xc /* since: priv-1.10.0= */ #define RISCV_EXCP_LOAD_PAGE_FAULT 0xd /* since: priv-1.10.0= */ #define RISCV_EXCP_STORE_PAGE_FAULT 0xf /* since: priv-1.10.0= */ +#define RISCV_EXCP_SEMIHOST 0x10 #define RISCV_EXCP_INST_GUEST_PAGE_FAULT 0x14 #define RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT 0x15 #define RISCV_EXCP_VIRT_INSTRUCTION_FAULT 0x16 diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index a2787b1d48..e730fd1fe9 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -24,6 +24,7 @@ #include "exec/exec-all.h" #include "tcg/tcg-op.h" #include "trace.h" +#include "hw/semihosting/common-semi.h" =20 int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch) { @@ -844,6 +845,15 @@ void riscv_cpu_do_interrupt(CPUState *cs) target_ulong htval =3D 0; target_ulong mtval2 =3D 0; =20 + if (cause =3D=3D RISCV_EXCP_SEMIHOST) { + if (env->priv >=3D PRV_S) { + env->gpr[xA0] =3D do_common_semihosting(cs); + env->pc +=3D 4; + return; + } + cause =3D RISCV_EXCP_BREAKPOINT; + } + if (!async) { /* set tval to badaddr for traps with address information */ switch (cause) { diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/= insn_trans/trans_privileged.c.inc index 2a61a853bf..32312be202 100644 --- a/target/riscv/insn_trans/trans_privileged.c.inc +++ b/target/riscv/insn_trans/trans_privileged.c.inc @@ -29,7 +29,42 @@ static bool trans_ecall(DisasContext *ctx, arg_ecall *a) =20 static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a) { - generate_exception(ctx, RISCV_EXCP_BREAKPOINT); + target_ulong ebreak_addr =3D ctx->base.pc_next; + target_ulong pre_addr =3D ebreak_addr - 4; + target_ulong post_addr =3D ebreak_addr + 4; + uint32_t pre =3D 0; + uint32_t ebreak =3D 0; + uint32_t post =3D 0; + + /* + * The RISC-V semihosting spec specifies the following + * three-instruction sequence to flag a semihosting call: + * + * slli zero, zero, 0x1f 0x01f01013 + * ebreak 0x00100073 + * srai zero, zero, 0x7 0x40705013 + * + * The two shift operations on the zero register are no-ops, used + * here to signify a semihosting exception, rather than a breakpoint. + * + * Uncompressed instructions are required so that the sequence is easy + * to validate. + * + * The three instructions are required to lie in the same page so + * that no exception will be raised when fetching them. + */ + + if ((pre_addr & TARGET_PAGE_MASK) =3D=3D (post_addr & TARGET_PAGE_MASK= )) { + pre =3D opcode_at(&ctx->base, pre_addr); + ebreak =3D opcode_at(&ctx->base, ebreak_addr); + post =3D opcode_at(&ctx->base, post_addr); + } + + if (pre =3D=3D 0x01f01013 && ebreak =3D=3D 0x00100073 && post =3D=3D = 0x40705013) { + generate_exception(ctx, RISCV_EXCP_SEMIHOST); + } else { + generate_exception(ctx, RISCV_EXCP_BREAKPOINT); + } exit_tb(ctx); /* no chaining */ ctx->base.is_jmp =3D DISAS_NORETURN; return true; diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 554d52a4be..0f28b5f41e 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -64,6 +64,7 @@ typedef struct DisasContext { uint16_t vlen; uint16_t mlen; bool vl_eq_vlmax; + CPUState *cs; } DisasContext; =20 #ifdef TARGET_RISCV64 @@ -747,6 +748,15 @@ static bool gen_shift(DisasContext *ctx, arg_r *a, return true; } =20 +static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc) +{ + DisasContext *ctx =3D container_of(dcbase, DisasContext, base); + CPUState *cpu =3D ctx->cs; + CPURISCVState *env =3D cpu->env_ptr; + + return cpu_ldl_code(env, pc); +} + /* Include insn module translation function */ #include "insn_trans/trans_rvi.c.inc" #include "insn_trans/trans_rvm.c.inc" @@ -814,6 +824,7 @@ static void riscv_tr_init_disas_context(DisasContextBas= e *dcbase, CPUState *cs) ctx->lmul =3D FIELD_EX32(tb_flags, TB_FLAGS, LMUL); ctx->mlen =3D 1 << (ctx->sew + 3 - ctx->lmul); ctx->vl_eq_vlmax =3D FIELD_EX32(tb_flags, TB_FLAGS, VL_EQ_VLMAX); + ctx->cs =3D cs; } =20 static void riscv_tr_tb_start(DisasContextBase *db, CPUState *cpu) --=20 2.29.2 From nobody Sun May 5 13:47:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1606340565; cv=none; d=zohomail.com; s=zohoarc; b=YMCFRrVsm0eYJRE2aGHbhhxS4pqhDcOPkMJVVs0sIGorlQZeOjcr5GE768gcJqlvvXGOI34b9DA0k1Y0z8ME2qpjHiSiUhNb3koG+LiR+Gqfw1OvgQL0zg/0KnPpttvhvdhmx/4hi1MA4AvP7RZmbzWWi6DJS2upS2uWFCXpjfU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606340565; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Cayx0LMpRbGoW11vUGACsJCxYxfI6jR9yWeom47DT7w=; b=XtLBMeWVZCcQxvbAViGQFrqaBmXU0qSQrSs39qvrpMUcoRXCxuhpftYKOhuuKNHg+9xYEtxRfcvmKwTLPcb6XyK7bHT4WNAnbQqTXRso8IWaML6LUqWpDxKlaNF0562EXaG+4sLxSCEqbBIXKISYKbcD2/GFIE90Mcy8/qr0hS0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1606340565476328.72282121091075; Wed, 25 Nov 2020 13:42:45 -0800 (PST) Received: from localhost ([::1]:54086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ki2Ym-0000fc-FQ for importer@patchew.org; Wed, 25 Nov 2020 16:42:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37140) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ki2Sw-0002Kh-Ub; Wed, 25 Nov 2020 16:36:45 -0500 Received: from home.keithp.com ([63.227.221.253]:37068 helo=elaine.keithp.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ki2Sv-0001Eh-BU; Wed, 25 Nov 2020 16:36:42 -0500 Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 165343F2E28B; Wed, 25 Nov 2020 13:36:34 -0800 (PST) Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 9-WVyI-M0toE; Wed, 25 Nov 2020 13:36:33 -0800 (PST) Received: from keithp.com (koto.keithp.com [10.0.0.2]) by elaine.keithp.com (Postfix) with ESMTPSA id D16493F2E28D; Wed, 25 Nov 2020 13:36:31 -0800 (PST) Received: by keithp.com (Postfix, from userid 1000) id A9DE215821C6; Wed, 25 Nov 2020 13:36:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1606340194; bh=Cw84Eb20GftlPfR2b4GGp2hGK6fNq0OdbxjdyxpyqIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ooRBkaYO9o8cYqWlVPe7zarLUNe/qPPBr9F9qol7Z9CZEJf/Jd/5IDmi40qZsxPQT 8Xc/eWdzqxQTF30byqcQ1Rj0VnQXex3xImTYQmMStdfIhJntiE2UT9EJjAFRhCdHda vBzt/MBRqlPpkTX7OCFm71wDXEl0XHHx+8qkxv6dok/xuzrwLOOHeYLFOznvbnQOa/ 2b8ElsS774lbT4pvmXSTa0/EDxKBytYwtZZqG0dtIufFzX8onnqblqYVpiXRJbAaMf Qb+736Q3Pbs8rpvmbb/RK7GsbLPEUtqJHR3qRFKchg30dhs3RWg5jGagsnUCkIN6+o y46nw3LuLtJIA== X-Virus-Scanned: Debian amavisd-new at keithp.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1606340191; bh=Cw84Eb20GftlPfR2b4GGp2hGK6fNq0OdbxjdyxpyqIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pb/e9FqAYFnbrb+spiZKTq66SzJZiP3ORQEPM1Le4kR4VD+JqkgVuoONdJUeG4c5O t2eFVVjMFC5EAoz3PEaSmwgkIfUrrbWLmBKn6uZjTrnWBCHM/814KmTiNOAFmmiDYc HFnPncBgfus8dAF61TOKmEiVOYJ+0LTEt3cvouMTaw+oSuPcY3uy8xD9EZG9U8jIYS 2nR9zl7pDX3ECSKEafWCdtAx3/TpByY4LRGqwA/mGKo82CSCrNmMRWbWsQWST60zmu KF7OjtIcMwsqL85BAYxzjyvupwUaySVoexjbsTV15Njb3MG2xbVWgTanaGK77tBzVy PV9Nhi7f3dYxw== To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alistair Francis , Bastian Koppelmann , Laurent Vivier , Palmer Dabbelt , Peter Maydell , qemu-arm@nongnu.org, qemu-riscv@nongnu.org, Sagar Karandikar , Keith Packard Subject: [PATCH 6/8] semihosting: Implement SYS_ELAPSED and SYS_TICKFREQ Date: Wed, 25 Nov 2020 13:36:15 -0800 Message-Id: <20201125213617.2496935-7-keithp@keithp.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201125213617.2496935-1-keithp@keithp.com> References: <20201125213617.2496935-1-keithp@keithp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=63.227.221.253; envelope-from=keithp@keithp.com; helo=elaine.keithp.com 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Keith Packard From: Keith Packard via X-ZohoMail-DKIM: fail (found 2 invalid signatures) Content-Type: text/plain; charset="utf-8" These are part of Semihosting for AArch32 and AArch64 Release 2.0 Signed-off-by: Keith Packard --- hw/semihosting/common-semi.c | 16 ++++++++++++++++ include/qemu/timer.h | 2 ++ util/qemu-timer-common.c | 4 ++++ 3 files changed, 22 insertions(+) diff --git a/hw/semihosting/common-semi.c b/hw/semihosting/common-semi.c index 2b6a3fd9fd..c84b0d906b 100644 --- a/hw/semihosting/common-semi.c +++ b/hw/semihosting/common-semi.c @@ -38,6 +38,7 @@ #include "hw/semihosting/console.h" #include "hw/semihosting/common-semi.h" #include "qemu/log.h" +#include "qemu/timer.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" =20 @@ -69,6 +70,8 @@ #define TARGET_SYS_EXIT 0x18 #define TARGET_SYS_SYNCCACHE 0x19 #define TARGET_SYS_EXIT_EXTENDED 0x20 +#define TARGET_SYS_ELAPSED 0x30 +#define TARGET_SYS_TICKFREQ 0x31 =20 /* ADP_Stopped_ApplicationExit is used for exit(0), * anything else is implemented as exit(1) */ @@ -832,6 +835,7 @@ target_ulong do_common_semihosting(CPUState *cs) uint32_t ret; uint32_t len; GuestFD *gf; + int64_t elapsed; =20 (void) env; /* Used implicitly by arm lock_user macro */ nr =3D common_semi_arg(cs, 0) & 0xffffffffU; @@ -1241,6 +1245,18 @@ target_ulong do_common_semihosting(CPUState *cs) } gdb_exit(cs->env_ptr, ret); exit(ret); + case TARGET_SYS_ELAPSED: + elapsed =3D get_clock() - clock_start; + if (sizeof(target_ulong) =3D=3D 8) { + SET_ARG(0, elapsed); + } else { + SET_ARG(0, (uint32_t) elapsed); + SET_ARG(1, (uint32_t) (elapsed >> 32)); + } + return 0; + case TARGET_SYS_TICKFREQ: + /* qemu always uses nsec */ + return 1000000000; case TARGET_SYS_SYNCCACHE: /* * Clean the D-cache and invalidate the I-cache for the specified diff --git a/include/qemu/timer.h b/include/qemu/timer.h index bdecc5b41f..ca6fae51f1 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -806,6 +806,8 @@ static inline int64_t get_clock_realtime(void) return tv.tv_sec * 1000000000LL + (tv.tv_usec * 1000); } =20 +extern int64_t clock_start; + /* Warning: don't insert tracepoints into these functions, they are also used by simpletrace backend and tracepoints would cause an infinite recursion! */ diff --git a/util/qemu-timer-common.c b/util/qemu-timer-common.c index baf3317f74..cc1326f726 100644 --- a/util/qemu-timer-common.c +++ b/util/qemu-timer-common.c @@ -27,6 +27,8 @@ /***********************************************************/ /* real time host monotonic timer */ =20 +int64_t clock_start; + #ifdef _WIN32 =20 int64_t clock_freq; @@ -41,6 +43,7 @@ static void __attribute__((constructor)) init_get_clock(v= oid) exit(1); } clock_freq =3D freq.QuadPart; + clock_start =3D get_clock(); } =20 #else @@ -55,5 +58,6 @@ static void __attribute__((constructor)) init_get_clock(v= oid) if (clock_gettime(CLOCK_MONOTONIC, &ts) =3D=3D 0) { use_rt_clock =3D 1; } + clock_start =3D get_clock(); } #endif --=20 2.29.2 From nobody Sun May 5 13:47:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1606340538; cv=none; d=zohomail.com; s=zohoarc; b=cVcXGlrGePiM/S1vads/IkWyqTo6UPYh/aQv5NimcoMAvoDAqJ72btckgfdcIFBx0OwexCuRYhaxsG8gjqnM3vUPekiH8wtd9vyh76e8/Nvlk/lHj6ushNZbqgU8teHTiRidKnbIJ+xC1yflsRWVRm/6/Wrmm11oTu5FxWQ0YK8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606340538; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=3uziBAMog/sEGFYGWVS2QkLO0tPqFi3gn6secFja0bs=; b=gDvtIFND9ZklgFk130W3e5XaJtqu86epuM/QNk8oWbyvQ/aorevIDAeCmXK/m5SDtiHNASlgHr3PMJ1ftzcmsaL6LSDBvEz+3BVXkezdpJ4PO4oE5HwzwCRAM181SeJN0Ei+CbpMz2hbD05EjWz3T8zRBDI9R/kl62h/Gd427/g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160634053818687.62204051147467; Wed, 25 Nov 2020 13:42:18 -0800 (PST) Received: from localhost ([::1]:51932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ki2YL-0008Di-3Z for importer@patchew.org; Wed, 25 Nov 2020 16:42:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ki2Su-0002Ia-UD; Wed, 25 Nov 2020 16:36:40 -0500 Received: from home.keithp.com ([63.227.221.253]:37064 helo=elaine.keithp.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ki2St-0001D0-8Y; Wed, 25 Nov 2020 16:36:40 -0500 Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 179693F2E28C; Wed, 25 Nov 2020 13:36:34 -0800 (PST) Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 1eugfL796m84; Wed, 25 Nov 2020 13:36:33 -0800 (PST) Received: from keithp.com (koto.keithp.com [10.0.0.2]) by elaine.keithp.com (Postfix) with ESMTPSA id D7D113F2E28E; Wed, 25 Nov 2020 13:36:31 -0800 (PST) Received: by keithp.com (Postfix, from userid 1000) id B199F15821C7; Wed, 25 Nov 2020 13:36:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1606340194; bh=X4hIM5LaBzi6bmbdhBPAXlHvcdNLVM4OJv26kvDk8og=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YO6+aZlRWsLi69HaWWeCe205Mqpf0zpt6SkYMFTzcJo18ObzuvESQ0N7EO64PAIKf eH4TC+FN/icNxTu9zM2pH1/9CmGzQhGVmrV7gPjaFy67Sv8yzuOHNUDliExlbcf/zr LogfOAwQdwH1AZjSlS9ho/07KBlrwqXGbz+6fUxD7zjoqlng37xEcFkcXAr91yfJH3 gATVtIBsjP0nANTTTGDRQjhQsOax97CixK/vkwTiCIckzm6oMvYfz+mgI08uLuN2fO VG6tO2y6P1gVWR5Bwo4ueH91ohmXfIu0u/pgd7lY7ctngtnq+w+pXtwQR8MlqagR9O YN7gH7T1abybA== X-Virus-Scanned: Debian amavisd-new at keithp.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1606340191; bh=X4hIM5LaBzi6bmbdhBPAXlHvcdNLVM4OJv26kvDk8og=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GXFg3FePa/UjrsJNhHi2cYnldYMPTkueZ0f3FnFWinzynk4LJURqsTVyt8okKKy7e fde9Wus8OFw3y5bq8vF+ND6tSRkqGqJ8ejrbWvBOzb7fNqBQLXaaqm34mBjeOY55VZ eEjB9q4eYCRnpgnWarC6/dwnNuBFGT4uhNDzjyD8L+x77fljcGANDqGl9DCa8mGHMo IoWJpjnqdMp3WmEydX0w2a8YlgFaimAxGX0NhNzInkig5FePgicvYImW+X6gIu8orb CagLmOqTcqafg6Y/CPNT6AH9YY0RA7L2PJSm4Ad3m0qVJeOFgjYnPBobg86KRBu2PZ YVAImv5yAJbUA== To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alistair Francis , Bastian Koppelmann , Laurent Vivier , Palmer Dabbelt , Peter Maydell , qemu-arm@nongnu.org, qemu-riscv@nongnu.org, Sagar Karandikar , Keith Packard Subject: [PATCH 7/8] semihosting: Implement SYS_TMPNAM Date: Wed, 25 Nov 2020 13:36:16 -0800 Message-Id: <20201125213617.2496935-8-keithp@keithp.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201125213617.2496935-1-keithp@keithp.com> References: <20201125213617.2496935-1-keithp@keithp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=63.227.221.253; envelope-from=keithp@keithp.com; helo=elaine.keithp.com 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Keith Packard From: Keith Packard via X-ZohoMail-DKIM: fail (found 2 invalid signatures) Content-Type: text/plain; charset="utf-8" Part of Semihosting for AArch32 and AArch64 Release 2.0 Signed-off-by: Keith Packard --- hw/semihosting/common-semi.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/hw/semihosting/common-semi.c b/hw/semihosting/common-semi.c index c84b0d906b..9a04d98e4e 100644 --- a/hw/semihosting/common-semi.c +++ b/hw/semihosting/common-semi.c @@ -830,6 +830,7 @@ target_ulong do_common_semihosting(CPUState *cs) CPUArchState *env =3D cs->env_ptr; target_ulong args; target_ulong arg0, arg1, arg2, arg3; + target_ulong ul_ret; char * s; int nr; uint32_t ret; @@ -993,8 +994,24 @@ target_ulong do_common_semihosting(CPUState *cs) =20 return guestfd_fns[gf->type].flenfn(cs, gf); case TARGET_SYS_TMPNAM: - qemu_log_mask(LOG_UNIMP, "%s: SYS_TMPNAM not implemented", __func_= _); - return -1; + GET_ARG(0); + GET_ARG(1); + GET_ARG(2); + if (asprintf(&s, "/tmp/qemu-%x%02x", getpid(), + (int) (arg1 & 0xff)) < 0) { + return -1; + } + ul_ret =3D (target_ulong) -1; + + /* Make sure there's enough space in the buffer */ + if (strlen(s) < arg2) { + char *output =3D lock_user(VERIFY_WRITE, arg0, arg2, 0); + strcpy(output, s); + unlock_user(output, arg0, arg2); + ul_ret =3D 0; + } + free(s); + return ul_ret; case TARGET_SYS_REMOVE: GET_ARG(0); GET_ARG(1); --=20 2.29.2 From nobody Sun May 5 13:47:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1606340559; cv=none; d=zohomail.com; s=zohoarc; b=AF2ZycHBVSF/EokvgRxbMiwHt4oc67l76UDDjDsEhZ5hNIceWxJYr8IFYcejC9RPVE3nFxXnzLr+SWF4q5CScqkD+XjRXEdih+G/IMhTpQqdvegqQP02hXVlZAK+CPGBgMqZ+aMLLcWspnQH0hf3ZDOGLfxkevBvexpKsW2S8bQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606340559; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=dKF027fXs2jW0c+ylTXjuovm//tll0AqRf8NM7cMCZU=; b=eUKRU/6lM9RIM+CzeUPgVhJIOS0N34h8LRByYiI/Vh8tbuqJJyJVCyQJbSjWMHDImzyXP5xZZPuqtsbAyYGBECo3AcFb1F2J+vnn0sACHfQOmIqc4Qbp6eEhA7plvZWIge6nDgBsNHvcTHRbHIPffL7N48zVfa2bsYJsUBF3+VE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1606340559143510.68542425765565; Wed, 25 Nov 2020 13:42:39 -0800 (PST) Received: from localhost ([::1]:53794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ki2Yg-0000Yb-3U for importer@patchew.org; Wed, 25 Nov 2020 16:42:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37142) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ki2Sx-0002M1-W8; Wed, 25 Nov 2020 16:36:45 -0500 Received: from home.keithp.com ([63.227.221.253]:37066 helo=elaine.keithp.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ki2Sv-0001Eg-ID; Wed, 25 Nov 2020 16:36:43 -0500 Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 887533F2E28D; Wed, 25 Nov 2020 13:36:34 -0800 (PST) Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 328h7N6Smk8K; Wed, 25 Nov 2020 13:36:34 -0800 (PST) Received: from keithp.com (koto.keithp.com [10.0.0.2]) by elaine.keithp.com (Postfix) with ESMTPSA id DEB2A3F2E290; Wed, 25 Nov 2020 13:36:31 -0800 (PST) Received: by keithp.com (Postfix, from userid 1000) id B5D6C15821C8; Wed, 25 Nov 2020 13:36:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1606340194; bh=FgE+/ceRdQ5QyczkoIKEDBQkeANqnbnZZ159aE22FPc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GfsxZTibe8Udu5GnRr2FGaSJgAgUAJ/OU3wuvsXClaDgKq/0B7F70y5FzIp7nIdxR z2XlXuVX6lmKdgP//BxLtWuEhUURQyxfZzh18RRQsQkxFO07+EF/r1WhBsuIrnjr0x vD+sA7pay6dAN5euR/KtdlgoaxfxlfVumEk53lTQ14kiIRJ/SAMIBE3x4hyEv2yqoT wreljoMw+pBCwpJeprpgjvFYxANZ1gY8SImD9Bm/p80j5xntoOPHu0CBG6aQY9zy7F 7jOl+CkIbpQQa5KFIIedECcjRououIeSwHRN4FEYlFr29ZjShh5KbpYidwrFq9fTI6 QwQRhddULBnCQ== X-Virus-Scanned: Debian amavisd-new at keithp.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1606340191; bh=FgE+/ceRdQ5QyczkoIKEDBQkeANqnbnZZ159aE22FPc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NukZG3Dxu+PDk2NKh4YZIKRnizoHsVPc9HYjba3XvSdjsBZjIJ8UxHJmcJi4QRMeG JbSFYkdLS0AjJA4H+cL7Dfc3bJxjcfUqWgd2e2sHrHd0Bnf0hEha7R7fUocIdVB3Ub uAuPNLT8sxFrt0IAPHo0vZSR08Qkz05KiYPvoQu6ZJobB9nOixEgnmA1JREAhJOQ4e AYx4mjizBm1og9CiGy7bL+SEmJpTmQsf6N7JSDEq7iBmEYLvQ5RszC98AwJmdioupK Gd+VqBEbULn6+2M30ZnIp7iXNlyDwJXLGcRzyhI0RakUU5kyYvWe2dS9bFAO+G2JFi dCEr5MuW9mF3Q== To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alistair Francis , Bastian Koppelmann , Laurent Vivier , Palmer Dabbelt , Peter Maydell , qemu-arm@nongnu.org, qemu-riscv@nongnu.org, Sagar Karandikar , Keith Packard Subject: [PATCH 8/8] semihosting: Implement SYS_ISERROR Date: Wed, 25 Nov 2020 13:36:17 -0800 Message-Id: <20201125213617.2496935-9-keithp@keithp.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201125213617.2496935-1-keithp@keithp.com> References: <20201125213617.2496935-1-keithp@keithp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=63.227.221.253; envelope-from=keithp@keithp.com; helo=elaine.keithp.com 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Keith Packard From: Keith Packard via X-ZohoMail-DKIM: fail (found 2 invalid signatures) Content-Type: text/plain; charset="utf-8" Part of Semihosting for AArch32 and AArch64 Release 2.0 Signed-off-by: Keith Packard --- hw/semihosting/common-semi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/semihosting/common-semi.c b/hw/semihosting/common-semi.c index 9a04d98e4e..fda0e714ef 100644 --- a/hw/semihosting/common-semi.c +++ b/hw/semihosting/common-semi.c @@ -55,6 +55,7 @@ #define TARGET_SYS_WRITE 0x05 #define TARGET_SYS_READ 0x06 #define TARGET_SYS_READC 0x07 +#define TARGET_SYS_ISERROR 0x08 #define TARGET_SYS_ISTTY 0x09 #define TARGET_SYS_SEEK 0x0a #define TARGET_SYS_FLEN 0x0c @@ -962,6 +963,9 @@ target_ulong do_common_semihosting(CPUState *cs) return guestfd_fns[gf->type].readfn(cs, gf, arg1, len); case TARGET_SYS_READC: return qemu_semihosting_console_inc(cs->env_ptr); + case TARGET_SYS_ISERROR: + GET_ARG(0); + return (target_long) arg0 < 0 ? 1 : 0; case TARGET_SYS_ISTTY: GET_ARG(0); =20 --=20 2.29.2