From nobody Tue Apr 30 01:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600041842; cv=none; d=zohomail.com; s=zohoarc; b=NachzzpQVLhsrzltU6fhz4Q9EDy/DzJev3AE5sXivdvyUR/F6LojGi+42BXZb80+tI++NifKatgApgLh2KhGNizGay9TF5CRhpgHKju3fD04QweIZQIHfZV7xVp+HSZ+VJSIhxQw7J7aR8WuRtNJGt9uKw4tJpPprJXAv/S66rU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600041842; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1udUAr8a7IXOV2H9rA8omIwMHcyQUC+GvcI+H0onXWA=; b=JQmjQ5kvgJZ5vy+gJEh+xkzi0XcqphT0XrZ/Xv41BO+luEyWNv+8wtaixB1JCyrstJYR87peQORPx+2mTwcOkoMsfMHWxwAPKdB+CaHyL8Rwkwbgi1nqNZnxS1gkPGm0aN5ACEnh3QPrwdkHB65+sgA/aPoOdy4BTN8+JFf8CvM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600041842634828.6129280892211; Sun, 13 Sep 2020 17:04:02 -0700 (PDT) Received: from localhost ([::1]:37882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHbyT-0006RS-DS for importer@patchew.org; Sun, 13 Sep 2020 20:04:01 -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) 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) 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-Google-Smtp-Source: ABdhPJxwZNNflMubO9tL+ul472twpJwRlhJHLpU9uoUUxbux6A+eJ72GTvjuqkI9AVYEKzI/fXfqAA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" There are better ways to do this, e.g. meson cmake subproject, but that requires cmake 3.7 and some of our CI environments only provide cmake 3.5. Nor can we add a meson.build file to capstone/, because the git submodule would then always report "untracked files". Fixing that would require creating our own branch on the qemu git mirror, at which point we could just as easily create a native meson subproject. 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(-) diff --git a/configure b/configure index 2b6a1196da..4fc5c15283 100755 --- a/configure +++ b/configure @@ -5146,27 +5146,15 @@ case "$capstone" in esac =20 case "$capstone" in - git | internal) + git) if test "$capstone" =3D git; then git_submodules=3D"${git_submodules} capstone" fi - mkdir -p capstone - if test "$mingw32" =3D "yes"; then - LIBCAPSTONE=3Dcapstone.lib - else - LIBCAPSTONE=3Dlibcapstone.a - fi - capstone_libs=3D"-Lcapstone -lcapstone" - capstone_cflags=3D"-I${source_path}/capstone/include" ;; =20 - system) - capstone_libs=3D"$($pkg_config --libs capstone)" - capstone_cflags=3D"$($pkg_config --cflags capstone)" + internal | system | no) ;; =20 - no) - ;; *) error_exit "Unknown state for capstone: $capstone" ;; @@ -7290,8 +7278,6 @@ if test "$ivshmem" =3D "yes" ; then fi if test "$capstone" !=3D "no" ; then echo "CONFIG_CAPSTONE=3Dy" >> $config_host_mak - echo "CAPSTONE_CFLAGS=3D$capstone_cflags" >> $config_host_mak - echo "CAPSTONE_LIBS=3D$capstone_libs" >> $config_host_mak fi if test "$debug_mutex" =3D "yes" ; then echo "CONFIG_DEBUG_MUTEX=3Dy" >> $config_host_mak @@ -7816,9 +7802,6 @@ done # for target in $targets if [ "$fdt" =3D "git" ]; then subdirs=3D"$subdirs dtc" fi -if [ "$capstone" =3D "git" -o "$capstone" =3D "internal" ]; then - subdirs=3D"$subdirs capstone" -fi echo "SUBDIRS=3D$subdirs" >> $config_host_mak if test -n "$LIBCAPSTONE"; then echo "LIBCAPSTONE=3D$LIBCAPSTONE" >> $config_host_mak @@ -8005,7 +7988,8 @@ NINJA=3D${ninja:-$PWD/ninjatool} $meson setup \ -Db_coverage=3D$(if test "$gcov" =3D yes; then echo true; else ech= o false; fi) \ -Dsdl=3D$sdl -Dsdl_image=3D$sdl_image \ -Dvnc=3D$vnc -Dvnc_sasl=3D$vnc_sasl -Dvnc_jpeg=3D$vnc_jpeg -Dvnc_png=3D$v= nc_png \ - -Dgettext=3D$gettext -Dxkbcommon=3D$xkbcommon -Du2f=3D$u2f\ + -Dgettext=3D$gettext -Dxkbcommon=3D$xkbcommon -Du2f=3D$u2f \ + -Dcapstone=3D$capstone \ $cross_arg \ "$PWD" "$source_path" =20 diff --git a/Makefile b/Makefile index 57f72f56c6..0746aa83e3 100644 --- a/Makefile +++ b/Makefile @@ -156,22 +156,6 @@ dtc/all: .git-submodule-status dtc/libfdt dtc/%: .git-submodule-status @mkdir -p $@ =20 -# Overriding CFLAGS causes us to lose defines added in the sub-makefile. -# Not overriding CFLAGS leads to mis-matches between compilation modes. -# Therefore we replicate some of the logic in the sub-makefile. -# Remove all the extra -Warning flags that QEMU uses that Capstone doesn't; -# no need to annoy QEMU developers with such things. -CAP_CFLAGS =3D $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS)) $(CAPSTONE_CFLAGS) -CAP_CFLAGS +=3D -DCAPSTONE_USE_SYS_DYN_MEM -CAP_CFLAGS +=3D -DCAPSTONE_HAS_ARM -CAP_CFLAGS +=3D -DCAPSTONE_HAS_ARM64 -CAP_CFLAGS +=3D -DCAPSTONE_HAS_POWERPC -CAP_CFLAGS +=3D -DCAPSTONE_HAS_X86 - -.PHONY: capstone/all -capstone/all: .git-submodule-status - $(call quiet-command,$(MAKE) -C $(SRC_PATH)/capstone CAPSTONE_SHARED=3Dno= BUILDDIR=3D"$(BUILD_DIR)/capstone" CC=3D"$(CC)" AR=3D"$(AR)" LD=3D"$(LD)" = RANLIB=3D"$(RANLIB)" CFLAGS=3D"$(CAP_CFLAGS)" $(SUBDIR_MAKEFLAGS) $(BUILD_D= IR)/capstone/$(LIBCAPSTONE)) - .PHONY: slirp/all slirp/all: .git-submodule-status $(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp \ diff --git a/meson.build b/meson.build index 690723b470..4417de1e14 100644 --- a/meson.build +++ b/meson.build @@ -415,11 +415,6 @@ if 'CONFIG_USB_LIBUSB' in config_host libusb =3D declare_dependency(compile_args: config_host['LIBUSB_CFLAGS']= .split(), link_args: config_host['LIBUSB_LIBS'].split(= )) endif -capstone =3D not_found -if 'CONFIG_CAPSTONE' in config_host - capstone =3D declare_dependency(compile_args: config_host['CAPSTONE_CFLA= GS'].split(), - link_args: config_host['CAPSTONE_LIBS'].sp= lit()) -endif libpmem =3D not_found if 'CONFIG_LIBPMEM' in config_host libpmem =3D declare_dependency(compile_args: config_host['LIBPMEM_CFLAGS= '].split(), @@ -616,6 +611,90 @@ config_all +=3D { 'CONFIG_ALL': true, } =20 +if get_option('capstone') =3D=3D 'no' + capstone =3D not_found +elif get_option('capstone') =3D=3D 'system' + capstone =3D dependency('capstone', static: enable_static, required: tru= e) +else + capstone_data =3D configuration_data() + capstone_data.set('CAPSTONE_USE_SYS_DYN_MEM', '1') + + capstone_files =3D files( + 'capstone/cs.c', + 'capstone/MCInst.c', + 'capstone/MCInstrDesc.c', + 'capstone/MCRegisterInfo.c', + 'capstone/SStream.c', + 'capstone/utils.c' + ) + + if 'CONFIG_ARM_DIS' in config_all_disas + capstone_data.set('CAPSTONE_HAS_ARM', '1') + capstone_files +=3D files( + 'capstone/arch/ARM/ARMDisassembler.c', + 'capstone/arch/ARM/ARMInstPrinter.c', + 'capstone/arch/ARM/ARMMapping.c', + 'capstone/arch/ARM/ARMModule.c' + ) + endif + + # FIXME: This config entry currently depends on a c++ compiler. + # Which is needed for building libvixl, but not for capstone. + if 'CONFIG_ARM_A64_DIS' in config_all_disas + capstone_data.set('CAPSTONE_HAS_ARM64', '1') + capstone_files +=3D files( + 'capstone/arch/AArch64/AArch64BaseInfo.c', + 'capstone/arch/AArch64/AArch64Disassembler.c', + 'capstone/arch/AArch64/AArch64InstPrinter.c', + 'capstone/arch/AArch64/AArch64Mapping.c', + 'capstone/arch/AArch64/AArch64Module.c' + ) + endif + + if 'CONFIG_PPC_DIS' in config_all_disas + capstone_data.set('CAPSTONE_HAS_POWERPC', '1') + capstone_files +=3D files( + 'capstone/arch/PowerPC/PPCDisassembler.c', + 'capstone/arch/PowerPC/PPCInstPrinter.c', + 'capstone/arch/PowerPC/PPCMapping.c', + 'capstone/arch/PowerPC/PPCModule.c' + ) + endif + + if 'CONFIG_I386_DIS' in config_all_disas + capstone_data.set('CAPSTONE_HAS_X86', 1) + capstone_files +=3D files( + 'capstone/arch/X86/X86Disassembler.c', + 'capstone/arch/X86/X86DisassemblerDecoder.c', + 'capstone/arch/X86/X86ATTInstPrinter.c', + 'capstone/arch/X86/X86IntelInstPrinter.c', + 'capstone/arch/X86/X86Mapping.c', + 'capstone/arch/X86/X86Module.c' + ) + endif + + configure_file(output: 'capstone-defs.h', + configuration: capstone_data) + + capstone_cargs =3D [ + # FIXME: There does not seem to be a way to completely replace the c_a= rgs + # that come from add_project_arguments() -- we can only add to them. + # So: disable all warnings with a big hammer. + '-Wno-error', '-w', + # Include all configuration defines via a header file, which will wind= up + # as a dependency on the object file, and thus changes here will result + # in a rebuild. + '-include', 'capstone-defs.h' + ] + + libcapstone =3D static_library('capstone', + sources: capstone_files, + c_args: capstone_cargs, + include_directories: 'capstone/include') + capstone =3D declare_dependency(link_with: libcapstone, + include_directories: 'capstone/include') +endif + # Generators =20 hxtool =3D 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') --=20 2.25.1 From nobody Tue Apr 30 01:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600041990; cv=none; d=zohomail.com; s=zohoarc; b=hdpqCS1CsOEeJzRkWxY1ZbnHjDiWYAY7RKB41tuqgxN/QMSSnrppdyKWw3e9aNRxNZnI9zvgYOcUwVazoqR0kmZ7snGTxpL9TsI5VUAY/6Ku4+POO4Q3a2K/ErrvAeE2MomHg3RifGKMC8VvOE1bWTm6DeZD429nje38H6qj3qI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600041990; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UsRV3idEmZ+/7qjR3Tg+F66rL9CHGtYoIl+nOlZddzg=; b=KBRIliOc08umSxQWu567gUMXVpLWk+CzG/nef5C0HJcg2QU9LEIX5WXeU5C+iKgcVZJgJAtdmB5y5dIdcvWMb4mQIbmyNb7F1Ho0qs/KSJTzDuf7oWSdX8NCjPQ3VOevDXXWgP+0hnjtaOV7cYNCcvLZ1rHaCfWYqQa0PkKjiFQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600041990876769.2135858840588; Sun, 13 Sep 2020 17:06:30 -0700 (PDT) Received: from localhost ([::1]:43328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHc0r-0000IE-RY for importer@patchew.org; Sun, 13 Sep 2020 20:06:29 -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) 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) 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-Google-Smtp-Source: ABdhPJyZ6mtjEgnGri46aRmccinbdJrIjU28EK7rvV++7PNcKEnbODN/0NxwM34K6v9wxxycNjNSFA== X-Received: by 2002:a63:4cc:: with SMTP id 195mr8937776pge.376.1600041717778; 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::442; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 Tested-by: Philippe Mathieu-Daud=C3=A9 --- capstone | 2 +- meson.build | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/capstone b/capstone index 22ead3e0bf..f8b1b83301 160000 --- a/capstone +++ b/capstone @@ -1 +1 @@ -Subproject commit 22ead3e0bfdb87516656453336160e0a37b066bf +Subproject commit f8b1b833015a4ae47110ed068e0deb7106ced66d diff --git a/meson.build b/meson.build index 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 =3D declare_dependency(link_with: libcapstone, - include_directories: 'capstone/include') + include_directories: 'capstone/include/cap= stone') endif =20 # Generators --=20 2.25.1 From nobody Tue Apr 30 01:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600041778; cv=none; d=zohomail.com; s=zohoarc; b=YAYp8Kvv0innT4jCbQOQrGkgcCFIwR11tbKKlAO5khO+coFmjOAqDEVEeFkK1Jt+G7OKxDoLiTwv0i27oS36XCHKEC7uWF0SAbgyI+MuAmXqYY3iAimy5JesREZPYOoOXLB/gxluoIt5NF+r9HizcU9IX/7fLr1cDZBt4N+dIJY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600041778; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=O5tftEr4wcy+EcfeUo13CTd2wMJ9pZ9l7p7m81TmeOA=; b=ipNPi+HxpX8Fit0rdFsN1shypd/75fV/4rZbA/lv+VRnLx01UJeVfS1Ll8jUdNTXk6/AY8Jfmtbe8XVRTkS18vhhK5j4yzux4zHabN0s3uqZ+gCZ8a+OLarKBwO8RK4Kr7J2R0wIrEzd0BSEBqxOSPWnIn4CPaF7LEawvvOkMmY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600041778441761.7894601380824; Sun, 13 Sep 2020 17:02:58 -0700 (PDT) Received: from localhost ([::1]:60236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHbxQ-00046r-5Y for importer@patchew.org; Sun, 13 Sep 2020 20:02:56 -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) 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) 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-Google-Smtp-Source: ABdhPJzpGKJta5u1QxHiPUyl6EVaj4u9+eeY8CWo/7hJq+oWV2ud3N4elyysPxrhxkM1dzN0CQ1IpA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Instead of creating GStrings and passing them into log_disas, just print the annotations directly in tb_gen_code. Fix the annotations for the slow paths of the TB, after the part implementing the final guest instruction. Signed-off-by: Richard Henderson --- include/disas/disas.h | 2 +- include/exec/log.h | 4 ++-- accel/tcg/translate-all.c | 24 +++++++++++++++--------- disas.c | 29 +++++++++-------------------- tcg/tcg.c | 4 ++-- 5 files changed, 29 insertions(+), 34 deletions(-) diff --git a/include/disas/disas.h b/include/disas/disas.h index 1b6e035e32..36c33f6f19 100644 --- a/include/disas/disas.h +++ b/include/disas/disas.h @@ -7,7 +7,7 @@ #include "cpu.h" =20 /* Disassemble this for me please... (debugging). */ -void disas(FILE *out, void *code, unsigned long size, const char *note); +void disas(FILE *out, void *code, unsigned long size); void target_disas(FILE *out, CPUState *cpu, target_ulong code, target_ulong size); =20 diff --git a/include/exec/log.h b/include/exec/log.h index 3ed797c1c8..fcc7b9e00b 100644 --- a/include/exec/log.h +++ b/include/exec/log.h @@ -56,13 +56,13 @@ static inline void log_target_disas(CPUState *cpu, targ= et_ulong start, rcu_read_unlock(); } =20 -static inline void log_disas(void *code, unsigned long size, const char *n= ote) +static inline void log_disas(void *code, unsigned long size) { QemuLogFile *logfile; rcu_read_lock(); logfile =3D atomic_rcu_read(&qemu_logfile); if (logfile) { - disas(logfile->fd, code, size, note); + disas(logfile->fd, code, size); } rcu_read_unlock(); } diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 2d83013633..2874104a6a 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1815,10 +1815,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu, qemu_log_in_addr_range(tb->pc)) { FILE *logfile =3D qemu_log_lock(); int code_size, data_size =3D 0; - g_autoptr(GString) note =3D g_string_new("[tb header & initial ins= truction]"); - size_t chunk_start =3D 0; + size_t chunk_start; int insn =3D 0; - qemu_log("OUT: [size=3D%d]\n", gen_code_size); + if (tcg_ctx->data_gen_ptr) { code_size =3D tcg_ctx->data_gen_ptr - tb->tc.ptr; data_size =3D gen_code_size - code_size; @@ -1827,26 +1826,33 @@ TranslationBlock *tb_gen_code(CPUState *cpu, } =20 /* Dump header and the first instruction */ + qemu_log("OUT: [size=3D%d]\n", gen_code_size); + qemu_log(" -- guest addr 0x" TARGET_FMT_lx " + tb prologue\n", + tcg_ctx->gen_insn_data[insn][0]); chunk_start =3D tcg_ctx->gen_insn_end_off[insn]; - log_disas(tb->tc.ptr, chunk_start, note->str); + log_disas(tb->tc.ptr, chunk_start); =20 /* * Dump each instruction chunk, wrapping up empty chunks into * the next instruction. The whole array is offset so the * first entry is the beginning of the 2nd instruction. */ - while (insn <=3D tb->icount && chunk_start < code_size) { + while (insn < tb->icount) { size_t chunk_end =3D tcg_ctx->gen_insn_end_off[insn]; if (chunk_end > chunk_start) { - g_string_printf(note, "[guest addr: " TARGET_FMT_lx "]", - tcg_ctx->gen_insn_data[insn][0]); - log_disas(tb->tc.ptr + chunk_start, chunk_end - chunk_star= t, - note->str); + qemu_log(" -- guest addr 0x" TARGET_FMT_lx "\n", + tcg_ctx->gen_insn_data[insn][0]); + log_disas(tb->tc.ptr + chunk_start, chunk_end - chunk_star= t); chunk_start =3D chunk_end; } insn++; } =20 + if (chunk_start < code_size) { + qemu_log(" -- tb slow paths + alignment\n"); + log_disas(tb->tc.ptr + chunk_start, code_size - chunk_start); + } + /* Finally dump any data we may have after the block */ if (data_size) { int i; diff --git a/disas.c b/disas.c index c1397d3933..a4304e8137 100644 --- a/disas.c +++ b/disas.c @@ -262,8 +262,7 @@ static void cap_dump_insn_units(disassemble_info *info,= cs_insn *insn, } } =20 -static void cap_dump_insn(disassemble_info *info, cs_insn *insn, - const char *note) +static void cap_dump_insn(disassemble_info *info, cs_insn *insn) { fprintf_function print =3D info->fprintf_func; int i, n, split; @@ -284,11 +283,7 @@ static void cap_dump_insn(disassemble_info *info, cs_i= nsn *insn, } =20 /* Print the actual instruction. */ - print(info->stream, " %-8s %s", insn->mnemonic, insn->op_str); - if (note) { - print(info->stream, "\t\t%s", note); - } - print(info->stream, "\n"); + print(info->stream, " %-8s %s\n", insn->mnemonic, insn->op_str); =20 /* Dump any remaining part of the insn on subsequent lines. */ for (i =3D split; i < n; i +=3D split) { @@ -320,7 +315,7 @@ static bool cap_disas_target(disassemble_info *info, ui= nt64_t pc, size_t size) size -=3D tsize; =20 while (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { - cap_dump_insn(info, insn, NULL); + cap_dump_insn(info, insn); } =20 /* If the target memory is not consumed, go back for more... */ @@ -349,8 +344,7 @@ static bool cap_disas_target(disassemble_info *info, ui= nt64_t pc, size_t size) } =20 /* Disassemble SIZE bytes at CODE for the host. */ -static bool cap_disas_host(disassemble_info *info, void *code, size_t size, - const char *note) +static bool cap_disas_host(disassemble_info *info, void *code, size_t size) { csh handle; const uint8_t *cbuf; @@ -366,8 +360,7 @@ static bool cap_disas_host(disassemble_info *info, void= *code, size_t size, pc =3D (uintptr_t)code; =20 while (cs_disasm_iter(handle, &cbuf, &size, &pc, insn)) { - cap_dump_insn(info, insn, note); - note =3D NULL; + cap_dump_insn(info, insn); } if (size !=3D 0) { (*info->fprintf_func)(info->stream, @@ -411,7 +404,7 @@ static bool cap_disas_monitor(disassemble_info *info, u= int64_t pc, int count) csize +=3D tsize; =20 if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { - cap_dump_insn(info, insn, NULL); + cap_dump_insn(info, insn); if (--count <=3D 0) { break; } @@ -425,7 +418,7 @@ static bool cap_disas_monitor(disassemble_info *info, u= int64_t pc, int count) #endif /* !CONFIG_USER_ONLY */ #else # define cap_disas_target(i, p, s) false -# define cap_disas_host(i, p, s, n) false +# define cap_disas_host(i, p, s) false # define cap_disas_monitor(i, p, c) false # define cap_disas_plugin(i, p, c) false #endif /* CONFIG_CAPSTONE */ @@ -595,7 +588,7 @@ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t= size) } =20 /* Disassemble this for me please... (debugging). */ -void disas(FILE *out, void *code, unsigned long size, const char *note) +void disas(FILE *out, void *code, unsigned long size) { uintptr_t pc; int count; @@ -673,7 +666,7 @@ void disas(FILE *out, void *code, unsigned long size, c= onst char *note) print_insn =3D print_insn_hppa; #endif =20 - if (s.info.cap_arch >=3D 0 && cap_disas_host(&s.info, code, size, note= )) { + if (s.info.cap_arch >=3D 0 && cap_disas_host(&s.info, code, size)) { return; } =20 @@ -683,10 +676,6 @@ void disas(FILE *out, void *code, unsigned long size, = const char *note) for (pc =3D (uintptr_t)code; size > 0; pc +=3D count, size -=3D count)= { fprintf(out, "0x%08" PRIxPTR ": ", pc); count =3D print_insn(pc, &s.info); - if (note) { - fprintf(out, "\t\t%s", note); - note =3D NULL; - } fprintf(out, "\n"); if (count < 0) { break; diff --git a/tcg/tcg.c b/tcg/tcg.c index 62f299e36e..9a111ce604 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1101,7 +1101,7 @@ void tcg_prologue_init(TCGContext *s) size_t data_size =3D prologue_size - code_size; size_t i; =20 - log_disas(buf0, code_size, NULL); + log_disas(buf0, code_size); =20 for (i =3D 0; i < data_size; i +=3D sizeof(tcg_target_ulong)) { if (sizeof(tcg_target_ulong) =3D=3D 8) { @@ -1115,7 +1115,7 @@ void tcg_prologue_init(TCGContext *s) } } } else { - log_disas(buf0, prologue_size, NULL); + log_disas(buf0, prologue_size); } qemu_log("\n"); qemu_log_flush(); --=20 2.25.1 From nobody Tue Apr 30 01:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600042061; cv=none; d=zohomail.com; s=zohoarc; b=dekjIBqMSM5lYjkihqVmQEHjhmckzlF0ZcO4lgKVv6XGEE5mbConswrdSm0KdAXiBpAZcXVFjtBOAX/bWPjxhGzTjPSm7uykPh/JvJdplJc5zzm55C3ndS6RsEMlHoRcfohkeFW9i3qfKJys7CVbSFBpNQ47ydtRPlWqgY7feCE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600042061; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7F/Aro6rbDEPwg9gtfNrFuKJoWXLzLpxKySFvgwO7/U=; b=bJCTdOl5hZRzl8NIwGW/Q+NbDpD14pYZA3Kp23FsNO4Ne+r2t+cmOtBpNqVbp/uhvXl2OTuUPedhym6TvCmh3Q/4aKfSSFgdi3bRqj+iiCy+ftKEG41D3tuoQuTgiLrW32FnitdjybeJVzkc7JMGtTGmiT7Ok6QPs1V4OpdA9r4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600042061615450.8630261558626; Sun, 13 Sep 2020 17:07:41 -0700 (PDT) Received: from localhost ([::1]:46610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHc20-0001fw-4t for importer@patchew.org; Sun, 13 Sep 2020 20:07:40 -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) 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) 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-Google-Smtp-Source: ABdhPJyKyQYBNGWsHycP7dFne2rSaCaiWjtlsGBe3e2sT6PD5JdGUZMUpKQ5LOcUtNYOEDpu6kvhyQ== X-Received: by 2002:a63:485c:: with SMTP id x28mr9173603pgk.289.1600041720332; Sun, 13 Sep 2020 17:02:00 -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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x532.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_PDS_OTHER_BAD_TLD=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Rename 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(-) diff --git a/include/disas/dis-asm.h b/include/disas/dis-asm.h index 9856bf7921..d2418c977e 100644 --- a/include/disas/dis-asm.h +++ b/include/disas/dis-asm.h @@ -461,67 +461,7 @@ int print_insn_riscv32 (bfd_vma, disassemble_= info*); int print_insn_riscv64 (bfd_vma, disassemble_info*); int print_insn_rx(bfd_vma, disassemble_info *); =20 -#if 0 -/* Fetch the disassembler for a given BFD, if that support is available. = */ -disassembler_ftype disassembler(bfd *); -#endif - =0C -/* This block of definitions is for particular callers who read instructio= ns - into a buffer before calling the instruction decoder. */ - -/* Here is a function which callers may wish to use for read_memory_func. - It gets bytes from a buffer. */ -int buffer_read_memory(bfd_vma, bfd_byte *, int, struct disassemble_info *= ); - -/* This function goes with buffer_read_memory. - It prints a message using info->fprintf_func and info->stream. */ -void perror_memory(int, bfd_vma, struct disassemble_info *); - - -/* Just print the address in hex. This is included for completeness even - though both GDB and objdump provide their own (to print symbolic - addresses). */ -void generic_print_address(bfd_vma, struct disassemble_info *); - -/* Always true. */ -int generic_symbol_at_address(bfd_vma, struct disassemble_info *); - -/* Macro to initialize a disassemble_info struct. This should be called - by all applications creating such a struct. */ -#define INIT_DISASSEMBLE_INFO(INFO, STREAM, FPRINTF_FUNC) \ - (INFO).flavour =3D bfd_target_unknown_flavour, \ - (INFO).arch =3D bfd_arch_unknown, \ - (INFO).mach =3D 0, \ - (INFO).endian =3D BFD_ENDIAN_UNKNOWN, \ - INIT_DISASSEMBLE_INFO_NO_ARCH(INFO, STREAM, FPRINTF_FUNC) - -/* Call this macro to initialize only the internal variables for the - disassembler. Architecture dependent things such as byte order, or mac= hine - variant are not touched by this macro. This makes things much easier f= or - GDB which must initialize these things separately. */ - -#define INIT_DISASSEMBLE_INFO_NO_ARCH(INFO, STREAM, FPRINTF_FUNC) \ - (INFO).fprintf_func =3D (FPRINTF_FUNC), \ - (INFO).stream =3D (STREAM), \ - (INFO).symbols =3D NULL, \ - (INFO).num_symbols =3D 0, \ - (INFO).private_data =3D NULL, \ - (INFO).buffer =3D NULL, \ - (INFO).buffer_vma =3D 0, \ - (INFO).buffer_length =3D 0, \ - (INFO).read_memory_func =3D buffer_read_memory, \ - (INFO).memory_error_func =3D perror_memory, \ - (INFO).print_address_func =3D generic_print_address, \ - (INFO).print_insn =3D NULL, \ - (INFO).symbol_at_address_func =3D generic_symbol_at_address, \ - (INFO).flags =3D 0, \ - (INFO).bytes_per_line =3D 0, \ - (INFO).bytes_per_chunk =3D 0, \ - (INFO).display_endian =3D BFD_ENDIAN_UNKNOWN, \ - (INFO).disassembler_options =3D NULL, \ - (INFO).insn_info_valid =3D 0 - #ifndef ATTRIBUTE_UNUSED #define ATTRIBUTE_UNUSED __attribute__((unused)) #endif diff --git a/disas.c b/disas.c index a4304e8137..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 =3D NULL; =20 -/* Get LENGTH bytes from info's buffer, at target address memaddr. - Transfer them to myaddr. */ -int -buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length, - struct disassemble_info *info) +/* + * Get LENGTH bytes from info's buffer, at host address memaddr. + * Transfer them to myaddr. + */ +static int host_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length, + struct disassemble_info *info) { if (memaddr < info->buffer_vma - || memaddr + length > info->buffer_vma + info->buffer_length) + || memaddr + length > info->buffer_vma + info->buffer_length) { /* Out of bounds. Use EIO because GDB uses it. */ return EIO; + } memcpy (myaddr, info->buffer + (memaddr - info->buffer_vma), length); return 0; } =20 -/* Get LENGTH bytes from info's buffer, at target address memaddr. - Transfer them to myaddr. */ -static int -target_read_memory (bfd_vma memaddr, - bfd_byte *myaddr, - int length, - struct disassemble_info *info) +/* + * Get LENGTH bytes from info's buffer, at target address memaddr. + * Transfer them to myaddr. + */ +static int target_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int lengt= h, + struct disassemble_info *info) { CPUDebug *s =3D container_of(info, CPUDebug, info); - int r; - - r =3D cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0); - + int r =3D cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0); return r ? EIO : 0; } =20 /* Print an error message. We can assume that this is in response to an error return from buffer_read_memory. */ -void -perror_memory (int status, bfd_vma memaddr, struct disassemble_info *info) +static void perror_memory(int status, bfd_vma memaddr, + struct disassemble_info *info) { - if (status !=3D EIO) - /* Can't happen. */ - (*info->fprintf_func) (info->stream, "Unknown error %d\n", status); - else - /* Actually, address between memaddr and memaddr + len was - out of bounds. */ - (*info->fprintf_func) (info->stream, - "Address 0x%" PRIx64 " is out of bounds.\n", memaddr); + if (status !=3D EIO) { + /* Can't happen. */ + info->fprintf_func(info->stream, "Unknown error %d\n", status); + } else { + /* Address between memaddr and memaddr + len was out of bounds. */ + info->fprintf_func(info->stream, + "Address 0x%" PRIx64 " is out of bounds.\n", + memaddr); + } } =20 -/* This could be in a separate file, to save minuscule amounts of space - in statically linked executables. */ - -/* Just print the address is hex. This is included for completeness even - though both GDB and objdump provide their own (to print symbolic - addresses). */ - -void -generic_print_address (bfd_vma addr, struct disassemble_info *info) +/* + * Print 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); } =20 /* Print address in hex, truncated to the width of a host virtual address.= */ -static void -generic_print_host_address(bfd_vma addr, struct disassemble_info *info) +static void generic_print_host_address(bfd_vma addr, + struct disassemble_info *info) { - uint64_t mask =3D ~0ULL >> (64 - (sizeof(void *) * 8)); - generic_print_address(addr & mask, info); + generic_print_address((uintptr_t)addr, info); } =20 /* Just return the given address. */ =20 -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 */ =20 +static void initialize_debug(CPUDebug *s) +{ + memset(s, 0, sizeof(*s)); + s->info.arch =3D bfd_arch_unknown; + s->info.cap_arch =3D -1; + s->info.cap_insn_unit =3D 4; + s->info.cap_insn_split =3D 4; + s->info.memory_error_func =3D perror_memory; + s->info.symbol_at_address_func =3D generic_symbol_at_address; +} + +static void initialize_debug_target(CPUDebug *s, CPUState *cpu) +{ + initialize_debug(s); + + s->cpu =3D cpu; + s->info.read_memory_func =3D target_read_memory; + s->info.print_address_func =3D generic_print_address; +#ifdef TARGET_WORDS_BIGENDIAN + s->info.endian =3D BFD_ENDIAN_BIG; +#else + s->info.endian =3D BFD_ENDIAN_LITTLE; +#endif + + CPUClass *cc =3D CPU_GET_CLASS(cpu); + if (cc->disas_set_info) { + cc->disas_set_info(cpu, &s->info); + } +} + +static void initialize_debug_host(CPUDebug *s) +{ + initialize_debug(s); + + s->info.read_memory_func =3D host_read_memory; + s->info.print_address_func =3D generic_print_host_address; +#ifdef HOST_WORDS_BIGENDIAN + s->info.endian =3D BFD_ENDIAN_BIG; +#else + s->info.endian =3D BFD_ENDIAN_LITTLE; +#endif +#if defined(CONFIG_TCG_INTERPRETER) + s->info.print_insn =3D print_insn_tci; +#elif defined(__i386__) + s->info.mach =3D bfd_mach_i386_i386; + s->info.print_insn =3D print_insn_i386; + s->info.cap_arch =3D CS_ARCH_X86; + s->info.cap_mode =3D CS_MODE_32; + s->info.cap_insn_unit =3D 1; + s->info.cap_insn_split =3D 8; +#elif defined(__x86_64__) + s->info.mach =3D bfd_mach_x86_64; + s->info.print_insn =3D print_insn_i386; + s->info.cap_arch =3D CS_ARCH_X86; + s->info.cap_mode =3D CS_MODE_64; + s->info.cap_insn_unit =3D 1; + s->info.cap_insn_split =3D 8; +#elif defined(_ARCH_PPC) + s->info.disassembler_options =3D (char *)"any"; + s->info.print_insn =3D print_insn_ppc; + s->info.cap_arch =3D CS_ARCH_PPC; +# ifdef _ARCH_PPC64 + s->info.cap_mode =3D CS_MODE_64; +# endif +#elif defined(__riscv) && defined(CONFIG_RISCV_DIS) +#if defined(_ILP32) || (__riscv_xlen =3D=3D 32) + s->info.print_insn =3D print_insn_riscv32; +#elif defined(_LP64) + s->info.print_insn =3D print_insn_riscv64; +#else +#error unsupported RISC-V ABI +#endif +#elif defined(__aarch64__) && defined(CONFIG_ARM_A64_DIS) + s->info.print_insn =3D print_insn_arm_a64; + s->info.cap_arch =3D CS_ARCH_ARM64; +#elif defined(__alpha__) + s->info.print_insn =3D print_insn_alpha; +#elif defined(__sparc__) + s->info.print_insn =3D print_insn_sparc; + s->info.mach =3D bfd_mach_sparc_v9b; +#elif defined(__arm__) + /* TCG only generates code for arm mode. */ + s->info.print_insn =3D print_insn_arm; + s->info.cap_arch =3D CS_ARCH_ARM; +#elif defined(__MIPSEB__) + s->info.print_insn =3D print_insn_big_mips; +#elif defined(__MIPSEL__) + s->info.print_insn =3D print_insn_little_mips; +#elif defined(__m68k__) + s->info.print_insn =3D print_insn_m68k; +#elif defined(__s390__) + s->info.print_insn =3D print_insn_s390; +#elif defined(__hppa__) + s->info.print_insn =3D print_insn_hppa; +#endif +} + /* Disassemble this for me please... (debugging). */ void target_disas(FILE *out, CPUState *cpu, target_ulong code, target_ulong size) { - CPUClass *cc =3D CPU_GET_CLASS(cpu); target_ulong pc; int count; CPUDebug s; =20 - INIT_DISASSEMBLE_INFO(s.info, out, fprintf); - - s.cpu =3D cpu; - s.info.read_memory_func =3D target_read_memory; + initialize_debug_target(&s, cpu); + s.info.fprintf_func =3D fprintf; + s.info.stream =3D out; s.info.buffer_vma =3D code; s.info.buffer_length =3D size; - s.info.print_address_func =3D generic_print_address; - s.info.cap_arch =3D -1; - s.info.cap_mode =3D 0; - s.info.cap_insn_unit =3D 4; - s.info.cap_insn_split =3D 4; - -#ifdef TARGET_WORDS_BIGENDIAN - s.info.endian =3D BFD_ENDIAN_BIG; -#else - s.info.endian =3D BFD_ENDIAN_LITTLE; -#endif - - if (cc->disas_set_info) { - cc->disas_set_info(cpu, &s.info); - } =20 if (s.info.cap_arch >=3D 0 && cap_disas_target(&s.info, code, size)) { return; @@ -540,34 +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 =3D CPU_GET_CLASS(cpu); int count; CPUDebug s; GString *ds =3D g_string_set_size(&plugin_disas_output, 0); =20 g_assert(ds =3D=3D &plugin_disas_output); =20 - INIT_DISASSEMBLE_INFO(s.info, NULL, plugin_printf); - - s.cpu =3D cpu; - s.info.read_memory_func =3D target_read_memory; + initialize_debug_target(&s, cpu); + s.info.fprintf_func =3D plugin_printf; s.info.buffer_vma =3D addr; s.info.buffer_length =3D size; s.info.print_address_func =3D plugin_print_address; - s.info.cap_arch =3D -1; - s.info.cap_mode =3D 0; - s.info.cap_insn_unit =3D 4; - s.info.cap_insn_split =3D 4; - -#ifdef TARGET_WORDS_BIGENDIAN - s.info.endian =3D BFD_ENDIAN_BIG; -#else - s.info.endian =3D BFD_ENDIAN_LITTLE; -#endif - - if (cc->disas_set_info) { - cc->disas_set_info(cpu, &s.info); - } =20 if (s.info.cap_arch >=3D 0 && cap_disas_plugin(&s.info, addr, size)) { return g_strdup(ds->str); @@ -593,89 +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) =3D NULL; - - INIT_DISASSEMBLE_INFO(s.info, out, fprintf); - s.info.print_address_func =3D generic_print_host_address; =20 + initialize_debug_host(&s); + s.info.fprintf_func =3D fprintf; + s.info.stream =3D out; s.info.buffer =3D code; s.info.buffer_vma =3D (uintptr_t)code; s.info.buffer_length =3D size; - s.info.cap_arch =3D -1; - s.info.cap_mode =3D 0; - s.info.cap_insn_unit =3D 4; - s.info.cap_insn_split =3D 4; - -#ifdef HOST_WORDS_BIGENDIAN - s.info.endian =3D BFD_ENDIAN_BIG; -#else - s.info.endian =3D BFD_ENDIAN_LITTLE; -#endif -#if defined(CONFIG_TCG_INTERPRETER) - print_insn =3D print_insn_tci; -#elif defined(__i386__) - s.info.mach =3D bfd_mach_i386_i386; - print_insn =3D print_insn_i386; - s.info.cap_arch =3D CS_ARCH_X86; - s.info.cap_mode =3D CS_MODE_32; - s.info.cap_insn_unit =3D 1; - s.info.cap_insn_split =3D 8; -#elif defined(__x86_64__) - s.info.mach =3D bfd_mach_x86_64; - print_insn =3D print_insn_i386; - s.info.cap_arch =3D CS_ARCH_X86; - s.info.cap_mode =3D CS_MODE_64; - s.info.cap_insn_unit =3D 1; - s.info.cap_insn_split =3D 8; -#elif defined(_ARCH_PPC) - s.info.disassembler_options =3D (char *)"any"; - print_insn =3D print_insn_ppc; - s.info.cap_arch =3D CS_ARCH_PPC; -# ifdef _ARCH_PPC64 - s.info.cap_mode =3D CS_MODE_64; -# endif -#elif defined(__riscv) && defined(CONFIG_RISCV_DIS) -#if defined(_ILP32) || (__riscv_xlen =3D=3D 32) - print_insn =3D print_insn_riscv32; -#elif defined(_LP64) - print_insn =3D print_insn_riscv64; -#else -#error unsupported RISC-V ABI -#endif -#elif defined(__aarch64__) && defined(CONFIG_ARM_A64_DIS) - print_insn =3D print_insn_arm_a64; - s.info.cap_arch =3D CS_ARCH_ARM64; -#elif defined(__alpha__) - print_insn =3D print_insn_alpha; -#elif defined(__sparc__) - print_insn =3D print_insn_sparc; - s.info.mach =3D bfd_mach_sparc_v9b; -#elif defined(__arm__) - print_insn =3D print_insn_arm; - s.info.cap_arch =3D CS_ARCH_ARM; - /* TCG only generates code for arm mode. */ -#elif defined(__MIPSEB__) - print_insn =3D print_insn_big_mips; -#elif defined(__MIPSEL__) - print_insn =3D print_insn_little_mips; -#elif defined(__m68k__) - print_insn =3D print_insn_m68k; -#elif defined(__s390__) - print_insn =3D print_insn_s390; -#elif defined(__hppa__) - print_insn =3D print_insn_hppa; -#endif =20 if (s.info.cap_arch >=3D 0 && cap_disas_host(&s.info, code, size)) { return; } =20 - if (print_insn =3D=3D NULL) { - print_insn =3D print_insn_od_host; + if (s.info.print_insn =3D=3D NULL) { + s.info.print_insn =3D print_insn_od_host; } for (pc =3D (uintptr_t)code; size > 0; pc +=3D count, size -=3D count)= { fprintf(out, "0x%08" PRIxPTR ": ", pc); - count =3D print_insn(pc, &s.info); + count =3D s.info.print_insn(pc, &s.info); fprintf(out, "\n"); if (count < 0) { break; @@ -720,31 +713,15 @@ physical_read_memory(bfd_vma memaddr, bfd_byte *myadd= r, int length, void monitor_disas(Monitor *mon, CPUState *cpu, target_ulong pc, int nb_insn, int is_physical) { - CPUClass *cc =3D CPU_GET_CLASS(cpu); int count, i; CPUDebug s; =20 - INIT_DISASSEMBLE_INFO(s.info, NULL, qemu_fprintf); - - s.cpu =3D cpu; - s.info.read_memory_func - =3D (is_physical ? physical_read_memory : target_read_memory); - s.info.print_address_func =3D generic_print_address; - s.info.buffer_vma =3D pc; - s.info.cap_arch =3D -1; - s.info.cap_mode =3D 0; - s.info.cap_insn_unit =3D 4; - s.info.cap_insn_split =3D 4; - -#ifdef TARGET_WORDS_BIGENDIAN - s.info.endian =3D BFD_ENDIAN_BIG; -#else - s.info.endian =3D BFD_ENDIAN_LITTLE; -#endif - - if (cc->disas_set_info) { - cc->disas_set_info(cpu, &s.info); + initialize_debug_target(&s, cpu); + s.info.fprintf_func =3D qemu_fprintf; + if (is_physical) { + s.info.read_memory_func =3D physical_read_memory; } + s.info.buffer_vma =3D pc; =20 if (s.info.cap_arch >=3D 0 && cap_disas_monitor(&s.info, pc, nb_insn))= { return; --=20 2.25.1 From nobody Tue Apr 30 01:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600041779; cv=none; d=zohomail.com; s=zohoarc; b=Ql6unggQDj+LpgAz4IZbdBH/kSKku+ESlFJKscKXAVdedFRxP3gXDs+X3E6OSqgLjtW+pzHI/BZJK/Rf2HtQr6UoXe0TWJAaoNzm6LG58l3jPkSjwZ9DWBScot0K1QnCXud9IQGZ7Y7W/Pet9I4aSg/scuZ98bzxzh7R/+BR3To= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600041779; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9uEhRDQbPBvpSG5xc2pJjbxBlGNp1Es5E3WFmyWYEgg=; b=O+bbD/3LeD7BMQX/JWIUUXRriuMacDFcehQa7OZtllBokFlkGsQMjdLYN12EJmlyRX9eZtcfO61gP+KEj9bqVPjNBNj1GYm5+SMB9bcXEtnL3jT+iaEXPB7rTfTPSmugl0Xc6pV1ESTPbWr6H7HJ7OPEH0xwuVT/JpvKiS4Bpwk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600041779346443.13436737545226; Sun, 13 Sep 2020 17:02:59 -0700 (PDT) Received: from localhost ([::1]:60238 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHbxQ-00046t-4f for importer@patchew.org; Sun, 13 Sep 2020 20:02:56 -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) 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) 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-Google-Smtp-Source: ABdhPJxwVr1oppoIGobuV9LmqBXCta2XXV+YRKXVMah1ORF4zVuA7eMOzgfMyNcKW9vRRHNX7uzLXQ== X-Received: by 2002:a17:90a:6a4e:: with SMTP id d14mr11001888pjm.63.1600041721573; Sun, 13 Sep 2020 17:02:01 -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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1043; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1043.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Use the routines we have already instead of open-coding. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/disas/dis-asm.h | 32 ++++++++++++++++++++---- disas.c | 55 ----------------------------------------- 2 files changed, 27 insertions(+), 60 deletions(-) diff --git a/include/disas/dis-asm.h b/include/disas/dis-asm.h index d2418c977e..8a216ac495 100644 --- a/include/disas/dis-asm.h +++ b/include/disas/dis-asm.h @@ -468,11 +468,33 @@ int print_insn_rx(bfd_vma, disassemble_info *); =20 /* from libbfd */ =20 -bfd_vma bfd_getl64 (const bfd_byte *addr); -bfd_vma bfd_getl32 (const bfd_byte *addr); -bfd_vma bfd_getb32 (const bfd_byte *addr); -bfd_vma bfd_getl16 (const bfd_byte *addr); -bfd_vma bfd_getb16 (const bfd_byte *addr); +#include "qemu/bswap.h" + +static inline bfd_vma bfd_getl64(const bfd_byte *addr) +{ + return ldq_le_p(addr); +} + +static inline bfd_vma bfd_getl32(const bfd_byte *addr) +{ + return (uint32_t)ldl_le_p(addr); +} + +static inline bfd_vma bfd_getl16(const bfd_byte *addr) +{ + return lduw_le_p(addr); +} + +static inline bfd_vma bfd_getb32(const bfd_byte *addr) +{ + return (uint32_t)ldl_be_p(addr); +} + +static inline bfd_vma bfd_getb16(const bfd_byte *addr) +{ + return lduw_be_p(addr); +} + typedef bool bfd_boolean; =20 #endif /* DISAS_DIS_ASM_H */ diff --git a/disas.c b/disas.c index 50b5677930..20fad6aabb 100644 --- a/disas.c +++ b/disas.c @@ -85,61 +85,6 @@ generic_symbol_at_address (bfd_vma addr, struct disassem= ble_info *info) return 1; } =20 -bfd_vma bfd_getl64 (const bfd_byte *addr) -{ - unsigned long long v; - - v =3D (unsigned long long) addr[0]; - v |=3D (unsigned long long) addr[1] << 8; - v |=3D (unsigned long long) addr[2] << 16; - v |=3D (unsigned long long) addr[3] << 24; - v |=3D (unsigned long long) addr[4] << 32; - v |=3D (unsigned long long) addr[5] << 40; - v |=3D (unsigned long long) addr[6] << 48; - v |=3D (unsigned long long) addr[7] << 56; - return (bfd_vma) v; -} - -bfd_vma bfd_getl32 (const bfd_byte *addr) -{ - unsigned long v; - - v =3D (unsigned long) addr[0]; - v |=3D (unsigned long) addr[1] << 8; - v |=3D (unsigned long) addr[2] << 16; - v |=3D (unsigned long) addr[3] << 24; - return (bfd_vma) v; -} - -bfd_vma bfd_getb32 (const bfd_byte *addr) -{ - unsigned long v; - - v =3D (unsigned long) addr[0] << 24; - v |=3D (unsigned long) addr[1] << 16; - v |=3D (unsigned long) addr[2] << 8; - v |=3D (unsigned long) addr[3]; - return (bfd_vma) v; -} - -bfd_vma bfd_getl16 (const bfd_byte *addr) -{ - unsigned long v; - - v =3D (unsigned long) addr[0]; - v |=3D (unsigned long) addr[1] << 8; - return (bfd_vma) v; -} - -bfd_vma bfd_getb16 (const bfd_byte *addr) -{ - unsigned long v; - - v =3D (unsigned long) addr[0] << 24; - v |=3D (unsigned long) addr[1] << 16; - return (bfd_vma) v; -} - static int print_insn_objdump(bfd_vma pc, disassemble_info *info, const char *prefix) { --=20 2.25.1 From nobody Tue Apr 30 01:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600042111; cv=none; d=zohomail.com; s=zohoarc; b=CoeY2hgn6u14AamNNag0GVpgGJS9Ru2E+pGiCHNnUiowINnbSI9u2uO9C/H6zwOi82svW3PMdjb2wkN8u2Dl2nSgljbFoDv/KPKEdxXqtHRoJhIUaXIWugnfQI0LZTbL9/BIX0+loFOAnFXyjcdeiTAJbImAMGhBj5nx3AgebFI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600042111; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=inMfli2pDbU3kA4lojjL53bmShI2QMyc74Hc7w0ZLmA=; b=Vk43gXwZXfrXhrFa5fBEZN3U/F2CgZ1XZvOAyZgOZ+olX4rhWc/WUxf73QrjqRhtUgNpOxBTmT7/su+yxFflmka/Id+VzBnCvS6AJJND7mXGEhF7GGVhuhS3A3IUEoTwf15gD1EZz/UUHc9ZgfRJ24BDisUVrJ93qatoZIvYvJU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600042111373438.83512276317356; Sun, 13 Sep 2020 17:08:31 -0700 (PDT) Received: from localhost ([::1]:48716 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHc2o-0002X1-4X for importer@patchew.org; Sun, 13 Sep 2020 20:08:30 -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) 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) 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-Google-Smtp-Source: ABdhPJwmJ8Vo1qiME16/LKOV1qSRjDo1b9/nYsc/IBeK3fgsXqrYcOsZZHX9Km7g51wtKIdDkPzK5w== X-Received: by 2002:a63:1925:: with SMTP id z37mr1984764pgl.23.1600041722760; 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Do not retain a GString in thread-local storage. Allocate a new one and free it on every invocation. Do not g_strdup the result; return the buffer from the GString. Do not use warn_report. Using cs_disasm allocated memory via the &insn parameter, but that was never freed. Use cs_disasm_iter so that we use the memory that we've already allocated, and so that we only try to disassemble one insn, as desired. Do not allocate 1k to hold the bytes for a single instruction. Signed-off-by: Richard Henderson --- disas.c | 55 +++++++++++++++++++------------------------------------ 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/disas.c b/disas.c index 20fad6aabb..ed9965c32f 100644 --- a/disas.c +++ b/disas.c @@ -498,13 +498,12 @@ void target_disas(FILE *out, CPUState *cpu, target_ul= ong code, } } =20 -static __thread GString plugin_disas_output; - static int plugin_printf(FILE *stream, const char *fmt, ...) { - va_list va; - GString *s =3D &plugin_disas_output; + /* We abuse the FILE parameter to pass a GString. */ + GString *s =3D (GString *)stream; int initial_len =3D s->len; + va_list va; =20 va_start(va, fmt); g_string_append_vprintf(s, fmt, va); @@ -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 =3D cap_buf; csh handle; - cs_insn *insn; - size_t csize =3D 0; - int count; - GString *s =3D &plugin_disas_output; =20 if (cap_disas_start(info, &handle) !=3D CS_ERR_OK) { return false; } - insn =3D cap_insn; =20 - size_t tsize =3D MIN(sizeof(cap_buf) - csize, size); - const uint8_t *cbuf =3D cap_buf; - target_read_memory(pc, cap_buf, tsize, info); + assert(size < sizeof(cap_buf)); + target_read_memory(pc, cap_buf, size, info); =20 - count =3D cs_disasm(handle, cbuf, size, 0, 1, &insn); - - if (count) { - g_string_printf(s, "%s %s", insn->mnemonic, insn->op_str); - } else { - g_string_printf(s, "cs_disasm failed"); + if (cs_disasm_iter(handle, &cbuf, &size, &pc, cap_insn)) { + GString *s =3D (GString *)info->stream; + g_string_printf(s, "%s %s", cap_insn->mnemonic, cap_insn->op_str); } =20 cs_close(&handle); @@ -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 =3D g_string_set_size(&plugin_disas_output, 0); - - g_assert(ds =3D=3D &plugin_disas_output); + GString *ds =3D g_string_new(NULL); =20 initialize_debug_target(&s, cpu); s.info.fprintf_func =3D plugin_printf; + s.info.stream =3D (FILE *)ds; /* abuse this slot */ s.info.buffer_vma =3D addr; s.info.buffer_length =3D size; s.info.print_address_func =3D plugin_print_address; =20 if (s.info.cap_arch >=3D 0 && cap_disas_plugin(&s.info, addr, size)) { - return g_strdup(ds->str); + ; /* done */ + } else if (s.info.print_insn) { + s.info.print_insn(addr, &s.info); + } else { + ; /* cannot disassemble -- return empty string */ } =20 - if (s.info.print_insn =3D=3D NULL) { - s.info.print_insn =3D print_insn_od_target; - } - - count =3D s.info.print_insn(addr, &s.info); - - /* The decoder probably read more than it needed it's not critical */ - if (count < size) { - warn_report("%s: %zu bytes left over", __func__, size - count); - } - - return g_strdup(ds->str); + /* Return the buffer, freeing the GString container. */ + return g_string_free(ds, false); } =20 /* Disassemble this for me please... (debugging). */ --=20 2.25.1 From nobody Tue Apr 30 01:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600041851; cv=none; d=zohomail.com; s=zohoarc; b=URM7oipEdF3Gw8v5o8r5t7JQcauRuM59ugnzK93pPkgidTRSUWlmPpTyhvBhbE6SaLA4gw1ThTpd1kgWh7eg6s0mwea2FTJLtp8NJnQWZA05N49Iv+BrH6Z/qlktylY/W6RX6kM6u1yYgjPJA1xN411zSMzaFezlhCTOjaZbiBk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600041851; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vOtHj+mVdsMkoT/WjxFe7ZI43yFPE5uJFgaFbrClmPo=; b=GR3ciFyErd/f3ACbQrVvIwluDCVCs7aw1oa66zMIh6kj73Pmaa4hYW1M9l1VLdOqlgxoxAVMnI/sur4Wa1NqPmimOzoD1Ux98clapq6DiP9r/r77bIWdOjjji3ToOPG2x7qF0Ja0REIdSseKyrJR79N6syMe0sBiqEGsjMnvWpM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600041851689132.73048421590988; Sun, 13 Sep 2020 17:04:11 -0700 (PDT) Received: from localhost ([::1]:38286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHbyc-0006bM-L4 for importer@patchew.org; Sun, 13 Sep 2020 20:04:10 -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) 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) 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-Google-Smtp-Source: ABdhPJzfFAVO4IfR/+R9NxUmrscBvQRzmtLWeenByaYMb3/a1eP5/GnqeJFTo/IOpKJRcFQYMdsNmA== X-Received: by 2002:a17:902:7c84:: with SMTP id y4mr7571775pll.97.1600041723952; 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::442; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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(-) 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 =3D print_insn_arm_a64; +#elif defined(__aarch64__) s->info.cap_arch =3D CS_ARCH_ARM64; +# ifdef CONFIG_ARM_A64_DIS + s->info.print_insn =3D print_insn_arm_a64; +# endif #elif defined(__alpha__) s->info.print_insn =3D print_insn_alpha; #elif defined(__sparc__) --=20 2.25.1 From nobody Tue Apr 30 01:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600042177; cv=none; d=zohomail.com; s=zohoarc; b=VCNFUGcpfSqA5gG0+USQERWPBYQixtf/PBh8/4xuqbM6JDmtSlIIGvFB8u370E9HuS9NNmM1ECyD5dLlQ8UStafcj/9tWUHkVBzNn1Y8gF6mxTd5o+r8BnQQEEe5G8GxpKy2phZr3DIX6QbwwCjbl7SxdNgd1EXpMFYK/64BrGs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600042177; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=prabnvoVsXrpx3moA7+Jtv7qklFTNLg9Xp3czxUE/mc=; b=D2WhhN9dI7Pj+oRk9TKYoJpYsMeOWwsdqd7zhMY3h09+oxuzDpdk0dc5RVdeo2MCGZEk/U1/vcDdyRGUK86O3l6dW9zUfQvg7RC8HV4gCquOFDfskoHBYzOcOCcUqOoWeH9JPk7mFhlnXg11/GbFo1LPS9Cc66n5AMHwPyWYskI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600042177874185.03365847647387; Sun, 13 Sep 2020 17:09:37 -0700 (PDT) Received: from localhost ([::1]:52626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHc3s-00046j-Mi for importer@patchew.org; Sun, 13 Sep 2020 20:09:36 -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) 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) 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-Google-Smtp-Source: ABdhPJwCi/Ej3uDvCKpNn5l+btGpEdlu8jEGhwPB61Jrfmb7HpF3wPk6Y9IQSp+T/6YeOtW5OtGuRw== X-Received: by 2002:a17:902:b216:: with SMTP id t22mr12178272plr.35.1600041725071; Sun, 13 Sep 2020 17:02:05 -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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" There is nothing target-specific about this code, so it can be added to common_ss. This also requires that the base capstone dependency be added to common_ss, so that we get the correct include paths added to CFLAGS. Signed-off-by: Richard Henderson --- include/disas/dis-asm.h | 12 ++ disas.c | 275 -------------------------------------- disas/capstone.c | 286 ++++++++++++++++++++++++++++++++++++++++ disas/meson.build | 1 + meson.build | 1 + 5 files changed, 300 insertions(+), 275 deletions(-) create mode 100644 disas/capstone.c diff --git a/include/disas/dis-asm.h b/include/disas/dis-asm.h index 8a216ac495..a34837e4db 100644 --- a/include/disas/dis-asm.h +++ b/include/disas/dis-asm.h @@ -461,6 +461,18 @@ int print_insn_riscv32 (bfd_vma, disassemble_= info*); int print_insn_riscv64 (bfd_vma, disassemble_info*); int print_insn_rx(bfd_vma, disassemble_info *); =20 +#ifdef CONFIG_CAPSTONE +bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size); +bool cap_disas_host(disassemble_info *info, void *code, size_t size); +bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int count); +bool cap_disas_plugin(disassemble_info *info, uint64_t pc, size_t size); +#else +# define cap_disas_target(i, p, s) false +# define cap_disas_host(i, p, s) false +# define cap_disas_monitor(i, p, c) false +# define cap_disas_plugin(i, p, c) false +#endif /* CONFIG_CAPSTONE */ + =0C #ifndef ATTRIBUTE_UNUSED #define ATTRIBUTE_UNUSED __attribute__((unused)) diff --git a/disas.c b/disas.c index 5d81403125..7fb85bbfa8 100644 --- a/disas.c +++ b/disas.c @@ -114,255 +114,6 @@ static int print_insn_od_target(bfd_vma pc, disassemb= le_info *info) return print_insn_objdump(pc, info, "OBJD-T"); } =20 -#ifdef CONFIG_CAPSTONE -/* Temporary storage for the capstone library. This will be alloced via - malloc with a size private to the library; thus there's no reason not - to share this across calls and across host vs target disassembly. */ -static __thread cs_insn *cap_insn; - -/* Initialize the Capstone library. */ -/* ??? It would be nice to cache this. We would need one handle for the - host and one for the target. For most targets we can reset specific - parameters via cs_option(CS_OPT_MODE, new_mode), but we cannot change - CS_ARCH_* in this way. Thus we would need to be able to close and - re-open the target handle with a different arch for the target in order - to handle AArch64 vs AArch32 mode switching. */ -static cs_err cap_disas_start(disassemble_info *info, csh *handle) -{ - cs_mode cap_mode =3D info->cap_mode; - cs_err err; - - cap_mode +=3D (info->endian =3D=3D BFD_ENDIAN_BIG ? CS_MODE_BIG_ENDIAN - : CS_MODE_LITTLE_ENDIAN); - - err =3D cs_open(info->cap_arch, cap_mode, handle); - if (err !=3D CS_ERR_OK) { - return err; - } - - /* ??? There probably ought to be a better place to put this. */ - if (info->cap_arch =3D=3D CS_ARCH_X86) { - /* We don't care about errors (if for some reason the library - is compiled without AT&T syntax); the user will just have - to deal with the Intel syntax. */ - cs_option(*handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_ATT); - } - - /* "Disassemble" unknown insns as ".byte W,X,Y,Z". */ - cs_option(*handle, CS_OPT_SKIPDATA, CS_OPT_ON); - - /* Allocate temp space for cs_disasm_iter. */ - if (cap_insn =3D=3D NULL) { - cap_insn =3D cs_malloc(*handle); - if (cap_insn =3D=3D NULL) { - cs_close(handle); - return CS_ERR_MEM; - } - } - return CS_ERR_OK; -} - -static void cap_dump_insn_units(disassemble_info *info, cs_insn *insn, - int i, int n) -{ - fprintf_function print =3D info->fprintf_func; - FILE *stream =3D info->stream; - - switch (info->cap_insn_unit) { - case 4: - if (info->endian =3D=3D BFD_ENDIAN_BIG) { - for (; i < n; i +=3D 4) { - print(stream, " %08x", ldl_be_p(insn->bytes + i)); - - } - } else { - for (; i < n; i +=3D 4) { - print(stream, " %08x", ldl_le_p(insn->bytes + i)); - } - } - break; - - case 2: - if (info->endian =3D=3D BFD_ENDIAN_BIG) { - for (; i < n; i +=3D 2) { - print(stream, " %04x", lduw_be_p(insn->bytes + i)); - } - } else { - for (; i < n; i +=3D 2) { - print(stream, " %04x", lduw_le_p(insn->bytes + i)); - } - } - break; - - default: - for (; i < n; i++) { - print(stream, " %02x", insn->bytes[i]); - } - break; - } -} - -static void cap_dump_insn(disassemble_info *info, cs_insn *insn) -{ - fprintf_function print =3D info->fprintf_func; - int i, n, split; - - print(info->stream, "0x%08" PRIx64 ": ", insn->address); - - n =3D insn->size; - split =3D info->cap_insn_split; - - /* Dump the first SPLIT bytes of the instruction. */ - cap_dump_insn_units(info, insn, 0, MIN(n, split)); - - /* Add padding up to SPLIT so that mnemonics line up. */ - if (n < split) { - int width =3D (split - n) / info->cap_insn_unit; - width *=3D (2 * info->cap_insn_unit + 1); - print(info->stream, "%*s", width, ""); - } - - /* Print the actual instruction. */ - print(info->stream, " %-8s %s\n", insn->mnemonic, insn->op_str); - - /* Dump any remaining part of the insn on subsequent lines. */ - for (i =3D split; i < n; i +=3D split) { - print(info->stream, "0x%08" PRIx64 ": ", insn->address + i); - cap_dump_insn_units(info, insn, i, MIN(n, i + split)); - print(info->stream, "\n"); - } -} - -/* Disassemble SIZE bytes at PC for the target. */ -static bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t s= ize) -{ - uint8_t cap_buf[1024]; - csh handle; - cs_insn *insn; - size_t csize =3D 0; - - if (cap_disas_start(info, &handle) !=3D CS_ERR_OK) { - return false; - } - insn =3D cap_insn; - - while (1) { - size_t tsize =3D MIN(sizeof(cap_buf) - csize, size); - const uint8_t *cbuf =3D cap_buf; - - target_read_memory(pc + csize, cap_buf + csize, tsize, info); - csize +=3D tsize; - size -=3D tsize; - - while (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { - cap_dump_insn(info, insn); - } - - /* If the target memory is not consumed, go back for more... */ - if (size !=3D 0) { - /* ... taking care to move any remaining fractional insn - to the beginning of the buffer. */ - if (csize !=3D 0) { - memmove(cap_buf, cbuf, csize); - } - continue; - } - - /* Since the target memory is consumed, we should not have - a remaining fractional insn. */ - if (csize !=3D 0) { - (*info->fprintf_func)(info->stream, - "Disassembler disagrees with translator " - "over instruction decoding\n" - "Please report this to qemu-devel@nongnu.org\n"); - } - break; - } - - cs_close(&handle); - return true; -} - -/* Disassemble SIZE bytes at CODE for the host. */ -static bool cap_disas_host(disassemble_info *info, void *code, size_t size) -{ - csh handle; - const uint8_t *cbuf; - cs_insn *insn; - uint64_t pc; - - if (cap_disas_start(info, &handle) !=3D CS_ERR_OK) { - return false; - } - insn =3D cap_insn; - - cbuf =3D code; - pc =3D (uintptr_t)code; - - while (cs_disasm_iter(handle, &cbuf, &size, &pc, insn)) { - cap_dump_insn(info, insn); - } - if (size !=3D 0) { - (*info->fprintf_func)(info->stream, - "Disassembler disagrees with TCG over instruction encoding\n" - "Please report this to qemu-devel@nongnu.org\n"); - } - - cs_close(&handle); - return true; -} - -#if !defined(CONFIG_USER_ONLY) -/* Disassemble COUNT insns at PC for the target. */ -static bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int cou= nt) -{ - uint8_t cap_buf[32]; - csh handle; - cs_insn *insn; - size_t csize =3D 0; - - if (cap_disas_start(info, &handle) !=3D CS_ERR_OK) { - return false; - } - insn =3D cap_insn; - - while (1) { - /* We want to read memory for one insn, but generically we do not - know how much memory that is. We have a small buffer which is - known to be sufficient for all supported targets. Try to not - read beyond the page, Just In Case. For even more simplicity, - ignore the actual target page size and use a 1k boundary. If - that turns out to be insufficient, we'll come back around the - loop and read more. */ - uint64_t epc =3D QEMU_ALIGN_UP(pc + csize + 1, 1024); - size_t tsize =3D MIN(sizeof(cap_buf) - csize, epc - pc); - const uint8_t *cbuf =3D cap_buf; - - /* Make certain that we can make progress. */ - assert(tsize !=3D 0); - info->read_memory_func(pc, cap_buf + csize, tsize, info); - csize +=3D tsize; - - if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { - cap_dump_insn(info, insn); - if (--count <=3D 0) { - break; - } - } - memmove(cap_buf, cbuf, csize); - } - - cs_close(&handle); - return true; -} -#endif /* !CONFIG_USER_ONLY */ -#else -# define cap_disas_target(i, p, s) false -# define cap_disas_host(i, p, s) false -# define cap_disas_monitor(i, p, c) false -# define cap_disas_plugin(i, p, c) false -#endif /* CONFIG_CAPSTONE */ - static void initialize_debug(CPUDebug *s) { memset(s, 0, sizeof(*s)); @@ -520,32 +271,6 @@ static void plugin_print_address(bfd_vma addr, struct = disassemble_info *info) } =20 =20 -#ifdef CONFIG_CAPSTONE -/* Disassemble a single instruction directly into plugin output */ -static -bool cap_disas_plugin(disassemble_info *info, uint64_t pc, size_t size) -{ - uint8_t cap_buf[64]; - const uint8_t *cbuf =3D cap_buf; - csh handle; - - if (cap_disas_start(info, &handle) !=3D CS_ERR_OK) { - return false; - } - - assert(size < sizeof(cap_buf)); - target_read_memory(pc, cap_buf, size, info); - - if (cs_disasm_iter(handle, &cbuf, &size, &pc, cap_insn)) { - GString *s =3D (GString *)info->stream; - g_string_printf(s, "%s %s", cap_insn->mnemonic, cap_insn->op_str); - } - - cs_close(&handle); - return true; -} -#endif - /* * We should only be dissembling one instruction at a time here. If * there is left over it usually indicates the front end has read more diff --git a/disas/capstone.c b/disas/capstone.c new file mode 100644 index 0000000000..b48f83958d --- /dev/null +++ b/disas/capstone.c @@ -0,0 +1,286 @@ +/* + * Interface to the capstone disassembler. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/bswap.h" +#include "disas/dis-asm.h" +#include "disas/capstone.h" + + +/* + * Temporary storage for the capstone library. This will be alloced via + * malloc with a size private to the library; thus there's no reason not + * to share this across calls and across host vs target disassembly. + */ +static __thread cs_insn *cap_insn; + +/* + * Initialize the Capstone library. + * + * ??? It would be nice to cache this. We would need one handle for the + * host and one for the target. For most targets we can reset specific + * parameters via cs_option(CS_OPT_MODE, new_mode), but we cannot change + * CS_ARCH_* in this way. Thus we would need to be able to close and + * re-open the target handle with a different arch for the target in order + * to handle AArch64 vs AArch32 mode switching. + */ +static cs_err cap_disas_start(disassemble_info *info, csh *handle) +{ + cs_mode cap_mode =3D info->cap_mode; + cs_err err; + + cap_mode +=3D (info->endian =3D=3D BFD_ENDIAN_BIG ? CS_MODE_BIG_ENDIAN + : CS_MODE_LITTLE_ENDIAN); + + err =3D cs_open(info->cap_arch, cap_mode, handle); + if (err !=3D CS_ERR_OK) { + return err; + } + + /* "Disassemble" unknown insns as ".byte W,X,Y,Z". */ + cs_option(*handle, CS_OPT_SKIPDATA, CS_OPT_ON); + + if (info->cap_arch =3D=3D CS_ARCH_X86) { + /* + * We don't care about errors (if for some reason the library + * is compiled without AT&T syntax); the user will just have + * to deal with the Intel syntax. + */ + cs_option(*handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_ATT); + } + + /* Allocate temp space for cs_disasm_iter. */ + if (cap_insn =3D=3D NULL) { + cap_insn =3D cs_malloc(*handle); + if (cap_insn =3D=3D NULL) { + cs_close(handle); + return CS_ERR_MEM; + } + } + return CS_ERR_OK; +} + +static void cap_dump_insn_units(disassemble_info *info, cs_insn *insn, + int i, int n) +{ + fprintf_function print =3D info->fprintf_func; + FILE *stream =3D info->stream; + + switch (info->cap_insn_unit) { + case 4: + if (info->endian =3D=3D BFD_ENDIAN_BIG) { + for (; i < n; i +=3D 4) { + print(stream, " %08x", ldl_be_p(insn->bytes + i)); + + } + } else { + for (; i < n; i +=3D 4) { + print(stream, " %08x", ldl_le_p(insn->bytes + i)); + } + } + break; + + case 2: + if (info->endian =3D=3D BFD_ENDIAN_BIG) { + for (; i < n; i +=3D 2) { + print(stream, " %04x", lduw_be_p(insn->bytes + i)); + } + } else { + for (; i < n; i +=3D 2) { + print(stream, " %04x", lduw_le_p(insn->bytes + i)); + } + } + break; + + default: + for (; i < n; i++) { + print(stream, " %02x", insn->bytes[i]); + } + break; + } +} + +static void cap_dump_insn(disassemble_info *info, cs_insn *insn) +{ + fprintf_function print =3D info->fprintf_func; + FILE *stream =3D info->stream; + int i, n, split; + + print(stream, "0x%08" PRIx64 ": ", insn->address); + + n =3D insn->size; + split =3D info->cap_insn_split; + + /* Dump the first SPLIT bytes of the instruction. */ + cap_dump_insn_units(info, insn, 0, MIN(n, split)); + + /* Add padding up to SPLIT so that mnemonics line up. */ + if (n < split) { + int width =3D (split - n) / info->cap_insn_unit; + width *=3D (2 * info->cap_insn_unit + 1); + print(stream, "%*s", width, ""); + } + + /* Print the actual instruction. */ + print(stream, " %-8s %s\n", insn->mnemonic, insn->op_str); + + /* Dump any remaining part of the insn on subsequent lines. */ + for (i =3D split; i < n; i +=3D split) { + print(stream, "0x%08" PRIx64 ": ", insn->address + i); + cap_dump_insn_units(info, insn, i, MIN(n, i + split)); + print(stream, "\n"); + } +} + +/* Disassemble SIZE bytes at PC for the target. */ +bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size) +{ + uint8_t cap_buf[1024]; + csh handle; + cs_insn *insn; + size_t csize =3D 0; + + if (cap_disas_start(info, &handle) !=3D CS_ERR_OK) { + return false; + } + insn =3D cap_insn; + + while (1) { + size_t tsize =3D MIN(sizeof(cap_buf) - csize, size); + const uint8_t *cbuf =3D cap_buf; + + info->read_memory_func(pc + csize, cap_buf + csize, tsize, info); + csize +=3D tsize; + size -=3D tsize; + + while (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { + cap_dump_insn(info, insn); + } + + /* If the target memory is not consumed, go back for more... */ + if (size !=3D 0) { + /* + * ... taking care to move any remaining fractional insn + * to the beginning of the buffer. + */ + if (csize !=3D 0) { + memmove(cap_buf, cbuf, csize); + } + continue; + } + + /* + * Since the target memory is consumed, we should not have + * a remaining fractional insn. + */ + if (csize !=3D 0) { + info->fprintf_func(info->stream, + "Disassembler disagrees with translator " + "over instruction decoding\n" + "Please report this to qemu-devel@nongnu.org\n"); + } + break; + } + + cs_close(&handle); + return true; +} + +/* Disassemble SIZE bytes at CODE for the host. */ +bool cap_disas_host(disassemble_info *info, void *code, size_t size) +{ + csh handle; + const uint8_t *cbuf; + cs_insn *insn; + uint64_t pc; + + if (cap_disas_start(info, &handle) !=3D CS_ERR_OK) { + return false; + } + insn =3D cap_insn; + + cbuf =3D code; + pc =3D (uintptr_t)code; + + while (cs_disasm_iter(handle, &cbuf, &size, &pc, insn)) { + cap_dump_insn(info, insn); + } + if (size !=3D 0) { + info->fprintf_func(info->stream, + "Disassembler disagrees with TCG over instruction encoding\n" + "Please report this to qemu-devel@nongnu.org\n"); + } + + cs_close(&handle); + return true; +} + +/* Disassemble COUNT insns at PC for the target. */ +bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int count) +{ + uint8_t cap_buf[32]; + csh handle; + cs_insn *insn; + size_t csize =3D 0; + + if (cap_disas_start(info, &handle) !=3D CS_ERR_OK) { + return false; + } + insn =3D cap_insn; + + while (1) { + /* + * We want to read memory for one insn, but generically we do not + * know how much memory that is. We have a small buffer which is + * known to be sufficient for all supported targets. Try to not + * read beyond the page, Just In Case. For even more simplicity, + * ignore the actual target page size and use a 1k boundary. If + * that turns out to be insufficient, we'll come back around the + * loop and read more. + */ + uint64_t epc =3D QEMU_ALIGN_UP(pc + csize + 1, 1024); + size_t tsize =3D MIN(sizeof(cap_buf) - csize, epc - pc); + const uint8_t *cbuf =3D cap_buf; + + /* Make certain that we can make progress. */ + assert(tsize !=3D 0); + info->read_memory_func(pc, cap_buf + csize, tsize, info); + csize +=3D tsize; + + if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { + cap_dump_insn(info, insn); + if (--count <=3D 0) { + break; + } + } + memmove(cap_buf, cbuf, csize); + } + + cs_close(&handle); + return true; +} + +/* Disassemble a single instruction directly into plugin output */ +bool cap_disas_plugin(disassemble_info *info, uint64_t pc, size_t size) +{ + uint8_t cap_buf[32]; + const uint8_t *cbuf =3D cap_buf; + csh handle; + + if (cap_disas_start(info, &handle) !=3D CS_ERR_OK) { + return false; + } + + assert(size < sizeof(cap_buf)); + info->read_memory_func(pc, cap_buf, size, info); + + if (cs_disasm_iter(handle, &cbuf, &size, &pc, cap_insn)) { + info->fprintf_func(info->stream, "%s %s", + cap_insn->mnemonic, cap_insn->op_str); + } + + cs_close(&handle); + return true; +} diff --git a/disas/meson.build b/disas/meson.build index bde8280c73..d682f2d005 100644 --- a/disas/meson.build +++ b/disas/meson.build @@ -21,5 +21,6 @@ common_ss.add(when: 'CONFIG_S390_DIS', if_true: files('s3= 90.c')) common_ss.add(when: 'CONFIG_SH4_DIS', if_true: files('sh4.c')) common_ss.add(when: 'CONFIG_SPARC_DIS', if_true: files('sparc.c')) common_ss.add(when: 'CONFIG_XTENSA_DIS', if_true: files('xtensa.c')) +common_ss.add(when: 'CONFIG_CAPSTONE', if_true: files('capstone.c')) =20 specific_ss.add(when: 'CONFIG_TCG_INTERPRETER', if_true: files('tci.c')) diff --git a/meson.build b/meson.build index 00e2b8cc29..4839bdabab 100644 --- a/meson.build +++ b/meson.build @@ -953,6 +953,7 @@ common_ss.add(files('cpus-common.c')) =20 subdir('softmmu') =20 +common_ss.add(capstone) specific_ss.add(files('disas.c', 'exec.c', 'gdbstub.c'), capstone, libpmem= , libdaxctl) specific_ss.add(files('exec-vary.c')) specific_ss.add(when: 'CONFIG_TCG', if_true: files( --=20 2.25.1 From nobody Tue Apr 30 01:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600041995; cv=none; d=zohomail.com; s=zohoarc; b=ir5cqGzOmZrETUMpFqkczzMgjhbsY5jRqD9EvJ05+AqwTLSW1Is44rO7KSWaJ8Oqv+dwR1txv1tGJ5oNAzXXR6BwVA6EhyPj+pp4WIYHWftPnxDewWi2hF6/osPiHetHBPMTWJYXRBw4sf4m4ku91kZF/LCIQxQvGD/xn3PR0is= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600041995; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LokPjQNyghrgWvJ1kJqbWazyHqKRlOm6HdtdDxRh6d4=; b=N45vQewxTqu5w7wze3g7QRaM3Gk5W13FTGr2fsi24KSji7KBnHSgc1+58H6N2nQJ7KKNNCdghl8aDykikrMRWJAHpbLQj8NJkRhf1X+7A+Tlwsy+ALx2GHs1uwqkLRzvYrTVdn1N0V+sESQX120o6JSwoTq7IOMVaxa53bKZjc0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600041995435891.7724768413664; Sun, 13 Sep 2020 17:06:35 -0700 (PDT) Received: from localhost ([::1]:43550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHc0w-0000O2-9W for importer@patchew.org; Sun, 13 Sep 2020 20:06:34 -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) 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) 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-Google-Smtp-Source: ABdhPJzK50LNLDp2cp9fjq/DO4gum+UC9ahfYSlYKKtf8f9SRnck0E/xXAYO4jf0NPss8Z5h9gLyrg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Enable s390x, aka SYSZ, in the git submodule build. Set the capstone parameters for both s390x host and guest. Signed-off-by: Richard Henderson --- disas.c | 3 +++ target/s390x/cpu.c | 4 ++++ meson.build | 11 +++++++++++ 3 files changed, 18 insertions(+) diff --git a/disas.c b/disas.c index 7fb85bbfa8..5e943181d8 100644 --- a/disas.c +++ b/disas.c @@ -208,6 +208,9 @@ static void initialize_debug_host(CPUDebug *s) s->info.print_insn =3D print_insn_m68k; #elif defined(__s390__) s->info.print_insn =3D print_insn_s390; + s->info.cap_arch =3D CS_ARCH_SYSZ; + s->info.cap_insn_unit =3D 2; + s->info.cap_insn_split =3D 6; #elif defined(__hppa__) s->info.print_insn =3D print_insn_hppa; #endif diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index 749cd548f0..2a96692691 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -44,6 +44,7 @@ #include "sysemu/tcg.h" #endif #include "fpu/softfloat-helpers.h" +#include "disas/capstone.h" =20 #define CR0_RESET 0xE0UL #define CR14_RESET 0xC2000000UL; @@ -182,6 +183,9 @@ static void s390_cpu_disas_set_info(CPUState *cpu, disa= ssemble_info *info) { info->mach =3D bfd_mach_s390_64; info->print_insn =3D print_insn_s390; + info->cap_arch =3D CS_ARCH_SYSZ; + info->cap_insn_unit =3D 2; + info->cap_insn_split =3D 6; } =20 static void s390_cpu_realizefn(DeviceState *dev, Error **errp) diff --git a/meson.build b/meson.build index 4839bdabab..82cf4a9258 100644 --- a/meson.build +++ b/meson.build @@ -661,6 +661,17 @@ else ) endif =20 + if 'CONFIG_S390_DIS' in config_all_disas + capstone_data.set('CAPSTONE_HAS_SYSZ', '1') + capstone_files +=3D files( + 'capstone/arch/SystemZ/SystemZDisassembler.c', + 'capstone/arch/SystemZ/SystemZInstPrinter.c', + 'capstone/arch/SystemZ/SystemZMapping.c', + 'capstone/arch/SystemZ/SystemZModule.c', + 'capstone/arch/SystemZ/SystemZMCTargetDesc.c' + ) + endif + if 'CONFIG_I386_DIS' in config_all_disas capstone_data.set('CAPSTONE_HAS_X86', 1) capstone_files +=3D files( --=20 2.25.1 From nobody Tue Apr 30 01:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600042229; cv=none; d=zohomail.com; s=zohoarc; b=P0ADXP8LLX2XTtBJVlxUFLWK8Pm204WcIkz/wsHVg+CKhipE6bWu+0w1nHC9iNQdY2tUfdC5NyR6H4iVm+faG52DZGPU5LZHZ+7tV1FfgI4pb/nssMwsgl0JSQ3M4dgIVMQmmHaAflyX2HZ0SCTkuxiXFE7vctj0ppHVm56zKi0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600042229; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FHMdFNxA5DgdfHwVaO5Ocox79qcbsSZjeiufIYJ4nxY=; b=e9w+OYti9aE/ujlFwHyW6JbrZMB+cebwJv12v/+tNZllAD74RnZzgOsYh77oepPoXRl3FMF2+n1rEztOwJGnb8UTOmKy2Fj9f8S9H5tv9wWLsfIMklfXcIeZcu5CvolOwsZbbAIxxPMyIQxRKwn4sO2TVjD5hJp8ROoya+/7luk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600042229390821.5487403710301; Sun, 13 Sep 2020 17:10:29 -0700 (PDT) Received: from localhost ([::1]:54876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHc4i-00051M-AI for importer@patchew.org; Sun, 13 Sep 2020 20:10:28 -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) 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) 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-Google-Smtp-Source: ABdhPJz+7uo7MnBvnN7Om2YH7E+7o8KpLOK+urcSXOJOLEd9cYl2lyv4TFytPHEJXvyY2OQ2akZDBA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- disas/capstone.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/disas/capstone.c b/disas/capstone.c index b48f83958d..0a9ef9c892 100644 --- a/disas/capstone.c +++ b/disas/capstone.c @@ -16,6 +16,39 @@ */ static __thread cs_insn *cap_insn; =20 +/* + * The capstone library always skips 2 bytes for S390X. + * This is less than ideal, since we can tell from the first two bits + * the size of the insn and thus stay in sync with the insn stream. + */ +static size_t CAPSTONE_API +cap_skipdata_s390x_cb(const uint8_t *code, size_t code_size, + size_t offset, void *user_data) +{ + size_t ilen; + + /* See get_ilen() in target/s390x/internal.h. */ + switch (code[offset] >> 6) { + case 0: + ilen =3D 2; + break; + case 1: + case 2: + ilen =3D 4; + break; + default: + ilen =3D 6; + break; + } + + return ilen; +} + +static const cs_opt_skipdata cap_skipdata_s390x =3D { + .mnemonic =3D ".byte", + .callback =3D cap_skipdata_s390x_cb +}; + /* * Initialize the Capstone library. * @@ -42,13 +75,20 @@ static cs_err cap_disas_start(disassemble_info *info, c= sh *handle) /* "Disassemble" unknown insns as ".byte W,X,Y,Z". */ cs_option(*handle, CS_OPT_SKIPDATA, CS_OPT_ON); =20 - if (info->cap_arch =3D=3D CS_ARCH_X86) { + switch (info->cap_arch) { + case CS_ARCH_SYSZ: + cs_option(*handle, CS_OPT_SKIPDATA_SETUP, + (uintptr_t)&cap_skipdata_s390x); + break; + + case CS_ARCH_X86: /* * We don't care about errors (if for some reason the library * is compiled without AT&T syntax); the user will just have * to deal with the Intel syntax. */ cs_option(*handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_ATT); + break; } =20 /* Allocate temp space for cs_disasm_iter. */ --=20 2.25.1 From nobody Tue Apr 30 01:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600041853; cv=none; d=zohomail.com; s=zohoarc; b=SxSj9FKAM3+dgq7ho2SmxRRHJ4PCPFcKvTGD/kedLQGhzXHf8k/KwqPLoP8hx7tysBMmel0rlI2S2kizX5YmkzBO4NlEL0CuVtRUko/vDnx4KQJKy7B3fntBzzAJJy9qE6fjHCleasc3oMWgDfKtz0JF0NqbC+upYHgK+LluSFE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600041853; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NCHT5fgIvwDcF4K56DTDB0FLtjYLg/nKnYjeWLy1ICY=; b=QaDSS99fxQNqBqg/qvbJsmtmTmhAG8KPgdZZbIafxMrqn+Ge8Liu9QWO8/rHYUaEGcexJ5+E+BuIWq4NFQEvo4M5jde4bf7X6oJoGytfj7p3At6iSga5ykQBcTb2+dLe6LhVsq7iRyTGFzYJn0KjW4DP+cukmyXbuhf+lSd9pUI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600041853631330.69766104374764; Sun, 13 Sep 2020 17:04:13 -0700 (PDT) Received: from localhost ([::1]:38254 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHbye-0006ab-GG for importer@patchew.org; Sun, 13 Sep 2020 20:04:12 -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) 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) 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-Google-Smtp-Source: ABdhPJx990jZk5gxIZprKMEX7IUMmvbFIhns21m/AaoSwQoGwHVVGMm3XLt2EZkZOK2LB/vV/ZZxsA== X-Received: by 2002:a17:90b:a0a:: with SMTP id gg10mr11565237pjb.20.1600041729085; Sun, 13 Sep 2020 17:02:09 -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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson Tested-by: Philippe Mathieu-Daud=C3=A9 --- disas.c | 2 ++ target/sparc/cpu.c | 4 ++++ meson.build | 10 ++++++++++ 3 files changed, 16 insertions(+) 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 =3D print_insn_sparc; s->info.mach =3D bfd_mach_sparc_v9b; + s->info.cap_arch =3D CS_ARCH_SPARC; + s->info.cap_mode =3D CS_MODE_V9; #elif defined(__arm__) /* TCG only generates code for arm mode. */ s->info.print_insn =3D 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" + =20 //#define DEBUG_FEATURES =20 @@ -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 =3D print_insn_sparc; + info->cap_arch =3D CS_ARCH_SPARC; #ifdef TARGET_SPARC64 info->mach =3D bfd_mach_sparc_v9b; + info->cap_mode =3D CS_MODE_V9; #endif } =20 diff --git a/meson.build b/meson.build index 82cf4a9258..b1c54024ac 100644 --- a/meson.build +++ b/meson.build @@ -661,6 +661,16 @@ else ) endif =20 + if 'CONFIG_SPARC_DIS' in config_all_disas + capstone_data.set('CAPSTONE_HAS_SPARC', '1') + capstone_files +=3D 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 +=3D files( --=20 2.25.1