From patchwork Fri Apr 5 10:24:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 786236 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1101:b0:343:f27d:c44e with SMTP id z1csp93837wrw; Fri, 5 Apr 2024 03:29:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWmssvsYE3C/zYJ6qVnMWhH000BUYQYRjK5NNyZrFFTo9fC28Ve3RUDiI46n+zNrXKb29cFzSV3ap32ZtfTGbtP X-Google-Smtp-Source: AGHT+IGLWz+MHrpgNRvohuZUbcnDOoz1SbVNX/0LabaYAj0jFzyBJnt9T/Hk3izReO3I40KpMdPm X-Received: by 2002:a05:620a:3953:b0:78b:de20:932a with SMTP id qs19-20020a05620a395300b0078bde20932amr1830434qkn.13.1712312991079; Fri, 05 Apr 2024 03:29:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712312991; cv=none; d=google.com; s=arc-20160816; b=ttLUVaDn9YekuSMkOy6PKMadM/H88XDMpN01IeMaQvkxBbhCxIUYqVthE1jhxBcI+Z cxKUYmeXGS+lYJemhq/moIvUeaJZbJhs/szXPNZRYt9IiNCzhvOvFCJ/0CWzbYKihRBU 6S1VT4WYxZ45c5uq/IUplgfcoaM7cyiq/W3GGLqJ3hnjHW2LCs4xWreChE4XR0wzkG8I 1BYJ1+v5VGWu85O6jozsyLfDer9G9yrVvAU9VTRMC1QzslNzPuINFPP6AlZnXneG6mKi i/PF3NBiSDt9kftZ6TbOTl9kva0OZLr/kVwQnlQs6wawCXLq7B+2bvrZ+UXxZDhm0YFT ymZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=BSWmY5g0BLOjDo6Xjv7CB1e+gl5EQ0oR0a5drHt964Q=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=FNYpAwun62+zr6BRHIfNuph0kZpbq9jMDfezx1+X/Sm3jZsAIpl8kCKAdwSTxTBYO8 dun20/Y+msbxaEZAsmFRbXW7JvhMBdVHa4TbGZeb3Y3TmxKzrrePZv9Ho6u4Y0FaMXEr nTrBkdRlXV/hQVBQRcgEKC2ajASvPJXZSJMsS2iJGbGyqQ9cVE2XiWCxaTqAyDLAQkbZ uPZT67+N6EfNNcsjaIVDnOl/wxvb+dHzLAVSnaiyXpG2egTBmE+jaJyF0XCYhpIhJftR K+6ukmhpyFo8/MLybzP762nW66J/g6ths/yXz1/7Xg17nVsoSQ6Y66d5KmKU3K4YsClD MUYA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GifGIhqn; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j6-20020a05620a146600b00789d7cd3815si1400240qkl.471.2024.04.05.03.29.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 05 Apr 2024 03:29:51 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GifGIhqn; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rsglH-00064b-Qg; Fri, 05 Apr 2024 06:25:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rsglF-00062o-Bv for qemu-devel@nongnu.org; Fri, 05 Apr 2024 06:25:29 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rsglD-0004mT-FK for qemu-devel@nongnu.org; Fri, 05 Apr 2024 06:25:29 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6ecf9898408so794574b3a.1 for ; Fri, 05 Apr 2024 03:25:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712312726; x=1712917526; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=BSWmY5g0BLOjDo6Xjv7CB1e+gl5EQ0oR0a5drHt964Q=; b=GifGIhqnx9Nx8glcn0CrFMCXiKfr9hTJyJRtRzguVbq2/rtL3lO7WM/dCI3Tv/lMPH 3Hw0ehkvqUrTaqDf9lPz7T2IIoXIJaAR+ZtdtQqq02x6aD7H/x1jbHhTCGwOV4KeMzhP XfN6xI8vTkQUcZa/8yVN0XJU9vgII05hYB4mUkUjwYljeFATrq4Sww6oyHQhgPWiCYLB d026ySu3zLfD8n6CEm02xI5RrG2UPf7Vl+JreUDr5MVN+Myjsy6ZN9Kisp0WuZgmuMdv 2YlIcxO9oBO/z6/Mrxi8LnMj6Tb7H+ym4KtwPaAD5a07ViQ2yhwup9NyC8ffn/0t0HUo 6Yyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712312726; x=1712917526; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BSWmY5g0BLOjDo6Xjv7CB1e+gl5EQ0oR0a5drHt964Q=; b=s4vUM79Ng9hB6fYMT0ICa6G4+hw7O4aI2GdTKsyaxrNwUzntdb7+UtFXmqClLTCscK AweUC6ldoEZr5TEplBgD0IEdIggzoG39Up/VOS7R0luqZspgbIwzefc1tTEAZ8p9Z9hU B4aljDUrIr573vnGYuPc9b5VJwZxsjf5XkqYvIngbWQZsfmzGMZl6uALflHPwt2WU43S 5Q9MFgk3tj2W1IFGalAVR+K2am1AVoMjTzsPNoafMu0rBIHFQygYQcJzo3HAgftVVd/c tu/ast6oLtpEyqMHoboVZZS/lbi48CFCsyxm1aq/Upa8xCk4tIR8NuDeD4DutQ+KiXeQ 8+WQ== X-Gm-Message-State: AOJu0YywoKu0rt9N2f5MhXMtdlsDrDBgBXdnH34CpF2NnTA+hkxch9y1 ///u9OVAbz3MtE4rqD1+5mg36JN2NbblJmvhZ/3cmdC3Snd327yUsldeRAOoDkuQm3xWjbNJZNt t X-Received: by 2002:a05:6a20:7488:b0:1a5:69db:d92b with SMTP id p8-20020a056a20748800b001a569dbd92bmr2980850pzd.14.1712312726136; Fri, 05 Apr 2024 03:25:26 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id h10-20020a63f90a000000b005e438fe702dsm1104304pgi.65.2024.04.05.03.25.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 03:25:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 19/32] disas: Use translator_st to get disassembly data Date: Fri, 5 Apr 2024 00:24:46 -1000 Message-Id: <20240405102459.462551-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240405102459.462551-1-richard.henderson@linaro.org> References: <20240405102459.462551-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x436.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.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, PDS_OTHER_BAD_TLD=1.999, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Read from already translated pages, or saved mmio data. Signed-off-by: Richard Henderson --- include/disas/disas.h | 5 +++-- include/exec/translator.h | 4 ++-- include/qemu/typedefs.h | 1 + accel/tcg/translator.c | 2 +- disas/disas-common.c | 14 -------------- disas/disas-mon.c | 15 +++++++++++++++ disas/disas-target.c | 19 +++++++++++++++++-- plugins/api.c | 4 ++-- 8 files changed, 41 insertions(+), 23 deletions(-) diff --git a/include/disas/disas.h b/include/disas/disas.h index 54a5e68443..c702b1effc 100644 --- a/include/disas/disas.h +++ b/include/disas/disas.h @@ -4,14 +4,15 @@ /* Disassemble this for me please... (debugging). */ #ifdef CONFIG_TCG void disas(FILE *out, const void *code, size_t size); -void target_disas(FILE *out, CPUState *cpu, uint64_t code, size_t size); +void target_disas(FILE *out, CPUState *cpu, const DisasContextBase *db); #endif void monitor_disas(Monitor *mon, CPUState *cpu, uint64_t pc, int nb_insn, bool is_physical); #ifdef CONFIG_PLUGIN -char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size); +char *plugin_disas(CPUState *cpu, const DisasContextBase *db, + uint64_t addr, size_t size); #endif /* Look up symbol for debugging purpose. Returns "" if unknown. */ diff --git a/include/exec/translator.h b/include/exec/translator.h index 6ebe69d25c..777dee0ce2 100644 --- a/include/exec/translator.h +++ b/include/exec/translator.h @@ -78,7 +78,7 @@ typedef enum DisasJumpType { * * Architecture-agnostic disassembly context. */ -typedef struct DisasContextBase { +struct DisasContextBase { TranslationBlock *tb; vaddr pc_first; vaddr pc_next; @@ -102,7 +102,7 @@ typedef struct DisasContextBase { int record_start; int record_len; uint8_t record[32]; -} DisasContextBase; +}; /** * TranslatorOps: diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index 50c277cf0b..0b3cf3f3ec 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -50,6 +50,7 @@ typedef struct CPUTLBEntryFull CPUTLBEntryFull; typedef struct DeviceListener DeviceListener; typedef struct DeviceState DeviceState; typedef struct DirtyBitmapSnapshot DirtyBitmapSnapshot; +typedef struct DisasContextBase DisasContextBase; typedef struct DisplayChangeListener DisplayChangeListener; typedef struct DriveInfo DriveInfo; typedef struct DumpState DumpState; diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index 712e0d5c7e..4c1dc57890 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -227,7 +227,7 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns, if (!ops->disas_log || !ops->disas_log(db, cpu, logfile)) { fprintf(logfile, "IN: %s\n", lookup_symbol(db->pc_first)); - target_disas(logfile, cpu, db->pc_first, db->tb->size); + target_disas(logfile, cpu, db); } fprintf(logfile, "\n"); qemu_log_unlock(logfile); diff --git a/disas/disas-common.c b/disas/disas-common.c index e4118a381f..e4118e996b 100644 --- a/disas/disas-common.c +++ b/disas/disas-common.c @@ -7,25 +7,12 @@ #include "disas/disas.h" #include "disas/capstone.h" #include "hw/core/cpu.h" -#include "exec/memory.h" #include "disas-internal.h" /* Filled in by elfload.c. Simplistic, but will do for now. */ struct syminfo *syminfos = NULL; -/* - * Get LENGTH bytes from info's buffer, at target address memaddr. - * Transfer them to myaddr. - */ -static int target_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length, - struct disassemble_info *info) -{ - CPUDebug *s = container_of(info, CPUDebug, info); - int r = cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0); - return r ? EIO : 0; -} - /* * Print an error message. We can assume that this is in response to * an error return from {host,target}_read_memory. @@ -72,7 +59,6 @@ void disas_initialize_debug_target(CPUDebug *s, CPUState *cpu) disas_initialize_debug(s); s->cpu = cpu; - s->info.read_memory_func = target_read_memory; s->info.print_address_func = print_address; if (target_words_bigendian()) { s->info.endian = BFD_ENDIAN_BIG; diff --git a/disas/disas-mon.c b/disas/disas-mon.c index 5d6d9aa02d..37bf16ac79 100644 --- a/disas/disas-mon.c +++ b/disas/disas-mon.c @@ -11,6 +11,19 @@ #include "hw/core/cpu.h" #include "monitor/monitor.h" +/* + * Get LENGTH bytes from info's buffer, at target address memaddr. + * Transfer them to myaddr. + */ +static int +virtual_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length, + struct disassemble_info *info) +{ + CPUDebug *s = container_of(info, CPUDebug, info); + int r = cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0); + return r ? EIO : 0; +} + static int physical_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length, struct disassemble_info *info) @@ -38,6 +51,8 @@ void monitor_disas(Monitor *mon, CPUState *cpu, uint64_t pc, if (is_physical) { s.info.read_memory_func = physical_read_memory; + } else { + s.info.read_memory_func = virtual_read_memory; } s.info.buffer_vma = pc; diff --git a/disas/disas-target.c b/disas/disas-target.c index 82313b2a67..48f3a365dc 100644 --- a/disas/disas-target.c +++ b/disas/disas-target.c @@ -6,16 +6,28 @@ #include "qemu/osdep.h" #include "disas/disas.h" #include "disas/capstone.h" +#include "exec/translator.h" #include "disas-internal.h" -void target_disas(FILE *out, CPUState *cpu, uint64_t code, size_t size) +static int translator_read_memory(bfd_vma memaddr, bfd_byte *myaddr, + int length, struct disassemble_info *info) { + const DisasContextBase *db = info->application_data; + return translator_st(db, myaddr, memaddr, length) ? 0 : EIO; +} + +void target_disas(FILE *out, CPUState *cpu, const struct DisasContextBase *db) +{ + uint64_t code = db->pc_first; + size_t size = translator_st_len(db); uint64_t pc; int count; CPUDebug s; disas_initialize_debug_target(&s, cpu); + s.info.read_memory_func = translator_read_memory; + s.info.application_data = (void *)db; s.info.fprintf_func = fprintf; s.info.stream = out; s.info.buffer_vma = code; @@ -58,12 +70,15 @@ static void plugin_print_address(bfd_vma addr, struct disassemble_info *info) * there is left over it usually indicates the front end has read more * bytes than it needed. */ -char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size) +char *plugin_disas(CPUState *cpu, const DisasContextBase *db, + uint64_t addr, size_t size) { CPUDebug s; GString *ds = g_string_new(NULL); disas_initialize_debug_target(&s, cpu); + s.info.read_memory_func = translator_read_memory; + s.info.application_data = (void *)db; s.info.fprintf_func = disas_gstring_printf; s.info.stream = (FILE *)ds; /* abuse this slot */ s.info.buffer_vma = addr; diff --git a/plugins/api.c b/plugins/api.c index 36ab47cdae..c084f335dd 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -271,8 +271,8 @@ void *qemu_plugin_insn_haddr(const struct qemu_plugin_insn *insn) char *qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn) { - CPUState *cpu = current_cpu; - return plugin_disas(cpu, insn->vaddr, insn->len); + return plugin_disas(tcg_ctx->cpu, tcg_ctx->plugin_db, + insn->vaddr, insn->len); } const char *qemu_plugin_insn_symbol(const struct qemu_plugin_insn *insn)