From patchwork Mon Sep 14 00:01:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 249747 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1199935ilg; Sun, 13 Sep 2020 17:03:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztp4fXz2xeVdN02Ig/I3RYeqM3sBE4op0+IIn7m0xoLHYTjDrtSFHQ7a5gl9Lk9l4rUFXb X-Received: by 2002:ad4:4c0a:: with SMTP id bz10mr11083580qvb.14.1600041804079; Sun, 13 Sep 2020 17:03:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600041804; cv=none; d=google.com; s=arc-20160816; b=fFrT8XHK+csQy5lQ77Rqj23eJnbh8nfkXEo0e7iKWBAMrmi9NIvEqFjwdblc2r+en1 GFQUrJkXdA2PviqUISKZGxvVgk7pEIk8U6erYTzp96EMK6GRx2qYVXi81jZObq9uPFwd 1/itKe7YP2J2TR04v6NNEQorhAchTOsl/knHT6JTXZBSXdKajv2ZyFGZRU2ChgH/knCX UIohJI/FH5nypPij7HRjr6wgujAtXtHEQ9Wn5HA3u659srCwFBjox/8msgQ+VJqV6Dv5 3jL+3GWS//oAsGudVuQ9X5q9Xz/Z7JpBBC0z4l1IoFDrc9rmmI7mUNgpj9VmTu5+pXC7 0WKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=1udUAr8a7IXOV2H9rA8omIwMHcyQUC+GvcI+H0onXWA=; b=hIBZZ6FE/4Og864lcegjglXY2c+frioXU5LqFGTT7q6OyRFKe9qQ+Q4HQRZ0/6PU0W oGWJZPGqr5LoMkEXa2wm3Ru/JtHf6YhLQbD45IUSZa0+NAOay2bp/wN+tCzSm27dfooW M4CMCUx4jPUQlJ0wPtkNohz2siFrDbHDyZaGsAJ4a/SxyGjn5C1aJS2EHP5fHJsU+nYn x104qz1rHKM6u0PSZPgeDFY/vITmQYFpjVgqqqv209W5iP9O8Avwv2qaBwQy0oDxhzgu 2M7KJGFT+SDNwcVqwAJf40SNfRbnpcExjiPK5YBvRMdtFsZK5DNgCrZJsa7piLkoQ3P+ cRPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tH9ekyKb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w54si5728832qtk.197.2020.09.13.17.03.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 13 Sep 2020 17:03:24 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tH9ekyKb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34780 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHbxr-0005CZ-HL for patch@linaro.org; Sun, 13 Sep 2020 20:03:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43508) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHbwW-0002Ua-8i for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:00 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]:42415) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHbwU-0004BW-14 for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:01:59 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d6so11043556pfn.9 for ; Sun, 13 Sep 2020 17:01:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1udUAr8a7IXOV2H9rA8omIwMHcyQUC+GvcI+H0onXWA=; b=tH9ekyKbKNqBu7NOdNeDYHc1kHfGZjX9Q4P+BttxtUy7ZI073n3WDF+AnHW3gpSyiI T0KTeU697vw0Ig5J+9TDKOSUhVOiEw8xICE2gHJ4vHCmC+gbL5w1k3zkB1mA8FFh12sJ KCuvbrffdclxn8MPs1fe3eCwR1ft80V+UOh1+UlTqMm/6E1FcedtMNAFUeGquFPnHyHs zVjZhYgC8XjtWRAon7HCfgimsXiG2OHCCJpgspXYj3IZE4/wOUtiiyjNaqc99j9AOJk4 F52ZQ3iWMyAvKnKBQxhmsKGUzgr1VUZqosyl711uZfsHVUkygGW+0o9l4FEpSiAfn7Hb 8LCA== 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=1udUAr8a7IXOV2H9rA8omIwMHcyQUC+GvcI+H0onXWA=; b=WUn9Z6HYxB9t44+QAZqxn79xy0bMlhySegYV0+IxsQnhgcxN4PgRsq4MZ0o4EgJOiM sYEfYznhzeKnmtqsRGxTCs/qF3cxCdntHdzXBvjmRys4qjwaMkWa52U+jwwB8f4kdf6j 4ogJ8HYDosi+EMMf/1cUyGqPBl83HJS2QC5xf++pBnFT9PoWjm1yP+pz/yZT1ysgXX0c uaqgvD9l90a+L8AToD814I12sNUu7N9kcXlidT6YDUwvBKhKu1Ki3blMCbnS/7QDj4fL mEfEVPvDarwPV3Ayc/dDrZJWfuuTeSda6htto56qLwZfG/agG0pybenWjBCDSt5SoncJ bH7g== X-Gm-Message-State: AOAM530OHNcc8tdXrmh+wb+QWsTyiEsh1clOoCaYl4syU7yTk2xiaY+o VmOktKNI/tEb5HzyMwF3O8v90O5gFbFe4Q== X-Received: by 2002:a17:902:eb05:b029:d1:8c50:b1bc with SMTP id l5-20020a170902eb05b02900d18c50b1bcmr11606416plb.35.1600041716306; Sun, 13 Sep 2020 17:01:56 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id 31sm6538252pgs.59.2020.09.13.17.01.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Sep 2020 17:01:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 01/11] capstone: Convert Makefile bits to meson bits Date: Sun, 13 Sep 2020 17:01:43 -0700 Message-Id: <20200914000153.1725632-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914000153.1725632-1-richard.henderson@linaro.org> References: <20200914000153.1725632-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.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. In leiu, build the library via the main meson.build. This improves the current state of affairs in that we will re-link the qemu executables against a changed libcapstone.a, which we wouldn't do before-hand. In addition, the use of the confuration header file instead of command-line -DEFINES means that we will rebuild the capstone objects with changes to meson.build. Cc: Paolo Bonzini Signed-off-by: Richard Henderson --- configure | 24 +++---------- Makefile | 16 --------- meson.build | 89 ++++++++++++++++++++++++++++++++++++++++++++--- meson_options.txt | 3 ++ 4 files changed, 91 insertions(+), 41 deletions(-) -- 2.25.1 diff --git a/configure b/configure index 2b6a1196da..4fc5c15283 100755 --- a/configure +++ b/configure @@ -5146,27 +5146,15 @@ case "$capstone" in esac case "$capstone" in - git | internal) + git) if test "$capstone" = git; 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)" + internal | system | no) ;; - no) - ;; *) error_exit "Unknown state for capstone: $capstone" ;; @@ -7290,8 +7278,6 @@ if test "$ivshmem" = "yes" ; then 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 @@ -7816,9 +7802,6 @@ 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 @@ -8005,7 +7988,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 57f72f56c6..0746aa83e3 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 690723b470..4417de1e14 100644 --- a/meson.build +++ b/meson.build @@ -415,11 +415,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(), @@ -616,6 +611,90 @@ config_all += { 'CONFIG_ALL': true, } +if get_option('capstone') == 'no' + capstone = not_found +elif get_option('capstone') == 'system' + capstone = dependency('capstone', static: enable_static, required: true) +else + 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 + # Generators hxtool = find_program('scripts/hxtool') diff --git a/meson_options.txt b/meson_options.txt index 543cf70043..99ecd44aca 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -22,3 +22,6 @@ 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: 'string', value: 'no', + description: 'capstone support') From patchwork Mon Sep 14 00:01:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 249751 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1201450ilg; Sun, 13 Sep 2020 17:05:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQM64kZaHPdqTg3ywiaC2UiZDPZ28SRyko2ThZVFIt0fzkB0fkwq7y+bnimFyjkQBQWdo3 X-Received: by 2002:a25:e905:: with SMTP id n5mr15677182ybd.46.1600041954326; Sun, 13 Sep 2020 17:05:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600041954; cv=none; d=google.com; s=arc-20160816; b=EGCmz3dtIQP/jrqDgehgnmERMTYqNG064xJWQW+gZfulzloIxdmv0fs3+JQqZX3ofn GC9DYGzpNyEFW5XfNkpFZiPxZIw10tkiTm/iTRP3Djs3bJABUYK1mj8KK/+FaRTKO5UQ wY8PYtT2yl9OCooiAuGLdcsFP1zlaMrNiVvP/oFYWRiEjp4sAbX0Lm94rGzeOFhHjWqi hYEGTFkpijiFTujxdu/YwhsgqqrThZ06KqeagOcm4EcFrc69HQw9vyG4oZzl3NHeRiSD XFEamaM6WiD0UBBlEB8+9bE/AWV+kDi4OeoGWuPubkLf72o1B6HFyzyf3eO4Gcyj2zN6 BN0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=UsRV3idEmZ+/7qjR3Tg+F66rL9CHGtYoIl+nOlZddzg=; b=p50PKUqIf1yTTYfMH7DOPziieYHdOTRxYM1lBUmRTpraB+I2H9UYz8wbm2gOs1B2pM 5hAjo7byZzE0nr1aI/3jxSTDQWpHDnAaLHCd+IYGosMoDBqlsuVvh3n6lNFFDjbDca4L MPiexuH3aPNl5VANIdDW0XtQwDLQpGir3TVFuSi32OCj7Wc/1k5M+hhoT7GLS/VvSNhv JxduHNyzvV2cbzYcPAMGyq1VmRlvbAwZdpMtAsTSsqG496si+tKCZQkXNoH1u/PoWxOP 8yTRx0ulZHfkn3KoDYvxdldl/viwkiyIl/6lp1oWYEhDgetJpHP0vcsPk2Pa1nos2fcQ FAqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=S1ejjA33; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a11si478477ybg.248.2020.09.13.17.05.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 13 Sep 2020 17:05:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=S1ejjA33; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:41150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHc0H-0007lA-SW for patch@linaro.org; Sun, 13 Sep 2020 20:05:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43516) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHbwX-0002Ux-4D for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:01 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:36974) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHbwV-0004Bc-GX for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:00 -0400 Received: by mail-pf1-x442.google.com with SMTP id w7so11057360pfi.4 for ; Sun, 13 Sep 2020 17:01:59 -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=UsRV3idEmZ+/7qjR3Tg+F66rL9CHGtYoIl+nOlZddzg=; b=S1ejjA33gC3ItQhoOI6s3TmYQmyP0giAf0zZldU7vpqPM9Ni9tX6pfMz+OUy1BKFtV lsJnIP605SDMPPjuBznP2iI1i7WT46tnJ2YCEF+1kO4U4y9DplvfkZZktR5gDjgIidN7 E15L8E++ooaubWkE09UaZMKlkD9pMFQGKaR4ztb04l1j5YIL9zcGU4A59LIusOOOWEpF QnnqqLAznEZ5jWYqjnq+eiMbIjTYTppVnqOI0de02sfmulWjtEET89nJYuASMcynQjv5 ONYxfge13Q05qgvFqvrnHpKjiXHg317Ko6JjXgnN+wtpUXDkoAS3+DnAlb7frw+AAyQV sGcA== 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=UsRV3idEmZ+/7qjR3Tg+F66rL9CHGtYoIl+nOlZddzg=; b=C32cx7L1ToP0bLwX5gZtnF7ppjPclWWADnYGg+0BjrEdonM/kmpxNzGMtFZ8CpnPgm y+FTalKAzefUWBd/rGYRTPuRdD8l+8XXblmMw2cFJjgbz+5mKES9A83DQqTInqqivUTH bRk5DiyDUGCCH9mp47hbsWYhzSXFPxOmegblTd+8Mos0ufei94sXsJVGeQn2cpiBChPP u7C7cTXUmNCgFRbNY6GJNflpZGWdTc2MaKddTyZTiFD31KUeSGD3cpYK/DpNKR4BaNxN hUkSRCz6LgEAEsL1iXXYfsHsD0iQkwRnOgC0VcwCKHE+6UGa3xFHiYjzHeHyyxtrOerH tNyA== X-Gm-Message-State: AOAM531xwGv3sZEiOjLZ86zYuycn6K43hbn5f2gCy5abSV7uV3drCd5Z dbnOlznhe1KPj05EFMW1m8Pjl8Mx/kAc/Q== X-Received: by 2002:a63:4cc:: with SMTP id 195mr8937776pge.376.1600041717778; Sun, 13 Sep 2020 17:01:57 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id 31sm6538252pgs.59.2020.09.13.17.01.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Sep 2020 17:01:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 02/11] capstone: Update to upstream "next" branch Date: Sun, 13 Sep 2020 17:01:44 -0700 Message-Id: <20200914000153.1725632-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914000153.1725632-1-richard.henderson@linaro.org> References: <20200914000153.1725632-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::442; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.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. Signed-off-by: Richard Henderson --- capstone | 2 +- meson.build | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) -- 2.25.1 Tested-by: Philippe Mathieu-Daudé 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 4417de1e14..00e2b8cc29 100644 --- a/meson.build +++ b/meson.build @@ -668,6 +668,7 @@ else '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' ) @@ -692,7 +693,7 @@ else c_args: capstone_cargs, include_directories: 'capstone/include') capstone = declare_dependency(link_with: libcapstone, - include_directories: 'capstone/include') + include_directories: 'capstone/include/capstone') endif # Generators From patchwork Mon Sep 14 00:01:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 249745 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1199163ilg; Sun, 13 Sep 2020 17:02:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9oXe1EipQIi5cMdw4bQvEsr796OUaGQXrWdsXaP/EGiAN9RmxASAJ+2Qbi26jTXaew7Jc X-Received: by 2002:a25:c00e:: with SMTP id c14mr10244514ybf.262.1600041737114; Sun, 13 Sep 2020 17:02:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600041737; cv=none; d=google.com; s=arc-20160816; b=zU46XWChDD3GrzslBQPfIjbXY4zkG/+U39J9OoOFN+nqYRh+VanDEheoyZttatlBAS 5QI0LElruE2n7bGslTAS3De4x01m52WAZB0VF7ybFhx4ZPlEaUWk8FPbD4d81lM/I7HO I6MlFeyDRyeIvwfxSk9Tj02VtvhWUnO52K2H2o/lF5LxKrkTrN+BADed20ad/tCuXgPY uxnRiw1+lN+1LKDMPImCPmHy7LpJyMKCeQWc5LiSocNcFrkNF24U/2XYaIuW2SSpuImD VFbH7LcOzfYlSrnJz7hA5EDxGJgYk/R83C46L+PTpYMlZVVWhQL2OSIznWYwoWkt46ME tVqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=O5tftEr4wcy+EcfeUo13CTd2wMJ9pZ9l7p7m81TmeOA=; b=CpFJTm01Rn4582CaVPkoeirQ8X49x4McH2LeCaO6z+UCKt+4Ee7kwdLWwQJLxlVvOG 7U1RxyclF+uugvdGGN/YPtGGidqDOU8d2gyBEbSNMUr4Ssi2p4PJrUwU1b1qahVBEAI1 OS9xKUUrMb/tIfgqQ2mHWzsLNo41mz1AQ/dMqIElpE2yGHxETatxNDGso6uiYufz1PMR 2Bdn0PpBQFjqzLxPTRCOYGIFq0u1eYWGQEyRXNG78SBM6qlL5DTJ40mih7eS2ESNBo/x OmvhIBCGEKb0Igh0DlsONJDfstDXaZACgq8c5z9yaGttiFBpYUypWYNpuqKPlS4APrrW 4XRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=a4jx8KNt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i67si9874470ybi.220.2020.09.13.17.02.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 13 Sep 2020 17:02:17 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=a4jx8KNt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHbwm-0002bk-HQ for patch@linaro.org; Sun, 13 Sep 2020 20:02:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43530) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHbwZ-0002Y9-35 for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:03 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]:36394) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHbwW-0004Bl-QZ for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:02 -0400 Received: by mail-pg1-x530.google.com with SMTP id f2so8059297pgd.3 for ; Sun, 13 Sep 2020 17:02:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O5tftEr4wcy+EcfeUo13CTd2wMJ9pZ9l7p7m81TmeOA=; b=a4jx8KNtbPTtoVGXQhAkL61kwJ/+cCW577j+6XALCPm4TfyPNmIBEnol5PMTaZ/8Fe TBCkRYp52Et7uZNMb/Bm4YCsRvnUDJgfD78RWC0EyYp/CozSZH7uYpfH97CKwYgu9RAM 5sg6D1QP95zzbYLiyEcnHccaT7WVtsNp6RJfHjNqQaikPiJNfIL0lCB0l4Ri22zWXIrK Q31naU314Lga14bIcpsfuLyHEQYmwmRfPNhQBzZ0JCz7ODt/N+exrKFNhsMABgE46YY7 reE8DetEZz0C2ZHmPyerlgoj+draJxhljEJmm6VEkcmTbIaaPQ+mrXqVXUT1s+6oeSNV EDIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O5tftEr4wcy+EcfeUo13CTd2wMJ9pZ9l7p7m81TmeOA=; b=s9EwnesMr6UFoMFQ3afWx52d/HeFz0oBC4WG8wkq64CBXuNgMtA6mASUfOucb//4iZ fpTwp1OPGgWm+CvJOciSxvXYKNPiQgaJ53X1f2ph8ne1+9/XIIxtzCyWf1g9BHJhjg76 xw06b8FYeIAF4YaMvTZqcUTTmWgNINA4hjD+gVUFxH/Q5ryGUpeOiSn7TwnWjP7XlvL4 SX/Yt84xZN6iNtQbH3KUXbnfjR4zDpDC+ACwir/+eXvareDrXICkfErsVWuCil0r22i4 6MT9M11qiz1eah9p2GHB8JTyCkID0CDtyz94rtyZ2GT3aDsCgXu+JtX4TNfwLMERGvtv dXVw== X-Gm-Message-State: AOAM531ZO+FpsgaALISTT9ceecvhADVtJ9uYjesjwCq9xY6/FT/Cr8Vs Cz/FM5URLZPPau+wyzSPhjU4MHEu4pWT7g== X-Received: by 2002:a17:902:8605:b029:d0:cbe1:e773 with SMTP id f5-20020a1709028605b02900d0cbe1e773mr12522978plo.26.1600041719103; Sun, 13 Sep 2020 17:01:59 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id 31sm6538252pgs.59.2020.09.13.17.01.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Sep 2020 17:01:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 03/11] disas: Move host asm annotations to tb_gen_code Date: Sun, 13 Sep 2020 17:01:45 -0700 Message-Id: <20200914000153.1725632-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914000153.1725632-1-richard.henderson@linaro.org> References: <20200914000153.1725632-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x530.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.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. Signed-off-by: Richard Henderson --- include/disas/disas.h | 2 +- include/exec/log.h | 4 ++-- accel/tcg/translate-all.c | 24 +++++++++++++++--------- disas.c | 29 +++++++++-------------------- tcg/tcg.c | 4 ++-- 5 files changed, 29 insertions(+), 34 deletions(-) -- 2.25.1 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 14 00:01:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 249752 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1202183ilg; Sun, 13 Sep 2020 17:07:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXdVy4najpmWtLiumWE3Y+0NT4j5vymxHQP9wbXGT9l8W6CrVhsJHJWNFNUN/P98m8+nvo X-Received: by 2002:a25:3f81:: with SMTP id m123mr16236144yba.197.1600042029672; Sun, 13 Sep 2020 17:07:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600042029; cv=none; d=google.com; s=arc-20160816; b=kKdv9nWLkApF92TtmtXKOuSwlnhZUt6t5L6A7gdOq6JH1yUD+f7YPyfnyWfmHw4+KH aND8XnbWJBljcbA6UgmBkq1kqYCtNJ83t0vhhsSrv56YlptyFiWUtTvq1gZuAAj+U2Fm wRZTKMJtEIV83MI+1w8EkGFNMfYOPJu+mThCxLmPIXqdJoaHD0thOQHZ1uklIDwyYf0T 5tfC+pbEw76N2yqRo+m8ydlD03cSHAOq07oEDOsnI0WcOhivOgYDEnR/C09/4KXvrZRp RjVYdtcq2sbaDZrJB7N4pY9BgzyOfEB49en3pLHEi9TxLQ+rk9y2zhbgp1aD9L+0Pq0k zxOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=9Q9iyS4+070kw5nQFpfTmG4IVebUEHcY0984nv5bR9Y=; b=JmXOaP6zfI1Jw6N83PNU7ynhx8Baipn85T59yds2zUS0qb7DRPpRK7IAoRvZ/peJ63 IZzfjgtcPeqzpGM8KCNhni+Uz8MI7rWHGedX62O/uLCGiAlk7cEZWS9bOM2paRFA3mKt ZTrWDdvqkXsyFx7XoKLk6wa9z5Leg3Wfg62w8wimYB4bxpygQbJXQBkhw6VG+/7l4/+o 34WMj18nVIop8kNFmBnLwGWTiy1zBnE2nQaq+yhtIPRSmWh0QqRhGnhQnGd4KLustVSU +yeU1Jwc+6ulInjIIjLa/E9JSDP9UsCh/3ZXl+enw5xcTdcBDj3hZsvnCK7xvYnv4bjR O/XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Cp9hRogr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y2si1346588ybn.217.2020.09.13.17.07.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 13 Sep 2020 17:07:09 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Cp9hRogr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45478 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHc1V-0001Bp-4F for patch@linaro.org; Sun, 13 Sep 2020 20:07:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHbwc-0002eX-Jl for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:06 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:39190) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHbwY-0004Bz-NY for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:06 -0400 Received: by mail-pg1-x532.google.com with SMTP id d13so1849711pgl.6 for ; Sun, 13 Sep 2020 17:02:02 -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=9Q9iyS4+070kw5nQFpfTmG4IVebUEHcY0984nv5bR9Y=; b=Cp9hRogrZuLzluRG810fLmYeLx3KV/Gr8QdQYPFoVofiDjwoUEEjtEVFtKYMJt9TAW 1xsvfM18s1M/U/RPdD18tP4+TX7W+rrF9glFasNI1pMaJsxBrQb/nGWnpafCohcjxUPC EMuHo5s709nLYHd3PARC36XrvhJg3HX7TA3H4unCkxFT60Tdpj+2AiuWp4RjkaH+J5aI JikcRLPqJ4U8w/gshtrYzV1NRot/aLT7CbNGA3Gbo82978hvOzXbaYHCRlPIH5Mh0nvi dyGcmg/SuGMZxj37FZsEY1vjMrpazQyLVKWwGdCLH9IHYMqjRQHP4znwFcU+djRXJ2Vd jZ4Q== 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=9Q9iyS4+070kw5nQFpfTmG4IVebUEHcY0984nv5bR9Y=; b=qmMsS75ukrpmd22AiGJcdTzXRChZ8mn0tKdTMiddZe0HXJ8dkdPPscb/rQYsOlDpbx Y4b9yqtQNCnJL/XK8ZZ+QJhXfwYeWkDu23TfPEQQXYwNg4u+SqN8Nw4VSbDZE7mtZBJb eHSfo8SFaOW661EoKOIkooAz2X39m6ZLn3Mj/fFJfMasjnjfrNbJmx238Y4c+MWyh04w IH1Cjkch+OZNiqT4My+ELJ63r3W3zfaDyQyahavS0UkKnD8UJvthMftYeK7h/Egics9M 8kV3po1jpaTy8vSA0l6MujhCqh0n7yiX4MhFoiB82cNYzdfvdoS3QGTpwbw7IcCgdDTR Wc5w== X-Gm-Message-State: AOAM5319LhrP7s/PNdrA227bDOk0cJsURVGd3PWAiogoQZqZkEguVp4U l6yL3l7max+K6hSLQBMKwzoiyC3zs9zxyA== X-Received: by 2002:a63:485c:: with SMTP id x28mr9173603pgk.289.1600041720332; Sun, 13 Sep 2020 17:02:00 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id 31sm6538252pgs.59.2020.09.13.17.01.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Sep 2020 17:01:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 04/11] disas: Clean up CPUDebug initialization Date: Sun, 13 Sep 2020 17:01:46 -0700 Message-Id: <20200914000153.1725632-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914000153.1725632-1-richard.henderson@linaro.org> References: <20200914000153.1725632-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x532.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_PDS_OTHER_BAD_TLD=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Rename buffer_read_memory to host_read_memory. Make a bunch of functions static that are not used outside this file. Replace INIT_DISASSEMBLE_INFO with a trio of functions. Signed-off-by: Richard Henderson --- include/disas/dis-asm.h | 60 -------- disas.c | 323 +++++++++++++++++++--------------------- 2 files changed, 150 insertions(+), 233 deletions(-) -- 2.25.1 diff --git a/include/disas/dis-asm.h b/include/disas/dis-asm.h index 9856bf7921..d2418c977e 100644 --- a/include/disas/dis-asm.h +++ b/include/disas/dis-asm.h @@ -461,67 +461,7 @@ int print_insn_riscv32 (bfd_vma, disassemble_info*); int print_insn_riscv64 (bfd_vma, disassemble_info*); int print_insn_rx(bfd_vma, disassemble_info *); -#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..50b5677930 100644 --- a/disas.c +++ b/disas.c @@ -16,75 +16,70 @@ 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) +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 the address is hex. This is included for completeness even + * though both GDB and objdump provide their own (to print symbolic + * addresses). + */ +static void generic_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 generic_print_host_address(bfd_vma addr, + struct disassemble_info *info) { - uint64_t mask = ~0ULL >> (64 - (sizeof(void *) * 8)); - generic_print_address(addr & mask, info); + generic_print_address((uintptr_t)addr, info); } /* Just return the given address. */ -int +static int generic_symbol_at_address (bfd_vma addr, struct disassemble_info *info) { return 1; @@ -423,36 +418,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 = generic_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 = generic_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 = generic_print_host_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 +615,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 +651,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 +713,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 14 00:01:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 249746 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1199175ilg; Sun, 13 Sep 2020 17:02:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuNYMk0rgxfdt4kGnZPiEPY6rlmBdGBJdaujVg67tzii2jBSnd0TICfhwjWGRYGYA9mwHz X-Received: by 2002:a25:21c5:: with SMTP id h188mr17572970ybh.37.1600041738098; Sun, 13 Sep 2020 17:02:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600041738; cv=none; d=google.com; s=arc-20160816; b=BUrXLpeDnRkF2RPMz+l1Hx2szX02QOEV/zgETrS0dx447fZY7xI8TaAmjMnhKZd0/H Rf3vkcgxELyXK+epb24bPafM5HpShDX5w/4FxVMxjk1eFLyXbfHsjbF1Sa2Yi3n9bJPv 6q50y5T/OH46+dnwSHdjEDZeZ5w/z/blKC9NQRTs3JJaPGm0TMBepp5+8U2YOZN0U+wE s9ROJQPx2YDzWMjpohRQulWPW7yUANu9bd0RmE5Va1JO/ebA3bKwhAmi7zesI7nCsaDC tMtEj2rTBESoOc3eU+B1VNbINpkAA2cv1aK2hYblXosY6cf91BZMwNbjLVFfFS5Hfkw9 wqVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=9uEhRDQbPBvpSG5xc2pJjbxBlGNp1Es5E3WFmyWYEgg=; b=Q1zMvG9S08nWIiKAPy7wlCB4EjCmQaDjb37rQcQLHlMQeVNlCUQsqs7NHX5L8udlIu 2Dac+xlWIvlmdgckuNR2JYCpS92JbA84oCdDeo60I+t9yl8Tcpi0eEb8+R7FxJJ+000J IMUiOEkES0zzyGHi59/ynzpITV0jduYo/M+8FVIxPGQYpy0WlfYgVZuhMj4wicxp6Ups wr3WyJRxHvg92uggknrA0OTIBgqWfC9bifw6WKdsrGKRt2x1rc9Ad2MEyUBA6piqMHhh 91tQpsCFFoobkMtAhgaSKFu9NuGz38e02YWYYiP0F7+hevkgNShzc0NunWXONzZuENeQ UoMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=vrw+7R58; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l65si9181653ybl.97.2020.09.13.17.02.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 13 Sep 2020 17:02:18 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=vrw+7R58; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHbwn-0002eH-G8 for patch@linaro.org; Sun, 13 Sep 2020 20:02:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43556) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHbwb-0002bg-6D for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:05 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:33971) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHbwZ-0004C4-Av for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:04 -0400 Received: by mail-pj1-x1043.google.com with SMTP id s14so418837pju.1 for ; Sun, 13 Sep 2020 17:02:02 -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=9uEhRDQbPBvpSG5xc2pJjbxBlGNp1Es5E3WFmyWYEgg=; b=vrw+7R58kQ5LK4jlxQL0MS/fmlg++1IqtaK293e8p3GYKqLWMTXNbUpZSkQjn4pFTi WtLnwHeufF/paKi7S2P2s7mE5uwds/VdVXj7A5gEpkFPvv09ogeiiDo4k02rGWUB+JYc 2wDrcMkOh4f7MmE79HVCi1O/sTkhWphooGyMS4MCpXvEtXpgHo6/KYB6K279l/1cCSSp oifxrv2hAuiGwwVKl1GjJVAsGrHE4KIUkq2Cao27+iRN6zou+vTbjCsE08E9Om0J6kQf 5i5BEOnGY5XI5NE2Fub1ahGaLVRRctvJ3uZkx4QwqkI2drI2WiGebrkEDMR1UKNj8Qqv sklw== 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=9uEhRDQbPBvpSG5xc2pJjbxBlGNp1Es5E3WFmyWYEgg=; b=oE3XHveCkctfF0CmctVZn1kFOHHbDYjo9JHSznl4YDwCQ2snI5QrZyVM2N7Ja1k+d8 WezHJX+NxH2YmxLbfjxmH8bY8b0QUrrMvoVryHyfu0zU3PxLStoIgu1T2i1LWUsRFAj+ LkQGtdOudihyPxKYZGbBeTwwgHyjaBzIPC6wKYxU8euqMRP9qwN205At+NkxsLZd2JLl p4wwhWuZE1w0qi/BTjO8PZMCpPAVFnbcYkPc95tndl7NW7fngoK3rVbZjMN47YkZOrrs 9EtXejZK7a66cwa/ha7zhRfXi1cMF2WVa1BNXmxWIDNnaNNDGwo/mP5W3z87aPEMYv+m xpIQ== X-Gm-Message-State: AOAM530lf+pSbtqIsPiyC+sb3U4TPiq6FjTPxz5G+Hf75P1crQTglQLB TM9UYNB/PHyjKAIbROpj8/vAJvzfIz78SQ== X-Received: by 2002:a17:90a:6a4e:: with SMTP id d14mr11001888pjm.63.1600041721573; Sun, 13 Sep 2020 17:02:01 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id 31sm6538252pgs.59.2020.09.13.17.02.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Sep 2020 17:02:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 05/11] disas: Use qemu/bswap.h for bfd endian loads Date: Sun, 13 Sep 2020 17:01:47 -0700 Message-Id: <20200914000153.1725632-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914000153.1725632-1-richard.henderson@linaro.org> References: <20200914000153.1725632-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: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use the routines we have already instead of open-coding. Signed-off-by: Richard Henderson --- include/disas/dis-asm.h | 32 ++++++++++++++++++++---- disas.c | 55 ----------------------------------------- 2 files changed, 27 insertions(+), 60 deletions(-) -- 2.25.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/include/disas/dis-asm.h b/include/disas/dis-asm.h index d2418c977e..8a216ac495 100644 --- a/include/disas/dis-asm.h +++ b/include/disas/dis-asm.h @@ -468,11 +468,33 @@ int print_insn_rx(bfd_vma, disassemble_info *); /* 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 50b5677930..20fad6aabb 100644 --- a/disas.c +++ b/disas.c @@ -85,61 +85,6 @@ generic_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 14 00:01:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 249753 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1202837ilg; Sun, 13 Sep 2020 17:08:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxROxyPyUP7CW4yRzVHO3VOrwY16Kq+a+Wa04TDcMbx6HNqiQ/xDT4CuRewJo8EfGe/1EY1 X-Received: by 2002:ac8:1adb:: with SMTP id h27mr7207632qtk.250.1600042096575; Sun, 13 Sep 2020 17:08:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600042096; cv=none; d=google.com; s=arc-20160816; b=bmducfk/HQFwU4DjujUnaobo4fO3W/RYR4AUHHhLvZlCn17edkt/PIM+OvPHxd07EF Xq2zNckOA0FM6/m7EEI85/NqR2+9tdzjiHwtWNWnex/5ONsdC020fF3u3uHbLTQBMrol prKQojgs6L+BjQeFhWom4CxSssWl+R7LlQcMe2hCMy0IcgW6C/EWou2uSt/hD1e+Vy9k CyK+vMgDlchhnRWObESkZTRcUrc5EfzQDgQf88UC4mKw8Qp3da+nO1GbgJaux/pFV4mm q9wm7xUFCwmJZlKnU9lvevNLKPrVKasgRmDIJKoZ7ufhHQ2EBE77ajBBvBRZx1/+oata wDhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=inMfli2pDbU3kA4lojjL53bmShI2QMyc74Hc7w0ZLmA=; b=kvJ2Ov3sLEhvWp7whdGujKY3euQAuDQ+yiNZAcYaIEygZckD/emHo77MnZJpOQmyWN GxvXX0/7uI6VrN3zcWKdYsfWUL9YTZbzVH5d/AmghFpjWIrDg7YV9pl9gX4hTt5i/IRa jQb1CrYsdhIdc9bvImRiYjzWF+p7BBJHsBavuTf+zQXqXqR9EzW5iz509r4var53bzDn IDhOaGrxoFJDwIbvp5Mg88GQAyd3gdU5HRpqvqQX9tTjjLj4db5GRdenJ71H6klGpRw/ 7h3s8bbYATueEZ6fwfVHcauiZ97fPj2eWE/wBw+P7JU8e4KAU6EAF/bYzUg2LV4rWE8N kaJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PA8dBs8A; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g43si5929080qtc.78.2020.09.13.17.08.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 13 Sep 2020 17:08:16 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PA8dBs8A; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHc2a-000278-4D for patch@linaro.org; Sun, 13 Sep 2020 20:08:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43580) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHbwc-0002fC-UR for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:06 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:46127) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHbwa-0004CB-FQ for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:06 -0400 Received: by mail-pg1-x541.google.com with SMTP id 34so10058826pgo.13 for ; Sun, 13 Sep 2020 17:02:04 -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=inMfli2pDbU3kA4lojjL53bmShI2QMyc74Hc7w0ZLmA=; b=PA8dBs8AR+0g73MQhP0H29Dw0WnCWu1lFOGv5y8V9rbotwTNmZPNczXYCg1fCgvYvL 4V9XU7BJw4J1THaMWJr15wMis8Hg2LkQ2oSoD1sBdIE33TkmE0YI1J/9BBjaxdkaLhGJ acZ5VnGot+swtU76I431Fc/zP6MYx8MAKTsUwiZLHjZoT3YKCi9MHO0Wkk7pPp/u4oTQ amzR7OtNLwREWll2BYB/5ztch7BTvEv+tlmlhYcT6FMhd2PC6U0qyPtd/iU7m8PeqtsM +w23+9b7g8rDN8gOdmGRIu1kgsfaWp/Nh55HumyNEMGRdNNyzlGfsq/m89gE3ckkfHIW Z+tA== 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=inMfli2pDbU3kA4lojjL53bmShI2QMyc74Hc7w0ZLmA=; b=qJXdQX06rSdEg84TCHnkf5mrMQFL4PlqmV36Tihnru43wZ1wnYkZTDwTlVwRlQdT73 zLUF4UNHosTPRqNzqOlj6oN5DEVYV5Aby24qfm/a48whvjd8C4OkZp/LACV8gTDMa5Nb D04S4w9zject3C51bT3MzeEk6nAFDL/u418GLQ1bYPHBhE7Na2k12VVMB5AsO4427OSL 5Dx5K2HqRMTh5Ee2V+jQLokpc8cgIJX04QMCNReb3dMFRsrLsf0BKvUQPloUbSO52+8I YcVVjnSdhj7pnfHVc4246i3vbrbEPdx+jmTqyOu+JYqP1ebW0oR99oni4f8E3s2wRV4n CADg== X-Gm-Message-State: AOAM5314hRX54EE6pdI93nBceDD/MVx7ZmhhdFzJIcURyvwdCWpOrgYQ apnsDmM/BC22J48voISBiwcAObg+LwRKhA== X-Received: by 2002:a63:1925:: with SMTP id z37mr1984764pgl.23.1600041722760; Sun, 13 Sep 2020 17:02:02 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id 31sm6538252pgs.59.2020.09.13.17.02.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Sep 2020 17:02:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 06/11] disas: Cleanup plugin_disas Date: Sun, 13 Sep 2020 17:01:48 -0700 Message-Id: <20200914000153.1725632-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914000153.1725632-1-richard.henderson@linaro.org> References: <20200914000153.1725632-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, T_PDS_OTHER_BAD_TLD=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.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 --- disas.c | 55 +++++++++++++++++++------------------------------------ 1 file changed, 19 insertions(+), 36 deletions(-) -- 2.25.1 diff --git a/disas.c b/disas.c index 20fad6aabb..ed9965c32f 100644 --- a/disas.c +++ b/disas.c @@ -498,13 +498,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); @@ -524,28 +523,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); @@ -560,34 +551,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 14 00:01:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 249748 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1199981ilg; Sun, 13 Sep 2020 17:03:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZ+/2izV6JBOzHLVMLMnIYwW9il5DjP/CFnUkqNX9Os1FHq3ne9zO80qXDc+A0nSyxjKLN X-Received: by 2002:ae9:ebcf:: with SMTP id b198mr10561153qkg.488.1600041809148; Sun, 13 Sep 2020 17:03:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600041809; cv=none; d=google.com; s=arc-20160816; b=ESIqPpLljiKnMMnLVGoNALzAo8lgVpNX3Io02RhEtA6HSzmftOmeAlKa7SCaHX56iG Jyvv6QW7Bx+XIqhWNIy9aEXo13NyPE7/piPp3bzZr3kDMhVY0+09vGy4Tx6nwRG7O0EZ TjEFdMz8AHjADIh2QUHQ8jmQoXtzA5cMMRLVfd2oPDcZgW9U41tMQ8f7OTEx26bQUuOv GnkyKKbD0GC+filaKuGpWxTV3CFtmW/AfXAdPxXlHziqFZzxcbx01vUk+j5YhmX+YUou pMww+MEFapqKzWwc52uH/Zmz3Xfkn7IAjpilVcHuhusmzQXSdCWvKfGqzbWwZm3swLDW 1lbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=vOtHj+mVdsMkoT/WjxFe7ZI43yFPE5uJFgaFbrClmPo=; b=bptITniJ7IcIynrSPNCTf90/sLTC7hr3+A6VyJTIegLWtJXyIDswjf2KjpVMKcxBH/ fl7ATYQMD8tljLhcD6/2knGH2wXXpQuWfayKW/RvEo+NJonAEMNWSp7gOq0Cvj3Zo6zh HagLNSzBrBb0yDEDQCHvSb2DWvHE1ilm7A6peMAiSufoFsYVTVH1MQgVvOsbSiCtHxAG k4kQYEPD1sRZSgI97LIeHf0FH+i26wcm0A+BgyXYnGmb4jT2vtorruYafDXXBW73JejK JmZWNdcc8QE5kaopxRq1390Em3OpFFDpQ/hLM8TORCYcc0dbLfk4WanT93ZPjBJgkSUj njJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=pXi7CPLT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 69si5610385qkg.328.2020.09.13.17.03.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 13 Sep 2020 17:03:29 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=pXi7CPLT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:35262 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHbxw-0005P7-Nt for patch@linaro.org; Sun, 13 Sep 2020 20:03:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHbwd-0002gR-Ic for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:07 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:40178) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHbwb-0004CI-GK for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:07 -0400 Received: by mail-pf1-x442.google.com with SMTP id x123so11045235pfc.7 for ; Sun, 13 Sep 2020 17:02:05 -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=vOtHj+mVdsMkoT/WjxFe7ZI43yFPE5uJFgaFbrClmPo=; b=pXi7CPLTSfaRbijb3DyVLi0XCPaUG2ZAo6g3rjE6hIqv9sFcdfZfrKM8wl9Jq0i+28 H/4dSkJFa54x7fBIUaXiSeqca2/Q0ZuyixblBiAPoKNwTIysBRWLl27jTTc1WQWeSeUA H7QTVql1vd3/v3sXrDrfTzukImuu1wmdPkzVkZSdrOzyXXtEJAVoe/suhuaInV2wQaAx n4FP5aY0VWbcjVsVFOzdLgpP4kpueCpSYAWGVdYTutnmfnh55wMoMIMxEiHfy5OM0FZc zVJOCKTsk7eLlm4CFBAdtFvfDASYA7uey5Ke558jfML7l6igRdHB2++tSTIJ1i+WIzfu FqyQ== 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=vOtHj+mVdsMkoT/WjxFe7ZI43yFPE5uJFgaFbrClmPo=; b=Ib51IW20Knmzyg0xw4c4o/VCAep8qcd5z+97QXGkC1LH4GSftNHLuO0ESkz1adB8UF 7fghfgvVUa4mHMBoCYQ4XlfgZ2IfKLHPTQc1ByvVWulNK7QxlLHtSsKsHgEGdapobEHM MvBhge7eKSbKrQGsOdDCEjJmMXqhJin5wX9ePioTGFYl87tVXyc4ZQ1QgBiHjhsnt9hO BObVki2f5OK2MxebQXlhRFiYd6NncDw2+IXaBD3n5mKz7GVDfTJtuZ997sTkoN1cOIup iYoGI20o0tpF8jATLASjR1jKDGbYxsz4pBjAh7sV96puK2qoTnsxWH/108Qc4szgWgYM dN5w== X-Gm-Message-State: AOAM53257hFcwSBaCDi85eX1Y79HeCAHWtJqv2X5R9/jBndOe1sbIWdt vL9t76mDZGzqAThPXz74E9grnxWvmeY/vg== X-Received: by 2002:a17:902:7c84:: with SMTP id y4mr7571775pll.97.1600041723952; Sun, 13 Sep 2020 17:02:03 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id 31sm6538252pgs.59.2020.09.13.17.02.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Sep 2020 17:02:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 07/11] disas: Configure capstone for aarch64 host without libvixl Date: Sun, 13 Sep 2020 17:01:49 -0700 Message-Id: <20200914000153.1725632-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914000153.1725632-1-richard.henderson@linaro.org> References: <20200914000153.1725632-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::442; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.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). Signed-off-by: Richard Henderson --- disas.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) -- 2.25.1 diff --git a/disas.c b/disas.c index ed9965c32f..5d81403125 100644 --- a/disas.c +++ b/disas.c @@ -435,9 +435,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 14 00:01:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 249754 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1203310ilg; Sun, 13 Sep 2020 17:09:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpipWzoAIlWyfpV3tbz9vpubIAp9gHGUS1+/pLZAzI5WtWQJQ4eEmo9NwRet4jvAuGtWVF X-Received: by 2002:ac8:3fee:: with SMTP id v43mr10969507qtk.192.1600042144731; Sun, 13 Sep 2020 17:09:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600042144; cv=none; d=google.com; s=arc-20160816; b=WbCSgNWmMzY6L43qLLTgtpD41wQrttplA4L3kSkDn5qQSfmovzzjTQVXwFD2XyhSE1 BCX1hG0dT5c6jyQZgQkza+lTJP/FtQrtAsbMN5OiMVU+XLsj//IWs9XbRgT6KfwVXEzs OUFvFA0rDmuxrZemgKCTaabDdKB8Qg9Gpxky3OrlmeMvRRmR7iaLMEDDOYJ4r/dUKB0B Ju2VVmyRvgknyJvoeq23Axx+2cQuWqiq3I7Nea/BXzftO4/E4tSIJ3P28t+6oiHpsCAF LuLySGkGVL5jW59Bfe21nfDlEvSwquC+i8+PAMeS3iR8nZN4juvAV1RubXxQHVZRH4qz ocbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Kk1rx9tJfTiuYmR+n7+//c1oqViMIbACaS0IvOQjK38=; b=BQj0mbrq+hSHaYhvktTP839Ryng5T9SP6I2x5H7oj6ZT2BjaXQW0jvlRE16Wtr6Wbj M/TX0vHpYvVOpGK4fSlnmVz7tzQQNcn2ZzXCnpTJKXqomJ+8Mlpbn+KgCw5XUsamGAqt TNjDJY7oVa2bPW0s2c/uoSyvYXVcegCFfr1CyulZyYy7v0WZV9Cc4iXS92oZdthc/jf6 /w0fQzqj5Ec6+CMUcrjewfenn4y464NWNQyMwkc/RuVowX9kuhUO7f3cGgYqUgX3hNnb Jv7AmCRhSFuImPAnnTczwoX0hugbpY20EmYpwMxHiuELbRXooOVfkf4lWDiRJUU0MsdN Najw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=oUDe8Dxi; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w18si5438469qvs.205.2020.09.13.17.09.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 13 Sep 2020 17:09:04 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=oUDe8Dxi; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHc3M-0003IC-7p for patch@linaro.org; Sun, 13 Sep 2020 20:09:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHbwh-0002qH-64 for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:11 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:41143) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHbwd-0004CR-3T for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:10 -0400 Received: by mail-pf1-x444.google.com with SMTP id z19so11036828pfn.8 for ; Sun, 13 Sep 2020 17:02:06 -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=Kk1rx9tJfTiuYmR+n7+//c1oqViMIbACaS0IvOQjK38=; b=oUDe8Dxi8JKOkP64TIjUNWEj5mlfxr3Q3sP1KyGVKdwBjJ7CdLI2zHcDQyw2HOEf3I HhOEoCGrdUOswY4HEklh1Qy4JqyF1ZC+y7NdCI+h173akntRjxo4A0XZHaE8uzQb0uNg Q7UP45CVD7WJ/txpGHPpbaGTlmGzhS2vO1lyapR0i4bCsAVe4pOmqKeZb65xDKAEH2yA 0tpx0sJ6TFm4Axq/YmKArRaeQ4Sj/dq8/12DnHrKvMUcbJ4CLhPM9C/c+t8CwTizUddQ Bl63pYtU+TfN6CNt+D7ozPAYK6z1mSn2AlmZ+/V3hlO2diV6pJyuK84teqnMEjzmS6kP 1TNw== 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=Kk1rx9tJfTiuYmR+n7+//c1oqViMIbACaS0IvOQjK38=; b=nh+cggkjYuhO59pz7ZOPo+jCc+vBS/MFbh0I+2WeAZK1j6oyHApEcTtwHNEK8/R0pB v7E4T7oHpZlZ9tJ0WL5Dh5kuZAPb7V2CRoa9Z7NnYC91JjSi+ra9ikHQzt9NOtP9zUUr Of9rFEjfLHnfd7GvY994tg4/PYusfI9udMUQ5OKynbKMHu/eKKTAC4CCDJkBd7E7eM4N OPoPvca3jee9tyby3m7ZMyOO/P8Iq6ynHpizSpfP3JCzq2GZL5dvRhztj5mQRWXstnXz afevx7PfROBt3p7UvnYriiHlIXMi+LSJK+yhidu5+8CPnl7MCv1IQZHdrvZbxUwnZSIH 28qg== X-Gm-Message-State: AOAM530Gjc/rA6xGRs+0ELq5+iBX2gbwduynr4Hgn/fDBlRq5fuslnMT 7f0QgPxSHR6ma4iEf7om7WMqVq03iMpwzA== X-Received: by 2002:a17:902:b216:: with SMTP id t22mr12178272plr.35.1600041725071; Sun, 13 Sep 2020 17:02:05 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id 31sm6538252pgs.59.2020.09.13.17.02.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Sep 2020 17:02:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 08/11] disas: Split out capstone code to disas/capstone.c Date: Sun, 13 Sep 2020 17:01:50 -0700 Message-Id: <20200914000153.1725632-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914000153.1725632-1-richard.henderson@linaro.org> References: <20200914000153.1725632-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::444; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.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 --- 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 -- 2.25.1 diff --git a/include/disas/dis-asm.h b/include/disas/dis-asm.h index 8a216ac495..a34837e4db 100644 --- a/include/disas/dis-asm.h +++ b/include/disas/dis-asm.h @@ -461,6 +461,18 @@ int print_insn_riscv32 (bfd_vma, disassemble_info*); int print_insn_riscv64 (bfd_vma, disassemble_info*); int print_insn_rx(bfd_vma, disassemble_info *); +#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)) diff --git a/disas.c b/disas.c index 5d81403125..7fb85bbfa8 100644 --- a/disas.c +++ b/disas.c @@ -114,255 +114,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)); @@ -520,32 +271,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..d682f2d005 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: 'CONFIG_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 00e2b8cc29..4839bdabab 100644 --- a/meson.build +++ b/meson.build @@ -953,6 +953,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 14 00:01:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 249750 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1201024ilg; Sun, 13 Sep 2020 17:05:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgJmWJWFKQbejKA6t7ok088sh89ulsEmBkZLtLTy4qeXmf1L9EPuulfsEopQ/nicq52PoL X-Received: by 2002:a25:6902:: with SMTP id e2mr15782749ybc.30.1600041909333; Sun, 13 Sep 2020 17:05:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600041909; cv=none; d=google.com; s=arc-20160816; b=KpfrVXui+N2ttXws1YtusxEQmfSrIFQ8Iswh8D6Sd3olhotArUqSLIyyC9OcOtaEju rgWVBa8y5Wx4A0fFtYd2JtuZiEog19Vkg4Rw+fmkHl1zhyGczC68uF+LmvsoGNsJ7Vi4 nCrx/ysIdiRjMVIHZOHn+DvmCtOP2qd6r8GMtCuqM/X4SeII91swTy92l2IyVCodbHFI gh80c+WWl6hUTdzXMVSmAHYM07/imXbtVIjkYhKRyAITHgiehkhFmwchDR+eN665/fRO /gIzzZOrG97XNmtyd82eTxD+aOHpjwY+qrPlzVfCYTTmweg2N4DcDRfS4IPv2pjQYCDt KkGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=LokPjQNyghrgWvJ1kJqbWazyHqKRlOm6HdtdDxRh6d4=; b=CvZaMQM8Dm+3wNaCeFJO5K3kxIj+nATfUg3jfO/PZthL2bG2OhUfyMHXbuo2ye0Z/K huVS9/Rs028dpPwq8u5ePKlC2LLq6a0FMZlHV2VbOrmS/P5Iil0dJVtn8wJ10arROXvE LETg8bIdA4pqgKZlfrixtejVXjRvOqbNbImCh0lU52KWSpiT7NYIHShyfAQrJOfxwnuU QSCJ3lxJYMM4IFUaQ3zZnAa7mJ8Hlp49sABWvuqhhf2Q2gBWjXWPljka+13s96uX/SQ5 4Z45QSrBZ71+H6mkxPZwzkyrj9hKSZueNGc+ItV35xxcdbfSQZ9gJBk+zefyp+ky1ouK KyUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Gt1ubhlq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e14si8852021ybk.391.2020.09.13.17.05.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 13 Sep 2020 17:05:09 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Gt1ubhlq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:41506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHbzY-0007tZ-QM for patch@linaro.org; Sun, 13 Sep 2020 20:05:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHbwf-0002nO-Vw for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:10 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:35911) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHbwe-0004Ce-3O for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:09 -0400 Received: by mail-pg1-x543.google.com with SMTP id f2so8059451pgd.3 for ; Sun, 13 Sep 2020 17:02:07 -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=LokPjQNyghrgWvJ1kJqbWazyHqKRlOm6HdtdDxRh6d4=; b=Gt1ubhlqQj/dgrQHS3dAMAJVgPNkILwwnw6vl1cIccdKZtEaMiAnNsrazKoZ3jo7nL pT1sUWK13y+qE1bfexEO7t88PDk5G91WDrbbLr9alPpwuAH6+7dkgWizAsG2IEDFTJ+8 GOVW6Q/bkwzYdeFwLh5Q1VIpOp4xsYP06DCDv/FI9RRkurcbaaQsCkl8RBxdsglUJ3sh 6hjppK3xr43PMXFwSyXFTwIUaawSNQpzHJMqSlmt95dFBtXdZbq+txRhROUwg1Qphq56 uqwbku1rZLef6Aku1w7wqYHcr/QVYQW8Dnp6PeV4pOFLAcfv0kjgKKug3I5nZvD3sbDo /F4g== 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=LokPjQNyghrgWvJ1kJqbWazyHqKRlOm6HdtdDxRh6d4=; b=Fp6SUoLCHTe42rjbMXZ30oDW5bz+O4Yg8f7qTP2vD6nSvVrFG5q9jNpCs7JAIJtd9C goTYG3ed9PPgbqOgXN3Mvyce3uPCFey6URjNgi1QLdQcMWDCpc9I1wSmUR7Rl2o6kIMK O8Uj/6+M9NyHgz9gF0ZxMJitE0CV3AZvSGAzUBkqCqOuhhNNHQS7OvKFOr8EVa+6lKRY j06JlwO3iEIgtQOBFhlwvQ3c6nVEwaYM2XiYWy86A2gIKei/FnAN4p+syOwKh6/GhC3G xW6q6GkBr/5jQxQmqZfc8mjnBhW08KCxL6Yi3odMULG2AURO/qMKj97b/mrmZKb6Nxnw xaHw== X-Gm-Message-State: AOAM532guhP0TURl3VpzWk1Sg+z5rp+uGM0Hn4bA289Pk13KpVLYb26n 3YHRiSwRSSKTG6wYbPKOeFrBE75tSgOFOg== X-Received: by 2002:a17:902:758b:b029:d1:bb0f:25fc with SMTP id j11-20020a170902758bb02900d1bb0f25fcmr8301573pll.40.1600041726466; Sun, 13 Sep 2020 17:02:06 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id 31sm6538252pgs.59.2020.09.13.17.02.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Sep 2020 17:02:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 09/11] disas: Enable capstone disassembly for s390x Date: Sun, 13 Sep 2020 17:01:51 -0700 Message-Id: <20200914000153.1725632-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914000153.1725632-1-richard.henderson@linaro.org> References: <20200914000153.1725632-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: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.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. Signed-off-by: Richard Henderson --- disas.c | 3 +++ target/s390x/cpu.c | 4 ++++ meson.build | 11 +++++++++++ 3 files changed, 18 insertions(+) -- 2.25.1 diff --git a/disas.c b/disas.c index 7fb85bbfa8..5e943181d8 100644 --- a/disas.c +++ b/disas.c @@ -208,6 +208,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 4839bdabab..82cf4a9258 100644 --- a/meson.build +++ b/meson.build @@ -661,6 +661,17 @@ else ) 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 14 00:01:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 249755 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1203711ilg; Sun, 13 Sep 2020 17:09:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdjvLN9CARZQkOXECgWCE7V0jXrkpNK2w8suG7X2IHtp+XYMyh1NiyhGx282F3Kt2M8Q4J X-Received: by 2002:a25:5cf:: with SMTP id 198mr16818497ybf.409.1600042199851; Sun, 13 Sep 2020 17:09:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600042199; cv=none; d=google.com; s=arc-20160816; b=cOICE7Ql7NSRBRXt7F5EOELa2qfTH13DvFcEH/ZZXBMSTaARj+th017r/6oFyLEblG oPeJto0LS0gtoTxZSAmihoitOFOKhvcjNjYJRn/nsFAUFhk/Bc/wC1tFsEVH/RYqkOBT Qzn80QNzfpK5dK8xLRtRNAERqM7OQGVDNS9w7ybiRHOq/9kr860PN3Hh4yijeK7H6QDg ag9VRtDLx9fqEe1lTrNwtT+qwIOc1lLDeK3NQSBz0Kf/XrDvwxMetpazgVT2u5UPWO6a 6EX3CGaXSG4jzcajM17puRLs6XGB1BoVfZ9xSPQxbYKqWTtRN/zaykM3Gfcc1BYpIue8 48iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=FHMdFNxA5DgdfHwVaO5Ocox79qcbsSZjeiufIYJ4nxY=; b=dH5SseIkwQFz56LTSJeIH301hvqrwY4ZUarSrz6cb46DvXfWDlHJwclGdkr82nwu6Q iLAnFIRgoDmmR1Ax+6bBka/nWSpagEfv7OV8vFlvBV1NTFxLwZOyKXBOoh9zl1Ligu/G UgbF+2RYajZ7JJZnJGLHf4kVEtXxdGRcH0PbKP1hCZBGMOUp7w2gMDY/O22AVePdFOQk 4UK6RvrKZmifa/XmcXEHryaq2lQ0QXD6LwrZ+0r2QBEkmp3ZVVEgmIymcIEvT4Nppa9T 8E5yDnD3dL5hlV8b4Gg2nGIdX4K3ItY8mRdG3ARasZLdFsQ7UUT6+468U8a9w3AQdULo er2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ZfVnAuEZ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w8si8734618ybw.299.2020.09.13.17.09.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 13 Sep 2020 17:09:59 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ZfVnAuEZ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:53868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHc4F-0004ap-D9 for patch@linaro.org; Sun, 13 Sep 2020 20:09:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHbwh-0002rR-Jh for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:11 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:43546) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHbwf-0004Cv-Jq for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:11 -0400 Received: by mail-pg1-x543.google.com with SMTP id t14so10060415pgl.10 for ; Sun, 13 Sep 2020 17:02:09 -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=FHMdFNxA5DgdfHwVaO5Ocox79qcbsSZjeiufIYJ4nxY=; b=ZfVnAuEZNFZuQPDiVwW+EdPFbdJntGLKtnjL4Pmw7INWhZy67p0KuaF6q61TALlmIB /jw1W32K042JP20cA0R5GagqbHh/NE5pbEpNdRfP7yi90VCqa7NGXvRWudcLuUozBY/l QGNxZY7G5XVOxOIlUpe0caDrVDT2YxqGOFZ1zlKykDBC4HhiY6wpoa+9bu5q7lNmwCaj ckOjUnifKTjV3f+y2vaIpLDs75IRc26Dl6FbKdD2zZ7bTxa+cWKct1nBXPdRq0iXZv/A 6472h1zZDUx04Ur4WiZwPbTLddbZpnv1vdNkE3xsFhmPyNjF8q+k6hZXHzXsMKHxjbUL 0CIw== 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=FHMdFNxA5DgdfHwVaO5Ocox79qcbsSZjeiufIYJ4nxY=; b=feEokkIZ+XS8g2h40LkuuKC61EWpDblh9lapi1fpOHOo2fRQsZlTZ68La013F8fz67 LzZSC2W5D5Kf7jWyWiEJTTxbcWbS3GFyRMaKui7Uhe5NUGnkZsJ3drD4tDYDtTQgZBXP i3JP3uuvN7km8D7QMjWpjYZ4lJrrM6l5Q+byH083J1Ebv1Yre4qZ3RvD1vNOManKtrpR Bp2FYKP7cnBzkubV19W2i1kbcgXdYUb5q1/LnYLeCJxXEeFv3Jk6T//uC99KghKCdaV9 MqNr0avyIXjuK+SZXPexNaq/AbzcGc8pVpDk/USLITtDF4BbP1BUt2wJ7PHVu3+E8NIE JvPg== X-Gm-Message-State: AOAM533LV/x4sJB3tpImI8I08VDzHg1AkpXW+kmKRxTux21pLPme9q3N PFuY2o6ofmYjut3V8wypJsPMQ0CKgCXeog== X-Received: by 2002:a17:902:8e86:b029:d1:9be4:b49d with SMTP id bg6-20020a1709028e86b02900d19be4b49dmr11920941plb.22.1600041727906; Sun, 13 Sep 2020 17:02:07 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id 31sm6538252pgs.59.2020.09.13.17.02.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Sep 2020 17:02:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 10/11] disas/capstone: Add skipdata hook for s390x Date: Sun, 13 Sep 2020 17:01:52 -0700 Message-Id: <20200914000153.1725632-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914000153.1725632-1-richard.henderson@linaro.org> References: <20200914000153.1725632-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: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.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. Signed-off-by: Richard Henderson --- disas/capstone.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) -- 2.25.1 Reviewed-by: Philippe Mathieu-Daudé 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. */ From patchwork Mon Sep 14 00:01:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 249749 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1200188ilg; Sun, 13 Sep 2020 17:03:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqdyTZ/L7auZywkFyX3DJwzPQdXavUlAPTgd9fm918ErIl2vecu2aiHVyRc1eqnQpmvYD5 X-Received: by 2002:ac8:75d4:: with SMTP id z20mr5771194qtq.370.1600041828303; Sun, 13 Sep 2020 17:03:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600041828; cv=none; d=google.com; s=arc-20160816; b=vmhzCyqNqqniQqYDt/tZdmL8ROLiiOlZLYeCfkwelnIy+3qEKgXEHU8uLO590oBf6R PPcBdJHzv+EeS4Kfpb9DKEMlKXa6DiUTawcKAi9ThHMInIg1nBDQ9nWdaP3Xtr6N4kuk RaymMgQm5Xer+0Aou86eLHCrCkkdPFgfYrvA6ViYR8ZXFhVyaQFqP0cZTpOrKsMVZdRn 9RWUqdTCRYjG/XKmUHzDmeezUvIApmI2dTk2VvcK0V1qyWCvTnVsPDK4cZ49g2h1LUHQ R50uQDltj2BpbIB9UOTX3AgqIbCh5ubOOme9VDwM92t6ehIzYSkndAqHSc2xyoUnssxn zalQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=NCHT5fgIvwDcF4K56DTDB0FLtjYLg/nKnYjeWLy1ICY=; b=UhV19y0ZO0bYmsIZxCRf1fofF3nNNV/EFMQMhadOQZkE3IQ84Xfm9bFdV+pTDv6B97 F2ro4WvL3uht9hwwyTm3Fzasgbx6ShLICF3bO3dVcAo6zc6MaQsrruX0Z6Wagta/kAyb jjqHtJXbrQ2/D1C+8rn1VQSFu/5HqMBs7bod1FaSNG1zb42DV6QOCmpmbJLOlugCUSn5 YnkVYY2yzJEVsnB25pH/12QWfO3FRA9lzQyXBt8psWCQH+bmziTiJ/rrUbxwNiIdo9wc jydpxOdzRgh9N2+8nAnPnMrr3dGapc3lkxCLgwSBa0WB8M9Azw8rGRSR/Ql8uKqymqsc NuUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=STBBIZyc; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t23si6814929qtj.151.2020.09.13.17.03.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 13 Sep 2020 17:03:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=STBBIZyc; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:35296 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHbyF-0005Pr-RR for patch@linaro.org; Sun, 13 Sep 2020 20:03:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHbwi-0002ua-QK for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:12 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]:36341) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHbwg-0004D6-QD for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:12 -0400 Received: by mail-pj1-x1029.google.com with SMTP id b17so4429347pji.1 for ; Sun, 13 Sep 2020 17:02:10 -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=NCHT5fgIvwDcF4K56DTDB0FLtjYLg/nKnYjeWLy1ICY=; b=STBBIZyczgTwCopMTEJOA+ZySjUp1HsoIwsV4GRrmwl1O4A3bNEpjQcKLw4Jji+3nK 19vjthoLnaXP7e5lTFjoIDKwTOUlzug3JGrHpfGAnVRmgicUPgRfoshanPiSkUzAfp7b v6/AgKhJTVayVCLvxaIJqfbMt18/hLHWPMdYJSVvtVvHnYafjLkiu2+F1pzFN/mzPFZi eP9XtzGpFjcxSoVEmbvWA5dYU6XZvxwfzAHWh7RCRwoD8tIsBk2EA3/bTvamuc210Y7t zjThwDfWOpsPb/3MZv9Q2lVVNKzTghdAJmWbndZWRetTY2ph3Y7tU9++S4+S91GXgJqs IOSg== 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=NCHT5fgIvwDcF4K56DTDB0FLtjYLg/nKnYjeWLy1ICY=; b=RDJCdFuIAgZHehOxGrk18zUwfHL8TK8HfJp33Ywt3F33LV0oj89Fv++WpWCvHHm/Mz 1VfcmPRaXkF0F2LIkM2MBf0KlhaPBvNFeWKZtO9GRMTKpgFoWM5npZHPAXk4zYoLhbfC 0Eurlnx89J1B/YEVgpSbTz8+SFWS0zya6bjCWkoLDK/wDsxd6UzVV1RZsEt59ovOHVEe FUuZVt+RznORXZkF0Ar+yEORf7xNK9DfyexJsJnn+0Oqj+r84694D2SOouJfKKVlOX55 AxO/vrQVR3ujZX1Low5CGPEZGriHWIx7Op/o1SPMXTmMCbk7ghPhxGkwsiZXqXDGPWfx o+XA== X-Gm-Message-State: AOAM530bNG8IbKPIvlZfvsLuea1xMCn0hZAEPo5VYWMGA4zCeGI2FQkC 56+E7HYc4n2Up+2saLZvw9ZQnPYwqhWOHw== X-Received: by 2002:a17:90b:a0a:: with SMTP id gg10mr11565237pjb.20.1600041729085; Sun, 13 Sep 2020 17:02:09 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id 31sm6538252pgs.59.2020.09.13.17.02.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Sep 2020 17:02:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 11/11] disas: Enable capstone disassembly for sparc Date: Sun, 13 Sep 2020 17:01:53 -0700 Message-Id: <20200914000153.1725632-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914000153.1725632-1-richard.henderson@linaro.org> References: <20200914000153.1725632-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- disas.c | 2 ++ target/sparc/cpu.c | 4 ++++ meson.build | 10 ++++++++++ 3 files changed, 16 insertions(+) -- 2.25.1 Tested-by: Philippe Mathieu-Daudé diff --git a/disas.c b/disas.c index 5e943181d8..b71d06d890 100644 --- a/disas.c +++ b/disas.c @@ -196,6 +196,8 @@ static void initialize_debug_host(CPUDebug *s) #elif defined(__sparc__) s->info.print_insn = print_insn_sparc; s->info.mach = bfd_mach_sparc_v9b; + s->info.cap_arch = CS_ARCH_SPARC; + s->info.cap_mode = CS_MODE_V9; #elif defined(__arm__) /* TCG only generates code for arm mode. */ s->info.print_insn = print_insn_arm; diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c index cf21efd85f..e0b0a88d26 100644 --- a/target/sparc/cpu.c +++ b/target/sparc/cpu.c @@ -25,6 +25,8 @@ #include "exec/exec-all.h" #include "hw/qdev-properties.h" #include "qapi/visitor.h" +#include "disas/capstone.h" + //#define DEBUG_FEATURES @@ -100,8 +102,10 @@ static bool sparc_cpu_exec_interrupt(CPUState *cs, int interrupt_request) static void cpu_sparc_disas_set_info(CPUState *cpu, disassemble_info *info) { info->print_insn = print_insn_sparc; + info->cap_arch = CS_ARCH_SPARC; #ifdef TARGET_SPARC64 info->mach = bfd_mach_sparc_v9b; + info->cap_mode = CS_MODE_V9; #endif } diff --git a/meson.build b/meson.build index 82cf4a9258..b1c54024ac 100644 --- a/meson.build +++ b/meson.build @@ -661,6 +661,16 @@ else ) endif + if 'CONFIG_SPARC_DIS' in config_all_disas + capstone_data.set('CAPSTONE_HAS_SPARC', '1') + capstone_files += files( + 'capstone/arch/Sparc/SparcDisassembler.c', + 'capstone/arch/Sparc/SparcInstPrinter.c', + 'capstone/arch/Sparc/SparcMapping.c', + 'capstone/arch/Sparc/SparcModule.c' + ) + endif + if 'CONFIG_S390_DIS' in config_all_disas capstone_data.set('CAPSTONE_HAS_SYSZ', '1') capstone_files += files(