From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org, Richard Henderson <richard.henderson@linaro.org>
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Laurent Vivier" <laurent@vivier.eu>,
"Kyle Evans" <kevans@freebsd.org>, "Warner Losh" <imp@bsdimp.com>
Subject: [RFC PATCH 1/2] disas: Move softmmu specific code to separate file
Date: Mon, 8 May 2023 15:37:44 +0200 [thread overview]
Message-ID: <20230508133745.109463-2-thuth@redhat.com> (raw)
In-Reply-To: <20230508133745.109463-1-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.
While doing the movement, change the type of the "pc" parameter of
the monitor_disas() function to "hwaddr" instead of "target_ulong",
so we can add the file to the generic softmmu_ss source set instead
of the specific_ss source set.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
disas/disas-internal.h | 20 +++++++++++
include/disas/disas.h | 6 ++--
disas.c | 76 ++++--------------------------------------
disas/disas-mon.c | 65 ++++++++++++++++++++++++++++++++++++
disas/meson.build | 2 ++
5 files changed, 96 insertions(+), 73 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..354c01307b
--- /dev/null
+++ b/disas/disas-internal.h
@@ -0,0 +1,20 @@
+/*
+ * 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/include/disas/disas.h b/include/disas/disas.h
index d363e95ede..6c04428620 100644
--- a/include/disas/disas.h
+++ b/include/disas/disas.h
@@ -11,15 +11,15 @@ void disas(FILE *out, const void *code, unsigned long size);
void target_disas(FILE *out, CPUState *cpu, target_ulong code,
target_ulong size);
-void monitor_disas(Monitor *mon, CPUState *cpu,
- target_ulong pc, int nb_insn, int is_physical);
-
char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size);
/* Look up symbol for debugging purpose. Returns "" if unknown. */
const char *lookup_symbol(target_ulong orig_addr);
#endif
+void monitor_disas(Monitor *mon, CPUState *cpu,
+ hwaddr pc, int nb_insn, int is_physical);
+
struct syminfo;
struct elf32_sym;
struct elf64_sym;
diff --git a/disas.c b/disas.c
index b087c12c47..4f4a07d611 100644
--- a/disas.c
+++ b/disas.c
@@ -1,17 +1,12 @@
/* 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"
#include "disas/capstone.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;
@@ -119,7 +114,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, target_ulong code,
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;
@@ -241,8 +236,7 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code,
}
}
-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;
@@ -272,8 +266,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;
@@ -338,61 +332,3 @@ const char *lookup_symbol(target_ulong 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,
- target_ulong pc, int nb_insn, int 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" TARGET_FMT_lx
- ": Asm output not supported on this arch\n", pc);
- return;
- }
-
- for (i = 0; i < nb_insn; i++) {
- g_string_append_printf(ds, "0x" TARGET_FMT_lx ": ", 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/disas-mon.c b/disas/disas-mon.c
new file mode 100644
index 0000000000..31b7413c40
--- /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,
+ hwaddr pc, int nb_insn, int 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" HWADDR_FMT_plx
+ ": Asm output not supported on this arch\n", pc);
+ return;
+ }
+
+ for (i = 0; i < nb_insn; i++) {
+ g_string_append_printf(ds, "0x" HWADDR_FMT_plx ": ", 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/meson.build b/disas/meson.build
index c865bdd882..ca6dd81ecf 100644
--- a/disas/meson.build
+++ b/disas/meson.build
@@ -11,3 +11,5 @@ common_ss.add(when: 'CONFIG_SH4_DIS', if_true: files('sh4.c'))
common_ss.add(when: 'CONFIG_SPARC_DIS', if_true: files('sparc.c'))
common_ss.add(when: 'CONFIG_XTENSA_DIS', if_true: files('xtensa.c'))
common_ss.add(when: capstone, if_true: files('capstone.c'))
+
+softmmu_ss.add(files('disas-mon.c'))
--
2.31.1
next prev parent reply other threads:[~2023-05-08 13:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-08 13:37 [RFC PATCH 0/2] Make the core disassembler functions target-independent Thomas Huth
2023-05-08 13:37 ` Thomas Huth [this message]
2023-05-08 13:37 ` [RFC PATCH 2/2] disas: Move disas.c into the target-independent source set Thomas Huth
2023-05-08 14:04 ` [RFC PATCH 0/2] Make the core disassembler functions target-independent Richard Henderson
2023-05-08 14:28 ` Thomas Huth
2023-05-09 15:54 ` 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=20230508133745.109463-2-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=berrange@redhat.com \
--cc=imp@bsdimp.com \
--cc=kevans@freebsd.org \
--cc=laurent@vivier.eu \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/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).