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 2/2] disas: Move disas.c into the target-independent source set
Date: Mon, 8 May 2023 15:37:45 +0200 [thread overview]
Message-ID: <20230508133745.109463-3-thuth@redhat.com> (raw)
In-Reply-To: <20230508133745.109463-1-thuth@redhat.com>
By using hwaddr instead of target_ulong and by tweaking some other
spots, we can turn this code into target-independent code for
compiling it only once and not multiple times during the build
process.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
meson.build | 4 ++--
include/disas/disas.h | 15 +++------------
include/hw/elf_ops.h | 2 +-
bsd-user/elfload.c | 2 +-
disas.c | 22 ++++++++++++----------
linux-user/elfload.c | 2 +-
6 files changed, 20 insertions(+), 27 deletions(-)
diff --git a/meson.build b/meson.build
index 229eb585f7..73ceed037f 100644
--- a/meson.build
+++ b/meson.build
@@ -3152,8 +3152,8 @@ specific_ss.add(files('cpu.c'))
subdir('softmmu')
-common_ss.add(capstone)
-specific_ss.add(files('disas.c'), capstone)
+common_ss.add(files('disas.c'), capstone)
+specific_ss.add(capstone)
# Work around a gcc bug/misfeature wherein constant propagation looks
# through an alias:
diff --git a/include/disas/disas.h b/include/disas/disas.h
index 6c04428620..5132ebf982 100644
--- a/include/disas/disas.h
+++ b/include/disas/disas.h
@@ -3,19 +3,14 @@
#include "exec/hwaddr.h"
-#ifdef NEED_CPU_H
-#include "cpu.h"
-
/* Disassemble this for me please... (debugging). */
void disas(FILE *out, const void *code, unsigned long size);
-void target_disas(FILE *out, CPUState *cpu, target_ulong code,
- target_ulong size);
+void target_disas(FILE *out, CPUState *cpu, hwaddr code, long size);
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
+const char *lookup_symbol(hwaddr orig_addr);
void monitor_disas(Monitor *mon, CPUState *cpu,
hwaddr pc, int nb_insn, int is_physical);
@@ -24,11 +19,7 @@ struct syminfo;
struct elf32_sym;
struct elf64_sym;
-#if defined(CONFIG_USER_ONLY)
-typedef const char *(*lookup_symbol_t)(struct syminfo *s, target_ulong orig_addr);
-#else
-typedef const char *(*lookup_symbol_t)(struct syminfo *s, hwaddr orig_addr);
-#endif
+typedef const char *(*lookup_symbol_t)(struct syminfo *s, uint64_t orig_addr);
struct syminfo {
lookup_symbol_t lookup_symbol;
diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
index dffb0e73d2..5e2af4d504 100644
--- a/include/hw/elf_ops.h
+++ b/include/hw/elf_ops.h
@@ -81,7 +81,7 @@ static int glue(symfind, SZ)(const void *s0, const void *s1)
}
static const char *glue(lookup_symbol, SZ)(struct syminfo *s,
- hwaddr orig_addr)
+ uint64_t orig_addr)
{
struct elf_sym *syms = glue(s->disas_symtab.elf, SZ);
struct elf_sym *sym;
diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c
index fbcdc94b96..7c784518ed 100644
--- a/bsd-user/elfload.c
+++ b/bsd-user/elfload.c
@@ -363,7 +363,7 @@ static int symfind(const void *s0, const void *s1)
return result;
}
-static const char *lookup_symbolxx(struct syminfo *s, target_ulong orig_addr)
+static const char *lookup_symbolxx(struct syminfo *s, uint64_t orig_addr)
{
#if ELF_CLASS == ELFCLASS32
struct elf_sym *syms = s->disas_symtab.elf32;
diff --git a/disas.c b/disas.c
index 4f4a07d611..31edbd2e70 100644
--- a/disas.c
+++ b/disas.c
@@ -3,6 +3,9 @@
#include "disas/disas-internal.h"
#include "elf.h"
#include "qemu/qemu-print.h"
+#include "exec/cpu-common.h"
+#include "exec/memory.h"
+#include "hw/core/cpu.h"
#include "disas/disas.h"
#include "disas/capstone.h"
@@ -121,11 +124,11 @@ void disas_initialize_debug_target(CPUDebug *s, CPUState *cpu)
s->cpu = cpu;
s->info.read_memory_func = target_read_memory;
s->info.print_address_func = print_address;
-#if TARGET_BIG_ENDIAN
- s->info.endian = BFD_ENDIAN_BIG;
-#else
- s->info.endian = BFD_ENDIAN_LITTLE;
-#endif
+ if (target_words_bigendian()) {
+ s->info.endian = BFD_ENDIAN_BIG;
+ } else {
+ s->info.endian = BFD_ENDIAN_LITTLE;
+ }
CPUClass *cc = CPU_GET_CLASS(cpu);
if (cc->disas_set_info) {
@@ -199,10 +202,9 @@ static void initialize_debug_host(CPUDebug *s)
}
/* Disassemble this for me please... (debugging). */
-void target_disas(FILE *out, CPUState *cpu, target_ulong code,
- target_ulong size)
+void target_disas(FILE *out, CPUState *cpu, hwaddr code, long size)
{
- target_ulong pc;
+ hwaddr pc;
int count;
CPUDebug s;
@@ -221,7 +223,7 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code,
}
for (pc = code; size > 0; pc += count, size -= count) {
- fprintf(out, "0x" TARGET_FMT_lx ": ", pc);
+ fprintf(out, "0x" HWADDR_FMT_plx ": ", pc);
count = s.info.print_insn(pc, &s.info);
fprintf(out, "\n");
if (count < 0)
@@ -318,7 +320,7 @@ void disas(FILE *out, const void *code, unsigned long size)
}
/* Look up symbol for debugging purpose. Returns "" if unknown. */
-const char *lookup_symbol(target_ulong orig_addr)
+const char *lookup_symbol(hwaddr orig_addr)
{
const char *symbol = "";
struct syminfo *s;
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 703f7434a0..48c9e910a8 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -3338,7 +3338,7 @@ static int symfind(const void *s0, const void *s1)
return result;
}
-static const char *lookup_symbolxx(struct syminfo *s, target_ulong orig_addr)
+static const char *lookup_symbolxx(struct syminfo *s, uint64_t orig_addr)
{
#if ELF_CLASS == ELFCLASS32
struct elf_sym *syms = s->disas_symtab.elf32;
--
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 ` [RFC PATCH 1/2] disas: Move softmmu specific code to separate file Thomas Huth
2023-05-08 13:37 ` Thomas Huth [this message]
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-3-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).