From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: Thomas Huth <thuth@redhat.com>
Subject: [PULL 07/53] disas: Move softmmu specific code to separate file
Date: Thu, 11 May 2023 09:04:04 +0100 [thread overview]
Message-ID: <20230511080450.860923-8-richard.henderson@linaro.org> (raw)
In-Reply-To: <20230511080450.860923-1-richard.henderson@linaro.org>
From: Thomas Huth <thuth@redhat.com>
We'd like to move disas.c into the common code source set, where
CONFIG_USER_ONLY is not available anymore. So we have to move
the related code into a separate file instead.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20230508133745.109463-2-thuth@redhat.com>
[rth: Type change done in a separate patch]
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
disas/disas-internal.h | 21 ++++++++++++
disas/disas-mon.c | 65 ++++++++++++++++++++++++++++++++++++
disas/disas.c | 76 ++++--------------------------------------
disas/meson.build | 1 +
4 files changed, 93 insertions(+), 70 deletions(-)
create mode 100644 disas/disas-internal.h
create mode 100644 disas/disas-mon.c
diff --git a/disas/disas-internal.h b/disas/disas-internal.h
new file mode 100644
index 0000000000..84a01f126f
--- /dev/null
+++ b/disas/disas-internal.h
@@ -0,0 +1,21 @@
+/*
+ * Definitions used internally in the disassembly code
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef DISAS_INTERNAL_H
+#define DISAS_INTERNAL_H
+
+#include "disas/dis-asm.h"
+
+typedef struct CPUDebug {
+ struct disassemble_info info;
+ CPUState *cpu;
+} CPUDebug;
+
+void disas_initialize_debug_target(CPUDebug *s, CPUState *cpu);
+int disas_gstring_printf(FILE *stream, const char *fmt, ...)
+ G_GNUC_PRINTF(2, 3);
+
+#endif
diff --git a/disas/disas-mon.c b/disas/disas-mon.c
new file mode 100644
index 0000000000..48ac492c6c
--- /dev/null
+++ b/disas/disas-mon.c
@@ -0,0 +1,65 @@
+/*
+ * Functions related to disassembly from the monitor
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "disas-internal.h"
+#include "disas/disas.h"
+#include "exec/memory.h"
+#include "hw/core/cpu.h"
+#include "monitor/monitor.h"
+
+static int
+physical_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length,
+ struct disassemble_info *info)
+{
+ CPUDebug *s = container_of(info, CPUDebug, info);
+ MemTxResult res;
+
+ res = address_space_read(s->cpu->as, memaddr, MEMTXATTRS_UNSPECIFIED,
+ myaddr, length);
+ return res == MEMTX_OK ? 0 : EIO;
+}
+
+/* Disassembler for the monitor. */
+void monitor_disas(Monitor *mon, CPUState *cpu, uint64_t pc,
+ int nb_insn, bool is_physical)
+{
+ int count, i;
+ CPUDebug s;
+ g_autoptr(GString) ds = g_string_new("");
+
+ disas_initialize_debug_target(&s, cpu);
+ s.info.fprintf_func = disas_gstring_printf;
+ s.info.stream = (FILE *)ds; /* abuse this slot */
+
+ if (is_physical) {
+ s.info.read_memory_func = physical_read_memory;
+ }
+ s.info.buffer_vma = pc;
+
+ if (s.info.cap_arch >= 0 && cap_disas_monitor(&s.info, pc, nb_insn)) {
+ monitor_puts(mon, ds->str);
+ return;
+ }
+
+ if (!s.info.print_insn) {
+ monitor_printf(mon, "0x%08" PRIx64
+ ": Asm output not supported on this arch\n", pc);
+ return;
+ }
+
+ for (i = 0; i < nb_insn; i++) {
+ g_string_append_printf(ds, "0x%08" PRIx64 ": ", pc);
+ count = s.info.print_insn(pc, &s.info);
+ g_string_append_c(ds, '\n');
+ if (count < 0) {
+ break;
+ }
+ pc += count;
+ }
+
+ monitor_puts(mon, ds->str);
+}
diff --git a/disas/disas.c b/disas/disas.c
index a06954254b..45614af02d 100644
--- a/disas/disas.c
+++ b/disas/disas.c
@@ -1,6 +1,6 @@
/* General "disassemble this chunk" code. Used for debugging. */
#include "qemu/osdep.h"
-#include "disas/dis-asm.h"
+#include "disas/disas-internal.h"
#include "elf.h"
#include "qemu/qemu-print.h"
#include "disas/disas.h"
@@ -8,11 +8,6 @@
#include "hw/core/cpu.h"
#include "exec/memory.h"
-typedef struct CPUDebug {
- struct disassemble_info info;
- CPUState *cpu;
-} CPUDebug;
-
/* Filled in by elfload.c. Simplistic, but will do for now. */
struct syminfo *syminfos = NULL;
@@ -120,7 +115,7 @@ static void initialize_debug(CPUDebug *s)
s->info.symbol_at_address_func = symbol_at_address;
}
-static void initialize_debug_target(CPUDebug *s, CPUState *cpu)
+void disas_initialize_debug_target(CPUDebug *s, CPUState *cpu)
{
initialize_debug(s);
@@ -211,7 +206,7 @@ void target_disas(FILE *out, CPUState *cpu, uint64_t code, size_t size)
int count;
CPUDebug s;
- initialize_debug_target(&s, cpu);
+ disas_initialize_debug_target(&s, cpu);
s.info.fprintf_func = fprintf;
s.info.stream = out;
s.info.buffer_vma = code;
@@ -242,8 +237,7 @@ void target_disas(FILE *out, CPUState *cpu, uint64_t code, size_t size)
}
}
-static int G_GNUC_PRINTF(2, 3)
-gstring_printf(FILE *stream, const char *fmt, ...)
+int disas_gstring_printf(FILE *stream, const char *fmt, ...)
{
/* We abuse the FILE parameter to pass a GString. */
GString *s = (GString *)stream;
@@ -273,8 +267,8 @@ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size)
CPUDebug s;
GString *ds = g_string_new(NULL);
- initialize_debug_target(&s, cpu);
- s.info.fprintf_func = gstring_printf;
+ disas_initialize_debug_target(&s, cpu);
+ s.info.fprintf_func = disas_gstring_printf;
s.info.stream = (FILE *)ds; /* abuse this slot */
s.info.buffer_vma = addr;
s.info.buffer_length = size;
@@ -339,61 +333,3 @@ const char *lookup_symbol(uint64_t orig_addr)
return symbol;
}
-
-#if !defined(CONFIG_USER_ONLY)
-
-#include "monitor/monitor.h"
-
-static int
-physical_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length,
- struct disassemble_info *info)
-{
- CPUDebug *s = container_of(info, CPUDebug, info);
- MemTxResult res;
-
- res = address_space_read(s->cpu->as, memaddr, MEMTXATTRS_UNSPECIFIED,
- myaddr, length);
- return res == MEMTX_OK ? 0 : EIO;
-}
-
-/* Disassembler for the monitor. */
-void monitor_disas(Monitor *mon, CPUState *cpu, uint64_t pc,
- int nb_insn, bool is_physical)
-{
- int count, i;
- CPUDebug s;
- g_autoptr(GString) ds = g_string_new("");
-
- initialize_debug_target(&s, cpu);
- s.info.fprintf_func = gstring_printf;
- s.info.stream = (FILE *)ds; /* abuse this slot */
-
- if (is_physical) {
- s.info.read_memory_func = physical_read_memory;
- }
- s.info.buffer_vma = pc;
-
- if (s.info.cap_arch >= 0 && cap_disas_monitor(&s.info, pc, nb_insn)) {
- monitor_puts(mon, ds->str);
- return;
- }
-
- if (!s.info.print_insn) {
- monitor_printf(mon, "0x%08" PRIx64
- ": Asm output not supported on this arch\n", pc);
- return;
- }
-
- for (i = 0; i < nb_insn; i++) {
- g_string_append_printf(ds, "0x%08" PRIx64 ": ", pc);
- count = s.info.print_insn(pc, &s.info);
- g_string_append_c(ds, '\n');
- if (count < 0) {
- break;
- }
- pc += count;
- }
-
- monitor_puts(mon, ds->str);
-}
-#endif
diff --git a/disas/meson.build b/disas/meson.build
index cbf6315f25..f40230c58f 100644
--- a/disas/meson.build
+++ b/disas/meson.build
@@ -12,4 +12,5 @@ common_ss.add(when: 'CONFIG_SPARC_DIS', if_true: files('sparc.c'))
common_ss.add(when: 'CONFIG_XTENSA_DIS', if_true: files('xtensa.c'))
common_ss.add(when: capstone, if_true: [files('capstone.c'), capstone])
+softmmu_ss.add(files('disas-mon.c'))
specific_ss.add(files('disas.c'), capstone)
--
2.34.1
next prev parent reply other threads:[~2023-05-11 8:05 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-11 8:03 [PULL 00/53] tcg patch queue Richard Henderson
2023-05-11 8:03 ` [PULL 01/53] target/m68k: Fix gen_load_fp for OS_LONG Richard Henderson
2023-05-11 8:03 ` [PULL 02/53] accel/tcg: Fix atomic_mmu_lookup for reads Richard Henderson
2023-05-11 8:04 ` [PULL 03/53] disas: Fix tabs and braces in disas.c Richard Henderson
2023-05-11 8:04 ` [PULL 04/53] disas: Move disas.c to disas/ Richard Henderson
2023-05-11 8:04 ` [PULL 05/53] disas: Remove target_ulong from the interface Richard Henderson
2023-05-11 8:04 ` [PULL 06/53] disas: Remove target-specific headers Richard Henderson
2023-05-11 8:04 ` Richard Henderson [this message]
2023-05-11 8:04 ` [PULL 08/53] disas: Move disas.c into the target-independent source set Richard Henderson
2023-05-11 8:04 ` [PULL 09/53] cpu: expose qemu_cpu_list_lock for lock-guard use Richard Henderson
2023-05-11 8:04 ` [PULL 10/53] accel/tcg/tcg-accel-ops-rr: ensure fairness with icount Richard Henderson
2023-05-11 8:04 ` [PULL 11/53] tcg/i386: Introduce prepare_host_addr Richard Henderson
2023-05-11 8:04 ` [PULL 12/53] tcg/i386: Use indexed addressing for softmmu fast path Richard Henderson
2023-05-11 8:04 ` [PULL 13/53] tcg/aarch64: Introduce prepare_host_addr Richard Henderson
2023-05-11 8:04 ` [PULL 14/53] tcg/arm: " Richard Henderson
2023-05-11 8:04 ` [PULL 15/53] tcg/loongarch64: " Richard Henderson
2023-05-11 8:04 ` [PULL 16/53] tcg/mips: " Richard Henderson
2023-05-11 8:04 ` [PULL 17/53] tcg/ppc: " Richard Henderson
2023-05-11 8:04 ` [PULL 18/53] tcg/riscv: " Richard Henderson
2023-05-11 8:04 ` [PULL 19/53] tcg/s390x: " Richard Henderson
2023-05-11 8:04 ` [PULL 20/53] tcg: Add routines for calling slow-path helpers Richard Henderson
2023-05-11 8:04 ` [PULL 21/53] tcg/i386: Convert tcg_out_qemu_ld_slow_path Richard Henderson
2023-05-11 8:04 ` [PULL 22/53] tcg/i386: Convert tcg_out_qemu_st_slow_path Richard Henderson
2023-05-11 8:04 ` [PULL 23/53] tcg/aarch64: Convert tcg_out_qemu_{ld,st}_slow_path Richard Henderson
2023-05-11 8:04 ` [PULL 24/53] tcg/arm: " Richard Henderson
2023-05-11 8:04 ` [PULL 25/53] tcg/loongarch64: " Richard Henderson
2023-05-11 8:04 ` [PULL 26/53] tcg/mips: " Richard Henderson
2023-05-11 8:04 ` [PULL 27/53] tcg/ppc: " Richard Henderson
2023-05-11 8:04 ` [PULL 28/53] tcg/riscv: " Richard Henderson
2023-05-11 8:04 ` [PULL 29/53] tcg/s390x: " Richard Henderson
2023-05-11 8:04 ` [PULL 30/53] tcg/loongarch64: Simplify constraints on qemu_ld/st Richard Henderson
2023-05-11 8:04 ` [PULL 31/53] tcg/mips: Remove MO_BSWAP handling Richard Henderson
2023-05-11 8:04 ` [PULL 32/53] tcg/mips: Reorg tlb load within prepare_host_addr Richard Henderson
2023-05-11 8:04 ` [PULL 33/53] tcg/mips: Simplify constraints on qemu_ld/st Richard Henderson
2023-05-11 8:04 ` [PULL 34/53] tcg/ppc: Reorg tcg_out_tlb_read Richard Henderson
2023-05-11 8:04 ` [PULL 35/53] tcg/ppc: Adjust constraints on qemu_ld/st Richard Henderson
2023-05-11 8:04 ` [PULL 36/53] tcg/ppc: Remove unused constraints A, B, C, D Richard Henderson
2023-05-11 8:04 ` [PULL 37/53] tcg/ppc: Remove unused constraint J Richard Henderson
2023-05-11 8:04 ` [PULL 38/53] tcg/riscv: Simplify constraints on qemu_ld/st Richard Henderson
2023-05-11 8:04 ` [PULL 39/53] tcg/s390x: Use ALGFR in constructing softmmu host address Richard Henderson
2023-05-11 8:04 ` [PULL 40/53] tcg/s390x: Simplify constraints on qemu_ld/st Richard Henderson
2023-05-11 8:04 ` [PULL 41/53] target/mips: Add MO_ALIGN to gen_llwp, gen_scwp Richard Henderson
2023-05-11 8:04 ` [PULL 42/53] target/mips: Add missing default_tcg_memop_mask Richard Henderson
2023-05-11 8:04 ` [PULL 43/53] target/mips: Use MO_ALIGN instead of 0 Richard Henderson
2023-05-11 8:04 ` [PULL 44/53] target/mips: Remove TARGET_ALIGNED_ONLY Richard Henderson
2023-05-11 8:04 ` [PULL 45/53] target/nios2: " Richard Henderson
2023-05-11 8:04 ` [PULL 46/53] target/sh4: Use MO_ALIGN where required Richard Henderson
2023-05-11 8:04 ` [PULL 47/53] target/sh4: Remove TARGET_ALIGNED_ONLY Richard Henderson
2023-05-11 8:04 ` [PULL 48/53] tcg: " Richard Henderson
2023-05-11 8:04 ` [PULL 49/53] accel/tcg: Add cpu_in_serial_context Richard Henderson
2023-05-11 8:04 ` [PULL 50/53] accel/tcg: Introduce tlb_read_idx Richard Henderson
2023-05-11 8:04 ` [PULL 51/53] accel/tcg: Reorg system mode load helpers Richard Henderson
2023-05-11 8:04 ` [PULL 52/53] accel/tcg: Reorg system mode store helpers Richard Henderson
2023-05-11 8:04 ` [PULL 53/53] target/loongarch: Do not include tcg-ldst.h Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230511080450.860923-8-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).