From nobody Sat Apr 27 17:26:39 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=1600797599; cv=none; d=zohomail.com; s=zohoarc; b=YA6iTl5SSR2pfrwtYUCmCYONjtrL6+O00pKNERzS7EdhTaLS6xVVrZOziGObJNRxSauW7K8Y/+kC1sGBlma+1ljqlpqyJug/3bKhPR1NJeTf2YL/UME4Dp39XOY22R1tPbqf7VfxC05/htFhOYHDW4yrxsegoBRKUWlzPhJZWBw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600797599; 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=NzrU2ZsvOjr+qbxxdvFZuzTGss8rzY+sdJQi0RtRziQ=; b=T0p6HZO9ke38+Ypuk+qXyx/XhRUY2P5hTHAcnZh+kkhqeGRLJqzwG/gjrwoKwJB7hUQg7lN5Hpd5O3s+isf0euzy1wzRFyeCogpkgApUPCkaOem+TIDT6LecgAi4+n58umPc6ykfsyNE/uzpaBG+HprIW/LcXR7myObtswGlaf0= 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 1600797599904551.9964140368987; Tue, 22 Sep 2020 10:59:59 -0700 (PDT) Received: from localhost ([::1]:47976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKma6-0003Ps-1C for importer@patchew.org; Tue, 22 Sep 2020 13:59:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45454) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKmOL-0007wK-NY for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:47:51 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:37670) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKmOJ-0004KF-77 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:47:49 -0400 Received: by mail-pj1-x102e.google.com with SMTP id kk9so1802414pjb.2 for ; Tue, 22 Sep 2020 10:47:46 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id r1sm14825310pgl.66.2020.09.22.10.47.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 10:47:44 -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=NzrU2ZsvOjr+qbxxdvFZuzTGss8rzY+sdJQi0RtRziQ=; b=uAToL0DU1Mm97ZdYy/+TRMsG1IhcG61Pv1uWzjcaMJBWfsP/WThWM4ikyC89JOHuWU sK0SFpXqPv1OCJB0i0wkChVYZv0gxXmfjVW3ylT4YDXn51e5VkpjPAdaO0TbhEhJax2O dyobhsSurRikdhJiEgjn+ZDahfKNK5KJW0eshQgvBR7ubl0/FRB59svqoa2CPZqeTGMO 56HHx3SRbasmgTqoTYVg+ZuR+UzVHIdh4yN4XdLRvupFr9H9PiBuifpXAqsrTEiaYp/l i2R90WR3c6cJeZ68zyMjbLCmC681CGBjyK4jjXwmngKO6sYKAI4yU6fmIFwcynq36YpN ey1Q== 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=NzrU2ZsvOjr+qbxxdvFZuzTGss8rzY+sdJQi0RtRziQ=; b=S+c4r/rIXWUAtxAL6IW9gWqp+w6yrPuFzBv2+FLjvBuuLvsI6n7anQjX5zTD8rtKxs OJGqcaYKIfjtrc9i7sTPiSRoARHS9PoszDsA2OjU9PflKz1WOSSgpblcC2FUvdzoS45A +xhs54y7ZssYoYNvaVvBSPuoHU+Cod+p6aPzfmd9h5VSSTTrvDfbHpqvhi3RKlYYjfzN DMZ2MuEncjwR3FGnaAhJYf+FIEdzTBHqwh9ljPjK/Se43mH/AlB1uUbGKcdaLhgYOTj0 2Ml5KI1Sfw27Rk1rZxYCZy3CxW4IIw6T1CtxhRlIhGSnIRGv+L5Yi4v2fcjdOfDdYm2Z mcMw== X-Gm-Message-State: AOAM532INLtt9/Rv8TKd6mekfsZTVrCEUYWO4/VNeZ+yf21lw6qdHxJP /MPTBWnczDzjoXcLTHSUdCAZ0+FSDHxYpg== X-Google-Smtp-Source: ABdhPJx9PzNrDNdbs4LSj4wcGQMWlETdqE2AaY+abDMrJErBMmQzjMZqEZTJwO3869tk4gPM+dGUrQ== X-Received: by 2002:a17:90b:a4b:: with SMTP id gw11mr4565955pjb.37.1600796864946; Tue, 22 Sep 2020 10:47:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 01/11] capstone: Convert Makefile bits to meson bits Date: Tue, 22 Sep 2020 10:47:31 -0700 Message-Id: <20200922174741.475876-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200922174741.475876-1-richard.henderson@linaro.org> References: <20200922174741.475876-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::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.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: peter.maydell@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 configuration header file instead of command-line -DEFINES means that we will rebuild the capstone objects with changes to meson.build. Acked-by: Paolo Bonzini Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- configure | 64 +++----------------------- Makefile | 16 ------- meson.build | 111 +++++++++++++++++++++++++++++++++++++++++++--- meson_options.txt | 4 ++ 4 files changed, 115 insertions(+), 80 deletions(-) diff --git a/configure b/configure index e8e8e984f2..a82b16a60a 100755 --- a/configure +++ b/configure @@ -478,7 +478,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"" @@ -1580,7 +1580,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" ;; @@ -5128,51 +5128,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 @@ -7292,11 +7252,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 @@ -7819,13 +7774,7 @@ 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 -fi =20 if test "$numa" =3D "yes"; then echo "CONFIG_NUMA=3Dy" >> $config_host_mak @@ -8008,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 f4d1ab1096..f23273693d 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') @@ -409,11 +410,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(), @@ -470,7 +466,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 {} @@ -610,6 +605,108 @@ config_all +=3D { 'CONFIG_ALL': true, } =20 +# Submodules + +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') @@ -1512,7 +1609,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..e650a937e7 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: 'auto', + choices: ['no', 'yes', 'auto', 'system', 'internal'], + description: 'Whether and how to find the capstone library') --=20 2.25.1 From nobody Sat Apr 27 17:26:39 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=1600797834; cv=none; d=zohomail.com; s=zohoarc; b=D6N2nqXS5DO+o2+pI3i3BS9uKIZRhN+fVSnPBU2bzn9iiSJI8FdDFNWzvMHZsi/JMEIn3kR4BmqxXckqGsfOEOMpFGHnOZG38Dk0PkYyE8bfwxvqo09XFDzeFAApR0sjjinPyrxJgVOc6PrajRftp/mpvMLoPsboAAR51xjS79Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600797834; 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=RjVvqo8ZN1svnaE4XjyeOaQhSPIhylYmlVezwsCJ1nc=; b=JukMep7W0010mt+tW7s4s20CIVoaarB2RXFoMXbLALMPY+shNtCbZr0sp7kgINrubAw2YY0yKmFOPY4D5asNStwY8wtMqPHeo8RrDW9FEEza45w+F9SuzwfXNearUqAn2w7MfJUsAGB2ihyvlhZr2q5sLrr+jDIwbB26eXFRvx0= 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 1600797834564754.2219819124591; Tue, 22 Sep 2020 11:03:54 -0700 (PDT) Received: from localhost ([::1]:54230 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKmds-0006Py-RC for importer@patchew.org; Tue, 22 Sep 2020 14:03:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45476) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKmOW-0007xl-55 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:48:09 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:44012) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKmOL-0004KW-7m for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:47:56 -0400 Received: by mail-pg1-x532.google.com with SMTP id t14so12557828pgl.10 for ; Tue, 22 Sep 2020 10:47:48 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id r1sm14825310pgl.66.2020.09.22.10.47.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 10:47:45 -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=RjVvqo8ZN1svnaE4XjyeOaQhSPIhylYmlVezwsCJ1nc=; b=fe241jQt1CLM5drVljMaKw7BmUENOHX1OQIzxLY7Lo8knciMmnVGe3D9G9RCfEML6p uLKR6SUk1xc+5tmbZPHa6UBvk+68sLYhrwb007RcXobJIKmbj9Lv49o8g2DKoJP+eSJ+ CiBFHNI2FiiUWiajDMp7/R+1am2WUZVyHrA7OkUlbr/P0m8gPo5dJWWuqOAB1JYI+jLh z2EPAJE/Cq3EXmSJLycmJ5W8EVrPZzUax5OGY8BBdGvgW679vfZkGhOFyLAWO9S36/iQ FjaEzlfSxztO//Y1rxC9FAjGpQ/7ry5MqSZzrdWxg2hHNjq+XE80xTNwRhN2m3QSX65k fEQw== 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=RjVvqo8ZN1svnaE4XjyeOaQhSPIhylYmlVezwsCJ1nc=; b=qFSByWRhaDtkcrolJqbaZlr2W4MFKknEOD142Afp5C4/f7smfRcWafwRqH1d+363iw 9YnjEU8S9w1CkWJvYNOeZh4Ku55L7LB+00WAf0+x9cYwElseYZgR5tijXxKufCSLNZmU 2LaWc8RXAliqCR+keHgGACHMrv3rymaIFaYlJ5e1iczlapuJcCktinEOy1YG5m34/XEP yVMqPEPm1AmMK0kp0PHJ7cPnPTwKrZ481kcAUipeGnLSGrbLF3mfwZu+DK2yJbJY7e0v v+N7A4gF66tSmuepo8AYWYUtSqly6pLaaRQmbXEoiK0JrFYq1c99HwnE/AnkqcA3RGIq pHCQ== X-Gm-Message-State: AOAM531cINYp5PXzQcnqE8cwkQ/ntM6YQCpn3F4eSBqVN0OUu8vopH0h vikXax7HYFlmfdmiW23jqUHl887VbxItNA== X-Google-Smtp-Source: ABdhPJxLgT9SV2tXvE9EG91wrJGb07wqVJtx4cgIL8tUqgRiKbZ/3re9QYmuBbwpTEAaBPdj0F2ilQ== X-Received: by 2002:a65:4b86:: with SMTP id t6mr4197575pgq.81.1600796866879; Tue, 22 Sep 2020 10:47:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 02/11] capstone: Update to upstream "next" branch Date: Tue, 22 Sep 2020 10:47:32 -0700 Message-Id: <20200922174741.475876-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200922174741.475876-1-richard.henderson@linaro.org> References: <20200922174741.475876-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::532; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x532.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: peter.maydell@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?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 Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- meson.build | 3 ++- capstone | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index f23273693d..4c92b43fe5 100644 --- a/meson.build +++ b/meson.build @@ -677,6 +677,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' ) @@ -701,7 +702,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 diff --git a/capstone b/capstone index 22ead3e0bf..f8b1b83301 160000 --- a/capstone +++ b/capstone @@ -1 +1 @@ -Subproject commit 22ead3e0bfdb87516656453336160e0a37b066bf +Subproject commit f8b1b833015a4ae47110ed068e0deb7106ced66d --=20 2.25.1 From nobody Sat Apr 27 17:26:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600797159; cv=none; d=zohomail.com; s=zohoarc; b=efg5qLQFXbFobC4jFvCdk+BxybR5lH2m3PqjZqjKHgwlFCQnkvAbKaKwpmUkR1d0ilt1L1OoKAEwpGtoGAaU2cZiY7PSWNXseOtDnvB0d0gJRX0XMjRiVeh0MQRUyHMK3/3WFrgCwZGd+IhNMD5cEAjx3PohF35/O2ytPU6mohk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600797159; 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=Nh1db1dZeJoMf+455PtMij2SzqSvT9UF/0EwtPYuxYM=; b=SEzEUFfQS8wbJSH0J1fmoPq0qOTELimpHfovog/PWt0bT1YpjMwKrcqya0zp/bFferAGL412eGtbOINfCvyxjzqC4rS6+j9kyWPJkVGCA+ETdzCS7IzWfYhECEnBAyUsnJN6Z9MKm6pEOqZRuU3VXbuRUX3pqaB6LSf020165Ew= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600797159585131.92358682359475; Tue, 22 Sep 2020 10:52:39 -0700 (PDT) Received: from localhost ([::1]:57636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKmT0-0003qm-5S for importer@patchew.org; Tue, 22 Sep 2020 13:52:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45486) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKmOX-0007xp-K7 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:48:09 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]:34243) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKmOM-0004Kj-Ta for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:47:59 -0400 Received: by mail-pg1-x52e.google.com with SMTP id u24so1752152pgi.1 for ; Tue, 22 Sep 2020 10:47:49 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id r1sm14825310pgl.66.2020.09.22.10.47.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 10:47:47 -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=Nh1db1dZeJoMf+455PtMij2SzqSvT9UF/0EwtPYuxYM=; b=rCRmzQtZcOTLr4VP/p62Ndm89mwkUbhNCCL9dUAG+GvMLnfEV1L0APVkyjB6gt4Ujn wrgGck2FsZ0lpmU0XKoftyB/YDx8Cwdkwmy/N17xgM2rjkBg7+jfeGRSHAiCeS/LoYpP ZwqO6fBoppgRyapoI7x1tgQWAVJOb6kT0OQ+Hc6wrzkOVudQbMJPLupvD9dqJrWMpRdc 2MH8Ahyn/s4JmKQ0Q13pTrJu4zxOb3afDbbg3OeR2GS+iVpkQ0LGDoIQsyJhZNPYqHqC lymYznp7D18pKVC5Tv8Za3kJKEjQbKKVFaXWNuAXe/NOmTkYXiO16ogc4l027Vwim1LV 5d5A== 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=Nh1db1dZeJoMf+455PtMij2SzqSvT9UF/0EwtPYuxYM=; b=mhJAnGcm/pEbzwuOlLlRaQhuUrH2YubaopEWwuVAORwfx2PSu75PTsfu/7Mgi0iskN qQ4kPt4ju8QcnKOVDjmxdr4570+HO9iNALyLjv2rU7Q7kJUtgKC/2VYq064v+mqyVylc X0vTYb8BbzQ0IHi78eFfdv4w3WCzHiyE4N4smvqLXEWrtwVkcsjjqO0sC3Nsdue07nje lFqSVFGPsJ/3psMIjkIVP6JCQx55RXmaXQ651uGfVB65Y2lU5j5fH9s1P8xY+Ehv8axV pYEboVhUffPlrTQqnD2XA2eD9Y0t7AbnfOe7lMC/P5/2gVqnwVl+Mstrp4Jd1UVa1H2g C7wQ== X-Gm-Message-State: AOAM533rd1piAOs0xjgkcPABeQaufLoX4Wc6FWb/ans+FG57dJy79wnH NMUlXL+F+X6fhTgm4C90+uQWeKVclBPxcg== X-Google-Smtp-Source: ABdhPJyOfjFDPEXoXd5Sf8B+XN2kw/K/E8Vr5gwnmOaI/t8zhFnfj5RpID9z5crNVGN550dz0qflOA== X-Received: by 2002:a65:5902:: with SMTP id f2mr4195566pgu.379.1600796868535; Tue, 22 Sep 2020 10:47:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 03/11] capstone: Require version 4.0 from a system library Date: Tue, 22 Sep 2020 10:47:33 -0700 Message-Id: <20200922174741.475876-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200922174741.475876-1-richard.henderson@linaro.org> References: <20200922174741.475876-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::52e; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52e.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: peter.maydell@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) We're about to use a portion of the 4.0 API. Reject a system library version prior to that. Tested-by: Alex Benn=C3=A9e Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 4c92b43fe5..114b136129 100644 --- a/meson.build +++ b/meson.build @@ -613,7 +613,7 @@ 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, + capstone =3D dependency('capstone', version: '>=3D4.0', static: enable_s= tatic, required: capstone_opt =3D=3D 'system' or capstone_opt =3D=3D 'yes' and not have_i= nternal) if capstone.found() --=20 2.25.1 From nobody Sat Apr 27 17:26:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600797133; cv=none; d=zohomail.com; s=zohoarc; b=aUN0VEm4X/qvR3mc/diY6uWMOK32n+3C3dJNg9ADKLZClI8PWP/bd3/gFnO973e8g968BnbRtux+gC7KyBR8GiOa4YoigUoZRJJFUxnN2s4z+qpKs/T4K6Fg9+2caYa58KX9FMXtcLZUVpD9NMGSA9OSDQePUwKL4HHYzdZtnQk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600797133; 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=CzXADkkcwqXZtobMqRgIZ6k008MJ95TKA8X3VHJ5T3U=; b=NJr4h8kAzwIBfsnTK72VhlfZBueXrt9XwIZeaEbB6bMWbxQt9Tmdtb5xwr2wqqnAqUrgVcn58P9d37ByP+40CFyYuuYCdiDdo27FLuAiXY1yFAiWPb2vtgpKoEoZqq6B40dbFRriYzjFEXggOSZeVwbcb8+v0v+C0LOf/y82lrw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600797133626705.3476543799691; Tue, 22 Sep 2020 10:52:13 -0700 (PDT) Received: from localhost ([::1]:56372 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKmSa-0003J8-5v for importer@patchew.org; Tue, 22 Sep 2020 13:52:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45526) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKmOf-0007yD-6W for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:48:09 -0400 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]:40152) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKmOW-0004Ks-7i for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:48:07 -0400 Received: by mail-pg1-x52d.google.com with SMTP id k133so7810101pgc.7 for ; Tue, 22 Sep 2020 10:47:52 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id r1sm14825310pgl.66.2020.09.22.10.47.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 10:47:49 -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=CzXADkkcwqXZtobMqRgIZ6k008MJ95TKA8X3VHJ5T3U=; b=pXl4JIWdqO+G90JBZGgr51GEsVfBjrIMi/z5bvv4pJ3x8rj6ugGUqnB8/XzawS8NZO r2blOOhMXYLS5FQWjq72k4BCeuhhx9lUL53QWgo598aqBunR6tva+JB356DfpiNlqIIA 3I0eztV0m9frnssLO1z711MDVMSE0S+IW44Ie/7DviAQTFOEPPnspIiIi0Ergw85DYlv d+gkNE4asJfM6mRqcd9c+OoeWLGOvfgU0gsQTKtPBGPOSeSBIGQ2/mONxR1jM4yEBU0N 1473eWmHm7I5h+CX3QbgRRIydi8cijLly8RQF6U3LuL1nFanDMzJb/1Qi2yZeZD9TiMw xzvQ== 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=CzXADkkcwqXZtobMqRgIZ6k008MJ95TKA8X3VHJ5T3U=; b=bnEBF9vyJY+YUvrqHGWKDynntwzsGiQ6gjmCRIG8j0jABUMPpKg6egHSo6TzJ8igoE R9Ww2VS+CLNkIr8p8qvGbEJluzH8x1jY39cCSIaTWjyv6bkeQhOa5XIIt2Tl36CmKxaZ 9TzR80jyvbderjJQ7MFyfqCC7RrOTya3tErfOwbbh1EQjAdIO6ziQ15UOCnmU2YY+0WB lDku0HHHQ7T7Z5XxWkdAPcxWe1r41BMDc3QoaPTG7Q3ky1vmt++kUmSCgdbPfHnNf+WE WFFC0a3TLO/MHdqMr3BLnJcq7qDd10bkHA7223r4dEvSI/DbkuBFYnocdTDpV/ZR8e1S AgWQ== X-Gm-Message-State: AOAM533IBPjqY5bLsmKM6NcV/WEFPJXD6I5Qvr3zCUG6UbcKbLWiqWMv RUu0ez+YpsgfK7JzSb/ph3+cIOttClXHAw== X-Google-Smtp-Source: ABdhPJxeOt/K4mKPisiJoAFF2GJFHZCvC457NNe/ITK8x5enway30MPhzQSnODDNeMiVlwQuqrbI6Q== X-Received: by 2002:a17:902:b186:b029:d1:cc21:9a7d with SMTP id s6-20020a170902b186b02900d1cc219a7dmr5637042plr.8.1600796870648; Tue, 22 Sep 2020 10:47:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 04/11] disas: Move host asm annotations to tb_gen_code Date: Tue, 22 Sep 2020 10:47:34 -0700 Message-Id: <20200922174741.475876-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200922174741.475876-1-richard.henderson@linaro.org> References: <20200922174741.475876-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::52d; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52d.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: peter.maydell@linaro.org, Thomas Huth , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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. Reviewed-by: Thomas Huth Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- 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 Apr 27 17:26:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600797020; cv=none; d=zohomail.com; s=zohoarc; b=k4md7UjSjrCHWXSzRha7Oyh6ih4hS92njO1jUMr+fIw0zUMW1lsGjEOsfCLM8RyhuNsFczMBaBuK3vILIUZmyOrEf1YpOOcsUEuj9f6OfQoD3zvOPnCJ0fY+8TUFZbNEhu8d6Tr63YVL9dfL063IQtkkQcLUerv/n2MSUjuJ2xg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600797020; 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=7DH5ACZrmuE+pcBzcImmHajEhvsRaYsVmW707wTIMrk=; b=gWp1gInvc8eOYgsk+XDSMTG78FiRyI/yqAPkKHxw1gLEKMr7s2Z2nDetYakXBRUQfza/AIKH+j7Tt9k+E5vKc3pNHP2HqPBtc74lB5kZZKTUoSRy+yoYTXfTx4E4FofCXpTfevLQhcYAPtmGVhfHbCd8bGFfPsnHlXI6WVnJ4IU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600797020822578.1774135914577; Tue, 22 Sep 2020 10:50:20 -0700 (PDT) Received: from localhost ([::1]:51992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKmQl-0001Oz-3h for importer@patchew.org; Tue, 22 Sep 2020 13:50:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKmOf-0007yh-WD for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:48:10 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]:46789) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKmOV-0004Ky-S0 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:48:09 -0400 Received: by mail-pf1-x429.google.com with SMTP id b124so13115397pfg.13 for ; Tue, 22 Sep 2020 10:47:53 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id r1sm14825310pgl.66.2020.09.22.10.47.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 10:47:51 -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=/MwDE87kvs37+LuOQWfCbKlVXbdf8wzkD2pAO2kX6Cc=; b=BumFl4HXJsPVWLPhDj69j4XyJGtQCHaSBFEzpECOlVghhpU+sHuXq0v7hmInlVBsmL VjPfAiXEs+MVoRieIx6bMm0ztV7qbNKuIb2VFqmLnJhQFaZ/iX02t+4yqAaScUv9+cSy 1LxIJNdYFRv1EE355J0pzdrs9yKaSY6VJKaUeNtkgaP/5FuuG2M+G/k4qbQXzO+7MUyP JJkDZKz/zqn9guTfOSFbKx6NY+GKJW6bsc44zCVXoSqH+clAJJb2frGNMLotKrxhTmV7 vMQOtuP5sg3pA0nUuoTFH+5dNYTnpKBdvLhMZsoGBQ7KyuPH9pKMa18YgTzjqogg3Ix6 K8kQ== 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=/MwDE87kvs37+LuOQWfCbKlVXbdf8wzkD2pAO2kX6Cc=; b=qIwQSXRJn6LFWH4zE7qNVTFu77dz/6HOZ9JukY18qTmuZnHylpxxVaiK0dBmxCs6zF qD6JW/8YyzCkNXvBz/ml2xsnlZtZSvYmlMURsDDAibibyNrnddLVM/KA0HGF3/BHrloz mjpUaNfNUKEdqYqZyXetH8C65mQ6sXQS2J6CFDGeTWm0CtUqgepL4UrCh6H1T23k3uEL vpNCXZCaZTRwTdYvyRFu3n+49BH+bldtxw6uCHFALLPpPhRb5Z4NXtyx2Hvil6kPn89U 59yls1XMwzFcyNQc2Q+FlF5cl4mwvLZLEbxzm6g1jl9pIqKms+mejH+2OsorHHZx51eW dR/Q== X-Gm-Message-State: AOAM530NHdEWa5E3TdDiW1DRg+PM4Yx8e8AAJP4sCEl6IHuH12x+8Ko+ A8Cni5HuX3SVduM4W8wR+ErI6vSYaJx+6Q== X-Google-Smtp-Source: ABdhPJwP6KgTysIeL1/zByG9RfyQz0pBjexWdZvYoHG0gH5UAakpNmO07SRuV2ggW8oJHU42a4iGZw== X-Received: by 2002:a17:902:7c83:b029:d1:e603:af74 with SMTP id y3-20020a1709027c83b02900d1e603af74mr5737532pll.82.1600796871967; Tue, 22 Sep 2020 10:47:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 05/11] disas: Clean up CPUDebug initialization Date: Tue, 22 Sep 2020 10:47:35 -0700 Message-Id: <20200922174741.475876-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200922174741.475876-1-richard.henderson@linaro.org> References: <20200922174741.475876-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::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.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: peter.maydell@linaro.org, Thomas Huth , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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. Acked-by: Thomas Huth Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- include/disas/dis-asm.h | 62 -------- disas.c | 330 ++++++++++++++++++---------------------- 2 files changed, 151 insertions(+), 241 deletions(-) diff --git a/include/disas/dis-asm.h b/include/disas/dis-asm.h index 9856bf7921..dda247eaf2 100644 --- a/include/disas/dis-asm.h +++ b/include/disas/dis-asm.h @@ -406,7 +406,6 @@ typedef struct disassemble_info { =20 } disassemble_info; =20 -=0C /* Standard disassemblers. Disassemble one instruction at the given target address. Return number of bytes processed. */ typedef int (*disassembler_ftype) (bfd_vma, disassemble_info *); @@ -461,67 +460,6 @@ 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..1f35a4a33b 100644 --- a/disas.c +++ b/disas.c @@ -16,78 +16,68 @@ 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) +/* + * Print an error message. We can assume that this is in response to + * 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 +413,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 +610,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 +646,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 +708,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 Apr 27 17:26:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600798056; cv=none; d=zohomail.com; s=zohoarc; b=bFPywFdydMv72PqCMyrPVGgGxLIEM66dJyxgKZWPS+Jhevh25eNZYSb/ArMJcNfbYZmERAZXsTgtnnWN8yk6VKNevXWABEAj1fnvgT5se2y4DWAIf7nGZGfuLeHlKrC11T07ckNlKck7dGBAonfzN70iox4XHCTPzVDBjHlHek0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600798056; 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=Xl0njD+k9BHK11779kcuePFVTL4w0dzNFEMm1XknPiM=; b=oDPcEFl2MB4XZ6QxWy4n2P8aTQdVWUa6K2sd8a6acSDCUmqvO/hjj9Gt9FqEV6uWQ/jq5GueRIM02HHsm1a5wrHghou1FL4WVDCYHXs2ThewCj3CZmcwyFGKlfOdm3c98YZaLeTzHnzSETaygMMgidVvF2sJ0DkJ3UccJbnQL2w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600798056819416.4817242310917; Tue, 22 Sep 2020 11:07:36 -0700 (PDT) Received: from localhost ([::1]:59366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKmhT-0000L6-88 for importer@patchew.org; Tue, 22 Sep 2020 14:07:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKmOg-0007zh-CU for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:48:10 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]:39747) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKmOY-0004L5-C5 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:48:10 -0400 Received: by mail-pf1-x42f.google.com with SMTP id n14so13132241pff.6 for ; Tue, 22 Sep 2020 10:47:54 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id r1sm14825310pgl.66.2020.09.22.10.47.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 10:47:52 -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=Xl0njD+k9BHK11779kcuePFVTL4w0dzNFEMm1XknPiM=; b=oSzCqkmdKmOyCI86Cn5o33TjoGcj6s+D7UShBli05lgWxHh2Xs1mt+p4cmf2zEY6Og vDHGXC6viKd+ES+NL8vc0KEnlGV4/U7tEy/kvbB49xuK7NeboiLT13Rbl3numJAOAf7R pZIX+zZA5q6SfRt5l7pX3qRrgbsfSXrjdVgq6cbbuPJoTOBKOeydM4lNOynpwT6eTzax I2Z1GVcVt5jvYrOUQIYeLfHPvGgeraEiNtA63sWqrSPL3+thCRxgkn3eDnpIdUxojZae oJ3Zkk71vxWHKiFnOd3DTJDc5Tcu001W9N24Qfz1n4+T5yNkzvo3wXrhltHOQbGt8UEG Ebyw== 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=Xl0njD+k9BHK11779kcuePFVTL4w0dzNFEMm1XknPiM=; b=sZcZPBHkyHWPE+m4Nn0nmsjPnryw6aGNMd9uNd1ha40Ts9Mt3QzROAVJAGcojlQfVV Kjw+Uam8VNA/C+06gUjzFqYnVS6eHgwxdLAWDwcB9JypC+WiVkVSbwwozatmGRcoEj1V At6XQwsK5TWKTO7tbuopF0ElYP3OeH1poJHdpQAfAQ0/WbsBn1BalbNb+Hz5UquEh9E0 mElxklCLhS9JGaCWZ2H4SYJ0M02vjuK+TQGKMq8f5TToMmZGfxhy+9/SyAvK8BEfUFp7 KPuPHdG9Bp7oE45fpREj6ke+Z+S5J+a8qc5WQYxYYIgqohxi/t/8O6/u7bescuJOA6dA oWoQ== X-Gm-Message-State: AOAM532pGpdsNjuUBEllXHJJZOsMYlAXI1bso6/uCi406mbYefz2teDI 3EvlnjX+bmifTOx17qduJiSapghVufhGmw== X-Google-Smtp-Source: ABdhPJz8ktM9wqQeSaAWHaDg5sKxOY4h7ka27EP4hLl0BlZBtN14+s7XXhKO6PKEaKW0mMZBgG9U2A== X-Received: by 2002:a65:5aca:: with SMTP id d10mr4447952pgt.362.1600796873585; Tue, 22 Sep 2020 10:47:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 06/11] disas: Use qemu/bswap.h for bfd endian loads Date: Tue, 22 Sep 2020 10:47:36 -0700 Message-Id: <20200922174741.475876-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200922174741.475876-1-richard.henderson@linaro.org> References: <20200922174741.475876-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::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.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: peter.maydell@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Use the routines we have already instead of open-coding. Reviewed-by: Alex Benn=C3=A9e 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 dda247eaf2..6b45aa9898 100644 --- a/include/disas/dis-asm.h +++ b/include/disas/dis-asm.h @@ -466,11 +466,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 1f35a4a33b..8d1403dedc 100644 --- a/disas.c +++ b/disas.c @@ -80,61 +80,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 Apr 27 17:26:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600797344; cv=none; d=zohomail.com; s=zohoarc; b=cwzrO+qSoLnazTr05zAn3vS7+LOG6LG9nw/FcwHD+rys4eaDg2Uin+4X4ymGa5ej4KUfeBobGFJlsCvlW9bp1/jfHXz2Skm25Omh05cSHHlc5oz1d1pQzboZu2QFHZsHtXxTRAyrJMwBk2XfBKYoFy+JLutm4opNswdUiYW+Pu8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600797344; 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=c3L7ongZcFIrjIrL9FZxznJ0aLcGoTeG6OyijrdzkkY=; b=EohMPQ8Ieo14hYqD2lBpsHcjoycykRUXVvEG6aWHM8cQgJA81EsL3Rb71nOtaQ+WLikSusUa25n4QtKrWXb4ohpDz9jy1FEnASp7XTZrb8bBFn1HsPo/59kAvXEXf6vFEr2KLT4RptqPI07XO5Wgo/Y3VkYOjrW9osfrg02iq+8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600797344666280.3181371741433; Tue, 22 Sep 2020 10:55:44 -0700 (PDT) Received: from localhost ([::1]:38940 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKmVz-0007mw-8h for importer@patchew.org; Tue, 22 Sep 2020 13:55:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKmOj-00086M-Et for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:48:13 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:39912) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKmOf-0004LA-MT for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:48:13 -0400 Received: by mail-pf1-x443.google.com with SMTP id n14so13132292pff.6 for ; Tue, 22 Sep 2020 10:47:56 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id r1sm14825310pgl.66.2020.09.22.10.47.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 10:47:54 -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=c3L7ongZcFIrjIrL9FZxznJ0aLcGoTeG6OyijrdzkkY=; b=Se6gP4o2PGt3zFRfnC4L3JHF73dkbf7H8OpwU7H88ODAfQa9oAwOQYNo9Wp23pqZqM 6VPYtk5fvOk1n3sXjf38ySkcCEbqmG+xIJL+FE/nmZV+c/RbpqvZabIIvBGrZa2lwWCU 6aVsU+dTmXjtoFyF0n2rL5U594+mOXHdiUgqKG6bS8ErMsX4FIkZoXONL9PwziUf6ysi IG82e7G0W5A1aYRGU/HnUCLAWz5oO2CMX2Ws4QY1zzk54xWNojcifDASM47MU4eKGaY6 Lm2awsgBBlVK3bhZe0le+HG6Ssa7AXZZUlsgSesDghkH5aIbLDwbDqmslsVxFAZKFMng FOHw== 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=c3L7ongZcFIrjIrL9FZxznJ0aLcGoTeG6OyijrdzkkY=; b=YDNrtZytmQBJ7tCJsBEcgQflFkBFT48t/LmDNAdHxkUEW1USOZ0O2Kx837wjYA5H/U XhKx3U0WJmO249//7GUv9vf+YO6g8PN2r96E+Om+eTDLe/dL5NPvYXYBymzBwvu6PUUK UGH0Y3GdxEKim1rZAZqbDzVvj+0xf5NsMmLbyIJ4aTf8+YoHOniYnOJEj6Jz6cIeb1hG n79o8wYkAPKTJ/X+rsH77TwnnMQTUJHTayPmJ4VJ+vzrtKeBHejuQTylaCo8XIqQcmSQ UBnhrELJSl9KdENaxJmtgsLVxJMBWoXEkipmqpYhGYygl5AptaUC426okrTXAtK7kxRJ cbVQ== X-Gm-Message-State: AOAM532Qzke6rINP0ef98LTdKTeKp2Zro59216VAWKde4smNnymqmltO QhJSHGbvG3oZVuSzgfKHqgM2sGw9j+qQAg== X-Google-Smtp-Source: ABdhPJxIybTfPjzUTkxU2jMCrWRYL32D1s7+4a8JZiz2E7mI1OyJ7NAacAeukYklcVeAABQN6w24mw== X-Received: by 2002:a62:7c82:0:b029:13c:1611:66b9 with SMTP id x124-20020a627c820000b029013c161166b9mr5018303pfc.4.1600796874830; Tue, 22 Sep 2020 10:47:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 07/11] disas: Cleanup plugin_disas Date: Tue, 22 Sep 2020 10:47:37 -0700 Message-Id: <20200922174741.475876-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200922174741.475876-1-richard.henderson@linaro.org> References: <20200922174741.475876-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::443; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x443.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: peter.maydell@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- disas.c | 55 +++++++++++++++++++------------------------------------ 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/disas.c b/disas.c index 8d1403dedc..54a540180f 100644 --- a/disas.c +++ b/disas.c @@ -493,13 +493,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); @@ -519,28 +518,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); @@ -555,34 +546,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 Apr 27 17:26:39 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=1600797268; cv=none; d=zohomail.com; s=zohoarc; b=WBC5/OWnjAiYtBLWlV8D9MhuLoJJ0Pndr8uckUI5kNyLd6i877N3RoMrUvdP6urpzwG5Mm1mxIC6hpVNbq6MRGN4GUtp0+da0RIGytvwMP2dszsD/WDal8Br7AvdHrDo29Y3q8a1BS67T+WiGlTtGAXY1tkXwpEdkYzQGmzPy+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600797268; 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=aVjTTGPPlbmxoAcKrlyikOZCYood3q70I0b99WJvGvs=; b=gkUKy+7WHksjbAxmorFQFtojiaNvteD+2MWhA3LybAeStexwkPriDDMu5Y9Q8Xk+mf5/YF4IUgLiiuYWaiOANPR/4Pq8UWJjfaNTg/qvMdAxwDg1nnrWGclvpBKNkClL1NPvitRu8u/Xg8X+pRc8ftZNDAgQdkNp/x5BS2ZL7Bo= 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 16007972683741023.5825134230402; Tue, 22 Sep 2020 10:54:28 -0700 (PDT) Received: from localhost ([::1]:35862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKmUl-0006Vu-24 for importer@patchew.org; Tue, 22 Sep 2020 13:54:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45604) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKmOi-00083l-8j for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:48:12 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:39913) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKmOf-0004LE-Ix for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:48:11 -0400 Received: by mail-pf1-x443.google.com with SMTP id n14so13132364pff.6 for ; Tue, 22 Sep 2020 10:47:57 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id r1sm14825310pgl.66.2020.09.22.10.47.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 10:47:55 -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=aVjTTGPPlbmxoAcKrlyikOZCYood3q70I0b99WJvGvs=; b=JoGWuQQh4GyTFG80W0ad4QgGXomABnZrYUmNNBkOnzd6xAoDYva2pCvPoh3/+zfkzB OLBmmp3gRZlxtizGgGofh/b4yBKZt6uQ3ubrMhk8F25N63y2K5i4O1KfIhO6g9cByGbW CMWCdlec6XWceOIU2b/Q9aYTyyro6U6t+NH4CkZuq1YaOtkLRRcjj5ockRz9kXMzFwHK ayAC8zPaShvkml4mtM+LpXJiQ6qTilSCbqNzN+Ar8PQI9PghUkF/QsUHhm72rIkmsxrR MwHwvVayBnE+Rpk4sPq53fHrCl9/fak1H9+zGIOpdX3/mGSdV4aZDCmZXBzBeMhDFAJG 9lBQ== 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=aVjTTGPPlbmxoAcKrlyikOZCYood3q70I0b99WJvGvs=; b=BDggHLlnts8IB0NlCxI9GcxZxfVAZMpLir3iJ+u05XwaknLZIk92Cc2vyCiowjgLaW jc6JX82Gif+huL24yIcDxbk7Av4VJcoBQPpyo81HiAlrxT/ZonwnWk8OUiShfv+XZihE bb7UzbK3qk/FMVBokqqRlBdgSy5oBA8E5aDVAnmU169jeLrPQKQVccJMfgsnl91rq5Y3 lkrYAOaaqoffF8fY7mVphW7mDg/tOoTzpXHnivpSSUpUZkA63NdTajB7wKHTyRPBUcRd 5+wKvJa8aHlYfZDhGolJrouKxOKEDC17HtexlgpJf15d8jnpfjhFzxPjCQhWxYtuThBU 3rWg== X-Gm-Message-State: AOAM533oVpJRM9bzQaUgQgxWOb1pGWAawgUFB/DPwTxXSVw5hVbiaHf1 oSXT98FcsGrKHGBfs1XqUw4TBT7OPXY9xg== X-Google-Smtp-Source: ABdhPJw3mu5ZsZ1eXAcqnN6IfCddtZj/M20oSQvxXkxxGVUS1iHPl+faUM3sKW+XiRnrU0Ud2M3blg== X-Received: by 2002:a17:902:9301:b029:d1:cc21:99d0 with SMTP id bc1-20020a1709029301b02900d1cc2199d0mr5905070plb.25.1600796876513; Tue, 22 Sep 2020 10:47:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 08/11] disas: Configure capstone for aarch64 host without libvixl Date: Tue, 22 Sep 2020 10:47:38 -0700 Message-Id: <20200922174741.475876-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200922174741.475876-1-richard.henderson@linaro.org> References: <20200922174741.475876-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::443; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x443.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: peter.maydell@linaro.org, Thomas Huth , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?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) The ifdef tangle failed to set cap_arch if libvixl itself was not configured (e.g. due to lack of c++ compiler). Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- disas.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/disas.c b/disas.c index 54a540180f..cafd063d42 100644 --- a/disas.c +++ b/disas.c @@ -430,9 +430,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 Apr 27 17:26:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600797423; cv=none; d=zohomail.com; s=zohoarc; b=NGdq3zK6S7TH3vuXVuoijvgnIn1R1X4AAizQzp1vhazCVSyNY9o/JTFy6uYwazaKwVy5kRkZn38oegLEWfmQh5Oiet2JK1xlGBpnguExkXbua9Sz5l98bSkRrDC8GMxOh4fQIo78+i0rDLGde8vtkP+xXXeEZ7gI5ZAhMjkM1+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600797423; 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=32ksAvLgJOxJOqykaUU7L7gysmeStCf/ZQlD3B5l6Po=; b=YzvmPoZ0d3mrNHUMOVOLi1TOcZq/k2Zfn2t86fjRJlK6V4tDRnJHzVl6ItM4cVM6sFLmWFJg5hIgg6sXS+1fsTc37DalUl8t1fcDdT3Pyh+UwP2wIdYBxpTtImcCH3+2mfve51lSWVM/i+uUG7NkI9Vs3lXVKSM8GxSYD1tZ5Qs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600797423044699.8648830761329; Tue, 22 Sep 2020 10:57:03 -0700 (PDT) Received: from localhost ([::1]:42266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKmXF-0000rr-Jm for importer@patchew.org; Tue, 22 Sep 2020 13:57:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45646) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKmOm-0008E2-Mx for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:48:16 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:37066) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKmOf-0004LK-MW for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:48:16 -0400 Received: by mail-pg1-x542.google.com with SMTP id l71so12570240pge.4 for ; Tue, 22 Sep 2020 10:47:59 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id r1sm14825310pgl.66.2020.09.22.10.47.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 10:47:57 -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=32ksAvLgJOxJOqykaUU7L7gysmeStCf/ZQlD3B5l6Po=; b=yEF5DiMoelbTd0weLAhRFc8ob5svQtbfIaP2HHeauQQQtTqD/LxiKQcAeszkh2BE/q nNvcPQvUxj0non327ADbfLqeP7KhjosjeeHAbtnsjWx7VC/f8ApjvTtL1RFG7JkAuqiX /yRpdP9BVZ9KnZV6S1T0KE8kNetm4e51OOTScjySo6d4ILdm+9+CQKmI/GyuaB6bB74D w0vR0YYiYzGlfnGsuYmv0NioMtxwLEVzhUrZ6ca2+293FW0rLl/mkINhcF/+oepffZ+H LtVx7l/JiQutz1/H7cwS6BTNaL6QzebuOjM5SMNw68BgdAMfO4R/ylF5N+H4bG109Auz 03jw== 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=32ksAvLgJOxJOqykaUU7L7gysmeStCf/ZQlD3B5l6Po=; b=UE5df7cYnOXlbx07/VSF1/pQu4zwL0BbDMlHDAc5MBx5WT0pIff7C0fHfV1WhyH4un Au9gh/8WTAEzWTwN6MvwaZpj0ZqPagcmrbjlvGvA/L8PsckSy6iliYUiQkJo2+7cX3VZ U8Xkv0v/Tnrpc8b0O605OCWlqAqIR4EUGko/Apqu5XCfZyj2wPz0TjEZzC/BWospw6m7 a9KJghutyLy5+bFr8GIQmimO/bXg7Mj+qnbevgkgo18mcrEuNVEr0jqDWODvUFXTDk/3 R49VPq5xBtmK4sTm24OKOeudKfZRwVCp6ZrD3dOBznnkgvzi0IhaA3A1nSrhs5D3q1dT wKXg== X-Gm-Message-State: AOAM5305XhmqIXiirN5nZGMUUzS3Ud0yc5EBtC/k0Zj1Auy6ZwM8GzMH hFxQuFYN6rcgAVhIpI8n7mSs8z7FWmRasQ== X-Google-Smtp-Source: ABdhPJzU4CdbAXMyeNVAO8KlzH9gc7R8rGCg2fJ6Wd4RaYwF/GV2ARzvIo8Ro1DvtUDFv3Z2tBJkhA== X-Received: by 2002:a05:6a00:1481:b029:142:2501:35d7 with SMTP id v1-20020a056a001481b0290142250135d7mr5168510pfu.55.1600796877904; Tue, 22 Sep 2020 10:47:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 09/11] disas: Split out capstone code to disas/capstone.c Date: Tue, 22 Sep 2020 10:47:39 -0700 Message-Id: <20200922174741.475876-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200922174741.475876-1-richard.henderson@linaro.org> References: <20200922174741.475876-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::542; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x542.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: peter.maydell@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- meson.build | 1 + include/disas/dis-asm.h | 12 ++ disas.c | 275 -------------------------------------- disas/capstone.c | 286 ++++++++++++++++++++++++++++++++++++++++ disas/meson.build | 1 + 5 files changed, 300 insertions(+), 275 deletions(-) create mode 100644 disas/capstone.c diff --git a/meson.build b/meson.build index 114b136129..f06e3a1b65 100644 --- a/meson.build +++ b/meson.build @@ -965,6 +965,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( diff --git a/include/disas/dis-asm.h b/include/disas/dis-asm.h index 6b45aa9898..2164762b46 100644 --- a/include/disas/dis-asm.h +++ b/include/disas/dis-asm.h @@ -460,6 +460,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 */ + #ifndef ATTRIBUTE_UNUSED #define ATTRIBUTE_UNUSED __attribute__((unused)) #endif diff --git a/disas.c b/disas.c index cafd063d42..9dfbeededc 100644 --- a/disas.c +++ b/disas.c @@ -109,255 +109,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)); @@ -515,32 +266,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')) --=20 2.25.1 From nobody Sat Apr 27 17:26:39 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=1600798203; cv=none; d=zohomail.com; s=zohoarc; b=krGikUTiVkG3ows83dcGKP96pHAhctAvp3gK2iKxNw3fpwarKIViJ4GA1ikf8onds1JqmwKYUMW+6YxihBZFQ56iz+cN0bRza0nfk5rYMtkwOZT19PuEFIJp0NrRtqEvVuCXPRZQirnl7mlgvUNKVDo4yH0U0h4a5YhPrC834V4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600798203; 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=7lTlFlivfAiJTzCGws6plI8BPc5bxV1RgMbX8sbBRYM=; b=Fsv2k/1HkKFoCaOJF3ZRdtSQCoL5YLl2AflTWDHER1AjJqhw5BjnBvkgcsV2quvd94CZzd1/BFB4Q7xEnHCAyM21nTXDneSjOQ6we+d/b1nPbKK98jidphJyMIzW4EcQwXhY/OVQMROV6C/irAbr4SOatt/yyXhuIvAB6rIZ6Ew= 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 1600798203741903.5811999994191; Tue, 22 Sep 2020 11:10:03 -0700 (PDT) Received: from localhost ([::1]:33600 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKmjq-0001Xa-Dt for importer@patchew.org; Tue, 22 Sep 2020 14:10:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45618) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKmOj-00085p-7f for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:48:13 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:42618) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKmOe-0004LT-DA for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:48:12 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d6so13132774pfn.9 for ; Tue, 22 Sep 2020 10:48:01 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id r1sm14825310pgl.66.2020.09.22.10.47.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 10:47:58 -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=7lTlFlivfAiJTzCGws6plI8BPc5bxV1RgMbX8sbBRYM=; b=chAcqkeAXTZdqMfGFWd4pzCHuQZp/ko/3zd5B3wn9SFMg//uFw/yYjqyOFEBgbY6jA IaWQiFP2EcfebDOI6/kV8h+T/lmI6yLtvBzOpWmxCOiRxzmDxvff+etN/Llw4j/05kqZ uEF5X/pwzycv8DM7eHkzJeD6VEZsy8I9G8lZQrRjq04jTHfuJK2QInHB6Bd5PGqbRYbE deRFj0SeErudf/entQQMGEQsEbESYqqqHvEpfFvKzbfTagxcnVLU+yQXy8DVA7OcoBxn SMZTxsqqGdswpYkHT+LIwxd8u/68swr2LgoiflI0kpzMPoo3e3yEz8tPGuvIZBPmsKpk /RSg== 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=7lTlFlivfAiJTzCGws6plI8BPc5bxV1RgMbX8sbBRYM=; b=TYmVcb0PEo8GaBt8MTy9+Wr+7LVGSsfJ5mEgnfW55zHUBREG0PNrwrGr35GKIlDWMn fxcCUPGT/tc6zDwQu/NwW/0lMzt5Y1V6pdCkPSWFOLM21+vGEXzDM6qtwl1ytDF57ncl pJ5DMpUjYeuL8UrqjeQ7zZ/6SOTWz6PjF8yttjZNBo79gEkeHlr+lNaDP8R9BCJ2ESWs I5PtG8jGbghI5LYZN3orcAipL2sWq2xCEPxEVHG6dmOnnGsbosBE0od4TCEsIBSbhRxG HvZfHUY9ThqRS5GATBG0pLgoBZjFS9vunH9I6b3cHM0p0GzZWHVrxaGCe48h93uodB2A 4saA== X-Gm-Message-State: AOAM532LNBbK6tb+jlvAkFVWhPgSZ6DTe56Qabw7sd9tZ6qrj+e1ryGc UCJk3AQIRN6qZuo6ehYbDVQl7xzuaB3BwQ== X-Google-Smtp-Source: ABdhPJwkuSTFhb4ui8LhVYCjG3aio1nPQPQymTuO+bQ/cseGKv2iRvKL86TvGOUx4+khMy8BBi8gZA== X-Received: by 2002:aa7:9093:0:b029:142:2501:39da with SMTP id i19-20020aa790930000b0290142250139damr5082511pfa.41.1600796879744; Tue, 22 Sep 2020 10:47:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 10/11] disas: Enable capstone disassembly for s390x Date: Tue, 22 Sep 2020 10:47:40 -0700 Message-Id: <20200922174741.475876-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200922174741.475876-1-richard.henderson@linaro.org> References: <20200922174741.475876-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::42a; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42a.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: peter.maydell@linaro.org, Thomas Huth , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Enable s390x, aka SYSZ, in the git submodule build. Set the capstone parameters for both s390x host and guest. Tested-by: Alex Benn=C3=A9e Reviewed-by: Alex Benn=C3=A9e Acked-by: Thomas Huth Signed-off-by: Richard Henderson --- meson.build | 11 +++++++++++ disas.c | 3 +++ target/s390x/cpu.c | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/meson.build b/meson.build index f06e3a1b65..d9f021837b 100644 --- a/meson.build +++ b/meson.build @@ -670,6 +670,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( diff --git a/disas.c b/disas.c index 9dfbeededc..7c18d7d2a7 100644 --- a/disas.c +++ b/disas.c @@ -203,6 +203,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 e350edc9f5..f21b1f7795 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) --=20 2.25.1 From nobody Sat Apr 27 17:26:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600797209; cv=none; d=zohomail.com; s=zohoarc; b=UthAjgumv9PQDwth9FFFdraSPOK7vzne8PJlbIaxdc6wAOO0CAhsyb9dJ6GTJquDvAzqCNiPRzQXCtPQsya/SfsgdJ8Hj/0keum9FYxze1Q+IfiOXkbbkl6WWg2z6rBSlqUV72/ayXuXJuh2n3bZBwMKPpsPYXLVxM944zKP/Do= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600797209; 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=fL9vcubZUcrgmVjSWEvSPM+/Ls8w7nQK9m+00GRHc10=; b=cIzvwZYYIzjYm7wEE9NilWQWV8hBRKTnRYz7GTsKfoeeSdOUgfdzwMAhVHYJsxXzep+xstzMlgX0ODAzI4XvXwTfcaBbi9LDmMD0uvtZkMYraIwagwSJd4BXO87oc+U/SAMleyIgpH/FC2MN37vTrvC3zHFrAsAYDeZ3WT20L/A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16007972093801004.2796689256098; Tue, 22 Sep 2020 10:53:29 -0700 (PDT) Received: from localhost ([::1]:60460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKmTo-00051F-3e for importer@patchew.org; Tue, 22 Sep 2020 13:53:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45594) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKmOh-000836-TF for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:48:11 -0400 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]:54226) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKmOf-0004Lb-Js for qemu-devel@nongnu.org; Tue, 22 Sep 2020 13:48:11 -0400 Received: by mail-pj1-x1041.google.com with SMTP id t7so1844154pjd.3 for ; Tue, 22 Sep 2020 10:48:02 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id r1sm14825310pgl.66.2020.09.22.10.47.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 10:48:00 -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=fL9vcubZUcrgmVjSWEvSPM+/Ls8w7nQK9m+00GRHc10=; b=MkImU6cAIAbe0MvakOL2TARvA6rK63JRjLZBh9PmpPSCogeg8NfZJc8cf/cfM+hn2I jAhAxVdLdgTDJ+hh2NGlq7RPyAJWzF+kVPS0+cDvgpnECq/0EaWfVoX5bwkC7WcBVO6K 2npIQJBSNTEgN3r+v/U7zqtDE3f4gd0zbxf6LZmXqeWYX2HlJmLuN2+IsOxEiUf71nKp 7XQLafK7Tb2rSWsDfuJsVwGmHb2mUwNeCAfkOHx/rGwhWMy2RZNsk2AWvxTTc6B60q5Y DOqY78P6TLXAU+MCbq2QEnz50yThZk7KrC7BwiR4amJK8kvdBqYNqUidetJ2jDE3c4ko sBPg== 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=fL9vcubZUcrgmVjSWEvSPM+/Ls8w7nQK9m+00GRHc10=; b=TrRmZd5hdwG7J14UHRgHACOi3rE0BKEIKp37/81RqWrJ/lppYu6L9PW4h02I6Uxlxr vgMMtjYpFZRONIuu6z29jUnuOFCHhk/LI7ZCqnnG379uY3DgBWDTUxKnexESgSXxGcCc 7sXHo+pnxIHOkTWupmjRTXTNvfOQV2f6nDVnVlEBeitqjHeg1jABzp7YwMaO3aUyoh8q mDZSjskoMqE72puVgqoXVFRIQXgY5ZnlFoG7O2EFGuZ86XK/Aavr9knrk6jgn7GBSqrA 71LTX7eTryAUDK9Dyt9p7KU3jmFS3FjLrjzJWjWrSNwDqFvgfrXwK7dJVGxyxZJTGpu+ uy1Q== X-Gm-Message-State: AOAM531ihPetA3XWMZ1PaWfqYVDGDOwiRaeWkMe+KZ9hGuwCzIHoiMuI vNMtU3BmQ0H3Yo1br/tuK/jK+QhMpiTrYQ== X-Google-Smtp-Source: ABdhPJwgduNFkYxk204k2YPCIi2kGLIwTnMvHvLdyBDw+wcYb0OZ5lzAHByCMrA/PKu7EMid8OYNQw== X-Received: by 2002:a17:90b:1098:: with SMTP id gj24mr910074pjb.55.1600796881019; Tue, 22 Sep 2020 10:48:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 11/11] disas/capstone: Add skipdata hook for s390x Date: Tue, 22 Sep 2020 10:47:41 -0700 Message-Id: <20200922174741.475876-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200922174741.475876-1-richard.henderson@linaro.org> References: <20200922174741.475876-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::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 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: peter.maydell@linaro.org, Thomas Huth , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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. Acked-by: Thomas Huth Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- 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