From patchwork Mon Sep 21 17:41:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 11790551 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9DE86139A for ; Mon, 21 Sep 2020 17:46:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 47F23216C4 for ; Mon, 21 Sep 2020 17:46:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="RpXWDogN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 47F23216C4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:38704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKPtl-00054r-B1 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 21 Sep 2020 13:46:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45974) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKPom-000872-NA for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:36 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:39587) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKPod-0000Go-A3 for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:31 -0400 Received: by mail-pf1-x42c.google.com with SMTP id n14so9894898pff.6 for ; Mon, 21 Sep 2020 10:41:24 -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=qouecY1rcHHrcHeKklviJ147E1PN1Y8pYyAnMkB/X4c=; b=RpXWDogNeZ4rATRjt79b0frD9j6vaNaEIgPZeN9Bo+ZYlDdEAehUVyiR2mKFwKAjgm fQq6jEJLHEEOZv7sVSFbi90H1k5vBCyPPnz8R3wa9vk3UviLrXL8N1fheF38x8RQ0IFV LnTi8aQFlWnVw0mmJi0+vkoBLfs0K6/2/2i5AccV1obMBSwfU5HaEq3gZERfyiO/sJko ZVh/UwLVoxMZZd63Lf/AHgh7SCyqOwzDHXODLlzT32sIjlsW5oO2LXuhU7il6dJXg2kr vy5yyWP/SHUsuHiTdwYer4JbqVWIDMRcZvGhI2t5TfzXeTOiQULqVRcnFvz/c+TyuLQr NlFg== 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=qouecY1rcHHrcHeKklviJ147E1PN1Y8pYyAnMkB/X4c=; b=IxHK8sSbvn1MVNzqu0NoE2fBYI5QbLKMMF85hO1hD1eEcwx5DlpIizDW53Zuos0v5j 2LtGM4KYGQO+A/Bos/Z+qTB3/8KiIAtbmT5k7XPSwHN4SYJJtJjNN1Y8hfWDAubOiool tVOLH7Ys/aA3t+m3wnB6S3xPYIh0HOmWGqLyH7awu9UnNRSQ7h2YWQ5Z2apGy1ubOqYm 2wIs+5ICNF/ee+dyiBTIiD3hrHcqDj8S4mQEcc9LC6npWntkivC6TFNHVDSC1RSa5uxg pmpij9NKoFgUxHG9/hkdW09Co7i7cQopU4jv/BCI3p9CLhYNshhUEI5Vzqls+sszIq6a GfCA== X-Gm-Message-State: AOAM530O+lOb0tLcPZ8IFt1KjZc0nYicMvkxhuXGu0Tv8m49OdUOwUJX pZeXr/mMQ/U9T4ZJ7DYBvgYJgEdS0UfqNA== X-Google-Smtp-Source: ABdhPJy/ae4G99z3x8MuT3sUKL+yxQFEZaboDcX/xSX+tGsXNyBnFK7NypXq3Y3zU9MTxX6T//Ue3g== X-Received: by 2002:a17:902:ed43:b029:d1:e603:5439 with SMTP id y3-20020a170902ed43b02900d1e6035439mr946454plb.81.1600710082631; Mon, 21 Sep 2020 10:41:22 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id x4sm12585379pfm.86.2020.09.21.10.41.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 10:41:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 01/11] capstone: Convert Makefile bits to meson bits Date: Mon, 21 Sep 2020 10:41:08 -0700 Message-Id: <20200921174118.39352-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200921174118.39352-1-richard.henderson@linaro.org> References: <20200921174118.39352-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- 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 7564479008..03915267e2 100755 --- a/configure +++ b/configure @@ -478,7 +478,7 @@ opengl="" opengl_dmabuf="no" cpuid_h="no" avx2_opt="" -capstone="" +capstone="auto" lzo="" snappy="" bzip2="" @@ -1580,7 +1580,7 @@ for opt do ;; --enable-capstone) capstone="yes" ;; - --enable-capstone=git) capstone="git" + --enable-capstone=git) capstone="internal" ;; --enable-capstone=system) capstone="system" ;; @@ -5128,51 +5128,11 @@ fi # capstone case "$capstone" in - "" | yes) - if $pkg_config capstone; then - capstone=system - elif test -e "${source_path}/.git" && test $git_update = 'yes' ; then - capstone=git - elif test -e "${source_path}/capstone/Makefile" ; then - capstone=internal - elif test -z "$capstone" ; then - capstone=no - else - feature_not_found "capstone" "Install capstone devel or git submodule" - fi - ;; - - system) - if ! $pkg_config capstone; then - feature_not_found "capstone" "Install capstone devel" - fi - ;; -esac - -case "$capstone" in - git | internal) - if test "$capstone" = git; then + auto | yes | internal) + # Simpler to always update submodule, even if not needed. + if test -e "${source_path}/.git" && test $git_update = 'yes' ; then git_submodules="${git_submodules} capstone" fi - mkdir -p capstone - if test "$mingw32" = "yes"; then - LIBCAPSTONE=capstone.lib - else - LIBCAPSTONE=libcapstone.a - fi - capstone_libs="-Lcapstone -lcapstone" - capstone_cflags="-I${source_path}/capstone/include" - ;; - - system) - capstone_libs="$($pkg_config --libs capstone)" - capstone_cflags="$($pkg_config --cflags capstone)" - ;; - - no) - ;; - *) - error_exit "Unknown state for capstone: $capstone" ;; esac @@ -7292,11 +7252,6 @@ fi if test "$ivshmem" = "yes" ; then echo "CONFIG_IVSHMEM=y" >> $config_host_mak fi -if test "$capstone" != "no" ; then - echo "CONFIG_CAPSTONE=y" >> $config_host_mak - echo "CAPSTONE_CFLAGS=$capstone_cflags" >> $config_host_mak - echo "CAPSTONE_LIBS=$capstone_libs" >> $config_host_mak -fi if test "$debug_mutex" = "yes" ; then echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak fi @@ -7819,13 +7774,7 @@ done # for target in $targets if [ "$fdt" = "git" ]; then subdirs="$subdirs dtc" fi -if [ "$capstone" = "git" -o "$capstone" = "internal" ]; then - subdirs="$subdirs capstone" -fi echo "SUBDIRS=$subdirs" >> $config_host_mak -if test -n "$LIBCAPSTONE"; then - echo "LIBCAPSTONE=$LIBCAPSTONE" >> $config_host_mak -fi if test "$numa" = "yes"; then echo "CONFIG_NUMA=y" >> $config_host_mak @@ -8008,7 +7957,8 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \ -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \ -Dsdl=$sdl -Dsdl_image=$sdl_image \ -Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \ - -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f\ + -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \ + -Dcapstone=$capstone \ $cross_arg \ "$PWD" "$source_path" 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 $@ -# 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 = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS)) $(CAPSTONE_CFLAGS) -CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM -CAP_CFLAGS += -DCAPSTONE_HAS_ARM -CAP_CFLAGS += -DCAPSTONE_HAS_ARM64 -CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC -CAP_CFLAGS += -DCAPSTONE_HAS_X86 - -.PHONY: capstone/all -capstone/all: .git-submodule-status - $(call quiet-command,$(MAKE) -C $(SRC_PATH)/capstone CAPSTONE_SHARED=no BUILDDIR="$(BUILD_DIR)/capstone" CC="$(CC)" AR="$(AR)" LD="$(LD)" RANLIB="$(RANLIB)" CFLAGS="$(CAP_CFLAGS)" $(SUBDIR_MAKEFLAGS) $(BUILD_DIR)/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 = import('unstable-keyval') endif ss = import('sourceset') +fs = import('fs') sh = find_program('sh') cc = meson.get_compiler('c') @@ -409,11 +410,6 @@ if 'CONFIG_USB_LIBUSB' in config_host libusb = declare_dependency(compile_args: config_host['LIBUSB_CFLAGS'].split(), link_args: config_host['LIBUSB_LIBS'].split()) endif -capstone = not_found -if 'CONFIG_CAPSTONE' in config_host - capstone = declare_dependency(compile_args: config_host['CAPSTONE_CFLAGS'].split(), - link_args: config_host['CAPSTONE_LIBS'].split()) -endif libpmem = not_found if 'CONFIG_LIBPMEM' in config_host libpmem = declare_dependency(compile_args: config_host['LIBPMEM_CFLAGS'].split(), @@ -470,7 +466,6 @@ foreach k, v: config_host config_host_data.set(k, v == 'y' ? 1 : v) endif endforeach -genh += configure_file(output: 'config-host.h', configuration: config_host_data) minikconf = find_program('scripts/minikconf.py') config_all_devices = {} @@ -610,6 +605,108 @@ config_all += { 'CONFIG_ALL': true, } +# Submodules + +capstone = not_found +capstone_opt = get_option('capstone') +if capstone_opt == 'no' + capstone_opt = false +elif capstone_opt in ['yes', 'auto', 'system'] + have_internal = fs.exists('capstone/Makefile') + capstone = dependency('capstone', static: enable_static, + required: capstone_opt == 'system' or + capstone_opt == 'yes' and not have_internal) + if capstone.found() + capstone_opt = 'system' + elif have_internal + capstone_opt = 'internal' + else + capstone_opt = false + endif +endif +if capstone_opt == 'internal' + capstone_data = configuration_data() + capstone_data.set('CAPSTONE_USE_SYS_DYN_MEM', '1') + + capstone_files = 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 += 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 += 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 += 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 += 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 = [ + # FIXME: There does not seem to be a way to completely replace the c_args + # 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 = static_library('capstone', + sources: capstone_files, + c_args: capstone_cargs, + include_directories: 'capstone/include') + capstone = declare_dependency(link_with: libcapstone, + include_directories: 'capstone/include') +endif +config_host_data.set('CONFIG_CAPSTONE', capstone.found()) + +genh += configure_file(output: 'config-host.h', configuration: config_host_data) + # Generators hxtool = find_program('scripts/hxtool') @@ -1512,7 +1609,7 @@ summary_info += {'vvfat support': config_host.has_key('CONFIG_VVFAT')} summary_info += {'qed support': config_host.has_key('CONFIG_QED')} summary_info += {'parallels support': config_host.has_key('CONFIG_PARALLELS')} summary_info += {'sheepdog support': config_host.has_key('CONFIG_SHEEPDOG')} -summary_info += {'capstone': config_host.has_key('CONFIG_CAPSTONE')} +summary_info += {'capstone': capstone_opt} summary_info += {'libpmem support': config_host.has_key('CONFIG_LIBPMEM')} summary_info += {'libdaxctl support': config_host.has_key('CONFIG_LIBDAXCTL')} summary_info += {'libudev': config_host.has_key('CONFIG_LIBUDEV')} 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') From patchwork Mon Sep 21 17:41:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 11790549 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8015D59D for ; Mon, 21 Sep 2020 17:46:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3B8502151B for ; Mon, 21 Sep 2020 17:46:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="jFLDZ5AT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B8502151B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:38674 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKPtl-00054A-97 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 21 Sep 2020 13:46:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45998) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKPon-000877-0v for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:37 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:37050) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKPod-0000Gz-AC for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:36 -0400 Received: by mail-pg1-x541.google.com with SMTP id l71so9676033pge.4 for ; Mon, 21 Sep 2020 10:41:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uTrm0sdq7gARiBpxaC3cYgqckLUxE92nb3e9fV7DsLA=; b=jFLDZ5ATXaWvlzcXmV/xiQcxecmzsVuh+EuyF/7534wfuniNgqC7AfEH/1LCBv0uAI nwcQwj25X+tGTdlQjtIYcJgQgnY/0d7tr5X6oPSdutKJIQko6/MtQaRcCuIOePJVenWa 6rgGTq3FfcziZgmiV0kt1uFVDQQMRKlKyHF+fetL4+IuzKHe/PjgU0zopCzUsu+uAUc9 non6MHMmZT13jCo8kBzRcjcfl/uU3koDGl+/gKE1A9A5y/QvFKAgrjdPFQiG1kTFIF7r MaOcyWUzLpBZeCYU4izWBiHVoXWVBNjTqu4ZwtgOrso8knAjmpXfU/nsn9NwaG8ex2BD EJMQ== 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=uTrm0sdq7gARiBpxaC3cYgqckLUxE92nb3e9fV7DsLA=; b=HUOVdV1LVEHQTo78CeUwcYqQLgGEoChEaevJwMPj0XihI5UAmyR8R1vKb6yIAq+Udl 6WBcDwu8vP5JqHkfNNlpqtyZwUZK1uM1aakcmcUyANfcXmpDjY5fyXayO2vMZwshmBWS sYZ2eqk+x8EAUVOub0bKmmhNI1UVOuBcnoGv4eYOV+6VjWXZ+M0y9f1oVq70gHVky/OS /ILDrh+XHz67y8r1RsXmJqS6Z8zSOWOZgRspoZykJRYBGd7RIElj1Bw6aKYyH9O9vId7 veLQXPEcGrLLKzUjAXy4U4n8QPDP3KP96EqZqDTcvxoTFR7jhFXjRf1wFxOVp79gwXkC jMqg== X-Gm-Message-State: AOAM531oVQiz5PqQRp1qgUD2OzuO58sCWkhf6rRxHwCljRAtiyN5t3yx Zp+djbcBtIja31ZRyRDWnmJPbogWBoa65g== X-Google-Smtp-Source: ABdhPJyK70BxsOILtMf7FpeZBdTNVbvwiYGabIz8KA5FQFl1ib1r54jAac+F3M7J6dT0qjNx4S62oQ== X-Received: by 2002:a17:902:fe88:b029:d2:2a16:254 with SMTP id x8-20020a170902fe88b02900d22a160254mr957689plm.23.1600710084094; Mon, 21 Sep 2020 10:41:24 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id x4sm12585379pfm.86.2020.09.21.10.41.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 10:41:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 02/11] capstone: Update to upstream "next" branch Date: Mon, 21 Sep 2020 10:41:09 -0700 Message-Id: <20200921174118.39352-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200921174118.39352-1-richard.henderson@linaro.org> References: <20200921174118.39352-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::541; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x541.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: alex.bennee@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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é Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- capstone | 2 +- meson.build | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/capstone b/capstone index 22ead3e0bf..f8b1b83301 160000 --- a/capstone +++ b/capstone @@ -1 +1 @@ -Subproject commit 22ead3e0bfdb87516656453336160e0a37b066bf +Subproject commit f8b1b833015a4ae47110ed068e0deb7106ced66d diff --git a/meson.build b/meson.build index f23273693d..4c92b43fe5 100644 --- a/meson.build +++ b/meson.build @@ -677,6 +677,7 @@ if capstone_opt == '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 == 'internal' c_args: capstone_cargs, include_directories: 'capstone/include') capstone = declare_dependency(link_with: libcapstone, - include_directories: 'capstone/include') + include_directories: 'capstone/include/capstone') endif config_host_data.set('CONFIG_CAPSTONE', capstone.found()) From patchwork Mon Sep 21 17:41:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 11790541 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0C1B659D for ; Mon, 21 Sep 2020 17:43:44 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9A2B72151B for ; Mon, 21 Sep 2020 17:43:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="awAmJULs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9A2B72151B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:58744 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKPqo-0001UY-CA for patchwork-qemu-devel@patchwork.kernel.org; Mon, 21 Sep 2020 13:43:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46014) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKPon-00087R-Px for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:37 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]:34104) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKPoe-0000H9-Lf for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:37 -0400 Received: by mail-pj1-x1034.google.com with SMTP id s14so240081pju.1 for ; Mon, 21 Sep 2020 10:41:26 -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=a3xDNZ7X5vKgkbce6iNasAuvv5vN3OhZYwiJJsW3uGU=; b=awAmJULsrklwurhqPSgooahcyyO8jhAtSszZlCnIWwHNzyw6XkHtgKt6GASQAP4GIW ST3/TMT/fYB03UUhXAZWlctkkP33nLHq3sMyrjjOzoR/Ly48qtRy0QHI1NHFbmDyXDXK 4JJAaoVWBmbPkIEpp40I6KCmUp2XJU21offAHLx5z01d8efx1Lvtbge/hvAvMaiYwFn1 UkPL6VjXFjxaNN7VIcFUtOkCuyjGVaFVkG2HMSMnKnh4hwFQ8c9FzZBb3ELq7nOGYhgC vHgVn+sBEaIQ5ffFyrymNKjTJcfEWMW15XT4RISHWf1o0i8Ske5KB3naDohiStDwsQo8 PiSQ== 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=a3xDNZ7X5vKgkbce6iNasAuvv5vN3OhZYwiJJsW3uGU=; b=fkEKEdyO6yi1vZ2HROmRFQAaCmabaFr7ouGdbcNdFHb+VINeSvm6LrDbaaJ6nB47af dcglNnzFoQNJvyhRs5OgvxeoGu6l2G7g7rOYSbzeRX0hkmCSPD9OwiKo0CBMo5MAAKTS PS+ytvU/tJAe2SChQq0EuZvgTwXZhuiW3J/4Lj4YmPx/npuAy57K0odh1cbqV8HISd+/ /5r4dIU610y0C33bgTaG7wshkdXo3jCXpTIGa0nlNKkOlQujSqC9P0SsdsjYT6Qo2S5g RG2mzP1UvlSwCla2VT+eJQNHdHqKnJNcJrX6P4Hvyf1oO1CXNqwAKvfgqtp3VlT0XJda Il+A== X-Gm-Message-State: AOAM530AIVDeQwVONXINAeMspTMXWk721pbk9cUc3FeEWJuBXX5W6wMc QMLN0oLy1Z8jjBxk8a7chwG9uDn17bNgAw== X-Google-Smtp-Source: ABdhPJz6WfiAQwmlqC3V2y5W+SuTJ74316H8Kh/+ChUO4g1NpnX2N7hmWyISqwoagIev/8k8/OZB8Q== X-Received: by 2002:a17:90a:cb93:: with SMTP id a19mr383566pju.207.1600710085421; Mon, 21 Sep 2020 10:41:25 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id x4sm12585379pfm.86.2020.09.21.10.41.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 10:41:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 03/11] capstone: Require version 4.0 from a system library Date: Mon, 21 Sep 2020 10:41:10 -0700 Message-Id: <20200921174118.39352-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200921174118.39352-1-richard.henderson@linaro.org> References: <20200921174118.39352-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1034.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: alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" We're about to use a portion of the 4.0 API. Reject a system library version prior to that. Signed-off-by: Richard Henderson Tested-by: Alex Bennée Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé --- 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 == 'no' capstone_opt = false elif capstone_opt in ['yes', 'auto', 'system'] have_internal = fs.exists('capstone/Makefile') - capstone = dependency('capstone', static: enable_static, + capstone = dependency('capstone', version: '>=4.0', static: enable_static, required: capstone_opt == 'system' or capstone_opt == 'yes' and not have_internal) if capstone.found() From patchwork Mon Sep 21 17:41:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 11790553 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8337159D for ; Mon, 21 Sep 2020 17:46:48 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4294F216C4 for ; Mon, 21 Sep 2020 17:46:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="N9lrZwYe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4294F216C4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:38848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKPtn-00058K-5r for patchwork-qemu-devel@patchwork.kernel.org; Mon, 21 Sep 2020 13:46:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKPoo-000884-Jd for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:38 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]:33947) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKPoe-0000HI-Mv for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:38 -0400 Received: by mail-pf1-x42e.google.com with SMTP id k13so9393874pfg.1 for ; Mon, 21 Sep 2020 10:41:28 -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=MS/1tLLb4oetx2r+bYB6y25h/eLEAPaiuMEVSm1K/g8=; b=N9lrZwYeB6sz4Au/Wa7vLEJQxFz1Hq1+Pi54ZVyAHlu3jeas0hx5YbwCPZ2PL6y1rb VMVdWornGQk074pgqRI+9VZOVnn6hQ888k8jZgOinddxZKlWKCptbmoG8JmoAInB1Ick mvkmPJ/k2uwHS/0aOiwrXwsyGWgUHb3bUa5nbUutjgyro/vG40pjixrbCUxCeRDWPRVm 0cH13bfulCfJelGIj+qLm8mJW1eJHfNFiZ1dWLSe8yiZgAHPBB8685KcbJYSI5dCyxji 6bFPS0fPxWKWBQRCU29RZxBU4Q8zAK5bJM6ZJ1w4em8iV9iqlIdzIhSvGDvW+GLCM25S OBwQ== 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=MS/1tLLb4oetx2r+bYB6y25h/eLEAPaiuMEVSm1K/g8=; b=iZqMbBlPldPMLyoBIdTE0LMJ/53LSV2iGBYN0tyJQtNy5Eti9wS8CvD9SNBfPe2PtO BmpSRomxq73i+0TUAN/OYPdQzihOo3rutpC0BkqclXWoQfe8aLbY3JhvplSpcWrAiqMi g+GokENnHaly8NdekfFQJeVv/s9nrdRulrrV0lVI6CAxv20B59id2nUmtv+sa7e28c/a 7o24LrC+UXn7XpwLEp22wI8Hdvf8+UxQP5DbQXmHIAq3DWFV+uctrrx+fT9IuJhzZTEm aZqzJC+t1vodEw+Lu/5RcVzlUemQHtDi82lbCSBKGeVRsmnImLQGKYMvbFPj049sVMDn RHSw== X-Gm-Message-State: AOAM532+ZyBEuXlb7V5Nq7wlqTEiJRHSiMTC+cwrpYEyA1ndD3XQy0Hx BlwQsgqW9O4KjKi+/vOsChMBH/XyAZW5GA== X-Google-Smtp-Source: ABdhPJzuCCn1Tebi3TeLwaWpeFPHDk97r1qNyyEga1I1BpJibKdhWc3pBoPNAONA22Zz5NDsUjCYdg== X-Received: by 2002:a05:6a00:2db:b029:142:2501:34ed with SMTP id b27-20020a056a0002dbb0290142250134edmr772645pft.70.1600710086865; Mon, 21 Sep 2020 10:41:26 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id x4sm12585379pfm.86.2020.09.21.10.41.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 10:41:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 04/11] disas: Move host asm annotations to tb_gen_code Date: Mon, 21 Sep 2020 10:41:11 -0700 Message-Id: <20200921174118.39352-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200921174118.39352-1-richard.henderson@linaro.org> References: <20200921174118.39352-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.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: Thomas Huth , alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- 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" /* 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); 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, target_ulong start, rcu_read_unlock(); } -static inline void log_disas(void *code, unsigned long size, const char *note) +static inline void log_disas(void *code, unsigned long size) { QemuLogFile *logfile; rcu_read_lock(); logfile = 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 = qemu_log_lock(); int code_size, data_size = 0; - g_autoptr(GString) note = g_string_new("[tb header & initial instruction]"); - size_t chunk_start = 0; + size_t chunk_start; int insn = 0; - qemu_log("OUT: [size=%d]\n", gen_code_size); + if (tcg_ctx->data_gen_ptr) { code_size = tcg_ctx->data_gen_ptr - tb->tc.ptr; data_size = gen_code_size - code_size; @@ -1827,26 +1826,33 @@ TranslationBlock *tb_gen_code(CPUState *cpu, } /* Dump header and the first instruction */ + qemu_log("OUT: [size=%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 = tcg_ctx->gen_insn_end_off[insn]; - log_disas(tb->tc.ptr, chunk_start, note->str); + log_disas(tb->tc.ptr, chunk_start); /* * 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 <= tb->icount && chunk_start < code_size) { + while (insn < tb->icount) { size_t chunk_end = 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_start, - 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_start); chunk_start = chunk_end; } insn++; } + 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, } } -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 = info->fprintf_func; int i, n, split; @@ -284,11 +283,7 @@ static void cap_dump_insn(disassemble_info *info, cs_insn *insn, } /* 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); /* Dump any remaining part of the insn on subsequent lines. */ for (i = split; i < n; i += split) { @@ -320,7 +315,7 @@ static bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size) size -= tsize; while (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { - cap_dump_insn(info, insn, NULL); + cap_dump_insn(info, insn); } /* If the target memory is not consumed, go back for more... */ @@ -349,8 +344,7 @@ static bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size) } /* 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 = (uintptr_t)code; while (cs_disasm_iter(handle, &cbuf, &size, &pc, insn)) { - cap_dump_insn(info, insn, note); - note = NULL; + cap_dump_insn(info, insn); } if (size != 0) { (*info->fprintf_func)(info->stream, @@ -411,7 +404,7 @@ static bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int count) csize += tsize; if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { - cap_dump_insn(info, insn, NULL); + cap_dump_insn(info, insn); if (--count <= 0) { break; } @@ -425,7 +418,7 @@ static bool cap_disas_monitor(disassemble_info *info, uint64_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) } /* 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, const char *note) print_insn = print_insn_hppa; #endif - if (s.info.cap_arch >= 0 && cap_disas_host(&s.info, code, size, note)) { + if (s.info.cap_arch >= 0 && cap_disas_host(&s.info, code, size)) { return; } @@ -683,10 +676,6 @@ void disas(FILE *out, void *code, unsigned long size, const char *note) for (pc = (uintptr_t)code; size > 0; pc += count, size -= count) { fprintf(out, "0x%08" PRIxPTR ": ", pc); count = print_insn(pc, &s.info); - if (note) { - fprintf(out, "\t\t%s", note); - note = 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 = prologue_size - code_size; size_t i; - log_disas(buf0, code_size, NULL); + log_disas(buf0, code_size); for (i = 0; i < data_size; i += sizeof(tcg_target_ulong)) { if (sizeof(tcg_target_ulong) == 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(); From patchwork Mon Sep 21 17:41:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 11790555 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A6DB9112E for ; Mon, 21 Sep 2020 17:46:48 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 342752151B for ; Mon, 21 Sep 2020 17:46:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="udRw1PEK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 342752151B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:38860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKPtn-00058h-55 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 21 Sep 2020 13:46:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKPoq-000895-2R for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:40 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:42717) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKPoi-0000Ia-Fx for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:39 -0400 Received: by mail-pf1-x443.google.com with SMTP id d6so9899475pfn.9 for ; Mon, 21 Sep 2020 10:41:29 -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=U6fE0rS6g/PgpT0BfNKV2MVny74HOKVIxnGhNrYyK/8=; b=udRw1PEKT89MnyaGWp2310AXBPUgnfQ/kKm18Fc51qFZYFivCBkkTGPyxCxH+RGI9x G+bLJB7wru5yliewIdpqAy+yISt3+qOw3WWmXMEf2tfgyP0wlBjts01O7qqmEcs8nEmp EgN2yeSt+HyL5AaoYj3WHsb1vnTgUiqt8RPF0fvb2sUpEQhiHyHtYM17XwXAjptOMgKC 0Rfn8A1Aw/oZY9GDWTxtAAkCl61HTXsCmQFFfS8FTGCozIfcPiS+lEpHtnhjZAOZoHYX 0QcD1S+6iNrNrl5A3nQ15aVE21eskw+NV2PzXid3Zfb5FnLVyxWXX/S2Khlkb0/59qBl LX/Q== 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=U6fE0rS6g/PgpT0BfNKV2MVny74HOKVIxnGhNrYyK/8=; b=U5OKpuM1LKL7X8kJEIQOH66IHC4/px1uOa9T/o5KJRROLPxrcaVTV4wy524d5DS9c+ eXro9uRgxC8UP1miIFo5sKqZk0bQ9Sj1oOaGPIgycAnCvWf7tzQDPB2WWbIOBzh9SnCF RyNfkYlm0ko7/bqxsUgSD2RPnlw82P7leCVN0OLWffAk/q+fYk13Px6rmGiZKCKodXX0 yeW7RaP4hSQOfAlUXXNTkpASK7Yd6nxZeaQdf/OinFeTSO13XywwhDk2tHfkH4mv7LQl g3z2Os3Blk9n9agO6rCqGV7+gGvLkUL9irRwEkFBVUBr1AjtfoG3xyGr3ug4k2R8lBp2 I7mQ== X-Gm-Message-State: AOAM5307Il2W4bPXMwpsBKB4d/kwPHQjIBRzAmSCOp+8O6kJnId1hfmr ztUfocjG3Yp8TWiuzBj6+2jYgu2xHUMktQ== X-Google-Smtp-Source: ABdhPJxZHY9MX05Ro77pIXIpk2flVw8bF7ksTNujHp6vyooeHREpTtyjuC+fp9iyIUt5cGYTSnzEAA== X-Received: by 2002:aa7:9edb:0:b029:13e:d13d:a059 with SMTP id r27-20020aa79edb0000b029013ed13da059mr815824pfq.31.1600710088122; Mon, 21 Sep 2020 10:41:28 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id x4sm12585379pfm.86.2020.09.21.10.41.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 10:41:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 05/11] disas: Clean up CPUDebug initialization Date: Mon, 21 Sep 2020 10:41:12 -0700 Message-Id: <20200921174118.39352-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200921174118.39352-1-richard.henderson@linaro.org> References: <20200921174118.39352-1-richard.henderson@linaro.org> MIME-Version: 1.0 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: Thomas Huth , alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- include/disas/dis-asm.h | 62 -------- disas.c | 326 ++++++++++++++++++---------------------- 2 files changed, 148 insertions(+), 240 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 { } disassemble_info; - /* 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 *); -#if 0 -/* Fetch the disassembler for a given BFD, if that support is available. */ -disassembler_ftype disassembler(bfd *); -#endif - - -/* This block of definitions is for particular callers who read instructions - 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 = bfd_target_unknown_flavour, \ - (INFO).arch = bfd_arch_unknown, \ - (INFO).mach = 0, \ - (INFO).endian = 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 machine - variant are not touched by this macro. This makes things much easier for - GDB which must initialize these things separately. */ - -#define INIT_DISASSEMBLE_INFO_NO_ARCH(INFO, STREAM, FPRINTF_FUNC) \ - (INFO).fprintf_func = (FPRINTF_FUNC), \ - (INFO).stream = (STREAM), \ - (INFO).symbols = NULL, \ - (INFO).num_symbols = 0, \ - (INFO).private_data = NULL, \ - (INFO).buffer = NULL, \ - (INFO).buffer_vma = 0, \ - (INFO).buffer_length = 0, \ - (INFO).read_memory_func = buffer_read_memory, \ - (INFO).memory_error_func = perror_memory, \ - (INFO).print_address_func = generic_print_address, \ - (INFO).print_insn = NULL, \ - (INFO).symbol_at_address_func = generic_symbol_at_address, \ - (INFO).flags = 0, \ - (INFO).bytes_per_line = 0, \ - (INFO).bytes_per_chunk = 0, \ - (INFO).display_endian = BFD_ENDIAN_UNKNOWN, \ - (INFO).disassembler_options = NULL, \ - (INFO).insn_info_valid = 0 - #ifndef ATTRIBUTE_UNUSED #define ATTRIBUTE_UNUSED __attribute__((unused)) #endif diff --git a/disas.c b/disas.c index a4304e8137..7bc8e9a037 100644 --- a/disas.c +++ b/disas.c @@ -16,78 +16,66 @@ typedef struct CPUDebug { /* Filled in by elfload.c. Simplistic, but will do for now. */ struct syminfo *syminfos = NULL; -/* 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; } -/* 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 length, + struct disassemble_info *info) { CPUDebug *s = container_of(info, CPUDebug, info); - int r; - - r = cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0); - + int r = cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0); return r ? EIO : 0; } /* Print an error message. We can assume that this is in response to - an error return from buffer_read_memory. */ -void -perror_memory (int status, bfd_vma memaddr, struct disassemble_info *info) + an error return from {host,target}_read_memory. */ +static void perror_memory(int status, bfd_vma memaddr, + struct disassemble_info *info) { - if (status != 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 != 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); + } } -/* 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); } /* 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 = ~0ULL >> (64 - (sizeof(void *) * 8)); - generic_print_address(addr & mask, info); + print_address((uintptr_t)addr, info); } -/* 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; } bfd_vma bfd_getl64 (const bfd_byte *addr) @@ -423,36 +411,116 @@ static bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int count) # define cap_disas_plugin(i, p, c) false #endif /* CONFIG_CAPSTONE */ +static void initialize_debug(CPUDebug *s) +{ + memset(s, 0, sizeof(*s)); + s->info.arch = bfd_arch_unknown; + s->info.cap_arch = -1; + s->info.cap_insn_unit = 4; + s->info.cap_insn_split = 4; + s->info.memory_error_func = perror_memory; + s->info.symbol_at_address_func = symbol_at_address; +} + +static void initialize_debug_target(CPUDebug *s, CPUState *cpu) +{ + initialize_debug(s); + + s->cpu = cpu; + s->info.read_memory_func = target_read_memory; + s->info.print_address_func = print_address; +#ifdef TARGET_WORDS_BIGENDIAN + s->info.endian = BFD_ENDIAN_BIG; +#else + s->info.endian = BFD_ENDIAN_LITTLE; +#endif + + CPUClass *cc = 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 = host_read_memory; + s->info.print_address_func = host_print_address; +#ifdef HOST_WORDS_BIGENDIAN + s->info.endian = BFD_ENDIAN_BIG; +#else + s->info.endian = BFD_ENDIAN_LITTLE; +#endif +#if defined(CONFIG_TCG_INTERPRETER) + s->info.print_insn = print_insn_tci; +#elif defined(__i386__) + s->info.mach = bfd_mach_i386_i386; + s->info.print_insn = print_insn_i386; + s->info.cap_arch = CS_ARCH_X86; + s->info.cap_mode = CS_MODE_32; + s->info.cap_insn_unit = 1; + s->info.cap_insn_split = 8; +#elif defined(__x86_64__) + s->info.mach = bfd_mach_x86_64; + s->info.print_insn = print_insn_i386; + s->info.cap_arch = CS_ARCH_X86; + s->info.cap_mode = CS_MODE_64; + s->info.cap_insn_unit = 1; + s->info.cap_insn_split = 8; +#elif defined(_ARCH_PPC) + s->info.disassembler_options = (char *)"any"; + s->info.print_insn = print_insn_ppc; + s->info.cap_arch = CS_ARCH_PPC; +# ifdef _ARCH_PPC64 + s->info.cap_mode = CS_MODE_64; +# endif +#elif defined(__riscv) && defined(CONFIG_RISCV_DIS) +#if defined(_ILP32) || (__riscv_xlen == 32) + s->info.print_insn = print_insn_riscv32; +#elif defined(_LP64) + s->info.print_insn = print_insn_riscv64; +#else +#error unsupported RISC-V ABI +#endif +#elif defined(__aarch64__) && defined(CONFIG_ARM_A64_DIS) + s->info.print_insn = print_insn_arm_a64; + s->info.cap_arch = CS_ARCH_ARM64; +#elif defined(__alpha__) + s->info.print_insn = print_insn_alpha; +#elif defined(__sparc__) + s->info.print_insn = print_insn_sparc; + s->info.mach = bfd_mach_sparc_v9b; +#elif defined(__arm__) + /* TCG only generates code for arm mode. */ + s->info.print_insn = print_insn_arm; + s->info.cap_arch = CS_ARCH_ARM; +#elif defined(__MIPSEB__) + s->info.print_insn = print_insn_big_mips; +#elif defined(__MIPSEL__) + s->info.print_insn = print_insn_little_mips; +#elif defined(__m68k__) + s->info.print_insn = print_insn_m68k; +#elif defined(__s390__) + s->info.print_insn = print_insn_s390; +#elif defined(__hppa__) + s->info.print_insn = 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 = CPU_GET_CLASS(cpu); target_ulong pc; int count; CPUDebug s; - INIT_DISASSEMBLE_INFO(s.info, out, fprintf); - - s.cpu = cpu; - s.info.read_memory_func = target_read_memory; + initialize_debug_target(&s, cpu); + s.info.fprintf_func = fprintf; + s.info.stream = out; s.info.buffer_vma = code; s.info.buffer_length = size; - s.info.print_address_func = generic_print_address; - s.info.cap_arch = -1; - s.info.cap_mode = 0; - s.info.cap_insn_unit = 4; - s.info.cap_insn_split = 4; - -#ifdef TARGET_WORDS_BIGENDIAN - s.info.endian = BFD_ENDIAN_BIG; -#else - s.info.endian = BFD_ENDIAN_LITTLE; -#endif - - if (cc->disas_set_info) { - cc->disas_set_info(cpu, &s.info); - } if (s.info.cap_arch >= 0 && cap_disas_target(&s.info, code, size)) { return; @@ -540,34 +608,17 @@ bool cap_disas_plugin(disassemble_info *info, uint64_t pc, size_t size) */ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size) { - CPUClass *cc = CPU_GET_CLASS(cpu); int count; CPUDebug s; GString *ds = g_string_set_size(&plugin_disas_output, 0); g_assert(ds == &plugin_disas_output); - INIT_DISASSEMBLE_INFO(s.info, NULL, plugin_printf); - - s.cpu = cpu; - s.info.read_memory_func = target_read_memory; + initialize_debug_target(&s, cpu); + s.info.fprintf_func = plugin_printf; s.info.buffer_vma = addr; s.info.buffer_length = size; s.info.print_address_func = plugin_print_address; - s.info.cap_arch = -1; - s.info.cap_mode = 0; - s.info.cap_insn_unit = 4; - s.info.cap_insn_split = 4; - -#ifdef TARGET_WORDS_BIGENDIAN - s.info.endian = BFD_ENDIAN_BIG; -#else - s.info.endian = BFD_ENDIAN_LITTLE; -#endif - - if (cc->disas_set_info) { - cc->disas_set_info(cpu, &s.info); - } if (s.info.cap_arch >= 0 && cap_disas_plugin(&s.info, addr, size)) { return g_strdup(ds->str); @@ -593,89 +644,24 @@ void disas(FILE *out, void *code, unsigned long size) uintptr_t pc; int count; CPUDebug s; - int (*print_insn)(bfd_vma pc, disassemble_info *info) = NULL; - - INIT_DISASSEMBLE_INFO(s.info, out, fprintf); - s.info.print_address_func = generic_print_host_address; + initialize_debug_host(&s); + s.info.fprintf_func = fprintf; + s.info.stream = out; s.info.buffer = code; s.info.buffer_vma = (uintptr_t)code; s.info.buffer_length = size; - s.info.cap_arch = -1; - s.info.cap_mode = 0; - s.info.cap_insn_unit = 4; - s.info.cap_insn_split = 4; - -#ifdef HOST_WORDS_BIGENDIAN - s.info.endian = BFD_ENDIAN_BIG; -#else - s.info.endian = BFD_ENDIAN_LITTLE; -#endif -#if defined(CONFIG_TCG_INTERPRETER) - print_insn = print_insn_tci; -#elif defined(__i386__) - s.info.mach = bfd_mach_i386_i386; - print_insn = print_insn_i386; - s.info.cap_arch = CS_ARCH_X86; - s.info.cap_mode = CS_MODE_32; - s.info.cap_insn_unit = 1; - s.info.cap_insn_split = 8; -#elif defined(__x86_64__) - s.info.mach = bfd_mach_x86_64; - print_insn = print_insn_i386; - s.info.cap_arch = CS_ARCH_X86; - s.info.cap_mode = CS_MODE_64; - s.info.cap_insn_unit = 1; - s.info.cap_insn_split = 8; -#elif defined(_ARCH_PPC) - s.info.disassembler_options = (char *)"any"; - print_insn = print_insn_ppc; - s.info.cap_arch = CS_ARCH_PPC; -# ifdef _ARCH_PPC64 - s.info.cap_mode = CS_MODE_64; -# endif -#elif defined(__riscv) && defined(CONFIG_RISCV_DIS) -#if defined(_ILP32) || (__riscv_xlen == 32) - print_insn = print_insn_riscv32; -#elif defined(_LP64) - print_insn = print_insn_riscv64; -#else -#error unsupported RISC-V ABI -#endif -#elif defined(__aarch64__) && defined(CONFIG_ARM_A64_DIS) - print_insn = print_insn_arm_a64; - s.info.cap_arch = CS_ARCH_ARM64; -#elif defined(__alpha__) - print_insn = print_insn_alpha; -#elif defined(__sparc__) - print_insn = print_insn_sparc; - s.info.mach = bfd_mach_sparc_v9b; -#elif defined(__arm__) - print_insn = print_insn_arm; - s.info.cap_arch = CS_ARCH_ARM; - /* TCG only generates code for arm mode. */ -#elif defined(__MIPSEB__) - print_insn = print_insn_big_mips; -#elif defined(__MIPSEL__) - print_insn = print_insn_little_mips; -#elif defined(__m68k__) - print_insn = print_insn_m68k; -#elif defined(__s390__) - print_insn = print_insn_s390; -#elif defined(__hppa__) - print_insn = print_insn_hppa; -#endif if (s.info.cap_arch >= 0 && cap_disas_host(&s.info, code, size)) { return; } - if (print_insn == NULL) { - print_insn = print_insn_od_host; + if (s.info.print_insn == NULL) { + s.info.print_insn = print_insn_od_host; } for (pc = (uintptr_t)code; size > 0; pc += count, size -= count) { fprintf(out, "0x%08" PRIxPTR ": ", pc); - count = print_insn(pc, &s.info); + count = s.info.print_insn(pc, &s.info); fprintf(out, "\n"); if (count < 0) { break; @@ -720,31 +706,15 @@ physical_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length, void monitor_disas(Monitor *mon, CPUState *cpu, target_ulong pc, int nb_insn, int is_physical) { - CPUClass *cc = CPU_GET_CLASS(cpu); int count, i; CPUDebug s; - INIT_DISASSEMBLE_INFO(s.info, NULL, qemu_fprintf); - - s.cpu = cpu; - s.info.read_memory_func - = (is_physical ? physical_read_memory : target_read_memory); - s.info.print_address_func = generic_print_address; - s.info.buffer_vma = pc; - s.info.cap_arch = -1; - s.info.cap_mode = 0; - s.info.cap_insn_unit = 4; - s.info.cap_insn_split = 4; - -#ifdef TARGET_WORDS_BIGENDIAN - s.info.endian = BFD_ENDIAN_BIG; -#else - s.info.endian = 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 = qemu_fprintf; + if (is_physical) { + s.info.read_memory_func = physical_read_memory; } + s.info.buffer_vma = pc; if (s.info.cap_arch >= 0 && cap_disas_monitor(&s.info, pc, nb_insn)) { return; From patchwork Mon Sep 21 17:41:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 11790565 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 78F4E59D for ; Mon, 21 Sep 2020 17:50:02 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 035E0216C4 for ; Mon, 21 Sep 2020 17:50:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="vxHMu+H4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 035E0216C4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:47354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKPwu-0000J7-OL for patchwork-qemu-devel@patchwork.kernel.org; Mon, 21 Sep 2020 13:50:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46080) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKPoq-00089b-O9 for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:42 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:41997) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKPom-0000If-GP for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:40 -0400 Received: by mail-pg1-x543.google.com with SMTP id k14so9661101pgi.9 for ; Mon, 21 Sep 2020 10:41:30 -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=kjSlGDaz/gKdqZUsB3eBl8fd3FyvHs6q0rMsilYCIuA=; b=vxHMu+H40KDYMN3/MTzuVX8DAb9y9T87S5rN2r+jnp4MDeQcPY07lzvgveqVlPswTW A0y/Tk03gWaPGd/8wa9zZihSjQkLWtgFYHWESTFJ2wD8IBQ3mUqvQVX1f+de/FVpPuBI YNCXKEgYUYdTwEOa2siSUs+KpWFzJ28MueTSWFWNoKErCNWKlVrrYkCmAV7/sNl1kg/Y 4xLOeNco6zLRKDuR6NABHJrlxbUSyHKvGBxFAM98Vai6KnN+/LaGlY8hmdPF4sHwzVu8 zGrY3JatDbbGaCI/3eH27FxKi9UAY+SMtZiSj/p1fJT7PtjKnSBF62nVmwZqfCUQlxtD 0wjQ== 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=kjSlGDaz/gKdqZUsB3eBl8fd3FyvHs6q0rMsilYCIuA=; b=XM2h7bpSFHP6WpH93nYR+zss+vk2XEiSkQ2oX+GOtdEabBL9CdE9Ghnl1wZxLWVUwX CpaPLFx2coG4633tDL3xlDZKnTQC1/eS3jOdW21WKThXzgyk13sFYQtLx9xrLEPomsCm 2wqcZKqDEFXuInXPPqCO3XhjrVRCaGhMDCVF9/DXqzKyGRY9KdwIs0P7l9J9rRE8JNB4 qNVt4Ezlpx/aApN2zON9YCN5RdNiLITqLL7X6m+lOHYMJOuDxHfyTzGQxaabbh3DA+d1 W2YbdtWXt+xm3naZRQFY24uB1EsIAUnecr0aqea8ogRfnvvFUDZO0Tg3AAMHXrRAXVq1 QN5w== X-Gm-Message-State: AOAM531y2HBuLH/+Ced3O6pWjNFSl6+TfmenjT0uFByPEZWCM1nTS4wI VExrYdQiG+X5+7TICHHF+kBQNk/lxN+n8g== X-Google-Smtp-Source: ABdhPJwOR8qUzoCfgkxtONRpWoLgHkydQtTrffsHF02IAwgerVzpa6+0acU1om5u+51g6bhK5J4FGQ== X-Received: by 2002:a62:1b4e:0:b029:13e:d13d:a135 with SMTP id b75-20020a621b4e0000b029013ed13da135mr829180pfb.29.1600710089601; Mon, 21 Sep 2020 10:41:29 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id x4sm12585379pfm.86.2020.09.21.10.41.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 10:41:28 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 06/11] disas: Use qemu/bswap.h for bfd endian loads Date: Mon, 21 Sep 2020 10:41:13 -0700 Message-Id: <20200921174118.39352-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200921174118.39352-1-richard.henderson@linaro.org> References: <20200921174118.39352-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::543; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x543.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: alex.bennee@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Use the routines we have already instead of open-coding. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- 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 *); /* from libbfd */ -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; #endif /* DISAS_DIS_ASM_H */ diff --git a/disas.c b/disas.c index 7bc8e9a037..bf19b1b0bf 100644 --- a/disas.c +++ b/disas.c @@ -78,61 +78,6 @@ static int symbol_at_address(bfd_vma addr, struct disassemble_info *info) return 1; } -bfd_vma bfd_getl64 (const bfd_byte *addr) -{ - unsigned long long v; - - v = (unsigned long long) addr[0]; - v |= (unsigned long long) addr[1] << 8; - v |= (unsigned long long) addr[2] << 16; - v |= (unsigned long long) addr[3] << 24; - v |= (unsigned long long) addr[4] << 32; - v |= (unsigned long long) addr[5] << 40; - v |= (unsigned long long) addr[6] << 48; - v |= (unsigned long long) addr[7] << 56; - return (bfd_vma) v; -} - -bfd_vma bfd_getl32 (const bfd_byte *addr) -{ - unsigned long v; - - v = (unsigned long) addr[0]; - v |= (unsigned long) addr[1] << 8; - v |= (unsigned long) addr[2] << 16; - v |= (unsigned long) addr[3] << 24; - return (bfd_vma) v; -} - -bfd_vma bfd_getb32 (const bfd_byte *addr) -{ - unsigned long v; - - v = (unsigned long) addr[0] << 24; - v |= (unsigned long) addr[1] << 16; - v |= (unsigned long) addr[2] << 8; - v |= (unsigned long) addr[3]; - return (bfd_vma) v; -} - -bfd_vma bfd_getl16 (const bfd_byte *addr) -{ - unsigned long v; - - v = (unsigned long) addr[0]; - v |= (unsigned long) addr[1] << 8; - return (bfd_vma) v; -} - -bfd_vma bfd_getb16 (const bfd_byte *addr) -{ - unsigned long v; - - v = (unsigned long) addr[0] << 24; - v |= (unsigned long) addr[1] << 16; - return (bfd_vma) v; -} - static int print_insn_objdump(bfd_vma pc, disassemble_info *info, const char *prefix) { From patchwork Mon Sep 21 17:41:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 11790543 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DE38659D for ; Mon, 21 Sep 2020 17:43:44 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 890942151B for ; Mon, 21 Sep 2020 17:43:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="K1Myh6UA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 890942151B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:58884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKPqp-0001YC-Hv for patchwork-qemu-devel@patchwork.kernel.org; Mon, 21 Sep 2020 13:43:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKPop-00088l-Ku for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:39 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:35554) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKPom-0000Im-GE for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:39 -0400 Received: by mail-pg1-x543.google.com with SMTP id g29so9685287pgl.2 for ; Mon, 21 Sep 2020 10:41:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AcobOMV5CV8pSJwR9n+sDy8pDWv6IjgjNuunOfxWOco=; b=K1Myh6UAyiqLmrGli4PTBUvy13Ewb1oaOjjdyp5TRK3oS3llVptmHSkRGFEsCYAt02 UgZAXzp79DLswFndRm62FQ+cdW4dUfiGSFTbGZCvk6st8oqwimc+OM2fWIlrSTXO02aO Z/ZpCE4viS4zcOkWawOqXFq7LUrOWBILvvr1Lp1CZ13Yz97BLpMDCH1CDisU7/5CrUo5 8xZD+iJztJimgJGgci5/qWFNDK6efnOJB/XPYFI9UKRutnyF9TSvsWxxiGGPOFpmJxD2 RbDABevTEqx++rruuvPM9DeQ+hdQqzEKT90CXH4aE4rC10EA6w7OkWbWldFXevtc5s7M T/NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AcobOMV5CV8pSJwR9n+sDy8pDWv6IjgjNuunOfxWOco=; b=NaeOz9LzWWXpyV/MmQyDjlQ1tEglpLbMs0+Oeo/rE3ZNreKG1YE+HYizonDcy1YOOU C/E1Thv0cxpY312vMyF+WmVizM4I2lkvmMfCZCwuCMKMsLsMWiirS/UB6JWrvxeempI1 W/+WSXRvZtqdnaKkxAhe1YEO4NTBtcYSlG9L3iqCtXnN1Sc0Ag4x+o91BDZC3w7DTFVz l0XKziiTEBk6+uqRzWKqjAS4aiEwp6BSmKYERjJ5VElpiSHb8uCOpg4M9l48gz/NKIb7 TZ15v/Vr9917267etLo4XxDrQFvVqIh1SFtZIpjsNinyBOizD0J2ng2rXRrgpv3EZrtY A8bg== X-Gm-Message-State: AOAM531iEahknr2uQlERtDnmA7XtiYyu6ruK3VtWLcpohBt3qUf1mmkO k8d2R+/Z+5v7MmU7AMAzMeLQfYOv8B6FsA== X-Google-Smtp-Source: ABdhPJzlzDXm+ratHKgGk08DLSHXQFJIoQ117zYK5j26K22HdKAf0Oq/sDHGXcMP3yODUHtcD/zOxA== X-Received: by 2002:aa7:941a:0:b029:142:2501:34dc with SMTP id x26-20020aa7941a0000b0290142250134dcmr804543pfo.53.1600710090845; Mon, 21 Sep 2020 10:41:30 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id x4sm12585379pfm.86.2020.09.21.10.41.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 10:41:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 07/11] disas: Cleanup plugin_disas Date: Mon, 21 Sep 2020 10:41:14 -0700 Message-Id: <20200921174118.39352-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200921174118.39352-1-richard.henderson@linaro.org> References: <20200921174118.39352-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::543; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x543.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: alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Do not retain a GString in thread-local storage. Allocate a new one and free it on every invocation. Do not g_strdup the result; return the buffer from the GString. Do not use warn_report. Using cs_disasm allocated memory via the &insn parameter, but that was never freed. Use cs_disasm_iter so that we use the memory that we've already allocated, and so that we only try to disassemble one insn, as desired. Do not allocate 1k to hold the bytes for a single instruction. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- disas.c | 55 +++++++++++++++++++------------------------------------ 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/disas.c b/disas.c index bf19b1b0bf..d0ccd4b727 100644 --- a/disas.c +++ b/disas.c @@ -491,13 +491,12 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code, } } -static __thread GString plugin_disas_output; - static int plugin_printf(FILE *stream, const char *fmt, ...) { - va_list va; - GString *s = &plugin_disas_output; + /* We abuse the FILE parameter to pass a GString. */ + GString *s = (GString *)stream; int initial_len = s->len; + va_list va; va_start(va, fmt); g_string_append_vprintf(s, fmt, va); @@ -517,28 +516,20 @@ static void plugin_print_address(bfd_vma addr, struct disassemble_info *info) static bool cap_disas_plugin(disassemble_info *info, uint64_t pc, size_t size) { - uint8_t cap_buf[1024]; + uint8_t cap_buf[64]; + const uint8_t *cbuf = cap_buf; csh handle; - cs_insn *insn; - size_t csize = 0; - int count; - GString *s = &plugin_disas_output; if (cap_disas_start(info, &handle) != CS_ERR_OK) { return false; } - insn = cap_insn; - size_t tsize = MIN(sizeof(cap_buf) - csize, size); - const uint8_t *cbuf = cap_buf; - target_read_memory(pc, cap_buf, tsize, info); + assert(size < sizeof(cap_buf)); + target_read_memory(pc, cap_buf, size, info); - count = 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 = (GString *)info->stream; + g_string_printf(s, "%s %s", cap_insn->mnemonic, cap_insn->op_str); } cs_close(&handle); @@ -553,34 +544,26 @@ bool cap_disas_plugin(disassemble_info *info, uint64_t pc, size_t size) */ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size) { - int count; CPUDebug s; - GString *ds = g_string_set_size(&plugin_disas_output, 0); - - g_assert(ds == &plugin_disas_output); + GString *ds = g_string_new(NULL); initialize_debug_target(&s, cpu); s.info.fprintf_func = plugin_printf; + s.info.stream = (FILE *)ds; /* abuse this slot */ s.info.buffer_vma = addr; s.info.buffer_length = size; s.info.print_address_func = plugin_print_address; if (s.info.cap_arch >= 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 */ } - if (s.info.print_insn == NULL) { - s.info.print_insn = print_insn_od_target; - } - - count = 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); } /* Disassemble this for me please... (debugging). */ From patchwork Mon Sep 21 17:41:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 11790561 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D142112E for ; Mon, 21 Sep 2020 17:49:51 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 92D65216C4 for ; Mon, 21 Sep 2020 17:49:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="yVZFklJC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 92D65216C4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKPwh-00005p-An for patchwork-qemu-devel@patchwork.kernel.org; Mon, 21 Sep 2020 13:49:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKPov-0008BK-4R for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:47 -0400 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]:33639) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKPom-0000Iu-Ge for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:44 -0400 Received: by mail-pj1-x1041.google.com with SMTP id md22so243571pjb.0 for ; Mon, 21 Sep 2020 10:41:33 -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=J+BOVOHGD/QEo5qK+coXTJ7fUE4O+DKxbUmsuQDQSc8=; b=yVZFklJCySAXao2GaMbnYtfDemeyeBrlYIN7T5twoToUNRHb2fG6yU2bPxOnHdraar 3AE6kwvngR0yMzWfbI4w3NlNkTd0AyDgu7ejpQEjIMiQHXLYQHZnppI3GTZPrtCg9SGr Qo0v/LU1OQeLbuC0iik1nGHFdzUGRbnAMp3R0TWIqFLlyKcNis4OCqnGOBHCxNT87lHM LEfGfQdwtiucEFmlSLV1vtoYbk0rAHgo5s7BQwXzgsnJFSk4Xf2q19YwpnrR9y8LFOHv D1+Qz3CKQlc5JOmtug8a2TLwlXHNk76KAY4NzM6/aoR5kkPN9+8nRKySqw5KD6y4aIs5 EekA== 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=J+BOVOHGD/QEo5qK+coXTJ7fUE4O+DKxbUmsuQDQSc8=; b=ahp/HxX1VmIanpPGbfmSRR+d/jR0NTJU9Rl4GbZWhh922gd45LvO9fr1aEsyoiyVZG qse8sPwTA4x7Z2oQMuF2e11gd4fpR8EPFN3pauJoNsna4pg/9L6AfP55Uz+WlnCKzYoe UYMDVTnN+EbsjddPROVcRLTPpjMDGzwk2eEaRoEH9xrhbnIUHKAmi87JRFyLpEZHO8J4 n/OmLn5iveelFP8sJlSR4xGcfai3s6q+XQH3nWlCEY6URAAJfUbk/mp1zgkSnyaxbFkY J/eIhoLER0Wv6e7mfxpX4f82NXdlRegi6Ns1Ja/fcFbyuKcLDFhLkmfH/2kO0wcDCsjl CeZw== X-Gm-Message-State: AOAM5311rpFQ2vkPHXWKeAM/eJzX1CRxuspLlEFLv1V47uY0/j47baMe U/stKK4YetjCLbkVkN9WoA9hPk4+OV06mA== X-Google-Smtp-Source: ABdhPJzT4uijQ8mwrvdGxBFzrHityhvl0bPPlmhe6TqOeZnqggiLD/K0g0bKySVHrpz5aen7TunLGw== X-Received: by 2002:a17:90b:350b:: with SMTP id ls11mr392341pjb.201.1600710092199; Mon, 21 Sep 2020 10:41:32 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id x4sm12585379pfm.86.2020.09.21.10.41.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 10:41:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 08/11] disas: Configure capstone for aarch64 host without libvixl Date: Mon, 21 Sep 2020 10:41:15 -0700 Message-Id: <20200921174118.39352-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200921174118.39352-1-richard.henderson@linaro.org> References: <20200921174118.39352-1-richard.henderson@linaro.org> MIME-Version: 1.0 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: Thomas Huth , alex.bennee@linaro.org, =?utf-8?q?Philip?= =?utf-8?q?pe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The ifdef tangle failed to set cap_arch if libvixl itself was not configured (e.g. due to lack of c++ compiler). Reviewed-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- disas.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/disas.c b/disas.c index d0ccd4b727..01c8bc6c9e 100644 --- a/disas.c +++ b/disas.c @@ -428,9 +428,11 @@ static void initialize_debug_host(CPUDebug *s) #else #error unsupported RISC-V ABI #endif -#elif defined(__aarch64__) && defined(CONFIG_ARM_A64_DIS) - s->info.print_insn = print_insn_arm_a64; +#elif defined(__aarch64__) s->info.cap_arch = CS_ARCH_ARM64; +# ifdef CONFIG_ARM_A64_DIS + s->info.print_insn = print_insn_arm_a64; +# endif #elif defined(__alpha__) s->info.print_insn = print_insn_alpha; #elif defined(__sparc__) From patchwork Mon Sep 21 17:41:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 11790573 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 28E25112E for ; Mon, 21 Sep 2020 17:52:58 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B15F620BED for ; Mon, 21 Sep 2020 17:52:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="VFTisdKo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B15F620BED Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:55616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKPzk-0003td-Qm for patchwork-qemu-devel@patchwork.kernel.org; Mon, 21 Sep 2020 13:52:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46126) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKPoy-0008Ba-Rf for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:50 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:40714) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKPom-0000J1-P6 for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:48 -0400 Received: by mail-pj1-x1043.google.com with SMTP id gf14so145058pjb.5 for ; Mon, 21 Sep 2020 10:41:35 -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=i9goDzbjSTWkoFEIajUOTkDHVXwsFM6EiBokklPiC/I=; b=VFTisdKorwd8Ug81L0VzhpB2ZYpTKCGXicOUlJ+oIpROe9+eryyIg2VDRnptv1zV9s CD1Q1Vkmuf4rEfEBcAOR5Or8P94Gk+2Zh11fapkdK0l249MMslthDG81zPw5oPVBLB6A sZFn8681Ga+aCB/uls98LTqU2K8NJoyNb9Rmm05DZzopWJwvimpTM0IQ+vSG168KOzT2 V6KYD6dKsGaG9R3EyTwfb2EQFJonrmagE30Nq3XDHh4OSQI1ffgSt+qSsJTiTxx1QwcP UIOoLOyKVDverJKKUOk9G41zBqbBEMw8taX74mICXpM87CsAosYqUWe2AkaNYh0hwNM4 mvlQ== 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=i9goDzbjSTWkoFEIajUOTkDHVXwsFM6EiBokklPiC/I=; b=OsWwuWzFNMGZ02b//AbIyNQd3jNwn+sYLCPYfqXvZEmjdwbZWLAxFy+5AeuBKsWBHN jqJNSguZSGr9MYVGjpDi6aFNaAovqZWrb0dKJ2wlUDVfmuw70H2maFi9qEHQiF7/6MHD WkDADPB1SuO/Tzte7jWH8na9+ms0gEMRqEjvPG7XUv4KOs98sPmgWV6uAm8sb5EAUvva TpK+aeDdseeB8Nf4GC/9Z5FaKQ8ZsDhyRAXZlS6J5Euj6c+jQkFTyc1/KOukqyq1bCvD PxWscFj8LxWhuIkiYZa2++s1Wk1UKG+oOh9PWX03P6ExaGW3m3s4Xe6tj5yIcTo+ed3O hUZg== X-Gm-Message-State: AOAM531PliGVP04uX3qkW/W0DMz8PEZ56l1P0aQ3jnaAgp4VHXEIGY0k ssmjEk3+Lq+bUa+wokGPchs5op7agpp50w== X-Google-Smtp-Source: ABdhPJyzC1eb0mCyxNxQVwoBJPqOHcZJML3V5oGsIJ5YS5dyAX+aAqPXL4Hphyx3nF0jY9sSqE6jzg== X-Received: by 2002:a17:90a:6701:: with SMTP id n1mr414465pjj.87.1600710093492; Mon, 21 Sep 2020 10:41:33 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id x4sm12585379pfm.86.2020.09.21.10.41.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 10:41:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 09/11] disas: Split out capstone code to disas/capstone.c Date: Mon, 21 Sep 2020 10:41:16 -0700 Message-Id: <20200921174118.39352-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200921174118.39352-1-richard.henderson@linaro.org> References: <20200921174118.39352-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1043; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1043.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" There is nothing target-specific about this code, so it can be added to common_ss. This also requires that the base capstone dependency be added to common_ss, so that we get the correct include paths added to CFLAGS. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- include/disas/dis-asm.h | 12 ++ disas.c | 275 -------------------------------------- disas/capstone.c | 286 ++++++++++++++++++++++++++++++++++++++++ disas/meson.build | 1 + meson.build | 1 + 5 files changed, 300 insertions(+), 275 deletions(-) create mode 100644 disas/capstone.c diff --git a/include/disas/dis-asm.h b/include/disas/dis-asm.h index 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 *); +#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 01c8bc6c9e..e27dea2c19 100644 --- a/disas.c +++ b/disas.c @@ -107,255 +107,6 @@ static int print_insn_od_target(bfd_vma pc, disassemble_info *info) return print_insn_objdump(pc, info, "OBJD-T"); } -#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 = info->cap_mode; - cs_err err; - - cap_mode += (info->endian == BFD_ENDIAN_BIG ? CS_MODE_BIG_ENDIAN - : CS_MODE_LITTLE_ENDIAN); - - err = cs_open(info->cap_arch, cap_mode, handle); - if (err != CS_ERR_OK) { - return err; - } - - /* ??? There probably ought to be a better place to put this. */ - if (info->cap_arch == 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 == NULL) { - cap_insn = cs_malloc(*handle); - if (cap_insn == 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 = info->fprintf_func; - FILE *stream = info->stream; - - switch (info->cap_insn_unit) { - case 4: - if (info->endian == BFD_ENDIAN_BIG) { - for (; i < n; i += 4) { - print(stream, " %08x", ldl_be_p(insn->bytes + i)); - - } - } else { - for (; i < n; i += 4) { - print(stream, " %08x", ldl_le_p(insn->bytes + i)); - } - } - break; - - case 2: - if (info->endian == BFD_ENDIAN_BIG) { - for (; i < n; i += 2) { - print(stream, " %04x", lduw_be_p(insn->bytes + i)); - } - } else { - for (; i < n; i += 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 = info->fprintf_func; - int i, n, split; - - print(info->stream, "0x%08" PRIx64 ": ", insn->address); - - n = insn->size; - split = 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 = (split - n) / info->cap_insn_unit; - width *= (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 = split; i < n; i += 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 size) -{ - uint8_t cap_buf[1024]; - csh handle; - cs_insn *insn; - size_t csize = 0; - - if (cap_disas_start(info, &handle) != CS_ERR_OK) { - return false; - } - insn = cap_insn; - - while (1) { - size_t tsize = MIN(sizeof(cap_buf) - csize, size); - const uint8_t *cbuf = cap_buf; - - target_read_memory(pc + csize, cap_buf + csize, tsize, info); - csize += tsize; - size -= 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 != 0) { - /* ... taking care to move any remaining fractional insn - to the beginning of the buffer. */ - if (csize != 0) { - memmove(cap_buf, cbuf, csize); - } - continue; - } - - /* Since the target memory is consumed, we should not have - a remaining fractional insn. */ - if (csize != 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) != CS_ERR_OK) { - return false; - } - insn = cap_insn; - - cbuf = code; - pc = (uintptr_t)code; - - while (cs_disasm_iter(handle, &cbuf, &size, &pc, insn)) { - cap_dump_insn(info, insn); - } - if (size != 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 count) -{ - uint8_t cap_buf[32]; - csh handle; - cs_insn *insn; - size_t csize = 0; - - if (cap_disas_start(info, &handle) != CS_ERR_OK) { - return false; - } - insn = 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 = QEMU_ALIGN_UP(pc + csize + 1, 1024); - size_t tsize = MIN(sizeof(cap_buf) - csize, epc - pc); - const uint8_t *cbuf = cap_buf; - - /* Make certain that we can make progress. */ - assert(tsize != 0); - info->read_memory_func(pc, cap_buf + csize, tsize, info); - csize += tsize; - - if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { - cap_dump_insn(info, insn); - if (--count <= 0) { - break; - } - } - memmove(cap_buf, cbuf, csize); - } - - cs_close(&handle); - return true; -} -#endif /* !CONFIG_USER_ONLY */ -#else -# define cap_disas_target(i, p, s) false -# define cap_disas_host(i, p, s) false -# define cap_disas_monitor(i, p, c) false -# define cap_disas_plugin(i, p, c) false -#endif /* CONFIG_CAPSTONE */ - static void initialize_debug(CPUDebug *s) { memset(s, 0, sizeof(*s)); @@ -513,32 +264,6 @@ static void plugin_print_address(bfd_vma addr, struct disassemble_info *info) } -#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 = cap_buf; - csh handle; - - if (cap_disas_start(info, &handle) != 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 = (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 = info->cap_mode; + cs_err err; + + cap_mode += (info->endian == BFD_ENDIAN_BIG ? CS_MODE_BIG_ENDIAN + : CS_MODE_LITTLE_ENDIAN); + + err = cs_open(info->cap_arch, cap_mode, handle); + if (err != 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 == 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 == NULL) { + cap_insn = cs_malloc(*handle); + if (cap_insn == 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 = info->fprintf_func; + FILE *stream = info->stream; + + switch (info->cap_insn_unit) { + case 4: + if (info->endian == BFD_ENDIAN_BIG) { + for (; i < n; i += 4) { + print(stream, " %08x", ldl_be_p(insn->bytes + i)); + + } + } else { + for (; i < n; i += 4) { + print(stream, " %08x", ldl_le_p(insn->bytes + i)); + } + } + break; + + case 2: + if (info->endian == BFD_ENDIAN_BIG) { + for (; i < n; i += 2) { + print(stream, " %04x", lduw_be_p(insn->bytes + i)); + } + } else { + for (; i < n; i += 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 = info->fprintf_func; + FILE *stream = info->stream; + int i, n, split; + + print(stream, "0x%08" PRIx64 ": ", insn->address); + + n = insn->size; + split = 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 = (split - n) / info->cap_insn_unit; + width *= (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 = split; i < n; i += 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 = 0; + + if (cap_disas_start(info, &handle) != CS_ERR_OK) { + return false; + } + insn = cap_insn; + + while (1) { + size_t tsize = MIN(sizeof(cap_buf) - csize, size); + const uint8_t *cbuf = cap_buf; + + info->read_memory_func(pc + csize, cap_buf + csize, tsize, info); + csize += tsize; + size -= 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 != 0) { + /* + * ... taking care to move any remaining fractional insn + * to the beginning of the buffer. + */ + if (csize != 0) { + memmove(cap_buf, cbuf, csize); + } + continue; + } + + /* + * Since the target memory is consumed, we should not have + * a remaining fractional insn. + */ + if (csize != 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) != CS_ERR_OK) { + return false; + } + insn = cap_insn; + + cbuf = code; + pc = (uintptr_t)code; + + while (cs_disasm_iter(handle, &cbuf, &size, &pc, insn)) { + cap_dump_insn(info, insn); + } + if (size != 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 = 0; + + if (cap_disas_start(info, &handle) != CS_ERR_OK) { + return false; + } + insn = 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 = QEMU_ALIGN_UP(pc + csize + 1, 1024); + size_t tsize = MIN(sizeof(cap_buf) - csize, epc - pc); + const uint8_t *cbuf = cap_buf; + + /* Make certain that we can make progress. */ + assert(tsize != 0); + info->read_memory_func(pc, cap_buf + csize, tsize, info); + csize += tsize; + + if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { + cap_dump_insn(info, insn); + if (--count <= 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 = cap_buf; + csh handle; + + if (cap_disas_start(info, &handle) != 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('s390.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')) specific_ss.add(when: 'CONFIG_TCG_INTERPRETER', if_true: files('tci.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')) subdir('softmmu') +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( From patchwork Mon Sep 21 17:41:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 11790591 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E2A659D for ; Mon, 21 Sep 2020 17:55:50 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A647220BED for ; Mon, 21 Sep 2020 17:55:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="S921QOqL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A647220BED Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:35824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKQ2W-0007Rx-PM for patchwork-qemu-devel@patchwork.kernel.org; Mon, 21 Sep 2020 13:55:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKPp0-0008CE-Uo for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:50 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:41596) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKPom-0000J5-Pw for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:49 -0400 Received: by mail-pg1-x543.google.com with SMTP id y1so9666144pgk.8 for ; Mon, 21 Sep 2020 10:41:35 -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=avZ+rMB6lV+f9plLNYbILt3X5fXdFe2OIgJnsNYwFZg=; b=S921QOqLUyaL2A/lUKrPYYLUsvHyFPlowKVG2hf0LXU/GaEOYR6zyF2k0rhAWD1qxQ NvV1qURUWJ2Bn+1Wm8Lbh2TINzMBDMGweY7OX0/e7a53L3e7V+a1iIn5BxDqiiasmV0b ILpf5BWcxtxGS4cEa8URxs/ga+xDCXLK2jjSVMgu3axPLWGXDA4cUlaJLQuo/2yJc/yy gtnXnst3iVEszd6oU8nSDnLpIAfBjN2c89A/h9hl+4UfeqbDUhC+5awXmy7ecKkYbaZQ VaW3lzUiDxKr+6rd0eeThpMSCRechrfdToiYLewSEVD9JKnDPOAwAP+VU00pdaXvYjw7 mm/A== 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=avZ+rMB6lV+f9plLNYbILt3X5fXdFe2OIgJnsNYwFZg=; b=ZgF18gIoGv8JO5S5Rmr+PT07z3y0eTacQpRSOiXuXCBYIOL3sivs7D39WreiSwUPXC CNwP9mjsKxyjmTftiA1cFiC4CO4FxZvC+yIMghhCfVNKId333sKt5pXchaLNKIdOJc4D MvixY56G6iUHgBgzAvW0NWAK+4bXQCKAi2fJ4iLbN1SzsEDGld8VtJd+Iu2D3I35y/iE Y9ODNW/SVRG3fJ57AsTevU2Go4lIE3LsenOZFLWCx7WaIzBCacE6DURNEvxsjBEbKHMW cqVC94yDqe5TRqYt0V5eT5fgybgM2M3M0LcH1YqbWcSvLfNSq1jC+xRANgl4Al1pCfx7 /C8Q== X-Gm-Message-State: AOAM532CxbrvsiZwRD2IWB8qoxuD4Cddc0r0u+rskcocAK4EO7qDGUJb +jt95otcPGrKhc+4RCwvP+W3CG4kis5twA== X-Google-Smtp-Source: ABdhPJz2IS+BVU/J6hY0+o24VuknSkagfMNLzCcp0Tk8KpdJGEae5aKESulD+l6eRENsBf4ga2ZsuA== X-Received: by 2002:a05:6a00:1b:b029:13e:d13d:a101 with SMTP id h27-20020a056a00001bb029013ed13da101mr770182pfk.29.1600710094500; Mon, 21 Sep 2020 10:41:34 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id x4sm12585379pfm.86.2020.09.21.10.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 10:41:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 10/11] disas: Enable capstone disassembly for s390x Date: Mon, 21 Sep 2020 10:41:17 -0700 Message-Id: <20200921174118.39352-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200921174118.39352-1-richard.henderson@linaro.org> References: <20200921174118.39352-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::543; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x543.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=unavailable 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: Thomas Huth , alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Enable s390x, aka SYSZ, in the git submodule build. Set the capstone parameters for both s390x host and guest. Acked-by: Thomas Huth Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée Tested-by: Alex Bennée --- disas.c | 3 +++ target/s390x/cpu.c | 4 ++++ meson.build | 11 +++++++++++ 3 files changed, 18 insertions(+) diff --git a/disas.c b/disas.c index e27dea2c19..c4cd305190 100644 --- a/disas.c +++ b/disas.c @@ -201,6 +201,9 @@ static void initialize_debug_host(CPUDebug *s) s->info.print_insn = print_insn_m68k; #elif defined(__s390__) s->info.print_insn = print_insn_s390; + s->info.cap_arch = CS_ARCH_SYSZ; + s->info.cap_insn_unit = 2; + s->info.cap_insn_split = 6; #elif defined(__hppa__) s->info.print_insn = print_insn_hppa; #endif diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index 749cd548f0..2a96692691 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -44,6 +44,7 @@ #include "sysemu/tcg.h" #endif #include "fpu/softfloat-helpers.h" +#include "disas/capstone.h" #define CR0_RESET 0xE0UL #define CR14_RESET 0xC2000000UL; @@ -182,6 +183,9 @@ static void s390_cpu_disas_set_info(CPUState *cpu, disassemble_info *info) { info->mach = bfd_mach_s390_64; info->print_insn = print_insn_s390; + info->cap_arch = CS_ARCH_SYSZ; + info->cap_insn_unit = 2; + info->cap_insn_split = 6; } static void s390_cpu_realizefn(DeviceState *dev, Error **errp) 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 == 'internal' ) endif + if 'CONFIG_S390_DIS' in config_all_disas + capstone_data.set('CAPSTONE_HAS_SYSZ', '1') + capstone_files += 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 += files( From patchwork Mon Sep 21 17:41:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 11790567 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 32501112E for ; Mon, 21 Sep 2020 17:51:15 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EAED72193E for ; Mon, 21 Sep 2020 17:51:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="LPhZXle6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EAED72193E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:50060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKPy6-0001VL-3W for patchwork-qemu-devel@patchwork.kernel.org; Mon, 21 Sep 2020 13:51:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKPp5-0008EL-87 for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:56 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:51327) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKPon-0000JB-9p for qemu-devel@nongnu.org; Mon, 21 Sep 2020 13:41:54 -0400 Received: by mail-pj1-x1043.google.com with SMTP id a9so168093pjg.1 for ; Mon, 21 Sep 2020 10:41:36 -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=wjvg2SPI3pDSrleHGUZpH6t3zzxOiZw90GPESZPEUKw=; b=LPhZXle68yO8XfsuPDJMqlafrS7AGvc3gLuSgSJRe3aGaHhIUWI29nkojgsidQV5BE u/CAkcZsfg8DnsZFD01wY35Uv1rR+Vnn6J3Crj2wLWNGo+a7oz8H0FhFPOBtxeXmSy4+ E3HzTfOdYIhD6RbRCl/Qa9jqdVXnBzY88UomEdrCuaxnbVQwEW35vKYEzltLl6SBO+8L 2e051S7iz2IBow+f09qjYIxi3ZnxupBn9D8mUV9dTNWEE2aOJK7bY1nRWlU9tDE6yCbU Ky53N70U6Vu7zKAsSZKrMvHpU4yPrqB8jmyMGQgDNRSTeo2ezln+7bjM7qWgF3KaBJJx 1UsA== 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=wjvg2SPI3pDSrleHGUZpH6t3zzxOiZw90GPESZPEUKw=; b=pPbKkiY0yBJHiRtL22mcpXj4CRM2V4CpQata5N9bppKPBh3BAsw92GAkUbkm11LFv8 eRd5OL2jw7WXfYfopyuzargrZCUHOxLXHYTANcNOxJqbDIzUAM32M1pmeZssSzzbrlct RwAo+DwC3zEK4CmjfEqfAUxV/+AmfqarEcQ41LSAw95lynwpO8xPArj27QQclLbJFJmr aLUeOmBm+hdj9TguzY8knyNxzbCdgw5AykQN2XRBxGGWMHJSGusSoivCePqeCWPz51yB d8zvtrvW03gIkFFdkF3XHeld/qNfZYzQVKzqhRwKmdMu6WHvO9ZZxCQDSUWhHLc1QUrF bs3A== X-Gm-Message-State: AOAM531qPgDlTlZ4Q5yHjDoYGcaDEgS7k7kTIE+8+jfwukEp35lRu5tt ihl5TLig2Kg+xq0fzbsZ+HhdzCDkgWiIcA== X-Google-Smtp-Source: ABdhPJzOhHVaCnMavIxFAIg3+Oge5LLc/q8MEGIvczTjBHGTkCg32ork7GC8U2btF87mjrsEL0sLsw== X-Received: by 2002:a17:90b:1212:: with SMTP id gl18mr416052pjb.138.1600710095634; Mon, 21 Sep 2020 10:41:35 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id x4sm12585379pfm.86.2020.09.21.10.41.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 10:41:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 11/11] disas/capstone: Add skipdata hook for s390x Date: Mon, 21 Sep 2020 10:41:18 -0700 Message-Id: <20200921174118.39352-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200921174118.39352-1-richard.henderson@linaro.org> References: <20200921174118.39352-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1043; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1043.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Thomas Huth , alex.bennee@linaro.org, =?utf-8?q?Philip?= =?utf-8?q?pe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- 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; +/* + * 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 = 2; + break; + case 1: + case 2: + ilen = 4; + break; + default: + ilen = 6; + break; + } + + return ilen; +} + +static const cs_opt_skipdata cap_skipdata_s390x = { + .mnemonic = ".byte", + .callback = cap_skipdata_s390x_cb +}; + /* * Initialize the Capstone library. * @@ -42,13 +75,20 @@ static cs_err cap_disas_start(disassemble_info *info, csh *handle) /* "Disassemble" unknown insns as ".byte W,X,Y,Z". */ cs_option(*handle, CS_OPT_SKIPDATA, CS_OPT_ON); - if (info->cap_arch == 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; } /* Allocate temp space for cs_disasm_iter. */