From nobody Sun May 12 17:47:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1694554159; cv=none; d=zohomail.com; s=zohoarc; b=LxBbgfo2N/kJ3n+Kgs7bFdhdwwjI2ItFlbvaPtwrweWEdlKBY4U2lYHrJSlH36IDVOEURqbvkq2L51M9KTCb56yJ4ABVHYdBVfS8r8+SqM94tWMCzcdI/zl0NvsHwMqXNYi2QtxdWzuCBL5W/BKBSqaAtOf/RgLQJd4hfAEYNJs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694554159; 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:References:Sender:Subject:To; bh=6wwFlKewAD3EbUW7aELNycuHcgFIWkZV/jDzQISrvf8=; b=JINbWfwNrctV1nToieWFxzDeOpq2KhbRA3TnmIc+WgsG0zsFYXAL884sfhlzZPKjEQIHNB7igsgja7eypUNCxVd+td90h003hEWeRIiiL38T9eCJPmLsl8yn0yVEhJtY8rJ4AUTSUFRVy85/wSa07g7FBrEYfrK8QCn0+8WPoT8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694554159522910.0087476982131; Tue, 12 Sep 2023 14:29:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgAwW-0000FV-F2; Tue, 12 Sep 2023 17:29:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgAwT-0000FC-96 for qemu-devel@nongnu.org; Tue, 12 Sep 2023 17:29:05 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgAwQ-0007TF-FO for qemu-devel@nongnu.org; Tue, 12 Sep 2023 17:29:04 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-68fdd5c1bbbso212436b3a.1 for ; Tue, 12 Sep 2023 14:29:02 -0700 (PDT) Received: from q1iq-virtual-machine.. ([114.249.236.97]) by smtp.gmail.com with ESMTPSA id u20-20020aa78394000000b0068be4ce33easm7930436pfm.96.2023.09.12.14.28.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 14:29:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694554141; x=1695158941; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6wwFlKewAD3EbUW7aELNycuHcgFIWkZV/jDzQISrvf8=; b=JHkeIfCRIqH6kwCXysJmwbiW/54KHXpfwyc59bRrC/pUz4T1c6VIlMb5vIVPBSKOK9 U3NpqdnUsU7udrJdnx7h6XlvXxs4L26DXXLH7FcKbWLY7Bmy0f63BXIcODSdO+VJtzzO np81ZHnyFtI0wBHzYEFE31ufcwYwq7tPKqO7kVUTlE+UF/goX1mRMxsn/KNSbtMaUwbW qM2jDWGjbvTCV25h8znVTb8zG8jXtIu1RIWcRp6lhsTfkIpGzWh6OjRFYfyInBfTVDtY Mw7gx5Cqb8kWO5rCsEVGjRQPytrGwzN20gSErASmRSOq6ytPo5azISyLxg6f7bUrfvOo DoEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694554141; x=1695158941; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6wwFlKewAD3EbUW7aELNycuHcgFIWkZV/jDzQISrvf8=; b=raVJeFk7JuFACI0zBuBmwmXJ0u078PNk6+9kgQjq9EScmPNSos08epCC0zIkcBIHgc ZFfzqV+lG/tgCPPWEg5t0qvdiiycZeeIFJa0g2ixmuS4vmPQn3254RQHmfztQwpLpnab 8WCl2nJnz17c+wkfZEShpxRsoLe56Efmj49oDG4MOC/vnJv/vIihrDY1cW4BmUQjJ2Ka r7iD2JmwR3wDkGNob7+oowX6NDXa+3J3pmMcqvJNsSfU2bNvEXqmmLXpLE+0zaPvhm8J Ycvbp+ZScwNnfgaW86h0X7DjZAq+mCkHYpJSFw9UHXNEizVgK+x0Z9IAZDUMovM24BMD /H9w== X-Gm-Message-State: AOJu0YxF7q63Lg+rLaLLWHgfvMbZS6igbWbeUewv3pHO3w72E+meHyun 1cm8hunim0YNpad0tVO4Sns= X-Google-Smtp-Source: AGHT+IHh00tfUbp3/Y/JotIxJ/UkGZ6qtccft87mC03YaSQCeqoRLxB33iis16MWhg2ZlUDYnY8C3g== X-Received: by 2002:a05:6a20:4326:b0:149:97e4:8ae4 with SMTP id h38-20020a056a20432600b0014997e48ae4mr1048368pzk.0.1694554141051; Tue, 12 Sep 2023 14:29:01 -0700 (PDT) From: Yeqi Fu To: alex.bennee@linaro.org Cc: richard.henderson@linaro.org, qemu-devel@nongnu.org, Yeqi Fu , Paolo Bonzini , Thomas Huth Subject: [RFC v6 1/9] build: Implement logic for sharing cross-building config files Date: Wed, 13 Sep 2023 05:28:34 +0800 Message-Id: <20230912212842.658374-2-fufuyqqqqqq@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912212842.658374-1-fufuyqqqqqq@gmail.com> References: <20230912212842.658374-1-fufuyqqqqqq@gmail.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=2607:f8b0:4864:20::433; envelope-from=fufuyqqqqqq@gmail.com; helo=mail-pf1-x433.google.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, FREEMAIL_FROM=0.001, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1694554161356100003 Content-Type: text/plain; charset="utf-8" Since both TCG tests and libnative libraries require cross-building, the config files for cross-building, config_target_mak, are now saved in the cross-build directory for sharing. This allows TCG tests and libnative libraries to use these config files through symbolic links when cross-building configuration is needed. Since config_host_mak essentially contains all the information from the original tests/tcg/config-host.mak, the original config-host.mak has been deleted and replaced with a symbolic link to config_host_mak. Signed-off-by: Yeqi Fu --- configure | 61 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/configure b/configure index 2b41c49c0d..7a1e463d9c 100755 --- a/configure +++ b/configure @@ -1751,32 +1751,23 @@ if test "$ccache_cpp2" =3D "yes"; then echo "export CCACHE_CPP2=3Dy" >> $config_host_mak fi =20 -# tests/tcg configuration -(config_host_mak=3Dtests/tcg/config-host.mak -mkdir -p tests/tcg -echo "# Automatically generated by configure - do not modify" > $config_ho= st_mak -echo "SRC_PATH=3D$source_path" >> $config_host_mak -echo "HOST_CC=3D$host_cc" >> $config_host_mak +# Prepare the config files for cross building. +# This process generates 'cross-build//config-target.mak' files. +# These files are then symlinked to the directories that need them which +# including the TCG tests (tests/tcg/) and the libnative library +# for linux-user (common/native//). +mkdir -p cross-build =20 -# versioned checked in the main config_host.mak above -if test -n "$gdb_bin"; then - echo "HAVE_GDB_BIN=3D$gdb_bin" >> $config_host_mak -fi -if test "$plugins" =3D "yes" ; then - echo "CONFIG_PLUGIN=3Dy" >> $config_host_mak -fi - -tcg_tests_targets=3D for target in $target_list; do arch=3D${target%%-*} - case $target in xtensa*-linux-user) - # the toolchain is not complete with headers, only build softmmu tes= ts + # the toolchain for tests/tcg is not complete with headers continue ;; *-softmmu) - test -f "$source_path/tests/tcg/$arch/Makefile.softmmu-target" || co= ntinue + # skip installing config-target.mak when we have no tests to build + test -f "${source_path}/tests/tcg/${arch}/Makefile.softmmu-target" |= | continue qemu=3D"qemu-system-$arch" ;; *-linux-user|*-bsd-user) @@ -1786,22 +1777,46 @@ for target in $target_list; do =20 if probe_target_compiler $target || test -n "$container_image"; then test -n "$container_image" && build_static=3Dy - mkdir -p "tests/tcg/$target" - config_target_mak=3Dtests/tcg/$target/config-target.mak - ln -sf "$source_path/tests/tcg/Makefile.target" "tests/tcg/$target/M= akefile" + mkdir -p "cross-build/${target}" + config_target_mak=3Dcross-build/${target}/config-target.mak echo "# Automatically generated by configure - do not modify" > "$co= nfig_target_mak" echo "TARGET_NAME=3D$arch" >> "$config_target_mak" echo "TARGET=3D$target" >> "$config_target_mak" - write_target_makefile "build-tcg-tests-$target" >> "$config_target_m= ak" + write_target_makefile "$target" >> "$config_target_mak" echo "BUILD_STATIC=3D$build_static" >> "$config_target_mak" echo "QEMU=3D$PWD/$qemu" >> "$config_target_mak" =20 + # get the interpreter prefix and the path of libnative required for = native call tests + if test -n "$target_cc" && [ -d "/usr/$(echo "$target_cc" | sed 's/-= gcc//')" ]; then + echo "LD_PREFIX=3D/usr/$(echo "$target_cc" | sed 's/-gcc//')" >>= "$config_target_mak" + fi + # will GDB work with these binaries? if test "${gdb_arches#*$arch}" !=3D "$gdb_arches"; then echo "HOST_GDB_SUPPORTS_ARCH=3Dy" >> "$config_target_mak" fi + fi +done + +# tests/tcg configuration +(mkdir -p tests/tcg +# create a symlink to the config-host.mak file in the tests/tcg +ln -srf $config_host_mak tests/tcg/config-host.mak +echo "HOST_CC=3D$host_cc" >> $config_host_mak + +tcg_tests_targets=3D +for target in $target_list; do + case $target in + *-softmmu) + test -f "${source_path}/tests/tcg/${arch}/Makefile.softmmu-target" |= | continue + ;; + esac =20 - echo "run-tcg-tests-$target: $qemu\$(EXESUF)" >> Makefile.prereqs + if test -f cross-build/${target}/config-target.mak; then + mkdir -p "tests/tcg/${target}" + ln -srf cross-build/${target}/config-target.mak tests/tcg/${target}/= config-target.mak + ln -sf ${source_path}/tests/tcg/Makefile.target tests/tcg/${target}/= Makefile + echo "run-tcg-tests-${target}: $qemu\$(EXESUF)" >> Makefile.prereqs tcg_tests_targets=3D"$tcg_tests_targets $target" fi done --=20 2.34.1 From nobody Sun May 12 17:47:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1694554190; cv=none; d=zohomail.com; s=zohoarc; b=PmUtEWRyfFfeWKOST72Eez4GLsFc//anRz9zz6trZPuqk0zFy37irIupTdP4eI+DWRLv/Pgip8BRefXdSCdxj68Ro1HjTcm84z3XK/YnoK7OQOFfI0Y8t/cJLYtAALK+2ZjwhssS9t+VY6ppjpk3bablSLgCrOBxE2GyROJEyfM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694554190; 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:References:Sender:Subject:To; bh=XuQ/6SpgQeQrGx0ORa1QWKQvqB4TSbMF35PDAL+KcfM=; b=johK6+DZKCrCglCzx8879cPYaIDFVjG45Y++01v8srC6AWMdbYdhB0V7huzI8Sv2TQ+R/wlI8w1I3MhJlLeba6Org/oFc9PaNRMYaGNn6bAXijN4fXnf4lfe9qc2b4TEMWvi1xj1wF6Xmp+IAhlBK6cjE3ZbVtgdVSImnxw1KzM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694554190166336.96571668607135; Tue, 12 Sep 2023 14:29:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgAwa-0000IH-Rk; Tue, 12 Sep 2023 17:29:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgAwX-0000Fl-Gn for qemu-devel@nongnu.org; Tue, 12 Sep 2023 17:29:09 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgAwU-0007Tt-Me for qemu-devel@nongnu.org; Tue, 12 Sep 2023 17:29:09 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-68fb98745c1so2159467b3a.1 for ; Tue, 12 Sep 2023 14:29:06 -0700 (PDT) Received: from q1iq-virtual-machine.. ([114.249.236.97]) by smtp.gmail.com with ESMTPSA id u20-20020aa78394000000b0068be4ce33easm7930436pfm.96.2023.09.12.14.29.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 14:29:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694554145; x=1695158945; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XuQ/6SpgQeQrGx0ORa1QWKQvqB4TSbMF35PDAL+KcfM=; b=Y/GGJgalYnevYIvCU5XcG4yHaCAWgpqpUMymsG6xCg4aNSWl8mQ28KrF3o4MVyH7+K j5+Vh2fAzRuMvYkabze7JFxpyCAfJ4HcS+0QpqU0SVz37OFh6KJG67UZsRCdQhdatza8 ZiIA/tedHGiaA4Jc808NhudAYwM92FmfU3uSwyNAbkUW8CUl6LpwGz83hw2jjmevmInj LqTXLFOyoZA7AxslvTCewpF0KRj96IZzlK44yeIp/FcFgvZJ5PZTfZUpGVZ+X5aff4YD 4mloA9ZzGiWcxYqHHz2F+76Al3dDSdiaUxpkP9WrI6UE2qIJL69+zB8r2cWuDBVXorYp 0JuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694554145; x=1695158945; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XuQ/6SpgQeQrGx0ORa1QWKQvqB4TSbMF35PDAL+KcfM=; b=psWZNC2ZoFJDa1DLChSCJC3IsxVLA3ihgScB5YwzSYOoEH3YPix4ZpS/UK2XVEK2WC jatr5YFbWPCk/AOmUu3YeVDUAY/ZI5ISt/2WfolpNdaY5TuBrBmmSvuR/qims5hFstNp wKRZHm6kWA6R20h605oibwsQL8ZUVZ8U/uw93HZloLAuxL7uiZMi1Yg2Nozg9hfSY0lt pGIXRLQ2GlMDCfVoLJOWxLVtGRXQ8i7/jlEoGAthdHeeKYIs9D5jXqsxTX9xzvuBbM3K G0UATkjp2aoFR3jeW5/VAROucuFAyoyz2FEMzcehGPnkgjrAH/zTJ995lVWqc9l84dsc +uuA== X-Gm-Message-State: AOJu0Yx7bJ2/TYk9z97ripvskyGuAmmNzL2l53WQjnB+QfTHckBBKsdV DGbBQVHpFnCF/Y/VmgNjbzs= X-Google-Smtp-Source: AGHT+IEX1hu977lh0KV6dgiNJQfo9M5sYCkVeJv8HnJWO/FFl9jBqwpy0n+n9milPOwwQqO6ZMspbg== X-Received: by 2002:a05:6a00:39a5:b0:68f:cd32:c52d with SMTP id fi37-20020a056a0039a500b0068fcd32c52dmr1097436pfb.14.1694554145329; Tue, 12 Sep 2023 14:29:05 -0700 (PDT) From: Yeqi Fu To: alex.bennee@linaro.org Cc: richard.henderson@linaro.org, qemu-devel@nongnu.org, Yeqi Fu , Paolo Bonzini , Thomas Huth , Riku Voipio Subject: [RFC v6 2/9] build: Implement libnative library and the build machinery for libnative Date: Wed, 13 Sep 2023 05:28:35 +0800 Message-Id: <20230912212842.658374-3-fufuyqqqqqq@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912212842.658374-1-fufuyqqqqqq@gmail.com> References: <20230912212842.658374-1-fufuyqqqqqq@gmail.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=2607:f8b0:4864:20::42c; envelope-from=fufuyqqqqqq@gmail.com; helo=mail-pf1-x42c.google.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, FREEMAIL_FROM=0.001, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1694554192224100003 Content-Type: text/plain; charset="utf-8" This commit implements a shared library, where native functions are rewritten as special instructions. At runtime, user programs load the shared library, and special instructions are executed when native functions are called. Signed-off-by: Yeqi Fu --- Makefile | 2 ++ common-user/native/Makefile.include | 8 +++++ common-user/native/Makefile.target | 22 +++++++++++++ common-user/native/libnative.S | 51 +++++++++++++++++++++++++++++ configure | 39 ++++++++++++++++++++++ 5 files changed, 122 insertions(+) create mode 100644 common-user/native/Makefile.include create mode 100644 common-user/native/Makefile.target create mode 100644 common-user/native/libnative.S diff --git a/Makefile b/Makefile index 5d48dfac18..6f6147b40f 100644 --- a/Makefile +++ b/Makefile @@ -182,6 +182,8 @@ SUBDIR_MAKEFLAGS=3D$(if $(V),,--no-print-directory --qu= iet) =20 include $(SRC_PATH)/tests/Makefile.include =20 +include $(SRC_PATH)/common-user/native/Makefile.include + all: recurse-all =20 ROMS_RULES=3D$(foreach t, all clean distclean, $(addsuffix /$(t), $(ROMS))) diff --git a/common-user/native/Makefile.include b/common-user/native/Makef= ile.include new file mode 100644 index 0000000000..65b10fddac --- /dev/null +++ b/common-user/native/Makefile.include @@ -0,0 +1,8 @@ +.PHONY: build-native +build-native: $(NATIVE_TARGETS:%=3Dbuild-native-library-%) +$(NATIVE_TARGETS:%=3Dbuild-native-library-%): build-native-library-%: + $(call quiet-command, \ + $(MAKE) -C common-user/native/$* $(SUBDIR_MAKEFLAGS), \ + "BUILD","$* native library") + +all: build-native diff --git a/common-user/native/Makefile.target b/common-user/native/Makefi= le.target new file mode 100644 index 0000000000..65d90102e2 --- /dev/null +++ b/common-user/native/Makefile.target @@ -0,0 +1,22 @@ +# -*- Mode: makefile -*- +# +# Library for native calls +# + +all: +-include ../../../config-host.mak +-include config-target.mak + +CFLAGS+=3D-shared -D $(TARGET_NAME) +LDFLAGS+=3D + +SRC =3D $(SRC_PATH)/common-user/native/libnative.S +LIBNATIVE =3D libnative.so + +all: $(LIBNATIVE) + +$(LIBNATIVE): $(SRC) + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(EXTRA_NATIVE_CALL_FLAGS) $< -o $@ $(LDF= LAGS) + +clean: + rm -f $(LIBNATIVE) diff --git a/common-user/native/libnative.S b/common-user/native/libnative.S new file mode 100644 index 0000000000..bc51dabedf --- /dev/null +++ b/common-user/native/libnative.S @@ -0,0 +1,51 @@ +.macro special_instr sym +#if defined(__i386__) + ud0 \sym-1f, %eax; 1: +#elif defined(__x86_64__) + ud0 \sym(%rip), %eax +#elif defined(__arm__) || defined(__aarch64__) + hlt 0xffff +1: .word \sym - 1b +#elif defined(__mips__) + syscall 0xffff +1: .word \sym - 1b +#else +# error +#endif +.endm + +.macro ret_instr +#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) + ret +#elif defined(__arm__) + bx lr +#elif defined(__mips__) + jr $ra +#else +# error +#endif +.endm + +/* Symbols of native functions */ + +.macro define_function name + .text +\name: + special_instr 9f + ret_instr + .globl \name + .type \name, %function + .size \name, . - \name + + .section .rodata +9: .asciz "\name" +.endm + +define_function memcmp +define_function memcpy +define_function memset +define_function strcat +define_function strcmp +define_function strcpy +define_function strncmp +define_function strncpy diff --git a/configure b/configure index 7a1e463d9c..de533b27a2 100755 --- a/configure +++ b/configure @@ -1826,6 +1826,45 @@ if test "$tcg" =3D "enabled"; then fi ) =20 +# common-user/native configuration +(mkdir -p common-user/native + +native_targets=3D +for target in $target_list; do + case $target in + *-softmmu) + continue + ;; + esac + + # native call is only supported on these architectures + arch=3D${target%%-*} + config_target_mak=3Dcommon-user/native/${target}/config-target.mak + case $arch in + i386|x86_64|arm|aarch64|mips|mips64) + if test -f cross-build/${target}/config-target.mak; then + mkdir -p "common-user/native/${target}" + ln -srf cross-build/${target}/config-target.mak "$config_target_ma= k" + if test $arch =3D arm; then + echo "EXTRA_NATIVE_CALL_FLAGS=3D-marm" >> "$config_target_mak" + fi + if test $arch =3D $cpu || \ + { test $arch =3D i386 && test $cpu =3D x86_64; } || \ + { test $arch =3D arm && test $cpu =3D aarch64; } || \ + { test $arch =3D mips && test $cpu =3D mips64; }; then + echo "LD_PREFIX=3D/" >> "$config_target_mak" + fi + echo "LIBNATIVE=3D$PWD/common-user/native/${target}/libnative.so" = >> "$config_target_mak" + ln -sf ${source_path}/common-user/native/Makefile.target common-us= er/native/${target}/Makefile + native_targets=3D"$native_targets ${target}" + fi + ;; + esac +done + +echo "NATIVE_TARGETS=3D$native_targets" >> config-host.mak +) + if test "$skip_meson" =3D no; then cross=3D"config-meson.cross.new" meson_quote() { --=20 2.34.1 From nobody Sun May 12 17:47:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1694554300; cv=none; d=zohomail.com; s=zohoarc; b=SpfzSxAaWmIfpANSINB9Cun1tP+I0kbCy4OwNMrdom3ZbRRRQ7Ve3mGF9wIz4Ti/ec+E5IqDCFhyj8aj77EkFudTvPjikmOUusUOIdjWhYSg2iqrGt7ZpUPT8m/se+2Wbu1yDmFuXsY015xZUWvN7Sal4MVhfGUDlieiwHqKqdI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694554300; 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:References:Sender:Subject:To; bh=zzF82Li+3BaSw18Hc0Zjslvm+ZS4IHMgCBVxHce2BXw=; b=hzCEZW0vJlLKDYzDAXnDLp7SDt2sqeaiqDmMJxrMAO3VJUKZ2IMSSgBo1J2YFFr6/yyddE+KApHTrHKXdrfKcWbLOskix0ID85R6m/Dzhqs0htc830evhgM3HchR38TN+XVZ+4oz2dsLOJyKwU4Lv5EOfX/8lcqtd9+AYu16kfQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694554300530869.0449031371853; Tue, 12 Sep 2023 14:31:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgAwd-0000KK-Jr; Tue, 12 Sep 2023 17:29:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgAwa-0000IK-Mo for qemu-devel@nongnu.org; Tue, 12 Sep 2023 17:29:12 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgAwY-0007UC-8F for qemu-devel@nongnu.org; Tue, 12 Sep 2023 17:29:12 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-68fac346f6aso2976191b3a.3 for ; Tue, 12 Sep 2023 14:29:09 -0700 (PDT) Received: from q1iq-virtual-machine.. ([114.249.236.97]) by smtp.gmail.com with ESMTPSA id u20-20020aa78394000000b0068be4ce33easm7930436pfm.96.2023.09.12.14.29.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 14:29:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694554149; x=1695158949; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zzF82Li+3BaSw18Hc0Zjslvm+ZS4IHMgCBVxHce2BXw=; b=jhZExz3zfShZwzcnpLQbg4sHoiI6YSFKhe0xEzxLvhN5Xt50LNIiHMw0w+B3b6mrAH EDLkB28p4yYP6qWDMMo9HdslgkuLLzkkuOgD6JZcJbef+lr8FFNSEWQlQdVzgRZyWerP 28hZAFie1mAmBsDpJc7TzB4vIfRMgxAl28g6i4YNdxP0kE2ys4tbTJLbXOQqlhVNtkf0 QBJ9J65akBp1K93PjLAAOa3DXtGfTY46jDio+1RIQaYUWAYMOVFCtf97TNpk0s4FKi4+ GT7oJE6HePVWJa9BBaqg6Rvy1dHNtyKc83kOS4f+T6fCvFMolAIHtSKRBCp//XMqIEKA kXKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694554149; x=1695158949; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zzF82Li+3BaSw18Hc0Zjslvm+ZS4IHMgCBVxHce2BXw=; b=eHsUBsy9kHrDM7l4XDSlbciz+eMYmd6FmINMpgu3k0+gaQO++q9WH1AilKzmzbZZOF awWl8CDwUA/6j3I4Dn/HxrTlM7SJIGfaCZKVdMNhVZt5i/5OyCVt5Jnl4fwXfVvA6n+p FaUsSFz26tlyFv8Z2QPhXaN6nFfdxddxQ8jSR47VmoPv2v9oVdVYgH8cGMuqhB+NeF/U 8X2nq4F1twinjJL50ge6U1GRoasVpOq1QpFy2YZgrftxFXMdlxQkwLyOkoarSZVkssLq 8pUuIC2Qx9g45WIlNkbdI9y1Erto352MXGcrflzrsQ3bAcngdDVnCKFIaShybSp30ZqH yf2w== X-Gm-Message-State: AOJu0YysalMZUqOBuuLtevZcOyuPkqRGajizgyXoar4MrLkPkHb4sdtP 5A0HjOl6BlwHnKXHeoKzT3g= X-Google-Smtp-Source: AGHT+IHiqsP37Tw90wiNrfDB8QoEnz/Qmk8PE9lSYWbHEk0FbEBWpyEH6gAJDkKdj35h+5Y8LuCR7Q== X-Received: by 2002:a05:6a20:12d6:b0:152:efa4:21b with SMTP id v22-20020a056a2012d600b00152efa4021bmr843732pzg.5.1694554148942; Tue, 12 Sep 2023 14:29:08 -0700 (PDT) From: Yeqi Fu To: alex.bennee@linaro.org Cc: richard.henderson@linaro.org, qemu-devel@nongnu.org, Yeqi Fu , Laurent Vivier Subject: [RFC v6 3/9] linux-user: Implement native-bypass option support Date: Wed, 13 Sep 2023 05:28:36 +0800 Message-Id: <20230912212842.658374-4-fufuyqqqqqq@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912212842.658374-1-fufuyqqqqqq@gmail.com> References: <20230912212842.658374-1-fufuyqqqqqq@gmail.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=2607:f8b0:4864:20::42d; envelope-from=fufuyqqqqqq@gmail.com; helo=mail-pf1-x42d.google.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, FREEMAIL_FROM=0.001, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1694554301836100001 Content-Type: text/plain; charset="utf-8" This commit implements support for the native-bypass option in linux-user. By utilizing this functionality, the specified shared library can be loaded into the user program. This is achieved by dynamically modifying the /etc/ld.so.preload file, enabling the user program to load the shared library effortlessly. Signed-off-by: Yeqi Fu --- include/native/native.h | 7 ++++++ linux-user/main.c | 20 +++++++++++++++ linux-user/syscall.c | 55 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 include/native/native.h diff --git a/include/native/native.h b/include/native/native.h new file mode 100644 index 0000000000..12462a261e --- /dev/null +++ b/include/native/native.h @@ -0,0 +1,7 @@ +#if defined(CONFIG_USER_ONLY) && defined(CONFIG_NATIVE_CALL) +extern char *native_lib_path; +/* Check if the native-bypass option is enabled. */ +#define native_bypass_enabled() (native_lib_path !=3D NULL) +#else +#define native_bypass_enabled() false +#endif diff --git a/linux-user/main.c b/linux-user/main.c index dba67ffa36..4c1d515944 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -60,6 +60,11 @@ #include "semihosting/semihost.h" #endif =20 +#if defined(CONFIG_NATIVE_CALL) +#include "native/native.h" +char *native_lib_path; +#endif + #ifndef AT_FLAGS_PRESERVE_ARGV0 #define AT_FLAGS_PRESERVE_ARGV0_BIT 0 #define AT_FLAGS_PRESERVE_ARGV0 (1 << AT_FLAGS_PRESERVE_ARGV0_BIT) @@ -293,6 +298,17 @@ static void handle_arg_set_env(const char *arg) free(r); } =20 +#if defined(CONFIG_NATIVE_CALL) +static void handle_arg_native_bypass(const char *arg) +{ + if (!g_file_test(arg, G_FILE_TEST_IS_REGULAR)) { + fprintf(stderr, "native library %s does not exist\n", arg); + exit(EXIT_FAILURE); + } + native_lib_path =3D g_strdup(arg); +} +#endif + static void handle_arg_unset_env(const char *arg) { char *r, *p, *token; @@ -522,6 +538,10 @@ static const struct qemu_argument arg_table[] =3D { "", "Generate a /tmp/perf-${pid}.map file for perf"}, {"jitdump", "QEMU_JITDUMP", false, handle_arg_jitdump, "", "Generate a jit-${pid}.dump file for perf"}, +#if defined(CONFIG_NATIVE_CALL) + {"native-bypass", "QEMU_NATIVE_BYPASS", true, handle_arg_native_bypass, + "", "native bypass for library calls"}, +#endif {NULL, NULL, false, NULL, NULL, NULL} }; =20 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 08162cc966..7034f58373 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -143,6 +143,7 @@ #include "fd-trans.h" #include "tcg/tcg.h" #include "cpu_loop-common.h" +#include "native/native.h" =20 #ifndef CLONE_IO #define CLONE_IO 0x80000000 /* Clone io context */ @@ -8503,6 +8504,40 @@ static int open_hardware(CPUArchState *cpu_env, int = fd) } #endif =20 +#if defined(CONFIG_NATIVE_CALL) +static int is_ld_so_preload(const char *filename, const char *entry) +{ + if (native_bypass_enabled() && !strcmp(filename, entry)) { + return 1; + } + return 0; +} + +/* This function is only called when the "native-bypass" option is provide= d. */ +static int open_ld_so_preload(CPUArchState *cpu_env, int fd) +{ + FILE *fp; + char *line =3D NULL; + size_t len =3D 0; + ssize_t read; + + dprintf(fd, "%s\n", native_lib_path); + fp =3D fopen("/etc/ld.so.preload", "r"); + if (fp =3D=3D NULL) { + return 0; + } + + while ((read =3D getline(&line, &len, fp)) !=3D -1) { + dprintf(fd, "%s", line); + } + + free(line); + fclose(fp); + + return 0; +} +#endif + int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, int flags, mode_t mode, bool safe) { @@ -8527,6 +8562,9 @@ int do_guest_openat(CPUArchState *cpu_env, int dirfd,= const char *pathname, #endif #if defined(TARGET_M68K) { "/proc/hardware", open_hardware, is_proc }, +#endif +#if defined(CONFIG_NATIVE_CALL) + { "/etc/ld.so.preload", open_ld_so_preload, is_ld_so_preload }, #endif { NULL, NULL, NULL } }; @@ -9523,6 +9561,11 @@ static abi_long do_syscall1(CPUArchState *cpu_env, i= nt num, abi_long arg1, return -TARGET_EFAULT; } ret =3D get_errno(access(path(p), arg2)); + if (ret !=3D 0 && native_bypass_enabled()) { + if (strcmp(p, "/etc/ld.so.preload") =3D=3D 0 && arg2 =3D=3D R_= OK) { + return 0; + } + } unlock_user(p, arg1, 0); return ret; #endif @@ -9532,6 +9575,12 @@ static abi_long do_syscall1(CPUArchState *cpu_env, i= nt num, abi_long arg1, return -TARGET_EFAULT; } ret =3D get_errno(faccessat(arg1, p, arg3, 0)); + if (ret !=3D 0 && native_bypass_enabled()) { + if (strcmp(p, "/etc/ld.so.preload") =3D=3D 0 && arg1 =3D=3D AT= _FDCWD && + arg3 =3D=3D R_OK) { + return 0; + } + } unlock_user(p, arg2, 0); return ret; #endif @@ -9541,6 +9590,12 @@ static abi_long do_syscall1(CPUArchState *cpu_env, i= nt num, abi_long arg1, return -TARGET_EFAULT; } ret =3D get_errno(faccessat(arg1, p, arg3, arg4)); + if (ret !=3D 0 && native_bypass_enabled()) { + if (strcmp(p, "/etc/ld.so.preload") =3D=3D 0 && arg1 =3D=3D AT= _FDCWD && + arg3 =3D=3D R_OK) { + return 0; + } + } unlock_user(p, arg2, 0); return ret; #endif --=20 2.34.1 From nobody Sun May 12 17:47:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1694554286; cv=none; d=zohomail.com; s=zohoarc; b=iejH2X6K7UbFP61tC5mSAaVUFVrR+Rw3D53kU3ZNFgltwJWlOuXLyNs1bDBRKRaSCXbipomO/h0d7eiYrxDMVvX1DErwJcNQngeaMBzrGs0V7jmoZvRMAvpX8ROC7wEXvo7loJvzRXJvYvnN6yx5Q5bjP5D3OGHFttsqWcaVjgc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694554286; 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:References:Sender:Subject:To; bh=S8/CaILzDlpI4gnj9PPg8ya6AqadQ5DfpDBACZN2fw4=; b=iIIWtXH7uaSfi/VixblUOoWZYssaHq8ObheCEn8DhMMCy8ZlG7LwfdUdzX7aOw5SPMqxkXSowhbr9K67JutyHKqyboCVCY+q7M+ZjKCl1CKfD1OFit35vZcEW1QKcoU6W7WFuQjFDleTTDfF3UDSPJEXNwNTj7OsWofq3Kg6d/A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694554286664456.76564663279316; Tue, 12 Sep 2023 14:31:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgAwi-0000Nv-NY; Tue, 12 Sep 2023 17:29:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgAwg-0000Kw-7G for qemu-devel@nongnu.org; Tue, 12 Sep 2023 17:29:18 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgAwd-0007W3-1J for qemu-devel@nongnu.org; Tue, 12 Sep 2023 17:29:17 -0400 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-68fb98745c1so2159539b3a.1 for ; Tue, 12 Sep 2023 14:29:14 -0700 (PDT) Received: from q1iq-virtual-machine.. ([114.249.236.97]) by smtp.gmail.com with ESMTPSA id u20-20020aa78394000000b0068be4ce33easm7930436pfm.96.2023.09.12.14.29.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 14:29:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694554153; x=1695158953; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=S8/CaILzDlpI4gnj9PPg8ya6AqadQ5DfpDBACZN2fw4=; b=cPp5rMG/JI73c7tNDQClNv4buqhkxtnXvP6t548TFoDoDTJJThduQcFwHxIKq1UEbg I7hUaFH4GKDXby6ETyQ0c32uh4kQmH4ci1n/2PbDaI7CNTt3+wNGTasP6e+aC4KFTJq+ rwah4GuJY63W+lOkY280iHymbwoOD8BXDhC/B1ngy3VOJtzs4k4CXEJS8taU576j3Bbh evQ9k4WvnF5yiRGFIl17WFlWmyhe8AaS6yfMzvxCRiAIOuFco5DcoCY+abHwUDGJcWat +54tWyJDtbCPz70bPN3P4TQHkzdQ2jiFFPvYROp30SM5QshiujCSKNuWlIVBpI03Ap7+ lwVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694554153; x=1695158953; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S8/CaILzDlpI4gnj9PPg8ya6AqadQ5DfpDBACZN2fw4=; b=kwhuJRP1rlFNKDq3vZ9QVxQKvYfTTD27D1qOJCF4qs/wxRJZ2HuhmGFD5z59yhGZen iwv7sv3mfjSQVIgv4B7LlqMBDkopyKV5GFX505MSRHty6jRSgiAAmWlVTJKBvGdLUs7m mWdKMGK+RKm0zHqqRejm1qucum6c/5espiddhkS3vM31SGc293BOlYqUAOMJlNc2SdGK p1fgE2k7Qj72aPN5TX4FH6rY5zBZf8EHoVdRUILJz4NPoIomgOkHqieHtLwIUOe50O2U ViFxTZy3LuSRsp2Kmx8FOnnG21qqvaKd1FBy1PZpkuMPJCJ3U4V5ISxHoP5F5pxICcWJ 3CzQ== X-Gm-Message-State: AOJu0Yw0DJxky/Qw5DDvKn+C36OU4wqxauihIGPIyJdb5dgqYnmJlD9n rt+K4roU//eEddHZpt+V0ssINyM4LDHHea3x X-Google-Smtp-Source: AGHT+IHwqC3gFKAxtdYl4UgaDyD8RXzFyfBBeC05STnM1UOgaVxfKZIitUhaEDHH1l0XWnrnf8scLQ== X-Received: by 2002:a05:6a20:841f:b0:157:dffb:fe1c with SMTP id c31-20020a056a20841f00b00157dffbfe1cmr808814pzd.22.1694554152774; Tue, 12 Sep 2023 14:29:12 -0700 (PDT) From: Yeqi Fu To: alex.bennee@linaro.org Cc: richard.henderson@linaro.org, qemu-devel@nongnu.org, Yeqi Fu , Paolo Bonzini Subject: [RFC v6 4/9] tcg: Add tcg opcodes and helpers for native library calls Date: Wed, 13 Sep 2023 05:28:37 +0800 Message-Id: <20230912212842.658374-5-fufuyqqqqqq@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912212842.658374-1-fufuyqqqqqq@gmail.com> References: <20230912212842.658374-1-fufuyqqqqqq@gmail.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=2607:f8b0:4864:20::431; envelope-from=fufuyqqqqqq@gmail.com; helo=mail-pf1-x431.google.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, FREEMAIL_FROM=0.001, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1694554288621100003 Content-Type: text/plain; charset="utf-8" This commit implements tcg opcodes and helpers for native library calls. A table is used to store the parameter types and return value types for each native library function. In terms of types, only three types are of real concern: the two base sizes int and intptr_t, and if the value is a pointer, tcg_gen_g2h and tcg_gen_h2g are used for address conversion. Signed-off-by: Yeqi Fu --- accel/tcg/tcg-runtime.c | 66 +++++++++++++++ accel/tcg/tcg-runtime.h | 12 +++ include/exec/helper-head.h | 1 + include/native/native-defs.h | 41 ++++++++++ include/tcg/tcg-op-common.h | 13 +++ include/tcg/tcg-op.h | 2 + include/tcg/tcg.h | 8 ++ tcg/tcg-op.c | 36 ++++++++ tcg/tcg.c | 154 +++++++++++++++++++++++++++++++++++ 9 files changed, 333 insertions(+) create mode 100644 include/native/native-defs.h diff --git a/accel/tcg/tcg-runtime.c b/accel/tcg/tcg-runtime.c index 9fa539ad3d..764ca631d5 100644 --- a/accel/tcg/tcg-runtime.c +++ b/accel/tcg/tcg-runtime.c @@ -152,3 +152,69 @@ void HELPER(exit_atomic)(CPUArchState *env) { cpu_loop_exit_atomic(env_cpu(env), GETPC()); } + +#ifdef CONFIG_USER_ONLY +int HELPER(nc_memcmp)(void *s1, void *s2, void *len) +{ + set_helper_retaddr(GETPC()); + int r =3D memcmp(s1, s2, (size_t)len); + clear_helper_retaddr(); + return r; +} + +void *HELPER(nc_memcpy)(void *dst, void *src, void *len) +{ + set_helper_retaddr(GETPC()); + void *r =3D memcpy(dst, src, (size_t)len); + clear_helper_retaddr(); + return r; +} + +void *HELPER(nc_memset)(void *b, int c, void *len) +{ + set_helper_retaddr(GETPC()); + void *r =3D memset(b, c, (size_t)len); + clear_helper_retaddr(); + return r; +} + +void *HELPER(nc_strcat)(void *dst, void *src) +{ + set_helper_retaddr(GETPC()); + void *r =3D strcat(dst, src); + clear_helper_retaddr(); + return r; +} + +int HELPER(nc_strcmp)(void *s1, void *s2) +{ + set_helper_retaddr(GETPC()); + int r =3D strcmp(s1, s2); + clear_helper_retaddr(); + return r; +} + +void *HELPER(nc_strcpy)(void *dst, void *src) +{ + set_helper_retaddr(GETPC()); + void *r =3D strcpy(dst, src); + clear_helper_retaddr(); + return r; +} + +int HELPER(nc_strncmp)(void *s1, void *s2, void *len) +{ + set_helper_retaddr(GETPC()); + int r =3D strncmp(s1, s2, (size_t)len); + clear_helper_retaddr(); + return r; +} + +void *HELPER(nc_strncpy)(void *dst, void *src, void *len) +{ + set_helper_retaddr(GETPC()); + void *r =3D strncpy(dst, src, (size_t)len); + clear_helper_retaddr(); + return r; +} +#endif diff --git a/accel/tcg/tcg-runtime.h b/accel/tcg/tcg-runtime.h index 39e68007f9..7330124c0b 100644 --- a/accel/tcg/tcg-runtime.h +++ b/accel/tcg/tcg-runtime.h @@ -298,3 +298,15 @@ DEF_HELPER_FLAGS_4(gvec_leu32, TCG_CALL_NO_RWG, void, = ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_4(gvec_leu64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) =20 DEF_HELPER_FLAGS_5(gvec_bitsel, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr,= i32) + +#ifdef CONFIG_USER_ONLY +/* Helpers for native library calls */ +DEF_HELPER_FLAGS_3(nc_memcmp, TCG_CALL_NO_RWG, int, ptr, ptr, ptr) +DEF_HELPER_FLAGS_3(nc_memcpy, TCG_CALL_NO_RWG, ptr, ptr, ptr, ptr) +DEF_HELPER_FLAGS_3(nc_memset, TCG_CALL_NO_RWG, ptr, ptr, int, ptr) +DEF_HELPER_FLAGS_2(nc_strcat, TCG_CALL_NO_RWG, ptr, ptr, ptr) +DEF_HELPER_FLAGS_2(nc_strcmp, TCG_CALL_NO_RWG, int, ptr, ptr) +DEF_HELPER_FLAGS_2(nc_strcpy, TCG_CALL_NO_RWG, ptr, ptr, ptr) +DEF_HELPER_FLAGS_3(nc_strncmp, TCG_CALL_NO_RWG, int, ptr, ptr, ptr) +DEF_HELPER_FLAGS_3(nc_strncpy, TCG_CALL_NO_RWG, ptr, ptr, ptr, ptr) +#endif diff --git a/include/exec/helper-head.h b/include/exec/helper-head.h index 28ceab0a46..438c74e2ac 100644 --- a/include/exec/helper-head.h +++ b/include/exec/helper-head.h @@ -84,6 +84,7 @@ =20 #define dh_typecode_void 0 #define dh_typecode_noreturn 0 +#define dh_typecode_iptr 1 #define dh_typecode_i32 2 #define dh_typecode_s32 3 #define dh_typecode_i64 4 diff --git a/include/native/native-defs.h b/include/native/native-defs.h new file mode 100644 index 0000000000..b193882698 --- /dev/null +++ b/include/native/native-defs.h @@ -0,0 +1,41 @@ +/* + * Argument encoding. We only really care about 3 types. The two base + * sizes (int and intptr_t) and if the value is a pointer (in which + * case we need to adjust it g2h before passing to the native + * function). + */ +#include "exec/helper-head.h" + +#define TYPE_AAAP \ + (dh_typemask(ptr, 0) | dh_typemask(ptr, 1) | dh_typemask(ptr, 2) | \ + dh_typemask(iptr, 3)) +#define TYPE_IAAP \ + (dh_typemask(int, 0) | dh_typemask(ptr, 1) | dh_typemask(ptr, 2) | \ + dh_typemask(iptr, 3)) +#define TYPE_AAIP \ + (dh_typemask(ptr, 0) | dh_typemask(ptr, 1) | dh_typemask(int, 2) | \ + dh_typemask(iptr, 3)) +#define TYPE_AAA \ + (dh_typemask(ptr, 0) | dh_typemask(ptr, 1) | dh_typemask(ptr, 2) | \ + dh_typemask(void, 3)) +#define TYPE_IAA \ + (dh_typemask(int, 0) | dh_typemask(ptr, 1) | dh_typemask(ptr, 2) | \ + dh_typemask(void, 3)) + +typedef void (*helper_pppp)(struct TCGv_ptr_d *, struct TCGv_ptr_d *, + struct TCGv_ptr_d *, struct TCGv_ptr_d *); +typedef void (*helper_ippp)(struct TCGv_i32_d *, struct TCGv_ptr_d *, + struct TCGv_ptr_d *, struct TCGv_ptr_d *); +typedef void (*helper_ppip)(struct TCGv_ptr_d *, struct TCGv_ptr_d *, + struct TCGv_i32_d *, struct TCGv_ptr_d *); +typedef void (*helper_ppp)(struct TCGv_ptr_d *, struct TCGv_ptr_d *, + struct TCGv_ptr_d *); +typedef void (*helper_ipp)(struct TCGv_i32_d *, struct TCGv_ptr_d *, + struct TCGv_ptr_d *); +typedef void (*helper_func)(void *, ...); + +typedef struct { + const char *func; + helper_func helper; + uint32_t type; +} FuncHelper; diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h index be382bbf77..86e3dcaf43 100644 --- a/include/tcg/tcg-op-common.h +++ b/include/tcg/tcg-op-common.h @@ -903,6 +903,14 @@ void tcg_gen_ld_vec(TCGv_vec r, TCGv_ptr base, TCGArg = offset); void tcg_gen_st_vec(TCGv_vec r, TCGv_ptr base, TCGArg offset); void tcg_gen_stl_vec(TCGv_vec r, TCGv_ptr base, TCGArg offset, TCGType t); =20 +#ifdef CONFIG_USER_ONLY +/* Host <-> guest conversions */ +void tcg_gen_g2h_i32(TCGv_ptr ret, TCGv_i32 arg); +void tcg_gen_g2h_i64(TCGv_ptr ret, TCGv_i64 arg); +void tcg_gen_h2g_i32(TCGv_i32 ret, TCGv_ptr arg); +void tcg_gen_h2g_i64(TCGv_i64 ret, TCGv_ptr arg); +#endif + /* Host pointer ops */ =20 #if UINTPTR_MAX =3D=3D UINT32_MAX @@ -938,6 +946,11 @@ static inline void tcg_gen_addi_ptr(TCGv_ptr r, TCGv_p= tr a, intptr_t b) glue(tcg_gen_addi_,PTR)((NAT)r, (NAT)a, b); } =20 +static inline void tcg_gen_subi_ptr(TCGv_ptr r, TCGv_ptr a, intptr_t b) +{ + glue(tcg_gen_subi_, PTR)((NAT)r, (NAT)a, b); +} + static inline void tcg_gen_mov_ptr(TCGv_ptr d, TCGv_ptr s) { glue(tcg_gen_mov_,PTR)((NAT)d, (NAT)s); diff --git a/include/tcg/tcg-op.h b/include/tcg/tcg-op.h index d63683c47b..5accbbbf54 100644 --- a/include/tcg/tcg-op.h +++ b/include/tcg/tcg-op.h @@ -279,6 +279,7 @@ DEF_ATOMIC2(tcg_gen_atomic_umax_fetch, i64) #define tcg_gen_dup_tl_vec tcg_gen_dup_i64_vec #define tcg_gen_dup_tl tcg_gen_dup_i64 #define dup_const_tl dup_const +#define gen_native_call_tl gen_native_call_i64 #else #define tcg_gen_movi_tl tcg_gen_movi_i32 #define tcg_gen_mov_tl tcg_gen_mov_i32 @@ -402,5 +403,6 @@ DEF_ATOMIC2(tcg_gen_atomic_umax_fetch, i64) : (qemu_build_not_reached_always(), 0)) \ : (target_long)dup_const(VECE, C)) =20 +#define gen_native_call_tl gen_native_call_i32 #endif /* TARGET_LONG_BITS =3D=3D 64 */ #endif /* TCG_TCG_OP_H */ diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 0875971719..ff1b5e3ca3 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -1148,4 +1148,12 @@ static inline const TCGOpcode *tcg_swap_vecop_list(c= onst TCGOpcode *n) =20 bool tcg_can_emit_vecop_list(const TCGOpcode *, TCGType, unsigned); =20 +#ifdef CONFIG_USER_ONLY +/* Native call support. */ +bool gen_native_call_i32(const char *func_name, TCGv_i32 ret, + TCGv_i32 arg1, TCGv_i32 arg2, TCGv_i32 arg3); +bool gen_native_call_i64(const char *func_name, TCGv_i64 ret, + TCGv_i64 arg1, TCGv_i64 arg2, TCGv_i64 arg3); +#endif + #endif /* TCG_H */ diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c index 7aadb37756..21b4410fd0 100644 --- a/tcg/tcg-op.c +++ b/tcg/tcg-op.c @@ -29,6 +29,7 @@ #include "exec/translation-block.h" #include "exec/plugin-gen.h" #include "tcg-internal.h" +#include "exec/user/guest-base.h" =20 =20 void tcg_gen_op1(TCGOpcode opc, TCGArg a1) @@ -2852,3 +2853,38 @@ void tcg_gen_lookup_and_goto_ptr(void) tcg_gen_op1i(INDEX_op_goto_ptr, tcgv_ptr_arg(ptr)); tcg_temp_free_ptr(ptr); } + +#ifdef CONFIG_USER_ONLY +void tcg_gen_g2h_i32(TCGv_ptr ret, TCGv_i32 arg) +{ + TCGv_ptr temp =3D tcg_temp_new_ptr(); + tcg_gen_ext_i32_ptr(temp, arg); + tcg_gen_addi_ptr(ret, temp, guest_base); + tcg_temp_free_ptr(temp); +} + +void tcg_gen_g2h_i64(TCGv_ptr ret, TCGv_i64 arg) +{ + TCGv_ptr temp =3D tcg_temp_new_ptr(); + tcg_gen_trunc_i64_ptr(temp, arg); + tcg_gen_addi_ptr(ret, temp, guest_base); + tcg_temp_free_ptr(temp); +} + +void tcg_gen_h2g_i32(TCGv_i32 ret, TCGv_ptr arg) +{ + TCGv_ptr temp =3D tcg_temp_new_ptr(); + tcg_gen_subi_ptr(temp, arg, guest_base); + tcg_gen_trunc_ptr_i32(ret, temp); + tcg_temp_free_ptr(temp); +} + +void tcg_gen_h2g_i64(TCGv_i64 ret, TCGv_ptr arg) +{ + TCGv_ptr temp =3D tcg_temp_new_ptr(); + tcg_gen_subi_ptr(temp, arg, guest_base); + tcg_gen_extu_ptr_i64(ret, temp); + tcg_temp_free_ptr(temp); +} + +#endif diff --git a/tcg/tcg.c b/tcg/tcg.c index a0628fe424..a4005ff5c2 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -57,6 +57,7 @@ #include "accel/tcg/perf.h" #ifdef CONFIG_USER_ONLY #include "exec/user/guest-base.h" +#include "native/native-defs.h" #endif =20 /* Forward declarations for functions declared in tcg-target.c.inc and @@ -6384,3 +6385,156 @@ void tcg_expand_vec_op(TCGOpcode o, TCGType t, unsi= gned e, TCGArg a0, ...) g_assert_not_reached(); } #endif + +#ifdef CONFIG_USER_ONLY +static const FuncHelper func_helper_table[] =3D { + { .func =3D "memcmp", + .helper =3D (helper_func)gen_helper_nc_memcmp, + .type =3D TYPE_IAAP }, + { .func =3D "memcpy", + .helper =3D (helper_func)gen_helper_nc_memcpy, + .type =3D TYPE_AAAP }, + { .func =3D "memset", + .helper =3D (helper_func)gen_helper_nc_memset, + .type =3D TYPE_AAIP }, + { .func =3D "strcat", + .helper =3D (helper_func)gen_helper_nc_strcat, + .type =3D TYPE_AAA }, + { .func =3D "strcmp", + .helper =3D (helper_func)gen_helper_nc_strcmp, + .type =3D TYPE_IAA }, + { .func =3D "strcpy", + .helper =3D (helper_func)gen_helper_nc_strcpy, + .type =3D TYPE_AAA }, + { .func =3D "strncmp", + .helper =3D (helper_func)gen_helper_nc_strncmp, + .type =3D TYPE_IAAP }, + { .func =3D "strncpy", + .helper =3D (helper_func)gen_helper_nc_strncpy, + .type =3D TYPE_AAAP }, +}; + +bool gen_native_call_i32(const char *func_name, TCGv_i32 ret, TCGv_i32 arg= 1, + TCGv_i32 arg2, TCGv_i32 arg3) +{ + TCGv_ptr arg1_ptr =3D tcg_temp_new_ptr(); + TCGv_ptr arg2_ptr =3D tcg_temp_new_ptr(); + TCGv_ptr arg3_ptr =3D tcg_temp_new_ptr(); + TCGv_ptr ret_ptr =3D tcg_temp_new_ptr(); + unsigned int i; + for (i =3D 0; i < sizeof(func_helper_table) / sizeof(FuncHelper); i++)= { + if (strcmp(func_name, func_helper_table[i].func) =3D=3D 0) { + break; + } + } + if (i >=3D sizeof(func_helper_table) / sizeof(FuncHelper)) { + qemu_log_mask(LOG_GUEST_ERROR, + "Unimplemented libnative call to \"%s\"\n", func_nam= e); + return false; + } + switch (func_helper_table[i].type) { + case TYPE_AAIP: + tcg_gen_g2h_i32(arg1_ptr, arg1); + tcg_gen_ext_i32_ptr(arg3_ptr, arg3); + ((helper_ppip)(func_helper_table[i].helper))(ret_ptr, arg1_ptr, ar= g2, + arg3_ptr); + goto ret_ptr; + case TYPE_AAAP: + tcg_gen_g2h_i32(arg1_ptr, arg1); + tcg_gen_g2h_i32(arg2_ptr, arg2); + tcg_gen_ext_i32_ptr(arg3_ptr, arg3); + ((helper_pppp)(func_helper_table[i].helper))(ret_ptr, arg1_ptr, + arg2_ptr, arg3_ptr); + goto ret_ptr; + case TYPE_IAAP: + tcg_gen_g2h_i32(arg1_ptr, arg1); + tcg_gen_g2h_i32(arg2_ptr, arg2); + tcg_gen_ext_i32_ptr(arg3_ptr, arg3); + ((helper_ippp)(func_helper_table[i].helper))(ret, arg1_ptr, arg2_p= tr, + arg3_ptr); + return true; + case TYPE_AAA: + tcg_gen_g2h_i32(arg1_ptr, arg1); + tcg_gen_g2h_i32(arg2_ptr, arg2); + ((helper_ppp)(func_helper_table[i].helper))(ret_ptr, arg1_ptr, + arg2_ptr); + goto ret_ptr; + case TYPE_IAA: + tcg_gen_g2h_i32(arg1_ptr, arg1); + tcg_gen_g2h_i32(arg2_ptr, arg2); + ((helper_ipp)(func_helper_table[i].helper))(ret, arg1_ptr, arg2_pt= r); + return true; + default: + return false; + } +ret_ptr: + tcg_gen_h2g_i32(ret, ret_ptr); + return true; +} + +bool gen_native_call_i64(const char *func_name, TCGv_i64 ret, TCGv_i64 arg= 1, + TCGv_i64 arg2, TCGv_i64 arg3) +{ + TCGv_ptr arg1_ptr =3D tcg_temp_new_ptr(); + TCGv_ptr arg2_ptr =3D tcg_temp_new_ptr(); + TCGv_ptr arg3_ptr =3D tcg_temp_new_ptr(); + TCGv_ptr ret_ptr =3D tcg_temp_new_ptr(); + TCGv_i32 arg2_i32, ret_i32 =3D tcg_temp_new_i32(); + unsigned int i; + for (i =3D 0; i < sizeof(func_helper_table) / sizeof(FuncHelper); i++)= { + if (strcmp(func_name, func_helper_table[i].func) =3D=3D 0) { + break; + } + } + if (i >=3D sizeof(func_helper_table) / sizeof(FuncHelper)) { + qemu_log_mask(LOG_GUEST_ERROR, + "Unimplemented libnative call to \"%s\"\n", func_nam= e); + return false; + } + + switch (func_helper_table[i].type) { + case TYPE_AAIP: + tcg_gen_g2h_i64(arg1_ptr, arg1); + arg2_i32 =3D tcg_temp_new_i32(); + tcg_gen_extrl_i64_i32(arg2_i32, arg2); + tcg_gen_trunc_i64_ptr(arg3_ptr, arg3); + ((helper_ppip)(func_helper_table[i].helper))(ret_ptr, arg1_ptr, + arg2_i32, arg3_ptr); + goto ret_ptr; + case TYPE_AAAP: + tcg_gen_g2h_i64(arg1_ptr, arg1); + tcg_gen_g2h_i64(arg2_ptr, arg2); + tcg_gen_trunc_i64_ptr(arg3_ptr, arg3); + ((helper_pppp)(func_helper_table[i].helper))(ret_ptr, arg1_ptr, + arg2_ptr, arg3_ptr); + goto ret_ptr; + case TYPE_IAAP: + tcg_gen_g2h_i64(arg1_ptr, arg1); + tcg_gen_g2h_i64(arg2_ptr, arg2); + tcg_gen_trunc_i64_ptr(arg3_ptr, arg3); + ((helper_ippp)(func_helper_table[i].helper))(ret_i32, arg1_ptr, + arg2_ptr, arg3_ptr); + goto ret_i32; + case TYPE_AAA: + tcg_gen_g2h_i64(arg1_ptr, arg1); + tcg_gen_g2h_i64(arg2_ptr, arg2); + ((helper_ppp)(func_helper_table[i].helper))(ret_ptr, arg1_ptr, + arg2_ptr); + goto ret_ptr; + case TYPE_IAA: + tcg_gen_g2h_i64(arg1_ptr, arg1); + tcg_gen_g2h_i64(arg2_ptr, arg2); + ((helper_ipp)(func_helper_table[i].helper))(ret_i32, arg1_ptr, + arg2_ptr); + goto ret_i32; + default: + return false; + } +ret_ptr: + tcg_gen_h2g_i64(ret, ret_ptr); + return true; +ret_i32: + tcg_gen_extu_i32_i64(ret, ret_i32); + return true; +} +#endif --=20 2.34.1 From nobody Sun May 12 17:47:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1694554213; cv=none; d=zohomail.com; s=zohoarc; b=PtN6Tk+KR6ehgD0qT/lW5dmRfkUiMQaabGNdDYWcggCSXCjoEu2dlTguEDQm//4ri0MsSUuLnn6QQ4gTWO0jM08ZBSmc3HlroLU0B70MNBIulpgDpCTpSLUeXNCyoC7qKIIIc7PLlZz4bljGBszIixudTdDIP5PRXsKWkLt+YtY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694554213; 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:References:Sender:Subject:To; bh=gwpMj7tp0FULMrReOws/DjaiBlzPphwQ/oUU2Dcj5vk=; b=hIkF3wVaCJQdokQFO5JVZDrOKAY/iUOmUninMTmRlJ7KBmkvXK95gHg63juFlT2cDluF3RcmLzczY0hFzj5V7Wd0Ko9J+3acwHHfcvqNN7nQbSRSi7LWahQCovZmB8lxxu8LHPpRHiPwpbqqLMr9ccfebbPHtRsCoyArF7fIKpA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694554213747963.1035837019758; Tue, 12 Sep 2023 14:30:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgAwu-0000Y8-Mg; Tue, 12 Sep 2023 17:29:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgAwk-0000Oe-0o for qemu-devel@nongnu.org; Tue, 12 Sep 2023 17:29:24 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgAwg-0007WZ-K0 for qemu-devel@nongnu.org; Tue, 12 Sep 2023 17:29:20 -0400 Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-573f722b86eso4326961a12.1 for ; Tue, 12 Sep 2023 14:29:18 -0700 (PDT) Received: from q1iq-virtual-machine.. ([114.249.236.97]) by smtp.gmail.com with ESMTPSA id u20-20020aa78394000000b0068be4ce33easm7930436pfm.96.2023.09.12.14.29.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 14:29:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694554157; x=1695158957; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gwpMj7tp0FULMrReOws/DjaiBlzPphwQ/oUU2Dcj5vk=; b=O7FSWASA8DnmwcQbg6RzFb1uRUQeMbuEXj5OnrQySAkdWg9Oujdw61k25EGGvm6pMa N+nLS9EoV+LQ0Z/TtlpaHJQ5wUTVBFH6gnOvdUepnMi5sVexZG9gLPftITA7Gpvz2NZy J2Sy79SyLYMsyKTeAeFNr9eRXJokfDoP0VRtEjGd4yiaY/s0xbttri0UaxD2qkPDYyZU Qa40kTROazLQtQSNog7FDCYpJhALWKbHkaO9f51yjPReP9ZlpBBBhoYkmEAMn1/MIicH FNtoJYnhFwokZUGPAnFLV4cWdVAs3eTZU3nfwenAGsgwegz/5F75hhYFcQzvwwCsXoWo asqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694554157; x=1695158957; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gwpMj7tp0FULMrReOws/DjaiBlzPphwQ/oUU2Dcj5vk=; b=QKQBm5pwjPiVJji6oqgeJ0LnjZeG4anfbDzuagXev6dGfwqE6hShy47gPUESLfYfCU xRPY3zveNsCs+PmYSTnMQw86co2yfjr+k7ypFkvW6Y66rMlWK3Xn0jp2mCob/t9JTpSG GaIxN20nMqDV90aCtLT1tJCBUTptfSLNDQHSe2p6KzaIXaW9G9MbmV6Hhx+MuzsRW0LT t8/zFjOdQLNbbqgO9nGO8HfE6noUEjRt3nYn7IgyCeYCnpLfqdm16HXgENyGUPTZVPWt sXTK4HdA09xUiskc0DVBiK77COOkNElwO+nNozYADHSXKUmFchdnoubgrSmw8zXbl9bU 74wA== X-Gm-Message-State: AOJu0YxH0lfrlHXg/cgsXSd3/QwXVSDe5T6mvVLzBXxVay3dZM4N5/Ea apBZWKi7QDqFFSlQcY5Mc5M= X-Google-Smtp-Source: AGHT+IHTuW8mjWHKJVLFpkAP0u2V+7EY2kln/DbdwzH1jQLWrQKrexe6SXm+fLg+DRzvv9YQh9P7bA== X-Received: by 2002:a05:6a20:8f12:b0:13d:1d14:6693 with SMTP id b18-20020a056a208f1200b0013d1d146693mr695360pzk.45.1694554157036; Tue, 12 Sep 2023 14:29:17 -0700 (PDT) From: Yeqi Fu To: alex.bennee@linaro.org Cc: richard.henderson@linaro.org, qemu-devel@nongnu.org, Yeqi Fu , Laurent Vivier , Paolo Bonzini , Eduardo Habkost Subject: [RFC v6 5/9] target/i386: Add support for native library calls Date: Wed, 13 Sep 2023 05:28:38 +0800 Message-Id: <20230912212842.658374-6-fufuyqqqqqq@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912212842.658374-1-fufuyqqqqqq@gmail.com> References: <20230912212842.658374-1-fufuyqqqqqq@gmail.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=2607:f8b0:4864:20::52c; envelope-from=fufuyqqqqqq@gmail.com; helo=mail-pg1-x52c.google.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, FREEMAIL_FROM=0.001, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1694554214706100001 Content-Type: text/plain; charset="utf-8" This commit introduces support for native library calls on the i386 target. When encountering special instructions reserved for native calls, this commit extracts the function name and generates the corresponding native call. Signed-off-by: Yeqi Fu --- configs/targets/i386-linux-user.mak | 1 + configs/targets/x86_64-linux-user.mak | 1 + target/i386/tcg/translate.c | 38 +++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/configs/targets/i386-linux-user.mak b/configs/targets/i386-lin= ux-user.mak index 5b2546a430..2d8bca8f93 100644 --- a/configs/targets/i386-linux-user.mak +++ b/configs/targets/i386-linux-user.mak @@ -2,3 +2,4 @@ TARGET_ARCH=3Di386 TARGET_SYSTBL_ABI=3Di386 TARGET_SYSTBL=3Dsyscall_32.tbl TARGET_XML_FILES=3D gdb-xml/i386-32bit.xml +CONFIG_NATIVE_CALL=3Dy diff --git a/configs/targets/x86_64-linux-user.mak b/configs/targets/x86_64= -linux-user.mak index 9ceefbb615..a53b017454 100644 --- a/configs/targets/x86_64-linux-user.mak +++ b/configs/targets/x86_64-linux-user.mak @@ -3,3 +3,4 @@ TARGET_BASE_ARCH=3Di386 TARGET_SYSTBL_ABI=3Dcommon,64 TARGET_SYSTBL=3Dsyscall_64.tbl TARGET_XML_FILES=3D gdb-xml/i386-64bit.xml +CONFIG_NATIVE_CALL=3Dy diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 90c7b32f36..a7a8377832 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -33,6 +33,7 @@ #include "helper-tcg.h" =20 #include "exec/log.h" +#include "native/native.h" =20 #define HELPER_H "helper.h" #include "exec/helper-info.c.inc" @@ -3075,6 +3076,37 @@ static void gen_cmpxchg16b(DisasContext *s, CPUX86St= ate *env, int modrm) } #endif =20 +static void gen_native_call(CPUState *cpu, DisasContext *s, CPUX86State *e= nv) +{ +#ifdef CONFIG_USER_ONLY + uint32_t func_tmp; + char *func_name; + TCGv ret =3D tcg_temp_new(); + TCGv arg1 =3D tcg_temp_new(); + TCGv arg2 =3D tcg_temp_new(); + TCGv arg3 =3D tcg_temp_new(); + x86_ldub_code(env, s); + func_tmp =3D x86_ldl_code(env, s); + func_name =3D g2h(cpu, s->pc + func_tmp); +#ifdef TARGET_X86_64 + tcg_gen_mov_tl(arg1, cpu_regs[R_EDI]); + tcg_gen_mov_tl(arg2, cpu_regs[R_ESI]); + tcg_gen_mov_tl(arg3, cpu_regs[R_EDX]); +#else + tcg_gen_addi_tl(arg1, cpu_regs[R_ESP], 4); + gen_op_ld_v(s, MO_UL, arg1, arg1); + tcg_gen_addi_tl(arg2, cpu_regs[R_ESP], 8); + gen_op_ld_v(s, MO_UL, arg2, arg2); + tcg_gen_addi_tl(arg3, cpu_regs[R_ESP], 12); + gen_op_ld_v(s, MO_UL, arg3, arg3); +#endif + if (!gen_native_call_tl(func_name, ret, arg1, arg2, arg3)) { + gen_illegal_opcode(s); + } + tcg_gen_mov_tl(cpu_regs[R_EAX], ret); +#endif +} + /* convert one instruction. s->base.is_jmp is set if the translation must be stopped. Return the next pc value */ static bool disas_insn(DisasContext *s, CPUState *cpu) @@ -6810,6 +6842,12 @@ static bool disas_insn(DisasContext *s, CPUState *cp= u) case 0x1d0 ... 0x1fe: disas_insn_new(s, cpu, b); break; + case 0x1ff: + if (native_bypass_enabled()) { + gen_native_call(cpu, s, env); + break; + } + goto unknown_op; default: goto unknown_op; } --=20 2.34.1 From nobody Sun May 12 17:47:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1694554202; cv=none; d=zohomail.com; s=zohoarc; b=ihk0gtH6lyAj3uhjvH2GYu3R7nCkc3Yq8ZYTvAAxNUzyQeS24opzAUzYyQdSMhKtw3G1woyfIOUhVUcc21TPmEHViLgt9vq7SyrHNccgU/HWaC1Dvv5iDVI8z+Ui2f9/qzUPPTLkVls12O8clpFh8vGftDhshtAKqDonm6+FDxM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694554202; 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:References:Sender:Subject:To; bh=U/AkEtNPg4wtt450WOc9tyNJVZZkvsy/I0yfwNJ/SAA=; b=amqkLxOqIJV5WFu+eNY+l7PqnnJpYyGrss7pefFIgaheD6EHVAKtHxE+YKdYWvQAgap2vLiczihfEegS14g3i18DmL7r31ptSYNmqAF2PWW1diLpsYtJxdc38jD7u/WlR0RAhRx8tkCHZLHAGz9r/niXfF71EyjpAkhcIwMAaO0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694554202779886.6483919108204; Tue, 12 Sep 2023 14:30:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgAww-0000dX-IJ; Tue, 12 Sep 2023 17:29:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgAwp-0000Wg-7N for qemu-devel@nongnu.org; Tue, 12 Sep 2023 17:29:28 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgAwm-0007X6-Ph for qemu-devel@nongnu.org; Tue, 12 Sep 2023 17:29:26 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-68fcb4dc8a9so2206140b3a.2 for ; Tue, 12 Sep 2023 14:29:23 -0700 (PDT) Received: from q1iq-virtual-machine.. ([114.249.236.97]) by smtp.gmail.com with ESMTPSA id u20-20020aa78394000000b0068be4ce33easm7930436pfm.96.2023.09.12.14.29.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 14:29:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694554162; x=1695158962; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=U/AkEtNPg4wtt450WOc9tyNJVZZkvsy/I0yfwNJ/SAA=; b=CSLkUlagYA6Ihg+IMQAPu9vhINTRywHjoL1EZK6iBbrz8hQg1TCn+ITmU6UkaXaFU0 N/k7attHu5/kQcw85HU0nemHg76fNFQIp/GJ3Ke2K0FgOgOEL/P0+PYt0eDEdoo2KKEp KCA5V4jkgNOkJQMx4fR5RcHLJpm0AlsnJcmhLQlHu4IxHYy3B4g2dwkmh7O7umd4iAs9 5g0xsHia4dVB6PchBgySDH/zqhgl7N9Wbw09wsQhagHkC2cJgGYkj3xO0Kq5514QV6I/ TL1u32MF7QPc6Zk6jJhAjY0ME7G3M/OzTi77xxjlC+oCdtqBjIDIPJ1qnrXCsbK1VY45 MhQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694554162; x=1695158962; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U/AkEtNPg4wtt450WOc9tyNJVZZkvsy/I0yfwNJ/SAA=; b=gjmK1QZzmJqxMlSLiTzdak9LYr34rPflt9qAw5vt/qvF+NRAQV/NyAtf88VQy+600D 0aH0tahXaZ/XyxBQNPyjMJFBXYbRRBFI4NCXVMpVTupeqfk+siobFrfdXe0Emkq9iu12 uL80obFrAvlrnPpVMKbTZVdppk4SlgKaTbBMupGua72u5VHcI2VyiwpQkjI8lXJl5dlS GUe3d/cX3SjxYCiHdAeweqOS9+dlDaOQOjclnSUeVFBoWbn4uJjPj32CzZnQRjp7YSog 9TXO2NzYpmx0pnNTcTmur5B3XD9iv8Zn/XzAAJyafsXc+QmUPE42UU2sujAZQWyWXR3N oMhQ== X-Gm-Message-State: AOJu0YwzCM72Y+JvMr1d3qgWS2erkXKxaEx7TsT1QOM5C2QyDi2qgjbe c4tZh7XA5bBkeuYuTdEEGLw= X-Google-Smtp-Source: AGHT+IHShwul/Ms1aEHxjppEklQ/AqOGKcpat1s+RUUYpFUWRNz2JaxiZ6xZtnvLy3G8wfbiNI2lgQ== X-Received: by 2002:a05:6a20:13cf:b0:153:6a8b:8f5d with SMTP id ho15-20020a056a2013cf00b001536a8b8f5dmr558064pzc.23.1694554161944; Tue, 12 Sep 2023 14:29:21 -0700 (PDT) From: Yeqi Fu To: alex.bennee@linaro.org Cc: richard.henderson@linaro.org, qemu-devel@nongnu.org, Yeqi Fu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Jiaxun Yang , Laurent Vivier , Aurelien Jarno , Aleksandar Rikalo Subject: [RFC v6 6/9] target/mips: Add support for native library calls Date: Wed, 13 Sep 2023 05:28:39 +0800 Message-Id: <20230912212842.658374-7-fufuyqqqqqq@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912212842.658374-1-fufuyqqqqqq@gmail.com> References: <20230912212842.658374-1-fufuyqqqqqq@gmail.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=2607:f8b0:4864:20::433; envelope-from=fufuyqqqqqq@gmail.com; helo=mail-pf1-x433.google.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, FREEMAIL_FROM=0.001, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1694554204694100007 Content-Type: text/plain; charset="utf-8" This commit introduces support for native library calls on the mips target. When encountering special instructions reserved for native calls, this commit extracts the function name and generates the corresponding native call. Signed-off-by: Yeqi Fu --- configs/targets/mips-linux-user.mak | 1 + configs/targets/mips64-linux-user.mak | 1 + target/mips/tcg/translate.c | 30 ++++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/configs/targets/mips-linux-user.mak b/configs/targets/mips-lin= ux-user.mak index b4569a9893..fa005d487a 100644 --- a/configs/targets/mips-linux-user.mak +++ b/configs/targets/mips-linux-user.mak @@ -3,3 +3,4 @@ TARGET_ABI_MIPSO32=3Dy TARGET_SYSTBL_ABI=3Do32 TARGET_SYSTBL=3Dsyscall_o32.tbl TARGET_BIG_ENDIAN=3Dy +CONFIG_NATIVE_CALL=3Dy diff --git a/configs/targets/mips64-linux-user.mak b/configs/targets/mips64= -linux-user.mak index d2ff509a11..ecfe6bcf73 100644 --- a/configs/targets/mips64-linux-user.mak +++ b/configs/targets/mips64-linux-user.mak @@ -4,3 +4,4 @@ TARGET_BASE_ARCH=3Dmips TARGET_SYSTBL_ABI=3Dn64 TARGET_SYSTBL=3Dsyscall_n64.tbl TARGET_BIG_ENDIAN=3Dy +CONFIG_NATIVE_CALL=3Dy diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c index 74af91e4f5..b2d60e83d9 100644 --- a/target/mips/tcg/translate.c +++ b/target/mips/tcg/translate.c @@ -31,6 +31,7 @@ #include "trace.h" #include "disas/disas.h" #include "fpu_helper.h" +#include "native/native.h" =20 #define HELPER_H "helper.h" #include "exec/helper-info.c.inc" @@ -13484,10 +13485,32 @@ static void decode_opc_special_legacy(CPUMIPSStat= e *env, DisasContext *ctx) } } =20 +static void gen_native_call(DisasContext *ctx, CPUMIPSState *env) +{ +#ifdef CONFIG_USER_ONLY + char *func_name; + uint32_t func_tmp; + TCGv arg1 =3D tcg_temp_new(); + TCGv arg2 =3D tcg_temp_new(); + TCGv arg3 =3D tcg_temp_new(); + TCGv ret =3D tcg_temp_new(); + tcg_gen_mov_tl(arg1, cpu_gpr[4]); + tcg_gen_mov_tl(arg2, cpu_gpr[5]); + tcg_gen_mov_tl(arg3, cpu_gpr[6]); + ctx->base.pc_next +=3D 4; + func_tmp =3D translator_ldl(env, &ctx->base, ctx->base.pc_next); + func_name =3D g2h(env_cpu(env), ctx->base.pc_next + func_tmp); + if (!gen_native_call_tl(func_name, ret, arg1, arg2, arg3)) { + gen_reserved_instruction(ctx); + } + tcg_gen_mov_tl(cpu_gpr[2], ret); +#endif +} + static void decode_opc_special(CPUMIPSState *env, DisasContext *ctx) { int rs, rt, rd, sa; - uint32_t op1; + uint32_t op1, sig; =20 rs =3D (ctx->opcode >> 21) & 0x1f; rt =3D (ctx->opcode >> 16) & 0x1f; @@ -13583,6 +13606,11 @@ static void decode_opc_special(CPUMIPSState *env, = DisasContext *ctx) #endif break; case OPC_SYSCALL: + sig =3D (ctx->opcode) >> 6; + if ((sig =3D=3D 0xffff) && native_bypass_enabled()) { + gen_native_call(ctx, env); + break; + } generate_exception_end(ctx, EXCP_SYSCALL); break; case OPC_BREAK: --=20 2.34.1 From nobody Sun May 12 17:47:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1694554198; cv=none; d=zohomail.com; s=zohoarc; b=UcOzuwrAtRAtXjKIyuNAcWU5y5xx9vJmgzQHUHy03tZx8IBpF5frEJOi+kHXNkQGYIHpJSAzZru6NGYHTCe4RnVy+IRFt2VNUTP+1AAiHcubvcRNVNUxntpIvtikSjDnqGPAQMrr27dHyjlnwpsO1DnB8NFPa1+TFRaFGXrD3s4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694554198; 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:References:Sender:Subject:To; bh=0c/U127kRZlzHBmfgSsC57fttRjeM+Iuaw+v/+H9H8A=; b=Gb9Bq8y5VJztJ1iwIH3G93kO4WzlH9198OGhSCMaApmOnlkC2i1M1jW3/9/+3Xxep308AbUSKgyc2L3jAEpUF7mU2xb5CQXjcozuOvOKzZJYeCV6diqkeJTQu0qHV4fH5mS8hZcyvKk7PAFyTcimIUrro2lUfbrwujw1f1+pIO8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694554198036666.6971779415433; Tue, 12 Sep 2023 14:29:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgAwx-0000hI-Qz; Tue, 12 Sep 2023 17:29:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgAwt-0000Yh-Im; Tue, 12 Sep 2023 17:29:31 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgAwr-0007Xk-2o; Tue, 12 Sep 2023 17:29:31 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-68faf930054so2866059b3a.0; Tue, 12 Sep 2023 14:29:27 -0700 (PDT) Received: from q1iq-virtual-machine.. ([114.249.236.97]) by smtp.gmail.com with ESMTPSA id u20-20020aa78394000000b0068be4ce33easm7930436pfm.96.2023.09.12.14.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 14:29:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694554166; x=1695158966; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0c/U127kRZlzHBmfgSsC57fttRjeM+Iuaw+v/+H9H8A=; b=cVCmIdORPyHDZEJAYKvYRORYkDjqAPZ1uNlu3wbsNPtLb7EkFgpMdezPP0/YZRaC4+ SaST9B3RAy94kIiuWeX+ipNN9NUO0XnEpA+zd5D+Fi1vhOUUYBqAST0bBLoNjV+Fs8VR kheYtjn3adt0BXcMJMK5W8XJ9avvsBqI53b4a27riVCMIunC3zslkmhNxWBQiSIvHLFq OPh5X/MovX0hvTsqwfNEQFdn1qkELRXacartSQB0ADhk0zwPCmHYI5h1kuyTOQ4IvXTm yJcKBMVG4QaaFFQqNDUjKmWbU/LbwwT6K8sxALo54PBNb2lX1xikbJ4BP3BM6NGAUKeQ jwCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694554166; x=1695158966; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0c/U127kRZlzHBmfgSsC57fttRjeM+Iuaw+v/+H9H8A=; b=DkGig0Lirrpc1jq5q730FraUJsNnG5tyZIaF6lKZlVJgKyhZCxC9dV5iPDg3Slk3uU lgE4vq40vPoALp0J//KHthW8HKrUrN408KuA96/zC+MaJVO7cfgtfE7P5BbiYIs4r/5G yRzQ5HH1XyYvdDr4Vy+MqyTZyL3/riLfs8VDlk2S3Td3eCUn7dkLM/+UztvOSn96KcjY vKVPaui3JifrXI1i1L08981qPERGjRQtlhwW6RXKleoh8Todh0UDsOtcr5t2NG1vqBDi kyHeb1aVCf2xwpXYIcI5VZ6tvZKCPsaU5gATXFFfnLkyZOfpzORT2sY70/dDUE0Jz1U1 4dhA== X-Gm-Message-State: AOJu0YyQuyfZkW1RiqxdQ0Nk6a/5SWq88d1x20fWzNHcG1yJsCoGQvEa LwWjo/F1Y3nu+n+OFJXTukUkxAt6UmJm1Qio X-Google-Smtp-Source: AGHT+IFDaZyoDJURSCapMwfTHRGZRvB1maqalNeG4nnq9hxM6QRvAvG/KIwVeBJ7sthGfs+XteHogg== X-Received: by 2002:a05:6a21:3d85:b0:131:a21:9f96 with SMTP id bj5-20020a056a213d8500b001310a219f96mr587036pzc.6.1694554166229; Tue, 12 Sep 2023 14:29:26 -0700 (PDT) From: Yeqi Fu To: alex.bennee@linaro.org Cc: richard.henderson@linaro.org, qemu-devel@nongnu.org, Yeqi Fu , Laurent Vivier , Peter Maydell , qemu-arm@nongnu.org (open list:ARM TCG CPUs) Subject: [RFC v6 7/9] target/arm: Add support for native library calls Date: Wed, 13 Sep 2023 05:28:40 +0800 Message-Id: <20230912212842.658374-8-fufuyqqqqqq@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912212842.658374-1-fufuyqqqqqq@gmail.com> References: <20230912212842.658374-1-fufuyqqqqqq@gmail.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=2607:f8b0:4864:20::42b; envelope-from=fufuyqqqqqq@gmail.com; helo=mail-pf1-x42b.google.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, FREEMAIL_FROM=0.001, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1694554198334100001 Content-Type: text/plain; charset="utf-8" This commit introduces support for native library calls on the arm target. When encountering special instructions reserved for native calls, this commit extracts the function name and generates the corresponding native call. Signed-off-by: Yeqi Fu --- configs/targets/aarch64-linux-user.mak | 1 + configs/targets/arm-linux-user.mak | 1 + target/arm/tcg/translate-a64.c | 32 ++++++++++++++++++++++++++ target/arm/tcg/translate.c | 29 +++++++++++++++++++++++ target/arm/tcg/translate.h | 5 ++++ 5 files changed, 68 insertions(+) diff --git a/configs/targets/aarch64-linux-user.mak b/configs/targets/aarch= 64-linux-user.mak index ba8bc5fe3f..5a8fd98cd9 100644 --- a/configs/targets/aarch64-linux-user.mak +++ b/configs/targets/aarch64-linux-user.mak @@ -4,3 +4,4 @@ TARGET_XML_FILES=3D gdb-xml/aarch64-core.xml gdb-xml/aarch6= 4-fpu.xml gdb-xml/aarch TARGET_HAS_BFLT=3Dy CONFIG_SEMIHOSTING=3Dy CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy +CONFIG_NATIVE_CALL=3Dy diff --git a/configs/targets/arm-linux-user.mak b/configs/targets/arm-linux= -user.mak index 7f5d65794c..f934fb82da 100644 --- a/configs/targets/arm-linux-user.mak +++ b/configs/targets/arm-linux-user.mak @@ -5,3 +5,4 @@ TARGET_XML_FILES=3D gdb-xml/arm-core.xml gdb-xml/arm-vfp.xm= l gdb-xml/arm-vfp3.xml TARGET_HAS_BFLT=3Dy CONFIG_SEMIHOSTING=3Dy CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy +CONFIG_NATIVE_CALL=3Dy diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c index 3baab6aa60..00b69e9c24 100644 --- a/target/arm/tcg/translate-a64.c +++ b/target/arm/tcg/translate-a64.c @@ -25,6 +25,7 @@ #include "arm_ldst.h" #include "semihosting/semihost.h" #include "cpregs.h" +#include "native/native.h" =20 static TCGv_i64 cpu_X[32]; static TCGv_i64 cpu_pc; @@ -2400,6 +2401,10 @@ static bool trans_HLT(DisasContext *s, arg_i *a) * it is required for halting debug disabled: it will UNDEF. * Secondly, "HLT 0xf000" is the A64 semihosting syscall instruction. */ + if (native_bypass_enabled() && (a->imm =3D=3D 0xffff)) { + s->native_call_status =3D true; + return true; + } if (semihosting_enabled(s->current_el =3D=3D 0) && a->imm =3D=3D 0xf00= 0) { gen_exception_internal_insn(s, EXCP_SEMIHOST); } else { @@ -13392,6 +13397,26 @@ void gen_gvec_rax1(unsigned vece, uint32_t rd_ofs,= uint32_t rn_ofs, tcg_gen_gvec_3(rd_ofs, rn_ofs, rm_ofs, opr_sz, max_sz, &op); } =20 +static void gen_native_call(CPUState *cpu, DisasContext *s, CPUARMState *e= nv) +{ +#ifdef CONFIG_USER_ONLY + TCGv_i64 arg1 =3D tcg_temp_new_i64(); + TCGv_i64 arg2 =3D tcg_temp_new_i64(); + TCGv_i64 arg3 =3D tcg_temp_new_i64(); + TCGv_i64 ret =3D tcg_temp_new_i64(); + uint32_t func_tmp =3D translator_ldl_swap(env, &s->base, s->base.pc_ne= xt, + bswap_code(s->sctlr_b)); + char *func_name =3D g2h(cpu, s->base.pc_next + func_tmp); + tcg_gen_mov_i64(arg1, cpu_reg(s, 0)); + tcg_gen_mov_i64(arg2, cpu_reg(s, 1)); + tcg_gen_mov_i64(arg3, cpu_reg(s, 2)); + if (!gen_native_call_i64(func_name, ret, arg1, arg2, arg3)) { + unallocated_encoding(s); + } + tcg_gen_mov_i64(cpu_reg(s, 0), ret); +#endif +} + /* Crypto three-reg SHA512 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0 * +-----------------------+------+---+---+-----+--------+------+------+ @@ -13950,6 +13975,13 @@ static void aarch64_tr_translate_insn(DisasContext= Base *dcbase, CPUState *cpu) uint64_t pc =3D s->base.pc_next; uint32_t insn; =20 + if (native_bypass_enabled() && s->native_call_status) { + gen_native_call(cpu, s, env); + s->base.pc_next =3D pc + 4; + s->native_call_status =3D false; + return; + } + /* Singlestep exceptions have the highest priority. */ if (s->ss_active && !s->pstate_ss) { /* Singlestep state is Active-pending. diff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c index 13c88ba1b9..7a5a0f9444 100644 --- a/target/arm/tcg/translate.c +++ b/target/arm/tcg/translate.c @@ -28,6 +28,7 @@ #include "semihosting/semihost.h" #include "cpregs.h" #include "exec/helper-proto.h" +#include "native/native.h" =20 #define HELPER_H "helper.h" #include "exec/helper-info.c.inc" @@ -1125,6 +1126,23 @@ void gen_lookup_tb(DisasContext *s) s->base.is_jmp =3D DISAS_EXIT; } =20 +static void gen_native_call(CPUState *cpu, DisasContext *dc, CPUARMState *= env) +{ +#ifdef CONFIG_USER_ONLY + TCGv_i32 arg1 =3D load_reg(dc, 0); + TCGv_i32 arg2 =3D load_reg(dc, 1); + TCGv_i32 arg3 =3D load_reg(dc, 2); + TCGv_i32 ret =3D tcg_temp_new_i32(); + uint32_t func_tmp =3D + arm_ldl_code(env, &dc->base, dc->base.pc_next, dc->sctlr_b); + char *func_name =3D g2h(cpu, dc->base.pc_next + func_tmp); + if (!gen_native_call_i32(func_name, ret, arg1, arg2, arg3)) { + unallocated_encoding(dc); + } + store_reg(dc, 0, ret); +#endif +} + static inline void gen_hlt(DisasContext *s, int imm) { /* HLT. This has two purposes. @@ -1139,6 +1157,10 @@ static inline void gen_hlt(DisasContext *s, int imm) * semihosting, to provide some semblance of security * (and for consistency with our 32-bit semihosting). */ + if (native_bypass_enabled() && (imm =3D=3D 0xffff)) { + s->native_call_status =3D true; + return; + } if (semihosting_enabled(s->current_el =3D=3D 0) && (imm =3D=3D (s->thumb ? 0x3c : 0xf000))) { gen_exception_internal_insn(s, EXCP_SEMIHOST); @@ -9329,6 +9351,13 @@ static void arm_tr_translate_insn(DisasContextBase *= dcbase, CPUState *cpu) uint32_t pc =3D dc->base.pc_next; unsigned int insn; =20 + if (native_bypass_enabled() && dc->native_call_status) { + gen_native_call(cpu, dc, env); + dc->base.pc_next =3D pc + 4; + dc->native_call_status =3D false; + return; + } + /* Singlestep exceptions have the highest priority. */ if (arm_check_ss_active(dc)) { dc->base.pc_next =3D pc + 4; diff --git a/target/arm/tcg/translate.h b/target/arm/tcg/translate.h index d1cacff0b2..3854a801e6 100644 --- a/target/arm/tcg/translate.h +++ b/target/arm/tcg/translate.h @@ -157,6 +157,11 @@ typedef struct DisasContext { int c15_cpar; /* TCG op of the current insn_start. */ TCGOp *insn_start; + /* + * Indicate whether the next instruction is a native function call (tr= ue) + * or not (false). + */ + bool native_call_status; } DisasContext; =20 typedef struct DisasCompare { --=20 2.34.1 From nobody Sun May 12 17:47:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1694554221; cv=none; d=zohomail.com; s=zohoarc; b=bxKl27irMZXILEUEpZI4oMmbPfn9k2iIoCgSE0N3SbxXt1BupLoJ1aAiXM2LcLk4WWrYrDLNFBbeavUkPtEnz1qvIcW7WJy1uAW/NYBkgJg5A/rTiAqlLONIeuvTYY/kQ6eK/PNkTxWVKONmxO/Zh8qpKlcAU1X+uARaj08Yegc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694554221; 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:References:Sender:Subject:To; bh=7HtD+OYfMKelkMTMTh4WfcoKEIkozBhy7qg4sRQ8vPQ=; b=HsOBcvFX0XwykGrLNCfl8juqBW6tz7OwF/CyflhHnc009hJcFBt1Cgz1mWQJokbFeGgWihkrcpROEOmNbGx3vOUYwCWUtCgj42lRUD6bS4Xs9gnE9X6k8Ft/Rlb9uMybvl2BGr2fINFdlUC8ikOs8hbeDOulxUeYdG/SuhZVDjs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694554221079974.4246204928729; Tue, 12 Sep 2023 14:30:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgAwz-0000q6-QN; Tue, 12 Sep 2023 17:29:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgAwv-0000eJ-IR for qemu-devel@nongnu.org; Tue, 12 Sep 2023 17:29:34 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgAwt-0007YA-1N for qemu-devel@nongnu.org; Tue, 12 Sep 2023 17:29:33 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-68fac346f6aso2976392b3a.3 for ; Tue, 12 Sep 2023 14:29:30 -0700 (PDT) Received: from q1iq-virtual-machine.. ([114.249.236.97]) by smtp.gmail.com with ESMTPSA id u20-20020aa78394000000b0068be4ce33easm7930436pfm.96.2023.09.12.14.29.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 14:29:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694554169; x=1695158969; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7HtD+OYfMKelkMTMTh4WfcoKEIkozBhy7qg4sRQ8vPQ=; b=EgX70aQjPh1J4XAuJgKL2LNlX7/42+viQflGVkznpQZpj1cyDzy2AG5jNhfH8poabU P+RHf6hlY413GX2b5OlBZSTjrxYzpFaUWYohuN9BFXQfKWTqeT5DDQ3fjk4fAflQRPL8 YTvqr7LEvLRm+GG1ElaFNnxy6dexkqNopWavCvHx4IS5rhbaD6FXKQbh/SZErsD1ln+1 9/m9BXtg7fpwAWaEBoN+PPjVmIwPxcWPKNjd0Zev+/rnUN+s8f8SGNVDF8iUY2TLTKNI dJaT833p06YtfHuwsLANNZZTpM+0PxykrRp9jxJg4szC/J2YagDoEqCxHTxBW13B1ARb OBXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694554169; x=1695158969; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7HtD+OYfMKelkMTMTh4WfcoKEIkozBhy7qg4sRQ8vPQ=; b=NRP9aC3vTqeV5NIRLBnZc+bv0EBpTR1+7Nwoyc/cVtruRSiyE3/BFaHb7RzRVDI9Nb rQJmjSLrQcw/TwFKI4jCs/3RJ4pa64bXHYIsfguApXqw0+a+ru2k75eX4hOsrNoiI0ZG p79WP2WbU0h+d4NDpebhOfQVSiyZb8AEd19xfGADjlaD+qoD2xEdHBaIAFuj1GOup14c EmKC9wurh0IH2y6DBSvtbgfKavx2jD3F7Qo877DOd4Rn6vRY3SpisoUnRi8M17SIiICW L5rkn8+QSuMZa4/mwy9CXmM9nboObliwbtLL28NZFhKC4fjrejUd2wJTcCQhoXNnOcy5 sCPg== X-Gm-Message-State: AOJu0YwgU/RUDGVXJmSSGI/D6zDZ73VbpeI0q2Vz090szmnbIZeHcteq FOgc5WoOoYssb3QpaGmDe/c= X-Google-Smtp-Source: AGHT+IFYKr01X4Yk7VsGlHcdI1Gtj0S1sJlmfQkvJU1ODOLCSUIe9pBbWvvJMbC0AgiRlxij/x/uMQ== X-Received: by 2002:a05:6a00:1891:b0:68f:cd71:45d5 with SMTP id x17-20020a056a00189100b0068fcd7145d5mr1268758pfh.3.1694554169506; Tue, 12 Sep 2023 14:29:29 -0700 (PDT) From: Yeqi Fu To: alex.bennee@linaro.org Cc: richard.henderson@linaro.org, qemu-devel@nongnu.org, Yeqi Fu Subject: [RFC v6 8/9] tests/tcg/multiarch: Add nativecall.c test Date: Wed, 13 Sep 2023 05:28:41 +0800 Message-Id: <20230912212842.658374-9-fufuyqqqqqq@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912212842.658374-1-fufuyqqqqqq@gmail.com> References: <20230912212842.658374-1-fufuyqqqqqq@gmail.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=2607:f8b0:4864:20::436; envelope-from=fufuyqqqqqq@gmail.com; helo=mail-pf1-x436.google.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, FREEMAIL_FROM=0.001, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1694554222952100003 Content-Type: text/plain; charset="utf-8" Introduce a new test for native calls to ensure their functionality. The process involves cross-compiling the test cases, building them as dynamically linked binaries, and running these binaries which necessitates the addition of the appropriate interpreter prefix. Signed-off-by: Yeqi Fu --- tests/tcg/multiarch/Makefile.target | 32 ++++++ tests/tcg/multiarch/native/nativecall.c | 132 ++++++++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 tests/tcg/multiarch/native/nativecall.c diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Make= file.target index 43bddeaf21..8bad8ac0d5 100644 --- a/tests/tcg/multiarch/Makefile.target +++ b/tests/tcg/multiarch/Makefile.target @@ -12,7 +12,9 @@ VPATH +=3D $(MULTIARCH_SRC) MULTIARCH_SRCS =3D $(notdir $(wildcard $(MULTIARCH_SRC)/*.c)) ifeq ($(filter %-linux-user, $(TARGET)),$(TARGET)) VPATH +=3D $(MULTIARCH_SRC)/linux +VPATH +=3D $(MULTIARCH_SRC)/native MULTIARCH_SRCS +=3D $(notdir $(wildcard $(MULTIARCH_SRC)/linux/*.c)) +MULTIARCH_SRCS +=3D $(notdir $(wildcard $(MULTIARCH_SRC)/native/*.c)) endif MULTIARCH_TESTS =3D $(MULTIARCH_SRCS:.c=3D) =20 @@ -138,5 +140,35 @@ run-plugin-semiconsole-with-%: TESTS +=3D semihosting semiconsole endif =20 +nativecall: LDFLAGS+=3D-ldl +nativecall: CFLAGS+=3D-D_GNU_SOURCE -fPIE +nativecall: nativecall.c + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(filter-out -static,$(LDFLAGS)) + +ifneq ($(LD_PREFIX),) +ifneq ($(LIBNATIVE),) +run-nativecall: nativecall + $(call run-test, $<, $(QEMU) -L $(LD_PREFIX) \ + --native-bypass $(LIBNATIVE) $<, "nativecall") + +run-plugin-nativecall-with-%: + $(call run-test, $@, $(QEMU) $(QEMU_OPTS) \ + -L $(LD_PREFIX) --native-bypass $(LIBNATIVE) \ + -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@)$(PLUGIN_ARGS) \ + $(call strip-plugin,$<) 2> $<.err, \ + $< with $*) +else +run-nativecall: nativecall + $(call skip-test, $<, "no native library found") +run-plugin-nativecall-with-%: + $(call skip-test, $<, "no native library found") +endif +else +run-nativecall: nativecall + $(call skip-test, $<, "no elf interpreter prefix found") +run-plugin-nativecall-with-%: + $(call skip-test, $<, "no elf interpreter prefix found") +endif + # Update TESTS TESTS +=3D $(MULTIARCH_TESTS) diff --git a/tests/tcg/multiarch/native/nativecall.c b/tests/tcg/multiarch/= native/nativecall.c new file mode 100644 index 0000000000..de18718c61 --- /dev/null +++ b/tests/tcg/multiarch/native/nativecall.c @@ -0,0 +1,132 @@ +#include +#include +#include +#include +#include +#include +#include + +void compare_memory(const void *a, const void *b, size_t n) +{ + const unsigned char *p1 =3D a; + const unsigned char *p2 =3D b; + for (size_t i =3D 0; i < n; i++) { + assert(p1[i] =3D=3D p2[i]); + } +} + +void test_memcpy(char *src) +{ + char dest[2000]; + memcpy(dest, src, 2000); + compare_memory(dest, src, 2000); +} + +void test_strncpy(char *src) +{ + char dest[2000]; + strncpy(dest, src, 2000); + compare_memory(dest, src, 2000); +} + +void test_strcpy(char *src) +{ + char dest[2000]; + strcpy(dest, src); + compare_memory(dest, src, 2000); +} + +void test_strcat() +{ + char src[30] =3D "Hello, "; + char dest[] =3D "world!"; + char str[] =3D "Hello, world!"; + strcat(src, dest); + compare_memory(src, str, 13); +} + +void test_memcmp(char *str1, char *str2, char *str3) +{ + int result1 =3D memcmp(str1, str2, 3); + int result2 =3D memcmp(str1, str3, 3); + int result3 =3D memcmp(str3, str1, 3); + assert(result1 =3D=3D 0); + assert(result2 < 0); + assert(result3 > 0); +} + +void test_strncmp(char *str1, char *str2, char *str3) +{ + int result1 =3D strncmp(str1, str2, 3); + int result2 =3D strncmp(str1, str3, 3); + int result3 =3D strncmp(str3, str1, 3); + assert(result1 =3D=3D 0); + assert(result2 < 0); + assert(result3 > 0); +} + +void test_strcmp(char *str1, char *str2, char *str3) +{ + int result1 =3D strcmp(str1, str2); + int result2 =3D strcmp(str1, str3); + int result3 =3D strcmp(str3, str1); + assert(result1 =3D=3D 0); + assert(result2 < 0); + assert(result3 > 0); +} + +void test_memset(char *buffer) +{ + memset(buffer, 'A', 2000 - 1); + for (int i =3D 0; i < 2000 - 1; i++) { + assert(buffer[i] =3D=3D 'A'); + } +} + +void test_libnative() +{ + Dl_info info; + void *memcpy_addr =3D (void *)memcpy; + if (dladdr(memcpy_addr, &info) !=3D 0) { + assert(strstr(info.dli_fname, "libnative.so") !=3D NULL); + } +} + +/* + * When executing execv, an error may occur stating that the shared library + * cannot be preloaded. + */ +void test_execv(const char *cmd) +{ + char *argv[4]; + argv[0] =3D (char *)"/bin/sh"; + argv[1] =3D (char *)"-c"; + argv[2] =3D (char *)cmd; + argv[3] =3D NULL; + execv("/bin/sh", argv); +} + +int main() +{ + char buf[2000]; + for (int i =3D 0; i < 2000 - 1; i++) { + buf[i] =3D 'A' + (i % 26); + } + buf[2000 - 1] =3D '\0'; + char str1[4] =3D "abc\0"; + char str2[4] =3D "abc\0"; + char str3[4] =3D "def\0"; + + test_memcpy(buf); + test_strncpy(buf); + test_strcpy(buf); + test_memcmp(str1, str2, str3); + test_strncmp(str1, str2, str3); + test_strcmp(str1, str2, str3); + test_strcat(); + test_memset(buf); + test_libnative(); + test_execv("echo 111"); + + return EXIT_SUCCESS; +} --=20 2.34.1 From nobody Sun May 12 17:47:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1694554198; cv=none; d=zohomail.com; s=zohoarc; b=h8ZraoqZsh10X6xLr4kxRSdhIHddgN/eylr8d3SpJMVDwIhBGL4fwDue+GRvkjktfNPq9su4DecbdnDHo4XdsHNrXbx5z6rsGMOd4aw5Z1/WZY+WoEubTwNQEfdY4Qukeo229v/0a59x43cGgZbgQVq601Ud8x/nQ0iPF4G/Pa8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694554198; 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:References:Sender:Subject:To; bh=CYFipkq5GBv0dRUOXcmoig3E3YvWubfKodSG8cGfqzk=; b=JzKLpVDgZxI4766fCPrOcx0cidgBTMixrF++LaOyZdPds0ffXfbRxaV3/UXnqun9zpfPgDBOYr7UGf/Zy4Jm1Hkfumlnovncqm0qQCibOv4ec8OAW4HqKb8TQGC9i+uWfmF2k597kavHWmUvNAyQfdRritW4rbb+3kAeAu4vDnI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694554198000995.8440913584654; Tue, 12 Sep 2023 14:29:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgAx3-0001FP-1c; Tue, 12 Sep 2023 17:29:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgAx0-0000xz-Tk for qemu-devel@nongnu.org; Tue, 12 Sep 2023 17:29:39 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgAww-0007ZF-OB for qemu-devel@nongnu.org; Tue, 12 Sep 2023 17:29:38 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-68fb98745c1so2159684b3a.1 for ; Tue, 12 Sep 2023 14:29:34 -0700 (PDT) Received: from q1iq-virtual-machine.. ([114.249.236.97]) by smtp.gmail.com with ESMTPSA id u20-20020aa78394000000b0068be4ce33easm7930436pfm.96.2023.09.12.14.29.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 14:29:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694554173; x=1695158973; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CYFipkq5GBv0dRUOXcmoig3E3YvWubfKodSG8cGfqzk=; b=JbGaKIzS5DoScMddJXNC+/nFyT10BbvftKv3y2xh5bMDcGZ1/YGv0PILjnvqJqzS/K zF+NxFC9pRz8QCim2SQ1p1jlL9HFEVD+9Oue5p2dH/nvYweJ4RK9AWRs2vHraiBnKBlL VO8j0EnhPvCQdPTxP64TcsjXLR4JFdQSI8/TG7HRpQfniqSwFPgCI3boHEqE+ZxKAvA2 nP2PdpJBIr7gx5yJ0gOc/1AhjFmfnX/AmNJfjvXdFcsX6hcqn1mlxuPQKxgTDE4XBR3l OKybHcV79XBT+wk0Otj4XQ3q290lfqjuB6fsQl1lsLMPaRi3uIG8c1/y0g0tcXPeuTrE eWzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694554173; x=1695158973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CYFipkq5GBv0dRUOXcmoig3E3YvWubfKodSG8cGfqzk=; b=APmsq5s4fP/vu/Lom/JdNliY1UdUgA2V3D7u0VvEXDnXzqVwlGKysPQMU/EA6FmGp6 oj3mjE6t1ayydhbWKVD6M3AUCoY9/ob6nDGko/Dgw7gXO8kzgy6FoO4EYQZHK6btymAW XE6OW6kC7xqCKevPeHUB7UQL1pgY+m1PTqGpVCG0iVcVF/wfw7L0ytQiY9MeLBoTmoUh Ll99jBT6Z7W8ykTumsBC3qf/MhVfWWXfykjUNKFE1bv8oWbJT3Wfgf41AtTVL62jXnFf k3uevPbKY8tjCXi/IcNed/ftuQs18OBdl6ci0377Y9k2p9XueWdLpRE8JVSLMHEsv5Io c6Kg== X-Gm-Message-State: AOJu0YzpGAIya7k0ESyvtxbuoIAcmmdXHMZkubq3C2onqf3fZR2EaJ9H 5A0osDDujvQ0+4KllcT/jRc= X-Google-Smtp-Source: AGHT+IHiXlZaUbkpcCVxFfB//bxKs0TYjbrNyFdzszgZQrYLaBubc7OFgyax8w8fdK4zJnTUFDQ2DQ== X-Received: by 2002:a05:6a00:2d87:b0:68f:ece2:ac3b with SMTP id fb7-20020a056a002d8700b0068fece2ac3bmr1035317pfb.5.1694554172859; Tue, 12 Sep 2023 14:29:32 -0700 (PDT) From: Yeqi Fu To: alex.bennee@linaro.org Cc: richard.henderson@linaro.org, qemu-devel@nongnu.org, Yeqi Fu Subject: [RFC v6 9/9] docs/user: Add doc for native library calls Date: Wed, 13 Sep 2023 05:28:42 +0800 Message-Id: <20230912212842.658374-10-fufuyqqqqqq@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912212842.658374-1-fufuyqqqqqq@gmail.com> References: <20230912212842.658374-1-fufuyqqqqqq@gmail.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=2607:f8b0:4864:20::42a; envelope-from=fufuyqqqqqq@gmail.com; helo=mail-pf1-x42a.google.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, FREEMAIL_FROM=0.001, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1694554200107100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Yeqi Fu --- docs/user/index.rst | 1 + docs/user/native_calls.rst | 91 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 docs/user/native_calls.rst diff --git a/docs/user/index.rst b/docs/user/index.rst index 782d27cda2..d3fc9b7af1 100644 --- a/docs/user/index.rst +++ b/docs/user/index.rst @@ -12,3 +12,4 @@ processes compiled for one CPU on another CPU. :maxdepth: 2 =20 main + native_calls diff --git a/docs/user/native_calls.rst b/docs/user/native_calls.rst new file mode 100644 index 0000000000..0f8c2273a3 --- /dev/null +++ b/docs/user/native_calls.rst @@ -0,0 +1,91 @@ +Native Library Calls Optimization +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D + +Description +----------- + +Executing a program under QEMU's user mode subjects the entire +program, including all library calls, to translation. It's important +to understand that many of these library functions are optimized +specifically for the guest architecture. Therefore, their +translation might not yield the most efficient execution. + +When the semantics of a library function are well defined, we can +capitalize on this by substituting the translated version with a call +to the native equivalent function. + +To achieve tangible results, focus should be given to functions such +as memory-related ('mem*') and string-related ('str*') functions. +These subsets of functions often have the most significant effect +on overall performance, making them optimal candidates for +optimization. + +Implementation +-------------- + +By writing the name of a specific library into the /etc/ld.so.preload +file, the dynamic linker will prioritize loading this library before +any others. If this library contains functions that share names with +functions in other libraries, the ones in the specified library will +take precedence. + +In order to bypass certain native libraries, we have developed a +shared library and re-implemented the native functions within it +as a special instruction sequence. By making dynamic modifications +to the /etc/ld.so.preload file, the shared library is loaded into +the user program. Consequently, when the user program calls a native +function, it executes the corresponding special instruction sequence. +During execution, the QEMU translator identifies these special +instructions and executes the corresponding native functions +accordingly. + +These special instructions are implemented using +architecture-specific unused or invalid opcodes, ensuring that they +do not conflict with existing instructions. + + +i386 and x86_64 +--------------- +An unused instruction is utilized to mark a native call. + +arm and aarch64 +--------------- +HLT is an invalid instruction for userspace programs, and is used to +mark a native call. + +mips and mips64 +--------------- +The syscall instruction contains 20 unused bits, which are typically +set to 0. These bits can be used to store non-zero data, +distinguishing them from a regular syscall instruction. + +Usage +----- + +1. Install cross-compilation tools + +Cross-compilation tools are required to build the shared libraries +that can hook the necessary library functions. For example, a viable +command on Ubuntu is: + +:: + + apt install gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu \ + gcc-mips-linux-gnu gcc-mips64-linux-gnuabi64 + + +2. Locate the compiled libnative.so + +After compilation, the libnative.so file can be found in the +``./build/common-user/native/-linux-user`` directory. + +3. Run the program with the ``--native-bypass`` option + +To run your program with native library bypass, use the +``--native-bypass`` option to import libnative.so: + +:: + + qemu- --native-bypass \ + ./build/common-user/native/-linux-user/libnative.so ./program + --=20 2.34.1