From nobody Sat May 4 05:29:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600124623; cv=none; d=zohomail.com; s=zohoarc; b=m7HBGPKVzKOTM3VuUEVcIS88Zxz8uxVpC6ssuOI0sYEAvWYogFwSIKzpdx0Vn5Ga2/wzBdffj31fbCa1tDS56ICBx04XeEGTT8iRjyS0QXhINwQQ9l05NhyVySUkPNvrE6YYxGwy5JclWhNlbmqtO/Ef+MF8DacYK3fLUHveHu8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600124623; 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=ALNSa/DecTe4W9DwCQMu8Ql5AeR22CfvyUrSkBl9Tqk=; b=dsdbZZyVdWgDs6/7Lw+omWIpWZ6LaOeDrVSmDosnm022wuvf3fSo3rmHLftjBTjVGZgRkPLTWpxsjKUK3Du0bO/Whl+SiArGq3HooJV+iGP1SisiyxKYSToKNFZ5bEiRnJln6/TlMdYy0mMyBiBPhS/Xwa5N53k6thxkyjuOFvU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160012462353640.44954982960542; Mon, 14 Sep 2020 16:03:43 -0700 (PDT) Received: from localhost ([::1]:33568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHxVe-0002Qz-BY for importer@patchew.org; Mon, 14 Sep 2020 19:03:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHxUI-0000tO-Qo for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:18 -0400 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]:40536) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHxUG-0006Zy-Jy for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:18 -0400 Received: by mail-pj1-x1044.google.com with SMTP id gf14so715287pjb.5 for ; Mon, 14 Sep 2020 16:02:16 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id l23sm9106076pgt.16.2020.09.14.16.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 16:02:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ALNSa/DecTe4W9DwCQMu8Ql5AeR22CfvyUrSkBl9Tqk=; b=vqoIS1eKFJXtgotvd5r7DVGjlJBlYJMiRum3qi6cx9mGs/mgZrX9fP7NDA+t9gIa81 VSgUuQ4SRIkb8qNOTxl/+nHXeBT4svi64WQFg1JAsP6Bk/P4v5yRt2ePLg5glfx7UYOJ zbBOwUvuh6VUim56o/Dzq5bTSb7xxjHSAN25Coz7+Rnixx5ioFALR0h0mpUT67ENarS0 Vg+KAUuM1+UZbXbWxn5KqgCIyDIlacYIMR+kBaMflj2h1iemv2F7ABbRjG7RGOTRL0om Rx8fAxVQVbNXzl//fJDb+DNuhjSf8xeBp74Pwi++/0hnCzIIxl5V5O4wXxTwnUxT79Bk 9m1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ALNSa/DecTe4W9DwCQMu8Ql5AeR22CfvyUrSkBl9Tqk=; b=ddIfsT2SqG1ahd+6dJ5p3YYMbxYaJZDzvY4FoWecpe8o2TdWZ/NodMqzQKtA2zZFg5 ZxKZpnejqLkHhk3L1cX/hEHF9JhWqsvZKeJHxTdALerQoqmODNe59w2Le0Cn+F+Hsnmc 8C9UrintCNsARZhJln4C3IwROUDUbL1tEiaBGR9yoFCn9Hnbf1/jsTQVKl5B/ji1+rS9 bCpeObShP1SgNEactHV11y+ix68bRJavBkw4b0K2vZmR9J+aW8x+yJdw/Qqr42W7NvjV YP0z+owayMRvRwd2892MhqxcyJ/GOghGlhNnOWKeH48kJc4uWXrUPxVp4XuyrR2u5k3W +hhg== X-Gm-Message-State: AOAM5303mUV9LMfWit0N5jEfvbPSzeUr3hwI7Z+cE19JYiWwfWcXry/H pHjW1m+mPrreHVWDzFvzQUmyRwkR/ni7Dg== X-Google-Smtp-Source: ABdhPJy4QQ7Z4nTZM1HHDp+Uc4KiSEsWUyXiUzoGlXUWSthRp9szo7AZDx08damRl8irUr+KrYenUA== X-Received: by 2002:a17:90a:71c7:: with SMTP id m7mr1516364pjs.190.1600124534393; Mon, 14 Sep 2020 16:02:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 01/10] capstone: Convert Makefile bits to meson bits Date: Mon, 14 Sep 2020 16:02:01 -0700 Message-Id: <20200914230210.2185860-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914230210.2185860-1-richard.henderson@linaro.org> References: <20200914230210.2185860-1-richard.henderson@linaro.org> 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::1044; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1044.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" There are better ways to do this, e.g. meson cmake subproject, but that requires cmake 3.7 and some of our CI environments only provide cmake 3.5. Nor can we add a meson.build file to capstone/, because the git submodule would then always report "untracked files". Fixing that would require creating our own branch on the qemu git mirror, at which point we could just as easily create a native meson subproject. Instead, build the library via the main meson.build. This improves the current state of affairs in that we will re-link the qemu executables against a changed libcapstone.a, which we wouldn't do before-hand. In addition, the use of the confuration header file instead of command-line -DEFINES means that we will rebuild the capstone objects with changes to meson.build. Signed-off-by: Richard Henderson --- Cc: Paolo Bonzini v2: Further reduce probing in configure (paolo), Drop state 'internal' and use 'git' even when it isn't git. Move CONFIG_CAPSTONE to config_host_data. --- configure | 61 +++----------------------- Makefile | 16 ------- meson.build | 109 +++++++++++++++++++++++++++++++++++++++++++--- meson_options.txt | 4 ++ 4 files changed, 113 insertions(+), 77 deletions(-) diff --git a/configure b/configure index ce27eafb0a..1fd80ed699 100755 --- a/configure +++ b/configure @@ -469,7 +469,7 @@ opengl=3D"" opengl_dmabuf=3D"no" cpuid_h=3D"no" avx2_opt=3D"" -capstone=3D"" +capstone=3D"auto" lzo=3D"" snappy=3D"" bzip2=3D"" @@ -1573,7 +1573,7 @@ for opt do ;; --enable-capstone) capstone=3D"yes" ;; - --enable-capstone=3Dgit) capstone=3D"git" + --enable-capstone=3Dgit) capstone=3D"internal" ;; --enable-capstone=3Dsystem) capstone=3D"system" ;; @@ -5124,51 +5124,11 @@ fi # capstone =20 case "$capstone" in - "" | yes) - if $pkg_config capstone; then - capstone=3Dsystem - elif test -e "${source_path}/.git" && test $git_update =3D 'yes' ; then - capstone=3Dgit - elif test -e "${source_path}/capstone/Makefile" ; then - capstone=3Dinternal - elif test -z "$capstone" ; then - capstone=3Dno - else - feature_not_found "capstone" "Install capstone devel or git submodul= e" - fi - ;; - - system) - if ! $pkg_config capstone; then - feature_not_found "capstone" "Install capstone devel" - fi - ;; -esac - -case "$capstone" in - git | internal) - if test "$capstone" =3D git; then + auto | yes | internal) + # Simpler to always update submodule, even if not needed. + if test -e "${source_path}/.git" && test $git_update =3D 'yes' ; then git_submodules=3D"${git_submodules} capstone" fi - mkdir -p capstone - if test "$mingw32" =3D "yes"; then - LIBCAPSTONE=3Dcapstone.lib - else - LIBCAPSTONE=3Dlibcapstone.a - fi - capstone_libs=3D"-Lcapstone -lcapstone" - capstone_cflags=3D"-I${source_path}/capstone/include" - ;; - - system) - capstone_libs=3D"$($pkg_config --libs capstone)" - capstone_cflags=3D"$($pkg_config --cflags capstone)" - ;; - - no) - ;; - *) - error_exit "Unknown state for capstone: $capstone" ;; esac =20 @@ -7288,11 +7248,6 @@ fi if test "$ivshmem" =3D "yes" ; then echo "CONFIG_IVSHMEM=3Dy" >> $config_host_mak fi -if test "$capstone" !=3D "no" ; then - echo "CONFIG_CAPSTONE=3Dy" >> $config_host_mak - echo "CAPSTONE_CFLAGS=3D$capstone_cflags" >> $config_host_mak - echo "CAPSTONE_LIBS=3D$capstone_libs" >> $config_host_mak -fi if test "$debug_mutex" =3D "yes" ; then echo "CONFIG_DEBUG_MUTEX=3Dy" >> $config_host_mak fi @@ -7816,9 +7771,6 @@ done # for target in $targets if [ "$fdt" =3D "git" ]; then subdirs=3D"$subdirs dtc" fi -if [ "$capstone" =3D "git" -o "$capstone" =3D "internal" ]; then - subdirs=3D"$subdirs capstone" -fi echo "SUBDIRS=3D$subdirs" >> $config_host_mak if test -n "$LIBCAPSTONE"; then echo "LIBCAPSTONE=3D$LIBCAPSTONE" >> $config_host_mak @@ -8005,7 +7957,8 @@ NINJA=3D${ninja:-$PWD/ninjatool} $meson setup \ -Db_coverage=3D$(if test "$gcov" =3D yes; then echo true; else ech= o false; fi) \ -Dsdl=3D$sdl -Dsdl_image=3D$sdl_image \ -Dvnc=3D$vnc -Dvnc_sasl=3D$vnc_sasl -Dvnc_jpeg=3D$vnc_jpeg -Dvnc_png=3D$v= nc_png \ - -Dgettext=3D$gettext -Dxkbcommon=3D$xkbcommon -Du2f=3D$u2f\ + -Dgettext=3D$gettext -Dxkbcommon=3D$xkbcommon -Du2f=3D$u2f \ + -Dcapstone=3D$capstone \ $cross_arg \ "$PWD" "$source_path" =20 diff --git a/Makefile b/Makefile index 7c60b9dcb8..f3da1760ad 100644 --- a/Makefile +++ b/Makefile @@ -156,22 +156,6 @@ dtc/all: .git-submodule-status dtc/libfdt dtc/%: .git-submodule-status @mkdir -p $@ =20 -# Overriding CFLAGS causes us to lose defines added in the sub-makefile. -# Not overriding CFLAGS leads to mis-matches between compilation modes. -# Therefore we replicate some of the logic in the sub-makefile. -# Remove all the extra -Warning flags that QEMU uses that Capstone doesn't; -# no need to annoy QEMU developers with such things. -CAP_CFLAGS =3D $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS)) $(CAPSTONE_CFLAGS) -CAP_CFLAGS +=3D -DCAPSTONE_USE_SYS_DYN_MEM -CAP_CFLAGS +=3D -DCAPSTONE_HAS_ARM -CAP_CFLAGS +=3D -DCAPSTONE_HAS_ARM64 -CAP_CFLAGS +=3D -DCAPSTONE_HAS_POWERPC -CAP_CFLAGS +=3D -DCAPSTONE_HAS_X86 - -.PHONY: capstone/all -capstone/all: .git-submodule-status - $(call quiet-command,$(MAKE) -C $(SRC_PATH)/capstone CAPSTONE_SHARED=3Dno= BUILDDIR=3D"$(BUILD_DIR)/capstone" CC=3D"$(CC)" AR=3D"$(AR)" LD=3D"$(LD)" = RANLIB=3D"$(RANLIB)" CFLAGS=3D"$(CAP_CFLAGS)" $(SUBDIR_MAKEFLAGS) $(BUILD_D= IR)/capstone/$(LIBCAPSTONE)) - .PHONY: slirp/all slirp/all: .git-submodule-status $(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp \ diff --git a/meson.build b/meson.build index 690723b470..df7d2eb52f 100644 --- a/meson.build +++ b/meson.build @@ -10,6 +10,7 @@ else keyval =3D import('unstable-keyval') endif ss =3D import('sourceset') +fs =3D import('fs') =20 sh =3D find_program('sh') cc =3D meson.get_compiler('c') @@ -415,11 +416,6 @@ if 'CONFIG_USB_LIBUSB' in config_host libusb =3D declare_dependency(compile_args: config_host['LIBUSB_CFLAGS']= .split(), link_args: config_host['LIBUSB_LIBS'].split(= )) endif -capstone =3D not_found -if 'CONFIG_CAPSTONE' in config_host - capstone =3D declare_dependency(compile_args: config_host['CAPSTONE_CFLA= GS'].split(), - link_args: config_host['CAPSTONE_LIBS'].sp= lit()) -endif libpmem =3D not_found if 'CONFIG_LIBPMEM' in config_host libpmem =3D declare_dependency(compile_args: config_host['LIBPMEM_CFLAGS= '].split(), @@ -476,7 +472,6 @@ foreach k, v: config_host config_host_data.set(k, v =3D=3D 'y' ? 1 : v) endif endforeach -genh +=3D configure_file(output: 'config-host.h', configuration: config_ho= st_data) =20 minikconf =3D find_program('scripts/minikconf.py') config_all_devices =3D {} @@ -616,6 +611,106 @@ config_all +=3D { 'CONFIG_ALL': true, } =20 +capstone =3D not_found +capstone_opt =3D get_option('capstone') +if capstone_opt =3D=3D 'no' + capstone_opt =3D false +elif capstone_opt in ['yes', 'auto', 'system'] + have_internal =3D fs.exists('capstone/Makefile') + capstone =3D dependency('capstone', static: enable_static, + required: capstone_opt =3D=3D 'system' or + capstone_opt =3D=3D 'yes' and not have_i= nternal) + if capstone.found() + capstone_opt =3D 'system' + elif have_internal + capstone_opt =3D 'internal' + else + capstone_opt =3D false + endif +endif +if capstone_opt =3D=3D 'internal' + capstone_data =3D configuration_data() + capstone_data.set('CAPSTONE_USE_SYS_DYN_MEM', '1') + + capstone_files =3D files( + 'capstone/cs.c', + 'capstone/MCInst.c', + 'capstone/MCInstrDesc.c', + 'capstone/MCRegisterInfo.c', + 'capstone/SStream.c', + 'capstone/utils.c' + ) + + if 'CONFIG_ARM_DIS' in config_all_disas + capstone_data.set('CAPSTONE_HAS_ARM', '1') + capstone_files +=3D files( + 'capstone/arch/ARM/ARMDisassembler.c', + 'capstone/arch/ARM/ARMInstPrinter.c', + 'capstone/arch/ARM/ARMMapping.c', + 'capstone/arch/ARM/ARMModule.c' + ) + endif + + # FIXME: This config entry currently depends on a c++ compiler. + # Which is needed for building libvixl, but not for capstone. + if 'CONFIG_ARM_A64_DIS' in config_all_disas + capstone_data.set('CAPSTONE_HAS_ARM64', '1') + capstone_files +=3D files( + 'capstone/arch/AArch64/AArch64BaseInfo.c', + 'capstone/arch/AArch64/AArch64Disassembler.c', + 'capstone/arch/AArch64/AArch64InstPrinter.c', + 'capstone/arch/AArch64/AArch64Mapping.c', + 'capstone/arch/AArch64/AArch64Module.c' + ) + endif + + if 'CONFIG_PPC_DIS' in config_all_disas + capstone_data.set('CAPSTONE_HAS_POWERPC', '1') + capstone_files +=3D files( + 'capstone/arch/PowerPC/PPCDisassembler.c', + 'capstone/arch/PowerPC/PPCInstPrinter.c', + 'capstone/arch/PowerPC/PPCMapping.c', + 'capstone/arch/PowerPC/PPCModule.c' + ) + endif + + if 'CONFIG_I386_DIS' in config_all_disas + capstone_data.set('CAPSTONE_HAS_X86', 1) + capstone_files +=3D files( + 'capstone/arch/X86/X86Disassembler.c', + 'capstone/arch/X86/X86DisassemblerDecoder.c', + 'capstone/arch/X86/X86ATTInstPrinter.c', + 'capstone/arch/X86/X86IntelInstPrinter.c', + 'capstone/arch/X86/X86Mapping.c', + 'capstone/arch/X86/X86Module.c' + ) + endif + + configure_file(output: 'capstone-defs.h', configuration: capstone_data) + + capstone_cargs =3D [ + # FIXME: There does not seem to be a way to completely replace the c_a= rgs + # that come from add_project_arguments() -- we can only add to them. + # So: disable all warnings with a big hammer. + '-Wno-error', '-w', + + # Include all configuration defines via a header file, which will wind= up + # as a dependency on the object file, and thus changes here will result + # in a rebuild. + '-include', 'capstone-defs.h' + ] + + libcapstone =3D static_library('capstone', + sources: capstone_files, + c_args: capstone_cargs, + include_directories: 'capstone/include') + capstone =3D declare_dependency(link_with: libcapstone, + include_directories: 'capstone/include') +endif +config_host_data.set('CONFIG_CAPSTONE', capstone.found()) + +genh +=3D configure_file(output: 'config-host.h', configuration: config_ho= st_data) + # Generators =20 hxtool =3D find_program('scripts/hxtool') @@ -1518,7 +1613,7 @@ summary_info +=3D {'vvfat support': config_host.h= as_key('CONFIG_VVFAT')} summary_info +=3D {'qed support': config_host.has_key('CONFIG_QED')} summary_info +=3D {'parallels support': config_host.has_key('CONFIG_PARALL= ELS')} summary_info +=3D {'sheepdog support': config_host.has_key('CONFIG_SHEEPD= OG')} -summary_info +=3D {'capstone': config_host.has_key('CONFIG_CAPSTO= NE')} +summary_info +=3D {'capstone': capstone_opt} summary_info +=3D {'libpmem support': config_host.has_key('CONFIG_LIBPME= M')} summary_info +=3D {'libdaxctl support': config_host.has_key('CONFIG_LIBDAX= CTL')} summary_info +=3D {'libudev': config_host.has_key('CONFIG_LIBUDE= V')} diff --git a/meson_options.txt b/meson_options.txt index 543cf70043..f6a1b8ad21 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -22,3 +22,7 @@ option('vnc_sasl', type : 'feature', value : 'auto', description: 'SASL authentication for VNC server') option('xkbcommon', type : 'feature', value : 'auto', description: 'xkbcommon support') + +option('capstone', type: 'combo', value: 'no', + choices: ['no', 'yes', 'auto', 'system', 'internal'], + description: 'Whether and how to find the capstone library') --=20 2.25.1 From nobody Sat May 4 05:29:20 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600124757; cv=none; d=zohomail.com; s=zohoarc; b=ZNy1GwEut2U5yJc5DGeh2zyLXtJl9HBXNUS0GFuu41Pcgkf21LaTIUqdhu2bXdr+sDOvBQ5dMr/Szg6TWgW49EP8O9AfuxVQ0sN4MbtOFvq1H1sd0Sp+OnPpb9QM2tnhuRkvvEnaM9rqqAVZG+hYaChcHY3cgGy8oiozoW/97Jk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600124757; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2HG6KEW7qktQOtGssjrwwM3B6qNk6TpaJpF0ge2S31g=; b=JT6OF1hUSJBIWfefvDCLf/h/x4GaNDE2tCfttiea7QI3KewJkun+AtnWd6ffo5lZg4d433UrAddTNztwJFjeFVQc+SV5BmXwfEX0BgaEWJ3OUB+rjQ2KySjBKadyiHdbjxaIWTrLjqwfI035aOXeeXhm5yxR90+CGzMrV6V0fqw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600124757246415.8275248826918; Mon, 14 Sep 2020 16:05:57 -0700 (PDT) Received: from localhost ([::1]:40718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHxXm-0005Lk-Vo for importer@patchew.org; Mon, 14 Sep 2020 19:05:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33644) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHxUI-0000t6-IV for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:18 -0400 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:37735) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHxUH-0006a2-0Y for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:18 -0400 Received: by mail-pj1-x1042.google.com with SMTP id kk9so723785pjb.2 for ; Mon, 14 Sep 2020 16:02:16 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id l23sm9106076pgt.16.2020.09.14.16.02.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 16:02:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2HG6KEW7qktQOtGssjrwwM3B6qNk6TpaJpF0ge2S31g=; b=GuubmxioeUKeJyFqPgyDdkJv9wSbBF78RqD0CeckpM6teJLShkohBPFQGt5IJ9uwwy BEYlu+Hgw00vScXE5M5G2fMJseKGbzj1CACG88WuF1gXds+D7KdBHvJp+sIdSFBxo8Bd X0tmEAXrvgtJrwWTITI4w1ZrsUvxToaE9djYOGi96lepC1C+7c3xGxqN2/+GghqkC+TF qXnByWmKbTmmxwoyoPyG9of+E2Yyee38kqCsMIwDsea2Tf83YXHww/QOsKRcTRxl865e HFJr1JqtrYPHyrtcOZvviCfe4gAGSty5+N35cC7mYpZHz3IfZm+dQi2mBm9Im3zwiio1 t/AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2HG6KEW7qktQOtGssjrwwM3B6qNk6TpaJpF0ge2S31g=; b=YFIRfRaTUIxa8kKlw4uC7iPqTOxMXr4Yj940gmJ9F2/KEQDYd/bWMq+ksImTdhWbdC YPwh564a7NFLskCI31h2vIVKiwm9S9vRJhmeH/JcEXjKebcqIO9NaZ40DDfJcStTkCpr v9ss37oJohHiubw/99JJwoMwjxZew24Ga6Z7tEC3vdR3evGy0UAWitLDPnlUMZoinEv9 XuTTLk2w5OhkrHOzev2uV1TsHYFMy2NeMxK/IUPD+Cb79ud2PVXVwx5kBicENeowUF7f y4B1+4TJlyu/BnKscMazhoKdIbJ/e2pv/kV4Oil4fFa6EOfJ0yf4KUjMTqvhzOTCo9HN eZ4A== X-Gm-Message-State: AOAM530dJ4yl2N1CIUQtj96WOzMCh3aK2384V+CcVjr19rwDpFqDXpyT MU28YN/tJN18/JYyIeb5r/SJAkKhUloi+Q== X-Google-Smtp-Source: ABdhPJz2cUE5iu+TTErqNFSzv4Ze07k4KrKSoIJkRcoMBKOOVXCN/8u2yrmsdkHjfHYt8FQkZ1/SsA== X-Received: by 2002:a17:90a:e02:: with SMTP id v2mr1440479pje.6.1600124535400; Mon, 14 Sep 2020 16:02:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 02/10] capstone: Update to upstream "next" branch Date: Mon, 14 Sep 2020 16:02:02 -0700 Message-Id: <20200914230210.2185860-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914230210.2185860-1-richard.henderson@linaro.org> References: <20200914230210.2185860-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1042; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1042.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This branch contains a number of improvements over master, including making all of the disassembler data constant. We are skipping past the 4.0 branchpoint, which changed the location of the includes within the source directory. Tested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- capstone | 2 +- meson.build | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/capstone b/capstone index 22ead3e0bf..f8b1b83301 160000 --- a/capstone +++ b/capstone @@ -1 +1 @@ -Subproject commit 22ead3e0bfdb87516656453336160e0a37b066bf +Subproject commit f8b1b833015a4ae47110ed068e0deb7106ced66d diff --git a/meson.build b/meson.build index df7d2eb52f..cbb8257d6b 100644 --- a/meson.build +++ b/meson.build @@ -681,6 +681,7 @@ if capstone_opt =3D=3D 'internal' 'capstone/arch/X86/X86DisassemblerDecoder.c', 'capstone/arch/X86/X86ATTInstPrinter.c', 'capstone/arch/X86/X86IntelInstPrinter.c', + 'capstone/arch/X86/X86InstPrinterCommon.c', 'capstone/arch/X86/X86Mapping.c', 'capstone/arch/X86/X86Module.c' ) @@ -705,7 +706,7 @@ if capstone_opt =3D=3D 'internal' c_args: capstone_cargs, include_directories: 'capstone/include') capstone =3D declare_dependency(link_with: libcapstone, - include_directories: 'capstone/include') + include_directories: 'capstone/include/cap= stone') endif config_host_data.set('CONFIG_CAPSTONE', capstone.found()) =20 --=20 2.25.1 From nobody Sat May 4 05:29:20 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600124625; cv=none; d=zohomail.com; s=zohoarc; b=a3JFCpvLHOZj8fED+ktwdSrx+gg5+l/UgAsSrpsRUiwTir+5PaS3T6Um84F3A4cDpQU5e/CIauE7+nvMn14cjUjR8mrDQ4prt2CxADgzTyYyqjhjRWTC4siwrUzcdZrPAwS3pZXPP6ZKrLUBfNQ7q45tBBmXEzNx0pWSZ6IutRw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600124625; 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=O5tftEr4wcy+EcfeUo13CTd2wMJ9pZ9l7p7m81TmeOA=; b=cqcPfcJNyRtlaeYHifeR8IjYTmf3DcwP/rQH0Hw+piDg1n08NgBd5f2IC9v8bX8c5Vc91sqneWZm9gzcR4mPCYRlTbDtIgWOTPEwWKj4zWV5HNpXJXGX6HTDBji4kdXfqWNnXYvYgNZrjdR7f94ZeVHMzG2FYuxxgyEEO8FzbWE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600124625259739.8835488789919; Mon, 14 Sep 2020 16:03:45 -0700 (PDT) Received: from localhost ([::1]:33862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHxVg-0002YG-2V for importer@patchew.org; Mon, 14 Sep 2020 19:03:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33666) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHxUK-0000vO-ED for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:20 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:37588) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHxUI-0006aM-G7 for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:20 -0400 Received: by mail-pl1-x629.google.com with SMTP id u9so291839plk.4 for ; Mon, 14 Sep 2020 16:02:18 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id l23sm9106076pgt.16.2020.09.14.16.02.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 16:02:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O5tftEr4wcy+EcfeUo13CTd2wMJ9pZ9l7p7m81TmeOA=; b=qTn+S/sjqQ+bcsb9+z9xX43/4W5MQf8c1MFy681kjsJKBX/ZmlhK7gv3eR1XbFgL5x 6KbcCG11Coru2vGjy83Mp151pXdYE1rwINqEnZVJbiM3sTwDlIIV4JqzBnt1svcXImAl ww18dF9bx0MNyiFO8slYHfgnBvMMrJEkjiMoFzjtAgdgp1TuHxzYNkALW7rX+GcAZ7yv LN1wF6fdQo0nzllTVU/mkh3D9MUMmHS59t/OeirPkJbbppXfcEOY+Sk4r7X7NLG0vI9H BK0Q/knDK1RXcJGwVWVXTt/RJxO7xERnh2pnzvfNMs0b0t5Nx4wOqtjL4O9HpHchCCpw 3Jhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O5tftEr4wcy+EcfeUo13CTd2wMJ9pZ9l7p7m81TmeOA=; b=KUNN8p5xGCeamHXMIUvnhnHoSAY6nwAz/qHVuoLWZdXKUcKDjOeXvXV15TdXy0n+19 Ql2ILkwYhUtId3RdRKrN7sFq7dT+QuhUPzvQCC7gUYXHWIsSiJikXc5SamcYcOj0p31g CKlxutypZB1naoGevp7iVlApoGiT7rY1A4YFhooiV9ACVBnViFOvtmrIgGBoxEeW47HM VHiNWMGmgN0LNE3RfEVhxPkzuV8XDO4Q8fm4IgoKBJw2QJ1mFKeUsCOfIAG37OS2HPYQ /jRQgWRAyOyLOnoL13qwMXZ8nTXtngQRi98zq0KFHraKbRVM2LjqpRaNEUdFudk2idZh LGHQ== X-Gm-Message-State: AOAM532Gr8ZvP2AL3US50QxykcmZ7cxk0vdfLcVrdrdcrueMpuEakMMZ oltLI1fmEOe9+sXT2QgDqfr7hZyHmm+DEQ== X-Google-Smtp-Source: ABdhPJzrkjSX1h6oiG0Xnlnrqml3KjeMjvm4yWFcU/it+hYB+lGo3PMvzYl1VrDItX8DE9m4sfiqEA== X-Received: by 2002:a17:90a:5304:: with SMTP id x4mr1400156pjh.16.1600124536586; Mon, 14 Sep 2020 16:02:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 03/10] disas: Move host asm annotations to tb_gen_code Date: Mon, 14 Sep 2020 16:02:03 -0700 Message-Id: <20200914230210.2185860-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914230210.2185860-1-richard.henderson@linaro.org> References: <20200914230210.2185860-1-richard.henderson@linaro.org> 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::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Instead of creating GStrings and passing them into log_disas, just print the annotations directly in tb_gen_code. Fix the annotations for the slow paths of the TB, after the part implementing the final guest instruction. Signed-off-by: Richard Henderson Reviewed-by: Thomas Huth --- include/disas/disas.h | 2 +- include/exec/log.h | 4 ++-- accel/tcg/translate-all.c | 24 +++++++++++++++--------- disas.c | 29 +++++++++-------------------- tcg/tcg.c | 4 ++-- 5 files changed, 29 insertions(+), 34 deletions(-) diff --git a/include/disas/disas.h b/include/disas/disas.h index 1b6e035e32..36c33f6f19 100644 --- a/include/disas/disas.h +++ b/include/disas/disas.h @@ -7,7 +7,7 @@ #include "cpu.h" =20 /* Disassemble this for me please... (debugging). */ -void disas(FILE *out, void *code, unsigned long size, const char *note); +void disas(FILE *out, void *code, unsigned long size); void target_disas(FILE *out, CPUState *cpu, target_ulong code, target_ulong size); =20 diff --git a/include/exec/log.h b/include/exec/log.h index 3ed797c1c8..fcc7b9e00b 100644 --- a/include/exec/log.h +++ b/include/exec/log.h @@ -56,13 +56,13 @@ static inline void log_target_disas(CPUState *cpu, targ= et_ulong start, rcu_read_unlock(); } =20 -static inline void log_disas(void *code, unsigned long size, const char *n= ote) +static inline void log_disas(void *code, unsigned long size) { QemuLogFile *logfile; rcu_read_lock(); logfile =3D atomic_rcu_read(&qemu_logfile); if (logfile) { - disas(logfile->fd, code, size, note); + disas(logfile->fd, code, size); } rcu_read_unlock(); } diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 2d83013633..2874104a6a 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1815,10 +1815,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu, qemu_log_in_addr_range(tb->pc)) { FILE *logfile =3D qemu_log_lock(); int code_size, data_size =3D 0; - g_autoptr(GString) note =3D g_string_new("[tb header & initial ins= truction]"); - size_t chunk_start =3D 0; + size_t chunk_start; int insn =3D 0; - qemu_log("OUT: [size=3D%d]\n", gen_code_size); + if (tcg_ctx->data_gen_ptr) { code_size =3D tcg_ctx->data_gen_ptr - tb->tc.ptr; data_size =3D gen_code_size - code_size; @@ -1827,26 +1826,33 @@ TranslationBlock *tb_gen_code(CPUState *cpu, } =20 /* Dump header and the first instruction */ + qemu_log("OUT: [size=3D%d]\n", gen_code_size); + qemu_log(" -- guest addr 0x" TARGET_FMT_lx " + tb prologue\n", + tcg_ctx->gen_insn_data[insn][0]); chunk_start =3D tcg_ctx->gen_insn_end_off[insn]; - log_disas(tb->tc.ptr, chunk_start, note->str); + log_disas(tb->tc.ptr, chunk_start); =20 /* * Dump each instruction chunk, wrapping up empty chunks into * the next instruction. The whole array is offset so the * first entry is the beginning of the 2nd instruction. */ - while (insn <=3D tb->icount && chunk_start < code_size) { + while (insn < tb->icount) { size_t chunk_end =3D tcg_ctx->gen_insn_end_off[insn]; if (chunk_end > chunk_start) { - g_string_printf(note, "[guest addr: " TARGET_FMT_lx "]", - tcg_ctx->gen_insn_data[insn][0]); - log_disas(tb->tc.ptr + chunk_start, chunk_end - chunk_star= t, - note->str); + qemu_log(" -- guest addr 0x" TARGET_FMT_lx "\n", + tcg_ctx->gen_insn_data[insn][0]); + log_disas(tb->tc.ptr + chunk_start, chunk_end - chunk_star= t); chunk_start =3D chunk_end; } insn++; } =20 + if (chunk_start < code_size) { + qemu_log(" -- tb slow paths + alignment\n"); + log_disas(tb->tc.ptr + chunk_start, code_size - chunk_start); + } + /* Finally dump any data we may have after the block */ if (data_size) { int i; diff --git a/disas.c b/disas.c index c1397d3933..a4304e8137 100644 --- a/disas.c +++ b/disas.c @@ -262,8 +262,7 @@ static void cap_dump_insn_units(disassemble_info *info,= cs_insn *insn, } } =20 -static void cap_dump_insn(disassemble_info *info, cs_insn *insn, - const char *note) +static void cap_dump_insn(disassemble_info *info, cs_insn *insn) { fprintf_function print =3D info->fprintf_func; int i, n, split; @@ -284,11 +283,7 @@ static void cap_dump_insn(disassemble_info *info, cs_i= nsn *insn, } =20 /* Print the actual instruction. */ - print(info->stream, " %-8s %s", insn->mnemonic, insn->op_str); - if (note) { - print(info->stream, "\t\t%s", note); - } - print(info->stream, "\n"); + print(info->stream, " %-8s %s\n", insn->mnemonic, insn->op_str); =20 /* Dump any remaining part of the insn on subsequent lines. */ for (i =3D split; i < n; i +=3D split) { @@ -320,7 +315,7 @@ static bool cap_disas_target(disassemble_info *info, ui= nt64_t pc, size_t size) size -=3D tsize; =20 while (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { - cap_dump_insn(info, insn, NULL); + cap_dump_insn(info, insn); } =20 /* If the target memory is not consumed, go back for more... */ @@ -349,8 +344,7 @@ static bool cap_disas_target(disassemble_info *info, ui= nt64_t pc, size_t size) } =20 /* Disassemble SIZE bytes at CODE for the host. */ -static bool cap_disas_host(disassemble_info *info, void *code, size_t size, - const char *note) +static bool cap_disas_host(disassemble_info *info, void *code, size_t size) { csh handle; const uint8_t *cbuf; @@ -366,8 +360,7 @@ static bool cap_disas_host(disassemble_info *info, void= *code, size_t size, pc =3D (uintptr_t)code; =20 while (cs_disasm_iter(handle, &cbuf, &size, &pc, insn)) { - cap_dump_insn(info, insn, note); - note =3D NULL; + cap_dump_insn(info, insn); } if (size !=3D 0) { (*info->fprintf_func)(info->stream, @@ -411,7 +404,7 @@ static bool cap_disas_monitor(disassemble_info *info, u= int64_t pc, int count) csize +=3D tsize; =20 if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { - cap_dump_insn(info, insn, NULL); + cap_dump_insn(info, insn); if (--count <=3D 0) { break; } @@ -425,7 +418,7 @@ static bool cap_disas_monitor(disassemble_info *info, u= int64_t pc, int count) #endif /* !CONFIG_USER_ONLY */ #else # define cap_disas_target(i, p, s) false -# define cap_disas_host(i, p, s, n) false +# define cap_disas_host(i, p, s) false # define cap_disas_monitor(i, p, c) false # define cap_disas_plugin(i, p, c) false #endif /* CONFIG_CAPSTONE */ @@ -595,7 +588,7 @@ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t= size) } =20 /* Disassemble this for me please... (debugging). */ -void disas(FILE *out, void *code, unsigned long size, const char *note) +void disas(FILE *out, void *code, unsigned long size) { uintptr_t pc; int count; @@ -673,7 +666,7 @@ void disas(FILE *out, void *code, unsigned long size, c= onst char *note) print_insn =3D print_insn_hppa; #endif =20 - if (s.info.cap_arch >=3D 0 && cap_disas_host(&s.info, code, size, note= )) { + if (s.info.cap_arch >=3D 0 && cap_disas_host(&s.info, code, size)) { return; } =20 @@ -683,10 +676,6 @@ void disas(FILE *out, void *code, unsigned long size, = const char *note) for (pc =3D (uintptr_t)code; size > 0; pc +=3D count, size -=3D count)= { fprintf(out, "0x%08" PRIxPTR ": ", pc); count =3D print_insn(pc, &s.info); - if (note) { - fprintf(out, "\t\t%s", note); - note =3D NULL; - } fprintf(out, "\n"); if (count < 0) { break; diff --git a/tcg/tcg.c b/tcg/tcg.c index 62f299e36e..9a111ce604 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1101,7 +1101,7 @@ void tcg_prologue_init(TCGContext *s) size_t data_size =3D prologue_size - code_size; size_t i; =20 - log_disas(buf0, code_size, NULL); + log_disas(buf0, code_size); =20 for (i =3D 0; i < data_size; i +=3D sizeof(tcg_target_ulong)) { if (sizeof(tcg_target_ulong) =3D=3D 8) { @@ -1115,7 +1115,7 @@ void tcg_prologue_init(TCGContext *s) } } } else { - log_disas(buf0, prologue_size, NULL); + log_disas(buf0, prologue_size); } qemu_log("\n"); qemu_log_flush(); --=20 2.25.1 From nobody Sat May 4 05:29:20 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600124762; cv=none; d=zohomail.com; s=zohoarc; b=HgQE3gjidxWmKhkglJB420C57OR4BCejGirghyQm71mVhKcoe723Ql8UinotLfPtHHAAiMFGkJU+vUJLAkZrui3jmIP6yAIYCyHfUGBJWRSqMnfIGhxZmNRao25+HVPUz/TkSJQZS58CJJz7x2c05vuOgt8bkWNMhTZRVAYGGJ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600124762; 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=4sUdV+AnKoygPiDGGXDfquQaBC+pBrFSbVXWz1IneU0=; b=g9nwJt4uJISYJ0zFFNLQCrKZJkWLsHuInE9foPh4zL30snvnD6oB8ZAQ/3R9renhQIEomzYTXRozBhjC96BxUbXCtwAlfa90imEsm1w1RmdPlml1YoJrCIXPmnvMOJP/NqOUTrAMZ3sTNyDwdPV1turtXYaPOTmScCz3/oXLtwI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600124762550839.4988075270309; Mon, 14 Sep 2020 16:06:02 -0700 (PDT) Received: from localhost ([::1]:41166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHxXt-0005Wf-E1 for importer@patchew.org; Mon, 14 Sep 2020 19:06:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33716) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHxUM-000108-V6 for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:22 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:38052) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHxUK-0006ak-6d for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:22 -0400 Received: by mail-pj1-x1043.google.com with SMTP id u3so718984pjr.3 for ; Mon, 14 Sep 2020 16:02:19 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id l23sm9106076pgt.16.2020.09.14.16.02.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 16:02:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hM6sB1a7DdXHdlE2+8qZ9MvtJp4Ce+lQYnkPJOeT+SU=; b=jpvojOfJXT87XTptHha4Wj9YaZBweyjM48BVT573jV46KPf5O6mRWmcWsKDn+z7uwo QIWQBAKdUZUsMcfRwua8ujFyUk42Ea8D3QCYdt/mHWSs21yga2LVPTcCn88mzCY0Th29 Pi357BXH+UMSLkNKRjcU82B+sETmjG4+fcuQ1LEApFZs7gTBSBfsbhcuA1hlJ9Du2sy4 amKCicDJ9Z1Sqe85LbuZSjq39JFaSuOQLLmueB+eIl7AG0udX7sNB+NdSzCtHNVI/wX2 Ylvppg0r5Jgl6CpuGnopBJnS6z7piph4mCbdG1VHXura46unzvRMONf8lI1nDNBM95fh stWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hM6sB1a7DdXHdlE2+8qZ9MvtJp4Ce+lQYnkPJOeT+SU=; b=HrhWlYUZLdMTjWyQufAyrKPSm2ClhorJBm+35BrxC7m2afmoPPhPgYAmdGcN7d3TeP foy9tbsv2zzMSrCstk8QMJVXeWYCFbiB19I8Z14q/9ebSQ5AtG/+SIyYfYo2pxeNffCA ejT3JCevQKbvXahKtPsY6cInMcMfAHl8wDmouozG0jeoQ1TECGSy9357FkB9gqlqr0w6 CDZ51hG+LSIs6qpsCJVj/uoWN39ABcMtCQ3yio2iEl1O0sBpZSbmOab1ywNz82bjiBGC pUEXPHByEC2sEJ9JJyFx91dEamME/ET/mzzFYBe0LN78kyGKsmT2CZeoaDBWG2thifJs 7hrw== X-Gm-Message-State: AOAM532sycw45HCXYFFBwl024bT4irzllclOWOs1FCJPN53tgPogk2pd jcHordCEdLMBcliyjgGO2+HVti0qiu+Kqw== X-Google-Smtp-Source: ABdhPJzPKX+t54bDSfbK2Nw9Ubxc3rHtB/8ig+h3NsIFH80cvBdu4KN+Yp82g7XcgsCXflMe0PaEZQ== X-Received: by 2002:a17:90b:4b09:: with SMTP id lx9mr1457251pjb.76.1600124537834; Mon, 14 Sep 2020 16:02:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 04/10] disas: Clean up CPUDebug initialization Date: Mon, 14 Sep 2020 16:02:04 -0700 Message-Id: <20200914230210.2185860-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914230210.2185860-1-richard.henderson@linaro.org> References: <20200914230210.2185860-1-richard.henderson@linaro.org> 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::1043; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1043.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_PDS_OTHER_BAD_TLD=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Rename several functions, dropping "generic" and making "host" vs "target" clearer. Make a bunch of functions static that are not used outside this file. Replace INIT_DISASSEMBLE_INFO with a trio of functions. Signed-off-by: Richard Henderson Acked-by: Thomas Huth --- include/disas/dis-asm.h | 60 -------- disas.c | 326 ++++++++++++++++++---------------------- 2 files changed, 148 insertions(+), 238 deletions(-) diff --git a/include/disas/dis-asm.h b/include/disas/dis-asm.h index 9856bf7921..d2418c977e 100644 --- a/include/disas/dis-asm.h +++ b/include/disas/dis-asm.h @@ -461,67 +461,7 @@ int print_insn_riscv32 (bfd_vma, disassemble_= info*); int print_insn_riscv64 (bfd_vma, disassemble_info*); int print_insn_rx(bfd_vma, disassemble_info *); =20 -#if 0 -/* Fetch the disassembler for a given BFD, if that support is available. = */ -disassembler_ftype disassembler(bfd *); -#endif - =0C -/* This block of definitions is for particular callers who read instructio= ns - into a buffer before calling the instruction decoder. */ - -/* Here is a function which callers may wish to use for read_memory_func. - It gets bytes from a buffer. */ -int buffer_read_memory(bfd_vma, bfd_byte *, int, struct disassemble_info *= ); - -/* This function goes with buffer_read_memory. - It prints a message using info->fprintf_func and info->stream. */ -void perror_memory(int, bfd_vma, struct disassemble_info *); - - -/* Just print the address in hex. This is included for completeness even - though both GDB and objdump provide their own (to print symbolic - addresses). */ -void generic_print_address(bfd_vma, struct disassemble_info *); - -/* Always true. */ -int generic_symbol_at_address(bfd_vma, struct disassemble_info *); - -/* Macro to initialize a disassemble_info struct. This should be called - by all applications creating such a struct. */ -#define INIT_DISASSEMBLE_INFO(INFO, STREAM, FPRINTF_FUNC) \ - (INFO).flavour =3D bfd_target_unknown_flavour, \ - (INFO).arch =3D bfd_arch_unknown, \ - (INFO).mach =3D 0, \ - (INFO).endian =3D BFD_ENDIAN_UNKNOWN, \ - INIT_DISASSEMBLE_INFO_NO_ARCH(INFO, STREAM, FPRINTF_FUNC) - -/* Call this macro to initialize only the internal variables for the - disassembler. Architecture dependent things such as byte order, or mac= hine - variant are not touched by this macro. This makes things much easier f= or - GDB which must initialize these things separately. */ - -#define INIT_DISASSEMBLE_INFO_NO_ARCH(INFO, STREAM, FPRINTF_FUNC) \ - (INFO).fprintf_func =3D (FPRINTF_FUNC), \ - (INFO).stream =3D (STREAM), \ - (INFO).symbols =3D NULL, \ - (INFO).num_symbols =3D 0, \ - (INFO).private_data =3D NULL, \ - (INFO).buffer =3D NULL, \ - (INFO).buffer_vma =3D 0, \ - (INFO).buffer_length =3D 0, \ - (INFO).read_memory_func =3D buffer_read_memory, \ - (INFO).memory_error_func =3D perror_memory, \ - (INFO).print_address_func =3D generic_print_address, \ - (INFO).print_insn =3D NULL, \ - (INFO).symbol_at_address_func =3D generic_symbol_at_address, \ - (INFO).flags =3D 0, \ - (INFO).bytes_per_line =3D 0, \ - (INFO).bytes_per_chunk =3D 0, \ - (INFO).display_endian =3D BFD_ENDIAN_UNKNOWN, \ - (INFO).disassembler_options =3D NULL, \ - (INFO).insn_info_valid =3D 0 - #ifndef ATTRIBUTE_UNUSED #define ATTRIBUTE_UNUSED __attribute__((unused)) #endif diff --git a/disas.c b/disas.c index a4304e8137..7bc8e9a037 100644 --- a/disas.c +++ b/disas.c @@ -16,78 +16,66 @@ typedef struct CPUDebug { /* Filled in by elfload.c. Simplistic, but will do for now. */ struct syminfo *syminfos =3D NULL; =20 -/* Get LENGTH bytes from info's buffer, at target address memaddr. - Transfer them to myaddr. */ -int -buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length, - struct disassemble_info *info) +/* + * Get LENGTH bytes from info's buffer, at host address memaddr. + * Transfer them to myaddr. + */ +static int host_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length, + struct disassemble_info *info) { if (memaddr < info->buffer_vma - || memaddr + length > info->buffer_vma + info->buffer_length) + || memaddr + length > info->buffer_vma + info->buffer_length) { /* Out of bounds. Use EIO because GDB uses it. */ return EIO; + } memcpy (myaddr, info->buffer + (memaddr - info->buffer_vma), length); return 0; } =20 -/* Get LENGTH bytes from info's buffer, at target address memaddr. - Transfer them to myaddr. */ -static int -target_read_memory (bfd_vma memaddr, - bfd_byte *myaddr, - int length, - struct disassemble_info *info) +/* + * Get LENGTH bytes from info's buffer, at target address memaddr. + * Transfer them to myaddr. + */ +static int target_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int lengt= h, + struct disassemble_info *info) { CPUDebug *s =3D container_of(info, CPUDebug, info); - int r; - - r =3D cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0); - + int r =3D cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0); return r ? EIO : 0; } =20 /* Print an error message. We can assume that this is in response to - an error return from buffer_read_memory. */ -void -perror_memory (int status, bfd_vma memaddr, struct disassemble_info *info) + an error return from {host,target}_read_memory. */ +static void perror_memory(int status, bfd_vma memaddr, + struct disassemble_info *info) { - if (status !=3D EIO) - /* Can't happen. */ - (*info->fprintf_func) (info->stream, "Unknown error %d\n", status); - else - /* Actually, address between memaddr and memaddr + len was - out of bounds. */ - (*info->fprintf_func) (info->stream, - "Address 0x%" PRIx64 " is out of bounds.\n", memaddr); + if (status !=3D EIO) { + /* Can't happen. */ + info->fprintf_func(info->stream, "Unknown error %d\n", status); + } else { + /* Address between memaddr and memaddr + len was out of bounds. */ + info->fprintf_func(info->stream, + "Address 0x%" PRIx64 " is out of bounds.\n", + memaddr); + } } =20 -/* This could be in a separate file, to save minuscule amounts of space - in statically linked executables. */ - -/* Just print the address is hex. This is included for completeness even - though both GDB and objdump provide their own (to print symbolic - addresses). */ - -void -generic_print_address (bfd_vma addr, struct disassemble_info *info) +/* Print address in hex. */ +static void print_address(bfd_vma addr, struct disassemble_info *info) { - (*info->fprintf_func) (info->stream, "0x%" PRIx64, addr); + info->fprintf_func(info->stream, "0x%" PRIx64, addr); } =20 /* Print address in hex, truncated to the width of a host virtual address.= */ -static void -generic_print_host_address(bfd_vma addr, struct disassemble_info *info) +static void host_print_address(bfd_vma addr, struct disassemble_info *info) { - uint64_t mask =3D ~0ULL >> (64 - (sizeof(void *) * 8)); - generic_print_address(addr & mask, info); + print_address((uintptr_t)addr, info); } =20 -/* Just return the given address. */ - -int -generic_symbol_at_address (bfd_vma addr, struct disassemble_info *info) +/* Stub prevents some fruitless earching in optabs disassemblers. */ +static int symbol_at_address(bfd_vma addr, struct disassemble_info *info) { - return 1; + return 1; } =20 bfd_vma bfd_getl64 (const bfd_byte *addr) @@ -423,36 +411,116 @@ static bool cap_disas_monitor(disassemble_info *info= , uint64_t pc, int count) # define cap_disas_plugin(i, p, c) false #endif /* CONFIG_CAPSTONE */ =20 +static void initialize_debug(CPUDebug *s) +{ + memset(s, 0, sizeof(*s)); + s->info.arch =3D bfd_arch_unknown; + s->info.cap_arch =3D -1; + s->info.cap_insn_unit =3D 4; + s->info.cap_insn_split =3D 4; + s->info.memory_error_func =3D perror_memory; + s->info.symbol_at_address_func =3D symbol_at_address; +} + +static void initialize_debug_target(CPUDebug *s, CPUState *cpu) +{ + initialize_debug(s); + + s->cpu =3D cpu; + s->info.read_memory_func =3D target_read_memory; + s->info.print_address_func =3D print_address; +#ifdef TARGET_WORDS_BIGENDIAN + s->info.endian =3D BFD_ENDIAN_BIG; +#else + s->info.endian =3D BFD_ENDIAN_LITTLE; +#endif + + CPUClass *cc =3D CPU_GET_CLASS(cpu); + if (cc->disas_set_info) { + cc->disas_set_info(cpu, &s->info); + } +} + +static void initialize_debug_host(CPUDebug *s) +{ + initialize_debug(s); + + s->info.read_memory_func =3D host_read_memory; + s->info.print_address_func =3D host_print_address; +#ifdef HOST_WORDS_BIGENDIAN + s->info.endian =3D BFD_ENDIAN_BIG; +#else + s->info.endian =3D BFD_ENDIAN_LITTLE; +#endif +#if defined(CONFIG_TCG_INTERPRETER) + s->info.print_insn =3D print_insn_tci; +#elif defined(__i386__) + s->info.mach =3D bfd_mach_i386_i386; + s->info.print_insn =3D print_insn_i386; + s->info.cap_arch =3D CS_ARCH_X86; + s->info.cap_mode =3D CS_MODE_32; + s->info.cap_insn_unit =3D 1; + s->info.cap_insn_split =3D 8; +#elif defined(__x86_64__) + s->info.mach =3D bfd_mach_x86_64; + s->info.print_insn =3D print_insn_i386; + s->info.cap_arch =3D CS_ARCH_X86; + s->info.cap_mode =3D CS_MODE_64; + s->info.cap_insn_unit =3D 1; + s->info.cap_insn_split =3D 8; +#elif defined(_ARCH_PPC) + s->info.disassembler_options =3D (char *)"any"; + s->info.print_insn =3D print_insn_ppc; + s->info.cap_arch =3D CS_ARCH_PPC; +# ifdef _ARCH_PPC64 + s->info.cap_mode =3D CS_MODE_64; +# endif +#elif defined(__riscv) && defined(CONFIG_RISCV_DIS) +#if defined(_ILP32) || (__riscv_xlen =3D=3D 32) + s->info.print_insn =3D print_insn_riscv32; +#elif defined(_LP64) + s->info.print_insn =3D print_insn_riscv64; +#else +#error unsupported RISC-V ABI +#endif +#elif defined(__aarch64__) && defined(CONFIG_ARM_A64_DIS) + s->info.print_insn =3D print_insn_arm_a64; + s->info.cap_arch =3D CS_ARCH_ARM64; +#elif defined(__alpha__) + s->info.print_insn =3D print_insn_alpha; +#elif defined(__sparc__) + s->info.print_insn =3D print_insn_sparc; + s->info.mach =3D bfd_mach_sparc_v9b; +#elif defined(__arm__) + /* TCG only generates code for arm mode. */ + s->info.print_insn =3D print_insn_arm; + s->info.cap_arch =3D CS_ARCH_ARM; +#elif defined(__MIPSEB__) + s->info.print_insn =3D print_insn_big_mips; +#elif defined(__MIPSEL__) + s->info.print_insn =3D print_insn_little_mips; +#elif defined(__m68k__) + s->info.print_insn =3D print_insn_m68k; +#elif defined(__s390__) + s->info.print_insn =3D print_insn_s390; +#elif defined(__hppa__) + s->info.print_insn =3D print_insn_hppa; +#endif +} + /* Disassemble this for me please... (debugging). */ void target_disas(FILE *out, CPUState *cpu, target_ulong code, target_ulong size) { - CPUClass *cc =3D CPU_GET_CLASS(cpu); target_ulong pc; int count; CPUDebug s; =20 - INIT_DISASSEMBLE_INFO(s.info, out, fprintf); - - s.cpu =3D cpu; - s.info.read_memory_func =3D target_read_memory; + initialize_debug_target(&s, cpu); + s.info.fprintf_func =3D fprintf; + s.info.stream =3D out; s.info.buffer_vma =3D code; s.info.buffer_length =3D size; - s.info.print_address_func =3D generic_print_address; - s.info.cap_arch =3D -1; - s.info.cap_mode =3D 0; - s.info.cap_insn_unit =3D 4; - s.info.cap_insn_split =3D 4; - -#ifdef TARGET_WORDS_BIGENDIAN - s.info.endian =3D BFD_ENDIAN_BIG; -#else - s.info.endian =3D BFD_ENDIAN_LITTLE; -#endif - - if (cc->disas_set_info) { - cc->disas_set_info(cpu, &s.info); - } =20 if (s.info.cap_arch >=3D 0 && cap_disas_target(&s.info, code, size)) { return; @@ -540,34 +608,17 @@ bool cap_disas_plugin(disassemble_info *info, uint64_= t pc, size_t size) */ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size) { - CPUClass *cc =3D CPU_GET_CLASS(cpu); int count; CPUDebug s; GString *ds =3D g_string_set_size(&plugin_disas_output, 0); =20 g_assert(ds =3D=3D &plugin_disas_output); =20 - INIT_DISASSEMBLE_INFO(s.info, NULL, plugin_printf); - - s.cpu =3D cpu; - s.info.read_memory_func =3D target_read_memory; + initialize_debug_target(&s, cpu); + s.info.fprintf_func =3D plugin_printf; s.info.buffer_vma =3D addr; s.info.buffer_length =3D size; s.info.print_address_func =3D plugin_print_address; - s.info.cap_arch =3D -1; - s.info.cap_mode =3D 0; - s.info.cap_insn_unit =3D 4; - s.info.cap_insn_split =3D 4; - -#ifdef TARGET_WORDS_BIGENDIAN - s.info.endian =3D BFD_ENDIAN_BIG; -#else - s.info.endian =3D BFD_ENDIAN_LITTLE; -#endif - - if (cc->disas_set_info) { - cc->disas_set_info(cpu, &s.info); - } =20 if (s.info.cap_arch >=3D 0 && cap_disas_plugin(&s.info, addr, size)) { return g_strdup(ds->str); @@ -593,89 +644,24 @@ void disas(FILE *out, void *code, unsigned long size) uintptr_t pc; int count; CPUDebug s; - int (*print_insn)(bfd_vma pc, disassemble_info *info) =3D NULL; - - INIT_DISASSEMBLE_INFO(s.info, out, fprintf); - s.info.print_address_func =3D generic_print_host_address; =20 + initialize_debug_host(&s); + s.info.fprintf_func =3D fprintf; + s.info.stream =3D out; s.info.buffer =3D code; s.info.buffer_vma =3D (uintptr_t)code; s.info.buffer_length =3D size; - s.info.cap_arch =3D -1; - s.info.cap_mode =3D 0; - s.info.cap_insn_unit =3D 4; - s.info.cap_insn_split =3D 4; - -#ifdef HOST_WORDS_BIGENDIAN - s.info.endian =3D BFD_ENDIAN_BIG; -#else - s.info.endian =3D BFD_ENDIAN_LITTLE; -#endif -#if defined(CONFIG_TCG_INTERPRETER) - print_insn =3D print_insn_tci; -#elif defined(__i386__) - s.info.mach =3D bfd_mach_i386_i386; - print_insn =3D print_insn_i386; - s.info.cap_arch =3D CS_ARCH_X86; - s.info.cap_mode =3D CS_MODE_32; - s.info.cap_insn_unit =3D 1; - s.info.cap_insn_split =3D 8; -#elif defined(__x86_64__) - s.info.mach =3D bfd_mach_x86_64; - print_insn =3D print_insn_i386; - s.info.cap_arch =3D CS_ARCH_X86; - s.info.cap_mode =3D CS_MODE_64; - s.info.cap_insn_unit =3D 1; - s.info.cap_insn_split =3D 8; -#elif defined(_ARCH_PPC) - s.info.disassembler_options =3D (char *)"any"; - print_insn =3D print_insn_ppc; - s.info.cap_arch =3D CS_ARCH_PPC; -# ifdef _ARCH_PPC64 - s.info.cap_mode =3D CS_MODE_64; -# endif -#elif defined(__riscv) && defined(CONFIG_RISCV_DIS) -#if defined(_ILP32) || (__riscv_xlen =3D=3D 32) - print_insn =3D print_insn_riscv32; -#elif defined(_LP64) - print_insn =3D print_insn_riscv64; -#else -#error unsupported RISC-V ABI -#endif -#elif defined(__aarch64__) && defined(CONFIG_ARM_A64_DIS) - print_insn =3D print_insn_arm_a64; - s.info.cap_arch =3D CS_ARCH_ARM64; -#elif defined(__alpha__) - print_insn =3D print_insn_alpha; -#elif defined(__sparc__) - print_insn =3D print_insn_sparc; - s.info.mach =3D bfd_mach_sparc_v9b; -#elif defined(__arm__) - print_insn =3D print_insn_arm; - s.info.cap_arch =3D CS_ARCH_ARM; - /* TCG only generates code for arm mode. */ -#elif defined(__MIPSEB__) - print_insn =3D print_insn_big_mips; -#elif defined(__MIPSEL__) - print_insn =3D print_insn_little_mips; -#elif defined(__m68k__) - print_insn =3D print_insn_m68k; -#elif defined(__s390__) - print_insn =3D print_insn_s390; -#elif defined(__hppa__) - print_insn =3D print_insn_hppa; -#endif =20 if (s.info.cap_arch >=3D 0 && cap_disas_host(&s.info, code, size)) { return; } =20 - if (print_insn =3D=3D NULL) { - print_insn =3D print_insn_od_host; + if (s.info.print_insn =3D=3D NULL) { + s.info.print_insn =3D print_insn_od_host; } for (pc =3D (uintptr_t)code; size > 0; pc +=3D count, size -=3D count)= { fprintf(out, "0x%08" PRIxPTR ": ", pc); - count =3D print_insn(pc, &s.info); + count =3D s.info.print_insn(pc, &s.info); fprintf(out, "\n"); if (count < 0) { break; @@ -720,31 +706,15 @@ physical_read_memory(bfd_vma memaddr, bfd_byte *myadd= r, int length, void monitor_disas(Monitor *mon, CPUState *cpu, target_ulong pc, int nb_insn, int is_physical) { - CPUClass *cc =3D CPU_GET_CLASS(cpu); int count, i; CPUDebug s; =20 - INIT_DISASSEMBLE_INFO(s.info, NULL, qemu_fprintf); - - s.cpu =3D cpu; - s.info.read_memory_func - =3D (is_physical ? physical_read_memory : target_read_memory); - s.info.print_address_func =3D generic_print_address; - s.info.buffer_vma =3D pc; - s.info.cap_arch =3D -1; - s.info.cap_mode =3D 0; - s.info.cap_insn_unit =3D 4; - s.info.cap_insn_split =3D 4; - -#ifdef TARGET_WORDS_BIGENDIAN - s.info.endian =3D BFD_ENDIAN_BIG; -#else - s.info.endian =3D BFD_ENDIAN_LITTLE; -#endif - - if (cc->disas_set_info) { - cc->disas_set_info(cpu, &s.info); + initialize_debug_target(&s, cpu); + s.info.fprintf_func =3D qemu_fprintf; + if (is_physical) { + s.info.read_memory_func =3D physical_read_memory; } + s.info.buffer_vma =3D pc; =20 if (s.info.cap_arch >=3D 0 && cap_disas_monitor(&s.info, pc, nb_insn))= { return; --=20 2.25.1 From nobody Sat May 4 05:29:20 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600124905; cv=none; d=zohomail.com; s=zohoarc; b=OrBRfN3nDC/Lj/KkV1o+2xFFpEKkL4zdg5MsZo+eb/8mQfClUY1L1UAncn3ryUsSkuI5UX9ASdGZB/F9I/zvI/nK4DBlE/oWt6fwJllCc63Pd1NVpn3iejhMqHBAQfV154KiwwomnB+Fb/rgb/dDt2jeVJF8f1zQUrjNNfynqZo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600124905; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Qtxl/BXbvXweTMsYpGrM9mtyoo8FEzJG3RdxXTc8HzE=; b=eF0O7t3x2xxOQVdDdNEGvOAQiCowEVrGEMiRXmlrF52QUjcFE5z++bZImIMFo2YUFYLUtt6OMKRS+IHo+Hu753SvCT0kTaJC4ZrJROGzjG5rkA0Ehr5oWxOX9ezCfGX7d7TPAZLoIaytlJixRjKVi9xk94Up3C+GGkmwWiiYrlc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600124905702690.4160270788929; Mon, 14 Sep 2020 16:08:25 -0700 (PDT) Received: from localhost ([::1]:49420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHxaC-0000UA-KF for importer@patchew.org; Mon, 14 Sep 2020 19:08:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33746) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHxUO-00013G-9F for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:24 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]:36346) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHxUK-0006ap-Ql for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:23 -0400 Received: by mail-pl1-x633.google.com with SMTP id k13so291536plk.3 for ; Mon, 14 Sep 2020 16:02:20 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id l23sm9106076pgt.16.2020.09.14.16.02.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 16:02:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qtxl/BXbvXweTMsYpGrM9mtyoo8FEzJG3RdxXTc8HzE=; b=tyNzmMNJG690Ppb4evlI1Zw2lCXeqLRnrgL03rQOHUuhJ7bAEzghrhQw9Wcpap+QyF ITh8yuCzNXvBTmtbZ/xQBGzDIgXBPAO2/cuNaZQTA4YEtp/yvTmx0+dCjN1HBqK83b3X /pS8Kkpp1POwZFT2MrwUG2lDDoTqRfG2LTpoFtdVA7raFtieMWbDzouv+1jhkRiz0uFJ XewC4btjTnkuasAcmdfhdrwtkbqaguV0bWEW5iBe2h5p1tORQkTWuMUIrTcKk0HvCl6y KPZ4l2wTq0AG642aIUlgBwq0rQrbsx/Wu0xE1D5UPIB7JHe2RbIU7eOIny3iN+dUkJg/ 056g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Qtxl/BXbvXweTMsYpGrM9mtyoo8FEzJG3RdxXTc8HzE=; b=EJZ+D4bWGHxIDwbvAGG/VL/RbAPgr0rgXVPtGF9WfgltizR7AiexCYclIHLw/qGG2I bYqoAqJm0b/XLE0y/IQGGSXbaFyK4SnOji0kncbvze4DJo6OepUFTWogyontgsN/Ca95 KN5jquJQ7JeK6z+2Yz799ZEk2JfstXmCZbXwwLfZ8UhhZzwJ+bnBfJlazy8uQ4MeqOC9 IPulJMr1lojfT9SuGQ045KjSlqYm4BKFHTfqMfKpQ+JU8+xvCl0//S33+WdogfVCk74S 32aWzuV7JLzAOy2rv7WrX3QzBe9QQOxGJt6G936oqvCg9lIDPkxQfhSN8QWJ9VKW2PgB MRhQ== X-Gm-Message-State: AOAM53292Wfj2kefGpXcVv6PEYzsL6PgZMpUgvLRKEtrq/Bp/telgU8Z CLoe9x0j2qyTTxKPPCoXpboU2LoO6IDq+g== X-Google-Smtp-Source: ABdhPJwm6kmFPgWfbGYB4JRfdE89pqncRZZfnEKy1IfvojlVwYUyLJkM2R4huVRmHMfZ8Pz4adht4w== X-Received: by 2002:a17:90a:ee4f:: with SMTP id bu15mr1389940pjb.16.1600124539109; Mon, 14 Sep 2020 16:02:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 05/10] disas: Use qemu/bswap.h for bfd endian loads Date: Mon, 14 Sep 2020 16:02:05 -0700 Message-Id: <20200914230210.2185860-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914230210.2185860-1-richard.henderson@linaro.org> References: <20200914230210.2185860-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Use the routines we have already instead of open-coding. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- include/disas/dis-asm.h | 32 ++++++++++++++++++++---- disas.c | 55 ----------------------------------------- 2 files changed, 27 insertions(+), 60 deletions(-) diff --git a/include/disas/dis-asm.h b/include/disas/dis-asm.h index d2418c977e..8a216ac495 100644 --- a/include/disas/dis-asm.h +++ b/include/disas/dis-asm.h @@ -468,11 +468,33 @@ int print_insn_rx(bfd_vma, disassemble_info *); =20 /* from libbfd */ =20 -bfd_vma bfd_getl64 (const bfd_byte *addr); -bfd_vma bfd_getl32 (const bfd_byte *addr); -bfd_vma bfd_getb32 (const bfd_byte *addr); -bfd_vma bfd_getl16 (const bfd_byte *addr); -bfd_vma bfd_getb16 (const bfd_byte *addr); +#include "qemu/bswap.h" + +static inline bfd_vma bfd_getl64(const bfd_byte *addr) +{ + return ldq_le_p(addr); +} + +static inline bfd_vma bfd_getl32(const bfd_byte *addr) +{ + return (uint32_t)ldl_le_p(addr); +} + +static inline bfd_vma bfd_getl16(const bfd_byte *addr) +{ + return lduw_le_p(addr); +} + +static inline bfd_vma bfd_getb32(const bfd_byte *addr) +{ + return (uint32_t)ldl_be_p(addr); +} + +static inline bfd_vma bfd_getb16(const bfd_byte *addr) +{ + return lduw_be_p(addr); +} + typedef bool bfd_boolean; =20 #endif /* DISAS_DIS_ASM_H */ diff --git a/disas.c b/disas.c index 7bc8e9a037..bf19b1b0bf 100644 --- a/disas.c +++ b/disas.c @@ -78,61 +78,6 @@ static int symbol_at_address(bfd_vma addr, struct disass= emble_info *info) return 1; } =20 -bfd_vma bfd_getl64 (const bfd_byte *addr) -{ - unsigned long long v; - - v =3D (unsigned long long) addr[0]; - v |=3D (unsigned long long) addr[1] << 8; - v |=3D (unsigned long long) addr[2] << 16; - v |=3D (unsigned long long) addr[3] << 24; - v |=3D (unsigned long long) addr[4] << 32; - v |=3D (unsigned long long) addr[5] << 40; - v |=3D (unsigned long long) addr[6] << 48; - v |=3D (unsigned long long) addr[7] << 56; - return (bfd_vma) v; -} - -bfd_vma bfd_getl32 (const bfd_byte *addr) -{ - unsigned long v; - - v =3D (unsigned long) addr[0]; - v |=3D (unsigned long) addr[1] << 8; - v |=3D (unsigned long) addr[2] << 16; - v |=3D (unsigned long) addr[3] << 24; - return (bfd_vma) v; -} - -bfd_vma bfd_getb32 (const bfd_byte *addr) -{ - unsigned long v; - - v =3D (unsigned long) addr[0] << 24; - v |=3D (unsigned long) addr[1] << 16; - v |=3D (unsigned long) addr[2] << 8; - v |=3D (unsigned long) addr[3]; - return (bfd_vma) v; -} - -bfd_vma bfd_getl16 (const bfd_byte *addr) -{ - unsigned long v; - - v =3D (unsigned long) addr[0]; - v |=3D (unsigned long) addr[1] << 8; - return (bfd_vma) v; -} - -bfd_vma bfd_getb16 (const bfd_byte *addr) -{ - unsigned long v; - - v =3D (unsigned long) addr[0] << 24; - v |=3D (unsigned long) addr[1] << 16; - return (bfd_vma) v; -} - static int print_insn_objdump(bfd_vma pc, disassemble_info *info, const char *prefix) { --=20 2.25.1 From nobody Sat May 4 05:29:20 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600124838; cv=none; d=zohomail.com; s=zohoarc; b=gy1zEbxZ5GGy1nVHl/Z01B56ipa+bpQI/YcVc0+//+jKCjtGRhaJ4CiN7gjlFFBVzHOgfaXWxZOdEgauDVlndhc7VEsYgtRToCUA3kS26ofn2B4Xsm3dcDsxsSFaBw87tr+boubOpsUZvXLOzXgJNH6FroZGsP7gs3d5/vXv47w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600124838; 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=AcobOMV5CV8pSJwR9n+sDy8pDWv6IjgjNuunOfxWOco=; b=ElOOOuPnadCF8Gvzd5VuIfu9Fu49th8b6FS8okhZnPFFuT0k+pWxq9cDUPcHj8TkqF+X6wIMnmyt6WUPfsdLEl02jt77KAMHHYnNM2Svj4JkUa/lj6Rs/EMj0Mdd1v70nIu5SzhV+M/KrefEJ/IaTxAcTV5HTBPX23URb/VZYS8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160012483885526.525014250502863; Mon, 14 Sep 2020 16:07:18 -0700 (PDT) Received: from localhost ([::1]:45382 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHxZ7-0007H2-QN for importer@patchew.org; Mon, 14 Sep 2020 19:07:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHxUO-00012j-3L for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:24 -0400 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]:51277) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHxUM-0006b3-72 for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:23 -0400 Received: by mail-pj1-x1041.google.com with SMTP id a9so731746pjg.1 for ; Mon, 14 Sep 2020 16:02:21 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id l23sm9106076pgt.16.2020.09.14.16.02.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 16:02:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AcobOMV5CV8pSJwR9n+sDy8pDWv6IjgjNuunOfxWOco=; b=E0AIHXOfc+KszyOAXsqWe4Yqsnce762fYysQsa0NINDAM2ugUuwiD2BoS3BWpOQGiJ xh85DanQ2RpccU2mh9R8AOkyhT3Ii3B175EIhguDvRpUVKazN8yRhdRvd22glOzGh03T L58Urw5EMA1Ae/Mme6xzArsNO4SLdWD8seqpVXHFi05VThB3VL6yk8wt61b5/VcAW48A 0dusX2M77iU4MqZ6RH7ZSnwraFWRoQ+Ciz2pGqKJXdNx5CXTRJKYI8yCBZo39RaLarpe QlUu6ose14s/Z23TWsAPvwEW5CtsbukruKOLix/DOX2s8pNMz4E5YFoIgbTT9EOStZ5C iwLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AcobOMV5CV8pSJwR9n+sDy8pDWv6IjgjNuunOfxWOco=; b=GMBfuXYKDzu2mgwFBTaIk9iBRH6RpJyL4BPW4Sl2HdHZykqZK0prh0ruHJvqxWk3Vb UVJED5cAZrl4MVVbmsyz1OJXCTkVYOjShQLerBrg4OnCsgck/lFjUx2UGiCfuV4BFyMK TlGtEixBpG4RyoNxXWu3sJ7jEUslm3OWInI+H7vfiugkkJI5JEbN0x4lxA90I20SvRMB Y6+etf0FvSDAyoBGsuexqHWMWWmUOfSYcMImMuIoD1KE4z1WZjt0BEyKKoHPAnqJX6ur bwHwjo67cKF1c3uM73TO50eo5n02o/dinQtVNdFx5KiZYDEWegkeFGSk7rXHkvG0pow7 rl+A== X-Gm-Message-State: AOAM530KoMB3eIn0k/JHi/k2P07oBFCzFbwwm44uTOOFGBKi25KWqQwV zB1xR7CHVWwqku0yYxfrK2Nd0++1cTyJsQ== X-Google-Smtp-Source: ABdhPJxFM0sBC086ye8+LV68B1Vc+bwrAIp98x0AHeOw7Ik5nyerC9ICImu21ViGSKPNZW3D/aSd0g== X-Received: by 2002:a17:902:d711:b029:d1:c6b5:ae5f with SMTP id w17-20020a170902d711b02900d1c6b5ae5fmr7567556ply.38.1600124540498; Mon, 14 Sep 2020 16:02:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 06/10] disas: Cleanup plugin_disas Date: Mon, 14 Sep 2020 16:02:06 -0700 Message-Id: <20200914230210.2185860-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914230210.2185860-1-richard.henderson@linaro.org> References: <20200914230210.2185860-1-richard.henderson@linaro.org> 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::1041; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1041.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_PDS_OTHER_BAD_TLD=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Do not retain a GString in thread-local storage. Allocate a new one and free it on every invocation. Do not g_strdup the result; return the buffer from the GString. Do not use warn_report. Using cs_disasm allocated memory via the &insn parameter, but that was never freed. Use cs_disasm_iter so that we use the memory that we've already allocated, and so that we only try to disassemble one insn, as desired. Do not allocate 1k to hold the bytes for a single instruction. Signed-off-by: Richard Henderson --- disas.c | 55 +++++++++++++++++++------------------------------------ 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/disas.c b/disas.c index bf19b1b0bf..d0ccd4b727 100644 --- a/disas.c +++ b/disas.c @@ -491,13 +491,12 @@ void target_disas(FILE *out, CPUState *cpu, target_ul= ong code, } } =20 -static __thread GString plugin_disas_output; - static int plugin_printf(FILE *stream, const char *fmt, ...) { - va_list va; - GString *s =3D &plugin_disas_output; + /* We abuse the FILE parameter to pass a GString. */ + GString *s =3D (GString *)stream; int initial_len =3D s->len; + va_list va; =20 va_start(va, fmt); g_string_append_vprintf(s, fmt, va); @@ -517,28 +516,20 @@ static void plugin_print_address(bfd_vma addr, struct= disassemble_info *info) static bool cap_disas_plugin(disassemble_info *info, uint64_t pc, size_t size) { - uint8_t cap_buf[1024]; + uint8_t cap_buf[64]; + const uint8_t *cbuf =3D cap_buf; csh handle; - cs_insn *insn; - size_t csize =3D 0; - int count; - GString *s =3D &plugin_disas_output; =20 if (cap_disas_start(info, &handle) !=3D CS_ERR_OK) { return false; } - insn =3D cap_insn; =20 - size_t tsize =3D MIN(sizeof(cap_buf) - csize, size); - const uint8_t *cbuf =3D cap_buf; - target_read_memory(pc, cap_buf, tsize, info); + assert(size < sizeof(cap_buf)); + target_read_memory(pc, cap_buf, size, info); =20 - count =3D cs_disasm(handle, cbuf, size, 0, 1, &insn); - - if (count) { - g_string_printf(s, "%s %s", insn->mnemonic, insn->op_str); - } else { - g_string_printf(s, "cs_disasm failed"); + if (cs_disasm_iter(handle, &cbuf, &size, &pc, cap_insn)) { + GString *s =3D (GString *)info->stream; + g_string_printf(s, "%s %s", cap_insn->mnemonic, cap_insn->op_str); } =20 cs_close(&handle); @@ -553,34 +544,26 @@ bool cap_disas_plugin(disassemble_info *info, uint64_= t pc, size_t size) */ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size) { - int count; CPUDebug s; - GString *ds =3D g_string_set_size(&plugin_disas_output, 0); - - g_assert(ds =3D=3D &plugin_disas_output); + GString *ds =3D g_string_new(NULL); =20 initialize_debug_target(&s, cpu); s.info.fprintf_func =3D plugin_printf; + s.info.stream =3D (FILE *)ds; /* abuse this slot */ s.info.buffer_vma =3D addr; s.info.buffer_length =3D size; s.info.print_address_func =3D plugin_print_address; =20 if (s.info.cap_arch >=3D 0 && cap_disas_plugin(&s.info, addr, size)) { - return g_strdup(ds->str); + ; /* done */ + } else if (s.info.print_insn) { + s.info.print_insn(addr, &s.info); + } else { + ; /* cannot disassemble -- return empty string */ } =20 - if (s.info.print_insn =3D=3D NULL) { - s.info.print_insn =3D print_insn_od_target; - } - - count =3D s.info.print_insn(addr, &s.info); - - /* The decoder probably read more than it needed it's not critical */ - if (count < size) { - warn_report("%s: %zu bytes left over", __func__, size - count); - } - - return g_strdup(ds->str); + /* Return the buffer, freeing the GString container. */ + return g_string_free(ds, false); } =20 /* Disassemble this for me please... (debugging). */ --=20 2.25.1 From nobody Sat May 4 05:29:20 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600124832; cv=none; d=zohomail.com; s=zohoarc; b=hd+q5xM95eRRsaH9fYTF+M6EHIUlLDYdYqmTzHLhJf9z48t4Gd2dT3gfJN6pXfOesFZN09y28YHYSaW2U9+j1pNw/Cis9clJTMuz+GtEZDaxJNrZ+NMcURjNenHTSeW9y8V+hEJXlg0FaDZrTb21PJY2nv/HRkEQ9osRCQB3sJM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600124832; 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=LENG1C+gvyxicL4wDRJAGnBo4QTtONcvzqY0emfT/VU=; b=QsTjB+TE8XsZ00PmkNPvhraRxek6kf5x/bax95UYXcBydejj1JCjr8F+K/3p5byK/fajG5xo6V6oH+cSC1FYEPKlnFbpzu+10Fwgi7dqZ49VswNGiDSJoomBEKbq9ZYSd8xC+etOEk0hzgy7pTs06H9xVjEfLAIyws62v0SZ2sQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600124832616151.78887668259813; Mon, 14 Sep 2020 16:07:12 -0700 (PDT) Received: from localhost ([::1]:44888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHxZ1-00071z-Ev for importer@patchew.org; Mon, 14 Sep 2020 19:07:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHxUO-00014y-Uj for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:24 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:37779) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHxUN-0006bC-Aw for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:24 -0400 Received: by mail-pf1-x441.google.com with SMTP id w7so805477pfi.4 for ; Mon, 14 Sep 2020 16:02:22 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id l23sm9106076pgt.16.2020.09.14.16.02.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 16:02:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LENG1C+gvyxicL4wDRJAGnBo4QTtONcvzqY0emfT/VU=; b=RTWQhbvfsnpqqL0NmJGJdO9yBxZjqM+TjbWeoW9Xu2cL55iUYlIHdWtVou2zb8O5lk a8Pj5ulhFf1VCYKTj/NWo4pJnnOGy+q6KFLAaB15J7wjdJH25Mibf5IOhDDcK+YSvJCj H+g3tjdF9x2G7Tkc3QjGDpXbP9J3hsvPkyZu9Ku0mo0qmCwla1Z4xi8C6MCbNRdtTBg/ BQK5dPc/Z06e5HxMAaEN8A5YCxCIbrtNX7LmEHQaGqjEBtrVfW29rPis1KGDAjVj3B4s wBOCzPUJ90iFNzTRRIDjC0JClubKR8hTiMO4EklFj6KLO1Et9m00BxuZENDf1FklnhHj GTBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LENG1C+gvyxicL4wDRJAGnBo4QTtONcvzqY0emfT/VU=; b=GSwXmrqh3fSclPRAM3/b1+MAXnBWg9Tt/dbVumTLYAb5PxnVwyhF1Y0KCmlkeDxjvG UuNJhmbLKTBiVWPdZvUil9Gep/jv4gt0BwK9/WIZPMzUZkZU7kh7VyyC6tqxN34F+JlZ IxNvr+jo3cF5FcuRGo4u4U+sirwq8d8HbwusBnnK4r0wfHDh35iied42KuMhQpuzOLS1 tzGzLPcTuIeRvKLpyI9IKC4JyvMjN0CMR02VkZScbmFwWoM3pJ+evOcBVPqvxo61haBz Dx22CaKOeq+LqAkSIl3LXpNnCYlVNglq1XNDW7VZvx8kMQ009HGQuowYok62wyalKYQZ /bRQ== X-Gm-Message-State: AOAM532YkvmDp1m3tkJy750NzAdjy4jBj6ywGVEXlrfJztG8RbT6xmYy Fp/TTL20vNSRVQX+BDQojCsQHVJMBXGt/A== X-Google-Smtp-Source: ABdhPJz1Dds4rMzQRYbFq3W3NQqCmMjeucgMMTVp6YYJOXEn+pQDEXPSsZLSgbVOPxu4nunqqoASuQ== X-Received: by 2002:a65:5502:: with SMTP id f2mr12223968pgr.418.1600124541622; Mon, 14 Sep 2020 16:02:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 07/10] disas: Configure capstone for aarch64 host without libvixl Date: Mon, 14 Sep 2020 16:02:07 -0700 Message-Id: <20200914230210.2185860-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914230210.2185860-1-richard.henderson@linaro.org> References: <20200914230210.2185860-1-richard.henderson@linaro.org> 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::441; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The ifdef tangle failed to set cap_arch if libvixl itself was not configured (e.g. due to lack of c++ compiler). Signed-off-by: Richard Henderson Reviewed-by: Thomas Huth --- disas.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/disas.c b/disas.c index d0ccd4b727..01c8bc6c9e 100644 --- a/disas.c +++ b/disas.c @@ -428,9 +428,11 @@ static void initialize_debug_host(CPUDebug *s) #else #error unsupported RISC-V ABI #endif -#elif defined(__aarch64__) && defined(CONFIG_ARM_A64_DIS) - s->info.print_insn =3D print_insn_arm_a64; +#elif defined(__aarch64__) s->info.cap_arch =3D CS_ARCH_ARM64; +# ifdef CONFIG_ARM_A64_DIS + s->info.print_insn =3D print_insn_arm_a64; +# endif #elif defined(__alpha__) s->info.print_insn =3D print_insn_alpha; #elif defined(__sparc__) --=20 2.25.1 From nobody Sat May 4 05:29:20 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600124901; cv=none; d=zohomail.com; s=zohoarc; b=DhS5EyFHlhnzpaUEwgEuQylCN4FSBBfL4kc3/TcBXYHpa5UG0aZAsjbTi4gUE6/6mGx//ePemtUPCFYF3oVntYzPVEk6w864ZrjYKc9IudyUl65Wy6ilr6mFaav3mmt+oFhAACvxxJ8Wg2HiSWwtT/6zd12jYps5EMX2NcB7/E0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600124901; 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=m0NuBq77UbZcFjF8+iusU5qFfFU9pIfJmyE8LiXvhOs=; b=Zo5GNfQXNIPiSaYnketsQ+HcLX5DbYWXbFvyteDgjEAMMWi4mQ6HfwZrC7KTlmGDUSvpMRR/z6R+E0rYMUT5p/NFpjJnGasdU7HQ8X13YEZYQU61TN1NJQjTmIH7nBxzLvop5TZsh0I8/l5vBRBatpIGA/nUl/5SE9Dg+oSRTTA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600124901034519.1606424664417; Mon, 14 Sep 2020 16:08:21 -0700 (PDT) Received: from localhost ([::1]:49064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHxa7-0000Kx-Td for importer@patchew.org; Mon, 14 Sep 2020 19:08:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHxUR-0001BR-Kl for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:27 -0400 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:53153) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHxUO-0006cc-SM for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:27 -0400 Received: by mail-pj1-x1042.google.com with SMTP id o16so727250pjr.2 for ; Mon, 14 Sep 2020 16:02:24 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id l23sm9106076pgt.16.2020.09.14.16.02.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 16:02:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=y02720T57TATamL+u4VILUZLxnQbECZxtzk44A9xgdQ=; b=V06SVqoZ3F2RYuGOSKq1k5bcwqEOHgTHgwxf+jqKg8S/jT+tutTB+xe1Fvsu8zlhZU QxVK5VKCokVeITJ0KDxVeFNFTTtZ3VDTaGx6Vv1R82GN6dc8ltOnRIFiLs2dDe8DCugr S8WnYS5ev9VSgWGepWw8owTXqINo2pptu51H4e2JF9i62svrXhuo6hW5ppx0JSNTyr1s /JFBfSw9YHowxUZnENLorgswHMWunTYPRVb1Zg4LVBretSW5DzJIbxMHH6BJV7Yr8Vfx zc+xdVmIlz+lMuWrnDW/Qc6iMravUR94qAJdzMGPP0Lw+UlbfNCnCRzbRje2KUPihRS4 V49w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=y02720T57TATamL+u4VILUZLxnQbECZxtzk44A9xgdQ=; b=tG17EtJK5lu2n+dGBww1D6z72neR+xtQimJOronfxcqLgWpUVR2wDN2zidiAEi1MUQ vcdBwlvDmslf8gtubipt6veBXSnib7LynvQbZy3W0CCdKdIvb4xgJUesDbcEDF2AlahN x/GaUgJSIZXlLD1v5kiRjN1aGKyc+oX9oYZg7YezbXoiHRdEylgL9tMMnZbbFfAOv/7n ZeDhatNletiWIy0AOPmXJN9TNh+5TmgPFinckCiL77koexK82/isU3EPR+5gZ7yn9db8 p0Z0Fz6jkcxdKO40ZRguXJmPZssgV4CuOUsR1dpMsCAi213tHxgWRPTpqKhJ2Zb4UWn5 82vA== X-Gm-Message-State: AOAM531Zv3WLnyXks6p1YJPXrwmqBe8KFGQex+HNGPuxTs8HFCswu9B0 IKbZQACihbxGh6jKq2ZB4/O0Ef048TTjiw== X-Google-Smtp-Source: ABdhPJzQ+1mKgMXOuh9YpYukCAEJ4Xsu9g/4koXaxELktjOFM9VRDM+opCw36jrYEQS2Z8SMOvN7CQ== X-Received: by 2002:a17:902:b08f:b029:d1:e3bd:48c5 with SMTP id p15-20020a170902b08fb02900d1e3bd48c5mr619240plr.4.1600124542829; Mon, 14 Sep 2020 16:02:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 08/10] disas: Split out capstone code to disas/capstone.c Date: Mon, 14 Sep 2020 16:02:08 -0700 Message-Id: <20200914230210.2185860-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914230210.2185860-1-richard.henderson@linaro.org> References: <20200914230210.2185860-1-richard.henderson@linaro.org> 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::1042; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1042.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" There is nothing target-specific about this code, so it can be added to common_ss. This also requires that the base capstone dependency be added to common_ss, so that we get the correct include paths added to CFLAGS. Signed-off-by: Richard Henderson --- include/disas/dis-asm.h | 12 ++ disas.c | 275 -------------------------------------- disas/capstone.c | 286 ++++++++++++++++++++++++++++++++++++++++ disas/meson.build | 1 + meson.build | 1 + 5 files changed, 300 insertions(+), 275 deletions(-) create mode 100644 disas/capstone.c diff --git a/include/disas/dis-asm.h b/include/disas/dis-asm.h index 8a216ac495..a34837e4db 100644 --- a/include/disas/dis-asm.h +++ b/include/disas/dis-asm.h @@ -461,6 +461,18 @@ int print_insn_riscv32 (bfd_vma, disassemble_= info*); int print_insn_riscv64 (bfd_vma, disassemble_info*); int print_insn_rx(bfd_vma, disassemble_info *); =20 +#ifdef CONFIG_CAPSTONE +bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size); +bool cap_disas_host(disassemble_info *info, void *code, size_t size); +bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int count); +bool cap_disas_plugin(disassemble_info *info, uint64_t pc, size_t size); +#else +# define cap_disas_target(i, p, s) false +# define cap_disas_host(i, p, s) false +# define cap_disas_monitor(i, p, c) false +# define cap_disas_plugin(i, p, c) false +#endif /* CONFIG_CAPSTONE */ + =0C #ifndef ATTRIBUTE_UNUSED #define ATTRIBUTE_UNUSED __attribute__((unused)) diff --git a/disas.c b/disas.c index 01c8bc6c9e..e27dea2c19 100644 --- a/disas.c +++ b/disas.c @@ -107,255 +107,6 @@ static int print_insn_od_target(bfd_vma pc, disassemb= le_info *info) return print_insn_objdump(pc, info, "OBJD-T"); } =20 -#ifdef CONFIG_CAPSTONE -/* Temporary storage for the capstone library. This will be alloced via - malloc with a size private to the library; thus there's no reason not - to share this across calls and across host vs target disassembly. */ -static __thread cs_insn *cap_insn; - -/* Initialize the Capstone library. */ -/* ??? It would be nice to cache this. We would need one handle for the - host and one for the target. For most targets we can reset specific - parameters via cs_option(CS_OPT_MODE, new_mode), but we cannot change - CS_ARCH_* in this way. Thus we would need to be able to close and - re-open the target handle with a different arch for the target in order - to handle AArch64 vs AArch32 mode switching. */ -static cs_err cap_disas_start(disassemble_info *info, csh *handle) -{ - cs_mode cap_mode =3D info->cap_mode; - cs_err err; - - cap_mode +=3D (info->endian =3D=3D BFD_ENDIAN_BIG ? CS_MODE_BIG_ENDIAN - : CS_MODE_LITTLE_ENDIAN); - - err =3D cs_open(info->cap_arch, cap_mode, handle); - if (err !=3D CS_ERR_OK) { - return err; - } - - /* ??? There probably ought to be a better place to put this. */ - if (info->cap_arch =3D=3D CS_ARCH_X86) { - /* We don't care about errors (if for some reason the library - is compiled without AT&T syntax); the user will just have - to deal with the Intel syntax. */ - cs_option(*handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_ATT); - } - - /* "Disassemble" unknown insns as ".byte W,X,Y,Z". */ - cs_option(*handle, CS_OPT_SKIPDATA, CS_OPT_ON); - - /* Allocate temp space for cs_disasm_iter. */ - if (cap_insn =3D=3D NULL) { - cap_insn =3D cs_malloc(*handle); - if (cap_insn =3D=3D NULL) { - cs_close(handle); - return CS_ERR_MEM; - } - } - return CS_ERR_OK; -} - -static void cap_dump_insn_units(disassemble_info *info, cs_insn *insn, - int i, int n) -{ - fprintf_function print =3D info->fprintf_func; - FILE *stream =3D info->stream; - - switch (info->cap_insn_unit) { - case 4: - if (info->endian =3D=3D BFD_ENDIAN_BIG) { - for (; i < n; i +=3D 4) { - print(stream, " %08x", ldl_be_p(insn->bytes + i)); - - } - } else { - for (; i < n; i +=3D 4) { - print(stream, " %08x", ldl_le_p(insn->bytes + i)); - } - } - break; - - case 2: - if (info->endian =3D=3D BFD_ENDIAN_BIG) { - for (; i < n; i +=3D 2) { - print(stream, " %04x", lduw_be_p(insn->bytes + i)); - } - } else { - for (; i < n; i +=3D 2) { - print(stream, " %04x", lduw_le_p(insn->bytes + i)); - } - } - break; - - default: - for (; i < n; i++) { - print(stream, " %02x", insn->bytes[i]); - } - break; - } -} - -static void cap_dump_insn(disassemble_info *info, cs_insn *insn) -{ - fprintf_function print =3D info->fprintf_func; - int i, n, split; - - print(info->stream, "0x%08" PRIx64 ": ", insn->address); - - n =3D insn->size; - split =3D info->cap_insn_split; - - /* Dump the first SPLIT bytes of the instruction. */ - cap_dump_insn_units(info, insn, 0, MIN(n, split)); - - /* Add padding up to SPLIT so that mnemonics line up. */ - if (n < split) { - int width =3D (split - n) / info->cap_insn_unit; - width *=3D (2 * info->cap_insn_unit + 1); - print(info->stream, "%*s", width, ""); - } - - /* Print the actual instruction. */ - print(info->stream, " %-8s %s\n", insn->mnemonic, insn->op_str); - - /* Dump any remaining part of the insn on subsequent lines. */ - for (i =3D split; i < n; i +=3D split) { - print(info->stream, "0x%08" PRIx64 ": ", insn->address + i); - cap_dump_insn_units(info, insn, i, MIN(n, i + split)); - print(info->stream, "\n"); - } -} - -/* Disassemble SIZE bytes at PC for the target. */ -static bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t s= ize) -{ - uint8_t cap_buf[1024]; - csh handle; - cs_insn *insn; - size_t csize =3D 0; - - if (cap_disas_start(info, &handle) !=3D CS_ERR_OK) { - return false; - } - insn =3D cap_insn; - - while (1) { - size_t tsize =3D MIN(sizeof(cap_buf) - csize, size); - const uint8_t *cbuf =3D cap_buf; - - target_read_memory(pc + csize, cap_buf + csize, tsize, info); - csize +=3D tsize; - size -=3D tsize; - - while (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { - cap_dump_insn(info, insn); - } - - /* If the target memory is not consumed, go back for more... */ - if (size !=3D 0) { - /* ... taking care to move any remaining fractional insn - to the beginning of the buffer. */ - if (csize !=3D 0) { - memmove(cap_buf, cbuf, csize); - } - continue; - } - - /* Since the target memory is consumed, we should not have - a remaining fractional insn. */ - if (csize !=3D 0) { - (*info->fprintf_func)(info->stream, - "Disassembler disagrees with translator " - "over instruction decoding\n" - "Please report this to qemu-devel@nongnu.org\n"); - } - break; - } - - cs_close(&handle); - return true; -} - -/* Disassemble SIZE bytes at CODE for the host. */ -static bool cap_disas_host(disassemble_info *info, void *code, size_t size) -{ - csh handle; - const uint8_t *cbuf; - cs_insn *insn; - uint64_t pc; - - if (cap_disas_start(info, &handle) !=3D CS_ERR_OK) { - return false; - } - insn =3D cap_insn; - - cbuf =3D code; - pc =3D (uintptr_t)code; - - while (cs_disasm_iter(handle, &cbuf, &size, &pc, insn)) { - cap_dump_insn(info, insn); - } - if (size !=3D 0) { - (*info->fprintf_func)(info->stream, - "Disassembler disagrees with TCG over instruction encoding\n" - "Please report this to qemu-devel@nongnu.org\n"); - } - - cs_close(&handle); - return true; -} - -#if !defined(CONFIG_USER_ONLY) -/* Disassemble COUNT insns at PC for the target. */ -static bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int cou= nt) -{ - uint8_t cap_buf[32]; - csh handle; - cs_insn *insn; - size_t csize =3D 0; - - if (cap_disas_start(info, &handle) !=3D CS_ERR_OK) { - return false; - } - insn =3D cap_insn; - - while (1) { - /* We want to read memory for one insn, but generically we do not - know how much memory that is. We have a small buffer which is - known to be sufficient for all supported targets. Try to not - read beyond the page, Just In Case. For even more simplicity, - ignore the actual target page size and use a 1k boundary. If - that turns out to be insufficient, we'll come back around the - loop and read more. */ - uint64_t epc =3D QEMU_ALIGN_UP(pc + csize + 1, 1024); - size_t tsize =3D MIN(sizeof(cap_buf) - csize, epc - pc); - const uint8_t *cbuf =3D cap_buf; - - /* Make certain that we can make progress. */ - assert(tsize !=3D 0); - info->read_memory_func(pc, cap_buf + csize, tsize, info); - csize +=3D tsize; - - if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { - cap_dump_insn(info, insn); - if (--count <=3D 0) { - break; - } - } - memmove(cap_buf, cbuf, csize); - } - - cs_close(&handle); - return true; -} -#endif /* !CONFIG_USER_ONLY */ -#else -# define cap_disas_target(i, p, s) false -# define cap_disas_host(i, p, s) false -# define cap_disas_monitor(i, p, c) false -# define cap_disas_plugin(i, p, c) false -#endif /* CONFIG_CAPSTONE */ - static void initialize_debug(CPUDebug *s) { memset(s, 0, sizeof(*s)); @@ -513,32 +264,6 @@ static void plugin_print_address(bfd_vma addr, struct = disassemble_info *info) } =20 =20 -#ifdef CONFIG_CAPSTONE -/* Disassemble a single instruction directly into plugin output */ -static -bool cap_disas_plugin(disassemble_info *info, uint64_t pc, size_t size) -{ - uint8_t cap_buf[64]; - const uint8_t *cbuf =3D cap_buf; - csh handle; - - if (cap_disas_start(info, &handle) !=3D CS_ERR_OK) { - return false; - } - - assert(size < sizeof(cap_buf)); - target_read_memory(pc, cap_buf, size, info); - - if (cs_disasm_iter(handle, &cbuf, &size, &pc, cap_insn)) { - GString *s =3D (GString *)info->stream; - g_string_printf(s, "%s %s", cap_insn->mnemonic, cap_insn->op_str); - } - - cs_close(&handle); - return true; -} -#endif - /* * We should only be dissembling one instruction at a time here. If * there is left over it usually indicates the front end has read more diff --git a/disas/capstone.c b/disas/capstone.c new file mode 100644 index 0000000000..b48f83958d --- /dev/null +++ b/disas/capstone.c @@ -0,0 +1,286 @@ +/* + * Interface to the capstone disassembler. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/bswap.h" +#include "disas/dis-asm.h" +#include "disas/capstone.h" + + +/* + * Temporary storage for the capstone library. This will be alloced via + * malloc with a size private to the library; thus there's no reason not + * to share this across calls and across host vs target disassembly. + */ +static __thread cs_insn *cap_insn; + +/* + * Initialize the Capstone library. + * + * ??? It would be nice to cache this. We would need one handle for the + * host and one for the target. For most targets we can reset specific + * parameters via cs_option(CS_OPT_MODE, new_mode), but we cannot change + * CS_ARCH_* in this way. Thus we would need to be able to close and + * re-open the target handle with a different arch for the target in order + * to handle AArch64 vs AArch32 mode switching. + */ +static cs_err cap_disas_start(disassemble_info *info, csh *handle) +{ + cs_mode cap_mode =3D info->cap_mode; + cs_err err; + + cap_mode +=3D (info->endian =3D=3D BFD_ENDIAN_BIG ? CS_MODE_BIG_ENDIAN + : CS_MODE_LITTLE_ENDIAN); + + err =3D cs_open(info->cap_arch, cap_mode, handle); + if (err !=3D CS_ERR_OK) { + return err; + } + + /* "Disassemble" unknown insns as ".byte W,X,Y,Z". */ + cs_option(*handle, CS_OPT_SKIPDATA, CS_OPT_ON); + + if (info->cap_arch =3D=3D CS_ARCH_X86) { + /* + * We don't care about errors (if for some reason the library + * is compiled without AT&T syntax); the user will just have + * to deal with the Intel syntax. + */ + cs_option(*handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_ATT); + } + + /* Allocate temp space for cs_disasm_iter. */ + if (cap_insn =3D=3D NULL) { + cap_insn =3D cs_malloc(*handle); + if (cap_insn =3D=3D NULL) { + cs_close(handle); + return CS_ERR_MEM; + } + } + return CS_ERR_OK; +} + +static void cap_dump_insn_units(disassemble_info *info, cs_insn *insn, + int i, int n) +{ + fprintf_function print =3D info->fprintf_func; + FILE *stream =3D info->stream; + + switch (info->cap_insn_unit) { + case 4: + if (info->endian =3D=3D BFD_ENDIAN_BIG) { + for (; i < n; i +=3D 4) { + print(stream, " %08x", ldl_be_p(insn->bytes + i)); + + } + } else { + for (; i < n; i +=3D 4) { + print(stream, " %08x", ldl_le_p(insn->bytes + i)); + } + } + break; + + case 2: + if (info->endian =3D=3D BFD_ENDIAN_BIG) { + for (; i < n; i +=3D 2) { + print(stream, " %04x", lduw_be_p(insn->bytes + i)); + } + } else { + for (; i < n; i +=3D 2) { + print(stream, " %04x", lduw_le_p(insn->bytes + i)); + } + } + break; + + default: + for (; i < n; i++) { + print(stream, " %02x", insn->bytes[i]); + } + break; + } +} + +static void cap_dump_insn(disassemble_info *info, cs_insn *insn) +{ + fprintf_function print =3D info->fprintf_func; + FILE *stream =3D info->stream; + int i, n, split; + + print(stream, "0x%08" PRIx64 ": ", insn->address); + + n =3D insn->size; + split =3D info->cap_insn_split; + + /* Dump the first SPLIT bytes of the instruction. */ + cap_dump_insn_units(info, insn, 0, MIN(n, split)); + + /* Add padding up to SPLIT so that mnemonics line up. */ + if (n < split) { + int width =3D (split - n) / info->cap_insn_unit; + width *=3D (2 * info->cap_insn_unit + 1); + print(stream, "%*s", width, ""); + } + + /* Print the actual instruction. */ + print(stream, " %-8s %s\n", insn->mnemonic, insn->op_str); + + /* Dump any remaining part of the insn on subsequent lines. */ + for (i =3D split; i < n; i +=3D split) { + print(stream, "0x%08" PRIx64 ": ", insn->address + i); + cap_dump_insn_units(info, insn, i, MIN(n, i + split)); + print(stream, "\n"); + } +} + +/* Disassemble SIZE bytes at PC for the target. */ +bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size) +{ + uint8_t cap_buf[1024]; + csh handle; + cs_insn *insn; + size_t csize =3D 0; + + if (cap_disas_start(info, &handle) !=3D CS_ERR_OK) { + return false; + } + insn =3D cap_insn; + + while (1) { + size_t tsize =3D MIN(sizeof(cap_buf) - csize, size); + const uint8_t *cbuf =3D cap_buf; + + info->read_memory_func(pc + csize, cap_buf + csize, tsize, info); + csize +=3D tsize; + size -=3D tsize; + + while (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { + cap_dump_insn(info, insn); + } + + /* If the target memory is not consumed, go back for more... */ + if (size !=3D 0) { + /* + * ... taking care to move any remaining fractional insn + * to the beginning of the buffer. + */ + if (csize !=3D 0) { + memmove(cap_buf, cbuf, csize); + } + continue; + } + + /* + * Since the target memory is consumed, we should not have + * a remaining fractional insn. + */ + if (csize !=3D 0) { + info->fprintf_func(info->stream, + "Disassembler disagrees with translator " + "over instruction decoding\n" + "Please report this to qemu-devel@nongnu.org\n"); + } + break; + } + + cs_close(&handle); + return true; +} + +/* Disassemble SIZE bytes at CODE for the host. */ +bool cap_disas_host(disassemble_info *info, void *code, size_t size) +{ + csh handle; + const uint8_t *cbuf; + cs_insn *insn; + uint64_t pc; + + if (cap_disas_start(info, &handle) !=3D CS_ERR_OK) { + return false; + } + insn =3D cap_insn; + + cbuf =3D code; + pc =3D (uintptr_t)code; + + while (cs_disasm_iter(handle, &cbuf, &size, &pc, insn)) { + cap_dump_insn(info, insn); + } + if (size !=3D 0) { + info->fprintf_func(info->stream, + "Disassembler disagrees with TCG over instruction encoding\n" + "Please report this to qemu-devel@nongnu.org\n"); + } + + cs_close(&handle); + return true; +} + +/* Disassemble COUNT insns at PC for the target. */ +bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int count) +{ + uint8_t cap_buf[32]; + csh handle; + cs_insn *insn; + size_t csize =3D 0; + + if (cap_disas_start(info, &handle) !=3D CS_ERR_OK) { + return false; + } + insn =3D cap_insn; + + while (1) { + /* + * We want to read memory for one insn, but generically we do not + * know how much memory that is. We have a small buffer which is + * known to be sufficient for all supported targets. Try to not + * read beyond the page, Just In Case. For even more simplicity, + * ignore the actual target page size and use a 1k boundary. If + * that turns out to be insufficient, we'll come back around the + * loop and read more. + */ + uint64_t epc =3D QEMU_ALIGN_UP(pc + csize + 1, 1024); + size_t tsize =3D MIN(sizeof(cap_buf) - csize, epc - pc); + const uint8_t *cbuf =3D cap_buf; + + /* Make certain that we can make progress. */ + assert(tsize !=3D 0); + info->read_memory_func(pc, cap_buf + csize, tsize, info); + csize +=3D tsize; + + if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { + cap_dump_insn(info, insn); + if (--count <=3D 0) { + break; + } + } + memmove(cap_buf, cbuf, csize); + } + + cs_close(&handle); + return true; +} + +/* Disassemble a single instruction directly into plugin output */ +bool cap_disas_plugin(disassemble_info *info, uint64_t pc, size_t size) +{ + uint8_t cap_buf[32]; + const uint8_t *cbuf =3D cap_buf; + csh handle; + + if (cap_disas_start(info, &handle) !=3D CS_ERR_OK) { + return false; + } + + assert(size < sizeof(cap_buf)); + info->read_memory_func(pc, cap_buf, size, info); + + if (cs_disasm_iter(handle, &cbuf, &size, &pc, cap_insn)) { + info->fprintf_func(info->stream, "%s %s", + cap_insn->mnemonic, cap_insn->op_str); + } + + cs_close(&handle); + return true; +} diff --git a/disas/meson.build b/disas/meson.build index bde8280c73..09a852742e 100644 --- a/disas/meson.build +++ b/disas/meson.build @@ -21,5 +21,6 @@ common_ss.add(when: 'CONFIG_S390_DIS', if_true: files('s3= 90.c')) common_ss.add(when: 'CONFIG_SH4_DIS', if_true: files('sh4.c')) common_ss.add(when: 'CONFIG_SPARC_DIS', if_true: files('sparc.c')) common_ss.add(when: 'CONFIG_XTENSA_DIS', if_true: files('xtensa.c')) +common_ss.add(when: capstone, if_true: files('capstone.c')) =20 specific_ss.add(when: 'CONFIG_TCG_INTERPRETER', if_true: files('tci.c')) diff --git a/meson.build b/meson.build index cbb8257d6b..2f3da5d8c6 100644 --- a/meson.build +++ b/meson.build @@ -969,6 +969,7 @@ common_ss.add(files('cpus-common.c')) =20 subdir('softmmu') =20 +common_ss.add(capstone) specific_ss.add(files('disas.c', 'exec.c', 'gdbstub.c'), capstone, libpmem= , libdaxctl) specific_ss.add(files('exec-vary.c')) specific_ss.add(when: 'CONFIG_TCG', if_true: files( --=20 2.25.1 From nobody Sat May 4 05:29:20 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600124643; cv=none; d=zohomail.com; s=zohoarc; b=ZNACMUtrwHYOvGbdyRgJGb4/ckrB3jSu/LfNy+c6zYBGaZSAKDUsdSHhJlNsRAdZMJM2uFn4wlWEzhlXOq8amflZRUb3BFvCygIG/ifJYOCbtKLCR8kpU39GBhFSDvh5XPi8bzOGuIdf2yEKDpklvd34Qd9FMEaPGg6/NcYU8tQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600124643; 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=KuC/kv5eCu0e0HbeQ2KRbyXfJmTxRoX2ga8TfPiXbIY=; b=UC89zW5J1a2ewUIAwbNHXZREqEbdCyf2rxBbPcgZ75FWdduBnkeEB2IJ8lAdrVm7jPKK7GKY2NE7J7tMqfB4RPjulMDyXaL2hTSHRyhUOa9Il3+VJs+Qjvdfv5RIZrt4GS7A635OHnkBAGKvpezK/tDvouEdcV7nyxbBltrWKjM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600124643549478.37216603451975; Mon, 14 Sep 2020 16:04:03 -0700 (PDT) Received: from localhost ([::1]:34742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHxVx-0002tX-3Y for importer@patchew.org; Mon, 14 Sep 2020 19:04:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33802) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHxUS-0001Ew-Ua for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:28 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:46440) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHxUQ-0006cw-6R for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:28 -0400 Received: by mail-pf1-x442.google.com with SMTP id b124so760475pfg.13 for ; Mon, 14 Sep 2020 16:02:25 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id l23sm9106076pgt.16.2020.09.14.16.02.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 16:02:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KuC/kv5eCu0e0HbeQ2KRbyXfJmTxRoX2ga8TfPiXbIY=; b=nOwaxnA9zzNKafeNrDowTb6Sm3VGUHGu5wm+ytHRLiIzGFGds6QGmNPiSNHaI1yg2L fnleHnxYiJDoQk3/b0XB+3YExklvm8i18gWIrzadkukuD/L2tbKtcM7+RwYD4h+ZRCtd kVvbfhVgnOBWH4l8PBtxeNCi4tnPmXcmQhD3zBSJmBLCSZiOvMz1Hje4ncfNy1o44vgU cbrgrw1qMJL2uYBcLPQNKSlgPZV+Lg2RDlfEbo9Abuxe4o5AWuz9vOdZDrKq8U3VF/Dv 7oOrL/2xFPbFYhTx3uykQxo4qqhnfLcKmPqWghFb96ie9sCYKzZvifOrY8MVckq8ie08 qtiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KuC/kv5eCu0e0HbeQ2KRbyXfJmTxRoX2ga8TfPiXbIY=; b=hovRZBwI/et3ezM9s1BmHrTH8LR5wzKlFntadfP705eSTLQLbJ4bJTunv9kCO3OFkX 33TR5WLYVbb8GN8gG2D9Bttd9RnwEnja+m+vmWcloOmTt6VMS9C7dZ2jyn141WYDmFAf xqM/7S9NNkeIRO38Jfu4wtAalKxVROhMWvivguvlwkxWQffR5n4LRJlRHL7xCnrBlPK0 hXA9gMCRDEbUYiIR/lSFnaHbioqXU8ZhGaAII1mUZsf0rmLxsuvuynmnvZFQpvbogVak 4EOzK2WfuqcqGvsJxmSRTlILbrkFgJ/0XUD7laZ4LTVedqDOk06dJyQscZUdlUCK7+ER t6AQ== X-Gm-Message-State: AOAM531u+jfcXSLKD8EfKI6w+eoM9C1pq6r+8tiBb/nkhYqXDQ5NOZMV IFkzHX5fiwNznMJ2av50JS27Kn830WHe9g== X-Google-Smtp-Source: ABdhPJxR+SyQPYDI+MKacRfaLxTQgkJUZzrk+czeKaxhK7wLMz8XzxxWbGUg3F96jSS+BSQRLn+qew== X-Received: by 2002:a63:753:: with SMTP id 80mr5881649pgh.347.1600124544378; Mon, 14 Sep 2020 16:02:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 09/10] disas: Enable capstone disassembly for s390x Date: Mon, 14 Sep 2020 16:02:09 -0700 Message-Id: <20200914230210.2185860-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914230210.2185860-1-richard.henderson@linaro.org> References: <20200914230210.2185860-1-richard.henderson@linaro.org> 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::442; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Enable s390x, aka SYSZ, in the git submodule build. Set the capstone parameters for both s390x host and guest. Signed-off-by: Richard Henderson Acked-by: Thomas Huth --- disas.c | 3 +++ target/s390x/cpu.c | 4 ++++ meson.build | 11 +++++++++++ 3 files changed, 18 insertions(+) diff --git a/disas.c b/disas.c index e27dea2c19..c4cd305190 100644 --- a/disas.c +++ b/disas.c @@ -201,6 +201,9 @@ static void initialize_debug_host(CPUDebug *s) s->info.print_insn =3D print_insn_m68k; #elif defined(__s390__) s->info.print_insn =3D print_insn_s390; + s->info.cap_arch =3D CS_ARCH_SYSZ; + s->info.cap_insn_unit =3D 2; + s->info.cap_insn_split =3D 6; #elif defined(__hppa__) s->info.print_insn =3D print_insn_hppa; #endif diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index 749cd548f0..2a96692691 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -44,6 +44,7 @@ #include "sysemu/tcg.h" #endif #include "fpu/softfloat-helpers.h" +#include "disas/capstone.h" =20 #define CR0_RESET 0xE0UL #define CR14_RESET 0xC2000000UL; @@ -182,6 +183,9 @@ static void s390_cpu_disas_set_info(CPUState *cpu, disa= ssemble_info *info) { info->mach =3D bfd_mach_s390_64; info->print_insn =3D print_insn_s390; + info->cap_arch =3D CS_ARCH_SYSZ; + info->cap_insn_unit =3D 2; + info->cap_insn_split =3D 6; } =20 static void s390_cpu_realizefn(DeviceState *dev, Error **errp) diff --git a/meson.build b/meson.build index 2f3da5d8c6..448c87f645 100644 --- a/meson.build +++ b/meson.build @@ -674,6 +674,17 @@ if capstone_opt =3D=3D 'internal' ) endif =20 + if 'CONFIG_S390_DIS' in config_all_disas + capstone_data.set('CAPSTONE_HAS_SYSZ', '1') + capstone_files +=3D files( + 'capstone/arch/SystemZ/SystemZDisassembler.c', + 'capstone/arch/SystemZ/SystemZInstPrinter.c', + 'capstone/arch/SystemZ/SystemZMapping.c', + 'capstone/arch/SystemZ/SystemZModule.c', + 'capstone/arch/SystemZ/SystemZMCTargetDesc.c' + ) + endif + if 'CONFIG_I386_DIS' in config_all_disas capstone_data.set('CAPSTONE_HAS_X86', 1) capstone_files +=3D files( --=20 2.25.1 From nobody Sat May 4 05:29:20 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600124990; cv=none; d=zohomail.com; s=zohoarc; b=HNlaX/GIonEMgEVkfb3RO8trJ1924CBYtc1mSqE2wWZK0+9XAu4WWvSzGloCXL8N+7+sFE2SM839x2L7eoMf+LnYCcEZVebZHhAS+q9yn5D9cx1JpUecBtVQ2FLw6mPmsOCKHr+IpbODlSPO3nplBtYxmKGTt8ErJ19eS6MGnpc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600124990; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hfLGTzL8Kx9EX3rC/1RV7M0Ql1gkiftzaDe5UPaelEg=; b=RF22I8v+4ex6Lk/NmFQ4rk+D0jmP/FH8WNpjh7Rdl3AiTcPdqFDSGx0OyhUDi+78qGpTKSjzE9ZTbjTk1DYYJTJmvZXJV6qJ8uSRk20Sm9E0pzPwFdyezxGu6JK/FYtWBBcG2S8f+OQIXBlmmxWWLHtcI1M8CV44gz8Eeg4nWSc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600124990190455.7530902233418; Mon, 14 Sep 2020 16:09:50 -0700 (PDT) Received: from localhost ([::1]:52520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHxbY-0001lA-R7 for importer@patchew.org; Mon, 14 Sep 2020 19:09:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33804) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHxUT-0001Fs-BR for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:29 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:36421) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHxUR-0006dA-K4 for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:29 -0400 Received: by mail-pg1-x544.google.com with SMTP id f2so946995pgd.3 for ; Mon, 14 Sep 2020 16:02:27 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id l23sm9106076pgt.16.2020.09.14.16.02.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 16:02:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hfLGTzL8Kx9EX3rC/1RV7M0Ql1gkiftzaDe5UPaelEg=; b=Th4OCI3qADxjsSfJUw/86xhbPR6CQPEiJ8mwbAe+GZ1aT0NJAhOZhLIlRoOKlagqxB EUgK7oiYCvSbhXUbGz+cFTNpC596n/F3PQmKuPuE8DcQzfXskd9tmnEFyAzyIdaI8b13 Bky66TQHA5pVM7Lk73wPBWfCaFW4tvJPLFivXivRr2xu66lxwMpAQdLQw9qaRTyEIC3G i95BgHjWKcOP6aL9VJHka1PctpRkiKC1GgZPUnHdtJcu0ygeu8ES8tarQ/NRqqKUvnwo UoAvNVMrnMAxWhzE9IKASohK3ucGOgjItWJNnLlY6Ns3hvtjzZLI13wOfZ/2ko5S30h8 kkkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hfLGTzL8Kx9EX3rC/1RV7M0Ql1gkiftzaDe5UPaelEg=; b=M5SQUfHPTrcGATKIenrF9BlgznOAtiAbzx9PKlTGoKA5x7/WLoXeoy18IzT4edNlPp pDr8IV59bubB+rYZ0Q2D9yYDkAK3AcxhycxiNEn4pq9Cy9QOzCyrudHlJodIu+85i83w LNUwoKC3A2e8TpQHaHv2/2DpqNfMyQ+HzMyZILeX3D4tFJpNrTX+jDY+vtVbfQ3SUnXz XhTHHjcZ7csAsdFjFftHmB/H5GmU1xYOElDYwRUYwASduFfwa1cwEa7LcxIyO1pyD97+ BKTtzWtso5Xz9ErEOomOgWsiIbfF3xKV6/ajdBEBQu6LCTLFkg3a37sEdwVxa3oczhbg Ixrg== X-Gm-Message-State: AOAM531MSNFGDDfSaRbxBdJfwejtxvclYDqJpZ8cIuFTG9j7hcnj0W11 42gH1vziX1ZTL3yBGjFdZnm+sqa+Joz6rA== X-Google-Smtp-Source: ABdhPJx6I58i4Dq6iVKpmjI6Q014K3IPzjStur67UPXLGPv83UatELc+3zi6NrXm6lhzBS6COYjm7Q== X-Received: by 2002:a63:28c:: with SMTP id 134mr12388204pgc.385.1600124545945; Mon, 14 Sep 2020 16:02:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 10/10] disas/capstone: Add skipdata hook for s390x Date: Mon, 14 Sep 2020 16:02:10 -0700 Message-Id: <20200914230210.2185860-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914230210.2185860-1-richard.henderson@linaro.org> References: <20200914230210.2185860-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::544; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x544.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) It is always possible to tell the length of an insn, even if the actual insn is unknown. Skip the correct number of bytes, so that we stay in sync with the instruction stream. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson Acked-by: Thomas Huth --- disas/capstone.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/disas/capstone.c b/disas/capstone.c index b48f83958d..0a9ef9c892 100644 --- a/disas/capstone.c +++ b/disas/capstone.c @@ -16,6 +16,39 @@ */ static __thread cs_insn *cap_insn; =20 +/* + * The capstone library always skips 2 bytes for S390X. + * This is less than ideal, since we can tell from the first two bits + * the size of the insn and thus stay in sync with the insn stream. + */ +static size_t CAPSTONE_API +cap_skipdata_s390x_cb(const uint8_t *code, size_t code_size, + size_t offset, void *user_data) +{ + size_t ilen; + + /* See get_ilen() in target/s390x/internal.h. */ + switch (code[offset] >> 6) { + case 0: + ilen =3D 2; + break; + case 1: + case 2: + ilen =3D 4; + break; + default: + ilen =3D 6; + break; + } + + return ilen; +} + +static const cs_opt_skipdata cap_skipdata_s390x =3D { + .mnemonic =3D ".byte", + .callback =3D cap_skipdata_s390x_cb +}; + /* * Initialize the Capstone library. * @@ -42,13 +75,20 @@ static cs_err cap_disas_start(disassemble_info *info, c= sh *handle) /* "Disassemble" unknown insns as ".byte W,X,Y,Z". */ cs_option(*handle, CS_OPT_SKIPDATA, CS_OPT_ON); =20 - if (info->cap_arch =3D=3D CS_ARCH_X86) { + switch (info->cap_arch) { + case CS_ARCH_SYSZ: + cs_option(*handle, CS_OPT_SKIPDATA_SETUP, + (uintptr_t)&cap_skipdata_s390x); + break; + + case CS_ARCH_X86: /* * We don't care about errors (if for some reason the library * is compiled without AT&T syntax); the user will just have * to deal with the Intel syntax. */ cs_option(*handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_ATT); + break; } =20 /* Allocate temp space for cs_disasm_iter. */ --=20 2.25.1